Grey out LE audio offload switcher as LE audio isn't enabled/supported
Screenshot: https://screenshot.googleplex.com/C6pRBzLh7CtNeXr
Bug: 233018305
Bug: 233005340
Test: make RunSettingsRoboTests ROBOTEST_FILTER=BluetoothLeAudioHwOffloadPreferenceControllerTest
Change-Id: I0ea498d2fa191f9b9352b37500a5d2c348b36ce0
Merged-In: I0ea498d2fa191f9b9352b37500a5d2c348b36ce0
(cherry picked from commit f71b2ea56e
)
This commit is contained in:
@@ -18,6 +18,9 @@ package com.android.settings.development;
|
|||||||
|
|
||||||
import static com.android.settings.development.BluetoothA2dpHwOffloadPreferenceController.A2DP_OFFLOAD_SUPPORTED_PROPERTY;
|
import static com.android.settings.development.BluetoothA2dpHwOffloadPreferenceController.A2DP_OFFLOAD_SUPPORTED_PROPERTY;
|
||||||
|
|
||||||
|
import android.bluetooth.BluetoothAdapter;
|
||||||
|
import android.bluetooth.BluetoothManager;
|
||||||
|
import android.bluetooth.BluetoothStatusCodes;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
|
|
||||||
@@ -43,6 +46,9 @@ public class BluetoothLeAudioHwOffloadPreferenceController
|
|||||||
static final String LE_AUDIO_OFFLOAD_SUPPORTED_PROPERTY =
|
static final String LE_AUDIO_OFFLOAD_SUPPORTED_PROPERTY =
|
||||||
"ro.bluetooth.leaudio_offload.supported";
|
"ro.bluetooth.leaudio_offload.supported";
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
BluetoothAdapter mBluetoothAdapter;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean mChanged = false;
|
boolean mChanged = false;
|
||||||
|
|
||||||
@@ -50,6 +56,7 @@ public class BluetoothLeAudioHwOffloadPreferenceController
|
|||||||
DevelopmentSettingsDashboardFragment fragment) {
|
DevelopmentSettingsDashboardFragment fragment) {
|
||||||
super(context);
|
super(context);
|
||||||
mFragment = fragment;
|
mFragment = fragment;
|
||||||
|
mBluetoothAdapter = context.getSystemService(BluetoothManager.class).getAdapter();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -66,10 +73,17 @@ public class BluetoothLeAudioHwOffloadPreferenceController
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
|
if (mBluetoothAdapter == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final boolean leAudioEnabled =
|
||||||
|
(mBluetoothAdapter.isLeAudioSupported() == BluetoothStatusCodes.FEATURE_SUPPORTED);
|
||||||
|
|
||||||
final boolean offloadSupported =
|
final boolean offloadSupported =
|
||||||
SystemProperties.getBoolean(A2DP_OFFLOAD_SUPPORTED_PROPERTY, false)
|
SystemProperties.getBoolean(A2DP_OFFLOAD_SUPPORTED_PROPERTY, false)
|
||||||
&& SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_SUPPORTED_PROPERTY, false);
|
&& SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_SUPPORTED_PROPERTY, false);
|
||||||
if (offloadSupported) {
|
if (leAudioEnabled && offloadSupported) {
|
||||||
final boolean offloadDisabled =
|
final boolean offloadDisabled =
|
||||||
SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, true);
|
SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, true);
|
||||||
((SwitchPreference) mPreference).setChecked(offloadDisabled);
|
((SwitchPreference) mPreference).setChecked(offloadDisabled);
|
||||||
@@ -82,12 +96,20 @@ public class BluetoothLeAudioHwOffloadPreferenceController
|
|||||||
@Override
|
@Override
|
||||||
protected void onDeveloperOptionsSwitchDisabled() {
|
protected void onDeveloperOptionsSwitchDisabled() {
|
||||||
super.onDeveloperOptionsSwitchDisabled();
|
super.onDeveloperOptionsSwitchDisabled();
|
||||||
|
if (mBluetoothAdapter == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final boolean leAudioEnabled =
|
||||||
|
(mBluetoothAdapter.isLeAudioSupported() == BluetoothStatusCodes.FEATURE_SUPPORTED);
|
||||||
final boolean offloadSupported =
|
final boolean offloadSupported =
|
||||||
SystemProperties.getBoolean(A2DP_OFFLOAD_SUPPORTED_PROPERTY, false)
|
SystemProperties.getBoolean(A2DP_OFFLOAD_SUPPORTED_PROPERTY, false)
|
||||||
&& SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_SUPPORTED_PROPERTY, false);
|
&& SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_SUPPORTED_PROPERTY, false);
|
||||||
if (offloadSupported) {
|
if (leAudioEnabled && offloadSupported) {
|
||||||
((SwitchPreference) mPreference).setChecked(true);
|
((SwitchPreference) mPreference).setChecked(true);
|
||||||
SystemProperties.set(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, "true");
|
SystemProperties.set(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, "true");
|
||||||
|
} else {
|
||||||
|
mPreference.setEnabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user