Update/Add method on InfoMediaManager
This CL include following change:
- Filter out non system route on getAllRoutes().
- Add releaseSession() to release session to stop playing media
on MediaDevice.
- Add test case.
Bug: 149896648
Test: make -j42 RunSettingsLibRoboTests
Change-Id: Ibed6e22a8b01d5e1a3c92a80f569b21f40441c27
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/InfoMediaManagerTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/InfoMediaManagerTest.java
index 9668629..edb121b 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/InfoMediaManagerTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/InfoMediaManagerTest.java
@@ -96,6 +96,7 @@
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);
@@ -166,6 +167,7 @@
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);
@@ -221,6 +223,7 @@
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);
@@ -438,4 +441,23 @@
assertThat(mInfoMediaManager.getSessionVolume()).isEqualTo(-1);
}
+
+ @Test
+ public void releaseSession_packageNameIsNull_returnFalse() {
+ mInfoMediaManager.mPackageName = null;
+
+ assertThat(mInfoMediaManager.releaseSession()).isFalse();
+ }
+
+ @Test
+ public void releaseSession_removeSuccessfully_returnTrue() {
+ final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>();
+ final RoutingSessionInfo info = mock(RoutingSessionInfo.class);
+ routingSessionInfos.add(info);
+
+ mShadowRouter2Manager.setRoutingSessions(routingSessionInfos);
+ when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME);
+
+ assertThat(mInfoMediaManager.releaseSession()).isTrue();
+ }
}