diff options
author | Kyunglyul Hyun <klhyun@google.com> | 2020-04-14 19:56:16 +0900 |
---|---|---|
committer | Kyunglyul Hyun <klhyun@google.com> | 2020-04-21 14:17:08 +0900 |
commit | f0eb51bc40e50a9b604417b3ba58334a05ad1b25 (patch) | |
tree | 71ade330e7147aee75ac3923c130747400eb9a58 /media/tests | |
parent | 9c5a02c269f63b1a331be6ec07747ed8ef608c10 (diff) |
Use session hints when create a session from MR2Manager
When MR2Manager requests to create a routing session, it should pass
session hints to the target provider.
This CL adds a logic that MR2Manager asks media router instance to
get session hints to be passed to the provider.
Bug: 152851868
Test: atest mediaroutertest
Change-Id: Ib421f61f663090c6ed95c8b1a2f7deeb80e5be16
Diffstat (limited to 'media/tests')
-rw-r--r-- | media/tests/MediaRouter/src/com/android/mediaroutertest/MediaRouter2ManagerTest.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/media/tests/MediaRouter/src/com/android/mediaroutertest/MediaRouter2ManagerTest.java b/media/tests/MediaRouter/src/com/android/mediaroutertest/MediaRouter2ManagerTest.java index 6ca564fb34cc..49a8ce9a18fb 100644 --- a/media/tests/MediaRouter/src/com/android/mediaroutertest/MediaRouter2ManagerTest.java +++ b/media/tests/MediaRouter/src/com/android/mediaroutertest/MediaRouter2ManagerTest.java @@ -47,6 +47,7 @@ import android.media.MediaRouter2Manager; import android.media.MediaRouter2Utils; import android.media.RouteDiscoveryPreference; import android.media.RoutingSessionInfo; +import android.os.Bundle; import android.support.test.InstrumentationRegistry; import android.support.test.filters.SmallTest; import android.support.test.runner.AndroidJUnit4; @@ -73,6 +74,8 @@ public class MediaRouter2ManagerTest { private static final String TAG = "MediaRouter2ManagerTest"; private static final int WAIT_TIME_MS = 2000; private static final int TIMEOUT_MS = 5000; + private static final String TEST_KEY = "test_key"; + private static final String TEST_VALUE = "test_value"; private Context mContext; private MediaRouter2Manager mManager; @@ -465,6 +468,56 @@ public class MediaRouter2ManagerTest { assertEquals(VOLUME_MAX, variableVolumeRoute.getVolumeMax()); } + @Test + public void testRouter2SetOnGetControllerHintsListener() throws Exception { + Map<String, MediaRoute2Info> routes = waitAndGetRoutesWithManager(FEATURES_ALL); + addRouterCallback(new RouteCallback() {}); + + MediaRoute2Info route = routes.get(ROUTE_ID1); + assertNotNull(route); + + final Bundle controllerHints = new Bundle(); + controllerHints.putString(TEST_KEY, TEST_VALUE); + final CountDownLatch hintLatch = new CountDownLatch(1); + final MediaRouter2.OnGetControllerHintsListener listener = + route1 -> { + hintLatch.countDown(); + return controllerHints; + }; + + final CountDownLatch successLatch = new CountDownLatch(1); + final CountDownLatch failureLatch = new CountDownLatch(1); + + addManagerCallback(new MediaRouter2Manager.Callback() { + @Override + public void onTransferred(RoutingSessionInfo oldSession, + RoutingSessionInfo newSession) { + assertTrue(newSession.getSelectedRoutes().contains(route.getId())); + // The StubMediaRoute2ProviderService is supposed to set control hints + // with the given controllerHints. + Bundle controlHints = newSession.getControlHints(); + assertNotNull(controlHints); + assertTrue(controlHints.containsKey(TEST_KEY)); + assertEquals(TEST_VALUE, controlHints.getString(TEST_KEY)); + + successLatch.countDown(); + } + + @Override + public void onTransferFailed(RoutingSessionInfo session, + MediaRoute2Info requestedRoute) { + failureLatch.countDown(); + } + }); + + mRouter2.setOnGetControllerHintsListener(listener); + mManager.selectRoute(mPackageName, route); + assertTrue(hintLatch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS)); + assertTrue(successLatch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS)); + + assertFalse(failureLatch.await(WAIT_TIME_MS, TimeUnit.MILLISECONDS)); + } + Map<String, MediaRoute2Info> waitAndGetRoutesWithManager(List<String> routeFeatures) throws Exception { CountDownLatch addedLatch = new CountDownLatch(1); |