Merge "Update/Add method on InfoMediaManager" into rvc-dev am: 0b4de66f6d am: fa37d01676

Change-Id: I1d3cf11824a3a230b7853a115eabddfaf06f9523
This commit is contained in:
Automerger Merge Worker
2020-02-27 06:58:10 +00:00
3 changed files with 52 additions and 1 deletions

View File

@@ -170,6 +170,26 @@ public class InfoMediaManager extends MediaManager {
return false;
}
/**
* Release session to stop playing media on MediaDevice.
*/
boolean releaseSession() {
if (TextUtils.isEmpty(mPackageName)) {
Log.w(TAG, "releaseSession() package name is null or empty!");
return false;
}
final RoutingSessionInfo info = getRoutingSessionInfo();
if (info != null) {
mRouterManager.getControllerForSession(info).release();
return true;
}
Log.w(TAG, "releaseSession() Ignoring release session : " + mPackageName);
return false;
}
/**
* Get the MediaDevice list that can be added to current media.
*
@@ -304,7 +324,9 @@ public class InfoMediaManager extends MediaManager {
private void buildAllRoutes() {
for (MediaRoute2Info route : mRouterManager.getAllRoutes()) {
addMediaDevice(route);
if (route.isSystemRoute()) {
addMediaDevice(route);
}
}
}

View File

@@ -281,6 +281,13 @@ public class LocalMediaManager implements BluetoothCallback {
return mInfoMediaManager.getSelectableMediaDevice();
}
/**
* Release session to stop playing media on MediaDevice.
*/
public boolean releaseSession() {
return mInfoMediaManager.releaseSession();
}
/**
* Get the MediaDevice list that has been selected to current media.
*

View File

@@ -96,6 +96,7 @@ public class InfoMediaManagerTest {
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 @@ public class InfoMediaManagerTest {
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 @@ public class InfoMediaManagerTest {
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 @@ public class InfoMediaManagerTest {
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();
}
}