0.7.0 my robotester script found a bug in my previous change!

properly map bluetooth addresses to the new transport independent address
pull/40/head
geeksville 2020-06-07 20:17:47 -07:00
rodzic 5bab88790b
commit 6a71e6c414
5 zmienionych plików z 28 dodań i 23 usunięć

Wyświetl plik

@ -17,8 +17,8 @@ android {
applicationId "com.geeksville.mesh"
minSdkVersion 22 // The oldest emulator image I have tried is 22 (though 21 probably works)
targetSdkVersion 29
versionCode 169
versionName "0.6.9"
versionCode 170
versionName "0.7.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {

Wyświetl plik

@ -470,7 +470,7 @@ class MainActivity : AppCompatActivity(), Logging,
// ... Continue interacting with the paired device.
model.meshService?.let { service ->
service.setDeviceAddress(device.address)
MeshService.changeDeviceAddress(this@MainActivity, service, device.address)
}
}

Wyświetl plik

@ -80,6 +80,15 @@ class MeshService : Service(), Logging {
}
}
/**
* Talk to our running service and try to set a new device address. And then immediately
* call start on the service to possibly promote our service to be a foreground service.
*/
fun changeDeviceAddress(context: Context, service: IMeshService, address: String?) {
service.setDeviceAddress(address)
startService(context)
}
/**
* Just after boot the android OS is super busy, so if we call startForegroundService then, our
* thread might be stalled long enough to expose this google/samsung bug:
@ -87,8 +96,6 @@ class MeshService : Service(), Logging {
*/
fun startLater(context: Context) {
// No point in even starting the service if the user doesn't have a device bonded
if (RadioInterfaceService.getBondedDeviceAddress(context) != null) {
info("Received boot complete announcement, starting mesh service in one minute")
val delayRequest = OneTimeWorkRequestBuilder<ServiceStarter>()
.setInitialDelay(1, TimeUnit.MINUTES)
@ -97,9 +104,6 @@ class MeshService : Service(), Logging {
.build()
WorkManager.getInstance(context).enqueue(delayRequest)
} else {
debug("Booted: but not starting mesh service - we are unbonded")
}
}
val intent = Intent().apply {
@ -1458,7 +1462,6 @@ class MeshService : Service(), Logging {
debug("Passing through device change to radio service: $deviceAddr")
discardNodeDB()
radio.service.setDeviceAddress(deviceAddr)
startForeground() // We might need to become foreground or background at this point
}
// Note: bound methods don't get properly exception caught/logged, so do that with a wrapper

Wyświetl plik

@ -190,7 +190,10 @@ class RadioInterfaceService : Service(), Logging {
'x' -> BluetoothInterface(this, rest)
's' -> SerialInterface(this, rest)
'n' -> nopIf
else -> TODO("Unexpected radio interface type")
else -> {
errormsg("Unexpected radio interface type")
nopIf
}
}
}
}

Wyświetl plik

@ -48,7 +48,7 @@ object SLogging : Logging {}
fun changeDeviceSelection(context: MainActivity, newAddr: String?) {
// FIXME, this is a kinda yucky way to find the service
context.model.meshService?.let { service ->
service.setDeviceAddress(newAddr)
MeshService.changeDeviceAddress(context, service, newAddr)
}
}
@ -165,7 +165,7 @@ class BTScanModel(app: Application) : AndroidViewModel(app), Logging {
if (selectedAddress == null && entry.bonded)
changeScanSelection(
GeeksvilleApplication.currentActivity as MainActivity,
addr
fullAddr
)
addDevice(entry) // Add/replace entry
}
@ -287,7 +287,7 @@ class BTScanModel(app: Application) : AndroidViewModel(app), Logging {
errorText.value = activity.getString(R.string.pairing_completed)
changeScanSelection(
activity,
device.address
it.address
)
} else {
errorText.value = activity.getString(R.string.pairing_failed_try_again)
@ -514,14 +514,13 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
// The device the user is already paired with is offline currently, still show it
// it in the list, but greyed out
val selectedAddr = scanModel.selectedAddress
if (!hasShownOurDevice && selectedAddr != null) {
if (!hasShownOurDevice && scanModel.selectedBluetooth != null) {
val bDevice =
scanModel.bluetoothAdapter!!.getRemoteDevice(scanModel.selectedBluetooth)
if (bDevice.name != null) { // ignore nodes that node have a name, that means we've lost them since they appeared
val curDevice = BTScanModel.DeviceListEntry(
bDevice.name,
selectedAddr,
scanModel.selectedAddress!!,
bDevice.bondState == BOND_BONDED
)
addDeviceButton(curDevice, false)