Updating SSL Certs & following linter advice
Signed-off-by: James Sutton <james.sutton@uk.ibm.com>
@ -8,7 +8,7 @@ buildscript {
|
||||
}
|
||||
dependencies {
|
||||
//classpath 'com.android.tools.build:gradle:2.0.0'
|
||||
classpath 'com.android.tools.build:gradle:2.0.0'
|
||||
classpath 'com.android.tools.build:gradle:2.1.2'
|
||||
//classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+'
|
||||
// Work around to fix build
|
||||
//classpath 'com.github.JakeWharton:sdk-manager-plugin:1d29782dd6'
|
||||
@ -21,7 +21,7 @@ buildscript {
|
||||
ext{
|
||||
|
||||
compileSdkVersion = 23
|
||||
buildToolsVersion = '23.0.2'
|
||||
buildToolsVersion = '24.0.1'
|
||||
|
||||
group = 'org.eclipse.paho'
|
||||
|
||||
|
Before Width: | Height: | Size: 526 B |
Before Width: | Height: | Size: 288 B |
Before Width: | Height: | Size: 526 B |
Before Width: | Height: | Size: 894 B |
Before Width: | Height: | Size: 563 B |
Before Width: | Height: | Size: 330 B |
Before Width: | Height: | Size: 194 B |
Before Width: | Height: | Size: 313 B |
Before Width: | Height: | Size: 566 B |
Before Width: | Height: | Size: 374 B |
Before Width: | Height: | Size: 558 B |
Before Width: | Height: | Size: 297 B |
Before Width: | Height: | Size: 751 B |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 745 B |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 503 B |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 1.2 KiB |
@ -1,295 +0,0 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:paho="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/drawer_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/container_toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<include
|
||||
android:id="@+id/toolbar"
|
||||
layout="@layout/toolbar" />
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/container_body"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1">
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/scrollView"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentStart="true">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<!-- General Settings -->
|
||||
|
||||
<TextView
|
||||
android:text="@string/add_connection_general_label"
|
||||
style="@style/HeaderText"
|
||||
android:id="@+id/generalTextView" />
|
||||
|
||||
|
||||
<org.eclipse.paho.android.sample.components.TextSelectComponent
|
||||
android:id="@+id/client_id_group"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/generalTextView"
|
||||
paho:main_label="@string/add_connection_client_id_label"
|
||||
paho:input_title="@string/add_connection_client_id_title"
|
||||
paho:default_value="@string/add_connection_client_id_default"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider1"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/client_id_group" />
|
||||
|
||||
<org.eclipse.paho.android.sample.components.TextSelectComponent
|
||||
android:id="@+id/server_group"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/divider1"
|
||||
paho:main_label="@string/add_connection_server_label"
|
||||
paho:input_title="@string/add_connection_server_title"
|
||||
paho:default_value="@string/add_connection_server_default"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider2"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/server_group" />
|
||||
|
||||
<org.eclipse.paho.android.sample.components.TextSelectComponent
|
||||
android:id="@+id/port_group"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/divider2"
|
||||
paho:main_label="@string/add_connection_port_label"
|
||||
paho:input_title="@string/add_connection_port_title"
|
||||
paho:default_value="@string/add_connection_port_default"
|
||||
paho:number="true"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider3"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/port_group" />
|
||||
|
||||
|
||||
<Switch
|
||||
android:text="@string/add_connection_clean_session_label"
|
||||
android:id="@+id/clean_session_switch"
|
||||
android:layout_below="@+id/divider3"
|
||||
style="@style/Switch" />
|
||||
|
||||
<!-- Advanced Settings -->
|
||||
<!-- General Settings -->
|
||||
|
||||
|
||||
<TextView
|
||||
android:text="@string/add_connection_advanced_label"
|
||||
style="@style/HeaderText"
|
||||
android:layout_below="@+id/clean_session_switch"
|
||||
android:id="@+id/advancedTextView" />
|
||||
|
||||
<org.eclipse.paho.android.sample.components.TextSelectComponent
|
||||
android:id="@+id/username_group"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/advancedTextView"
|
||||
paho:main_label="@string/add_connection_username_label"
|
||||
paho:input_title="@string/add_connection_username_title"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider4"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/username_group" />
|
||||
|
||||
<org.eclipse.paho.android.sample.components.TextSelectComponent
|
||||
android:id="@+id/password_group"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/divider4"
|
||||
paho:main_label="@string/add_connection_password_label"
|
||||
paho:input_title="@string/add_connection_password_title"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider5"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/password_group" />
|
||||
|
||||
<org.eclipse.paho.android.sample.components.TextSelectComponent
|
||||
android:id="@+id/tls_server_key"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/divider5"
|
||||
paho:main_label="@string/add_connection_tls_server_key_label"
|
||||
paho:input_title="@string/add_connection_tls_server_key_title"
|
||||
paho:default_value=""
|
||||
paho:number="true"/>
|
||||
|
||||
<org.eclipse.paho.android.sample.components.TextSelectComponent
|
||||
android:id="@+id/tls_client_key"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/tls_server_key"
|
||||
paho:main_label="@string/add_connection_tls_client_key_label"
|
||||
paho:input_title="@string/add_connection_tls_client_key_title"
|
||||
paho:default_value=""
|
||||
paho:number="true"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider6"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/tls_client_key" />
|
||||
|
||||
<org.eclipse.paho.android.sample.components.TextSelectComponent
|
||||
android:id="@+id/timeout_group"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/divider6"
|
||||
paho:main_label="@string/add_connection_timeout_label"
|
||||
paho:input_title="@string/add_connection_timeout_title"
|
||||
paho:default_value="@string/add_connection_timeout_default"
|
||||
paho:number="true"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider7"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/timeout_group" />
|
||||
|
||||
<org.eclipse.paho.android.sample.components.TextSelectComponent
|
||||
android:id="@+id/keep_alive_group"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/divider7"
|
||||
paho:main_label="@string/add_connection_keepalive_label"
|
||||
paho:input_title="@string/add_connection_keepalive_title"
|
||||
paho:default_value="@string/add_connection_keepalive_default"
|
||||
paho:number="true"/>
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- Last Will & Testament -->
|
||||
|
||||
<TextView
|
||||
android:text="@string/add_connection_lwt_label"
|
||||
style="@style/HeaderText"
|
||||
android:layout_below="@+id/keep_alive_group"
|
||||
android:id="@+id/lwtTextView" />
|
||||
|
||||
|
||||
<org.eclipse.paho.android.sample.components.TextSelectComponent
|
||||
android:id="@+id/topic_group"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/lwtTextView"
|
||||
paho:main_label="@string/add_connection_lwt_topic_label"
|
||||
paho:input_title="@string/add_connection_lwt_topic_title"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider8"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/topic_group" />
|
||||
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/lwt_message_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@+id/divider8">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lwt_message_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_lwt_message_label"/>
|
||||
|
||||
<EditText
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="30dp"
|
||||
android:inputType="textMultiLine"
|
||||
android:ems="10"
|
||||
android:lines="4"
|
||||
android:id="@+id/lwt_message"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
|
||||
<View
|
||||
android:id="@+id/divider9"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/lwt_message_group" />
|
||||
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/lwt_qos_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@+id/divider9">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lwt_qos_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_lwt_qos_label"/>
|
||||
|
||||
<Spinner
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/lwt_qos_spinner"
|
||||
|
||||
android:layout_centerHorizontal="true" />
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider10"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/lwt_qos_group" />
|
||||
|
||||
<Switch
|
||||
android:text="@string/add_connection_lwt_retain_label"
|
||||
android:id="@+id/retain_switch"
|
||||
android:layout_below="@+id/divider10"
|
||||
style="@style/Switch" />
|
||||
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"/>
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
</ScrollView>
|
||||
|
||||
|
||||
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
@ -8,7 +8,7 @@ android {
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 9
|
||||
targetSdkVersion 22
|
||||
targetSdkVersion 23
|
||||
testApplicationId "org.eclipse.paho.android.service.test"
|
||||
}
|
||||
buildTypes {
|
||||
@ -38,7 +38,7 @@ configurations {
|
||||
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')
|
||||
//compile fileTree(include: ['*.jar'], dir: 'libs')
|
||||
}
|
||||
|
||||
android.libraryVariants.all { variant ->
|
||||
|
@ -1,6 +1,5 @@
|
||||
# This is the server URI which will be set in the constructor of an MQTT Client
|
||||
# The default is "tcp://<localhost>:1883" with <localhost> expressed in IPV4 dotted decimal notation
|
||||
#SERVER_URI=tcp://mbtest1.hursley.ibm.com:1883
|
||||
SERVER_URI=tcp://iot.eclipse.org:1883
|
||||
SERVER_SSL_URI=ssl://iot.eclipse.org:8883
|
||||
CLIENT_KEY_STORE=test.bks
|
||||
|
@ -1,30 +1,15 @@
|
||||
package org.eclipse.paho.android;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.test.ApplicationTestCase;
|
||||
import android.test.ServiceTestCase;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.eclipse.paho.android.service.R;
|
||||
import org.eclipse.paho.client.mqttv3.IMqttActionListener;
|
||||
import org.eclipse.paho.client.mqttv3.IMqttAsyncClient;
|
||||
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
|
||||
import org.eclipse.paho.client.mqttv3.IMqttToken;
|
||||
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
import org.eclipse.paho.android.service.MqttAndroidClient;
|
||||
@ -36,9 +21,9 @@ import android.util.Log;
|
||||
*/
|
||||
public class AndroidServiceTest extends AndroidTestCase {
|
||||
|
||||
private static String TAG = "org.eclipse.paho.android.service.AndroidServiceTest";
|
||||
private static final String TAG = "AndroidServiceTest";
|
||||
|
||||
private String classCanonicalName = this.getClass().getCanonicalName();
|
||||
private final String classCanonicalName = this.getClass().getCanonicalName();
|
||||
|
||||
private String mqttServerURI;
|
||||
private String mqttSSLServerURI;
|
||||
@ -249,7 +234,7 @@ public class AndroidServiceTest extends AndroidTestCase {
|
||||
|
||||
mqttClient.close();
|
||||
}
|
||||
catch (Exception exception) {
|
||||
catch (Exception ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
@ -304,18 +289,18 @@ public class AndroidServiceTest extends AndroidTestCase {
|
||||
|
||||
subToken = mqttSubscriber[i].subscribe(topicNames, topicQos,
|
||||
null, null);
|
||||
Log.i(methodName, "subscribe " + topicNames[0].toString()
|
||||
Log.i(methodName, "subscribe " + topicNames[0]
|
||||
+ " QoS is " + topicQos[0]);
|
||||
subToken.waitForCompletion(waitForCompletionTime);
|
||||
} // for...
|
||||
|
||||
for (int iMessage = 0; iMessage < 2; iMessage++) {
|
||||
byte[] payload = ("Message " + iMessage).getBytes();
|
||||
for (int i = 0; i < mqttPublisher.length; i++) {
|
||||
pubToken = mqttPublisher[i].publish(topicNames[0], payload,
|
||||
for (IMqttAsyncClient aMqttPublisher : mqttPublisher) {
|
||||
pubToken = aMqttPublisher.publish(topicNames[0], payload,
|
||||
0, false, null, null);
|
||||
Log.i(methodName, "publish to " + topicNames[0]
|
||||
+ " payload is " + payload.toString());
|
||||
+ " payload is " + Arrays.toString(payload));
|
||||
|
||||
pubToken.waitForCompletion(waitForCompletionTime);
|
||||
}
|
||||
@ -323,7 +308,7 @@ public class AndroidServiceTest extends AndroidTestCase {
|
||||
TimeUnit.MILLISECONDS.sleep(30000);
|
||||
|
||||
for (int i = 0; i < mqttSubscriber.length; i++) {
|
||||
for (int ii = 0; ii < mqttPublisher.length; ii++) {
|
||||
for (IMqttAsyncClient aMqttPublisher : mqttPublisher) {
|
||||
Log.i(methodName,
|
||||
"validate time = " + new Date().toString());
|
||||
boolean ok = mqttV3Receiver[i].validateReceipt(
|
||||
@ -343,17 +328,17 @@ public class AndroidServiceTest extends AndroidTestCase {
|
||||
+ exception);
|
||||
} finally {
|
||||
try {
|
||||
for (int i = 0; i < mqttPublisher.length; i++) {
|
||||
disconnectToken = mqttPublisher[i].disconnect(null, null);
|
||||
for (IMqttAsyncClient aMqttPublisher : mqttPublisher) {
|
||||
disconnectToken = aMqttPublisher.disconnect(null, null);
|
||||
disconnectToken.waitForCompletion(waitForCompletionTime);
|
||||
mqttPublisher[i].close();
|
||||
aMqttPublisher.close();
|
||||
}
|
||||
for (int i = 0; i < mqttSubscriber.length; i++) {
|
||||
disconnectToken = mqttSubscriber[i].disconnect(null, null);
|
||||
for (IMqttAsyncClient aMqttSubscriber : mqttSubscriber) {
|
||||
disconnectToken = aMqttSubscriber.disconnect(null, null);
|
||||
disconnectToken.waitForCompletion(waitForCompletionTime);
|
||||
mqttSubscriber[i].close();
|
||||
aMqttSubscriber.close();
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
} catch (Exception ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
@ -549,7 +534,7 @@ public class AndroidServiceTest extends AndroidTestCase {
|
||||
|
||||
mqttClient.close();
|
||||
}
|
||||
catch (Exception exception) {
|
||||
catch (Exception ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
@ -686,7 +671,7 @@ public class AndroidServiceTest extends AndroidTestCase {
|
||||
|
||||
mqttClient.close();
|
||||
}
|
||||
catch (Exception exception) {
|
||||
catch (Exception ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
@ -792,7 +777,7 @@ public class AndroidServiceTest extends AndroidTestCase {
|
||||
|
||||
mqttClient.close();
|
||||
}
|
||||
catch (Exception exception) {
|
||||
catch (Exception ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
@ -899,7 +884,7 @@ public class AndroidServiceTest extends AndroidTestCase {
|
||||
subToken = mqttClientRetained.subscribe(topicNames, topicQos, null, null);
|
||||
subToken.waitForCompletion();
|
||||
|
||||
Log.i(methodName, "subscribe "+topicNames[0].toString() + " QoS is " + topicQos[0]);
|
||||
Log.i(methodName, "subscribe "+ topicNames[0] + " QoS is " + topicQos[0]);
|
||||
|
||||
TimeUnit.MILLISECONDS.sleep(3000);
|
||||
|
||||
|
@ -36,8 +36,6 @@ import org.eclipse.paho.android.service.MqttAndroidClient;
|
||||
*/
|
||||
public class AndroidServiceWithActionListenerTest extends ServiceTestCase {
|
||||
|
||||
private IBinder binder;
|
||||
|
||||
private String serverURI;
|
||||
private String mqttSSLServerURI;
|
||||
|
||||
@ -49,7 +47,7 @@ public class AndroidServiceWithActionListenerTest extends ServiceTestCase {
|
||||
//since we know tokens do not work when an action listener isn't specified
|
||||
private TestCaseNotifier notifier = new TestCaseNotifier();
|
||||
|
||||
private String classCanonicalName = this.getClass().getCanonicalName();
|
||||
private final String classCanonicalName = this.getClass().getCanonicalName();
|
||||
|
||||
|
||||
public AndroidServiceWithActionListenerTest() {
|
||||
@ -62,7 +60,7 @@ public class AndroidServiceWithActionListenerTest extends ServiceTestCase {
|
||||
super.setUp();
|
||||
Intent intent = new Intent();
|
||||
intent.setClassName("org.eclipse.paho.android.service", "MqttService");
|
||||
binder = bindService(intent);
|
||||
IBinder binder = bindService(intent);
|
||||
|
||||
TestProperties properties = new TestProperties(this.getContext());
|
||||
serverURI = properties.getServerURI();
|
||||
@ -99,7 +97,7 @@ public class AndroidServiceWithActionListenerTest extends ServiceTestCase {
|
||||
String methodName = "testRemoteConnect";
|
||||
IMqttAsyncClient mqttClient = null;
|
||||
|
||||
mqttClient = mqttClient = new MqttAndroidClient(mContext, serverURI, "testRemoteConnect");
|
||||
mqttClient = new MqttAndroidClient(mContext, serverURI, "testRemoteConnect");
|
||||
IMqttToken connectToken = null;
|
||||
IMqttToken subToken = null;
|
||||
IMqttDeliveryToken pubToken = null;
|
||||
@ -198,7 +196,7 @@ public class AndroidServiceWithActionListenerTest extends ServiceTestCase {
|
||||
|
||||
mqttClient.close();
|
||||
}
|
||||
catch (Exception exception) {
|
||||
catch (Exception ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
@ -246,8 +244,8 @@ public class AndroidServiceWithActionListenerTest extends ServiceTestCase {
|
||||
|
||||
for (int iMessage = 0; iMessage < 2; iMessage++) {
|
||||
byte[] payload = ("Message " + iMessage).getBytes();
|
||||
for (int i = 0; i < mqttPublisher.length; i++) {
|
||||
pubToken = mqttPublisher[i].publish(topicNames[0], payload, 0, false,
|
||||
for (IMqttAsyncClient aMqttPublisher : mqttPublisher) {
|
||||
pubToken = aMqttPublisher.publish(topicNames[0], payload, 0, false,
|
||||
null, new ActionListener(notifier));
|
||||
notifier.waitForCompletion(waitForCompletionTime);
|
||||
}
|
||||
@ -255,7 +253,7 @@ public class AndroidServiceWithActionListenerTest extends ServiceTestCase {
|
||||
TimeUnit.MILLISECONDS.sleep(30000);
|
||||
|
||||
for (int i = 0; i < mqttSubscriber.length; i++) {
|
||||
for (int ii = 0; ii < mqttPublisher.length; ii++) {
|
||||
for (IMqttAsyncClient aMqttPublisher : mqttPublisher) {
|
||||
boolean ok = mqttV3Receiver[i].validateReceipt(
|
||||
topicNames[0], 0, payload);
|
||||
if (!ok) {
|
||||
@ -266,15 +264,15 @@ public class AndroidServiceWithActionListenerTest extends ServiceTestCase {
|
||||
} // for messages...
|
||||
|
||||
|
||||
for (int i = 0; i < mqttPublisher.length; i++) {
|
||||
disconnectToken = mqttPublisher[i].disconnect(null, null);
|
||||
for (IMqttAsyncClient aMqttPublisher : mqttPublisher) {
|
||||
disconnectToken = aMqttPublisher.disconnect(null, null);
|
||||
disconnectToken.waitForCompletion(waitForCompletionTime);
|
||||
mqttPublisher[i].close();
|
||||
aMqttPublisher.close();
|
||||
}
|
||||
for (int i = 0; i < mqttSubscriber.length; i++) {
|
||||
disconnectToken = mqttSubscriber[i].disconnect(null, null);
|
||||
for (IMqttAsyncClient aMqttSubscriber : mqttSubscriber) {
|
||||
disconnectToken = aMqttSubscriber.disconnect(null, null);
|
||||
disconnectToken.waitForCompletion(waitForCompletionTime);
|
||||
mqttSubscriber[i].close();
|
||||
aMqttSubscriber.close();
|
||||
}
|
||||
|
||||
}
|
||||
@ -523,7 +521,7 @@ public class AndroidServiceWithActionListenerTest extends ServiceTestCase {
|
||||
|
||||
mqttClient.close();
|
||||
}
|
||||
catch (Exception exception) {
|
||||
catch (Exception ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
@ -591,7 +589,7 @@ public class AndroidServiceWithActionListenerTest extends ServiceTestCase {
|
||||
subToken = mqttClientRetained.subscribe(topicNames, topicQos, null, new ActionListener(notifier));
|
||||
notifier.waitForCompletion(waitForCompletionTime);
|
||||
|
||||
Log.i(methodName, "subscribe "+topicNames[0].toString() + " QoS is " + topicQos[0]);
|
||||
Log.i(methodName, "subscribe "+ topicNames[0] + " QoS is " + topicQos[0]);
|
||||
|
||||
TimeUnit.MILLISECONDS.sleep(3000);
|
||||
|
||||
|
@ -1,3 +1,15 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 IBM Corp.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*/
|
||||
package org.eclipse.paho.android;
|
||||
|
||||
import java.io.PrintStream;
|
||||
@ -16,9 +28,6 @@ import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Created by james on 19/08/15.
|
||||
*/
|
||||
public class MqttV3Receiver implements MqttCallback{
|
||||
|
||||
private final java.io.PrintStream reportStream;
|
||||
@ -42,7 +51,7 @@ public class MqttV3Receiver implements MqttCallback{
|
||||
}
|
||||
}
|
||||
|
||||
java.util.List<ReceivedMessage> receivedMessages = Collections.synchronizedList(new java.util.ArrayList<ReceivedMessage>());
|
||||
private java.util.List<ReceivedMessage> receivedMessages = Collections.synchronizedList(new java.util.ArrayList<ReceivedMessage>());
|
||||
|
||||
/**
|
||||
* @param mqttClient
|
||||
@ -149,7 +158,7 @@ public class MqttV3Receiver implements MqttCallback{
|
||||
if (!java.util.Arrays.equals(sentBytes,
|
||||
receivedMessage.message.getPayload())) {
|
||||
report("Received invalid payload="
|
||||
+ receivedMessage.message.getPayload() + "\n" + "Sent:"
|
||||
+ Arrays.toString(receivedMessage.message.getPayload()) + "\n" + "Sent:"
|
||||
+ new String(sentBytes) + "\n" + "Received:"
|
||||
+ new String(receivedMessage.message.getPayload()));
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package org.eclipse.paho.android;
|
||||
|
||||
public class TestCaseNotifier {
|
||||
class TestCaseNotifier {
|
||||
|
||||
private Throwable exception;
|
||||
|
||||
@ -13,7 +13,7 @@ public class TestCaseNotifier {
|
||||
try {
|
||||
wait(timeout);
|
||||
}
|
||||
catch (InterruptedException e) {}
|
||||
catch (InterruptedException ignored) {}
|
||||
|
||||
if (exception != null) {
|
||||
throw exception;
|
||||
|
@ -1,3 +1,15 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 IBM Corp.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*/
|
||||
package org.eclipse.paho.android;
|
||||
|
||||
import android.content.Context;
|
||||
@ -7,25 +19,17 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Created by james on 18/08/15.
|
||||
*/
|
||||
public class TestProperties {
|
||||
class TestProperties {
|
||||
|
||||
// public int waitForCompletionTime = 6000;
|
||||
// public String serverURI = "tcp://9.125.29.127:1883";
|
||||
// public static String serverURI = "tcp://9.119.156.175:1883";
|
||||
// public static String sslServerURI = "ssl://9.119.156.175:8892";
|
||||
// public String sslServerURI = "ssl://9.125.29.12:8892";
|
||||
|
||||
private final Class<?> cclass = TestProperties.class;
|
||||
private final String className = cclass.getName();
|
||||
|
||||
public final String KEY_SERVER_URI = "SERVER_URI";
|
||||
public final String KEY_CLIENT_KEY_STORE = "CLIENT_KEY_STORE";
|
||||
public final String KEY_CLIENT_KEY_STORE_PASSWORD = "CLIENT_KEY_STORE_PASSWORD";
|
||||
public final String KEY_SERVER_SSL_URI = "SERVER_SSL_URI";
|
||||
public final String KEY_WAIT_FOR_COMPLETION_TIME = "WAIT_FOR_COMPLETION_TIME";
|
||||
private final String KEY_SERVER_URI = "SERVER_URI";
|
||||
private final String KEY_CLIENT_KEY_STORE = "CLIENT_KEY_STORE";
|
||||
private final String KEY_CLIENT_KEY_STORE_PASSWORD = "CLIENT_KEY_STORE_PASSWORD";
|
||||
private final String KEY_SERVER_SSL_URI = "SERVER_SSL_URI";
|
||||
private final String KEY_WAIT_FOR_COMPLETION_TIME = "WAIT_FOR_COMPLETION_TIME";
|
||||
|
||||
private Properties properties = new Properties();
|
||||
|
||||
@ -85,9 +89,8 @@ public class TestProperties {
|
||||
* @param key
|
||||
* @return value
|
||||
*/
|
||||
public String getProperty(String key) {
|
||||
String value = properties.getProperty(key);
|
||||
return value;
|
||||
private String getProperty(String key) {
|
||||
return properties.getProperty(key);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,7 +106,7 @@ public class TestProperties {
|
||||
* @param key
|
||||
* @return value
|
||||
*/
|
||||
public int getIntProperty(String key) {
|
||||
private int getIntProperty(String key) {
|
||||
String value = getProperty(key);
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ import android.util.Log;
|
||||
*/
|
||||
class AlarmPingSender implements MqttPingSender {
|
||||
// Identifier for Intents, log messages, etc..
|
||||
static final String TAG = "AlarmPingSender";
|
||||
private static final String TAG = "AlarmPingSender";
|
||||
|
||||
// TODO: Add log.
|
||||
private ClientComms comms;
|
||||
@ -104,7 +104,15 @@ class AlarmPingSender implements MqttPingSender {
|
||||
Log.d(TAG, "Schedule next alarm at " + nextAlarmInMilliseconds);
|
||||
AlarmManager alarmManager = (AlarmManager) service
|
||||
.getSystemService(Service.ALARM_SERVICE);
|
||||
if (Build.VERSION.SDK_INT >= 19) {
|
||||
|
||||
if(Build.VERSION.SDK_INT >= 23){
|
||||
// In SDK 23 and above, dosing will prevent setExact, setExactAndAllowWhileIdle will force
|
||||
// the device to run this task whilst dosing.
|
||||
Log.d(TAG, "Alarm scheule using setExactAndAllowWhileIdle, next: " + delayInMilliseconds);
|
||||
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, nextAlarmInMilliseconds,
|
||||
pendingIntent);
|
||||
} else if (Build.VERSION.SDK_INT >= 19) {
|
||||
Log.d(TAG, "Alarm scheule using setExact, delay: " + delayInMilliseconds);
|
||||
alarmManager.setExact(AlarmManager.RTC_WAKEUP, nextAlarmInMilliseconds,
|
||||
pendingIntent);
|
||||
} else {
|
||||
@ -118,7 +126,7 @@ class AlarmPingSender implements MqttPingSender {
|
||||
*/
|
||||
class AlarmReceiver extends BroadcastReceiver {
|
||||
private WakeLock wakelock;
|
||||
private String wakeLockTag = MqttServiceConstants.PING_WAKELOCK
|
||||
private final String wakeLockTag = MqttServiceConstants.PING_WAKELOCK
|
||||
+ that.comms.getClient().getClientId();
|
||||
|
||||
@Override
|
||||
|
@ -33,7 +33,7 @@ import android.database.sqlite.SQLiteOpenHelper;
|
||||
class DatabaseMessageStore implements MessageStore {
|
||||
|
||||
// TAG used for indentify trace data etc.
|
||||
private static String TAG = "DatabaseMessageStore";
|
||||
private static final String TAG = "DatabaseMessageStore";
|
||||
|
||||
// One "private" database column name
|
||||
// The other database column names are defined in MqttServiceConstants
|
||||
@ -57,7 +57,7 @@ class DatabaseMessageStore implements MessageStore {
|
||||
*/
|
||||
private static class MQTTDatabaseHelper extends SQLiteOpenHelper {
|
||||
// TAG used for indentify trace data etc.
|
||||
private static String TAG = "MQTTDatabaseHelper";
|
||||
private static final String TAG = "MQTTDatabaseHelper";
|
||||
|
||||
private static final String DATABASE_NAME = "mqttAndroidService.db";
|
||||
|
||||
@ -141,7 +141,7 @@ class DatabaseMessageStore implements MessageStore {
|
||||
* a context to use for android calls
|
||||
*/
|
||||
public DatabaseMessageStore(MqttService service, Context context) {
|
||||
this.traceHandler = (MqttTraceHandler) service;
|
||||
this.traceHandler = service;
|
||||
|
||||
// Open message database
|
||||
mqttDb = new MQTTDatabaseHelper(traceHandler, context);
|
||||
@ -290,7 +290,7 @@ class DatabaseMessageStore implements MessageStore {
|
||||
return new Iterator<StoredMessage>() {
|
||||
private Cursor c;
|
||||
private boolean hasNext;
|
||||
private String[] selectionArgs = {
|
||||
private final String[] selectionArgs = {
|
||||
clientHandle,
|
||||
};
|
||||
|
||||
@ -321,7 +321,7 @@ class DatabaseMessageStore implements MessageStore {
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
if (hasNext == false){
|
||||
if (!hasNext){
|
||||
c.close();
|
||||
}
|
||||
return hasNext;
|
||||
@ -401,7 +401,6 @@ class DatabaseMessageStore implements MessageStore {
|
||||
}
|
||||
traceHandler.traceDebug(TAG, "clearArrivedMessages: rows affected = "
|
||||
+ rows);
|
||||
return;
|
||||
}
|
||||
|
||||
private class DbStoredData implements StoredMessage {
|
||||
|
@ -36,7 +36,7 @@ interface MessageStore {
|
||||
/**
|
||||
* External representation of a stored message
|
||||
*/
|
||||
public interface StoredMessage {
|
||||
interface StoredMessage {
|
||||
/**
|
||||
* @return the identifier for the message within the store
|
||||
*/
|
||||
@ -67,8 +67,8 @@ interface MessageStore {
|
||||
* message to be stored
|
||||
* @return a unique identifier for it
|
||||
*/
|
||||
public String storeArrived(String clientHandle, String Topic,
|
||||
MqttMessage message);
|
||||
String storeArrived(String clientHandle, String Topic,
|
||||
MqttMessage message);
|
||||
|
||||
/**
|
||||
* Discard a message - called when we are certain that an arrived message
|
||||
@ -79,7 +79,7 @@ interface MessageStore {
|
||||
* @param id
|
||||
* id of message to be discarded
|
||||
*/
|
||||
public boolean discardArrived(String clientHandle, String id);
|
||||
boolean discardArrived(String clientHandle, String id);
|
||||
|
||||
/**
|
||||
* Get all the stored messages, usually for a specific client
|
||||
@ -88,7 +88,7 @@ interface MessageStore {
|
||||
* identifier for the client - if null, then messages for all
|
||||
* clients are returned
|
||||
*/
|
||||
public Iterator<StoredMessage> getAllArrivedMessages(String clientHandle);
|
||||
Iterator<StoredMessage> getAllArrivedMessages(String clientHandle);
|
||||
|
||||
/**
|
||||
* Discard stored messages, usually for a specific client
|
||||
@ -97,7 +97,7 @@ interface MessageStore {
|
||||
* identifier for the client - if null, then messages for all
|
||||
* clients are discarded
|
||||
*/
|
||||
public void clearArrivedMessages(String clientHandle);
|
||||
void clearArrivedMessages(String clientHandle);
|
||||
|
||||
public void close();
|
||||
void close();
|
||||
}
|
||||
|
@ -16,7 +16,6 @@
|
||||
*/
|
||||
package org.eclipse.paho.android.service;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.KeyManagementException;
|
||||
@ -100,7 +99,7 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
|
||||
private static final int BIND_SERVICE_FLAG = 0;
|
||||
|
||||
private static ExecutorService pool = Executors.newCachedThreadPool();
|
||||
private static final ExecutorService pool = Executors.newCachedThreadPool();
|
||||
|
||||
/**
|
||||
* ServiceConnection to process when we bind to our service
|
||||
@ -123,7 +122,7 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
}
|
||||
|
||||
// Listener for when the service is connected or disconnected
|
||||
private MyServiceConnection serviceConnection = new MyServiceConnection();
|
||||
private final MyServiceConnection serviceConnection = new MyServiceConnection();
|
||||
|
||||
// The Android Service which will process our mqtt calls
|
||||
private MqttService mqttService;
|
||||
@ -132,16 +131,16 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
// the service
|
||||
private String clientHandle;
|
||||
|
||||
Context myContext;
|
||||
private Context myContext;
|
||||
|
||||
// We hold the various tokens in a collection and pass identifiers for them
|
||||
// to the service
|
||||
private SparseArray<IMqttToken> tokenMap = new SparseArray<IMqttToken>();
|
||||
private final SparseArray<IMqttToken> tokenMap = new SparseArray<>();
|
||||
private int tokenNumber = 0;
|
||||
|
||||
// Connection data
|
||||
private String serverURI;
|
||||
private String clientId;
|
||||
private final String serverURI;
|
||||
private final String clientId;
|
||||
private MqttClientPersistence persistence = null;
|
||||
private MqttConnectOptions connectOptions;
|
||||
private IMqttToken connectToken;
|
||||
@ -151,7 +150,7 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
private MqttTraceHandler traceCallback;
|
||||
|
||||
//The acknowledgment that a message has been processed by the application
|
||||
private Ack messageAck;
|
||||
private final Ack messageAck;
|
||||
private boolean traceEnabled = false;
|
||||
|
||||
private volatile boolean receiverRegistered = false;
|
||||
@ -249,11 +248,7 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
|
||||
if (clientHandle != null && mqttService != null) {
|
||||
return mqttService.isConnected(clientHandle);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return clientHandle != null && mqttService != null && mqttService.isConnected(clientHandle);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -500,7 +495,7 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
@Override
|
||||
public IMqttToken disconnect() throws MqttException {
|
||||
IMqttToken token = new MqttTokenAndroid(this, null,
|
||||
(IMqttActionListener) null);
|
||||
null);
|
||||
String activityToken = storeToken(token);
|
||||
mqttService.disconnect(clientHandle, null, activityToken);
|
||||
return token;
|
||||
@ -529,7 +524,7 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
@Override
|
||||
public IMqttToken disconnect(long quiesceTimeout) throws MqttException {
|
||||
IMqttToken token = new MqttTokenAndroid(this, null,
|
||||
(IMqttActionListener) null);
|
||||
null);
|
||||
String activityToken = storeToken(token);
|
||||
mqttService.disconnect(clientHandle, quiesceTimeout, null,
|
||||
activityToken);
|
||||
@ -1575,7 +1570,7 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
String destinationName = data
|
||||
.getString(MqttServiceConstants.CALLBACK_DESTINATION_NAME);
|
||||
|
||||
ParcelableMqttMessage message = (ParcelableMqttMessage) data
|
||||
ParcelableMqttMessage message = data
|
||||
.getParcelable(MqttServiceConstants.CALLBACK_MESSAGE_PARCEL);
|
||||
try {
|
||||
if (messageAck == Ack.AUTO_ACK) {
|
||||
@ -1656,8 +1651,7 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
private synchronized IMqttToken getMqttToken(Bundle data) {
|
||||
String activityToken = data
|
||||
.getString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN);
|
||||
IMqttToken token = tokenMap.get(Integer.parseInt(activityToken));
|
||||
return token;
|
||||
return tokenMap.get(Integer.parseInt(activityToken));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1714,17 +1708,7 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
sslSockFactory=ctx.getSocketFactory();
|
||||
return sslSockFactory;
|
||||
|
||||
} catch (KeyStoreException e) {
|
||||
throw new MqttSecurityException(e);
|
||||
} catch (CertificateException e) {
|
||||
throw new MqttSecurityException(e);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new MqttSecurityException(e);
|
||||
} catch (IOException e) {
|
||||
throw new MqttSecurityException(e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new MqttSecurityException(e);
|
||||
} catch (KeyManagementException e) {
|
||||
} catch (KeyStoreException | CertificateException | IOException | NoSuchAlgorithmException | KeyManagementException e) {
|
||||
throw new MqttSecurityException(e);
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
package org.eclipse.paho.android.service;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
@ -24,15 +25,12 @@ import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
|
||||
import org.eclipse.paho.client.mqttv3.IMqttMessageListener;
|
||||
import org.eclipse.paho.client.mqttv3.IMqttToken;
|
||||
import org.eclipse.paho.client.mqttv3.MqttAsyncClient;
|
||||
import org.eclipse.paho.client.mqttv3.MqttCallback;
|
||||
import org.eclipse.paho.client.mqttv3.MqttCallbackExtended;
|
||||
import org.eclipse.paho.client.mqttv3.MqttClientPersistence;
|
||||
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.eclipse.paho.client.mqttv3.MqttPersistenceException;
|
||||
import org.eclipse.paho.client.mqttv3.internal.DisconnectedMessageBuffer;
|
||||
import org.eclipse.paho.client.mqttv3.internal.ExceptionHelper;
|
||||
import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence;
|
||||
|
||||
import android.app.Service;
|
||||
@ -133,10 +131,10 @@ class MqttConnection implements MqttCallbackExtended {
|
||||
// Saved sent messages and their corresponding Topics, activityTokens and
|
||||
// invocationContexts, so we can handle "deliveryComplete" callbacks
|
||||
// from the mqttClient
|
||||
private Map<IMqttDeliveryToken, String /* Topic */> savedTopics = new HashMap<IMqttDeliveryToken, String>();
|
||||
private Map<IMqttDeliveryToken, MqttMessage> savedSentMessages = new HashMap<IMqttDeliveryToken, MqttMessage>();
|
||||
private Map<IMqttDeliveryToken, String> savedActivityTokens = new HashMap<IMqttDeliveryToken, String>();
|
||||
private Map<IMqttDeliveryToken, String> savedInvocationContexts = new HashMap<IMqttDeliveryToken, String>();
|
||||
private Map<IMqttDeliveryToken, String /* Topic */> savedTopics = new HashMap<>();
|
||||
private Map<IMqttDeliveryToken, MqttMessage> savedSentMessages = new HashMap<>();
|
||||
private Map<IMqttDeliveryToken, String> savedActivityTokens = new HashMap<>();
|
||||
private Map<IMqttDeliveryToken, String> savedInvocationContexts = new HashMap<>();
|
||||
|
||||
private WakeLock wakelock = null;
|
||||
private String wakeLockTag = null;
|
||||
@ -161,19 +159,19 @@ class MqttConnection implements MqttCallbackExtended {
|
||||
*/
|
||||
MqttConnection(MqttService service, String serverURI, String clientId,
|
||||
MqttClientPersistence persistence, String clientHandle) {
|
||||
this.serverURI = serverURI.toString();
|
||||
this.serverURI = serverURI;
|
||||
this.service = service;
|
||||
this.clientId = clientId;
|
||||
this.persistence = persistence;
|
||||
this.clientHandle = clientHandle;
|
||||
|
||||
StringBuffer buff = new StringBuffer(this.getClass().getCanonicalName());
|
||||
buff.append(" ");
|
||||
buff.append(clientId);
|
||||
buff.append(" ");
|
||||
buff.append("on host ");
|
||||
buff.append(serverURI);
|
||||
wakeLockTag = buff.toString();
|
||||
StringBuilder stringBuilder = new StringBuilder(this.getClass().getCanonicalName());
|
||||
stringBuilder.append(" ");
|
||||
stringBuilder.append(clientId);
|
||||
stringBuilder.append(" ");
|
||||
stringBuilder.append("on host ");
|
||||
stringBuilder.append(serverURI);
|
||||
wakeLockTag = stringBuilder.toString();
|
||||
}
|
||||
|
||||
// The major API implementation follows
|
||||
@ -271,7 +269,6 @@ class MqttConnection implements MqttCallbackExtended {
|
||||
service.traceDebug(TAG,
|
||||
"myClient != null and the client is connecting. Connect return directly.");
|
||||
service.traceDebug(TAG,"Connect return:isConnecting:"+isConnecting+".disconnected:"+disconnected);
|
||||
return;
|
||||
}else if(!disconnected){
|
||||
service.traceDebug(TAG,"myClient != null and the client is connected and notify!");
|
||||
doAfterConnectSuccess(resultBundle);
|
||||
@ -485,9 +482,7 @@ class MqttConnection implements MqttCallbackExtended {
|
||||
* @return true if we are connected to an MQTT server
|
||||
*/
|
||||
public boolean isConnected() {
|
||||
if (myClient != null)
|
||||
return myClient.isConnected();
|
||||
return false;
|
||||
return myClient != null && myClient.isConnected();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -660,7 +655,7 @@ class MqttConnection implements MqttCallbackExtended {
|
||||
*/
|
||||
public void subscribe(final String[] topic, final int[] qos,
|
||||
String invocationContext, String activityToken) {
|
||||
service.traceDebug(TAG, "subscribe({" + topic + "}," + qos + ",{"
|
||||
service.traceDebug(TAG, "subscribe({" + Arrays.toString(topic) + "}," + Arrays.toString(qos) + ",{"
|
||||
+ invocationContext + "}, {" + activityToken + "}");
|
||||
final Bundle resultBundle = new Bundle();
|
||||
resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION,
|
||||
@ -688,7 +683,7 @@ class MqttConnection implements MqttCallbackExtended {
|
||||
}
|
||||
|
||||
public void subscribe(String[] topicFilters, int[] qos, String invocationContext, String activityToken, IMqttMessageListener[] messageListeners) {
|
||||
service.traceDebug(TAG, "subscribe({" + topicFilters + "}," + qos + ",{"
|
||||
service.traceDebug(TAG, "subscribe({" + Arrays.toString(topicFilters) + "}," + Arrays.toString(qos) + ",{"
|
||||
+ invocationContext + "}, {" + activityToken + "}");
|
||||
final Bundle resultBundle = new Bundle();
|
||||
resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION, MqttServiceConstants.SUBSCRIBE_ACTION);
|
||||
@ -760,7 +755,7 @@ class MqttConnection implements MqttCallbackExtended {
|
||||
*/
|
||||
void unsubscribe(final String[] topic, String invocationContext,
|
||||
String activityToken) {
|
||||
service.traceDebug(TAG, "unsubscribe({" + topic + "},{"
|
||||
service.traceDebug(TAG, "unsubscribe({" + Arrays.toString(topic) + "},{"
|
||||
+ invocationContext + "}, {" + activityToken + "})");
|
||||
final Bundle resultBundle = new Bundle();
|
||||
resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION,
|
||||
@ -1086,7 +1081,7 @@ class MqttConnection implements MqttCallbackExtended {
|
||||
*
|
||||
* @param isConnecting
|
||||
*/
|
||||
synchronized void setConnectingState(boolean isConnecting){
|
||||
private synchronized void setConnectingState(boolean isConnecting){
|
||||
this.isConnecting = isConnecting;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.eclipse.paho.android.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@ -28,10 +27,8 @@ import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.eclipse.paho.client.mqttv3.MqttPersistenceException;
|
||||
import org.eclipse.paho.client.mqttv3.MqttSecurityException;
|
||||
import org.eclipse.paho.client.mqttv3.internal.DisconnectedMessageBuffer;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManager.RunningTaskInfo;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
@ -45,7 +42,6 @@ import android.os.IBinder;
|
||||
import android.os.PowerManager;
|
||||
import android.os.PowerManager.WakeLock;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -225,6 +221,7 @@ import android.util.Log;
|
||||
* </table >
|
||||
* </p>
|
||||
*/
|
||||
@SuppressLint("Registered")
|
||||
public class MqttService extends Service implements MqttTraceHandler {
|
||||
|
||||
// Identifier for Intents, log messages, etc..
|
||||
@ -254,7 +251,7 @@ public class MqttService extends Service implements MqttTraceHandler {
|
||||
private MqttServiceBinder mqttServiceBinder;
|
||||
|
||||
// mapping from client handle strings to actual client connections.
|
||||
private Map<String/* clientHandle */, MqttConnection/* client */> connections = new ConcurrentHashMap<String, MqttConnection>();
|
||||
private Map<String/* clientHandle */, MqttConnection/* client */> connections = new ConcurrentHashMap<>();
|
||||
|
||||
public MqttService() {
|
||||
super();
|
||||
@ -327,7 +324,7 @@ public class MqttService extends Service implements MqttTraceHandler {
|
||||
String invocationContext, String activityToken)
|
||||
throws MqttSecurityException, MqttException {
|
||||
MqttConnection client = getConnection(clientHandle);
|
||||
client.connect(connectOptions, invocationContext, activityToken);
|
||||
client.connect(connectOptions, null, activityToken);
|
||||
|
||||
}
|
||||
|
||||
@ -838,6 +835,7 @@ public class MqttService extends Service implements MqttTraceHandler {
|
||||
public boolean isOnline() {
|
||||
ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
|
||||
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
|
||||
//noinspection RedundantIfStatement
|
||||
if (networkInfo != null
|
||||
&& networkInfo.isAvailable()
|
||||
&& networkInfo.isConnected()
|
||||
@ -851,7 +849,7 @@ public class MqttService extends Service implements MqttTraceHandler {
|
||||
/**
|
||||
* Notify clients we're offline
|
||||
*/
|
||||
public void notifyClientsOffline() {
|
||||
private void notifyClientsOffline() {
|
||||
for (MqttConnection connection : connections.values()) {
|
||||
connection.offline();
|
||||
}
|
||||
|
@ -22,78 +22,78 @@ interface MqttServiceConstants {
|
||||
* Version information
|
||||
*/
|
||||
|
||||
static final String VERSION = "v0";
|
||||
String VERSION = "v0";
|
||||
|
||||
/*
|
||||
* Attributes of messages <p> Used for the column names in the database
|
||||
*/
|
||||
static final String DUPLICATE = "duplicate";
|
||||
static final String RETAINED = "retained";
|
||||
static final String QOS = "qos";
|
||||
static final String PAYLOAD = "payload";
|
||||
static final String DESTINATION_NAME = "destinationName";
|
||||
static final String CLIENT_HANDLE = "clientHandle";
|
||||
static final String MESSAGE_ID = "messageId";
|
||||
String DUPLICATE = "duplicate";
|
||||
String RETAINED = "retained";
|
||||
String QOS = "qos";
|
||||
String PAYLOAD = "payload";
|
||||
String DESTINATION_NAME = "destinationName";
|
||||
String CLIENT_HANDLE = "clientHandle";
|
||||
String MESSAGE_ID = "messageId";
|
||||
|
||||
/* Tags for actions passed between the Activity and the Service */
|
||||
static final String SEND_ACTION = "send";
|
||||
static final String UNSUBSCRIBE_ACTION = "unsubscribe";
|
||||
static final String SUBSCRIBE_ACTION = "subscribe";
|
||||
static final String DISCONNECT_ACTION = "disconnect";
|
||||
static final String CONNECT_ACTION = "connect";
|
||||
static final String CONNECT_EXTENDED_ACTION = "connectExtended";
|
||||
static final String MESSAGE_ARRIVED_ACTION = "messageArrived";
|
||||
static final String MESSAGE_DELIVERED_ACTION = "messageDelivered";
|
||||
static final String ON_CONNECTION_LOST_ACTION = "onConnectionLost";
|
||||
static final String TRACE_ACTION = "trace";
|
||||
String SEND_ACTION = "send";
|
||||
String UNSUBSCRIBE_ACTION = "unsubscribe";
|
||||
String SUBSCRIBE_ACTION = "subscribe";
|
||||
String DISCONNECT_ACTION = "disconnect";
|
||||
String CONNECT_ACTION = "connect";
|
||||
String CONNECT_EXTENDED_ACTION = "connectExtended";
|
||||
String MESSAGE_ARRIVED_ACTION = "messageArrived";
|
||||
String MESSAGE_DELIVERED_ACTION = "messageDelivered";
|
||||
String ON_CONNECTION_LOST_ACTION = "onConnectionLost";
|
||||
String TRACE_ACTION = "trace";
|
||||
|
||||
/* Identifies an Intent which calls back to the Activity */
|
||||
static final String CALLBACK_TO_ACTIVITY = MqttService.TAG
|
||||
String CALLBACK_TO_ACTIVITY = MqttService.TAG
|
||||
+ ".callbackToActivity"+"."+VERSION;
|
||||
|
||||
/* Identifiers for extra data on Intents broadcast to the Activity */
|
||||
static final String CALLBACK_ACTION = MqttService.TAG + ".callbackAction";
|
||||
static final String CALLBACK_STATUS = MqttService.TAG + ".callbackStatus";
|
||||
static final String CALLBACK_CLIENT_HANDLE = MqttService.TAG + "."
|
||||
String CALLBACK_ACTION = MqttService.TAG + ".callbackAction";
|
||||
String CALLBACK_STATUS = MqttService.TAG + ".callbackStatus";
|
||||
String CALLBACK_CLIENT_HANDLE = MqttService.TAG + "."
|
||||
+ CLIENT_HANDLE;
|
||||
static final String CALLBACK_ERROR_MESSAGE = MqttService.TAG
|
||||
String CALLBACK_ERROR_MESSAGE = MqttService.TAG
|
||||
+ ".errorMessage";
|
||||
static final String CALLBACK_EXCEPTION_STACK = MqttService.TAG
|
||||
String CALLBACK_EXCEPTION_STACK = MqttService.TAG
|
||||
+ ".exceptionStack";
|
||||
static final String CALLBACK_INVOCATION_CONTEXT = MqttService.TAG + "."
|
||||
String CALLBACK_INVOCATION_CONTEXT = MqttService.TAG + "."
|
||||
+ "invocationContext";
|
||||
static final String CALLBACK_ACTIVITY_TOKEN = MqttService.TAG + "."
|
||||
String CALLBACK_ACTIVITY_TOKEN = MqttService.TAG + "."
|
||||
+ "activityToken";
|
||||
static final String CALLBACK_DESTINATION_NAME = MqttService.TAG + '.'
|
||||
String CALLBACK_DESTINATION_NAME = MqttService.TAG + '.'
|
||||
+ DESTINATION_NAME;
|
||||
static final String CALLBACK_MESSAGE_ID = MqttService.TAG + '.'
|
||||
String CALLBACK_MESSAGE_ID = MqttService.TAG + '.'
|
||||
+ MESSAGE_ID;
|
||||
static final String CALLBACK_RECONNECT = MqttService.TAG + ".reconnect";
|
||||
static final String CALLBACK_SERVER_URI = MqttService.TAG + ".serverURI";
|
||||
static final String CALLBACK_MESSAGE_PARCEL = MqttService.TAG + ".PARCEL";
|
||||
static final String CALLBACK_TRACE_SEVERITY = MqttService.TAG
|
||||
String CALLBACK_RECONNECT = MqttService.TAG + ".reconnect";
|
||||
String CALLBACK_SERVER_URI = MqttService.TAG + ".serverURI";
|
||||
String CALLBACK_MESSAGE_PARCEL = MqttService.TAG + ".PARCEL";
|
||||
String CALLBACK_TRACE_SEVERITY = MqttService.TAG
|
||||
+ ".traceSeverity";
|
||||
static final String CALLBACK_TRACE_TAG = MqttService.TAG + ".traceTag";
|
||||
static final String CALLBACK_TRACE_ID = MqttService.TAG + ".traceId";
|
||||
static final String CALLBACK_ERROR_NUMBER = MqttService.TAG
|
||||
String CALLBACK_TRACE_TAG = MqttService.TAG + ".traceTag";
|
||||
String CALLBACK_TRACE_ID = MqttService.TAG + ".traceId";
|
||||
String CALLBACK_ERROR_NUMBER = MqttService.TAG
|
||||
+ ".ERROR_NUMBER";
|
||||
|
||||
static final String CALLBACK_EXCEPTION = MqttService.TAG + ".exception";
|
||||
String CALLBACK_EXCEPTION = MqttService.TAG + ".exception";
|
||||
|
||||
//Intent prefix for Ping sender.
|
||||
static final String PING_SENDER = MqttService.TAG + ".pingSender.";
|
||||
String PING_SENDER = MqttService.TAG + ".pingSender.";
|
||||
|
||||
//Constant for wakelock
|
||||
static final String PING_WAKELOCK = MqttService.TAG + ".client.";
|
||||
static final String WAKELOCK_NETWORK_INTENT = MqttService.TAG + "";
|
||||
String PING_WAKELOCK = MqttService.TAG + ".client.";
|
||||
String WAKELOCK_NETWORK_INTENT = MqttService.TAG + "";
|
||||
|
||||
//Trace severity levels
|
||||
static final String TRACE_ERROR = "error";
|
||||
static final String TRACE_DEBUG = "debug";
|
||||
static final String TRACE_EXCEPTION = "exception";
|
||||
String TRACE_ERROR = "error";
|
||||
String TRACE_DEBUG = "debug";
|
||||
String TRACE_EXCEPTION = "exception";
|
||||
|
||||
|
||||
//exception code for non MqttExceptions
|
||||
static final int NON_MQTT_EXCEPTION = -1;
|
||||
int NON_MQTT_EXCEPTION = -1;
|
||||
|
||||
}
|
@ -54,7 +54,7 @@ class MqttTokenAndroid implements IMqttToken {
|
||||
*/
|
||||
MqttTokenAndroid(MqttAndroidClient client,
|
||||
Object userContext, IMqttActionListener listener) {
|
||||
this(client, userContext, listener, (String[]) null);
|
||||
this(client, userContext, listener, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,7 +28,7 @@ public interface MqttTraceHandler {
|
||||
* @param message
|
||||
* the text to be traced
|
||||
*/
|
||||
public abstract void traceDebug(String source, String message);
|
||||
void traceDebug(String source, String message);
|
||||
|
||||
/**
|
||||
* Trace error information
|
||||
@ -38,7 +38,7 @@ public interface MqttTraceHandler {
|
||||
* @param message
|
||||
* the text to be traced
|
||||
*/
|
||||
public abstract void traceError(String source, String message);
|
||||
void traceError(String source, String message);
|
||||
|
||||
/**
|
||||
* trace exceptions
|
||||
@ -50,7 +50,7 @@ public interface MqttTraceHandler {
|
||||
* @param e
|
||||
* the exception
|
||||
*/
|
||||
public abstract void traceException(String source, String message,
|
||||
Exception e);
|
||||
void traceException(String source, String message,
|
||||
Exception e);
|
||||
|
||||
}
|
Before Width: | Height: | Size: 3.3 KiB |
Before Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 7.5 KiB |
@ -1,5 +1,5 @@
|
||||
<resources>
|
||||
|
||||
<string name="app_name">Android Service</string>
|
||||
|
||||
|
||||
</resources>
|
||||
|