From 92b3fa8d1f1f53358e6854d7d8365ef35195d142 Mon Sep 17 00:00:00 2001 From: geeksville Date: Sat, 4 Jul 2020 11:17:11 -0700 Subject: [PATCH] bug #76 - old sonys can take a VERY long time for the setMTU operation to complete. Change timeout to 10 secs (units in the field were showing the mtu operation completing after 5 seconds. Also - don't throw an exception if we encounter a result when we've already killed things with the failsafe timer --- .../geeksville/mesh/service/SafeBluetooth.kt | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 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 ee817b0e2..411956758 100644 --- a/app/src/main/java/com/geeksville/mesh/service/SafeBluetooth.kt +++ b/app/src/main/java/com/geeksville/mesh/service/SafeBluetooth.kt @@ -392,25 +392,30 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD // startup next job in queue before calling the completion handler val work = synchronized(workQueue) { - val w = - currentWork - ?: throw Exception("currentWork was null") // will throw if null, which is helpful (FIXME - throws in the field - because of a bogus mtu completion gatt call) - stopCurrentWork() // We are now no longer working on anything + val w = currentWork - startNewWork() + if (w != null) { + stopCurrentWork() // We are now no longer working on anything + + startNewWork() + } w } - debug("work ${work.tag} is completed, resuming status=$status, res=$res") - if (status != 0) - work.completion.resumeWithException( - BLEStatusException( - status, - "Bluetooth status=$status while doing ${work.tag}" + if (work == null) + warn("wor completed, but we already killed it via failsafetimer? status=$status, res=$res") + else { + debug("work ${work.tag} is completed, resuming status=$status, res=$res") + if (status != 0) + work.completion.resumeWithException( + BLEStatusException( + status, + "Bluetooth status=$status while doing ${work.tag}" + ) ) - ) - else - work.completion.resume(Result.success(res) as Result) + else + work.completion.resume(Result.success(res) as Result) + } } } @@ -607,7 +612,7 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD private fun queueRequestMtu( len: Int, cont: Continuation - ) = queueWork("reqMtu", cont, 5 * 1000) { + ) = queueWork("reqMtu", cont, 10 * 1000) { isSettingMtu = true gatt?.requestMtu(len) ?: false }