Merge changes I0ea498d2,I2d650eb3,I8adcf27e into tm-d1-dev am: 671c65235c

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/18740333

Change-Id: I30105608cf552ec60582cb296179b9cd94b6d66b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
TreeHugger Robot
2022-06-07 04:00:25 +00:00
committed by Automerger Merge Worker

View File

@@ -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);
} }
} }