From 25ceaa63646842d3c8a9b1ff1c93956e5b546643 Mon Sep 17 00:00:00 2001 From: geeksville Date: Sat, 18 Jul 2020 13:18:38 -0700 Subject: [PATCH] Fix autobugs related to Samsung BLE --- .../geeksville/mesh/service/SafeBluetooth.kt | 49 ++++++++++--------- app/src/main/res/values/strings.xml | 1 + 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/service/SafeBluetooth.kt b/app/src/main/java/com/geeksville/mesh/service/SafeBluetooth.kt index 4306ea3a8..f3330844d 100644 --- a/app/src/main/java/com/geeksville/mesh/service/SafeBluetooth.kt +++ b/app/src/main/java/com/geeksville/mesh/service/SafeBluetooth.kt @@ -609,7 +609,7 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD private fun queueDiscoverServices(cont: Continuation) { queueWork("discover", cont) { - gatt!!.discoverServices() + gatt?.discoverServices() ?: throw BLEException("GATT is null") } } @@ -742,6 +742,10 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD null // clear gat before calling close, bcause close might throw dead object exception g2.close() } + } catch (ex: NullPointerException) { + // Attempt to invoke virtual method 'com.android.bluetooth.gatt.AdvertiseClient com.android.bluetooth.gatt.AdvertiseManager.getAdvertiseClient(int)' on a null object reference + //com.geeksville.mesh.service.SafeBluetooth.closeGatt + warn("Ignoring NPE in close - probably buggy Samsung BLE") } catch (ex: DeadObjectException) { warn("Ignoring dead object exception, probably bluetooth was just disabled") } finally { @@ -789,28 +793,28 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD gatt!!.setCharacteristicNotification(c, enable) /* - c is null sometimes + c is null sometimes 2020-04-13 15:59:38.222 2111-2182/com.geeksville.mesh D/BluetoothGatt: setCharacteristicNotification() - uuid: ed9da18c-a800-4f66-a670-aa7547e34453 enable: true 2020-04-13 15:59:38.225 2111-2182/com.geeksville.mesh E/com.geeksville.util.Exceptions: exceptionReporter Uncaught Exception - kotlin.KotlinNullPointerException - at com.geeksville.mesh.service.SafeBluetooth.setNotify(SafeBluetooth.kt:505) - at com.geeksville.mesh.service.RadioInterfaceService$onConnect$1$1.invoke(RadioInterfaceService.kt:328) - at com.geeksville.mesh.service.RadioInterfaceService$onConnect$1$1.invoke(RadioInterfaceService.kt:90) - at com.geeksville.concurrent.CallbackContinuation.resume(SyncContinuation.kt:20) - at com.geeksville.mesh.service.SafeBluetooth$completeWork$1.invoke(SafeBluetooth.kt:329) - at com.geeksville.mesh.service.SafeBluetooth$completeWork$1.invoke(SafeBluetooth.kt:33) - at com.geeksville.util.ExceptionsKt.exceptionReporter(Exceptions.kt:34) - at com.geeksville.mesh.service.SafeBluetooth.completeWork(SafeBluetooth.kt:312) - at com.geeksville.mesh.service.SafeBluetooth.access$completeWork(SafeBluetooth.kt:33) - at com.geeksville.mesh.service.SafeBluetooth$gattCallback$1.onMtuChanged(SafeBluetooth.kt:221) - at android.bluetooth.BluetoothGatt$1$13.run(BluetoothGatt.java:658) - at android.bluetooth.BluetoothGatt.runOrQueueCallback(BluetoothGatt.java:780) - at android.bluetooth.BluetoothGatt.access$200(BluetoothGatt.java:41) - at android.bluetooth.BluetoothGatt$1.onConfigureMTU(BluetoothGatt.java:653) - at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:330) - at android.os.Binder.execTransactInternal(Binder.java:1021) - at android.os.Binder.execTransact(Binder.java:994) - */ +kotlin.KotlinNullPointerException + at com.geeksville.mesh.service.SafeBluetooth.setNotify(SafeBluetooth.kt:505) + at com.geeksville.mesh.service.RadioInterfaceService$onConnect$1$1.invoke(RadioInterfaceService.kt:328) + at com.geeksville.mesh.service.RadioInterfaceService$onConnect$1$1.invoke(RadioInterfaceService.kt:90) + at com.geeksville.concurrent.CallbackContinuation.resume(SyncContinuation.kt:20) + at com.geeksville.mesh.service.SafeBluetooth$completeWork$1.invoke(SafeBluetooth.kt:329) + at com.geeksville.mesh.service.SafeBluetooth$completeWork$1.invoke(SafeBluetooth.kt:33) + at com.geeksville.util.ExceptionsKt.exceptionReporter(Exceptions.kt:34) + at com.geeksville.mesh.service.SafeBluetooth.completeWork(SafeBluetooth.kt:312) + at com.geeksville.mesh.service.SafeBluetooth.access$completeWork(SafeBluetooth.kt:33) + at com.geeksville.mesh.service.SafeBluetooth$gattCallback$1.onMtuChanged(SafeBluetooth.kt:221) + at android.bluetooth.BluetoothGatt$1$13.run(BluetoothGatt.java:658) + at android.bluetooth.BluetoothGatt.runOrQueueCallback(BluetoothGatt.java:780) + at android.bluetooth.BluetoothGatt.access$200(BluetoothGatt.java:41) + at android.bluetooth.BluetoothGatt$1.onConfigureMTU(BluetoothGatt.java:653) + at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:330) + at android.os.Binder.execTransactInternal(Binder.java:1021) + at android.os.Binder.execTransact(Binder.java:994) + */ // per https://stackoverflow.com/questions/27068673/subscribe-to-a-ble-gatt-notification-android val descriptor: BluetoothGattDescriptor = c.getDescriptor(configurationDescriptorUUID) ?: throw BLEException("Notify descriptor not found for ${c.uuid}") // This can happen on buggy BLE implementations @@ -820,5 +824,4 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD debug("Notify enable=$enable completed") } } -} - +} \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1763a2332..5aeaa8f33 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -73,4 +73,5 @@ About A list of nodes in the mesh Text messages + This Channel URL is invalid and can not be used