[Audiosharing] Use getBroadcastToUnicastFallbackGroup to get primary

Flag: com.android.settingslib.flags.adopt_primary_group_management_api_v2
Test: atest
Bug: 397568136

Change-Id: I50487a8e5948fec6d8e71e2a0cf499cc7f0cf59d
This commit is contained in:
Yiyi Shen
2025-01-21 15:41:34 +08:00
parent c8d9ab2c55
commit ab6c7a8d97
6 changed files with 416 additions and 55 deletions

View File

@@ -207,7 +207,7 @@ public class AudioSharingCallAudioPreferenceController extends AudioSharingBaseP
(AudioSharingDeviceItem item) -> { (AudioSharingDeviceItem item) -> {
int currentCallAudioGroupId = int currentCallAudioGroupId =
BluetoothUtils.getPrimaryGroupIdForBroadcast( BluetoothUtils.getPrimaryGroupIdForBroadcast(
mContext.getContentResolver()); mContext.getContentResolver(), mBtManager);
int clickedGroupId = item.getGroupId(); int clickedGroupId = item.getGroupId();
if (clickedGroupId == currentCallAudioGroupId) { if (clickedGroupId == currentCallAudioGroupId) {
Log.d(TAG, "Skip set call audio device: unchanged"); Log.d(TAG, "Skip set call audio device: unchanged");
@@ -414,7 +414,8 @@ public class AudioSharingCallAudioPreferenceController extends AudioSharingBaseP
private Pair<Integer, AudioSharingDeviceItem> getActiveItemWithIndex() { private Pair<Integer, AudioSharingDeviceItem> getActiveItemWithIndex() {
List<AudioSharingDeviceItem> deviceItems = new ArrayList<>(mDeviceItemsInSharingSession); List<AudioSharingDeviceItem> deviceItems = new ArrayList<>(mDeviceItemsInSharingSession);
int fallbackActiveGroupId = int fallbackActiveGroupId =
BluetoothUtils.getPrimaryGroupIdForBroadcast(mContext.getContentResolver()); BluetoothUtils.getPrimaryGroupIdForBroadcast(mContext.getContentResolver(),
mBtManager);
if (fallbackActiveGroupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID) { if (fallbackActiveGroupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID) {
for (AudioSharingDeviceItem item : deviceItems) { for (AudioSharingDeviceItem item : deviceItems) {
if (item.getGroupId() == fallbackActiveGroupId) { if (item.getGroupId() == fallbackActiveGroupId) {

View File

@@ -418,7 +418,8 @@ public class AudioSharingDeviceVolumeGroupController extends AudioSharingBasePre
int groupId = BluetoothUtils.getGroupId(cachedDevice); int groupId = BluetoothUtils.getGroupId(cachedDevice);
// The fallback device rank first among the audio sharing device list. // The fallback device rank first among the audio sharing device list.
return (groupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID return (groupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID
&& groupId == BluetoothUtils.getPrimaryGroupIdForBroadcast(mContentResolver)) && groupId == BluetoothUtils.getPrimaryGroupIdForBroadcast(mContentResolver,
mBtManager))
? 0 ? 0
: 1; : 1;
} }

View File

@@ -46,6 +46,7 @@ public class AudioSharingDeviceVolumePreference extends SeekBarPreference {
private final Context mContext; private final Context mContext;
private final CachedBluetoothDevice mCachedDevice; private final CachedBluetoothDevice mCachedDevice;
@Nullable private final LocalBluetoothManager mBtManager;
@Nullable protected SeekBar mSeekBar; @Nullable protected SeekBar mSeekBar;
private Boolean mTrackingTouch = false; private Boolean mTrackingTouch = false;
private MetricsFeatureProvider mMetricsFeatureProvider = private MetricsFeatureProvider mMetricsFeatureProvider =
@@ -57,6 +58,7 @@ public class AudioSharingDeviceVolumePreference extends SeekBarPreference {
setLayoutResource(R.layout.preference_volume_slider); setLayoutResource(R.layout.preference_volume_slider);
mContext = context; mContext = context;
mCachedDevice = device; mCachedDevice = device;
mBtManager = Utils.getLocalBtManager(mContext);
} }
@NonNull @NonNull
@@ -110,7 +112,7 @@ public class AudioSharingDeviceVolumePreference extends SeekBarPreference {
if (groupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID if (groupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID
&& groupId && groupId
== BluetoothUtils.getPrimaryGroupIdForBroadcast( == BluetoothUtils.getPrimaryGroupIdForBroadcast(
mContext.getContentResolver())) { mContext.getContentResolver(), mBtManager)) {
// Set media stream volume for primary buds, audio manager will // Set media stream volume for primary buds, audio manager will
// update all buds volume in the audio sharing. // update all buds volume in the audio sharing.
setAudioManagerStreamVolume(progress); setAudioManagerStreamVolume(progress);
@@ -126,9 +128,8 @@ public class AudioSharingDeviceVolumePreference extends SeekBarPreference {
Log.d(TAG, "Skip set device volume, device is null"); Log.d(TAG, "Skip set device volume, device is null");
return; return;
} }
LocalBluetoothManager btManager = Utils.getLocalBtManager(mContext); VolumeControlProfile vc = mBtManager == null ? null
VolumeControlProfile vc = : mBtManager.getProfileManager().getVolumeControlProfile();
btManager == null ? null : btManager.getProfileManager().getVolumeControlProfile();
if (vc != null) { if (vc != null) {
vc.setDeviceVolume(device, progress, /* isGroupOp= */ true); vc.setDeviceVolume(device, progress, /* isGroupOp= */ true);
mMetricsFeatureProvider.action( mMetricsFeatureProvider.action(

View File

@@ -43,6 +43,8 @@ import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.database.ContentObserver; import android.database.ContentObserver;
import android.os.Looper; import android.os.Looper;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule; import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings; import android.provider.Settings;
import android.view.View; import android.view.View;
@@ -78,6 +80,7 @@ import com.android.settingslib.flags.Flags;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
@@ -113,9 +116,6 @@ public class AudioSharingCallAudioPreferenceControllerTest {
private static final int TEST_DEVICE_GROUP_ID1 = 1; private static final int TEST_DEVICE_GROUP_ID1 = 1;
private static final int TEST_DEVICE_GROUP_ID2 = 2; private static final int TEST_DEVICE_GROUP_ID2 = 2;
private static final String TEST_SETTINGS_KEY =
"bluetooth_le_broadcast_fallback_active_group_id";
@Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule(); @Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule();
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
@@ -125,6 +125,7 @@ public class AudioSharingCallAudioPreferenceControllerTest {
@Mock private BluetoothEventManager mBtEventManager; @Mock private BluetoothEventManager mBtEventManager;
@Mock private LocalBluetoothProfileManager mBtProfileManager; @Mock private LocalBluetoothProfileManager mBtProfileManager;
@Mock private CachedBluetoothDeviceManager mCacheManager; @Mock private CachedBluetoothDeviceManager mCacheManager;
@Mock private LeAudioProfile mLeaProfile;
@Mock private LocalBluetoothLeBroadcast mBroadcast; @Mock private LocalBluetoothLeBroadcast mBroadcast;
@Mock private LocalBluetoothLeBroadcastAssistant mAssistant; @Mock private LocalBluetoothLeBroadcastAssistant mAssistant;
@Mock private VolumeControlProfile mVolumeControl; @Mock private VolumeControlProfile mVolumeControl;
@@ -169,6 +170,7 @@ public class AudioSharingCallAudioPreferenceControllerTest {
when(btManager.getEventManager()).thenReturn(mBtEventManager); when(btManager.getEventManager()).thenReturn(mBtEventManager);
when(btManager.getProfileManager()).thenReturn(mBtProfileManager); when(btManager.getProfileManager()).thenReturn(mBtProfileManager);
when(btManager.getCachedDeviceManager()).thenReturn(mCacheManager); when(btManager.getCachedDeviceManager()).thenReturn(mCacheManager);
when(mBtProfileManager.getLeAudioProfile()).thenReturn(mLeaProfile);
when(mBtProfileManager.getLeAudioBroadcastProfile()).thenReturn(mBroadcast); when(mBtProfileManager.getLeAudioBroadcastProfile()).thenReturn(mBroadcast);
when(mBtProfileManager.getLeAudioBroadcastAssistantProfile()).thenReturn(mAssistant); when(mBtProfileManager.getLeAudioBroadcastAssistantProfile()).thenReturn(mAssistant);
when(mBtProfileManager.getVolumeControlProfile()).thenReturn(mVolumeControl); when(mBtProfileManager.getVolumeControlProfile()).thenReturn(mVolumeControl);
@@ -210,8 +212,8 @@ public class AudioSharingCallAudioPreferenceControllerTest {
} }
@Test @Test
@DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStart_flagOff_doNothing() { public void onStart_flagOff_doNothing() {
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.onStart(mLifecycleOwner); mController.onStart(mLifecycleOwner);
verify(mBtEventManager, never()).registerCallback(mController); verify(mBtEventManager, never()).registerCallback(mController);
verify(mContentResolver, never()) verify(mContentResolver, never())
@@ -225,8 +227,8 @@ public class AudioSharingCallAudioPreferenceControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStart_flagOn_registerCallback() { public void onStart_flagOn_registerCallback() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.onStart(mLifecycleOwner); mController.onStart(mLifecycleOwner);
verify(mBtEventManager).registerCallback(mController); verify(mBtEventManager).registerCallback(mController);
verify(mContentResolver) verify(mContentResolver)
@@ -240,8 +242,8 @@ public class AudioSharingCallAudioPreferenceControllerTest {
} }
@Test @Test
@DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStop_flagOff_doNothing() { public void onStop_flagOff_doNothing() {
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.setCallbacksRegistered(true); mController.setCallbacksRegistered(true);
mController.onStop(mLifecycleOwner); mController.onStop(mLifecycleOwner);
verify(mBtEventManager, never()).unregisterCallback(mController); verify(mBtEventManager, never()).unregisterCallback(mController);
@@ -251,8 +253,8 @@ public class AudioSharingCallAudioPreferenceControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStop_flagOn_notRegistered_doNothing() { public void onStop_flagOn_notRegistered_doNothing() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.setCallbacksRegistered(false); mController.setCallbacksRegistered(false);
mController.onStop(mLifecycleOwner); mController.onStop(mLifecycleOwner);
verify(mBtEventManager, never()).unregisterCallback(mController); verify(mBtEventManager, never()).unregisterCallback(mController);
@@ -262,8 +264,8 @@ public class AudioSharingCallAudioPreferenceControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStop_flagOn_registered_unregisterCallback() { public void onStop_flagOn_registered_unregisterCallback() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.setCallbacksRegistered(true); mController.setCallbacksRegistered(true);
mController.onStop(mLifecycleOwner); mController.onStop(mLifecycleOwner);
verify(mBtEventManager).unregisterCallback(mController); verify(mBtEventManager).unregisterCallback(mController);
@@ -273,20 +275,20 @@ public class AudioSharingCallAudioPreferenceControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void getAvailabilityStatus_flagOn() { public void getAvailabilityStatus_flagOn() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
} }
@Test @Test
@DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void getAvailabilityStatus_flagOff() { public void getAvailabilityStatus_flagOff() {
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
} }
@Test @Test
@DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void updateVisibility_flagOff_invisible() { public void updateVisibility_flagOff_invisible() {
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
when(mBroadcast.isEnabled(any())).thenReturn(true); when(mBroadcast.isEnabled(any())).thenReturn(true);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
mController.updateVisibility(); mController.updateVisibility();
@@ -295,8 +297,8 @@ public class AudioSharingCallAudioPreferenceControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void updateVisibility_broadcastOffBluetoothOff_invisible() { public void updateVisibility_broadcastOffBluetoothOff_invisible() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
when(mBroadcast.isEnabled(any())).thenReturn(false); when(mBroadcast.isEnabled(any())).thenReturn(false);
mShadowBluetoothAdapter.setEnabled(false); mShadowBluetoothAdapter.setEnabled(false);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
@@ -306,8 +308,8 @@ public class AudioSharingCallAudioPreferenceControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void updateVisibility_broadcastOnBluetoothOff_invisible() { public void updateVisibility_broadcastOnBluetoothOff_invisible() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
when(mBroadcast.isEnabled(any())).thenReturn(true); when(mBroadcast.isEnabled(any())).thenReturn(true);
mShadowBluetoothAdapter.setEnabled(false); mShadowBluetoothAdapter.setEnabled(false);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
@@ -317,8 +319,8 @@ public class AudioSharingCallAudioPreferenceControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void updateVisibility_broadcastOffBluetoothOn_invisible() { public void updateVisibility_broadcastOffBluetoothOn_invisible() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
when(mBroadcast.isEnabled(any())).thenReturn(false); when(mBroadcast.isEnabled(any())).thenReturn(false);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
mController.updateVisibility(); mController.updateVisibility();
@@ -327,8 +329,8 @@ public class AudioSharingCallAudioPreferenceControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void updateVisibility_broadcastOnBluetoothOn_visible() { public void updateVisibility_broadcastOnBluetoothOn_visible() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
when(mBroadcast.isEnabled(any())).thenReturn(true); when(mBroadcast.isEnabled(any())).thenReturn(true);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
mController.updateVisibility(); mController.updateVisibility();
@@ -337,8 +339,9 @@ public class AudioSharingCallAudioPreferenceControllerTest {
} }
@Test @Test
public void onProfileConnectionStateChanged_noDeviceInSharing_updateSummary() { @EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
Settings.Secure.putInt(mContentResolver, TEST_SETTINGS_KEY, TEST_DEVICE_GROUP_ID1); public void onProfileConnectionStateChanged_adoptApi_noDeviceInSharing_updateSummary() {
when(mLeaProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(TEST_DEVICE_GROUP_ID1);
when(mBroadcast.isEnabled(any())).thenReturn(true); when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of()); when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of());
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
@@ -354,8 +357,9 @@ public class AudioSharingCallAudioPreferenceControllerTest {
} }
@Test @Test
public void onFallbackDeviceChanged_updateSummary() { @EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
Settings.Secure.putInt(mContentResolver, TEST_SETTINGS_KEY, TEST_DEVICE_GROUP_ID1); public void onFallbackDeviceChanged_adoptApi_updateSummary() {
when(mLeaProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(TEST_DEVICE_GROUP_ID1);
when(mBroadcast.isEnabled(any())).thenReturn(true); when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1)); when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1));
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState)); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState));
@@ -372,8 +376,9 @@ public class AudioSharingCallAudioPreferenceControllerTest {
} }
@Test @Test
public void onActiveDeviceChanged_updateSummary() { @EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
Settings.Secure.putInt(mContentResolver, TEST_SETTINGS_KEY, public void onActiveDeviceChanged_adoptApi_updateSummary() {
when(mLeaProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(
BluetoothCsipSetCoordinator.GROUP_ID_INVALID); BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
when(mCachedDevice1.isActiveDevice(BluetoothProfile.LE_AUDIO)).thenReturn(true); when(mCachedDevice1.isActiveDevice(BluetoothProfile.LE_AUDIO)).thenReturn(true);
when(mBroadcast.isEnabled(any())).thenReturn(true); when(mBroadcast.isEnabled(any())).thenReturn(true);
@@ -392,8 +397,9 @@ public class AudioSharingCallAudioPreferenceControllerTest {
} }
@Test @Test
public void displayPreference_fallbackDeviceInSharing_showCorrectSummary() { @EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
Settings.Secure.putInt(mContentResolver, TEST_SETTINGS_KEY, TEST_DEVICE_GROUP_ID1); public void displayPreference_adoptApi_fallbackDeviceInSharing_showCorrectSummary() {
when(mLeaProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(TEST_DEVICE_GROUP_ID1);
when(mCachedDevice3.isActiveDevice(BluetoothProfile.LE_AUDIO)).thenReturn(true); when(mCachedDevice3.isActiveDevice(BluetoothProfile.LE_AUDIO)).thenReturn(true);
when(mBroadcast.isEnabled(any())).thenReturn(true); when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getAllConnectedDevices()) when(mAssistant.getAllConnectedDevices())
@@ -408,8 +414,9 @@ public class AudioSharingCallAudioPreferenceControllerTest {
} }
@Test @Test
public void displayPreference_activeDeviceInSharing_showCorrectSummary() { @EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
Settings.Secure.putInt(mContentResolver, TEST_SETTINGS_KEY, TEST_DEVICE_GROUP_ID2); public void displayPreference_adoptApi_activeDeviceInSharing_showCorrectSummary() {
when(mLeaProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(TEST_DEVICE_GROUP_ID2);
when(mCachedDevice1.isActiveDevice(BluetoothProfile.LE_AUDIO)).thenReturn(true); when(mCachedDevice1.isActiveDevice(BluetoothProfile.LE_AUDIO)).thenReturn(true);
when(mBroadcast.isEnabled(any())).thenReturn(true); when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1, mDevice2)); when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1, mDevice2));
@@ -422,8 +429,9 @@ public class AudioSharingCallAudioPreferenceControllerTest {
} }
@Test @Test
public void displayPreference_noFallbackDeviceOrActiveInSharing_showEmptySummary() { @EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
Settings.Secure.putInt(mContentResolver, TEST_SETTINGS_KEY, TEST_DEVICE_GROUP_ID2); public void displayPreference_adoptApi_noFallbackDeviceOrActiveInSharing_showEmptySummary() {
when(mLeaProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(TEST_DEVICE_GROUP_ID2);
when(mBroadcast.isEnabled(any())).thenReturn(true); when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1, mDevice2)); when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1, mDevice2));
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState)); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState));
@@ -433,9 +441,10 @@ public class AudioSharingCallAudioPreferenceControllerTest {
} }
@Test @Test
public void displayPreference_noFallbackOrActiveDevice_showEmptySummary() { @EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
Settings.Secure.putInt( public void displayPreference_adoptApi_noFallbackOrActiveDevice_showEmptySummary() {
mContentResolver, TEST_SETTINGS_KEY, BluetoothCsipSetCoordinator.GROUP_ID_INVALID); when(mLeaProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(
BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
when(mBroadcast.isEnabled(any())).thenReturn(true); when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of()); when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of());
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
@@ -444,13 +453,235 @@ public class AudioSharingCallAudioPreferenceControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void displayPreference_adoptApi_clickToShowCorrectDialog() {
AlertDialog latestAlertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
if (latestAlertDialog != null) {
latestAlertDialog.dismiss();
ShadowAlertDialogCompat.reset();
}
when(mLeaProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(TEST_DEVICE_GROUP_ID1);
mShadowBluetoothAdapter.setMostRecentlyConnectedDevices(
List.of(mDevice1, mDevice2, mDevice3));
when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getAllConnectedDevices()).thenReturn(
ImmutableList.of(mDevice1, mDevice2, mDevice3));
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState));
mController.init(mParentFragment);
mController.displayPreference(mScreen);
shadowOf(Looper.getMainLooper()).idle();
mPreference.performClick();
shadowOf(Looper.getMainLooper()).idle();
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
assertThat(dialog.isShowing()).isTrue();
assertThat(dialog.getListView().getCount()).isEqualTo(2);
ArrayList<View> outViews = new ArrayList<>();
dialog.getListView()
.findViewsWithText(outViews, TEST_DEVICE_NAME1, View.FIND_VIEWS_WITH_TEXT);
assertThat(outViews.size()).isEqualTo(1);
View view = Iterables.getOnlyElement(outViews);
assertThat(view instanceof CheckedTextView).isTrue();
assertThat(((CheckedTextView) view).isChecked()).isTrue();
verify(mFeatureFactory.metricsFeatureProvider)
.visible(
/* context= */ eq(null),
/* source= */ anyInt(),
eq(SettingsEnums.DIALOG_AUDIO_SHARING_CALL_AUDIO),
/* latency= */ anyInt());
}
@Test
@EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void testBluetoothLeBroadcastAssistantCallbacks_adoptApi_updateSummary() {
when(mLeaProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(
BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of());
mController.displayPreference(mScreen);
shadowOf(Looper.getMainLooper()).idle();
assertThat(mPreference.getSummary().toString()).isEmpty();
// onSourceAdded will update summary
when(mLeaProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(TEST_DEVICE_GROUP_ID1);
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1));
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState));
mController.mBroadcastAssistantCallback.onSourceAdded(mDevice1, /* sourceId= */
1, /* reason= */ 1);
shadowOf(Looper.getMainLooper()).idle();
assertThat(mPreference.getSummary().toString())
.isEqualTo(
mContext.getString(
R.string.audio_sharing_call_audio_description, TEST_DEVICE_NAME1));
}
@Test
@EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void testBluetoothLeBroadcastAssistantCallbacks_adoptApi_doNothing() {
when(mLeaProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(
BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of());
mController.displayPreference(mScreen);
shadowOf(Looper.getMainLooper()).idle();
assertThat(mPreference.getSummary().toString()).isEmpty();
when(mLeaProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(TEST_DEVICE_GROUP_ID1);
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1));
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState));
mController.mBroadcastAssistantCallback.onSearchStarted(/* reason= */ 1);
mController.mBroadcastAssistantCallback.onSearchStartFailed(/* reason= */ 1);
mController.mBroadcastAssistantCallback.onSearchStopped(/* reason= */ 1);
mController.mBroadcastAssistantCallback.onSearchStopFailed(/* reason= */ 1);
mController.mBroadcastAssistantCallback.onSourceAddFailed(
mDevice1, mSource, /* reason= */ 1);
mController.mBroadcastAssistantCallback.onSourceRemoved(
mDevice1, /* sourceId= */ 1, /* reason= */ 1);
mController.mBroadcastAssistantCallback.onSourceRemoveFailed(
mDevice1, /* sourceId= */ 1, /* reason= */ 1);
mController.mBroadcastAssistantCallback.onSourceModified(
mDevice1, /* sourceId= */ 1, /* reason= */ 1);
mController.mBroadcastAssistantCallback.onSourceModifyFailed(
mDevice1, /* sourceId= */ 1, /* reason= */ 1);
mController.mBroadcastAssistantCallback.onSourceFound(mSource);
mController.mBroadcastAssistantCallback.onSourceLost(/* broadcastId= */ 1);
shadowOf(Looper.getMainLooper()).idle();
mController.mBroadcastAssistantCallback.onReceiveStateChanged(mDevice1, /* sourceId= */ 1,
mState);
// Above callbacks won't update summary.
assertThat(mPreference.getSummary().toString()).isEmpty();
}
@Test
@DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void onProfileConnectionStateChanged_noDeviceInSharing_updateSummary() {
Settings.Secure.putInt(mContentResolver, BluetoothUtils.getPrimaryGroupIdUriForBroadcast(),
TEST_DEVICE_GROUP_ID1);
when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of());
mController.displayPreference(mScreen);
shadowOf(Looper.getMainLooper()).idle();
mPreference.setSummary("test");
mController.onProfileConnectionStateChanged(
mCachedDevice1,
BluetoothAdapter.STATE_DISCONNECTED,
BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT);
shadowOf(Looper.getMainLooper()).idle();
assertThat(mPreference.getSummary().toString()).isEmpty();
}
@Test
@DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void onFallbackDeviceChanged_updateSummary() {
Settings.Secure.putInt(mContentResolver, BluetoothUtils.getPrimaryGroupIdUriForBroadcast(),
TEST_DEVICE_GROUP_ID1);
when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1));
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState));
mController.displayPreference(mScreen);
shadowOf(Looper.getMainLooper()).idle();
mPreference.setSummary("test");
mContentObserver.onChange(true);
shadowOf(Looper.getMainLooper()).idle();
assertThat(mPreference.getSummary().toString())
.isEqualTo(
mContext.getString(
R.string.audio_sharing_call_audio_description, TEST_DEVICE_NAME1));
}
@Test
@DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void onActiveDeviceChanged_updateSummary() {
Settings.Secure.putInt(mContentResolver, BluetoothUtils.getPrimaryGroupIdUriForBroadcast(),
BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
when(mCachedDevice1.isActiveDevice(BluetoothProfile.LE_AUDIO)).thenReturn(true);
when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1));
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState));
mController.displayPreference(mScreen);
shadowOf(Looper.getMainLooper()).idle();
mPreference.setSummary("test");
mController.onActiveDeviceChanged(mCachedDevice1, BluetoothProfile.LE_AUDIO);
shadowOf(Looper.getMainLooper()).idle();
assertThat(mPreference.getSummary().toString())
.isEqualTo(
mContext.getString(
R.string.audio_sharing_call_audio_description, TEST_DEVICE_NAME1));
}
@Test
@DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void displayPreference_fallbackDeviceInSharing_showCorrectSummary() {
Settings.Secure.putInt(mContentResolver, BluetoothUtils.getPrimaryGroupIdUriForBroadcast(),
TEST_DEVICE_GROUP_ID1);
when(mCachedDevice3.isActiveDevice(BluetoothProfile.LE_AUDIO)).thenReturn(true);
when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getAllConnectedDevices())
.thenReturn(ImmutableList.of(mDevice1, mDevice2, mDevice3));
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState));
mController.displayPreference(mScreen);
shadowOf(Looper.getMainLooper()).idle();
assertThat(mPreference.getSummary().toString())
.isEqualTo(
mContext.getString(
R.string.audio_sharing_call_audio_description, TEST_DEVICE_NAME1));
}
@Test
@DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void displayPreference_activeDeviceInSharing_showCorrectSummary() {
Settings.Secure.putInt(mContentResolver, BluetoothUtils.getPrimaryGroupIdUriForBroadcast(),
TEST_DEVICE_GROUP_ID2);
when(mCachedDevice1.isActiveDevice(BluetoothProfile.LE_AUDIO)).thenReturn(true);
when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1, mDevice2));
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState));
mController.displayPreference(mScreen);
shadowOf(Looper.getMainLooper()).idle();
assertThat(mPreference.getSummary().toString())
.isEqualTo(mContext.getString(
R.string.audio_sharing_call_audio_description, TEST_DEVICE_NAME1));
}
@Test
@DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void displayPreference_noFallbackDeviceOrActiveInSharing_showEmptySummary() {
Settings.Secure.putInt(mContentResolver, BluetoothUtils.getPrimaryGroupIdUriForBroadcast(),
TEST_DEVICE_GROUP_ID2);
when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1, mDevice2));
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState));
mController.displayPreference(mScreen);
shadowOf(Looper.getMainLooper()).idle();
assertThat(mPreference.getSummary().toString()).isEmpty();
}
@Test
@DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void displayPreference_noFallbackOrActiveDevice_showEmptySummary() {
Settings.Secure.putInt(
mContentResolver, BluetoothUtils.getPrimaryGroupIdUriForBroadcast(),
BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of());
mController.displayPreference(mScreen);
shadowOf(Looper.getMainLooper()).idle();
assertThat(mPreference.getSummary().toString()).isEmpty();
}
@Test
@DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void displayPreference_clickToShowCorrectDialog() { public void displayPreference_clickToShowCorrectDialog() {
AlertDialog latestAlertDialog = ShadowAlertDialogCompat.getLatestAlertDialog(); AlertDialog latestAlertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
if (latestAlertDialog != null) { if (latestAlertDialog != null) {
latestAlertDialog.dismiss(); latestAlertDialog.dismiss();
ShadowAlertDialogCompat.reset(); ShadowAlertDialogCompat.reset();
} }
Settings.Secure.putInt(mContentResolver, TEST_SETTINGS_KEY, TEST_DEVICE_GROUP_ID1); Settings.Secure.putInt(mContentResolver, BluetoothUtils.getPrimaryGroupIdUriForBroadcast(),
TEST_DEVICE_GROUP_ID1);
mShadowBluetoothAdapter.setMostRecentlyConnectedDevices( mShadowBluetoothAdapter.setMostRecentlyConnectedDevices(
List.of(mDevice1, mDevice2, mDevice3)); List.of(mDevice1, mDevice2, mDevice3));
when(mBroadcast.isEnabled(any())).thenReturn(true); when(mBroadcast.isEnabled(any())).thenReturn(true);
@@ -497,7 +728,8 @@ public class AudioSharingCallAudioPreferenceControllerTest {
// Perform click to switch call audio device with API // Perform click to switch call audio device with API
mSetFlagsRule.enableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API); mSetFlagsRule.enableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API);
Settings.Secure.putInt(mContentResolver, TEST_SETTINGS_KEY, TEST_DEVICE_GROUP_ID2); Settings.Secure.putInt(mContentResolver, BluetoothUtils.getPrimaryGroupIdUriForBroadcast(),
TEST_DEVICE_GROUP_ID2);
index = listView.findIndexOfItemContainingText(TEST_DEVICE_NAME1); index = listView.findIndexOfItemContainingText(TEST_DEVICE_NAME1);
listView.performItemClick(index); listView.performItemClick(index);
shadowOf(Looper.getMainLooper()).idle(); shadowOf(Looper.getMainLooper()).idle();
@@ -548,9 +780,11 @@ public class AudioSharingCallAudioPreferenceControllerTest {
} }
@Test @Test
@DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void testBluetoothLeBroadcastAssistantCallbacks_updateSummary() { public void testBluetoothLeBroadcastAssistantCallbacks_updateSummary() {
Settings.Secure.putInt( Settings.Secure.putInt(
mContentResolver, TEST_SETTINGS_KEY, BluetoothCsipSetCoordinator.GROUP_ID_INVALID); mContentResolver, BluetoothUtils.getPrimaryGroupIdUriForBroadcast(),
BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
when(mBroadcast.isEnabled(any())).thenReturn(true); when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of()); when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of());
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
@@ -558,7 +792,8 @@ public class AudioSharingCallAudioPreferenceControllerTest {
assertThat(mPreference.getSummary().toString()).isEmpty(); assertThat(mPreference.getSummary().toString()).isEmpty();
// onSourceAdded will update summary // onSourceAdded will update summary
Settings.Secure.putInt(mContentResolver, TEST_SETTINGS_KEY, TEST_DEVICE_GROUP_ID1); Settings.Secure.putInt(mContentResolver, BluetoothUtils.getPrimaryGroupIdUriForBroadcast(),
TEST_DEVICE_GROUP_ID1);
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1)); when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1));
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState)); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState));
mController.mBroadcastAssistantCallback.onSourceAdded(mDevice1, /* sourceId= */ mController.mBroadcastAssistantCallback.onSourceAdded(mDevice1, /* sourceId= */
@@ -571,16 +806,19 @@ public class AudioSharingCallAudioPreferenceControllerTest {
} }
@Test @Test
@DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void testBluetoothLeBroadcastAssistantCallbacks_doNothing() { public void testBluetoothLeBroadcastAssistantCallbacks_doNothing() {
Settings.Secure.putInt( Settings.Secure.putInt(
mContentResolver, TEST_SETTINGS_KEY, BluetoothCsipSetCoordinator.GROUP_ID_INVALID); mContentResolver, BluetoothUtils.getPrimaryGroupIdUriForBroadcast(),
BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
when(mBroadcast.isEnabled(any())).thenReturn(true); when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of()); when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of());
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
shadowOf(Looper.getMainLooper()).idle(); shadowOf(Looper.getMainLooper()).idle();
assertThat(mPreference.getSummary().toString()).isEmpty(); assertThat(mPreference.getSummary().toString()).isEmpty();
Settings.Secure.putInt(mContentResolver, TEST_SETTINGS_KEY, TEST_DEVICE_GROUP_ID1); Settings.Secure.putInt(mContentResolver, BluetoothUtils.getPrimaryGroupIdUriForBroadcast(),
TEST_DEVICE_GROUP_ID1);
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1)); when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1));
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState)); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState));
mController.mBroadcastAssistantCallback.onSearchStarted(/* reason= */ 1); mController.mBroadcastAssistantCallback.onSearchStarted(/* reason= */ 1);

View File

@@ -23,6 +23,7 @@ import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
@@ -42,6 +43,8 @@ import android.content.Context;
import android.database.ContentObserver; import android.database.ContentObserver;
import android.media.AudioManager; import android.media.AudioManager;
import android.os.Looper; import android.os.Looper;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule; import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings; import android.provider.Settings;
@@ -60,6 +63,7 @@ import com.android.settings.testutils.shadow.ShadowThreadUtils;
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.CachedBluetoothDeviceManager; import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
import com.android.settingslib.bluetooth.LeAudioProfile;
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast; import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast;
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant; import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant;
import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothManager;
@@ -196,8 +200,8 @@ public class AudioSharingDeviceVolumeGroupControllerTest {
} }
@Test @Test
@DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStart_flagOff_doNothing() { public void onStart_flagOff_doNothing() {
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.onStart(mLifecycleOwner); mController.onStart(mLifecycleOwner);
verify(mAssistant, never()) verify(mAssistant, never())
.registerServiceCallBack( .registerServiceCallBack(
@@ -214,8 +218,8 @@ public class AudioSharingDeviceVolumeGroupControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStart_flagOn_registerCallbacks() { public void onStart_flagOn_registerCallbacks() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.onStart(mLifecycleOwner); mController.onStart(mLifecycleOwner);
verify(mAssistant) verify(mAssistant)
.registerServiceCallBack( .registerServiceCallBack(
@@ -229,8 +233,8 @@ public class AudioSharingDeviceVolumeGroupControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onAudioSharingProfilesConnected_flagOn_registerCallbacks() { public void onAudioSharingProfilesConnected_flagOn_registerCallbacks() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.onAudioSharingProfilesConnected(); mController.onAudioSharingProfilesConnected();
verify(mAssistant) verify(mAssistant)
.registerServiceCallBack( .registerServiceCallBack(
@@ -247,8 +251,8 @@ public class AudioSharingDeviceVolumeGroupControllerTest {
} }
@Test @Test
@DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStop_flagOff_doNothing() { public void onStop_flagOff_doNothing() {
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.onStop(mLifecycleOwner); mController.onStop(mLifecycleOwner);
verify(mAssistant, never()) verify(mAssistant, never())
.unregisterServiceCallBack(any(BluetoothLeBroadcastAssistant.Callback.class)); .unregisterServiceCallBack(any(BluetoothLeBroadcastAssistant.Callback.class));
@@ -259,8 +263,8 @@ public class AudioSharingDeviceVolumeGroupControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStop_flagOn_callbacksNotRegistered_doNothing() { public void onStop_flagOn_callbacksNotRegistered_doNothing() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.setCallbacksRegistered(false); mController.setCallbacksRegistered(false);
mController.onStop(mLifecycleOwner); mController.onStop(mLifecycleOwner);
verify(mAssistant, never()) verify(mAssistant, never())
@@ -272,8 +276,8 @@ public class AudioSharingDeviceVolumeGroupControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStop_flagOn_callbacksRegistered_unregisterCallbacks() { public void onStop_flagOn_callbacksRegistered_unregisterCallbacks() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.setCallbacksRegistered(true); mController.setCallbacksRegistered(true);
mController.onStop(mLifecycleOwner); mController.onStop(mLifecycleOwner);
verify(mAssistant) verify(mAssistant)
@@ -284,16 +288,16 @@ public class AudioSharingDeviceVolumeGroupControllerTest {
} }
@Test @Test
@DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void displayPreference_flagOff_doNothing() { public void displayPreference_flagOff_doNothing() {
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
assertThat(mPreferenceGroup.isVisible()).isFalse(); assertThat(mPreferenceGroup.isVisible()).isFalse();
verify(mDeviceUpdater, never()).forceUpdate(); verify(mDeviceUpdater, never()).forceUpdate();
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void displayPreference_flagOn_updateDeviceList() { public void displayPreference_flagOn_updateDeviceList() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
assertThat(mPreferenceGroup.isVisible()).isFalse(); assertThat(mPreferenceGroup.isVisible()).isFalse();
verify(mDeviceUpdater).forceUpdate(); verify(mDeviceUpdater).forceUpdate();
@@ -316,6 +320,24 @@ public class AudioSharingDeviceVolumeGroupControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void onDeviceAdded_adoptApi_rankFallbackDeviceOnTop() {
LeAudioProfile leAudioProfile = mock(LeAudioProfile.class);
when(leAudioProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(TEST_DEVICE_GROUP_ID2);
when(mProfileManager.getLeAudioProfile()).thenReturn(leAudioProfile);
when(mPreference1.getProgress()).thenReturn(TEST_VOLUME_VALUE);
when(mPreference2.getProgress()).thenReturn(TEST_VOLUME_VALUE);
mController.setPreferenceGroup(mPreferenceGroup);
mController.onDeviceAdded(mPreference1);
mController.onDeviceAdded(mPreference2);
shadowOf(Looper.getMainLooper()).idle();
verify(mPreference1).setOrder(1);
verify(mPreference2).setOrder(0);
}
@Test
@DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void onDeviceAdded_rankFallbackDeviceOnTop() { public void onDeviceAdded_rankFallbackDeviceOnTop() {
Settings.Secure.putInt( Settings.Secure.putInt(
mContentResolver, BluetoothUtils.getPrimaryGroupIdUriForBroadcast(), mContentResolver, BluetoothUtils.getPrimaryGroupIdUriForBroadcast(),
@@ -374,8 +396,8 @@ public class AudioSharingDeviceVolumeGroupControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void updateVisibility_emptyPreferenceGroup_doNothing() { public void updateVisibility_emptyPreferenceGroup_doNothing() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.setCallbacksRegistered(true); mController.setCallbacksRegistered(true);
mController.updateVisibility(); mController.updateVisibility();
shadowOf(Looper.getMainLooper()).idle(); shadowOf(Looper.getMainLooper()).idle();
@@ -384,8 +406,8 @@ public class AudioSharingDeviceVolumeGroupControllerTest {
} }
@Test @Test
@DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void updateVisibility_flagOff_setVisibleToFalse() { public void updateVisibility_flagOff_setVisibleToFalse() {
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.setCallbacksRegistered(true); mController.setCallbacksRegistered(true);
mPreferenceGroup.addPreference(mPreference1); mPreferenceGroup.addPreference(mPreference1);
when(mBroadcast.isEnabled(null)).thenReturn(true); when(mBroadcast.isEnabled(null)).thenReturn(true);
@@ -399,8 +421,8 @@ public class AudioSharingDeviceVolumeGroupControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void updateVisibility_notEmptyPreferenceGroup_noSharing_setVisibleToFalse() { public void updateVisibility_notEmptyPreferenceGroup_noSharing_setVisibleToFalse() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.setCallbacksRegistered(true); mController.setCallbacksRegistered(true);
mPreferenceGroup.addPreference(mPreference1); mPreferenceGroup.addPreference(mPreference1);
when(mBroadcast.isEnabled(null)).thenReturn(false); when(mBroadcast.isEnabled(null)).thenReturn(false);
@@ -414,8 +436,8 @@ public class AudioSharingDeviceVolumeGroupControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void updateVisibility_notEmptyPreferenceGroup_isSharing_setVisibleToTrue() { public void updateVisibility_notEmptyPreferenceGroup_isSharing_setVisibleToTrue() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.setCallbacksRegistered(true); mController.setCallbacksRegistered(true);
mPreferenceGroup.addPreference(mPreference1); mPreferenceGroup.addPreference(mPreference1);
when(mBroadcast.isEnabled(null)).thenReturn(true); when(mBroadcast.isEnabled(null)).thenReturn(true);
@@ -429,6 +451,29 @@ public class AudioSharingDeviceVolumeGroupControllerTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void settingsObserverOnChange_adoptApi_updatePreferenceOrder() {
LeAudioProfile leAudioProfile = mock(LeAudioProfile.class);
when(leAudioProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(TEST_DEVICE_GROUP_ID2);
when(mProfileManager.getLeAudioProfile()).thenReturn(leAudioProfile);
when(mPreference1.getProgress()).thenReturn(TEST_VOLUME_VALUE);
when(mPreference2.getProgress()).thenReturn(TEST_VOLUME_VALUE);
mController.setPreferenceGroup(mPreferenceGroup);
mController.onDeviceAdded(mPreference1);
mController.onDeviceAdded(mPreference2);
shadowOf(Looper.getMainLooper()).idle();
when(leAudioProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(TEST_DEVICE_GROUP_ID1);
mContentObserver.onChange(true);
shadowOf(Looper.getMainLooper()).idle();
verify(mPreference1).setOrder(0);
verify(mPreference2).setOrder(1);
}
@Test
@DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void settingsObserverOnChange_updatePreferenceOrder() { public void settingsObserverOnChange_updatePreferenceOrder() {
Settings.Secure.putInt( Settings.Secure.putInt(
mContentResolver, BluetoothUtils.getPrimaryGroupIdUriForBroadcast(), mContentResolver, BluetoothUtils.getPrimaryGroupIdUriForBroadcast(),

View File

@@ -31,6 +31,9 @@ import android.app.settings.SettingsEnums;
import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice;
import android.content.Context; import android.content.Context;
import android.media.AudioManager; import android.media.AudioManager;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings; import android.provider.Settings;
import android.widget.SeekBar; import android.widget.SeekBar;
@@ -41,9 +44,11 @@ import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowBluetoothUtils; import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
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.LeAudioProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import com.android.settingslib.bluetooth.VolumeControlProfile; import com.android.settingslib.bluetooth.VolumeControlProfile;
import com.android.settingslib.flags.Flags;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
@@ -64,9 +69,11 @@ public class AudioSharingDeviceVolumePreferenceTest {
private static final int TEST_MIN_STREAM_VALUE = 0; private static final int TEST_MIN_STREAM_VALUE = 0;
@Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule(); @Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule();
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
@Mock private LocalBluetoothManager mLocalBtManager; @Mock private LocalBluetoothManager mLocalBtManager;
@Mock private LocalBluetoothProfileManager mLocalBtProfileManager; @Mock private LocalBluetoothProfileManager mLocalBtProfileManager;
@Mock private LeAudioProfile mLeAudioProfile;
@Mock private VolumeControlProfile mVolumeControl; @Mock private VolumeControlProfile mVolumeControl;
@Mock private CachedBluetoothDevice mCachedDevice; @Mock private CachedBluetoothDevice mCachedDevice;
@Mock private BluetoothDevice mDevice; @Mock private BluetoothDevice mDevice;
@@ -84,6 +91,7 @@ public class AudioSharingDeviceVolumePreferenceTest {
mFeatureFactory = FakeFeatureFactory.setupForTest(); mFeatureFactory = FakeFeatureFactory.setupForTest();
when(mLocalBtManager.getProfileManager()).thenReturn(mLocalBtProfileManager); when(mLocalBtManager.getProfileManager()).thenReturn(mLocalBtProfileManager);
when(mLocalBtProfileManager.getVolumeControlProfile()).thenReturn(mVolumeControl); when(mLocalBtProfileManager.getVolumeControlProfile()).thenReturn(mVolumeControl);
when(mLocalBtProfileManager.getLeAudioProfile()).thenReturn(mLeAudioProfile);
when(mContext.getSystemService(AudioManager.class)).thenReturn(mAudioManager); when(mContext.getSystemService(AudioManager.class)).thenReturn(mAudioManager);
when(mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC)) when(mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC))
.thenReturn(TEST_MAX_STREAM_VALUE); .thenReturn(TEST_MAX_STREAM_VALUE);
@@ -161,6 +169,70 @@ public class AudioSharingDeviceVolumePreferenceTest {
} }
@Test @Test
@EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void onStopTrackingTouch_adoptApi_fallbackDevice_setDeviceVolume() {
when(mLeAudioProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(TEST_DEVICE_GROUP_ID);
mPreference.onStopTrackingTouch(mSeekBar);
verifyNoInteractions(mVolumeControl);
verify(mAudioManager)
.setStreamVolume(AudioManager.STREAM_MUSIC, TEST_MAX_STREAM_VALUE, /* flags= */ 0);
verify(mFeatureFactory.metricsFeatureProvider)
.action(
mContext,
SettingsEnums.ACTION_AUDIO_SHARING_CHANGE_MEDIA_DEVICE_VOLUME,
/* isPrimary= */ true);
}
@Test
@EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void onProgressChanged_adoptApi_fallbackDevice_fromUserNotInTouch_setDeviceVolume() {
when(mLeAudioProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(TEST_DEVICE_GROUP_ID);
mPreference.onProgressChanged(mSeekBar, TEST_VOLUME_VALUE, /* fromUser= */ true);
verifyNoInteractions(mVolumeControl);
verify(mAudioManager)
.setStreamVolume(AudioManager.STREAM_MUSIC, TEST_MAX_STREAM_VALUE, /* flags= */ 0);
verify(mFeatureFactory.metricsFeatureProvider)
.action(
mContext,
SettingsEnums.ACTION_AUDIO_SHARING_CHANGE_MEDIA_DEVICE_VOLUME,
/* isPrimary= */ true);
}
@Test
@EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void onProgressChanged_adoptApi_fallbackDevice_fromUserInTouch_doNothing() {
when(mLeAudioProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(TEST_DEVICE_GROUP_ID);
mPreference.onStartTrackingTouch(mSeekBar);
mPreference.onProgressChanged(mSeekBar, TEST_VOLUME_VALUE, /* fromUser= */ true);
verifyNoInteractions(mVolumeControl);
verifyNoInteractions(mAudioManager);
verify(mFeatureFactory.metricsFeatureProvider, never())
.action(
any(Context.class),
eq(SettingsEnums.ACTION_AUDIO_SHARING_CHANGE_MEDIA_DEVICE_VOLUME),
anyBoolean());
}
@Test
@EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void onProgressChanged_adoptApi_fallbackDevice_notFromUserNotInTouch_doNothing() {
when(mLeAudioProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(TEST_DEVICE_GROUP_ID);
mPreference.onProgressChanged(mSeekBar, TEST_VOLUME_VALUE, /* fromUser= */ false);
verifyNoInteractions(mVolumeControl);
verifyNoInteractions(mAudioManager);
verify(mFeatureFactory.metricsFeatureProvider, never())
.action(
any(Context.class),
eq(SettingsEnums.ACTION_AUDIO_SHARING_CHANGE_MEDIA_DEVICE_VOLUME),
anyBoolean());
}
@Test
@DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void onStopTrackingTouch_fallbackDevice_setDeviceVolume() { public void onStopTrackingTouch_fallbackDevice_setDeviceVolume() {
Settings.Secure.putInt( Settings.Secure.putInt(
mContext.getContentResolver(), mContext.getContentResolver(),
@@ -179,6 +251,7 @@ public class AudioSharingDeviceVolumePreferenceTest {
} }
@Test @Test
@DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void onProgressChanged_fallbackDevice_fromUserNotInTouch_setDeviceVolume() { public void onProgressChanged_fallbackDevice_fromUserNotInTouch_setDeviceVolume() {
Settings.Secure.putInt( Settings.Secure.putInt(
mContext.getContentResolver(), mContext.getContentResolver(),
@@ -197,6 +270,7 @@ public class AudioSharingDeviceVolumePreferenceTest {
} }
@Test @Test
@DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void onProgressChanged_fallbackDevice_fromUserInTouch_doNothing() { public void onProgressChanged_fallbackDevice_fromUserInTouch_doNothing() {
Settings.Secure.putInt( Settings.Secure.putInt(
mContext.getContentResolver(), mContext.getContentResolver(),
@@ -215,6 +289,7 @@ public class AudioSharingDeviceVolumePreferenceTest {
} }
@Test @Test
@DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void onProgressChanged_fallbackDevice_notFromUserNotInTouch_doNothing() { public void onProgressChanged_fallbackDevice_notFromUserNotInTouch_doNothing() {
Settings.Secure.putInt( Settings.Secure.putInt(
mContext.getContentResolver(), mContext.getContentResolver(),