From f1007faebab8bbf4770bf182366c6e1ecb678048 Mon Sep 17 00:00:00 2001 From: Paul Wang Date: Fri, 24 Feb 2023 14:30:47 +0000 Subject: [PATCH] Avoid disabling LE Audio when BT is off The `updateState` function gets called when the Developer Options menua is rendered (opened). Originally when BT is off at this point, LE Audio is disabled, and the user needs to reboot the device again to enable LE Audio. This CL fixes this and marks the option as disabled when BT is off. Bug: 263684630 Test: Manual Change-Id: I243e2c57fc12bfefd4ab83f63336fb41639f05a0 --- .../BluetoothLeAudioPreferenceController.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/com/android/settings/development/BluetoothLeAudioPreferenceController.java b/src/com/android/settings/development/BluetoothLeAudioPreferenceController.java index 00d0dd27af6..867bc2afd91 100644 --- a/src/com/android/settings/development/BluetoothLeAudioPreferenceController.java +++ b/src/com/android/settings/development/BluetoothLeAudioPreferenceController.java @@ -77,17 +77,19 @@ public class BluetoothLeAudioPreferenceController return; } - final boolean leAudioEnabled = - (mBluetoothAdapter.isLeAudioSupported() == BluetoothStatusCodes.FEATURE_SUPPORTED); - ((SwitchPreference) mPreference).setChecked(leAudioEnabled); - final boolean leAudioSwitchSupported = SystemProperties.getBoolean(LE_AUDIO_DYNAMIC_SWITCH_PROPERTY, false); - if (!leAudioSwitchSupported) { + + final int isLeAudioSupportedStatus = mBluetoothAdapter.isLeAudioSupported(); + final boolean leAudioEnabled = + (isLeAudioSupportedStatus == BluetoothStatusCodes.FEATURE_SUPPORTED); + + ((SwitchPreference) mPreference).setChecked(leAudioEnabled); + + // Disable option if Bluetooth is disabled or if switch is not supported + if (isLeAudioSupportedStatus == BluetoothStatusCodes.ERROR_BLUETOOTH_NOT_ENABLED + || !leAudioSwitchSupported) { mPreference.setEnabled(false); - } else { - SystemProperties.set(LE_AUDIO_DYNAMIC_ENABLED_PROPERTY, - Boolean.toString(leAudioEnabled)); } }