From e94c059acb90ac08b55fb8b0dca07cc41c8ab9c1 Mon Sep 17 00:00:00 2001 From: geeksville Date: Sun, 14 Jun 2020 16:43:21 -0700 Subject: [PATCH 1/4] 0.7.73 --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 39035cbba..d98b54c79 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -17,8 +17,8 @@ android { applicationId "com.geeksville.mesh" minSdkVersion 21 // The oldest emulator image I have tried is 22 (though 21 probably works) targetSdkVersion 29 - versionCode 10772 // format is Mmmss (where M is 1+the numeric major number - versionName "0.7.72" + versionCode 10773 // format is Mmmss (where M is 1+the numeric major number + versionName "0.7.73" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { From 7cca69be0d4c095bffe100f230d1a71aaf6c5310 Mon Sep 17 00:00:00 2001 From: geeksville Date: Sun, 14 Jun 2020 16:43:36 -0700 Subject: [PATCH 2/4] properly mark when we are disconnected --- .../mesh/service/BluetoothInterface.kt | 3 ++- .../mesh/service/RadioInterfaceService.kt | 16 ++++++++++++++-- .../geeksville/mesh/service/SerialInterface.kt | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/service/BluetoothInterface.kt b/app/src/main/java/com/geeksville/mesh/service/BluetoothInterface.kt index c52b0133d..4c79387fd 100644 --- a/app/src/main/java/com/geeksville/mesh/service/BluetoothInterface.kt +++ b/app/src/main/java/com/geeksville/mesh/service/BluetoothInterface.kt @@ -326,6 +326,7 @@ class BluetoothInterface(val service: RadioInterfaceService, val address: String ignoreException { s.closeConnection() } + service.onDisconnect(false) // assume we will fail delay(1000) // Give some nasty time for buggy BLE stacks to shutdown (500ms was not enough) reconnectJob = null // Any new reconnect requests after this will be allowed to run warn("Attempting reconnect") @@ -364,7 +365,7 @@ class BluetoothInterface(val service: RadioInterfaceService, val address: String isFirstSend = true // Now tell clients they can (finally use the api) - service.broadcastConnectionChanged(true, isPermanent = false) + service.onConnect() // Immediately broadcast any queued packets sitting on the device doReadFromRadio(true) diff --git a/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt b/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt index aed2886ca..fc79ee4aa 100644 --- a/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt @@ -135,7 +135,7 @@ class RadioInterfaceService : Service(), Logging { startInterface() // If bluetooth just got turned on, try to restart our ble link } - fun broadcastConnectionChanged(isConnected: Boolean, isPermanent: Boolean) { + private fun broadcastConnectionChanged(isConnected: Boolean, isPermanent: Boolean) { debug("Broadcasting connection=$isConnected") val intent = Intent(RADIO_CONNECTED_ACTION) intent.putExtra(EXTRA_CONNECTED, isConnected) @@ -163,8 +163,20 @@ class RadioInterfaceService : Service(), Logging { ) } + private var isConnected = false + + fun onConnect() { + if (!isConnected) { + isConnected = true + broadcastConnectionChanged(true, false) + } + } + fun onDisconnect(isPermanent: Boolean) { - broadcastConnectionChanged(false, isPermanent) + if (isConnected) { + isConnected = false + broadcastConnectionChanged(false, isPermanent) + } } diff --git a/app/src/main/java/com/geeksville/mesh/service/SerialInterface.kt b/app/src/main/java/com/geeksville/mesh/service/SerialInterface.kt index 74c2f7ec2..914708dbd 100644 --- a/app/src/main/java/com/geeksville/mesh/service/SerialInterface.kt +++ b/app/src/main/java/com/geeksville/mesh/service/SerialInterface.kt @@ -161,7 +161,7 @@ class SerialInterface(private val service: RadioInterfaceService, val address: S io.writeAsync(wakeBytes) // Now tell clients they can (finally use the api) - service.broadcastConnectionChanged(true, isPermanent = false) + service.onConnect() } } else { errormsg("Can't find device") From 44e084c99990a53636ec18dc5aa2c659464796f9 Mon Sep 17 00:00:00 2001 From: geeksville Date: Mon, 15 Jun 2020 07:09:21 -0700 Subject: [PATCH 3/4] fix dead object exception --- .../java/com/geeksville/mesh/service/SafeBluetooth.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 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 647ec4a54..f3cb6caf3 100644 --- a/app/src/main/java/com/geeksville/mesh/service/SafeBluetooth.kt +++ b/app/src/main/java/com/geeksville/mesh/service/SafeBluetooth.kt @@ -6,12 +6,14 @@ import android.content.Context import android.content.Intent import android.content.IntentFilter import android.os.Build +import android.os.DeadObjectException import android.os.Handler import com.geeksville.android.GeeksvilleApplication import com.geeksville.android.Logging import com.geeksville.concurrent.CallbackContinuation import com.geeksville.concurrent.Continuation import com.geeksville.concurrent.SyncContinuation +import com.geeksville.util.Exceptions import com.geeksville.util.exceptionReporter import com.geeksville.util.ignoreException import kotlinx.coroutines.* @@ -680,8 +682,12 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD info("Closing our GATT connection") gatt = null // Clear this first so the onConnectionChange callback can ignore while we are shutting down - g.disconnect() - g.close() + try { + g.disconnect() + g.close() + } catch (ex: DeadObjectException) { + Exceptions.report(ex, "Dead object while closing GATT") + } } } From 067fefe42a90c5f4494f9eaa13cc80d552892aea Mon Sep 17 00:00:00 2001 From: geeksville Date: Mon, 15 Jun 2020 07:09:58 -0700 Subject: [PATCH 4/4] 0.7.75 --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index d98b54c79..28e1587fc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -17,8 +17,8 @@ android { applicationId "com.geeksville.mesh" minSdkVersion 21 // The oldest emulator image I have tried is 22 (though 21 probably works) targetSdkVersion 29 - versionCode 10773 // format is Mmmss (where M is 1+the numeric major number - versionName "0.7.73" + versionCode 10775 // format is Mmmss (where M is 1+the numeric major number + versionName "0.7.75" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes {