Merge "Add MediaRouterManager.Callback#onSessionReleased" into rvc-dev am: 2950ebf07d
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11733425 Change-Id: I720ea5577814b17bfcfc705585af154566367a59
This commit is contained in:
@@ -24,8 +24,9 @@ import android.media.RoutingSessionInfo;
|
||||
* {@hide}
|
||||
*/
|
||||
oneway interface IMediaRouter2Manager {
|
||||
void notifySessionCreated(int requestId, in RoutingSessionInfo sessionInfo);
|
||||
void notifySessionUpdated(in RoutingSessionInfo sessionInfo);
|
||||
void notifySessionCreated(int requestId, in RoutingSessionInfo session);
|
||||
void notifySessionUpdated(in RoutingSessionInfo session);
|
||||
void notifySessionReleased(in RoutingSessionInfo session);
|
||||
void notifyPreferredFeaturesChanged(String packageName, in List<String> preferredFeatures);
|
||||
void notifyRoutesAdded(in List<MediaRoute2Info> routes);
|
||||
void notifyRoutesRemoved(in List<MediaRoute2Info> routes);
|
||||
|
||||
@@ -509,7 +509,7 @@ public final class MediaRouter2Manager {
|
||||
notifyRequestFailed(reason);
|
||||
}
|
||||
|
||||
void handleSessionsUpdated(RoutingSessionInfo sessionInfo) {
|
||||
void handleSessionsUpdatedOnHandler(RoutingSessionInfo sessionInfo) {
|
||||
for (TransferRequest request : mTransferRequests) {
|
||||
String sessionId = request.mOldSessionInfo.getId();
|
||||
if (!TextUtils.equals(sessionId, sessionInfo.getId())) {
|
||||
@@ -551,6 +551,12 @@ public final class MediaRouter2Manager {
|
||||
}
|
||||
}
|
||||
|
||||
void notifySessionReleased(RoutingSessionInfo session) {
|
||||
for (CallbackRecord record : mCallbackRecords) {
|
||||
record.mExecutor.execute(() -> record.mCallback.onSessionReleased(session));
|
||||
}
|
||||
}
|
||||
|
||||
void notifyRequestFailed(int reason) {
|
||||
for (CallbackRecord record : mCallbackRecords) {
|
||||
record.mExecutor.execute(() -> record.mCallback.onRequestFailed(reason));
|
||||
@@ -864,9 +870,16 @@ public final class MediaRouter2Manager {
|
||||
|
||||
/**
|
||||
* Called when a session is changed.
|
||||
* @param sessionInfo the updated session
|
||||
* @param session the updated session
|
||||
*/
|
||||
public void onSessionUpdated(@NonNull RoutingSessionInfo sessionInfo) {}
|
||||
public void onSessionUpdated(@NonNull RoutingSessionInfo session) {}
|
||||
|
||||
/**
|
||||
* Called when a session is released.
|
||||
* @param session the released session.
|
||||
* @see #releaseSession(RoutingSessionInfo)
|
||||
*/
|
||||
public void onSessionReleased(@NonNull RoutingSessionInfo session) {}
|
||||
|
||||
/**
|
||||
* Called when media is transferred.
|
||||
@@ -946,15 +959,21 @@ public final class MediaRouter2Manager {
|
||||
|
||||
class Client extends IMediaRouter2Manager.Stub {
|
||||
@Override
|
||||
public void notifySessionCreated(int requestId, RoutingSessionInfo sessionInfo) {
|
||||
public void notifySessionCreated(int requestId, RoutingSessionInfo session) {
|
||||
mHandler.sendMessage(obtainMessage(MediaRouter2Manager::createSessionOnHandler,
|
||||
MediaRouter2Manager.this, requestId, sessionInfo));
|
||||
MediaRouter2Manager.this, requestId, session));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifySessionUpdated(RoutingSessionInfo sessionInfo) {
|
||||
mHandler.sendMessage(obtainMessage(MediaRouter2Manager::handleSessionsUpdated,
|
||||
MediaRouter2Manager.this, sessionInfo));
|
||||
public void notifySessionUpdated(RoutingSessionInfo session) {
|
||||
mHandler.sendMessage(obtainMessage(MediaRouter2Manager::handleSessionsUpdatedOnHandler,
|
||||
MediaRouter2Manager.this, session));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifySessionReleased(RoutingSessionInfo session) {
|
||||
mHandler.sendMessage(obtainMessage(MediaRouter2Manager::notifySessionReleased,
|
||||
MediaRouter2Manager.this, session));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -281,17 +281,19 @@ public class MediaRouter2ManagerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRoutingControllers() throws Exception {
|
||||
public void testGetRoutingSessions() throws Exception {
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
|
||||
Map<String, MediaRoute2Info> routes = waitAndGetRoutesWithManager(FEATURES_ALL);
|
||||
MediaRoute2Info routeToSelect = routes.get(ROUTE_ID1);
|
||||
|
||||
addRouterCallback(new RouteCallback() {});
|
||||
addManagerCallback(new MediaRouter2Manager.Callback() {
|
||||
@Override
|
||||
public void onTransferred(RoutingSessionInfo oldSessionInfo,
|
||||
RoutingSessionInfo newSessionInfo) {
|
||||
if (TextUtils.equals(mPackageName, newSessionInfo.getClientPackageName())
|
||||
&& newSessionInfo.getSelectedRoutes().contains(ROUTE_ID1)) {
|
||||
&& newSessionInfo.getSelectedRoutes().contains(routeToSelect.getId())) {
|
||||
latch.countDown();
|
||||
}
|
||||
}
|
||||
@@ -299,11 +301,10 @@ public class MediaRouter2ManagerTest {
|
||||
|
||||
assertEquals(1, mManager.getRoutingSessions(mPackageName).size());
|
||||
|
||||
mManager.selectRoute(mPackageName, routes.get(ROUTE_ID1));
|
||||
latch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
mManager.selectRoute(mPackageName, routeToSelect);
|
||||
assertTrue(latch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||
|
||||
List<RoutingSessionInfo> sessions = mManager.getRoutingSessions(mPackageName);
|
||||
|
||||
assertEquals(2, sessions.size());
|
||||
|
||||
RoutingSessionInfo sessionInfo = sessions.get(1);
|
||||
@@ -344,6 +345,47 @@ public class MediaRouter2ManagerTest {
|
||||
assertTrue(onTransferFailedLatch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRouterRelease_managerGetRoutingSessions() throws Exception {
|
||||
CountDownLatch transferLatch = new CountDownLatch(1);
|
||||
CountDownLatch releaseLatch = new CountDownLatch(1);
|
||||
|
||||
Map<String, MediaRoute2Info> routes = waitAndGetRoutesWithManager(FEATURES_ALL);
|
||||
MediaRoute2Info routeToSelect = routes.get(ROUTE_ID1);
|
||||
assertNotNull(routeToSelect);
|
||||
|
||||
addRouterCallback(new RouteCallback() {});
|
||||
addManagerCallback(new MediaRouter2Manager.Callback() {
|
||||
@Override
|
||||
public void onTransferred(RoutingSessionInfo oldSessionInfo,
|
||||
RoutingSessionInfo newSessionInfo) {
|
||||
if (TextUtils.equals(mPackageName, newSessionInfo.getClientPackageName())
|
||||
&& newSessionInfo.getSelectedRoutes().contains(routeToSelect.getId())) {
|
||||
transferLatch.countDown();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onSessionReleased(RoutingSessionInfo session) {
|
||||
releaseLatch.countDown();
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals(1, mManager.getRoutingSessions(mPackageName).size());
|
||||
assertEquals(1, mRouter2.getControllers().size());
|
||||
|
||||
mManager.transfer(mManager.getRoutingSessions(mPackageName).get(0), routeToSelect);
|
||||
assertTrue(transferLatch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||
|
||||
assertEquals(2, mManager.getRoutingSessions(mPackageName).size());
|
||||
assertEquals(2, mRouter2.getControllers().size());
|
||||
mRouter2.getControllers().get(1).release();
|
||||
|
||||
assertTrue(releaseLatch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||
|
||||
assertEquals(1, mRouter2.getControllers().size());
|
||||
assertEquals(1, mManager.getRoutingSessions(mPackageName).size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests select, transfer, release of routes of a provider
|
||||
*/
|
||||
|
||||
@@ -1583,7 +1583,7 @@ class MediaRouter2ServiceImpl {
|
||||
private void onSessionInfoChangedOnHandler(@NonNull MediaRoute2Provider provider,
|
||||
@NonNull RoutingSessionInfo sessionInfo) {
|
||||
List<IMediaRouter2Manager> managers = getManagers();
|
||||
notifySessionInfoChangedToManagers(managers, sessionInfo);
|
||||
notifySessionUpdatedToManagers(managers, sessionInfo);
|
||||
|
||||
// For system provider, notify all routers.
|
||||
if (provider == mSystemProvider) {
|
||||
@@ -1608,7 +1608,7 @@ class MediaRouter2ServiceImpl {
|
||||
private void onSessionReleasedOnHandler(@NonNull MediaRoute2Provider provider,
|
||||
@NonNull RoutingSessionInfo sessionInfo) {
|
||||
List<IMediaRouter2Manager> managers = getManagers();
|
||||
notifySessionInfoChangedToManagers(managers, sessionInfo);
|
||||
notifySessionReleasedToManagers(managers, sessionInfo);
|
||||
|
||||
RouterRecord routerRecord = mSessionToRouterMap.get(sessionInfo.getId());
|
||||
if (routerRecord == null) {
|
||||
@@ -1913,15 +1913,28 @@ class MediaRouter2ServiceImpl {
|
||||
}
|
||||
}
|
||||
|
||||
private void notifySessionInfoChangedToManagers(
|
||||
private void notifySessionUpdatedToManagers(
|
||||
@NonNull List<IMediaRouter2Manager> managers,
|
||||
@NonNull RoutingSessionInfo sessionInfo) {
|
||||
for (IMediaRouter2Manager manager : managers) {
|
||||
try {
|
||||
manager.notifySessionUpdated(sessionInfo);
|
||||
} catch (RemoteException ex) {
|
||||
Slog.w(TAG, "notifySessionInfosChangedToManagers: "
|
||||
+ "failed to notify. Manager probably died.", ex);
|
||||
Slog.w(TAG, "notifySessionUpdatedToManagers: "
|
||||
+ "Failed to notify. Manager probably died.", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void notifySessionReleasedToManagers(
|
||||
@NonNull List<IMediaRouter2Manager> managers,
|
||||
@NonNull RoutingSessionInfo sessionInfo) {
|
||||
for (IMediaRouter2Manager manager : managers) {
|
||||
try {
|
||||
manager.notifySessionReleased(sessionInfo);
|
||||
} catch (RemoteException ex) {
|
||||
Slog.w(TAG, "notifySessionReleasedToManagers: "
|
||||
+ "Failed to notify. Manager probably died.", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user