mirror of
https://github.com/AU-COVIDSafe/mobile-android.git
synced 2025-01-18 16:56:34 +00:00
Testing a proof-of-concept fix for the duplicate GATT service issue.
- In ConcreteBLETransmitter.kt, make sure services are cleard and GATT server closed (if it exists) - In BluetoothMonitoringService.kt, make sure no duplicate SensorArray objects are created. DISCLAIMER: This modification is meant to demonstrate a diagnosis of the root cause of the issue; it is not meant as a definitive fix.
This commit is contained in:
parent
2ef00979e5
commit
222fa4f295
2 changed files with 29 additions and 7 deletions
|
@ -81,10 +81,20 @@ class ConcreteBLETransmitter(
|
|||
override fun bleTimer(now: Long) {
|
||||
if (!isSupported || bluetoothStateManager.state() == BluetoothState.poweredOff) {
|
||||
if (advertLoopState != AdvertLoopState.stopped) {
|
||||
// [AT] Clear services and close GATT server, if it exists
|
||||
try {
|
||||
if (bluetoothGattServer != null) {
|
||||
logger.debug("[AT] bleTimer, non-null gatt server, stopping GATT server")
|
||||
bluetoothGattServer!!.clearServices()
|
||||
bluetoothGattServer!!.close()
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
logger.fault("[AT] bleTimer, failed to stop GATT server", e)
|
||||
}
|
||||
advertiseCallback = null
|
||||
bluetoothGattServer = null
|
||||
state(now, AdvertLoopState.stopped)
|
||||
logger.debug("advertLoopTask, stop advert (advert={}ms)", timeSincelastStateChange(now))
|
||||
logger.debug("[AT] advertLoopTask, BluetoothState.powerdOff, stop advert (advert={}ms)", timeSincelastStateChange(now))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import android.content.IntentFilter
|
|||
import android.location.LocationManager
|
||||
import android.os.Build
|
||||
import android.os.PowerManager
|
||||
import android.util.Log
|
||||
import androidx.annotation.Keep
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.LifecycleService
|
||||
|
@ -93,12 +94,16 @@ class BluetoothMonitoringService : LifecycleService(), CoroutineScope, SensorDel
|
|||
}
|
||||
|
||||
fun teardown() {
|
||||
commandHandler.removeCallbacksAndMessages(null)
|
||||
//commandHandler.removeCallbacksAndMessages(null)
|
||||
|
||||
Utils.cancelBMUpdateCheck(this.applicationContext)
|
||||
Utils.cancelNextScan(this.applicationContext)
|
||||
Utils.cancelNextAdvertise(this.applicationContext)
|
||||
sensor?.stop()
|
||||
//Utils.cancelBMUpdateCheck(this.applicationContext)
|
||||
//Utils.cancelNextScan(this.applicationContext)
|
||||
//Utils.cancelNextAdvertise(this.applicationContext)
|
||||
|
||||
//[AT]
|
||||
Log.i(TAG, "[AT] teardown, do nothing")
|
||||
|
||||
//sensor?.stop()
|
||||
}
|
||||
|
||||
private fun setupNotifications() {
|
||||
|
@ -263,8 +268,15 @@ class BluetoothMonitoringService : LifecycleService(), CoroutineScope, SensorDel
|
|||
}
|
||||
|
||||
fun sensorStart() {
|
||||
if (broadcastMessage != null) {
|
||||
// [AT] Don't create a new sensor, to avoid creating multiple advertisements/duplicate GATT services
|
||||
Log.i(TAG, "[AT] sensorStart")
|
||||
|
||||
if (broadcastMessage != null && sensor == null) {
|
||||
|
||||
streetPassRecordStorage = StreetPassRecordStorage(applicationContext)
|
||||
|
||||
Log.i(TAG, "[AT] creating a new SensorArray")
|
||||
|
||||
sensor = SensorArray(applicationContext, this)
|
||||
getAppDelegate().sensor()?.add(this)
|
||||
// Sensor will start and stop with Bluetooth power on / off events
|
||||
|
|
Loading…
Reference in a new issue