Skip to content

Commit 1cf2ca8

Browse files
committed
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
1 parent ba4ac51 commit 1cf2ca8

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

core/java/android/app/MediaRouteButton.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ public int getRouteTypes() {
217217
void updateRemoteIndicator() {
218218
final RouteInfo selected = mRouter.getSelectedRoute(mRouteTypes);
219219
final boolean isRemote = selected != mRouter.getSystemAudioRoute();
220-
final boolean isConnecting = selected.getStatusCode() == RouteInfo.STATUS_CONNECTING;
220+
final boolean isConnecting = selected != null &&
221+
selected.getStatusCode() == RouteInfo.STATUS_CONNECTING;
221222

222223
boolean needsRefresh = false;
223224
if (mRemoteActive != isRemote) {

core/java/com/android/internal/app/MediaRouteChooserDialogFragment.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,14 @@ void updateVolume() {
136136
if (mRouter == null) return;
137137

138138
final RouteInfo selectedRoute = mRouter.getSelectedRoute(mRouteTypes);
139-
mVolumeIcon.setImageResource(
139+
mVolumeIcon.setImageResource(selectedRoute == null ||
140140
selectedRoute.getPlaybackType() == RouteInfo.PLAYBACK_TYPE_LOCAL ?
141141
R.drawable.ic_audio_vol : R.drawable.ic_media_route_on_holo_dark);
142142

143143
mIgnoreSliderVolumeChanges = true;
144144

145-
if (selectedRoute.getVolumeHandling() == RouteInfo.PLAYBACK_VOLUME_FIXED) {
145+
if (selectedRoute == null ||
146+
selectedRoute.getVolumeHandling() == RouteInfo.PLAYBACK_VOLUME_FIXED) {
146147
// Disable the slider and show it at max volume.
147148
mVolumeSlider.setMax(1);
148149
mVolumeSlider.setProgress(1);
@@ -160,7 +161,8 @@ void changeVolume(int newValue) {
160161
if (mIgnoreSliderVolumeChanges) return;
161162

162163
final RouteInfo selectedRoute = mRouter.getSelectedRoute(mRouteTypes);
163-
if (selectedRoute.getVolumeHandling() == RouteInfo.PLAYBACK_VOLUME_VARIABLE) {
164+
if (selectedRoute != null &&
165+
selectedRoute.getVolumeHandling() == RouteInfo.PLAYBACK_VOLUME_VARIABLE) {
164166
final int maxVolume = selectedRoute.getVolumeMax();
165167
newValue = Math.max(0, Math.min(newValue, maxVolume));
166168
selectedRoute.requestSetVolume(newValue);
@@ -652,14 +654,19 @@ public void onBackPressed() {
652654

653655
public boolean onKeyDown(int keyCode, KeyEvent event) {
654656
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN && mVolumeSlider.isEnabled()) {
655-
mRouter.getSelectedRoute(mRouteTypes).requestUpdateVolume(-1);
656-
return true;
657+
final RouteInfo selectedRoute = mRouter.getSelectedRoute(mRouteTypes);
658+
if (selectedRoute != null) {
659+
selectedRoute.requestUpdateVolume(-1);
660+
return true;
661+
}
657662
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && mVolumeSlider.isEnabled()) {
658-
mRouter.getSelectedRoute(mRouteTypes).requestUpdateVolume(1);
659-
return true;
660-
} else {
661-
return super.onKeyDown(keyCode, event);
663+
final RouteInfo selectedRoute = mRouter.getSelectedRoute(mRouteTypes);
664+
if (selectedRoute != null) {
665+
mRouter.getSelectedRoute(mRouteTypes).requestUpdateVolume(1);
666+
return true;
667+
}
662668
}
669+
return super.onKeyDown(keyCode, event);
663670
}
664671

665672
public boolean onKeyUp(int keyCode, KeyEvent event) {

media/java/android/media/MediaRouter.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,25 @@ public RouteCategory getSystemAudioCategory() {
313313
}
314314

315315
/**
316-
* Return the currently selected route for the given types
316+
* Return the currently selected route for any of the given types
317317
*
318318
* @param type route types
319319
* @return the selected route
320320
*/
321321
public RouteInfo getSelectedRoute(int type) {
322-
return sStatic.mSelectedRoute;
322+
if (sStatic.mSelectedRoute != null &&
323+
(sStatic.mSelectedRoute.mSupportedTypes & type) != 0) {
324+
// If the selected route supports any of the types supplied, it's still considered
325+
// 'selected' for that type.
326+
return sStatic.mSelectedRoute;
327+
} else if (type == ROUTE_TYPE_USER) {
328+
// The caller specifically asked for a user route and the currently selected route
329+
// doesn't qualify.
330+
return null;
331+
}
332+
// If the above didn't match and we're not specifically asking for a user route,
333+
// consider the default selected.
334+
return sStatic.mDefaultAudioVideo;
323335
}
324336

325337
/**

0 commit comments

Comments
 (0)