MediaRouter2: Release controller when transfer result arrives
Previously when MediaRouter2#transferTo(route) is called, it directly
released current controller. This CL changes the release timing to
when the actual transfer result comes.
Also, this CL prevents a RoutingController instance from being passed
both to:
- As 'oldController' in onTransfer()
- As 'controller' in onStop()
These works make TransferCallback easy to use: when onStop() is called,
app can just stop playing media.
Bug: 154680146
Test: Passed CTS / Checked logs in onTransfer/onStop
with output switcher
Change-Id: I4449021f98ca887252e05398356df9b53592c145
diff --git a/tests/tests/media/src/android/media/cts/MediaRouter2Test.java b/tests/tests/media/src/android/media/cts/MediaRouter2Test.java
index 566ebdd..2d1998e 100644
--- a/tests/tests/media/src/android/media/cts/MediaRouter2Test.java
+++ b/tests/tests/media/src/android/media/cts/MediaRouter2Test.java
@@ -269,6 +269,7 @@
final CountDownLatch successLatch1 = new CountDownLatch(1);
final CountDownLatch successLatch2 = new CountDownLatch(1);
final CountDownLatch failureLatch = new CountDownLatch(1);
+ final CountDownLatch stopLatch = new CountDownLatch(1);
final List<RoutingController> createdControllers = new ArrayList<>();
// Create session with this route
@@ -288,6 +289,11 @@
public void onTransferFailure(MediaRoute2Info requestedRoute) {
failureLatch.countDown();
}
+
+ @Override
+ public void onStop(RoutingController controller) {
+ stopLatch.countDown();
+ }
};
Map<String, MediaRoute2Info> routes = waitAndGetRoutes(sampleRouteType);
@@ -307,8 +313,9 @@
mRouter2.transferTo(route2);
assertTrue(successLatch2.await(TIMEOUT_MS, TimeUnit.MILLISECONDS));
- // onTransferFailure should not be called.
+ // onTransferFailure/onStop should not be called.
assertFalse(failureLatch.await(WAIT_MS, TimeUnit.MILLISECONDS));
+ assertFalse(stopLatch.await(WAIT_MS, TimeUnit.MILLISECONDS));
// Created controllers should have proper info
assertEquals(2, createdControllers.size());