Merge "Clear routes when media router manager has no callback" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
1bb914e8ec
@@ -237,9 +237,9 @@ public final class MediaRouter2 {
|
|||||||
} catch (RemoteException ex) {
|
} catch (RemoteException ex) {
|
||||||
Log.e(TAG, "Unable to unregister media router.", ex);
|
Log.e(TAG, "Unable to unregister media router.", ex);
|
||||||
}
|
}
|
||||||
|
mStub = null;
|
||||||
}
|
}
|
||||||
mShouldUpdateRoutes = true;
|
mShouldUpdateRoutes = true;
|
||||||
mStub = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -147,14 +147,16 @@ public final class MediaRouter2Manager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
synchronized (sLock) {
|
synchronized (sLock) {
|
||||||
if (mCallbackRecords.size() == 0 && mClient != null) {
|
if (mCallbackRecords.size() == 0) {
|
||||||
try {
|
if (mClient != null) {
|
||||||
mMediaRouterService.unregisterManager(mClient);
|
try {
|
||||||
} catch (RemoteException ex) {
|
mMediaRouterService.unregisterManager(mClient);
|
||||||
Log.e(TAG, "Unable to unregister media router manager", ex);
|
} catch (RemoteException ex) {
|
||||||
|
Log.e(TAG, "Unable to unregister media router manager", ex);
|
||||||
|
}
|
||||||
|
mClient = null;
|
||||||
}
|
}
|
||||||
//TODO: clear mRoutes?
|
mRoutes.clear();
|
||||||
mClient = null;
|
|
||||||
mPreferredFeaturesMap.clear();
|
mPreferredFeaturesMap.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import static com.android.mediaroutertest.StubMediaRoute2ProviderService.VOLUME_
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -160,6 +161,7 @@ public class MediaRouter2ManagerTest {
|
|||||||
});
|
});
|
||||||
|
|
||||||
MediaRoute2Info routeToRemove = routes.get(ROUTE_ID2);
|
MediaRoute2Info routeToRemove = routes.get(ROUTE_ID2);
|
||||||
|
assertNotNull(routeToRemove);
|
||||||
|
|
||||||
StubMediaRoute2ProviderService sInstance =
|
StubMediaRoute2ProviderService sInstance =
|
||||||
StubMediaRoute2ProviderService.getInstance();
|
StubMediaRoute2ProviderService.getInstance();
|
||||||
@@ -171,6 +173,52 @@ public class MediaRouter2ManagerTest {
|
|||||||
assertTrue(addedLatch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
assertTrue(addedLatch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetRoutes_removedRoute_returnsCorrectRoutes() throws Exception {
|
||||||
|
CountDownLatch addedLatch = new CountDownLatch(1);
|
||||||
|
CountDownLatch removedLatch = new CountDownLatch(1);
|
||||||
|
|
||||||
|
RouteCallback routeCallback = new RouteCallback() {
|
||||||
|
// Used to ensure the removed route is added.
|
||||||
|
@Override
|
||||||
|
public void onRoutesAdded(List<MediaRoute2Info> routes) {
|
||||||
|
if (removedLatch.getCount() > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
addedLatch.countDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRoutesRemoved(List<MediaRoute2Info> routes) {
|
||||||
|
removedLatch.countDown();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
mRouter2.registerRouteCallback(mExecutor, routeCallback,
|
||||||
|
new RouteDiscoveryPreference.Builder(FEATURES_ALL, true).build());
|
||||||
|
mRouteCallbacks.add(routeCallback);
|
||||||
|
|
||||||
|
Map<String, MediaRoute2Info> routes = waitAndGetRoutesWithManager(FEATURES_ALL);
|
||||||
|
MediaRoute2Info routeToRemove = routes.get(ROUTE_ID2);
|
||||||
|
assertNotNull(routeToRemove);
|
||||||
|
|
||||||
|
StubMediaRoute2ProviderService sInstance =
|
||||||
|
StubMediaRoute2ProviderService.getInstance();
|
||||||
|
assertNotNull(sInstance);
|
||||||
|
sInstance.removeRoute(ROUTE_ID2);
|
||||||
|
|
||||||
|
// Wait until the route is removed.
|
||||||
|
assertTrue(removedLatch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||||
|
|
||||||
|
Map<String, MediaRoute2Info> newRoutes = waitAndGetRoutesWithManager(FEATURES_ALL);
|
||||||
|
assertNull(newRoutes.get(ROUTE_ID2));
|
||||||
|
|
||||||
|
// Revert the removal.
|
||||||
|
sInstance.addRoute(routeToRemove);
|
||||||
|
assertTrue(addedLatch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||||
|
mRouter2.unregisterRouteCallback(routeCallback);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests if we get proper routes for application that has special route feature.
|
* Tests if we get proper routes for application that has special route feature.
|
||||||
*/
|
*/
|
||||||
@@ -475,8 +523,8 @@ public class MediaRouter2ManagerTest {
|
|||||||
MediaRouter2Manager.Callback managerCallback = new MediaRouter2Manager.Callback() {
|
MediaRouter2Manager.Callback managerCallback = new MediaRouter2Manager.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void onRoutesAdded(List<MediaRoute2Info> routes) {
|
public void onRoutesAdded(List<MediaRoute2Info> routes) {
|
||||||
for (int i = 0; i < routes.size(); i++) {
|
for (MediaRoute2Info route : routes) {
|
||||||
if (!routes.get(i).isSystemRoute()) {
|
if (!route.isSystemRoute()) {
|
||||||
addedLatch.countDown();
|
addedLatch.countDown();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,9 +65,9 @@ public class StubMediaRoute2ProviderService extends MediaRoute2ProviderService {
|
|||||||
public static final String ROUTE_NAME_VARIABLE_VOLUME = "Variable Volume Route";
|
public static final String ROUTE_NAME_VARIABLE_VOLUME = "Variable Volume Route";
|
||||||
|
|
||||||
public static final String FEATURE_SAMPLE =
|
public static final String FEATURE_SAMPLE =
|
||||||
"com.android.mediarouteprovider.FEATURE_SAMPLE";
|
"com.android.mediaroutertest.FEATURE_SAMPLE";
|
||||||
public static final String FEATURE_SPECIAL =
|
public static final String FEATURE_SPECIAL =
|
||||||
"com.android.mediarouteprovider.FEATURE_SPECIAL";
|
"com.android.mediaroutertest..FEATURE_SPECIAL";
|
||||||
|
|
||||||
Map<String, MediaRoute2Info> mRoutes = new HashMap<>();
|
Map<String, MediaRoute2Info> mRoutes = new HashMap<>();
|
||||||
Map<String, String> mRouteIdToSessionId = new HashMap<>();
|
Map<String, String> mRouteIdToSessionId = new HashMap<>();
|
||||||
|
|||||||
Reference in New Issue
Block a user