Merge "[Output Switcher] Add preference route listing check" into tm-qpr-dev

This commit is contained in:
Shaowei Shen
2023-01-09 13:07:48 +00:00
committed by Android (Google) Code Review
4 changed files with 56 additions and 8 deletions

View File

@@ -190,6 +190,10 @@ public class InfoMediaManager extends MediaManager {
return !isGroup;
}
boolean preferRouteListingOrdering() {
return false;
}
/**
* Remove a {@code device} from current media.
*

View File

@@ -212,6 +212,15 @@ public class LocalMediaManager implements BluetoothCallback {
return mInfoMediaManager.isRoutingSessionAvailableForVolumeControl();
}
/**
* Returns if media app establishes a preferred route listing order.
*
* @return True if route list ordering exist and not using system ordering, false otherwise.
*/
public boolean isPreferenceRouteListingExist() {
return mInfoMediaManager.preferRouteListingOrdering();
}
/**
* Start scan connected MediaDevice
*/

View File

@@ -630,10 +630,11 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback,
private void buildMediaItems(List<MediaDevice> devices) {
synchronized (mMediaDevicesLock) {
//TODO(b/257851968): do the organization only when there's no suggested sorted order
// we get from application
attachRangeInfo(devices);
Collections.sort(devices, Comparator.naturalOrder());
if (!isRouteProcessSupported() || (isRouteProcessSupported()
&& !mLocalMediaManager.isPreferenceRouteListingExist())) {
attachRangeInfo(devices);
Collections.sort(devices, Comparator.naturalOrder());
}
// For the first time building list, to make sure the top device is the connected
// device.
if (mMediaItemList.isEmpty()) {
@@ -751,6 +752,10 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback,
return mFeatureFlags.isEnabled(Flags.OUTPUT_SWITCHER_ADVANCED_LAYOUT);
}
public boolean isRouteProcessSupported() {
return mFeatureFlags.isEnabled(Flags.OUTPUT_SWITCHER_ROUTES_PROCESSING);
}
List<MediaDevice> getGroupMediaDevices() {
final List<MediaDevice> selectedDevices = getSelectedMediaDevice();
final List<MediaDevice> selectableDevices = getSelectableMediaDevice();

View File

@@ -149,7 +149,9 @@ public class MediaOutputControllerTest extends SysuiTestCase {
Optional.of(mNearbyMediaDevicesManager), mAudioManager, mPowerExemptionManager,
mKeyguardManager, mFlags);
when(mFlags.isEnabled(Flags.OUTPUT_SWITCHER_ADVANCED_LAYOUT)).thenReturn(false);
when(mFlags.isEnabled(Flags.OUTPUT_SWITCHER_ROUTES_PROCESSING)).thenReturn(false);
mLocalMediaManager = spy(mMediaOutputController.mLocalMediaManager);
when(mLocalMediaManager.isPreferenceRouteListingExist()).thenReturn(false);
mMediaOutputController.mLocalMediaManager = mLocalMediaManager;
MediaDescription.Builder builder = new MediaDescription.Builder();
builder.setTitle(TEST_SONG);
@@ -167,9 +169,9 @@ public class MediaOutputControllerTest extends SysuiTestCase {
when(mNearbyDevice1.getMediaRoute2Id()).thenReturn(TEST_DEVICE_1_ID);
when(mNearbyDevice1.getRangeZone()).thenReturn(NearbyDevice.RANGE_CLOSE);
when(mNearbyDevice1.getRangeZone()).thenReturn(NearbyDevice.RANGE_FAR);
when(mNearbyDevice2.getMediaRoute2Id()).thenReturn(TEST_DEVICE_2_ID);
when(mNearbyDevice2.getRangeZone()).thenReturn(NearbyDevice.RANGE_FAR);
when(mNearbyDevice2.getRangeZone()).thenReturn(NearbyDevice.RANGE_CLOSE);
mNearbyDevices.add(mNearbyDevice1);
mNearbyDevices.add(mNearbyDevice2);
}
@@ -274,8 +276,20 @@ public class MediaOutputControllerTest extends SysuiTestCase {
mMediaOutputController.onDevicesUpdated(mNearbyDevices);
mMediaOutputController.onDeviceListUpdate(mMediaDevices);
verify(mMediaDevice1).setRangeZone(NearbyDevice.RANGE_CLOSE);
verify(mMediaDevice2).setRangeZone(NearbyDevice.RANGE_FAR);
verify(mMediaDevice1).setRangeZone(NearbyDevice.RANGE_FAR);
verify(mMediaDevice2).setRangeZone(NearbyDevice.RANGE_CLOSE);
}
@Test
public void onDeviceListUpdate_withNearbyDevices_rankByRangeInformation()
throws RemoteException {
mMediaOutputController.start(mCb);
reset(mCb);
mMediaOutputController.onDevicesUpdated(mNearbyDevices);
mMediaOutputController.onDeviceListUpdate(mMediaDevices);
assertThat(mMediaDevices.get(0).getId()).isEqualTo(TEST_DEVICE_1_ID);
}
@Test
@@ -291,6 +305,22 @@ public class MediaOutputControllerTest extends SysuiTestCase {
verify(mCb).onDeviceListChanged();
}
@Test
public void routeProcessSupport_onDeviceListUpdate_preferenceExist_NotUpdatesRangeInformation()
throws RemoteException {
when(mLocalMediaManager.isPreferenceRouteListingExist()).thenReturn(true);
when(mFlags.isEnabled(Flags.OUTPUT_SWITCHER_ROUTES_PROCESSING)).thenReturn(true);
when(mFlags.isEnabled(Flags.OUTPUT_SWITCHER_ADVANCED_LAYOUT)).thenReturn(true);
mMediaOutputController.start(mCb);
reset(mCb);
mMediaOutputController.onDevicesUpdated(mNearbyDevices);
mMediaOutputController.onDeviceListUpdate(mMediaDevices);
verify(mMediaDevice1, never()).setRangeZone(anyInt());
verify(mMediaDevice2, never()).setRangeZone(anyInt());
}
@Test
public void advanced_onDeviceListUpdate_verifyDeviceListCallback() {
when(mFlags.isEnabled(Flags.OUTPUT_SWITCHER_ADVANCED_LAYOUT)).thenReturn(true);