diff --git a/aconfig/settings_bluetooth_declarations.aconfig b/aconfig/settings_bluetooth_declarations.aconfig index 3e771cdb6fa..3d4f4155c30 100644 --- a/aconfig/settings_bluetooth_declarations.aconfig +++ b/aconfig/settings_bluetooth_declarations.aconfig @@ -13,4 +13,14 @@ flag { namespace: "pixel_cross_device_control" description: "Gates whether to enable checker for bluetooth profile toggle visibility" bug: "321178209" +} + +flag { + name: "hide_le_audio_toggle_for_le_audio_only_device" + namespace: "pixel_cross_device_control" + description: "Gates whether to hide LeAudio toggle for LeAudio-only device" + bug: "333827147" + metadata { + purpose: PURPOSE_BUGFIX + } } \ No newline at end of file diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java b/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java index 943d99bb4ee..3fa811a5499 100644 --- a/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java +++ b/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java @@ -43,6 +43,7 @@ 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.HearingAidProfile; import com.android.settingslib.bluetooth.LeAudioProfile; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothProfile; @@ -512,6 +513,19 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll refresh(); } + private boolean isLeAudioOnlyDevice() { + if (mCachedDevice.getProfiles().stream() + .noneMatch(profile -> profile instanceof LeAudioProfile)) { + return false; + } + return mCachedDevice.getProfiles().stream() + .noneMatch( + profile -> + profile instanceof HearingAidProfile + || profile instanceof A2dpProfile + || profile instanceof HeadsetProfile); + } + private void updateLeAudioConfig() { mIsLeContactSharingEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI, SettingsUIDeviceConfig.BT_LE_AUDIO_CONTACT_SHARING_ENABLED, true); @@ -520,6 +534,13 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll boolean isLeEnabledByDefault = SystemProperties.getBoolean(LE_AUDIO_CONNECTION_BY_DEFAULT_PROPERTY, true); mIsLeAudioToggleEnabled = isLeAudioToggleVisible || isLeEnabledByDefault; + if (Flags.hideLeAudioToggleForLeAudioOnlyDevice() && isLeAudioOnlyDevice()) { + mIsLeAudioToggleEnabled = false; + Log.d( + TAG, + "Hide LeAudio toggle for LeAudio-only Device: " + + mCachedDevice.getDevice().getAnonymizedAddress()); + } Log.d(TAG, "BT_LE_AUDIO_CONTACT_SHARING_ENABLED:" + mIsLeContactSharingEnabled + ", LE_AUDIO_TOGGLE_VISIBLE_PROPERTY:" + isLeAudioToggleVisible + ", LE_AUDIO_CONNECTION_BY_DEFAULT_PROPERTY:" + isLeEnabledByDefault); diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsProfilesControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsProfilesControllerTest.java index 9b1466b4fcb..9b922349d6b 100644 --- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsProfilesControllerTest.java +++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsProfilesControllerTest.java @@ -558,4 +558,49 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont List switches = getProfileSwitches(false); assertThat(switches.get(0).isVisible()).isTrue(); } + + @Test + public void classicAudioDeviceWithLeAudio_showLeAudioToggle() { + mSetFlagsRule.enableFlags(Flags.FLAG_HIDE_LE_AUDIO_TOGGLE_FOR_LE_AUDIO_ONLY_DEVICE); + setupDevice(makeDefaultDeviceConfig()); + + LeAudioProfile leAudioProfile = mock(LeAudioProfile.class); + when(leAudioProfile.getNameResource(mDevice)) + .thenReturn(com.android.settingslib.R.string.bluetooth_profile_le_audio); + when(leAudioProfile.isProfileReady()).thenReturn(true); + when(leAudioProfile.toString()).thenReturn("LE_AUDIO"); + when(mProfileManager.getLeAudioProfile()).thenReturn(leAudioProfile); + mConnectableProfiles.add(leAudioProfile); + when(mCachedDevice.getProfiles()) + .thenAnswer( + invocation -> + ImmutableList.of( + leAudioProfile, addMockA2dpProfile(false, false, false))); + + showScreen(mController); + + List switches = getProfileSwitches(false); + assertThat(switches.get(0).isVisible()).isTrue(); + } + + @Test + public void leAudioOnlyDevice_hideLeAudioToggle() { + mSetFlagsRule.enableFlags(Flags.FLAG_HIDE_LE_AUDIO_TOGGLE_FOR_LE_AUDIO_ONLY_DEVICE); + setupDevice(makeDefaultDeviceConfig()); + + LeAudioProfile leAudioProfile = mock(LeAudioProfile.class); + when(leAudioProfile.getNameResource(mDevice)) + .thenReturn(com.android.settingslib.R.string.bluetooth_profile_le_audio); + when(leAudioProfile.isProfileReady()).thenReturn(true); + when(leAudioProfile.toString()).thenReturn("LE_AUDIO"); + when(mProfileManager.getLeAudioProfile()).thenReturn(leAudioProfile); + mConnectableProfiles.add(leAudioProfile); + when(mCachedDevice.getProfiles()) + .thenAnswer(invocation -> ImmutableList.of(leAudioProfile)); + + showScreen(mController); + + List switches = getProfileSwitches(false); + assertThat(switches.get(0).isVisible()).isFalse(); + } }