Merge "[Audiosharing] Clean up dup codes" into main

This commit is contained in:
Yiyi Shen
2024-07-31 05:20:39 +00:00
committed by Android (Google) Code Review
37 changed files with 182 additions and 302 deletions

View File

@@ -99,7 +99,7 @@ public class AudioSharingCallAudioDialogFragmentTest {
mParent = new Fragment();
FragmentController.setupFragment(
mParent, FragmentActivity.class, /* containerViewId= */ 0, /* bundle= */ null);
AudioSharingCallAudioDialogFragment.show(mParent, new ArrayList<>(), (item) -> {});
AudioSharingCallAudioDialogFragment.show(mParent, new ArrayList<>(), -1, (item) -> {});
shadowMainLooper().idle();
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
assertThat(dialog).isNull();
@@ -109,7 +109,7 @@ public class AudioSharingCallAudioDialogFragmentTest {
public void onCreateDialog_unattachedFragment_dialogNotExist() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
mParent = new Fragment();
AudioSharingCallAudioDialogFragment.show(mParent, new ArrayList<>(), (item) -> {});
AudioSharingCallAudioDialogFragment.show(mParent, new ArrayList<>(), -1, (item) -> {});
shadowMainLooper().idle();
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
assertThat(dialog).isNull();
@@ -138,7 +138,7 @@ public class AudioSharingCallAudioDialogFragmentTest {
ArrayList<AudioSharingDeviceItem> deviceItemList = new ArrayList<>();
deviceItemList.add(TEST_DEVICE_ITEM1);
deviceItemList.add(TEST_DEVICE_ITEM2);
AudioSharingCallAudioDialogFragment.show(mParent, deviceItemList, (item) -> {});
AudioSharingCallAudioDialogFragment.show(mParent, deviceItemList, 0, (item) -> {});
shadowMainLooper().idle();
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
assertThat(dialog).isNotNull();

View File

@@ -16,7 +16,6 @@
package com.android.settings.connecteddevice.audiosharing;
import static com.android.settings.connecteddevice.audiosharing.AudioSharingUtils.SETTINGS_KEY_FALLBACK_DEVICE_GROUP_ID;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
@@ -64,6 +63,7 @@ import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
import com.android.settings.testutils.shadow.ShadowThreadUtils;
import com.android.settingslib.bluetooth.BluetoothEventManager;
import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast;
@@ -197,7 +197,8 @@ public class AudioSharingCallAudioPreferenceControllerTest {
verify(mBtEventManager, never()).registerCallback(mController);
verify(mContentResolver, never())
.registerContentObserver(
Settings.Secure.getUriFor(SETTINGS_KEY_FALLBACK_DEVICE_GROUP_ID),
Settings.Secure.getUriFor(
BluetoothUtils.getPrimaryGroupIdUriForBroadcast()),
false,
mContentObserver);
verify(mAssistant, never())
@@ -211,7 +212,8 @@ public class AudioSharingCallAudioPreferenceControllerTest {
verify(mBtEventManager).registerCallback(mController);
verify(mContentResolver)
.registerContentObserver(
Settings.Secure.getUriFor(SETTINGS_KEY_FALLBACK_DEVICE_GROUP_ID),
Settings.Secure.getUriFor(
BluetoothUtils.getPrimaryGroupIdUriForBroadcast()),
false,
mContentObserver);
verify(mAssistant)
@@ -319,9 +321,7 @@ public class AudioSharingCallAudioPreferenceControllerTest {
public void onProfileConnectionStateChanged_noDeviceInSharing_updateSummary() {
Settings.Secure.putInt(mContentResolver, TEST_SETTINGS_KEY, TEST_DEVICE_GROUP_ID1);
when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(ImmutableList.of());
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of());
mController.displayPreference(mScreen);
mPreference.setSummary("test");
mController.onProfileConnectionStateChanged(
@@ -340,9 +340,7 @@ public class AudioSharingCallAudioPreferenceControllerTest {
when(mCachedDevice1.getName()).thenReturn(TEST_DEVICE_NAME1);
when(mCacheManager.findDevice(mDevice1)).thenReturn(mCachedDevice1);
when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(ImmutableList.of(mDevice1));
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1));
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState));
mController.displayPreference(mScreen);
mContentObserver.onChange(true);
@@ -369,8 +367,7 @@ public class AudioSharingCallAudioPreferenceControllerTest {
when(mCacheManager.findDevice(mDevice2)).thenReturn(mCachedDevice2);
when(mCacheManager.findDevice(mDevice3)).thenReturn(mCachedDevice3);
when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
when(mAssistant.getAllConnectedDevices())
.thenReturn(ImmutableList.of(mDevice1, mDevice2, mDevice3));
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState));
mController.displayPreference(mScreen);
@@ -389,9 +386,7 @@ public class AudioSharingCallAudioPreferenceControllerTest {
when(mCachedDevice1.getName()).thenReturn(TEST_DEVICE_NAME1);
when(mCacheManager.findDevice(mDevice1)).thenReturn(mCachedDevice1);
when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(ImmutableList.of(mDevice1));
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1));
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState));
mController.displayPreference(mScreen);
shadowOf(Looper.getMainLooper()).idle();
@@ -403,9 +398,7 @@ public class AudioSharingCallAudioPreferenceControllerTest {
Settings.Secure.putInt(
mContentResolver, TEST_SETTINGS_KEY, BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(ImmutableList.of());
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of());
mController.displayPreference(mScreen);
shadowOf(Looper.getMainLooper()).idle();
assertThat(mPreference.getSummary().toString()).isEmpty();
@@ -429,9 +422,7 @@ public class AudioSharingCallAudioPreferenceControllerTest {
when(mCacheManager.findDevice(mDevice2)).thenReturn(mCachedDevice2);
mShadowBluetoothAdapter.setMostRecentlyConnectedDevices(List.of(mDevice1, mDevice2));
when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(ImmutableList.of(mDevice1, mDevice2));
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1, mDevice2));
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState));
mController.init(mParentFragment);
mController.displayPreference(mScreen);
@@ -521,18 +512,14 @@ public class AudioSharingCallAudioPreferenceControllerTest {
Settings.Secure.putInt(
mContentResolver, TEST_SETTINGS_KEY, BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(ImmutableList.of());
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of());
mController.displayPreference(mScreen);
shadowOf(Looper.getMainLooper()).idle();
assertThat(mPreference.getSummary().toString()).isEmpty();
// onReceiveStateChanged will update summary
Settings.Secure.putInt(mContentResolver, TEST_SETTINGS_KEY, TEST_DEVICE_GROUP_ID1);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(ImmutableList.of(mDevice1));
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1));
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState));
mController.mBroadcastAssistantCallback.onReceiveStateChanged(
mDevice1, /* sourceId= */ 1, mState);
@@ -552,17 +539,13 @@ public class AudioSharingCallAudioPreferenceControllerTest {
Settings.Secure.putInt(
mContentResolver, TEST_SETTINGS_KEY, BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(ImmutableList.of());
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);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(ImmutableList.of(mDevice1));
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);

View File

@@ -16,8 +16,6 @@
package com.android.settings.connecteddevice.audiosharing;
import static com.android.settings.connecteddevice.audiosharing.AudioSharingUtils.SETTINGS_KEY_FALLBACK_DEVICE_GROUP_ID;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
@@ -59,6 +57,7 @@ import com.android.settings.connecteddevice.DevicePreferenceCallback;
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
import com.android.settings.testutils.shadow.ShadowThreadUtils;
import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast;
@@ -208,7 +207,8 @@ public class AudioSharingDeviceVolumeGroupControllerTest {
.registerCallback(any(Executor.class), any(BluetoothVolumeControl.Callback.class));
verify(mContentResolver, never())
.registerContentObserver(
Settings.Secure.getUriFor(SETTINGS_KEY_FALLBACK_DEVICE_GROUP_ID),
Settings.Secure.getUriFor(
BluetoothUtils.getPrimaryGroupIdUriForBroadcast()),
false,
mContentObserver);
}
@@ -223,11 +223,9 @@ public class AudioSharingDeviceVolumeGroupControllerTest {
verify(mDeviceUpdater).registerCallback();
verify(mVolumeControl)
.registerCallback(any(Executor.class), any(BluetoothVolumeControl.Callback.class));
verify(mContentResolver)
.registerContentObserver(
Settings.Secure.getUriFor(SETTINGS_KEY_FALLBACK_DEVICE_GROUP_ID),
false,
mContentObserver);
verify(mContentResolver).registerContentObserver(
Settings.Secure.getUriFor(BluetoothUtils.getPrimaryGroupIdUriForBroadcast()), false,
mContentObserver);
}
@Test
@@ -242,7 +240,8 @@ public class AudioSharingDeviceVolumeGroupControllerTest {
.registerCallback(any(Executor.class), any(BluetoothVolumeControl.Callback.class));
verify(mContentResolver)
.registerContentObserver(
Settings.Secure.getUriFor(SETTINGS_KEY_FALLBACK_DEVICE_GROUP_ID),
Settings.Secure.getUriFor(
BluetoothUtils.getPrimaryGroupIdUriForBroadcast()),
false,
mContentObserver);
}
@@ -317,7 +316,8 @@ public class AudioSharingDeviceVolumeGroupControllerTest {
@Test
public void onDeviceAdded_rankFallbackDeviceOnTop() {
Settings.Secure.putInt(
mContentResolver, SETTINGS_KEY_FALLBACK_DEVICE_GROUP_ID, TEST_DEVICE_GROUP_ID2);
mContentResolver, BluetoothUtils.getPrimaryGroupIdUriForBroadcast(),
TEST_DEVICE_GROUP_ID2);
when(mPreference1.getProgress()).thenReturn(TEST_VOLUME_VALUE);
when(mPreference2.getProgress()).thenReturn(TEST_VOLUME_VALUE);
mController.setPreferenceGroup(mPreferenceGroup);
@@ -427,7 +427,8 @@ public class AudioSharingDeviceVolumeGroupControllerTest {
@Test
public void settingsObserverOnChange_updatePreferenceOrder() {
Settings.Secure.putInt(
mContentResolver, SETTINGS_KEY_FALLBACK_DEVICE_GROUP_ID, TEST_DEVICE_GROUP_ID2);
mContentResolver, BluetoothUtils.getPrimaryGroupIdUriForBroadcast(),
TEST_DEVICE_GROUP_ID2);
when(mPreference1.getProgress()).thenReturn(TEST_VOLUME_VALUE);
when(mPreference2.getProgress()).thenReturn(TEST_VOLUME_VALUE);
mController.setPreferenceGroup(mPreferenceGroup);
@@ -435,8 +436,8 @@ public class AudioSharingDeviceVolumeGroupControllerTest {
mController.onDeviceAdded(mPreference2);
shadowOf(Looper.getMainLooper()).idle();
Settings.Secure.putInt(
mContentResolver, SETTINGS_KEY_FALLBACK_DEVICE_GROUP_ID, TEST_DEVICE_GROUP_ID1);
Settings.Secure.putInt(mContentResolver, BluetoothUtils.getPrimaryGroupIdUriForBroadcast(),
TEST_DEVICE_GROUP_ID1);
mContentObserver.onChange(true);
shadowOf(Looper.getMainLooper()).idle();

View File

@@ -35,7 +35,6 @@ import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothLeBroadcast;
import android.bluetooth.BluetoothLeBroadcastMetadata;
import android.bluetooth.BluetoothLeBroadcastReceiveState;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothStatusCodes;
import android.content.Context;
import android.os.Looper;
@@ -187,9 +186,7 @@ public class AudioSharingDialogHandlerTest {
public void handleUserTriggeredNonLeaDeviceConnected_noSharing_setActive() {
setUpBroadcast(false);
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice2);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(deviceList);
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
mHandler.handleDeviceConnected(mCachedDevice2, /* userTriggered= */ true);
shadowOf(Looper.getMainLooper()).idle();
@@ -200,9 +197,7 @@ public class AudioSharingDialogHandlerTest {
public void handleUserTriggeredNonLeaDeviceConnected_sharing_showStopDialog() {
setUpBroadcast(true);
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice2);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(deviceList);
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState));
mHandler.handleDeviceConnected(mCachedDevice2, /* userTriggered= */ true);
shadowOf(Looper.getMainLooper()).idle();
@@ -239,9 +234,7 @@ public class AudioSharingDialogHandlerTest {
public void handleUserTriggeredLeaDeviceConnected_noSharingNoTwoLeaDevices_setActive() {
setUpBroadcast(false);
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(deviceList);
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ true);
shadowOf(Looper.getMainLooper()).idle();
@@ -254,9 +247,7 @@ public class AudioSharingDialogHandlerTest {
when(mCachedDevice1.getGroupId()).thenReturn(-1);
when(mLeAudioProfile.getGroupId(mDevice1)).thenReturn(-1);
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1, mDevice3);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(deviceList);
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ true);
shadowOf(Looper.getMainLooper()).idle();
@@ -269,9 +260,7 @@ public class AudioSharingDialogHandlerTest {
public void handleUserTriggeredLeaDeviceConnected_noSharingTwoLeaDevices_showJoinDialog() {
setUpBroadcast(false);
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1, mDevice3);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(deviceList);
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ true);
shadowOf(Looper.getMainLooper()).idle();
@@ -314,9 +303,7 @@ public class AudioSharingDialogHandlerTest {
public void handleUserTriggeredLeaDeviceConnected_sharing_showJoinDialog() {
setUpBroadcast(true);
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1, mDevice3);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(deviceList);
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
when(mAssistant.getAllSources(mDevice1)).thenReturn(ImmutableList.of());
when(mAssistant.getAllSources(mDevice3)).thenReturn(ImmutableList.of(mState));
mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ true);
@@ -361,9 +348,7 @@ public class AudioSharingDialogHandlerTest {
handleUserTriggeredLeaDeviceConnected_sharingWithTwoLeaDevices_showDisconnectDialog() {
setUpBroadcast(true);
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1, mDevice3, mDevice4);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(deviceList);
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
when(mAssistant.getAllSources(mDevice1)).thenReturn(ImmutableList.of());
when(mAssistant.getAllSources(mDevice3)).thenReturn(ImmutableList.of(mState));
when(mAssistant.getAllSources(mDevice4)).thenReturn(ImmutableList.of(mState));
@@ -407,9 +392,7 @@ public class AudioSharingDialogHandlerTest {
public void handleNonLeaDeviceConnected_noSharing_doNothing() {
setUpBroadcast(false);
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice2);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(deviceList);
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
mHandler.handleDeviceConnected(mCachedDevice2, /* userTriggered= */ false);
shadowOf(Looper.getMainLooper()).idle();
@@ -420,9 +403,7 @@ public class AudioSharingDialogHandlerTest {
public void handleNonLeaDeviceConnected_sharing_showStopDialog() {
setUpBroadcast(true);
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(deviceList);
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState));
mHandler.handleDeviceConnected(mCachedDevice2, /* userTriggered= */ false);
shadowOf(Looper.getMainLooper()).idle();
@@ -459,9 +440,7 @@ public class AudioSharingDialogHandlerTest {
public void handleLeaDeviceConnected_noSharingNoTwoLeaDevices_doNothing() {
setUpBroadcast(false);
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(deviceList);
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ false);
shadowOf(Looper.getMainLooper()).idle();
@@ -474,9 +453,7 @@ public class AudioSharingDialogHandlerTest {
when(mCachedDevice1.getGroupId()).thenReturn(-1);
when(mLeAudioProfile.getGroupId(mDevice1)).thenReturn(-1);
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1, mDevice3);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(deviceList);
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ false);
shadowOf(Looper.getMainLooper()).idle();
@@ -489,9 +466,7 @@ public class AudioSharingDialogHandlerTest {
public void handleLeaDeviceConnected_noSharingTwoLeaDevices_showJoinDialog() {
setUpBroadcast(false);
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1, mDevice3);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(deviceList);
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ false);
shadowOf(Looper.getMainLooper()).idle();
@@ -534,9 +509,7 @@ public class AudioSharingDialogHandlerTest {
public void handleLeaDeviceConnected_sharing_showJoinDialog() {
setUpBroadcast(true);
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1, mDevice3);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(deviceList);
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
when(mAssistant.getAllSources(mDevice1)).thenReturn(ImmutableList.of());
when(mAssistant.getAllSources(mDevice3)).thenReturn(ImmutableList.of(mState));
mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ false);
@@ -580,9 +553,7 @@ public class AudioSharingDialogHandlerTest {
public void handleLeaDeviceConnected_sharingWithTwoLeaDevices_showDisconnectDialog() {
setUpBroadcast(true);
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1, mDevice3, mDevice4);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(deviceList);
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
when(mAssistant.getAllSources(mDevice1)).thenReturn(ImmutableList.of());
when(mAssistant.getAllSources(mDevice3)).thenReturn(ImmutableList.of(mState));
when(mAssistant.getAllSources(mDevice4)).thenReturn(ImmutableList.of(mState));
@@ -627,9 +598,7 @@ public class AudioSharingDialogHandlerTest {
// Show join dialog
setUpBroadcast(false);
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1, mDevice3);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(deviceList);
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ true);
shadowOf(Looper.getMainLooper()).idle();
@@ -661,9 +630,7 @@ public class AudioSharingDialogHandlerTest {
// Show disconnect dialog
setUpBroadcast(true);
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1, mDevice3, mDevice4);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(deviceList);
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
when(mAssistant.getAllSources(mDevice1)).thenReturn(ImmutableList.of());
when(mAssistant.getAllSources(mDevice3)).thenReturn(ImmutableList.of(mState));
when(mAssistant.getAllSources(mDevice4)).thenReturn(ImmutableList.of(mState));
@@ -697,9 +664,7 @@ public class AudioSharingDialogHandlerTest {
// Show stop dialog
setUpBroadcast(true);
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(deviceList);
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState));
mHandler.handleDeviceConnected(mCachedDevice2, /* userTriggered= */ true);
shadowOf(Looper.getMainLooper()).idle();
@@ -721,9 +686,7 @@ public class AudioSharingDialogHandlerTest {
public void closeOpeningDialogsOtherThan() {
setUpBroadcast(true);
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice3);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(deviceList);
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
when(mAssistant.getAllSources(mDevice3)).thenReturn(ImmutableList.of(mState));
mHandler.handleDeviceConnected(mCachedDevice2, /* userTriggered= */ true);
shadowOf(Looper.getMainLooper()).idle();
@@ -733,9 +696,7 @@ public class AudioSharingDialogHandlerTest {
.containsExactly(AudioSharingStopDialogFragment.tag());
deviceList = ImmutableList.of(mDevice1, mDevice3);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(deviceList);
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
when(mAssistant.getAllSources(mDevice1)).thenReturn(ImmutableList.of());
mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ false);
shadowOf(Looper.getMainLooper()).idle();
@@ -769,9 +730,7 @@ public class AudioSharingDialogHandlerTest {
public void onBroadcastStartFailed_logAction() {
setUpBroadcast(false);
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1, mDevice3);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(deviceList);
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ false);
shadowOf(Looper.getMainLooper()).idle();
@@ -797,9 +756,7 @@ public class AudioSharingDialogHandlerTest {
public void onPlaybackStarted_addSource() {
setUpBroadcast(false);
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1, mDevice3);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(deviceList);
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ true);
shadowOf(Looper.getMainLooper()).idle();
@@ -825,9 +782,7 @@ public class AudioSharingDialogHandlerTest {
public void onBroadcastStopFailed_logAction() {
setUpBroadcast(true);
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(deviceList);
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState));
mHandler.handleDeviceConnected(mCachedDevice2, /* userTriggered= */ false);
shadowOf(Looper.getMainLooper()).idle();

View File

@@ -378,9 +378,7 @@ public class AudioSharingSwitchBarControllerTest {
FeatureFlagUtils.setEnabled(
mContext, FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, true);
when(mBtnView.isEnabled()).thenReturn(true);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(ImmutableList.of());
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of());
doNothing().when(mBroadcast).startPrivateBroadcast();
mController.onCheckedChanged(mBtnView, /* isChecked= */ true);
assertThat(mSwitchBar.isChecked()).isFalse();
@@ -392,9 +390,7 @@ public class AudioSharingSwitchBarControllerTest {
FeatureFlagUtils.setEnabled(
mContext, FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, false);
when(mBtnView.isEnabled()).thenReturn(true);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(ImmutableList.of());
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of());
doNothing().when(mBroadcast).startPrivateBroadcast();
mController.onCheckedChanged(mBtnView, /* isChecked= */ true);
verify(mBroadcast).startPrivateBroadcast();
@@ -405,9 +401,7 @@ public class AudioSharingSwitchBarControllerTest {
FeatureFlagUtils.setEnabled(
mContext, FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, true);
when(mBtnView.isEnabled()).thenReturn(true);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(ImmutableList.of(mDevice1));
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1));
doNothing().when(mBroadcast).startPrivateBroadcast();
mController.onCheckedChanged(mBtnView, /* isChecked= */ true);
verify(mBroadcast).startPrivateBroadcast();
@@ -437,9 +431,7 @@ public class AudioSharingSwitchBarControllerTest {
FeatureFlagUtils.setEnabled(
mContext, FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, true);
when(mBtnView.isEnabled()).thenReturn(true);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(ImmutableList.of(mDevice2, mDevice1));
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice2, mDevice1));
doNothing().when(mBroadcast).startPrivateBroadcast();
mController =
new AudioSharingSwitchBarController(
@@ -469,9 +461,7 @@ public class AudioSharingSwitchBarControllerTest {
FeatureFlagUtils.setEnabled(
mContext, FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, true);
when(mBtnView.isEnabled()).thenReturn(true);
when(mAssistant.getDevicesMatchingConnectionStates(
new int[] {BluetoothProfile.STATE_CONNECTED}))
.thenReturn(ImmutableList.of(mDevice2, mDevice1));
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice2, mDevice1));
doNothing().when(mBroadcast).startPrivateBroadcast();
mController.onCheckedChanged(mBtnView, /* isChecked= */ true);
verify(mBroadcast).startPrivateBroadcast();

View File

@@ -219,7 +219,7 @@ public class AudioStreamConfirmDialogTest {
public void showDialog_noMetadata() {
List<BluetoothDevice> devices = new ArrayList<>();
devices.add(mBluetoothDevice);
when(mAssistant.getDevicesMatchingConnectionStates(any())).thenReturn(devices);
when(mAssistant.getAllConnectedDevices()).thenReturn(devices);
when(mBluetoothDevice.getAlias()).thenReturn(DEVICE_NAME);
FragmentController.setupFragment(
@@ -267,7 +267,7 @@ public class AudioStreamConfirmDialogTest {
public void showDialog_invalidMetadata() {
List<BluetoothDevice> devices = new ArrayList<>();
devices.add(mBluetoothDevice);
when(mAssistant.getDevicesMatchingConnectionStates(any())).thenReturn(devices);
when(mAssistant.getAllConnectedDevices()).thenReturn(devices);
when(mBluetoothDevice.getAlias()).thenReturn(DEVICE_NAME);
Intent intent = new Intent();
@@ -318,7 +318,7 @@ public class AudioStreamConfirmDialogTest {
public void showDialog_confirmListen() {
List<BluetoothDevice> devices = new ArrayList<>();
devices.add(mBluetoothDevice);
when(mAssistant.getDevicesMatchingConnectionStates(any())).thenReturn(devices);
when(mAssistant.getAllConnectedDevices()).thenReturn(devices);
when(mBluetoothDevice.getAlias()).thenReturn("");
Intent intent = new Intent();

View File

@@ -91,7 +91,7 @@ public class AudioStreamsHelperTest {
@Test
public void addSource_noDevice_doNothing() {
when(mAssistant.getDevicesMatchingConnectionStates(any()))
when(mAssistant.getAllConnectedDevices())
.thenReturn(Collections.emptyList());
mHelper.addSource(mMetadata);
@@ -102,7 +102,7 @@ public class AudioStreamsHelperTest {
public void addSource_hasDevice() {
List<BluetoothDevice> devices = new ArrayList<>();
devices.add(mDevice);
when(mAssistant.getDevicesMatchingConnectionStates(any())).thenReturn(devices);
when(mAssistant.getAllConnectedDevices()).thenReturn(devices);
when(mDeviceManager.findDevice(any())).thenReturn(mCachedDevice);
when(mCachedDevice.getDevice()).thenReturn(mDevice);
when(mCachedDevice.getGroupId()).thenReturn(GROUP_ID);
@@ -114,7 +114,7 @@ public class AudioStreamsHelperTest {
@Test
public void removeSource_noDevice_doNothing() {
when(mAssistant.getDevicesMatchingConnectionStates(any()))
when(mAssistant.getAllConnectedDevices())
.thenReturn(Collections.emptyList());
mHelper.removeSource(BROADCAST_ID_1);
@@ -125,7 +125,7 @@ public class AudioStreamsHelperTest {
public void removeSource_noConnectedSource_doNothing() {
List<BluetoothDevice> devices = new ArrayList<>();
devices.add(mDevice);
when(mAssistant.getDevicesMatchingConnectionStates(any())).thenReturn(devices);
when(mAssistant.getAllConnectedDevices()).thenReturn(devices);
BluetoothLeBroadcastReceiveState source = mock(BluetoothLeBroadcastReceiveState.class);
when(source.getBroadcastId()).thenReturn(BROADCAST_ID_2);
when(mDeviceManager.findDevice(any())).thenReturn(mCachedDevice);
@@ -142,7 +142,7 @@ public class AudioStreamsHelperTest {
public void removeSource_hasConnectedSource() {
List<BluetoothDevice> devices = new ArrayList<>();
devices.add(mDevice);
when(mAssistant.getDevicesMatchingConnectionStates(any())).thenReturn(devices);
when(mAssistant.getAllConnectedDevices()).thenReturn(devices);
BluetoothLeBroadcastReceiveState source = mock(BluetoothLeBroadcastReceiveState.class);
when(source.getBroadcastId()).thenReturn(BROADCAST_ID_2);
when(mDeviceManager.findDevice(any())).thenReturn(mCachedDevice);
@@ -164,7 +164,7 @@ public class AudioStreamsHelperTest {
var memberDevice = mock(BluetoothDevice.class);
devices.add(mDevice);
devices.add(memberDevice);
when(mAssistant.getDevicesMatchingConnectionStates(any())).thenReturn(devices);
when(mAssistant.getAllConnectedDevices()).thenReturn(devices);
BluetoothLeBroadcastReceiveState source = mock(BluetoothLeBroadcastReceiveState.class);
when(source.getBroadcastId()).thenReturn(BROADCAST_ID_2);
when(mDeviceManager.findDevice(any())).thenReturn(mCachedDevice);
@@ -196,7 +196,7 @@ public class AudioStreamsHelperTest {
public void getAllConnectedSources_returnSource() {
List<BluetoothDevice> devices = new ArrayList<>();
devices.add(mDevice);
when(mAssistant.getDevicesMatchingConnectionStates(any())).thenReturn(devices);
when(mAssistant.getAllConnectedDevices()).thenReturn(devices);
BluetoothLeBroadcastReceiveState source = mock(BluetoothLeBroadcastReceiveState.class);
when(mDeviceManager.findDevice(any())).thenReturn(mCachedDevice);
when(mCachedDevice.getDevice()).thenReturn(mDevice);
@@ -222,7 +222,7 @@ public class AudioStreamsHelperTest {
public void startMediaService_hasDevice() {
List<BluetoothDevice> devices = new ArrayList<>();
devices.add(mDevice);
when(mAssistant.getDevicesMatchingConnectionStates(any())).thenReturn(devices);
when(mAssistant.getAllConnectedDevices()).thenReturn(devices);
BluetoothLeBroadcastReceiveState source = mock(BluetoothLeBroadcastReceiveState.class);
when(mDeviceManager.findDevice(any())).thenReturn(mCachedDevice);
when(mCachedDevice.getDevice()).thenReturn(mDevice);