Add media router service and integrate with remote displays.
This change adds a new media router service whose purpose is to track
global state information associated with media routes. This service
publishes routes to the media router instance in application processes
and handles requested state changes such as selecting or unselecting
global routes. The service also binds to remote display provider
services which can offer new remote display routes to the system.
Includes a test application for manually verifying certain aspects
of the operation of the media router service.
The remote display provider interface is essentially a stripped down
media route provider interface as defined in the support library
media router implementation. For now, it is designed to be used only
by first parties to publish remote display routes to the system so
it is not exposed as public API in the SDK. In the future, the remote
display provider interface will most likely be deprecated and replaced
with a more featureful media route provider interface for third
party integration, similar to what is in the support library today.
Further patch sets integrate these new capabilities into the System UI
and Settings for connecting remote displays.
Bug: 11257292
Change-Id: I31109f23f17b474d17534d0f5f4503e388b081c2
diff --git a/core/java/android/app/MediaRouteButton.java b/core/java/android/app/MediaRouteButton.java
index 7e0a27a..9b1ff93 100644
--- a/core/java/android/app/MediaRouteButton.java
+++ b/core/java/android/app/MediaRouteButton.java
@@ -123,14 +123,14 @@
if (mToggleMode) {
if (mRemoteActive) {
- mRouter.selectRouteInt(mRouteTypes, mRouter.getDefaultRoute());
+ mRouter.selectRouteInt(mRouteTypes, mRouter.getDefaultRoute(), true);
} else {
final int N = mRouter.getRouteCount();
for (int i = 0; i < N; i++) {
final RouteInfo route = mRouter.getRouteAt(i);
if ((route.getSupportedTypes() & mRouteTypes) != 0 &&
route != mRouter.getDefaultRoute()) {
- mRouter.selectRouteInt(mRouteTypes, route);
+ mRouter.selectRouteInt(mRouteTypes, route, true);
}
}
}
@@ -201,7 +201,8 @@
if (mAttachedToWindow) {
updateRouteInfo();
- mRouter.addCallback(types, mRouterCallback);
+ mRouter.addCallback(types, mRouterCallback,
+ MediaRouter.CALLBACK_FLAG_PASSIVE_DISCOVERY);
}
}
@@ -217,8 +218,7 @@
void updateRemoteIndicator() {
final RouteInfo selected = mRouter.getSelectedRoute(mRouteTypes);
final boolean isRemote = selected != mRouter.getDefaultRoute();
- final boolean isConnecting = selected != null &&
- selected.getStatusCode() == RouteInfo.STATUS_CONNECTING;
+ final boolean isConnecting = selected != null && selected.isConnecting();
boolean needsRefresh = false;
if (mRemoteActive != isRemote) {
@@ -238,7 +238,7 @@
void updateRouteCount() {
final int N = mRouter.getRouteCount();
int count = 0;
- boolean hasVideoRoutes = false;
+ boolean scanRequired = false;
for (int i = 0; i < N; i++) {
final RouteInfo route = mRouter.getRouteAt(i);
final int routeTypes = route.getSupportedTypes();
@@ -248,8 +248,9 @@
} else {
count++;
}
- if ((routeTypes & MediaRouter.ROUTE_TYPE_LIVE_VIDEO) != 0) {
- hasVideoRoutes = true;
+ if (((routeTypes & MediaRouter.ROUTE_TYPE_LIVE_VIDEO
+ | MediaRouter.ROUTE_TYPE_REMOTE_DISPLAY)) != 0) {
+ scanRequired = true;
}
}
}
@@ -257,9 +258,10 @@
setEnabled(count != 0);
// Only allow toggling if we have more than just user routes.
- // Don't toggle if we support video routes, we may have to let the dialog scan.
- mToggleMode = count == 2 && (mRouteTypes & MediaRouter.ROUTE_TYPE_LIVE_AUDIO) != 0 &&
- !hasVideoRoutes;
+ // Don't toggle if we support video or remote display routes, we may have to
+ // let the dialog scan.
+ mToggleMode = count == 2 && (mRouteTypes & MediaRouter.ROUTE_TYPE_LIVE_AUDIO) != 0
+ && !scanRequired;
}
@Override
@@ -313,7 +315,8 @@
super.onAttachedToWindow();
mAttachedToWindow = true;
if (mRouteTypes != 0) {
- mRouter.addCallback(mRouteTypes, mRouterCallback);
+ mRouter.addCallback(mRouteTypes, mRouterCallback,
+ MediaRouter.CALLBACK_FLAG_PASSIVE_DISCOVERY);
updateRouteInfo();
}
}