Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8b38bc8a authored by Iván Budnik's avatar Iván Budnik Committed by Android (Google) Code Review
Browse files

Merge "Throw when setting RLP with privileged routers" into main

parents 811891a8 cdc8eecb
Loading
Loading
Loading
Loading
+34 −18
Original line number Diff line number Diff line
@@ -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.
     *
     * <p>Any calls to this method from a privileged router will throw an {@link
     * UnsupportedOperationException}.
     *
     * <p>Notes:
     *
     * <ol>
@@ -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<MediaRoute2Info> 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<MediaRoute2Info> 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()}.