From 3afc18af2cea898753b10e8575dcf20c11356bca Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Thu, 7 Mar 2013 13:21:13 -0800 Subject: [PATCH] Enhance MediaRouter API. The support library MediaRouter implementation needs a couple of extra generally useful APIs in the platform MediaRouter to ensure that it can safely synchronize its state. Change-Id: I72c5652e10f3b6de48800abfa922affbefbd250f --- api/current.txt | 1 + core/java/android/app/MediaRouteButton.java | 6 +++--- media/java/android/media/MediaRouter.java | 20 ++++++++++++++------ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/api/current.txt b/api/current.txt index 2e1dcf64aa180..72aecbbeebee7 100644 --- a/api/current.txt +++ b/api/current.txt @@ -11792,6 +11792,7 @@ package android.media { method public android.media.MediaRouter.UserRouteInfo createUserRoute(android.media.MediaRouter.RouteCategory); method public android.media.MediaRouter.RouteCategory getCategoryAt(int); method public int getCategoryCount(); + method public android.media.MediaRouter.RouteInfo getDefaultRoute(); method public android.media.MediaRouter.RouteInfo getRouteAt(int); method public int getRouteCount(); method public android.media.MediaRouter.RouteInfo getSelectedRoute(int); diff --git a/core/java/android/app/MediaRouteButton.java b/core/java/android/app/MediaRouteButton.java index a1a147a5f48bb..7e0a27aca508d 100644 --- a/core/java/android/app/MediaRouteButton.java +++ b/core/java/android/app/MediaRouteButton.java @@ -123,13 +123,13 @@ public class MediaRouteButton extends View { if (mToggleMode) { if (mRemoteActive) { - mRouter.selectRouteInt(mRouteTypes, mRouter.getSystemAudioRoute()); + mRouter.selectRouteInt(mRouteTypes, mRouter.getDefaultRoute()); } 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.getSystemAudioRoute()) { + route != mRouter.getDefaultRoute()) { mRouter.selectRouteInt(mRouteTypes, route); } } @@ -216,7 +216,7 @@ public class MediaRouteButton extends View { void updateRemoteIndicator() { final RouteInfo selected = mRouter.getSelectedRoute(mRouteTypes); - final boolean isRemote = selected != mRouter.getSystemAudioRoute(); + final boolean isRemote = selected != mRouter.getDefaultRoute(); final boolean isConnecting = selected != null && selected.getStatusCode() == RouteInfo.STATUS_CONNECTING; diff --git a/media/java/android/media/MediaRouter.java b/media/java/android/media/MediaRouter.java index 8b489b1c25b9f..795c3c2a38eb6 100644 --- a/media/java/android/media/MediaRouter.java +++ b/media/java/android/media/MediaRouter.java @@ -299,16 +299,21 @@ public class MediaRouter { } /** - * @hide for use by framework routing UI + * Gets the default route for playing media content on the system. + *

+ * The system always provides a default route. + *

+ * + * @return The default route, which is guaranteed to never be null. */ - public RouteInfo getSystemAudioRoute() { + public RouteInfo getDefaultRoute() { return sStatic.mDefaultAudioVideo; } /** * @hide for use by framework routing UI */ - public RouteCategory getSystemAudioCategory() { + public RouteCategory getSystemCategory() { return sStatic.mSystemCategory; } @@ -372,14 +377,17 @@ public class MediaRouter { /** * Select the specified route to use for output of the given media types. + *

+ * As API version 18, this function may be used to select any route. + * In prior versions, this function could only be used to select user + * routes and would ignore any attempt to select a system route. + *

* * @param types type flags indicating which types this route should be used for. * The route must support at least a subset. * @param route Route to select */ public void selectRoute(int types, RouteInfo route) { - // Applications shouldn't programmatically change anything but user routes. - types &= ROUTE_TYPE_USER; selectRouteStatic(types, route); } @@ -454,7 +462,7 @@ public class MediaRouter { * App-specified route definitions are created using {@link #createUserRoute(RouteCategory)} * * @param info Definition of the route to add - * @see #createUserRoute() + * @see #createUserRoute(RouteCategory) * @see #removeUserRoute(UserRouteInfo) */ public void addUserRoute(UserRouteInfo info) {