Throw for showSystemOutputSwitcher() call from privileged router
Previously, a call from a privileged router would have thrown a Security
Exception from MediaRouterService in a similar way to ag/24264289.
Bug: 192657812
Test: atest MediaRouter2Test SystemMediaRouter2Test
Change-Id: I32e27d5dfdd07f1d6dc334ab5e8fd02817006ecf
diff --git a/media/java/android/media/MediaRouter2.java b/media/java/android/media/MediaRouter2.java
index 6b67d14..1baae4a 100644
--- a/media/java/android/media/MediaRouter2.java
+++ b/media/java/android/media/MediaRouter2.java
@@ -439,14 +439,7 @@
* call is ignored because the app is in the background.
*/
public boolean showSystemOutputSwitcher() {
- synchronized (mLock) {
- try {
- return mMediaRouterService.showMediaOutputSwitcher(mImpl.getPackageName());
- } catch (RemoteException ex) {
- ex.rethrowFromSystemServer();
- }
- }
- return false;
+ return mImpl.showSystemOutputSwitcher();
}
/**
@@ -1950,6 +1943,8 @@
void setRouteListingPreference(@Nullable RouteListingPreference preference);
+ boolean showSystemOutputSwitcher();
+
List<MediaRoute2Info> getAllRoutes();
void setOnGetControllerHintsListener(OnGetControllerHintsListener listener);
@@ -2096,6 +2091,12 @@
"RouteListingPreference cannot be set by a privileged MediaRouter2 instance.");
}
+ @Override
+ public boolean showSystemOutputSwitcher() {
+ throw new UnsupportedOperationException(
+ "Cannot show system output switcher from a privileged router.");
+ }
+
/** Gets the list of all discovered routes. */
@Override
public List<MediaRoute2Info> getAllRoutes() {
@@ -2908,6 +2909,18 @@
}
}
+ @Override
+ public boolean showSystemOutputSwitcher() {
+ synchronized (mLock) {
+ try {
+ return mMediaRouterService.showMediaOutputSwitcher(mImpl.getPackageName());
+ } catch (RemoteException ex) {
+ ex.rethrowFromSystemServer();
+ }
+ }
+ return false;
+ }
+
/**
* Returns {@link Collections#emptyList()}. Local routes can only access routes related to
* their {@link RouteDiscoveryPreference} through {@link #getRoutes()}.