TbsGatt and MCS: unregister adapter state listener to prevent crash
Here is current flow of events when BT is disabled, while we have background scanning eneabled: MESSAGE_BLUETOOTH_STATE_CHANGE: ON > TURNING_OFF TbsService: cleanup() MESSAGE_BLUETOOTH_STATE_CHANGE: TURNING_OFF > BLE_ON And this happens when we try to enable it afterwards: MESSAGE_BLUETOOTH_STATE_CHANGE: BLE_ON > TURNING_ON MESSAGE_BLUETOOTH_STATE_CHANGE: TURNING_ON > ON TbsService: start() MESSAGE_BLUETOOTH_STATE_CHANGE: TURNING_ON > ON TbsGatt : onBluetoothStateChange: state=ON !Crash! Crash happens, because in cleanup() we don't unregister Adapter State listener, and it would be executed on old service instance. After this patch, callback is being unregistered in TbsGatt.cleanup(), and re-registered in TbsGatt.start(), with fresh instance that wouldn't cause crashes. Test: restart bluetooth while location and background scanning is on Bug: 304549080 Change-Id: Ibb08948b39f8ff1657a414234f67653b3dc12b25
Loading
Please register or sign in to comment