summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Zhang <chz@google.com>2013-11-08 09:46:24 -0800
committerChong Zhang <chz@google.com>2013-11-08 19:02:48 -0800
commit5830b0b33618940d65197cec99d697b21908fec8 (patch)
tree181c0879f182a2f65e082903e8aefa39f7b18064
parented7376fc4829e93f5f2d3037633a37d652a13a7c (diff)
downloadframeworks_base-5830b0b33618940d65197cec99d697b21908fec8.zip
frameworks_base-5830b0b33618940d65197cec99d697b21908fec8.tar.gz
frameworks_base-5830b0b33618940d65197cec99d697b21908fec8.tar.bz2
Fixed a bug updating presentation displays.
Also made findRemoteDisplay public. Bug: 11257292 Change-Id: Ibc9bf3d8ee7c90293ffd8796270e8883ea458a65
-rw-r--r--media/java/android/media/MediaRouter.java106
-rw-r--r--media/lib/java/com/android/media/remotedisplay/RemoteDisplayProvider.java13
2 files changed, 65 insertions, 54 deletions
diff --git a/media/java/android/media/MediaRouter.java b/media/java/android/media/MediaRouter.java
index c184e8f..fb62812 100644
--- a/media/java/android/media/MediaRouter.java
+++ b/media/java/android/media/MediaRouter.java
@@ -137,8 +137,7 @@ public class MediaRouter {
mDefaultAudioVideo = new RouteInfo(mSystemCategory);
mDefaultAudioVideo.mNameResId = com.android.internal.R.string.default_audio_route_name;
mDefaultAudioVideo.mSupportedTypes = ROUTE_TYPE_LIVE_AUDIO | ROUTE_TYPE_LIVE_VIDEO;
- mDefaultAudioVideo.mPresentationDisplay = choosePresentationDisplayForRoute(
- mDefaultAudioVideo, getAllPresentationDisplays());
+ mDefaultAudioVideo.updatePresentationDisplay();
addRouteStatic(mDefaultAudioVideo);
// This will select the active wifi display route if there is one.
@@ -311,15 +310,12 @@ public class MediaRouter {
}
private void updatePresentationDisplays(int changedDisplayId) {
- final Display[] displays = getAllPresentationDisplays();
final int count = mRoutes.size();
for (int i = 0; i < count; i++) {
- final RouteInfo info = mRoutes.get(i);
- Display display = choosePresentationDisplayForRoute(info, displays);
- if (display != info.mPresentationDisplay
- || (display != null && display.getDisplayId() == changedDisplayId)) {
- info.mPresentationDisplay = display;
- dispatchRoutePresentationDisplayChanged(info);
+ final RouteInfo route = mRoutes.get(i);
+ if (route.updatePresentationDisplay() || (route.mPresentationDisplay != null
+ && route.mPresentationDisplay.getDisplayId() == changedDisplayId)) {
+ dispatchRoutePresentationDisplayChanged(route);
}
}
}
@@ -480,7 +476,8 @@ public class MediaRouter {
route.mVolume = globalRoute.volume;
route.mVolumeMax = globalRoute.volumeMax;
route.mVolumeHandling = globalRoute.volumeHandling;
- route.mPresentationDisplay = getDisplayForGlobalRoute(globalRoute);
+ route.mPresentationDisplayId = globalRoute.presentationDisplayId;
+ route.updatePresentationDisplay();
return route;
}
@@ -532,9 +529,9 @@ public class MediaRouter {
changed = true;
volumeChanged = true;
}
- final Display presentationDisplay = getDisplayForGlobalRoute(globalRoute);
- if (route.mPresentationDisplay != presentationDisplay) {
- route.mPresentationDisplay = presentationDisplay;
+ if (route.mPresentationDisplayId != globalRoute.presentationDisplayId) {
+ route.mPresentationDisplayId = globalRoute.presentationDisplayId;
+ route.updatePresentationDisplay();
changed = true;
presentationDisplayChanged = true;
}
@@ -550,19 +547,6 @@ public class MediaRouter {
}
}
- Display getDisplayForGlobalRoute(MediaRouterClientState.RouteInfo globalRoute) {
- // Ensure that the specified display is valid for presentations.
- // This check will normally disallow the default display unless it was configured
- // as a presentation display for some reason.
- if (globalRoute.presentationDisplayId >= 0) {
- Display display = mDisplayService.getDisplay(globalRoute.presentationDisplayId);
- if (display != null && display.isPublicPresentation()) {
- return display;
- }
- }
- return null;
- }
-
RouteInfo findGlobalRoute(String globalRouteId) {
final int count = mRoutes.size();
for (int i = 0; i < count; i++) {
@@ -1312,9 +1296,7 @@ public class MediaRouter {
newRoute.mName = display.getFriendlyDisplayName();
newRoute.mDescription = sStatic.mResources.getText(
com.android.internal.R.string.wireless_display_route_description);
-
- newRoute.mPresentationDisplay = choosePresentationDisplayForRoute(newRoute,
- sStatic.getAllPresentationDisplays());
+ newRoute.updatePresentationDisplay();
return newRoute;
}
@@ -1364,27 +1346,6 @@ public class MediaRouter {
return null;
}
- private static Display choosePresentationDisplayForRoute(RouteInfo route, Display[] displays) {
- if ((route.mSupportedTypes & ROUTE_TYPE_LIVE_VIDEO) != 0) {
- if (route.mDeviceAddress != null) {
- // Find the indicated Wifi display by its address.
- for (Display display : displays) {
- if (display.getType() == Display.TYPE_WIFI
- && route.mDeviceAddress.equals(display.getAddress())) {
- return display;
- }
- }
- return null;
- }
-
- if (route == sStatic.mDefaultAudioVideo && displays.length > 0) {
- // Choose the first presentation display from the list.
- return displays[0];
- }
- }
- return null;
- }
-
/**
* Information about a media route.
*/
@@ -1405,6 +1366,7 @@ public class MediaRouter {
int mPlaybackStream = AudioManager.STREAM_MUSIC;
VolumeCallbackInfo mVcb;
Display mPresentationDisplay;
+ int mPresentationDisplayId = -1;
String mDeviceAddress;
boolean mEnabled = true;
@@ -1743,6 +1705,50 @@ public class MediaRouter {
return mPresentationDisplay;
}
+ boolean updatePresentationDisplay() {
+ Display display = choosePresentationDisplay();
+ if (mPresentationDisplay != display) {
+ mPresentationDisplay = display;
+ return true;
+ }
+ return false;
+ }
+
+ private Display choosePresentationDisplay() {
+ if ((mSupportedTypes & ROUTE_TYPE_LIVE_VIDEO) != 0) {
+ Display[] displays = sStatic.getAllPresentationDisplays();
+
+ // Ensure that the specified display is valid for presentations.
+ // This check will normally disallow the default display unless it was
+ // configured as a presentation display for some reason.
+ if (mPresentationDisplayId >= 0) {
+ for (Display display : displays) {
+ if (display.getDisplayId() == mPresentationDisplayId) {
+ return display;
+ }
+ }
+ return null;
+ }
+
+ // Find the indicated Wifi display by its address.
+ if (mDeviceAddress != null) {
+ for (Display display : displays) {
+ if (display.getType() == Display.TYPE_WIFI
+ && mDeviceAddress.equals(display.getAddress())) {
+ return display;
+ }
+ }
+ return null;
+ }
+
+ // For the default route, choose the first presentation display from the list.
+ if (this == sStatic.mDefaultAudioVideo && displays.length > 0) {
+ return displays[0];
+ }
+ }
+ return null;
+ }
+
/**
* Returns true if this route is enabled and may be selected.
*
diff --git a/media/lib/java/com/android/media/remotedisplay/RemoteDisplayProvider.java b/media/lib/java/com/android/media/remotedisplay/RemoteDisplayProvider.java
index 8e4042c..701c39c 100644
--- a/media/lib/java/com/android/media/remotedisplay/RemoteDisplayProvider.java
+++ b/media/lib/java/com/android/media/remotedisplay/RemoteDisplayProvider.java
@@ -257,6 +257,15 @@ public abstract class RemoteDisplayProvider {
publishState();
}
+ /**
+ * Finds the remote display with the specified id, returns null if not found.
+ *
+ * @param id Id of the remote display.
+ */
+ public RemoteDisplay findRemoteDisplay(String id) {
+ return mDisplays.get(id);
+ }
+
void setCallback(IRemoteDisplayCallback callback) {
mCallback = callback;
publishState();
@@ -285,10 +294,6 @@ public abstract class RemoteDisplayProvider {
}
}
- RemoteDisplay findRemoteDisplay(String id) {
- return mDisplays.get(id);
- }
-
final class ProviderStub extends IRemoteDisplayProvider.Stub {
@Override
public void setCallback(IRemoteDisplayCallback callback) {