diff --git a/src/com/android/settings/development/BluetoothLeAudioHwOffloadPreferenceController.java b/src/com/android/settings/development/BluetoothLeAudioHwOffloadPreferenceController.java index f406ae782cf..751ddce79d2 100644 --- a/src/com/android/settings/development/BluetoothLeAudioHwOffloadPreferenceController.java +++ b/src/com/android/settings/development/BluetoothLeAudioHwOffloadPreferenceController.java @@ -18,6 +18,9 @@ package com.android.settings.development; 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.os.SystemProperties; @@ -43,6 +46,9 @@ public class BluetoothLeAudioHwOffloadPreferenceController static final String LE_AUDIO_OFFLOAD_SUPPORTED_PROPERTY = "ro.bluetooth.leaudio_offload.supported"; + @VisibleForTesting + BluetoothAdapter mBluetoothAdapter; + @VisibleForTesting boolean mChanged = false; @@ -50,6 +56,7 @@ public class BluetoothLeAudioHwOffloadPreferenceController DevelopmentSettingsDashboardFragment fragment) { super(context); mFragment = fragment; + mBluetoothAdapter = context.getSystemService(BluetoothManager.class).getAdapter(); } @Override @@ -66,10 +73,17 @@ public class BluetoothLeAudioHwOffloadPreferenceController @Override public void updateState(Preference preference) { + if (mBluetoothAdapter == null) { + return; + } + + final boolean leAudioEnabled = + (mBluetoothAdapter.isLeAudioSupported() == BluetoothStatusCodes.FEATURE_SUPPORTED); + final boolean offloadSupported = SystemProperties.getBoolean(A2DP_OFFLOAD_SUPPORTED_PROPERTY, false) && SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_SUPPORTED_PROPERTY, false); - if (offloadSupported) { + if (leAudioEnabled && offloadSupported) { final boolean offloadDisabled = SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, true); ((SwitchPreference) mPreference).setChecked(offloadDisabled); @@ -82,12 +96,20 @@ public class BluetoothLeAudioHwOffloadPreferenceController @Override protected void onDeveloperOptionsSwitchDisabled() { super.onDeveloperOptionsSwitchDisabled(); + if (mBluetoothAdapter == null) { + return; + } + + final boolean leAudioEnabled = + (mBluetoothAdapter.isLeAudioSupported() == BluetoothStatusCodes.FEATURE_SUPPORTED); final boolean offloadSupported = SystemProperties.getBoolean(A2DP_OFFLOAD_SUPPORTED_PROPERTY, false) && SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_SUPPORTED_PROPERTY, false); - if (offloadSupported) { + if (leAudioEnabled && offloadSupported) { ((SwitchPreference) mPreference).setChecked(true); SystemProperties.set(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, "true"); + } else { + mPreference.setEnabled(false); } }