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

This commit is contained in:
Shaowei Shen
2023-05-09 06:29:55 +00:00
committed by Android (Google) Code Review
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. //TODO(b/148765806): use correct device type once api is ready.
mediaDevice = new InfoMediaDevice(mContext, mRouterManager, route, mediaDevice = new InfoMediaDevice(mContext, mRouterManager, route,
mPackageName, mPreferenceItemMap.get(route.getId())); mPackageName, mPreferenceItemMap.get(route.getId()));
if (!TextUtils.isEmpty(mPackageName)
&& getRoutingSessionInfo().getSelectedRoutes().contains(route.getId())) {
mediaDevice.setState(STATE_SELECTED);
if (mCurrentConnectedDevice == null) {
mCurrentConnectedDevice = mediaDevice;
}
}
break; break;
case TYPE_BUILTIN_SPEAKER: case TYPE_BUILTIN_SPEAKER:
case TYPE_USB_DEVICE: case TYPE_USB_DEVICE:
@@ -581,7 +574,13 @@ public class InfoMediaManager extends MediaManager {
break; break;
} }
if (mediaDevice != null && !TextUtils.isEmpty(mPackageName)
&& getRoutingSessionInfo().getSelectedRoutes().contains(route.getId())) {
mediaDevice.setState(STATE_SELECTED);
if (mCurrentConnectedDevice == null) {
mCurrentConnectedDevice = mediaDevice;
}
}
if (mediaDevice != null) { if (mediaDevice != null) {
mMediaDevices.add(mediaDevice); 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_NETWORK_ERROR;
import static android.media.MediaRoute2ProviderService.REASON_UNKNOWN_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 com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
@@ -1005,6 +1007,37 @@ public class InfoMediaManagerTest {
assertThat(mInfoMediaManager.mMediaDevices.size()).isEqualTo(0); 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 @Test
public void shouldDisableMediaOutput_infosIsEmpty_returnsTrue() { public void shouldDisableMediaOutput_infosIsEmpty_returnsTrue() {
mShadowRouter2Manager.setTransferableRoutes(new ArrayList<>()); mShadowRouter2Manager.setTransferableRoutes(new ArrayList<>());