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
This commit is contained in:
Paul Wang
2023-02-24 14:30:47 +00:00
parent 5bb798f518
commit f1007faeba

View File

@@ -77,17 +77,19 @@ public class BluetoothLeAudioPreferenceController
return; return;
} }
final boolean leAudioEnabled =
(mBluetoothAdapter.isLeAudioSupported() == BluetoothStatusCodes.FEATURE_SUPPORTED);
((SwitchPreference) mPreference).setChecked(leAudioEnabled);
final boolean leAudioSwitchSupported = final boolean leAudioSwitchSupported =
SystemProperties.getBoolean(LE_AUDIO_DYNAMIC_SWITCH_PROPERTY, false); 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); mPreference.setEnabled(false);
} else {
SystemProperties.set(LE_AUDIO_DYNAMIC_ENABLED_PROPERTY,
Boolean.toString(leAudioEnabled));
} }
} }