Merge pull request #49 from geeksville/dev

Dev
This commit is contained in:
Kevin Hester 2020-06-15 07:14:20 -07:00 committed by GitHub
commit 762d23069b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 8 deletions

View file

@ -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 10775 // format is Mmmss (where M is 1+the numeric major number
versionName "0.7.75"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {

View file

@ -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)

View file

@ -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)
}
}

View file

@ -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")
}
}
}

View file

@ -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")