]> hydra-www.ietfng.org Git - acmetensortoys-ctfws-android/commitdiff
MainService MQTT: unsubscribe only if connected
authorNathaniel Wesley Filardo <nwfilardo@gmail.com>
Tue, 1 Mar 2022 18:49:32 +0000 (18:49 +0000)
committerNathaniel Wesley Filardo <nwfilardo@gmail.com>
Tue, 1 Mar 2022 18:50:25 +0000 (18:50 +0000)
Otherwise we might throw a NPE from inside Paho

mobile/src/main/java/com/acmetensortoys/ctfwstimer/service/MainService.java

index 0c4707d1a6ce94aae1d3290e5c47ff17f7030e09..f27e96b6b1241b7869197b98972c7334d94556c7 100644 (file)
@@ -215,7 +215,7 @@ public class MainService extends Service {
 
         // Hang up on an existing connection, if we have one
         setMSE(MqttServerEvent.MSE_DISCONN);
-        if (mMqc != null) {
+        if ((mMqc != null) && mMqc.isConnected()) {
             mMqc.setCallback(null);
 
             // Observationally, it looks like .close() below isn't enough!  Deliberately
@@ -248,8 +248,12 @@ public class MainService extends Service {
             }
             mMqc.unregisterResources();
             mMqc = null;
-        } else {
+        } else if (mMqc == null) {
             Log.d("Service", "domqtt no client");
+        } else {
+            Log.d("Service", "domqtt client but not connected");
+            mMqc.unregisterResources();
+            mMqc = null;
         }
 
         // At this point, prevent the client we just shot down from making any further changes