Merge "[Satellite] Move entitlment check to auto type only." into main
diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCallAudioPreferenceController.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCallAudioPreferenceController.java
index 0c8b16b..be861a6 100644
--- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCallAudioPreferenceController.java
+++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCallAudioPreferenceController.java
@@ -207,7 +207,7 @@
(AudioSharingDeviceItem item) -> {
int currentCallAudioGroupId =
BluetoothUtils.getPrimaryGroupIdForBroadcast(
- mContext.getContentResolver());
+ mContext.getContentResolver(), mBtManager);
int clickedGroupId = item.getGroupId();
if (clickedGroupId == currentCallAudioGroupId) {
Log.d(TAG, "Skip set call audio device: unchanged");
@@ -414,7 +414,8 @@
private Pair<Integer, AudioSharingDeviceItem> getActiveItemWithIndex() {
List<AudioSharingDeviceItem> deviceItems = new ArrayList<>(mDeviceItemsInSharingSession);
int fallbackActiveGroupId =
- BluetoothUtils.getPrimaryGroupIdForBroadcast(mContext.getContentResolver());
+ BluetoothUtils.getPrimaryGroupIdForBroadcast(mContext.getContentResolver(),
+ mBtManager);
if (fallbackActiveGroupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID) {
for (AudioSharingDeviceItem item : deviceItems) {
if (item.getGroupId() == fallbackActiveGroupId) {
diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeGroupController.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeGroupController.java
index 7b670a8..1659d2d 100644
--- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeGroupController.java
+++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeGroupController.java
@@ -418,7 +418,8 @@
int groupId = BluetoothUtils.getGroupId(cachedDevice);
// The fallback device rank first among the audio sharing device list.
return (groupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID
- && groupId == BluetoothUtils.getPrimaryGroupIdForBroadcast(mContentResolver))
+ && groupId == BluetoothUtils.getPrimaryGroupIdForBroadcast(mContentResolver,
+ mBtManager))
? 0
: 1;
}
diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumePreference.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumePreference.java
index 816ec6e..944ac25 100644
--- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumePreference.java
+++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumePreference.java
@@ -46,6 +46,7 @@
private final Context mContext;
private final CachedBluetoothDevice mCachedDevice;
+ @Nullable private final LocalBluetoothManager mBtManager;
@Nullable protected SeekBar mSeekBar;
private Boolean mTrackingTouch = false;
private MetricsFeatureProvider mMetricsFeatureProvider =
@@ -57,6 +58,7 @@
setLayoutResource(R.layout.preference_volume_slider);
mContext = context;
mCachedDevice = device;
+ mBtManager = Utils.getLocalBtManager(mContext);
}
@NonNull
@@ -110,7 +112,7 @@
if (groupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID
&& groupId
== BluetoothUtils.getPrimaryGroupIdForBroadcast(
- mContext.getContentResolver())) {
+ mContext.getContentResolver(), mBtManager)) {
// Set media stream volume for primary buds, audio manager will
// update all buds volume in the audio sharing.
setAudioManagerStreamVolume(progress);
@@ -126,9 +128,8 @@
Log.d(TAG, "Skip set device volume, device is null");
return;
}
- LocalBluetoothManager btManager = Utils.getLocalBtManager(mContext);
- VolumeControlProfile vc =
- btManager == null ? null : btManager.getProfileManager().getVolumeControlProfile();
+ VolumeControlProfile vc = mBtManager == null ? null
+ : mBtManager.getProfileManager().getVolumeControlProfile();
if (vc != null) {
vc.setDeviceVolume(device, progress, /* isGroupOp= */ true);
mMetricsFeatureProvider.action(
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCallAudioPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCallAudioPreferenceControllerTest.java
index 4f6fed7..7fece8b 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCallAudioPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCallAudioPreferenceControllerTest.java
@@ -43,6 +43,8 @@
import android.content.Context;
import android.database.ContentObserver;
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.provider.Settings;
import android.view.View;
@@ -78,6 +80,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
import org.junit.After;
import org.junit.Before;
@@ -113,9 +116,6 @@
private static final int TEST_DEVICE_GROUP_ID1 = 1;
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 SetFlagsRule mSetFlagsRule = new SetFlagsRule();
@@ -125,6 +125,7 @@
@Mock private BluetoothEventManager mBtEventManager;
@Mock private LocalBluetoothProfileManager mBtProfileManager;
@Mock private CachedBluetoothDeviceManager mCacheManager;
+ @Mock private LeAudioProfile mLeaProfile;
@Mock private LocalBluetoothLeBroadcast mBroadcast;
@Mock private LocalBluetoothLeBroadcastAssistant mAssistant;
@Mock private VolumeControlProfile mVolumeControl;
@@ -169,6 +170,7 @@
when(btManager.getEventManager()).thenReturn(mBtEventManager);
when(btManager.getProfileManager()).thenReturn(mBtProfileManager);
when(btManager.getCachedDeviceManager()).thenReturn(mCacheManager);
+ when(mBtProfileManager.getLeAudioProfile()).thenReturn(mLeaProfile);
when(mBtProfileManager.getLeAudioBroadcastProfile()).thenReturn(mBroadcast);
when(mBtProfileManager.getLeAudioBroadcastAssistantProfile()).thenReturn(mAssistant);
when(mBtProfileManager.getVolumeControlProfile()).thenReturn(mVolumeControl);
@@ -210,8 +212,8 @@
}
@Test
+ @DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStart_flagOff_doNothing() {
- mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.onStart(mLifecycleOwner);
verify(mBtEventManager, never()).registerCallback(mController);
verify(mContentResolver, never())
@@ -225,8 +227,8 @@
}
@Test
+ @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStart_flagOn_registerCallback() {
- mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.onStart(mLifecycleOwner);
verify(mBtEventManager).registerCallback(mController);
verify(mContentResolver)
@@ -240,8 +242,8 @@
}
@Test
+ @DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStop_flagOff_doNothing() {
- mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.setCallbacksRegistered(true);
mController.onStop(mLifecycleOwner);
verify(mBtEventManager, never()).unregisterCallback(mController);
@@ -251,8 +253,8 @@
}
@Test
+ @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStop_flagOn_notRegistered_doNothing() {
- mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.setCallbacksRegistered(false);
mController.onStop(mLifecycleOwner);
verify(mBtEventManager, never()).unregisterCallback(mController);
@@ -262,8 +264,8 @@
}
@Test
+ @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStop_flagOn_registered_unregisterCallback() {
- mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.setCallbacksRegistered(true);
mController.onStop(mLifecycleOwner);
verify(mBtEventManager).unregisterCallback(mController);
@@ -273,20 +275,20 @@
}
@Test
+ @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void getAvailabilityStatus_flagOn() {
- mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test
+ @DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void getAvailabilityStatus_flagOff() {
- mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
}
@Test
+ @DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void updateVisibility_flagOff_invisible() {
- mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
when(mBroadcast.isEnabled(any())).thenReturn(true);
mController.displayPreference(mScreen);
mController.updateVisibility();
@@ -295,8 +297,8 @@
}
@Test
+ @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void updateVisibility_broadcastOffBluetoothOff_invisible() {
- mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
when(mBroadcast.isEnabled(any())).thenReturn(false);
mShadowBluetoothAdapter.setEnabled(false);
mController.displayPreference(mScreen);
@@ -306,8 +308,8 @@
}
@Test
+ @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void updateVisibility_broadcastOnBluetoothOff_invisible() {
- mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
when(mBroadcast.isEnabled(any())).thenReturn(true);
mShadowBluetoothAdapter.setEnabled(false);
mController.displayPreference(mScreen);
@@ -317,8 +319,8 @@
}
@Test
+ @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void updateVisibility_broadcastOffBluetoothOn_invisible() {
- mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
when(mBroadcast.isEnabled(any())).thenReturn(false);
mController.displayPreference(mScreen);
mController.updateVisibility();
@@ -327,8 +329,8 @@
}
@Test
+ @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void updateVisibility_broadcastOnBluetoothOn_visible() {
- mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
when(mBroadcast.isEnabled(any())).thenReturn(true);
mController.displayPreference(mScreen);
mController.updateVisibility();
@@ -337,8 +339,9 @@
}
@Test
- public void onProfileConnectionStateChanged_noDeviceInSharing_updateSummary() {
- Settings.Secure.putInt(mContentResolver, TEST_SETTINGS_KEY, TEST_DEVICE_GROUP_ID1);
+ @EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
+ public void onProfileConnectionStateChanged_adoptApi_noDeviceInSharing_updateSummary() {
+ when(mLeaProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(TEST_DEVICE_GROUP_ID1);
when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of());
mController.displayPreference(mScreen);
@@ -354,8 +357,9 @@
}
@Test
- public void onFallbackDeviceChanged_updateSummary() {
- Settings.Secure.putInt(mContentResolver, TEST_SETTINGS_KEY, TEST_DEVICE_GROUP_ID1);
+ @EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
+ public void onFallbackDeviceChanged_adoptApi_updateSummary() {
+ when(mLeaProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(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));
@@ -372,8 +376,9 @@
}
@Test
- public void onActiveDeviceChanged_updateSummary() {
- Settings.Secure.putInt(mContentResolver, TEST_SETTINGS_KEY,
+ @EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
+ public void onActiveDeviceChanged_adoptApi_updateSummary() {
+ when(mLeaProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(
BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
when(mCachedDevice1.isActiveDevice(BluetoothProfile.LE_AUDIO)).thenReturn(true);
when(mBroadcast.isEnabled(any())).thenReturn(true);
@@ -392,8 +397,9 @@
}
@Test
- public void displayPreference_fallbackDeviceInSharing_showCorrectSummary() {
- Settings.Secure.putInt(mContentResolver, TEST_SETTINGS_KEY, TEST_DEVICE_GROUP_ID1);
+ @EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
+ public void displayPreference_adoptApi_fallbackDeviceInSharing_showCorrectSummary() {
+ when(mLeaProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(TEST_DEVICE_GROUP_ID1);
when(mCachedDevice3.isActiveDevice(BluetoothProfile.LE_AUDIO)).thenReturn(true);
when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getAllConnectedDevices())
@@ -408,8 +414,9 @@
}
@Test
- public void displayPreference_activeDeviceInSharing_showCorrectSummary() {
- Settings.Secure.putInt(mContentResolver, TEST_SETTINGS_KEY, TEST_DEVICE_GROUP_ID2);
+ @EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
+ public void displayPreference_adoptApi_activeDeviceInSharing_showCorrectSummary() {
+ when(mLeaProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(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));
@@ -422,8 +429,9 @@
}
@Test
- public void displayPreference_noFallbackDeviceOrActiveInSharing_showEmptySummary() {
- Settings.Secure.putInt(mContentResolver, TEST_SETTINGS_KEY, TEST_DEVICE_GROUP_ID2);
+ @EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
+ public void displayPreference_adoptApi_noFallbackDeviceOrActiveInSharing_showEmptySummary() {
+ when(mLeaProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(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));
@@ -433,9 +441,10 @@
}
@Test
- public void displayPreference_noFallbackOrActiveDevice_showEmptySummary() {
- Settings.Secure.putInt(
- mContentResolver, TEST_SETTINGS_KEY, BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
+ @EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
+ public void displayPreference_adoptApi_noFallbackOrActiveDevice_showEmptySummary() {
+ when(mLeaProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(
+ BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of());
mController.displayPreference(mScreen);
@@ -444,13 +453,235 @@
}
@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() {
AlertDialog latestAlertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
if (latestAlertDialog != null) {
latestAlertDialog.dismiss();
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(
List.of(mDevice1, mDevice2, mDevice3));
when(mBroadcast.isEnabled(any())).thenReturn(true);
@@ -497,7 +728,8 @@
// Perform click to switch call audio device with 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);
listView.performItemClick(index);
shadowOf(Looper.getMainLooper()).idle();
@@ -548,9 +780,11 @@
}
@Test
+ @DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void testBluetoothLeBroadcastAssistantCallbacks_updateSummary() {
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(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of());
mController.displayPreference(mScreen);
@@ -558,7 +792,8 @@
assertThat(mPreference.getSummary().toString()).isEmpty();
// 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.getAllSources(any())).thenReturn(ImmutableList.of(mState));
mController.mBroadcastAssistantCallback.onSourceAdded(mDevice1, /* sourceId= */
@@ -571,16 +806,19 @@
}
@Test
+ @DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void testBluetoothLeBroadcastAssistantCallbacks_doNothing() {
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(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of());
mController.displayPreference(mScreen);
shadowOf(Looper.getMainLooper()).idle();
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.getAllSources(any())).thenReturn(ImmutableList.of(mState));
mController.mBroadcastAssistantCallback.onSearchStarted(/* reason= */ 1);
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeGroupControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeGroupControllerTest.java
index a739bb3..6ca0306 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeGroupControllerTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeGroupControllerTest.java
@@ -23,6 +23,7 @@
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
@@ -42,6 +43,8 @@
import android.database.ContentObserver;
import android.media.AudioManager;
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.provider.Settings;
@@ -60,6 +63,7 @@
import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
+import com.android.settingslib.bluetooth.LeAudioProfile;
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast;
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
@@ -196,8 +200,8 @@
}
@Test
+ @DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStart_flagOff_doNothing() {
- mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.onStart(mLifecycleOwner);
verify(mAssistant, never())
.registerServiceCallBack(
@@ -214,8 +218,8 @@
}
@Test
+ @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStart_flagOn_registerCallbacks() {
- mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.onStart(mLifecycleOwner);
verify(mAssistant)
.registerServiceCallBack(
@@ -229,8 +233,8 @@
}
@Test
+ @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onAudioSharingProfilesConnected_flagOn_registerCallbacks() {
- mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.onAudioSharingProfilesConnected();
verify(mAssistant)
.registerServiceCallBack(
@@ -247,8 +251,8 @@
}
@Test
+ @DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStop_flagOff_doNothing() {
- mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.onStop(mLifecycleOwner);
verify(mAssistant, never())
.unregisterServiceCallBack(any(BluetoothLeBroadcastAssistant.Callback.class));
@@ -259,8 +263,8 @@
}
@Test
+ @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStop_flagOn_callbacksNotRegistered_doNothing() {
- mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.setCallbacksRegistered(false);
mController.onStop(mLifecycleOwner);
verify(mAssistant, never())
@@ -272,8 +276,8 @@
}
@Test
+ @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void onStop_flagOn_callbacksRegistered_unregisterCallbacks() {
- mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.setCallbacksRegistered(true);
mController.onStop(mLifecycleOwner);
verify(mAssistant)
@@ -284,16 +288,16 @@
}
@Test
+ @DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void displayPreference_flagOff_doNothing() {
- mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.displayPreference(mScreen);
assertThat(mPreferenceGroup.isVisible()).isFalse();
verify(mDeviceUpdater, never()).forceUpdate();
}
@Test
+ @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void displayPreference_flagOn_updateDeviceList() {
- mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.displayPreference(mScreen);
assertThat(mPreferenceGroup.isVisible()).isFalse();
verify(mDeviceUpdater).forceUpdate();
@@ -316,6 +320,24 @@
}
@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() {
Settings.Secure.putInt(
mContentResolver, BluetoothUtils.getPrimaryGroupIdUriForBroadcast(),
@@ -374,8 +396,8 @@
}
@Test
+ @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void updateVisibility_emptyPreferenceGroup_doNothing() {
- mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.setCallbacksRegistered(true);
mController.updateVisibility();
shadowOf(Looper.getMainLooper()).idle();
@@ -384,8 +406,8 @@
}
@Test
+ @DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void updateVisibility_flagOff_setVisibleToFalse() {
- mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.setCallbacksRegistered(true);
mPreferenceGroup.addPreference(mPreference1);
when(mBroadcast.isEnabled(null)).thenReturn(true);
@@ -399,8 +421,8 @@
}
@Test
+ @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void updateVisibility_notEmptyPreferenceGroup_noSharing_setVisibleToFalse() {
- mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.setCallbacksRegistered(true);
mPreferenceGroup.addPreference(mPreference1);
when(mBroadcast.isEnabled(null)).thenReturn(false);
@@ -414,8 +436,8 @@
}
@Test
+ @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void updateVisibility_notEmptyPreferenceGroup_isSharing_setVisibleToTrue() {
- mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mController.setCallbacksRegistered(true);
mPreferenceGroup.addPreference(mPreference1);
when(mBroadcast.isEnabled(null)).thenReturn(true);
@@ -429,6 +451,29 @@
}
@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() {
Settings.Secure.putInt(
mContentResolver, BluetoothUtils.getPrimaryGroupIdUriForBroadcast(),
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumePreferenceTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumePreferenceTest.java
index 5ff143f..c84d7f8 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumePreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumePreferenceTest.java
@@ -31,6 +31,9 @@
import android.bluetooth.BluetoothDevice;
import android.content.Context;
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.widget.SeekBar;
@@ -41,9 +44,11 @@
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+import com.android.settingslib.bluetooth.LeAudioProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import com.android.settingslib.bluetooth.VolumeControlProfile;
+import com.android.settingslib.flags.Flags;
import org.junit.Before;
import org.junit.Rule;
@@ -64,9 +69,11 @@
private static final int TEST_MIN_STREAM_VALUE = 0;
@Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule();
+ @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
@Mock private LocalBluetoothManager mLocalBtManager;
@Mock private LocalBluetoothProfileManager mLocalBtProfileManager;
+ @Mock private LeAudioProfile mLeAudioProfile;
@Mock private VolumeControlProfile mVolumeControl;
@Mock private CachedBluetoothDevice mCachedDevice;
@Mock private BluetoothDevice mDevice;
@@ -84,6 +91,7 @@
mFeatureFactory = FakeFeatureFactory.setupForTest();
when(mLocalBtManager.getProfileManager()).thenReturn(mLocalBtProfileManager);
when(mLocalBtProfileManager.getVolumeControlProfile()).thenReturn(mVolumeControl);
+ when(mLocalBtProfileManager.getLeAudioProfile()).thenReturn(mLeAudioProfile);
when(mContext.getSystemService(AudioManager.class)).thenReturn(mAudioManager);
when(mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC))
.thenReturn(TEST_MAX_STREAM_VALUE);
@@ -161,6 +169,70 @@
}
@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() {
Settings.Secure.putInt(
mContext.getContentResolver(),
@@ -179,6 +251,7 @@
}
@Test
+ @DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void onProgressChanged_fallbackDevice_fromUserNotInTouch_setDeviceVolume() {
Settings.Secure.putInt(
mContext.getContentResolver(),
@@ -197,6 +270,7 @@
}
@Test
+ @DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void onProgressChanged_fallbackDevice_fromUserInTouch_doNothing() {
Settings.Secure.putInt(
mContext.getContentResolver(),
@@ -215,6 +289,7 @@
}
@Test
+ @DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void onProgressChanged_fallbackDevice_notFromUserNotInTouch_doNothing() {
Settings.Secure.putInt(
mContext.getContentResolver(),
diff --git a/tests/unit/src/com/android/settings/network/telephony/satellite/SatelliteSettingAboutContentControllerTest.kt b/tests/unit/src/com/android/settings/network/telephony/satellite/SatelliteSettingAboutContentControllerTest.kt
index d070811..036cc3f 100644
--- a/tests/unit/src/com/android/settings/network/telephony/satellite/SatelliteSettingAboutContentControllerTest.kt
+++ b/tests/unit/src/com/android/settings/network/telephony/satellite/SatelliteSettingAboutContentControllerTest.kt
@@ -63,11 +63,9 @@
controller.displayPreference(screen)
assertThat(preference.title).isEqualTo(
- context.getString(
- R.string.description_about_satellite_setting,
- TEST_SIM_OPERATOR_NAME
+ "You can send and receive text messages and use some apps by satellite with an eligible Test Carrier account"
)
- )
+
}
private companion object {