diff options
author | Joner Lin <jonerlin@google.com> | 2022-03-23 05:53:08 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2022-03-23 05:53:08 +0000 |
commit | bd01f52b72c98140e68c9238022525211f620465 (patch) | |
tree | 17444e1a744f9904817b30e1383053d629d3a819 /service/java/com/android/server/bluetooth/BluetoothManagerService.java | |
parent | d2bedfe2ac9e567e4c1e3577f5cafbf7e19ba0b5 (diff) | |
parent | 5b5bd513f78b5183007010ed9373ab18bfc963a4 (diff) |
Merge changes from topic "Handle Shutdown Intent"
* changes:
Do not allow Bluetooth enabling during device shutting down
Handle SHUTDOWN Intent in BluetoothManagerService
Diffstat (limited to 'service/java/com/android/server/bluetooth/BluetoothManagerService.java')
-rw-r--r-- | service/java/com/android/server/bluetooth/BluetoothManagerService.java | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/service/java/com/android/server/bluetooth/BluetoothManagerService.java b/service/java/com/android/server/bluetooth/BluetoothManagerService.java index d6052aae95..bd6dfc984f 100644 --- a/service/java/com/android/server/bluetooth/BluetoothManagerService.java +++ b/service/java/com/android/server/bluetooth/BluetoothManagerService.java @@ -217,6 +217,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub { // used inside handler thread private boolean mQuietEnable = false; private boolean mEnable; + private boolean mShutdownInProgress = false; private static CharSequence timeToLog(long timestamp) { return android.text.format.DateFormat.format("MM-dd HH:mm:ss", timestamp); @@ -477,6 +478,23 @@ class BluetoothManagerService extends IBluetoothManager.Stub { Slog.i(TAG, "Device disconnected, reactivating pending flag changes"); onInitFlagsChanged(); } + } else if (action.equals(Intent.ACTION_SHUTDOWN)) { + Slog.i(TAG, "Device is shutting down."); + mShutdownInProgress = true; + mBluetoothLock.readLock().lock(); + try { + mEnable = false; + mEnableExternal = false; + if (mBluetooth != null && (mState == BluetoothAdapter.STATE_BLE_ON)) { + synchronousOnBrEdrDown(mContext.getAttributionSource()); + } else if (mBluetooth != null && (mState == BluetoothAdapter.STATE_ON)) { + synchronousDisable(mContext.getAttributionSource()); + } + } catch (RemoteException | TimeoutException e) { + Slog.e(TAG, "Unable to shutdown Bluetooth", e); + } finally { + mBluetoothLock.readLock().unlock(); + } } } }; @@ -536,6 +554,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub { filter.addAction(Intent.ACTION_SETTING_RESTORED); filter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED); + filter.addAction(Intent.ACTION_SHUTDOWN); filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); mContext.registerReceiver(mReceiver, filter); @@ -1944,6 +1963,11 @@ class BluetoothManagerService extends IBluetoothManager.Stub { case MESSAGE_ENABLE: int quietEnable = msg.arg1; int isBle = msg.arg2; + if (mShutdownInProgress) { + Slog.i(TAG, "Skip Bluetooth Enable in device shutdown process"); + break; + } + if (mHandler.hasMessages(MESSAGE_HANDLE_DISABLE_DELAYED) || mHandler.hasMessages(MESSAGE_HANDLE_ENABLE_DELAYED)) { // We are handling enable or disable right now, wait for it. |