[Output switcher] Change to use selected routes
Use selected routes as a consistent way for checking current output. Selected route will also work no matter what type device is current output, we can directly use it to indicate current output. Bug: 279003337 Test: make -j64 RunSettingsLibRoboTests Change-Id: Ifdc2af2c7d2ea4754003d2178c24ba2f343483aa
This commit is contained in:
committed by
Shaowei Shen
parent
385ab32421
commit
a07e185f5e
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<>());
|
||||
|
||||
Reference in New Issue
Block a user