diff options
author | Jack He <siyuanh@google.com> | 2021-07-31 02:17:36 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-07-31 02:17:36 +0000 |
commit | 9d32443bbe01836a36b31d12fa9efd0711cbd68c (patch) | |
tree | 092607a1645af336d7b2f26e37547a3fbb6fbbea | |
parent | bb25aa658032d9ce6fb4f1edba46b47595df0ce4 (diff) | |
parent | 5666c0d4fe4785bc3049b660cdb167be29fc46e3 (diff) |
Merge "Broadcast Bluetooth state to OFF properly" into sc-dev am: cd9340419a
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15433382
Change-Id: Ibb2e2cddaf17c84c0d2e0a654448daf09815e849
-rw-r--r-- | service/java/com/android/server/bluetooth/BluetoothManagerService.java | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/service/java/com/android/server/bluetooth/BluetoothManagerService.java b/service/java/com/android/server/bluetooth/BluetoothManagerService.java index b4912bbc89..31061190b3 100644 --- a/service/java/com/android/server/bluetooth/BluetoothManagerService.java +++ b/service/java/com/android/server/bluetooth/BluetoothManagerService.java @@ -2509,6 +2509,16 @@ class BluetoothManagerService extends IBluetoothManager.Stub { mContext.sendBroadcastAsUser(intent, UserHandle.ALL, null, getTempAllowlistBroadcastOptions()); } + private boolean isBleState(int state) { + switch (state) { + case BluetoothAdapter.STATE_BLE_ON: + case BluetoothAdapter.STATE_BLE_TURNING_ON: + case BluetoothAdapter.STATE_BLE_TURNING_OFF: + return true; + } + return false; + } + @RequiresPermission(allOf = { android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED, @@ -2531,8 +2541,15 @@ class BluetoothManagerService extends IBluetoothManager.Stub { sendBluetoothServiceDownCallback(); unbindAndFinish(); sendBleStateChanged(prevState, newState); - // Don't broadcast as it has already been broadcast before - isStandardBroadcast = false; + + /* Currently, the OFF intent is broadcasted externally only when we transition + * from TURNING_OFF to BLE_ON state. So if the previous state is a BLE state, + * we are guaranteed that the OFF intent has been broadcasted earlier and we + * can safely skip it. + * Conversely, if the previous state is not a BLE state, it indicates that some + * sort of crash has occurred, moving us directly to STATE_OFF without ever + * passing through BLE_ON. We should broadcast the OFF intent in this case. */ + isStandardBroadcast = !isBleState(prevState); } else if (!intermediate_off) { // connect to GattService @@ -2585,6 +2602,11 @@ class BluetoothManagerService extends IBluetoothManager.Stub { // Show prevState of BLE_ON as OFF to standard users prevState = BluetoothAdapter.STATE_OFF; } + if (DBG) { + Slog.d(TAG, + "Sending State Change: " + BluetoothAdapter.nameForState(prevState) + " > " + + BluetoothAdapter.nameForState(newState)); + } Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED); intent.putExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE, prevState); intent.putExtra(BluetoothAdapter.EXTRA_STATE, newState); |