Merge "[Output switcher] Change to use selected routes" into udc-dev am: d1575fb232

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23011724

Change-Id: Icff9b3751c2fda03864bed0fa390f104aea36cee
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Shaowei Shen
2023-05-09 11:13:48 +00:00
committed by Automerger Merge Worker
2 changed files with 40 additions and 8 deletions

View File

@@ -542,13 +542,6 @@ public class InfoMediaManager extends MediaManager {
//TODO(b/148765806): use correct device type once api is ready.
mediaDevice = new InfoMediaDevice(mContext, mRouterManager, route,
mPackageName, mPreferenceItemMap.get(route.getId()));
if (!TextUtils.isEmpty(mPackageName)
&& getRoutingSessionInfo().getSelectedRoutes().contains(route.getId())) {
mediaDevice.setState(STATE_SELECTED);
if (mCurrentConnectedDevice == null) {
mCurrentConnectedDevice = mediaDevice;
}
}
break;
case TYPE_BUILTIN_SPEAKER:
case TYPE_USB_DEVICE:
@@ -581,7 +574,13 @@ public class InfoMediaManager extends MediaManager {
break;
}
if (mediaDevice != null && !TextUtils.isEmpty(mPackageName)
&& getRoutingSessionInfo().getSelectedRoutes().contains(route.getId())) {
mediaDevice.setState(STATE_SELECTED);
if (mCurrentConnectedDevice == null) {
mCurrentConnectedDevice = mediaDevice;
}
}
if (mediaDevice != null) {
mMediaDevices.add(mediaDevice);
}

View File

@@ -25,6 +25,8 @@ import static android.media.MediaRoute2Info.TYPE_WIRED_HEADSET;
import static android.media.MediaRoute2ProviderService.REASON_NETWORK_ERROR;
import static android.media.MediaRoute2ProviderService.REASON_UNKNOWN_ERROR;
import static com.android.settingslib.media.LocalMediaManager.MediaDeviceState.STATE_SELECTED;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
@@ -1005,6 +1007,37 @@ public class InfoMediaManagerTest {
assertThat(mInfoMediaManager.mMediaDevices.size()).isEqualTo(0);
}
@Test
public void addMediaDevice_deviceIncludedInSelectedDevices_shouldSetAsCurrentConnected() {
final MediaRoute2Info route2Info = mock(MediaRoute2Info.class);
final CachedBluetoothDeviceManager cachedBluetoothDeviceManager =
mock(CachedBluetoothDeviceManager.class);
final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class);
final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>();
final RoutingSessionInfo sessionInfo = mock(RoutingSessionInfo.class);
routingSessionInfos.add(sessionInfo);
when(mRouterManager.getRoutingSessions(TEST_PACKAGE_NAME)).thenReturn(routingSessionInfos);
when(sessionInfo.getSelectedRoutes()).thenReturn(ImmutableList.of(TEST_ID));
when(route2Info.getType()).thenReturn(TYPE_BLUETOOTH_A2DP);
when(route2Info.getAddress()).thenReturn("00:00:00:00:00:00");
when(route2Info.getId()).thenReturn(TEST_ID);
when(mLocalBluetoothManager.getCachedDeviceManager())
.thenReturn(cachedBluetoothDeviceManager);
when(cachedBluetoothDeviceManager.findDevice(any(BluetoothDevice.class)))
.thenReturn(cachedDevice);
mInfoMediaManager.mRouterManager = mRouterManager;
mInfoMediaManager.mMediaDevices.clear();
mInfoMediaManager.addMediaDevice(route2Info);
MediaDevice device = mInfoMediaManager.mMediaDevices.get(0);
assertThat(device instanceof BluetoothMediaDevice).isTrue();
assertThat(device.getState()).isEqualTo(STATE_SELECTED);
assertThat(mInfoMediaManager.getCurrentConnectedDevice()).isEqualTo(device);
}
@Test
public void shouldDisableMediaOutput_infosIsEmpty_returnsTrue() {
mShadowRouter2Manager.setTransferableRoutes(new ArrayList<>());