From 1cf2ca83584a4cf0aa3ded787bd191b9a60e3521 Mon Sep 17 00:00:00 2001 From: Adam Powell Date: Wed, 28 Nov 2012 10:46:56 -0800 Subject: Clean up behavior of type arguments for MediaRouter#getSelectedRoute MediaRouter's policy so far has been around a single selected route, but when route types are entirely orthogonal this should not be the case. However we still don't want to get into a situation where we have multiple, very different routes selected for different types at the same time, we still want to have more of an element of predictability. Behavior of getSelectedRoute is now: * If the selected route matches at least one type with the requested type flags, it is still considered selected for that request. * If the caller specifically requested the selected user route and the currently selected route is not a user route, return null. * If the requested type flags do not match any types with the selected route, return the default system route. Note that this is "any" behavior instead of "all" - this matches existing usage of the method. We may consider adding an "all" variant later on. Bug 7588042 Change-Id: I3a79d8153ca6b882fd3ef6b9b1de8f538873dec2 --- media/java/android/media/MediaRouter.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'media') diff --git a/media/java/android/media/MediaRouter.java b/media/java/android/media/MediaRouter.java index 8701f36..8b489b1 100644 --- a/media/java/android/media/MediaRouter.java +++ b/media/java/android/media/MediaRouter.java @@ -313,13 +313,25 @@ public class MediaRouter { } /** - * Return the currently selected route for the given types + * Return the currently selected route for any of the given types * * @param type route types * @return the selected route */ public RouteInfo getSelectedRoute(int type) { - return sStatic.mSelectedRoute; + if (sStatic.mSelectedRoute != null && + (sStatic.mSelectedRoute.mSupportedTypes & type) != 0) { + // If the selected route supports any of the types supplied, it's still considered + // 'selected' for that type. + return sStatic.mSelectedRoute; + } else if (type == ROUTE_TYPE_USER) { + // The caller specifically asked for a user route and the currently selected route + // doesn't qualify. + return null; + } + // If the above didn't match and we're not specifically asking for a user route, + // consider the default selected. + return sStatic.mDefaultAudioVideo; } /** -- cgit v1.1