summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
author William Escande <wescande@google.com> 2024-10-24 18:18:38 -0700
committer William Escande <wescande@google.com> 2024-10-25 13:43:08 -0700
commit41e77e909c22ec3395be0010e6ce5c304b3d23af (patch)
tree1586cc55d39ded4299fb681c811380492b9cc070 /service
parent29bf222fc71994460ff500c5bb7446165d15278a (diff)
Untangled RESTORE_USER_SETTING message
Using a different message for OFF and ON is way much clearer, especially with incoming test Bug: 328842491 Flag: Exempt, no-op Test: atest ServiceBluetoothTests Change-Id: I2ac8526c0395762748fb22a17613b6bbe2f61e17
Diffstat (limited to 'service')
-rw-r--r--service/src/com/android/server/bluetooth/BluetoothManagerService.java68
1 files changed, 31 insertions, 37 deletions
diff --git a/service/src/com/android/server/bluetooth/BluetoothManagerService.java b/service/src/com/android/server/bluetooth/BluetoothManagerService.java
index b59ab9de45..6a9e905310 100644
--- a/service/src/com/android/server/bluetooth/BluetoothManagerService.java
+++ b/service/src/com/android/server/bluetooth/BluetoothManagerService.java
@@ -157,10 +157,8 @@ class BluetoothManagerService {
@VisibleForTesting static final int MESSAGE_GET_NAME_AND_ADDRESS = 200;
@VisibleForTesting static final int MESSAGE_USER_SWITCHED = 300;
@VisibleForTesting static final int MESSAGE_USER_UNLOCKED = 301;
- @VisibleForTesting static final int MESSAGE_RESTORE_USER_SETTING = 500;
-
- private static final int RESTORE_SETTING_TO_ON = 1;
- private static final int RESTORE_SETTING_TO_OFF = 0;
+ @VisibleForTesting static final int MESSAGE_RESTORE_USER_SETTING_OFF = 501;
+ @VisibleForTesting static final int MESSAGE_RESTORE_USER_SETTING_ON = 502;
private static final int MAX_ERROR_RESTART_RETRIES = 6;
private static final int MAX_WAIT_FOR_ENABLE_DISABLE_RETRIES = 10;
@@ -557,17 +555,15 @@ class BluetoothManagerService {
+ (" prevValue=" + prevValue)
+ (" newValue=" + newValue));
- if ((newValue != null)
- && (prevValue != null)
- && !prevValue.equals(newValue)) {
- mHandler.obtainMessage(
- MESSAGE_RESTORE_USER_SETTING,
- newValue.equals("0")
- ? RESTORE_SETTING_TO_OFF
- : RESTORE_SETTING_TO_ON,
- 0)
- .sendToTarget();
+ if ((newValue == null)
+ || (prevValue == null)
+ || prevValue.equals(newValue)) {
+ return;
}
+ mHandler.sendEmptyMessage(
+ newValue.equals("0")
+ ? MESSAGE_RESTORE_USER_SETTING_OFF
+ : MESSAGE_RESTORE_USER_SETTING_ON);
}
} else if (action.equals(Intent.ACTION_SHUTDOWN)) {
Log.i(TAG, "Device is shutting down.");
@@ -1539,24 +1535,26 @@ class BluetoothManagerService {
}
break;
- case MESSAGE_RESTORE_USER_SETTING:
- if ((msg.arg1 == RESTORE_SETTING_TO_OFF) && mEnable) {
- Log.d(TAG, "MESSAGE_RESTORE_USER_SETTING: set Bluetooth state to disabled");
- setBluetoothPersistedState(BLUETOOTH_OFF);
- mEnableExternal = false;
- sendDisableMsg(ENABLE_DISABLE_REASON_RESTORE_USER_SETTING);
- } else if ((msg.arg1 == RESTORE_SETTING_TO_ON) && !mEnable) {
- Log.d(TAG, "MESSAGE_RESTORE_USER_SETTING: set Bluetooth state to enabled");
- mQuietEnableExternal = false;
- mEnableExternal = true;
- sendEnableMsg(false, ENABLE_DISABLE_REASON_RESTORE_USER_SETTING);
- } else {
- Log.w(
- TAG,
- "MESSAGE_RESTORE_USER_SETTING: Unhandled."
- + (" mEnable=" + mEnable)
- + (" msg.arg1=" + msg.arg1));
+ case MESSAGE_RESTORE_USER_SETTING_OFF:
+ if (!mEnable) {
+ Log.w(TAG, "RESTORE_USER_SETTING_OFF: Unhandled: already disabled");
+ break;
+ }
+ Log.d(TAG, "RESTORE_USER_SETTING_OFF: set Bluetooth state to disabled");
+ setBluetoothPersistedState(BLUETOOTH_OFF);
+ mEnableExternal = false;
+ sendDisableMsg(ENABLE_DISABLE_REASON_RESTORE_USER_SETTING);
+ break;
+
+ case MESSAGE_RESTORE_USER_SETTING_ON:
+ if (mEnable) {
+ Log.w(TAG, "RESTORE_USER_SETTING_ON: Unhandled: already enabled");
+ break;
}
+ Log.d(TAG, "RESTORE_USER_SETTING_ON: set Bluetooth state to enabled");
+ mQuietEnableExternal = false;
+ mEnableExternal = true;
+ sendEnableMsg(false, ENABLE_DISABLE_REASON_RESTORE_USER_SETTING);
break;
case MESSAGE_BLUETOOTH_SERVICE_CONNECTED:
@@ -1618,14 +1616,10 @@ class BluetoothManagerService {
bluetoothStateChangeHandler(prevState, newState);
// handle error state transition case from TURNING_ON to OFF
// unbind and rebind bluetooth service and enable bluetooth
- if ((prevState == STATE_BLE_TURNING_ON)
- && (newState == STATE_OFF)
- && mEnable) {
+ if ((prevState == STATE_BLE_TURNING_ON) && (newState == STATE_OFF) && mEnable) {
recoverBluetoothServiceFromError(false);
}
- if ((prevState == STATE_TURNING_ON)
- && (newState == STATE_BLE_ON)
- && mEnable) {
+ if ((prevState == STATE_TURNING_ON) && (newState == STATE_BLE_ON) && mEnable) {
recoverBluetoothServiceFromError(true);
}
// If we tried to enable BT while BT was in the process of shutting down,