diff --git a/.gitignore b/.gitignore index 8ce872ff4..9ccf75bfd 100644 --- a/.gitignore +++ b/.gitignore @@ -95,3 +95,11 @@ hs_err_pid* org.eclipse.paho.android.sample/libs/ + +# Ignore all IDE-related artifacts +.project +*/.project +*/.classpath +tags +.settings/* +*/.settings/* diff --git a/build.gradle b/build.gradle index a60ed7b22..b882c3499 100755 --- a/build.gradle +++ b/build.gradle @@ -2,11 +2,11 @@ buildscript { repositories { - jcenter() + google() mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.3' + classpath 'com.android.tools.build:gradle:8.2.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } @@ -57,7 +57,7 @@ println "SDK dir: $sdkDir" allprojects { repositories { - jcenter() + google() maven { url "file://$sdkDir/extras/android/m2repository/" } diff --git a/gradle.properties b/gradle.properties index 1d3591c8a..ccd5dda1d 100755 --- a/gradle.properties +++ b/gradle.properties @@ -15,4 +15,5 @@ # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true \ No newline at end of file +# org.gradle.parallel=true +android.useAndroidX=true \ No newline at end of file diff --git a/org.eclipse.paho.android.service/.project b/org.eclipse.paho.android.service/.project deleted file mode 100644 index 9b18a6d51..000000000 --- a/org.eclipse.paho.android.service/.project +++ /dev/null @@ -1,39 +0,0 @@ - - - org.eclipse.paho.android.service - - - - - - com.android.ide.eclipse.adt.ResourceManagerBuilder - - - - - com.android.ide.eclipse.adt.PreCompilerBuilder - - - - - org.eclipse.jdt.core.javabuilder - - - - - com.android.ide.eclipse.adt.ApkBuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - com.android.ide.eclipse.adt.AndroidNature - org.eclipse.m2e.core.maven2Nature - org.eclipse.jdt.core.javanature - - diff --git a/org.eclipse.paho.android.service/build.gradle b/org.eclipse.paho.android.service/build.gradle index bda982503..3aed5b375 100755 --- a/org.eclipse.paho.android.service/build.gradle +++ b/org.eclipse.paho.android.service/build.gradle @@ -2,11 +2,11 @@ apply plugin: 'com.android.library' apply plugin: 'maven-publish' android { + namespace "org.eclipse.paho" compileSdkVersion rootProject.ext.compileSdkVersion - buildToolsVersion rootProject.ext.buildToolsVersion defaultConfig { - minSdkVersion 9 + minSdkVersion 19 targetSdkVersion 24 testApplicationId "org.eclipse.paho.android.service.test" @@ -18,10 +18,6 @@ android { } } - dexOptions { - preDexLibraries = false - } - lintOptions { abortOnError false } @@ -32,40 +28,42 @@ repositories { } configurations { - //androidTestCompile.exclude module: 'org.eclipse.paho.client.mqttv3' + androidTestCompile.exclude module: 'org.eclipse.paho.client.mqttv3' } dependencies { - compile "org.eclipse.paho:org.eclipse.paho.client.mqttv3:${rootProject.ext.clientVersion}" - compile "com.android.support:support-v4:${rootProject.ext.supportLibVersion}" - compile fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.eclipse.paho:org.eclipse.paho.client.mqttv3:${rootProject.ext.clientVersion}" + implementation "com.android.support:support-v4:${rootProject.ext.supportLibVersion}" + implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation 'androidx.test.ext:junit:1.2.0-alpha03' + implementation 'androidx.test:rules:1.5.0' } -android.libraryVariants.all { variant -> - task("generate${variant.name}Javadoc", type: Javadoc) { - title = "$name $version API" - description "Generates Javadoc for $variant.name." - source = variant.javaCompile.source - ext.androidJar = - "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar" - classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar) - options.links("http://docs.oracle.com/javase/7/docs/api/"); - options.links("http://d.android.com/reference/"); - exclude '**/BuildConfig.java' - exclude '**/R.java' - } -} +//android.libraryVariants.all { variant -> +// task("generate${variant.name}Javadoc", type: Javadoc) { +// title = "$name $version API" +// description "Generates Javadoc for $variant.name." +// source = variant.javaCompile.source +// ext.androidJar = +// "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar" +// classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar) +// options.links("http://docs.oracle.com/javase/7/docs/api/"); +// options.links("http://d.android.com/reference/"); +// exclude '**/BuildConfig.java' +// exclude '**/R.java' +// } +//} // Generate Sources Jar task("generateSourcesJar", type: Jar) { from android.sourceSets.main.java.srcDirs - classifier = 'sources' + archiveClassifier = 'sources' } // Copy the Paho Java client into the libs directory to bundle it with the AAR task("copyLibs", type: Copy) { println "Copying MQTT Jar into libs directory" - from configurations.compile + from configurations.implementation into 'libs' include 'org.eclipse.paho*' } @@ -86,7 +84,7 @@ task("generateLibraryJar", type: Jar) { // Generate Javadoc task("generateJavaDocJar", type: Jar, dependsOn: (rootProject.ext.serviceVersion.endsWith('-SNAPSHOT') ? 'generatedebugJavadoc' : 'generatereleaseJavadoc')){ from("$buildDir/docs/javadoc") - classifier = 'javadoc' + archiveClassifier = 'javadoc' } publishing { @@ -117,13 +115,17 @@ publishing { } } - +/* task debug << { - configurations.compile.each { println it} + configurations.implementation.each { println it} } + */ + // Required to bundle Java library Jar in AAR clean.doLast{ - copyLibs.execute() + dependencies { + copyLibs + } } assemble.doLast { renameReleaseAAR.execute() diff --git a/org.eclipse.paho.android.service/src/androidTest/AndroidManifest.xml b/org.eclipse.paho.android.service/src/androidTest/AndroidManifest.xml index d01507322..a8bf893b1 100644 --- a/org.eclipse.paho.android.service/src/androidTest/AndroidManifest.xml +++ b/org.eclipse.paho.android.service/src/androidTest/AndroidManifest.xml @@ -1,5 +1,4 @@ - + diff --git a/org.eclipse.paho.android.service/src/androidTest/java/org/eclipse/paho/android/AndroidServiceTest.java b/org.eclipse.paho.android.service/src/androidTest/java/org/eclipse/paho/android/AndroidServiceTest.java index a259b279f..ce04951d5 100755 --- a/org.eclipse.paho.android.service/src/androidTest/java/org/eclipse/paho/android/AndroidServiceTest.java +++ b/org.eclipse.paho.android.service/src/androidTest/java/org/eclipse/paho/android/AndroidServiceTest.java @@ -10,16 +10,20 @@ import org.eclipse.paho.client.mqttv3.MqttConnectOptions; import org.eclipse.paho.client.mqttv3.MqttMessage; -import android.test.AndroidTestCase; +import androidx.test.rule.ServiceTestRule; +import androidx.test.platform.app.InstrumentationRegistry; import org.eclipse.paho.android.service.MqttAndroidClient; import android.util.Log; +import android.content.Context; +import static org.junit.Assert.*; + /** * Testing Fundamentals */ -public class AndroidServiceTest extends AndroidTestCase { +public class AndroidServiceTest extends ServiceTestRule { private static final String TAG = "AndroidServiceTest"; @@ -29,11 +33,15 @@ public class AndroidServiceTest extends AndroidTestCase { private String mqttSSLServerURI; private int waitForCompletionTime; private String keyStorePwd; + + private Context mContext; @Override - public void setUp() throws Exception { - super.setUp(); - TestProperties properties = new TestProperties(this.getContext()); + public void beforeService() { + super.beforeService(); + + mContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + TestProperties properties = new TestProperties(mContext); mqttServerURI = properties.getServerURI(); mqttSSLServerURI = properties.getServerSSLURI(); waitForCompletionTime = properties.getWaitForCompletionTime(); @@ -42,8 +50,6 @@ public void setUp() throws Exception { Log.d(TAG, properties.getServerSSLURI()); } - - /** * Tests that a client can be constructed and that it can connect to and * disconnect from the service @@ -170,7 +176,6 @@ public void testRemoteConnect() throws Exception { mqttClient.close(); } } - } /** @@ -237,7 +242,6 @@ public void testLargeMessage() { } } - } /** @@ -341,7 +345,6 @@ public void testMultipleClients() { } } - } /** @@ -537,7 +540,6 @@ public void testQoSPreserved() { } } - } /** @@ -674,7 +676,6 @@ public void testCleanStart() { } } - } // /** Oringally commented out from the fv test version // * Tests that invalid clientIds cannot connect. @@ -780,7 +781,6 @@ public void testPubSub(){ } } - } public void testHAConnect() throws Exception{ @@ -902,7 +902,6 @@ public void testRetainedMessage(){ fail("Failed to instantiate:" + methodName + " exception=" + exception); } - } /** @@ -920,7 +919,7 @@ public void testSSLConnect() throws Exception { "testSSLConnect"); MqttConnectOptions options = new MqttConnectOptions(); - options.setSocketFactory(mqttClient.getSSLSocketFactory(this.getContext().getAssets().open("test.bks"), keyStorePwd)); + options.setSocketFactory(mqttClient.getSSLSocketFactory(mContext.getAssets().open("test.bks"), keyStorePwd)); IMqttToken connectToken = null; IMqttToken disconnectToken = null; @@ -945,10 +944,8 @@ public void testSSLConnect() throws Exception { mqttClient.close(); } } - } - - + /** * An SSL connection with server cert authentication, simple pub/sub of an message * @@ -969,7 +966,7 @@ public void testSSLPubSub() throws Exception { "testSSLPubSub"); MqttConnectOptions options = new MqttConnectOptions(); - options.setSocketFactory(mqttClient.getSSLSocketFactory(this.getContext().getAssets().open("test.bks"), + options.setSocketFactory(mqttClient.getSSLSocketFactory(mContext.getAssets().open("test.bks"), keyStorePwd)); MqttV3Receiver mqttV3Receiver = new MqttV3Receiver(mqttClient, null); @@ -1009,8 +1006,5 @@ public void testSSLPubSub() throws Exception { mqttClient.close(); } } - } - - -} \ No newline at end of file +} diff --git a/org.eclipse.paho.android.service/src/androidTest/java/org/eclipse/paho/android/AndroidServiceWithActionListenerTest.java b/org.eclipse.paho.android.service/src/androidTest/java/org/eclipse/paho/android/AndroidServiceWithActionListenerTest.java index f6aba7ba1..b4e27a816 100644 --- a/org.eclipse.paho.android.service/src/androidTest/java/org/eclipse/paho/android/AndroidServiceWithActionListenerTest.java +++ b/org.eclipse.paho.android.service/src/androidTest/java/org/eclipse/paho/android/AndroidServiceWithActionListenerTest.java @@ -23,18 +23,22 @@ import org.eclipse.paho.client.mqttv3.MqttConnectOptions; import org.eclipse.paho.client.mqttv3.MqttMessage; +import androidx.test.platform.app.InstrumentationRegistry; + import android.content.Intent; -import android.os.IBinder; -import android.test.ServiceTestCase; +import android.content.Context; +import androidx.test.rule.ServiceTestRule; import android.util.Log; import org.eclipse.paho.android.service.MqttAndroidClient; +import java.util.concurrent.TimeoutException; + /** * @author Rhys * */ -public class AndroidServiceWithActionListenerTest extends ServiceTestCase { +public class AndroidServiceWithActionListenerTest extends ServiceTestRule { private String serverURI; private String mqttSSLServerURI; @@ -47,28 +51,32 @@ public class AndroidServiceWithActionListenerTest extends ServiceTestCase { private TestCaseNotifier notifier = new TestCaseNotifier(); private final String classCanonicalName = this.getClass().getCanonicalName(); + + private Context mContext; public AndroidServiceWithActionListenerTest() { - //noinspection unchecked - super(org.eclipse.paho.android.service.MqttService.class); + super(); } @Override - protected void setUp() throws Exception { - - super.setUp(); - Intent intent = new Intent(); - intent.setClassName("org.eclipse.paho.android.service", "MqttService"); - IBinder binder = bindService(intent); - - TestProperties properties = new TestProperties(this.getContext()); + protected void beforeService() { + super.beforeService(); + mContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + try { + startService(new Intent( + mContext, + org.eclipse.paho.android.service.MqttService.class)); + } catch (TimeoutException e) { + throw new RuntimeException(e); + } + + TestProperties properties = new TestProperties(mContext); serverURI = properties.getServerURI(); mqttSSLServerURI = properties.getServerSSLURI(); waitForCompletionTime = properties.getWaitForCompletionTime(); String clientKeyStore = properties.getClientKeyStore(); keyStorePwd = properties.getClientKeyStorePassword(); - } public void testConnect() throws Throwable { @@ -90,7 +98,6 @@ public void testConnect() throws Throwable { disconnectToken = mqttClient.disconnect(null, new ActionListener(notifier)); notifier.waitForCompletion(waitForCompletionTime); - } public void testRemoteConnect() throws Throwable { @@ -137,7 +144,6 @@ public void testRemoteConnect() throws Throwable { disconnectToken = mqttClient.disconnect(null, new ActionListener(notifier)); notifier.waitForCompletion(waitForCompletionTime); - } public void testLargeMessage() throws Throwable { @@ -200,7 +206,6 @@ public void testLargeMessage() throws Throwable { } } - } public void testMultipleClients() throws Throwable { @@ -263,7 +268,6 @@ public void testMultipleClients() throws Throwable { } // for subscribers... } // for messages... - for (IMqttAsyncClient aMqttPublisher : mqttPublisher) { disconnectToken = aMqttPublisher.disconnect(null, null); disconnectToken.waitForCompletion(waitForCompletionTime); @@ -274,7 +278,6 @@ public void testMultipleClients() throws Throwable { disconnectToken.waitForCompletion(waitForCompletionTime); aMqttSubscriber.close(); } - } // public void testNonDurableSubs() throws Throwable { @@ -432,7 +435,6 @@ public void testQoSPreserved() throws Throwable { disconnectToken = mqttClient.disconnect(null, new ActionListener(notifier)); notifier.waitForCompletion(waitForCompletionTime); - } @@ -507,7 +509,6 @@ public void testPubSub() throws Throwable{ if (!ok) { Assert.fail("Receive failed"); } - } catch (Exception exception) { Assert.fail("Failed to instantiate:" + methodName + " exception=" @@ -525,10 +526,8 @@ public void testPubSub() throws Throwable{ } } - } - public void testRetainedMessage() throws Throwable{ String methodName = "testRetainedMessage"; @@ -609,7 +608,6 @@ public void testRetainedMessage() throws Throwable{ Assert.fail("Failed to instantiate:" + methodName + " exception=" + exception); } - } /** @@ -626,19 +624,19 @@ public void testSSLConnect() throws Exception { mqttClient = new MqttAndroidClient(mContext, mqttSSLServerURI, "testSSLConnect"); MqttConnectOptions options = new MqttConnectOptions(); - options.setSocketFactory(mqttClient.getSSLSocketFactory(this.getContext().getAssets().open("test.bks"),keyStorePwd)); + options.setSocketFactory(mqttClient.getSSLSocketFactory(mContext.getAssets().open("test.bks"),keyStorePwd)); IMqttToken connectToken = null; IMqttToken disconnectToken = null; - connectToken = mqttClient.connect(options, this.getContext(), new ActionListener(notifier)); + connectToken = mqttClient.connect(options, mContext, new ActionListener(notifier)); connectToken.waitForCompletion(waitForCompletionTime); disconnectToken = mqttClient.disconnect(null, new ActionListener(notifier)); disconnectToken.waitForCompletion(waitForCompletionTime); - connectToken = mqttClient.connect(options, this.getContext(), new ActionListener(notifier)); + connectToken = mqttClient.connect(options, mContext, new ActionListener(notifier)); connectToken.waitForCompletion(waitForCompletionTime); disconnectToken = mqttClient.disconnect(null, new ActionListener(notifier)); @@ -652,7 +650,6 @@ public void testSSLConnect() throws Exception { mqttClient.close(); } } - } @@ -666,7 +663,6 @@ public void testSSLPubSub() throws Exception { MqttAndroidClient mqttClient = null; - IMqttToken connectToken = null; IMqttToken disconnectToken = null; IMqttToken subToken = null; @@ -676,13 +672,13 @@ public void testSSLPubSub() throws Exception { mqttClient = new MqttAndroidClient(mContext, mqttSSLServerURI, "testSSLPubSub"); MqttConnectOptions options = new MqttConnectOptions(); - options.setSocketFactory(mqttClient.getSSLSocketFactory(this.getContext().getAssets().open("test.bks"),keyStorePwd)); + options.setSocketFactory(mqttClient.getSSLSocketFactory(mContext.getAssets().open("test.bks"),keyStorePwd)); MqttV3Receiver mqttV3Receiver = new MqttV3Receiver(mqttClient, null); mqttClient.setCallback(mqttV3Receiver); - connectToken = mqttClient.connect(options,this.getContext(),new ActionListener(notifier)); + connectToken = mqttClient.connect(options,mContext, new ActionListener(notifier)); connectToken.waitForCompletion(waitForCompletionTime); String[] topicNames = new String[]{"testSSLPubSub"+"/Topic"}; @@ -702,13 +698,11 @@ public void testSSLPubSub() throws Exception { if (!ok) { Assert.fail("Receive failed"); } - } catch (Exception exception) { Assert.fail("Failed:" + "testSSLPubSub" + " exception=" + exception); } finally { - disconnectToken = mqttClient.disconnect(null, new ActionListener(notifier)); disconnectToken.waitForCompletion(waitForCompletionTime); @@ -716,7 +710,6 @@ public void testSSLPubSub() throws Exception { mqttClient.close(); } } - } @@ -736,7 +729,6 @@ public void onFailure(IMqttToken token, Throwable exception) { synchronized (notifier) { notifier.notifyAll(); } - } /* (non-Javadoc) @@ -746,9 +738,6 @@ public void onSuccess(IMqttToken token) { synchronized (notifier) { notifier.notifyAll(); } - } - } - } diff --git a/org.eclipse.paho.android.service/src/main/AndroidManifest.xml b/org.eclipse.paho.android.service/src/main/AndroidManifest.xml index b1c079cb8..cba1fe00a 100755 --- a/org.eclipse.paho.android.service/src/main/AndroidManifest.xml +++ b/org.eclipse.paho.android.service/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - + diff --git a/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/AlarmPingSender.java b/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/AlarmPingSender.java index 8ad9569f9..79b384feb 100755 --- a/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/AlarmPingSender.java +++ b/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/AlarmPingSender.java @@ -73,8 +73,14 @@ public void start() { Log.d(TAG, "Register alarmreceiver to MqttService"+ action); service.registerReceiver(alarmReceiver, new IntentFilter(action)); - pendingIntent = PendingIntent.getBroadcast(service, 0, new Intent( - action), PendingIntent.FLAG_UPDATE_CURRENT); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + pendingIntent = PendingIntent.getBroadcast(service, 0, new Intent( + action), PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE); + } + else { + pendingIntent = PendingIntent.getBroadcast(service, 0, new Intent( + action), PendingIntent.FLAG_UPDATE_CURRENT); + } schedule(comms.getKeepAlive()); hasStarted = true; diff --git a/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/DatabaseMessageStore.java b/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/DatabaseMessageStore.java index e11eca101..e5a31f73a 100755 --- a/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/DatabaseMessageStore.java +++ b/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/DatabaseMessageStore.java @@ -459,4 +459,4 @@ public void close() { } -} \ No newline at end of file +} diff --git a/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/MqttAndroidClient.java b/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/MqttAndroidClient.java index 06e5b7e98..4a985df60 100755 --- a/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/MqttAndroidClient.java +++ b/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/MqttAndroidClient.java @@ -55,7 +55,7 @@ import android.content.ServiceConnection; import android.os.Bundle; import android.os.IBinder; -import android.support.v4.content.LocalBroadcastManager; +import androidx.localbroadcastmanager.content.LocalBroadcastManager; import android.util.SparseArray; /** diff --git a/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/MqttService.java b/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/MqttService.java index 626c5b896..3c902ed40 100644 --- a/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/MqttService.java +++ b/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/MqttService.java @@ -41,7 +41,7 @@ import android.os.IBinder; import android.os.PowerManager; import android.os.PowerManager.WakeLock; -import android.support.v4.content.LocalBroadcastManager; +import androidx.localbroadcastmanager.content.LocalBroadcastManager; /** *