Hide LeAudio toggle for LeAudio-only device

Bug: 333827147
Test: atest BluetoothDetailsProfilesControllerTest
Change-Id: Ie446d8866fb51972795b66aac2db84703ef51b84
This commit is contained in:
Haijie Hong
2024-04-17 16:05:36 +08:00
parent 82e71b7278
commit 0307bbfb1f
3 changed files with 76 additions and 0 deletions

View File

@@ -14,3 +14,13 @@ flag {
description: "Gates whether to enable checker for bluetooth profile toggle visibility" description: "Gates whether to enable checker for bluetooth profile toggle visibility"
bug: "321178209" 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
}
}

View File

@@ -43,6 +43,7 @@ import com.android.settingslib.bluetooth.A2dpProfile;
import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.HeadsetProfile; import com.android.settingslib.bluetooth.HeadsetProfile;
import com.android.settingslib.bluetooth.HearingAidProfile;
import com.android.settingslib.bluetooth.LeAudioProfile; import com.android.settingslib.bluetooth.LeAudioProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfile; import com.android.settingslib.bluetooth.LocalBluetoothProfile;
@@ -512,6 +513,19 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
refresh(); 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() { private void updateLeAudioConfig() {
mIsLeContactSharingEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI, mIsLeContactSharingEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI,
SettingsUIDeviceConfig.BT_LE_AUDIO_CONTACT_SHARING_ENABLED, true); SettingsUIDeviceConfig.BT_LE_AUDIO_CONTACT_SHARING_ENABLED, true);
@@ -520,6 +534,13 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
boolean isLeEnabledByDefault = boolean isLeEnabledByDefault =
SystemProperties.getBoolean(LE_AUDIO_CONNECTION_BY_DEFAULT_PROPERTY, true); SystemProperties.getBoolean(LE_AUDIO_CONNECTION_BY_DEFAULT_PROPERTY, true);
mIsLeAudioToggleEnabled = isLeAudioToggleVisible || isLeEnabledByDefault; 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 Log.d(TAG, "BT_LE_AUDIO_CONTACT_SHARING_ENABLED:" + mIsLeContactSharingEnabled
+ ", LE_AUDIO_TOGGLE_VISIBLE_PROPERTY:" + isLeAudioToggleVisible + ", LE_AUDIO_TOGGLE_VISIBLE_PROPERTY:" + isLeAudioToggleVisible
+ ", LE_AUDIO_CONNECTION_BY_DEFAULT_PROPERTY:" + isLeEnabledByDefault); + ", LE_AUDIO_CONNECTION_BY_DEFAULT_PROPERTY:" + isLeEnabledByDefault);

View File

@@ -558,4 +558,49 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
List<SwitchPreferenceCompat> switches = getProfileSwitches(false); List<SwitchPreferenceCompat> switches = getProfileSwitches(false);
assertThat(switches.get(0).isVisible()).isTrue(); 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<SwitchPreferenceCompat> 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<SwitchPreferenceCompat> switches = getProfileSwitches(false);
assertThat(switches.get(0).isVisible()).isFalse();
}
} }