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:
committed by
Android (Google) Code Review
commit
97e13dbd32
@@ -193,6 +193,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
// used inside handler thread
|
// used inside handler thread
|
||||||
private boolean mQuietEnable = false;
|
private boolean mQuietEnable = false;
|
||||||
private boolean mEnable;
|
private boolean mEnable;
|
||||||
|
private boolean mShutdownInProgress = false;
|
||||||
|
|
||||||
private static CharSequence timeToLog(long timestamp) {
|
private static CharSequence timeToLog(long timestamp) {
|
||||||
return android.text.format.DateFormat.format("MM-dd HH:mm:ss", 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");
|
Slog.i(TAG, "Device disconnected, reactivating pending flag changes");
|
||||||
onInitFlagsChanged();
|
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(Intent.ACTION_SETTING_RESTORED);
|
||||||
filter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
|
filter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
|
||||||
filter.addAction(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
|
filter.addAction(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
|
||||||
|
filter.addAction(Intent.ACTION_SHUTDOWN);
|
||||||
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
||||||
mContext.registerReceiver(mReceiver, filter);
|
mContext.registerReceiver(mReceiver, filter);
|
||||||
|
|
||||||
@@ -1850,6 +1869,11 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
case MESSAGE_ENABLE:
|
case MESSAGE_ENABLE:
|
||||||
int quietEnable = msg.arg1;
|
int quietEnable = msg.arg1;
|
||||||
int isBle = msg.arg2;
|
int isBle = msg.arg2;
|
||||||
|
if (mShutdownInProgress) {
|
||||||
|
Slog.i(TAG, "Skip Bluetooth Enable in device shutdown process");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (mHandler.hasMessages(MESSAGE_HANDLE_DISABLE_DELAYED)
|
if (mHandler.hasMessages(MESSAGE_HANDLE_DISABLE_DELAYED)
|
||||||
|| mHandler.hasMessages(MESSAGE_HANDLE_ENABLE_DELAYED)) {
|
|| mHandler.hasMessages(MESSAGE_HANDLE_ENABLE_DELAYED)) {
|
||||||
// We are handling enable or disable right now, wait for it.
|
// We are handling enable or disable right now, wait for it.
|
||||||
|
|||||||
Reference in New Issue
Block a user