diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java b/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java index 84504a91785..61e0a75cc45 100644 --- a/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java +++ b/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java @@ -16,11 +16,14 @@ package com.android.settings.bluetooth; +import static android.bluetooth.BluetoothDevice.METADATA_MODEL_NAME; + import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; import android.content.Context; import android.os.SystemProperties; import android.provider.DeviceConfig; +import android.sysprop.BluetoothProperties; import android.text.TextUtils; import android.util.Log; @@ -34,6 +37,7 @@ import androidx.preference.SwitchPreference; import com.android.settings.R; import com.android.settings.core.SettingsUIDeviceConfig; import com.android.settingslib.bluetooth.A2dpProfile; +import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.HeadsetProfile; import com.android.settingslib.bluetooth.LeAudioProfile; @@ -121,12 +125,28 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll pref.setOnPreferenceClickListener(this); pref.setOrder(profile.getOrdinal()); - if (profile instanceof LeAudioProfile) { + if (profile instanceof LeAudioProfile && !isModelNameInAllowList( + BluetoothUtils.getStringMetaData(mCachedDevice.getDevice(), + METADATA_MODEL_NAME))) { pref.setSummary(R.string.device_details_leaudio_toggle_summary); } return pref; } + /** + * Checks if the device model name is in the LE audio allow list based on its model name. + * + * @param modelName The model name of the device to be checked. + * @return true if the device is in the allow list, false otherwise. + */ + @VisibleForTesting + boolean isModelNameInAllowList(String modelName) { + if (modelName == null || modelName.isEmpty()) { + return false; + } + return BluetoothProperties.le_audio_allow_list().contains(modelName); + } + /** * Refreshes the state for an existing SwitchPreference for a profile. */ diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsProfilesControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsProfilesControllerTest.java index 76023c58ec1..ad7c9843ef6 100644 --- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsProfilesControllerTest.java +++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsProfilesControllerTest.java @@ -28,6 +28,7 @@ import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; import android.content.Context; +import android.sysprop.BluetoothProperties; import androidx.preference.Preference; import androidx.preference.PreferenceCategory; @@ -41,6 +42,8 @@ import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; import com.android.settingslib.bluetooth.MapProfile; import com.android.settingslib.bluetooth.PbapServerProfile; +import com.google.common.collect.Lists; + import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -60,6 +63,8 @@ import java.util.Set; @Config(shadows = ShadowBluetoothDevice.class) public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsControllerTestBase { + private static final String LE_DEVICE_MODEL = "le_audio_headset"; + private static final String NON_LE_DEVICE_MODEL = "non_le_audio_headset"; private BluetoothDetailsProfilesController mController; private List mConnectableProfiles; private PreferenceCategory mProfiles; @@ -88,6 +93,7 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont mProfiles.setKey(mController.getPreferenceKey()); mController.mProfilesContainer = mProfiles; mScreen.addPreference(mProfiles); + BluetoothProperties.le_audio_allow_list(Lists.newArrayList(LE_DEVICE_MODEL)); } static class FakeBluetoothProfile implements LocalBluetoothProfile { @@ -472,4 +478,15 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont verify(mProfileManager).removeServiceListener(mController); } + + @Test + public void isDeviceInAllowList_returnTrue() { + assertThat(mController.isModelNameInAllowList(LE_DEVICE_MODEL)).isTrue(); + } + + @Test + public void isDeviceInAllowList_returnFalse() { + assertThat(mController.isModelNameInAllowList(null)).isFalse(); + assertThat(mController.isModelNameInAllowList(NON_LE_DEVICE_MODEL)).isFalse(); + } }