From 5d9648f6021ba2cee0b1bc1f0a6f1f506b76a429 Mon Sep 17 00:00:00 2001 From: geeksville Date: Tue, 9 Jun 2020 18:46:23 -0700 Subject: [PATCH] fix autobug in case device goes away at a bad time --- .../main/java/com/geeksville/mesh/MainActivity.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/MainActivity.kt b/app/src/main/java/com/geeksville/mesh/MainActivity.kt index dbc24651f..518310272 100644 --- a/app/src/main/java/com/geeksville/mesh/MainActivity.kt +++ b/app/src/main/java/com/geeksville/mesh/MainActivity.kt @@ -18,6 +18,7 @@ import android.hardware.usb.UsbManager import android.net.Uri import android.os.Build import android.os.Bundle +import android.os.RemoteException import android.view.Menu import android.view.MenuItem import android.view.MotionEvent @@ -695,8 +696,15 @@ class MainActivity : AppCompatActivity(), Logging, if (connectionState != MeshService.ConnectionState.CONNECTED) updateNodesFromDevice() - // We won't receive a notify for the initial state of connection, so we force an update here - onMeshConnectionChanged(connectionState) + try { + // We won't receive a notify for the initial state of connection, so we force an update here + onMeshConnectionChanged(connectionState) + } catch (ex: RemoteException) { + // If we get an exception while reading our service config, the device might have gone away, double check to see if we are really connected + errormsg("Device error during init ${ex.message}") + model.isConnected.value = + MeshService.ConnectionState.valueOf(service.connectionState()) + } debug("connected to mesh service, isConnected=${model.isConnected.value}") }