Loading packages/SettingsLib/src/com/android/settingslib/media/InfoMediaManager.java +9 −79 Original line number Original line Diff line number Diff line Loading @@ -92,13 +92,13 @@ public abstract class InfoMediaManager extends MediaManager { } } } } protected String mPackageName; @NonNull protected final String mPackageName; private MediaDevice mCurrentConnectedDevice; private MediaDevice mCurrentConnectedDevice; private final LocalBluetoothManager mBluetoothManager; private final LocalBluetoothManager mBluetoothManager; private final Map<String, RouteListingPreference.Item> mPreferenceItemMap = private final Map<String, RouteListingPreference.Item> mPreferenceItemMap = new ConcurrentHashMap<>(); new ConcurrentHashMap<>(); public InfoMediaManager( /* package */ InfoMediaManager( Context context, Context context, @NonNull String packageName, @NonNull String packageName, Notification notification, Notification notification, Loading @@ -112,7 +112,7 @@ public abstract class InfoMediaManager extends MediaManager { /** Creates an instance of InfoMediaManager. */ /** Creates an instance of InfoMediaManager. */ public static InfoMediaManager createInstance( public static InfoMediaManager createInstance( Context context, Context context, String packageName, @Nullable String packageName, Notification notification, Notification notification, LocalBluetoothManager localBluetoothManager) { LocalBluetoothManager localBluetoothManager) { Loading Loading @@ -148,8 +148,7 @@ public abstract class InfoMediaManager extends MediaManager { } } private void updateRouteListingPreference() { private void updateRouteListingPreference() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { && !TextUtils.isEmpty(mPackageName)) { RouteListingPreference routeListingPreference = RouteListingPreference routeListingPreference = getRouteListingPreference(); getRouteListingPreference(); Api34Impl.onRouteListingPreferenceUpdated(routeListingPreference, Api34Impl.onRouteListingPreferenceUpdated(routeListingPreference, Loading Loading @@ -218,12 +217,8 @@ public abstract class InfoMediaManager extends MediaManager { protected final void rebuildDeviceList() { protected final void rebuildDeviceList() { mMediaDevices.clear(); mMediaDevices.clear(); mCurrentConnectedDevice = null; mCurrentConnectedDevice = null; if (TextUtils.isEmpty(mPackageName)) { buildAllRoutes(); } else { buildAvailableRoutes(); buildAvailableRoutes(); } } } protected final void notifyCurrentConnectedDeviceChanged() { protected final void notifyCurrentConnectedDeviceChanged() { final String id = mCurrentConnectedDevice != null ? mCurrentConnectedDevice.getId() : null; final String id = mCurrentConnectedDevice != null ? mCurrentConnectedDevice.getId() : null; Loading @@ -250,13 +245,9 @@ public abstract class InfoMediaManager extends MediaManager { return; return; } } if (TextUtils.isEmpty(mPackageName)) { connectDeviceWithoutPackageName(device); } else { device.setConnectedRecord(); device.setConnectedRecord(); transferToRoute(device.mRouteInfo); transferToRoute(device.mRouteInfo); } } } /** /** * Add a MediaDevice to let it play current media. * Add a MediaDevice to let it play current media. Loading @@ -265,11 +256,6 @@ public abstract class InfoMediaManager extends MediaManager { * @return If add device successful return {@code true}, otherwise return {@code false} * @return If add device successful return {@code true}, otherwise return {@code false} */ */ boolean addDeviceToPlayMedia(MediaDevice device) { boolean addDeviceToPlayMedia(MediaDevice device) { if (TextUtils.isEmpty(mPackageName)) { Log.w(TAG, "addDeviceToPlayMedia() package name is null or empty!"); return false; } final RoutingSessionInfo info = getRoutingSessionInfo(); final RoutingSessionInfo info = getRoutingSessionInfo(); if (info == null || !info.getSelectableRoutes().contains(device.mRouteInfo.getId())) { if (info == null || !info.getSelectableRoutes().contains(device.mRouteInfo.getId())) { Log.w(TAG, "addDeviceToPlayMedia() Ignoring selecting a non-selectable device : " Log.w(TAG, "addDeviceToPlayMedia() Ignoring selecting a non-selectable device : " Loading Loading @@ -306,7 +292,6 @@ public abstract class InfoMediaManager extends MediaManager { boolean preferRouteListingOrdering() { boolean preferRouteListingOrdering() { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE return Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE && !TextUtils.isEmpty(mPackageName) && Api34Impl.preferRouteListingOrdering(getRouteListingPreference()); && Api34Impl.preferRouteListingOrdering(getRouteListingPreference()); } } Loading @@ -326,11 +311,6 @@ public abstract class InfoMediaManager extends MediaManager { * @return If device stop successful return {@code true}, otherwise return {@code false} * @return If device stop successful return {@code true}, otherwise return {@code false} */ */ boolean removeDeviceFromPlayMedia(MediaDevice device) { boolean removeDeviceFromPlayMedia(MediaDevice device) { if (TextUtils.isEmpty(mPackageName)) { Log.w(TAG, "removeDeviceFromMedia() package name is null or empty!"); return false; } final RoutingSessionInfo info = getRoutingSessionInfo(); final RoutingSessionInfo info = getRoutingSessionInfo(); if (info == null || !info.getSelectedRoutes().contains(device.mRouteInfo.getId())) { if (info == null || !info.getSelectedRoutes().contains(device.mRouteInfo.getId())) { Log.w(TAG, "removeDeviceFromMedia() Ignoring deselecting a non-deselectable device : " Log.w(TAG, "removeDeviceFromMedia() Ignoring deselecting a non-deselectable device : " Loading @@ -346,11 +326,6 @@ public abstract class InfoMediaManager extends MediaManager { * Release session to stop playing media on MediaDevice. * Release session to stop playing media on MediaDevice. */ */ boolean releaseSession() { boolean releaseSession() { if (TextUtils.isEmpty(mPackageName)) { Log.w(TAG, "releaseSession() package name is null or empty!"); return false; } final RoutingSessionInfo sessionInfo = getRoutingSessionInfo(); final RoutingSessionInfo sessionInfo = getRoutingSessionInfo(); if (sessionInfo == null) { if (sessionInfo == null) { Log.w(TAG, "releaseSession() Ignoring release session : " + mPackageName); Log.w(TAG, "releaseSession() Ignoring release session : " + mPackageName); Loading @@ -367,11 +342,6 @@ public abstract class InfoMediaManager extends MediaManager { */ */ @NonNull @NonNull List<MediaDevice> getSelectableMediaDevices() { List<MediaDevice> getSelectableMediaDevices() { if (TextUtils.isEmpty(mPackageName)) { Log.w(TAG, "getSelectableMediaDevices() package name is null or empty!"); return Collections.emptyList(); } final RoutingSessionInfo info = getRoutingSessionInfo(); final RoutingSessionInfo info = getRoutingSessionInfo(); if (info == null) { if (info == null) { Log.w(TAG, "getSelectableMediaDevices() cannot find selectable MediaDevice from : " Log.w(TAG, "getSelectableMediaDevices() cannot find selectable MediaDevice from : " Loading @@ -394,11 +364,6 @@ public abstract class InfoMediaManager extends MediaManager { */ */ @NonNull @NonNull List<MediaDevice> getDeselectableMediaDevices() { List<MediaDevice> getDeselectableMediaDevices() { if (TextUtils.isEmpty(mPackageName)) { Log.d(TAG, "getDeselectableMediaDevices() package name is null or empty!"); return Collections.emptyList(); } final RoutingSessionInfo info = getRoutingSessionInfo(); final RoutingSessionInfo info = getRoutingSessionInfo(); if (info == null) { if (info == null) { Log.d(TAG, "getDeselectableMediaDevices() cannot find deselectable MediaDevice from : " Log.d(TAG, "getDeselectableMediaDevices() cannot find deselectable MediaDevice from : " Loading Loading @@ -462,11 +427,6 @@ public abstract class InfoMediaManager extends MediaManager { * @param volume the value of volume * @param volume the value of volume */ */ void adjustSessionVolume(int volume) { void adjustSessionVolume(int volume) { if (TextUtils.isEmpty(mPackageName)) { Log.w(TAG, "adjustSessionVolume() package name is null or empty!"); return; } final RoutingSessionInfo info = getRoutingSessionInfo(); final RoutingSessionInfo info = getRoutingSessionInfo(); if (info == null) { if (info == null) { Log.w(TAG, "adjustSessionVolume() can't found corresponding RoutingSession with : " Log.w(TAG, "adjustSessionVolume() can't found corresponding RoutingSession with : " Loading @@ -484,11 +444,6 @@ public abstract class InfoMediaManager extends MediaManager { * @return maximum volume of the session, and return -1 if not found. * @return maximum volume of the session, and return -1 if not found. */ */ public int getSessionVolumeMax() { public int getSessionVolumeMax() { if (TextUtils.isEmpty(mPackageName)) { Log.w(TAG, "getSessionVolumeMax() package name is null or empty!"); return -1; } final RoutingSessionInfo info = getRoutingSessionInfo(); final RoutingSessionInfo info = getRoutingSessionInfo(); if (info == null) { if (info == null) { Log.w(TAG, "getSessionVolumeMax() can't find corresponding RoutingSession with : " Log.w(TAG, "getSessionVolumeMax() can't find corresponding RoutingSession with : " Loading @@ -505,11 +460,6 @@ public abstract class InfoMediaManager extends MediaManager { * @return current volume of the session, and return -1 if not found. * @return current volume of the session, and return -1 if not found. */ */ public int getSessionVolume() { public int getSessionVolume() { if (TextUtils.isEmpty(mPackageName)) { Log.w(TAG, "getSessionVolume() package name is null or empty!"); return -1; } final RoutingSessionInfo info = getRoutingSessionInfo(); final RoutingSessionInfo info = getRoutingSessionInfo(); if (info == null) { if (info == null) { Log.w(TAG, "getSessionVolume() can't find corresponding RoutingSession with : " Log.w(TAG, "getSessionVolume() can't find corresponding RoutingSession with : " Loading @@ -521,11 +471,6 @@ public abstract class InfoMediaManager extends MediaManager { } } CharSequence getSessionName() { CharSequence getSessionName() { if (TextUtils.isEmpty(mPackageName)) { Log.w(TAG, "Unable to get session name. The package name is null or empty!"); return null; } final RoutingSessionInfo info = getRoutingSessionInfo(); final RoutingSessionInfo info = getRoutingSessionInfo(); if (info == null) { if (info == null) { Log.w(TAG, "Unable to get session name for package: " + mPackageName); Log.w(TAG, "Unable to get session name for package: " + mPackageName); Loading @@ -546,20 +491,6 @@ public abstract class InfoMediaManager extends MediaManager { dispatchDeviceListAdded(); dispatchDeviceListAdded(); } } // MediaRoute2Info.getType was made public on API 34, but exists since API 30. @SuppressWarnings("NewApi") private void buildAllRoutes() { for (MediaRoute2Info route : getAllRoutes()) { if (DEBUG) { Log.d(TAG, "buildAllRoutes() route : " + route.getName() + ", volume : " + route.getVolume() + ", type : " + route.getType()); } if (route.isSystemRoute()) { addMediaDevice(route); } } } // MediaRoute2Info.getType was made public on API 34, but exists since API 30. // MediaRoute2Info.getType was made public on API 34, but exists since API 30. @SuppressWarnings("NewApi") @SuppressWarnings("NewApi") private synchronized void buildAvailableRoutes() { private synchronized void buildAvailableRoutes() { Loading Loading @@ -594,8 +525,7 @@ public abstract class InfoMediaManager extends MediaManager { infos.add(transferableRoute); infos.add(transferableRoute); } } } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { && !TextUtils.isEmpty(mPackageName)) { RouteListingPreference routeListingPreference = getRouteListingPreference(); RouteListingPreference routeListingPreference = getRouteListingPreference(); if (routeListingPreference != null) { if (routeListingPreference != null) { final List<RouteListingPreference.Item> preferenceRouteListing = final List<RouteListingPreference.Item> preferenceRouteListing = Loading Loading @@ -679,7 +609,7 @@ public abstract class InfoMediaManager extends MediaManager { break; break; } } if (mediaDevice != null && !TextUtils.isEmpty(mPackageName) if (mediaDevice != null && getRoutingSessionInfo().getSelectedRoutes().contains(route.getId())) { && getRoutingSessionInfo().getSelectedRoutes().contains(route.getId())) { mediaDevice.setState(STATE_SELECTED); mediaDevice.setState(STATE_SELECTED); if (mCurrentConnectedDevice == null) { if (mCurrentConnectedDevice == null) { Loading packages/SettingsLib/src/com/android/settingslib/media/ManagerInfoMediaManager.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -51,9 +51,9 @@ public class ManagerInfoMediaManager extends InfoMediaManager { private final Executor mExecutor = Executors.newSingleThreadExecutor(); private final Executor mExecutor = Executors.newSingleThreadExecutor(); public ManagerInfoMediaManager( /* package */ ManagerInfoMediaManager( Context context, Context context, String packageName, @NonNull String packageName, Notification notification, Notification notification, LocalBluetoothManager localBluetoothManager) { LocalBluetoothManager localBluetoothManager) { super(context, packageName, notification, localBluetoothManager); super(context, packageName, notification, localBluetoothManager); Loading packages/SettingsLib/src/com/android/settingslib/media/NoOpInfoMediaManager.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -41,7 +41,7 @@ import java.util.List; NoOpInfoMediaManager( NoOpInfoMediaManager( Context context, Context context, String packageName, @NonNull String packageName, Notification notification, Notification notification, LocalBluetoothManager localBluetoothManager) { LocalBluetoothManager localBluetoothManager) { super(context, packageName, notification, localBluetoothManager); super(context, packageName, notification, localBluetoothManager); Loading packages/SettingsLib/src/com/android/settingslib/media/RouterInfoMediaManager.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -65,9 +65,9 @@ public final class RouterInfoMediaManager extends InfoMediaManager { }; }; // TODO (b/321969740): Plumb target UserHandle between UMO and RouterInfoMediaManager. // TODO (b/321969740): Plumb target UserHandle between UMO and RouterInfoMediaManager. public RouterInfoMediaManager( /* package */ RouterInfoMediaManager( Context context, Context context, String packageName, @NonNull String packageName, Notification notification, Notification notification, LocalBluetoothManager localBluetoothManager) LocalBluetoothManager localBluetoothManager) throws PackageNotAvailableException { throws PackageNotAvailableException { Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/InfoMediaManagerTest.java +0 −159 Original line number Original line Diff line number Diff line Loading @@ -211,28 +211,6 @@ public class InfoMediaManagerTest { assertThat(mInfoMediaManager.getCurrentConnectedDevice()).isEqualTo(infoDevice1); assertThat(mInfoMediaManager.getCurrentConnectedDevice()).isEqualTo(infoDevice1); } } @Test public void onRouteAdded_buildAllRoutes_shouldAddMediaDevice() { final MediaRoute2Info info = mock(MediaRoute2Info.class); when(info.getId()).thenReturn(TEST_ID); when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); when(info.isSystemRoute()).thenReturn(true); final List<MediaRoute2Info> routes = new ArrayList<>(); routes.add(info); mShadowRouter2Manager.setAllRoutes(routes); final MediaDevice mediaDevice = mInfoMediaManager.findMediaDevice(TEST_ID); assertThat(mediaDevice).isNull(); mInfoMediaManager.mPackageName = ""; mInfoMediaManager.mMediaRouterCallback.onRoutesUpdated(); final MediaDevice infoDevice = mInfoMediaManager.mMediaDevices.get(0); assertThat(infoDevice.getId()).isEqualTo(TEST_ID); assertThat(mInfoMediaManager.mMediaDevices).hasSize(routes.size()); } @Test @Test public void onPreferredFeaturesChanged_samePackageName_shouldAddMediaDevice() { public void onPreferredFeaturesChanged_samePackageName_shouldAddMediaDevice() { final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); Loading Loading @@ -435,29 +413,6 @@ public class InfoMediaManagerTest { return availableRoutes; return availableRoutes; } } @Test public void onRoutesChanged_buildAllRoutes_shouldAddMediaDevice() { final MediaRoute2Info info = mock(MediaRoute2Info.class); when(info.getId()).thenReturn(TEST_ID); when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); when(info.isSystemRoute()).thenReturn(true); when(info.getDeduplicationIds()).thenReturn(Set.of()); final List<MediaRoute2Info> routes = new ArrayList<>(); routes.add(info); mShadowRouter2Manager.setAllRoutes(routes); final MediaDevice mediaDevice = mInfoMediaManager.findMediaDevice(TEST_ID); assertThat(mediaDevice).isNull(); mInfoMediaManager.mPackageName = ""; mInfoMediaManager.mMediaRouterCallback.onRoutesUpdated(); final MediaDevice infoDevice = mInfoMediaManager.mMediaDevices.get(0); assertThat(infoDevice.getId()).isEqualTo(TEST_ID); assertThat(mInfoMediaManager.mMediaDevices).hasSize(routes.size()); } @Test @Test public void hasPreferenceRouteListing_oldSdkVersion_returnsFalse() { public void hasPreferenceRouteListing_oldSdkVersion_returnsFalse() { assertThat(mInfoMediaManager.preferRouteListingOrdering()).isFalse(); assertThat(mInfoMediaManager.preferRouteListingOrdering()).isFalse(); Loading Loading @@ -586,36 +541,6 @@ public class InfoMediaManagerTest { assertThat(mInfoMediaManager.mMediaDevices).hasSize(routes.size()); assertThat(mInfoMediaManager.mMediaDevices).hasSize(routes.size()); } } @Test public void onRoutesRemoved_buildAllRoutes_shouldAddMediaDevice() { final MediaRoute2Info info = mock(MediaRoute2Info.class); when(info.getId()).thenReturn(TEST_ID); when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); when(info.isSystemRoute()).thenReturn(true); final List<MediaRoute2Info> routes = new ArrayList<>(); routes.add(info); when(mRouterManager.getAllRoutes()).thenReturn(routes); final MediaDevice mediaDevice = mInfoMediaManager.findMediaDevice(TEST_ID); assertThat(mediaDevice).isNull(); mInfoMediaManager.mPackageName = ""; mInfoMediaManager.mMediaRouterCallback.onRoutesUpdated(); final MediaDevice infoDevice = mInfoMediaManager.mMediaDevices.get(0); assertThat(infoDevice.getId()).isEqualTo(TEST_ID); assertThat(mInfoMediaManager.mMediaDevices).hasSize(routes.size()); } @Test public void addDeviceToPlayMedia_packageNameIsNull_returnFalse() { mInfoMediaManager.mPackageName = null; final MediaDevice device = mock(MediaDevice.class); assertThat(mInfoMediaManager.addDeviceToPlayMedia(device)).isFalse(); } @Test @Test public void addDeviceToPlayMedia_containSelectableRoutes_returnTrue() { public void addDeviceToPlayMedia_containSelectableRoutes_returnTrue() { final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); Loading Loading @@ -659,14 +584,6 @@ public class InfoMediaManagerTest { assertThat(mInfoMediaManager.addDeviceToPlayMedia(device)).isFalse(); assertThat(mInfoMediaManager.addDeviceToPlayMedia(device)).isFalse(); } } @Test public void removeDeviceFromMedia_packageNameIsNull_returnFalse() { mInfoMediaManager.mPackageName = null; final MediaDevice device = mock(MediaDevice.class); assertThat(mInfoMediaManager.removeDeviceFromPlayMedia(device)).isFalse(); } @Test @Test public void removeDeviceFromMedia_containSelectedRoutes_returnTrue() { public void removeDeviceFromMedia_containSelectedRoutes_returnTrue() { final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); Loading Loading @@ -710,13 +627,6 @@ public class InfoMediaManagerTest { assertThat(mInfoMediaManager.removeDeviceFromPlayMedia(device)).isFalse(); assertThat(mInfoMediaManager.removeDeviceFromPlayMedia(device)).isFalse(); } } @Test public void getSelectableMediaDevice_packageNameIsNull_returnFalse() { mInfoMediaManager.mPackageName = null; assertThat(mInfoMediaManager.getSelectableMediaDevices()).isEmpty(); } @Test @Test public void getSelectableMediaDevice_notContainPackageName_returnEmpty() { public void getSelectableMediaDevice_notContainPackageName_returnEmpty() { final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); Loading @@ -729,13 +639,6 @@ public class InfoMediaManagerTest { assertThat(mInfoMediaManager.getSelectableMediaDevices()).isEmpty(); assertThat(mInfoMediaManager.getSelectableMediaDevices()).isEmpty(); } } @Test public void getDeselectableMediaDevice_packageNameIsNull_returnFalse() { mInfoMediaManager.mPackageName = null; assertThat(mInfoMediaManager.getDeselectableMediaDevices()).isEmpty(); } @Test @Test public void getDeselectableMediaDevice_checkList() { public void getDeselectableMediaDevice_checkList() { final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); Loading @@ -760,20 +663,6 @@ public class InfoMediaManagerTest { mInfoMediaManager.adjustSessionVolume(null, 10); mInfoMediaManager.adjustSessionVolume(null, 10); } } @Test public void adjustSessionVolume_packageNameIsNull_noCrash() { mInfoMediaManager.mPackageName = null; mInfoMediaManager.adjustSessionVolume(10); } @Test public void getSessionVolumeMax_packageNameIsNull_returnNotFound() { mInfoMediaManager.mPackageName = null; assertThat(mInfoMediaManager.getSessionVolumeMax()).isEqualTo(-1); } @Test @Test public void getSessionVolumeMax_containPackageName_returnMaxVolume() { public void getSessionVolumeMax_containPackageName_returnMaxVolume() { final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); Loading @@ -799,13 +688,6 @@ public class InfoMediaManagerTest { assertThat(mInfoMediaManager.getSessionVolumeMax()).isEqualTo(-1); assertThat(mInfoMediaManager.getSessionVolumeMax()).isEqualTo(-1); } } @Test public void getSessionVolume_packageNameIsNull_returnNotFound() { mInfoMediaManager.mPackageName = null; assertThat(mInfoMediaManager.getSessionVolume()).isEqualTo(-1); } @Test @Test public void getSessionVolume_containPackageName_returnMaxVolume() { public void getSessionVolume_containPackageName_returnMaxVolume() { final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); Loading Loading @@ -840,13 +722,6 @@ public class InfoMediaManagerTest { assertThat(mInfoMediaManager.getRemoteSessions()).containsExactlyElementsIn(infos); assertThat(mInfoMediaManager.getRemoteSessions()).containsExactlyElementsIn(infos); } } @Test public void releaseSession_packageNameIsNull_returnFalse() { mInfoMediaManager.mPackageName = null; assertThat(mInfoMediaManager.releaseSession()).isFalse(); } @Test @Test public void releaseSession_removeSuccessfully_returnTrue() { public void releaseSession_removeSuccessfully_returnTrue() { final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); Loading @@ -859,13 +734,6 @@ public class InfoMediaManagerTest { assertThat(mInfoMediaManager.releaseSession()).isTrue(); assertThat(mInfoMediaManager.releaseSession()).isTrue(); } } @Test public void getSessionName_packageNameIsNull_returnNull() { mInfoMediaManager.mPackageName = null; assertThat(mInfoMediaManager.getSessionName()).isNull(); } @Test @Test public void getSessionName_routeSessionInfoIsNull_returnNull() { public void getSessionName_routeSessionInfoIsNull_returnNull() { final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); Loading Loading @@ -941,32 +809,6 @@ public class InfoMediaManagerTest { verify(mCallback).onConnectedDeviceChanged(TEST_ID); verify(mCallback).onConnectedDeviceChanged(TEST_ID); } } @Test public void onTransferred_buildAllRoutes_shouldAddMediaDevice() { final MediaRoute2Info info = mock(MediaRoute2Info.class); final RoutingSessionInfo sessionInfo = mock(RoutingSessionInfo.class); mInfoMediaManager.registerCallback(mCallback); when(info.getId()).thenReturn(TEST_ID); when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); when(info.isSystemRoute()).thenReturn(true); final List<MediaRoute2Info> routes = new ArrayList<>(); routes.add(info); mShadowRouter2Manager.setAllRoutes(routes); final MediaDevice mediaDevice = mInfoMediaManager.findMediaDevice(TEST_ID); assertThat(mediaDevice).isNull(); mInfoMediaManager.mPackageName = ""; mInfoMediaManager.mMediaRouterCallback.onTransferred(sessionInfo, sessionInfo); final MediaDevice infoDevice = mInfoMediaManager.mMediaDevices.get(0); assertThat(infoDevice.getId()).isEqualTo(TEST_ID); assertThat(mInfoMediaManager.mMediaDevices).hasSize(routes.size()); verify(mCallback).onConnectedDeviceChanged(null); } @Test @Test public void onSessionUpdated_shouldDispatchDeviceListAdded() { public void onSessionUpdated_shouldDispatchDeviceListAdded() { final MediaRoute2Info info = mock(MediaRoute2Info.class); final MediaRoute2Info info = mock(MediaRoute2Info.class); Loading @@ -978,7 +820,6 @@ public class InfoMediaManagerTest { routes.add(info); routes.add(info); mShadowRouter2Manager.setAllRoutes(routes); mShadowRouter2Manager.setAllRoutes(routes); mInfoMediaManager.mPackageName = ""; mInfoMediaManager.registerCallback(mCallback); mInfoMediaManager.registerCallback(mCallback); mInfoMediaManager.mMediaRouterCallback.onSessionUpdated(mock(RoutingSessionInfo.class)); mInfoMediaManager.mMediaRouterCallback.onSessionUpdated(mock(RoutingSessionInfo.class)); Loading Loading
packages/SettingsLib/src/com/android/settingslib/media/InfoMediaManager.java +9 −79 Original line number Original line Diff line number Diff line Loading @@ -92,13 +92,13 @@ public abstract class InfoMediaManager extends MediaManager { } } } } protected String mPackageName; @NonNull protected final String mPackageName; private MediaDevice mCurrentConnectedDevice; private MediaDevice mCurrentConnectedDevice; private final LocalBluetoothManager mBluetoothManager; private final LocalBluetoothManager mBluetoothManager; private final Map<String, RouteListingPreference.Item> mPreferenceItemMap = private final Map<String, RouteListingPreference.Item> mPreferenceItemMap = new ConcurrentHashMap<>(); new ConcurrentHashMap<>(); public InfoMediaManager( /* package */ InfoMediaManager( Context context, Context context, @NonNull String packageName, @NonNull String packageName, Notification notification, Notification notification, Loading @@ -112,7 +112,7 @@ public abstract class InfoMediaManager extends MediaManager { /** Creates an instance of InfoMediaManager. */ /** Creates an instance of InfoMediaManager. */ public static InfoMediaManager createInstance( public static InfoMediaManager createInstance( Context context, Context context, String packageName, @Nullable String packageName, Notification notification, Notification notification, LocalBluetoothManager localBluetoothManager) { LocalBluetoothManager localBluetoothManager) { Loading Loading @@ -148,8 +148,7 @@ public abstract class InfoMediaManager extends MediaManager { } } private void updateRouteListingPreference() { private void updateRouteListingPreference() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { && !TextUtils.isEmpty(mPackageName)) { RouteListingPreference routeListingPreference = RouteListingPreference routeListingPreference = getRouteListingPreference(); getRouteListingPreference(); Api34Impl.onRouteListingPreferenceUpdated(routeListingPreference, Api34Impl.onRouteListingPreferenceUpdated(routeListingPreference, Loading Loading @@ -218,12 +217,8 @@ public abstract class InfoMediaManager extends MediaManager { protected final void rebuildDeviceList() { protected final void rebuildDeviceList() { mMediaDevices.clear(); mMediaDevices.clear(); mCurrentConnectedDevice = null; mCurrentConnectedDevice = null; if (TextUtils.isEmpty(mPackageName)) { buildAllRoutes(); } else { buildAvailableRoutes(); buildAvailableRoutes(); } } } protected final void notifyCurrentConnectedDeviceChanged() { protected final void notifyCurrentConnectedDeviceChanged() { final String id = mCurrentConnectedDevice != null ? mCurrentConnectedDevice.getId() : null; final String id = mCurrentConnectedDevice != null ? mCurrentConnectedDevice.getId() : null; Loading @@ -250,13 +245,9 @@ public abstract class InfoMediaManager extends MediaManager { return; return; } } if (TextUtils.isEmpty(mPackageName)) { connectDeviceWithoutPackageName(device); } else { device.setConnectedRecord(); device.setConnectedRecord(); transferToRoute(device.mRouteInfo); transferToRoute(device.mRouteInfo); } } } /** /** * Add a MediaDevice to let it play current media. * Add a MediaDevice to let it play current media. Loading @@ -265,11 +256,6 @@ public abstract class InfoMediaManager extends MediaManager { * @return If add device successful return {@code true}, otherwise return {@code false} * @return If add device successful return {@code true}, otherwise return {@code false} */ */ boolean addDeviceToPlayMedia(MediaDevice device) { boolean addDeviceToPlayMedia(MediaDevice device) { if (TextUtils.isEmpty(mPackageName)) { Log.w(TAG, "addDeviceToPlayMedia() package name is null or empty!"); return false; } final RoutingSessionInfo info = getRoutingSessionInfo(); final RoutingSessionInfo info = getRoutingSessionInfo(); if (info == null || !info.getSelectableRoutes().contains(device.mRouteInfo.getId())) { if (info == null || !info.getSelectableRoutes().contains(device.mRouteInfo.getId())) { Log.w(TAG, "addDeviceToPlayMedia() Ignoring selecting a non-selectable device : " Log.w(TAG, "addDeviceToPlayMedia() Ignoring selecting a non-selectable device : " Loading Loading @@ -306,7 +292,6 @@ public abstract class InfoMediaManager extends MediaManager { boolean preferRouteListingOrdering() { boolean preferRouteListingOrdering() { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE return Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE && !TextUtils.isEmpty(mPackageName) && Api34Impl.preferRouteListingOrdering(getRouteListingPreference()); && Api34Impl.preferRouteListingOrdering(getRouteListingPreference()); } } Loading @@ -326,11 +311,6 @@ public abstract class InfoMediaManager extends MediaManager { * @return If device stop successful return {@code true}, otherwise return {@code false} * @return If device stop successful return {@code true}, otherwise return {@code false} */ */ boolean removeDeviceFromPlayMedia(MediaDevice device) { boolean removeDeviceFromPlayMedia(MediaDevice device) { if (TextUtils.isEmpty(mPackageName)) { Log.w(TAG, "removeDeviceFromMedia() package name is null or empty!"); return false; } final RoutingSessionInfo info = getRoutingSessionInfo(); final RoutingSessionInfo info = getRoutingSessionInfo(); if (info == null || !info.getSelectedRoutes().contains(device.mRouteInfo.getId())) { if (info == null || !info.getSelectedRoutes().contains(device.mRouteInfo.getId())) { Log.w(TAG, "removeDeviceFromMedia() Ignoring deselecting a non-deselectable device : " Log.w(TAG, "removeDeviceFromMedia() Ignoring deselecting a non-deselectable device : " Loading @@ -346,11 +326,6 @@ public abstract class InfoMediaManager extends MediaManager { * Release session to stop playing media on MediaDevice. * Release session to stop playing media on MediaDevice. */ */ boolean releaseSession() { boolean releaseSession() { if (TextUtils.isEmpty(mPackageName)) { Log.w(TAG, "releaseSession() package name is null or empty!"); return false; } final RoutingSessionInfo sessionInfo = getRoutingSessionInfo(); final RoutingSessionInfo sessionInfo = getRoutingSessionInfo(); if (sessionInfo == null) { if (sessionInfo == null) { Log.w(TAG, "releaseSession() Ignoring release session : " + mPackageName); Log.w(TAG, "releaseSession() Ignoring release session : " + mPackageName); Loading @@ -367,11 +342,6 @@ public abstract class InfoMediaManager extends MediaManager { */ */ @NonNull @NonNull List<MediaDevice> getSelectableMediaDevices() { List<MediaDevice> getSelectableMediaDevices() { if (TextUtils.isEmpty(mPackageName)) { Log.w(TAG, "getSelectableMediaDevices() package name is null or empty!"); return Collections.emptyList(); } final RoutingSessionInfo info = getRoutingSessionInfo(); final RoutingSessionInfo info = getRoutingSessionInfo(); if (info == null) { if (info == null) { Log.w(TAG, "getSelectableMediaDevices() cannot find selectable MediaDevice from : " Log.w(TAG, "getSelectableMediaDevices() cannot find selectable MediaDevice from : " Loading @@ -394,11 +364,6 @@ public abstract class InfoMediaManager extends MediaManager { */ */ @NonNull @NonNull List<MediaDevice> getDeselectableMediaDevices() { List<MediaDevice> getDeselectableMediaDevices() { if (TextUtils.isEmpty(mPackageName)) { Log.d(TAG, "getDeselectableMediaDevices() package name is null or empty!"); return Collections.emptyList(); } final RoutingSessionInfo info = getRoutingSessionInfo(); final RoutingSessionInfo info = getRoutingSessionInfo(); if (info == null) { if (info == null) { Log.d(TAG, "getDeselectableMediaDevices() cannot find deselectable MediaDevice from : " Log.d(TAG, "getDeselectableMediaDevices() cannot find deselectable MediaDevice from : " Loading Loading @@ -462,11 +427,6 @@ public abstract class InfoMediaManager extends MediaManager { * @param volume the value of volume * @param volume the value of volume */ */ void adjustSessionVolume(int volume) { void adjustSessionVolume(int volume) { if (TextUtils.isEmpty(mPackageName)) { Log.w(TAG, "adjustSessionVolume() package name is null or empty!"); return; } final RoutingSessionInfo info = getRoutingSessionInfo(); final RoutingSessionInfo info = getRoutingSessionInfo(); if (info == null) { if (info == null) { Log.w(TAG, "adjustSessionVolume() can't found corresponding RoutingSession with : " Log.w(TAG, "adjustSessionVolume() can't found corresponding RoutingSession with : " Loading @@ -484,11 +444,6 @@ public abstract class InfoMediaManager extends MediaManager { * @return maximum volume of the session, and return -1 if not found. * @return maximum volume of the session, and return -1 if not found. */ */ public int getSessionVolumeMax() { public int getSessionVolumeMax() { if (TextUtils.isEmpty(mPackageName)) { Log.w(TAG, "getSessionVolumeMax() package name is null or empty!"); return -1; } final RoutingSessionInfo info = getRoutingSessionInfo(); final RoutingSessionInfo info = getRoutingSessionInfo(); if (info == null) { if (info == null) { Log.w(TAG, "getSessionVolumeMax() can't find corresponding RoutingSession with : " Log.w(TAG, "getSessionVolumeMax() can't find corresponding RoutingSession with : " Loading @@ -505,11 +460,6 @@ public abstract class InfoMediaManager extends MediaManager { * @return current volume of the session, and return -1 if not found. * @return current volume of the session, and return -1 if not found. */ */ public int getSessionVolume() { public int getSessionVolume() { if (TextUtils.isEmpty(mPackageName)) { Log.w(TAG, "getSessionVolume() package name is null or empty!"); return -1; } final RoutingSessionInfo info = getRoutingSessionInfo(); final RoutingSessionInfo info = getRoutingSessionInfo(); if (info == null) { if (info == null) { Log.w(TAG, "getSessionVolume() can't find corresponding RoutingSession with : " Log.w(TAG, "getSessionVolume() can't find corresponding RoutingSession with : " Loading @@ -521,11 +471,6 @@ public abstract class InfoMediaManager extends MediaManager { } } CharSequence getSessionName() { CharSequence getSessionName() { if (TextUtils.isEmpty(mPackageName)) { Log.w(TAG, "Unable to get session name. The package name is null or empty!"); return null; } final RoutingSessionInfo info = getRoutingSessionInfo(); final RoutingSessionInfo info = getRoutingSessionInfo(); if (info == null) { if (info == null) { Log.w(TAG, "Unable to get session name for package: " + mPackageName); Log.w(TAG, "Unable to get session name for package: " + mPackageName); Loading @@ -546,20 +491,6 @@ public abstract class InfoMediaManager extends MediaManager { dispatchDeviceListAdded(); dispatchDeviceListAdded(); } } // MediaRoute2Info.getType was made public on API 34, but exists since API 30. @SuppressWarnings("NewApi") private void buildAllRoutes() { for (MediaRoute2Info route : getAllRoutes()) { if (DEBUG) { Log.d(TAG, "buildAllRoutes() route : " + route.getName() + ", volume : " + route.getVolume() + ", type : " + route.getType()); } if (route.isSystemRoute()) { addMediaDevice(route); } } } // MediaRoute2Info.getType was made public on API 34, but exists since API 30. // MediaRoute2Info.getType was made public on API 34, but exists since API 30. @SuppressWarnings("NewApi") @SuppressWarnings("NewApi") private synchronized void buildAvailableRoutes() { private synchronized void buildAvailableRoutes() { Loading Loading @@ -594,8 +525,7 @@ public abstract class InfoMediaManager extends MediaManager { infos.add(transferableRoute); infos.add(transferableRoute); } } } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { && !TextUtils.isEmpty(mPackageName)) { RouteListingPreference routeListingPreference = getRouteListingPreference(); RouteListingPreference routeListingPreference = getRouteListingPreference(); if (routeListingPreference != null) { if (routeListingPreference != null) { final List<RouteListingPreference.Item> preferenceRouteListing = final List<RouteListingPreference.Item> preferenceRouteListing = Loading Loading @@ -679,7 +609,7 @@ public abstract class InfoMediaManager extends MediaManager { break; break; } } if (mediaDevice != null && !TextUtils.isEmpty(mPackageName) if (mediaDevice != null && getRoutingSessionInfo().getSelectedRoutes().contains(route.getId())) { && getRoutingSessionInfo().getSelectedRoutes().contains(route.getId())) { mediaDevice.setState(STATE_SELECTED); mediaDevice.setState(STATE_SELECTED); if (mCurrentConnectedDevice == null) { if (mCurrentConnectedDevice == null) { Loading
packages/SettingsLib/src/com/android/settingslib/media/ManagerInfoMediaManager.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -51,9 +51,9 @@ public class ManagerInfoMediaManager extends InfoMediaManager { private final Executor mExecutor = Executors.newSingleThreadExecutor(); private final Executor mExecutor = Executors.newSingleThreadExecutor(); public ManagerInfoMediaManager( /* package */ ManagerInfoMediaManager( Context context, Context context, String packageName, @NonNull String packageName, Notification notification, Notification notification, LocalBluetoothManager localBluetoothManager) { LocalBluetoothManager localBluetoothManager) { super(context, packageName, notification, localBluetoothManager); super(context, packageName, notification, localBluetoothManager); Loading
packages/SettingsLib/src/com/android/settingslib/media/NoOpInfoMediaManager.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -41,7 +41,7 @@ import java.util.List; NoOpInfoMediaManager( NoOpInfoMediaManager( Context context, Context context, String packageName, @NonNull String packageName, Notification notification, Notification notification, LocalBluetoothManager localBluetoothManager) { LocalBluetoothManager localBluetoothManager) { super(context, packageName, notification, localBluetoothManager); super(context, packageName, notification, localBluetoothManager); Loading
packages/SettingsLib/src/com/android/settingslib/media/RouterInfoMediaManager.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -65,9 +65,9 @@ public final class RouterInfoMediaManager extends InfoMediaManager { }; }; // TODO (b/321969740): Plumb target UserHandle between UMO and RouterInfoMediaManager. // TODO (b/321969740): Plumb target UserHandle between UMO and RouterInfoMediaManager. public RouterInfoMediaManager( /* package */ RouterInfoMediaManager( Context context, Context context, String packageName, @NonNull String packageName, Notification notification, Notification notification, LocalBluetoothManager localBluetoothManager) LocalBluetoothManager localBluetoothManager) throws PackageNotAvailableException { throws PackageNotAvailableException { Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/InfoMediaManagerTest.java +0 −159 Original line number Original line Diff line number Diff line Loading @@ -211,28 +211,6 @@ public class InfoMediaManagerTest { assertThat(mInfoMediaManager.getCurrentConnectedDevice()).isEqualTo(infoDevice1); assertThat(mInfoMediaManager.getCurrentConnectedDevice()).isEqualTo(infoDevice1); } } @Test public void onRouteAdded_buildAllRoutes_shouldAddMediaDevice() { final MediaRoute2Info info = mock(MediaRoute2Info.class); when(info.getId()).thenReturn(TEST_ID); when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); when(info.isSystemRoute()).thenReturn(true); final List<MediaRoute2Info> routes = new ArrayList<>(); routes.add(info); mShadowRouter2Manager.setAllRoutes(routes); final MediaDevice mediaDevice = mInfoMediaManager.findMediaDevice(TEST_ID); assertThat(mediaDevice).isNull(); mInfoMediaManager.mPackageName = ""; mInfoMediaManager.mMediaRouterCallback.onRoutesUpdated(); final MediaDevice infoDevice = mInfoMediaManager.mMediaDevices.get(0); assertThat(infoDevice.getId()).isEqualTo(TEST_ID); assertThat(mInfoMediaManager.mMediaDevices).hasSize(routes.size()); } @Test @Test public void onPreferredFeaturesChanged_samePackageName_shouldAddMediaDevice() { public void onPreferredFeaturesChanged_samePackageName_shouldAddMediaDevice() { final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); Loading Loading @@ -435,29 +413,6 @@ public class InfoMediaManagerTest { return availableRoutes; return availableRoutes; } } @Test public void onRoutesChanged_buildAllRoutes_shouldAddMediaDevice() { final MediaRoute2Info info = mock(MediaRoute2Info.class); when(info.getId()).thenReturn(TEST_ID); when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); when(info.isSystemRoute()).thenReturn(true); when(info.getDeduplicationIds()).thenReturn(Set.of()); final List<MediaRoute2Info> routes = new ArrayList<>(); routes.add(info); mShadowRouter2Manager.setAllRoutes(routes); final MediaDevice mediaDevice = mInfoMediaManager.findMediaDevice(TEST_ID); assertThat(mediaDevice).isNull(); mInfoMediaManager.mPackageName = ""; mInfoMediaManager.mMediaRouterCallback.onRoutesUpdated(); final MediaDevice infoDevice = mInfoMediaManager.mMediaDevices.get(0); assertThat(infoDevice.getId()).isEqualTo(TEST_ID); assertThat(mInfoMediaManager.mMediaDevices).hasSize(routes.size()); } @Test @Test public void hasPreferenceRouteListing_oldSdkVersion_returnsFalse() { public void hasPreferenceRouteListing_oldSdkVersion_returnsFalse() { assertThat(mInfoMediaManager.preferRouteListingOrdering()).isFalse(); assertThat(mInfoMediaManager.preferRouteListingOrdering()).isFalse(); Loading Loading @@ -586,36 +541,6 @@ public class InfoMediaManagerTest { assertThat(mInfoMediaManager.mMediaDevices).hasSize(routes.size()); assertThat(mInfoMediaManager.mMediaDevices).hasSize(routes.size()); } } @Test public void onRoutesRemoved_buildAllRoutes_shouldAddMediaDevice() { final MediaRoute2Info info = mock(MediaRoute2Info.class); when(info.getId()).thenReturn(TEST_ID); when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); when(info.isSystemRoute()).thenReturn(true); final List<MediaRoute2Info> routes = new ArrayList<>(); routes.add(info); when(mRouterManager.getAllRoutes()).thenReturn(routes); final MediaDevice mediaDevice = mInfoMediaManager.findMediaDevice(TEST_ID); assertThat(mediaDevice).isNull(); mInfoMediaManager.mPackageName = ""; mInfoMediaManager.mMediaRouterCallback.onRoutesUpdated(); final MediaDevice infoDevice = mInfoMediaManager.mMediaDevices.get(0); assertThat(infoDevice.getId()).isEqualTo(TEST_ID); assertThat(mInfoMediaManager.mMediaDevices).hasSize(routes.size()); } @Test public void addDeviceToPlayMedia_packageNameIsNull_returnFalse() { mInfoMediaManager.mPackageName = null; final MediaDevice device = mock(MediaDevice.class); assertThat(mInfoMediaManager.addDeviceToPlayMedia(device)).isFalse(); } @Test @Test public void addDeviceToPlayMedia_containSelectableRoutes_returnTrue() { public void addDeviceToPlayMedia_containSelectableRoutes_returnTrue() { final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); Loading Loading @@ -659,14 +584,6 @@ public class InfoMediaManagerTest { assertThat(mInfoMediaManager.addDeviceToPlayMedia(device)).isFalse(); assertThat(mInfoMediaManager.addDeviceToPlayMedia(device)).isFalse(); } } @Test public void removeDeviceFromMedia_packageNameIsNull_returnFalse() { mInfoMediaManager.mPackageName = null; final MediaDevice device = mock(MediaDevice.class); assertThat(mInfoMediaManager.removeDeviceFromPlayMedia(device)).isFalse(); } @Test @Test public void removeDeviceFromMedia_containSelectedRoutes_returnTrue() { public void removeDeviceFromMedia_containSelectedRoutes_returnTrue() { final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); Loading Loading @@ -710,13 +627,6 @@ public class InfoMediaManagerTest { assertThat(mInfoMediaManager.removeDeviceFromPlayMedia(device)).isFalse(); assertThat(mInfoMediaManager.removeDeviceFromPlayMedia(device)).isFalse(); } } @Test public void getSelectableMediaDevice_packageNameIsNull_returnFalse() { mInfoMediaManager.mPackageName = null; assertThat(mInfoMediaManager.getSelectableMediaDevices()).isEmpty(); } @Test @Test public void getSelectableMediaDevice_notContainPackageName_returnEmpty() { public void getSelectableMediaDevice_notContainPackageName_returnEmpty() { final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); Loading @@ -729,13 +639,6 @@ public class InfoMediaManagerTest { assertThat(mInfoMediaManager.getSelectableMediaDevices()).isEmpty(); assertThat(mInfoMediaManager.getSelectableMediaDevices()).isEmpty(); } } @Test public void getDeselectableMediaDevice_packageNameIsNull_returnFalse() { mInfoMediaManager.mPackageName = null; assertThat(mInfoMediaManager.getDeselectableMediaDevices()).isEmpty(); } @Test @Test public void getDeselectableMediaDevice_checkList() { public void getDeselectableMediaDevice_checkList() { final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); Loading @@ -760,20 +663,6 @@ public class InfoMediaManagerTest { mInfoMediaManager.adjustSessionVolume(null, 10); mInfoMediaManager.adjustSessionVolume(null, 10); } } @Test public void adjustSessionVolume_packageNameIsNull_noCrash() { mInfoMediaManager.mPackageName = null; mInfoMediaManager.adjustSessionVolume(10); } @Test public void getSessionVolumeMax_packageNameIsNull_returnNotFound() { mInfoMediaManager.mPackageName = null; assertThat(mInfoMediaManager.getSessionVolumeMax()).isEqualTo(-1); } @Test @Test public void getSessionVolumeMax_containPackageName_returnMaxVolume() { public void getSessionVolumeMax_containPackageName_returnMaxVolume() { final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); Loading @@ -799,13 +688,6 @@ public class InfoMediaManagerTest { assertThat(mInfoMediaManager.getSessionVolumeMax()).isEqualTo(-1); assertThat(mInfoMediaManager.getSessionVolumeMax()).isEqualTo(-1); } } @Test public void getSessionVolume_packageNameIsNull_returnNotFound() { mInfoMediaManager.mPackageName = null; assertThat(mInfoMediaManager.getSessionVolume()).isEqualTo(-1); } @Test @Test public void getSessionVolume_containPackageName_returnMaxVolume() { public void getSessionVolume_containPackageName_returnMaxVolume() { final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); Loading Loading @@ -840,13 +722,6 @@ public class InfoMediaManagerTest { assertThat(mInfoMediaManager.getRemoteSessions()).containsExactlyElementsIn(infos); assertThat(mInfoMediaManager.getRemoteSessions()).containsExactlyElementsIn(infos); } } @Test public void releaseSession_packageNameIsNull_returnFalse() { mInfoMediaManager.mPackageName = null; assertThat(mInfoMediaManager.releaseSession()).isFalse(); } @Test @Test public void releaseSession_removeSuccessfully_returnTrue() { public void releaseSession_removeSuccessfully_returnTrue() { final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); Loading @@ -859,13 +734,6 @@ public class InfoMediaManagerTest { assertThat(mInfoMediaManager.releaseSession()).isTrue(); assertThat(mInfoMediaManager.releaseSession()).isTrue(); } } @Test public void getSessionName_packageNameIsNull_returnNull() { mInfoMediaManager.mPackageName = null; assertThat(mInfoMediaManager.getSessionName()).isNull(); } @Test @Test public void getSessionName_routeSessionInfoIsNull_returnNull() { public void getSessionName_routeSessionInfoIsNull_returnNull() { final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); Loading Loading @@ -941,32 +809,6 @@ public class InfoMediaManagerTest { verify(mCallback).onConnectedDeviceChanged(TEST_ID); verify(mCallback).onConnectedDeviceChanged(TEST_ID); } } @Test public void onTransferred_buildAllRoutes_shouldAddMediaDevice() { final MediaRoute2Info info = mock(MediaRoute2Info.class); final RoutingSessionInfo sessionInfo = mock(RoutingSessionInfo.class); mInfoMediaManager.registerCallback(mCallback); when(info.getId()).thenReturn(TEST_ID); when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); when(info.isSystemRoute()).thenReturn(true); final List<MediaRoute2Info> routes = new ArrayList<>(); routes.add(info); mShadowRouter2Manager.setAllRoutes(routes); final MediaDevice mediaDevice = mInfoMediaManager.findMediaDevice(TEST_ID); assertThat(mediaDevice).isNull(); mInfoMediaManager.mPackageName = ""; mInfoMediaManager.mMediaRouterCallback.onTransferred(sessionInfo, sessionInfo); final MediaDevice infoDevice = mInfoMediaManager.mMediaDevices.get(0); assertThat(infoDevice.getId()).isEqualTo(TEST_ID); assertThat(mInfoMediaManager.mMediaDevices).hasSize(routes.size()); verify(mCallback).onConnectedDeviceChanged(null); } @Test @Test public void onSessionUpdated_shouldDispatchDeviceListAdded() { public void onSessionUpdated_shouldDispatchDeviceListAdded() { final MediaRoute2Info info = mock(MediaRoute2Info.class); final MediaRoute2Info info = mock(MediaRoute2Info.class); Loading @@ -978,7 +820,6 @@ public class InfoMediaManagerTest { routes.add(info); routes.add(info); mShadowRouter2Manager.setAllRoutes(routes); mShadowRouter2Manager.setAllRoutes(routes); mInfoMediaManager.mPackageName = ""; mInfoMediaManager.registerCallback(mCallback); mInfoMediaManager.registerCallback(mCallback); mInfoMediaManager.mMediaRouterCallback.onSessionUpdated(mock(RoutingSessionInfo.class)); mInfoMediaManager.mMediaRouterCallback.onSessionUpdated(mock(RoutingSessionInfo.class)); Loading