diff --git a/media/java/android/media/MediaRouter2.java b/media/java/android/media/MediaRouter2.java
index f27a8dea737c4..6b67d1452debf 100644
--- a/media/java/android/media/MediaRouter2.java
+++ b/media/java/android/media/MediaRouter2.java
@@ -460,6 +460,9 @@ public final class MediaRouter2 {
* updates} in order to keep the system UI in a consistent state. You can also call this method
* at any other point to update the listing preference dynamically.
*
+ *
Any calls to this method from a privileged router will throw an {@link
+ * UnsupportedOperationException}.
+ *
*
Notes:
*
*
@@ -476,24 +479,7 @@ public final class MediaRouter2 {
* route listing. When null, the system uses its default listing criteria.
*/
public void setRouteListingPreference(@Nullable RouteListingPreference routeListingPreference) {
- synchronized (mLock) {
- if (Objects.equals(mRouteListingPreference, routeListingPreference)) {
- // Nothing changed. We return early to save a call to the system server.
- return;
- }
- mRouteListingPreference = routeListingPreference;
- try {
- if (mStub == null) {
- MediaRouter2Stub stub = new MediaRouter2Stub();
- mMediaRouterService.registerRouter2(stub, mImpl.getPackageName());
- mStub = stub;
- }
- mMediaRouterService.setRouteListingPreference(mStub, mRouteListingPreference);
- } catch (RemoteException ex) {
- ex.rethrowFromSystemServer();
- }
- notifyRouteListingPreferenceUpdated(routeListingPreference);
- }
+ mImpl.setRouteListingPreference(routeListingPreference);
}
/**
@@ -1962,6 +1948,8 @@ public final class MediaRouter2 {
void unregisterRouteCallback();
+ void setRouteListingPreference(@Nullable RouteListingPreference preference);
+
List getAllRoutes();
void setOnGetControllerHintsListener(OnGetControllerHintsListener listener);
@@ -2102,6 +2090,12 @@ public final class MediaRouter2 {
// Do nothing.
}
+ @Override
+ public void setRouteListingPreference(@Nullable RouteListingPreference preference) {
+ throw new UnsupportedOperationException(
+ "RouteListingPreference cannot be set by a privileged MediaRouter2 instance.");
+ }
+
/** Gets the list of all discovered routes. */
@Override
public List getAllRoutes() {
@@ -2892,6 +2886,28 @@ public final class MediaRouter2 {
}
}
+ @Override
+ public void setRouteListingPreference(@Nullable RouteListingPreference preference) {
+ synchronized (mLock) {
+ if (Objects.equals(mRouteListingPreference, preference)) {
+ // Nothing changed. We return early to save a call to the system server.
+ return;
+ }
+ mRouteListingPreference = preference;
+ try {
+ if (mStub == null) {
+ MediaRouter2Stub stub = new MediaRouter2Stub();
+ mMediaRouterService.registerRouter2(stub, mImpl.getPackageName());
+ mStub = stub;
+ }
+ mMediaRouterService.setRouteListingPreference(mStub, mRouteListingPreference);
+ } catch (RemoteException ex) {
+ ex.rethrowFromSystemServer();
+ }
+ notifyRouteListingPreferenceUpdated(preference);
+ }
+ }
+
/**
* Returns {@link Collections#emptyList()}. Local routes can only access routes related to
* their {@link RouteDiscoveryPreference} through {@link #getRoutes()}.