Merge changes from topic "Handle_Shutdown_Intent_sc-v2" into sc-v2-dev

* changes:
  [DO NOT MERGE] Do not allow Bluetooth enabling during device shutting down
  [DO NOT MERGE] Handle SHUTDOWN Intent in BluetoothManagerService
This commit is contained in:
TreeHugger Robot
2022-03-25 16:17:13 +00:00
committed by Android (Google) Code Review

View File

@@ -193,6 +193,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);
@@ -462,6 +463,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)) {
mBluetooth.onBrEdrDown(mContext.getAttributionSource());
} else if (mBluetooth != null && (mState == BluetoothAdapter.STATE_ON)) {
mBluetooth.disable(mContext.getAttributionSource());
}
} catch (RemoteException e) {
Slog.e(TAG, "Unable to shutdown Bluetooth", e);
} finally {
mBluetoothLock.readLock().unlock();
}
}
}
};
@@ -515,6 +533,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);
@@ -1850,6 +1869,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.