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

Commit 6b9c2948 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I66723a00,I07f8182d

* changes:
  Enforce MEDIA_CONTENT_CONTROL in verifyPackageName
  Simplify if/else branch in MR2ServiceImpl
parents aa757543 c5944b17
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -50,8 +50,7 @@ interface IMediaRouterService {
    // MediaRouterService.java for readability.

    // Methods for MediaRouter2
    boolean verifyPackageName(String clientPackageName);
    void enforceMediaContentControlPermission();
    boolean verifyPackageExists(String clientPackageName);
    List<MediaRoute2Info> getSystemRoutes();
    RoutingSessionInfo getSystemSessionInfo();

+3 −3
Original line number Diff line number Diff line
@@ -208,9 +208,9 @@ public final class MediaRouter2 {
                IMediaRouterService.Stub.asInterface(
                        ServiceManager.getService(Context.MEDIA_ROUTER_SERVICE));
        try {
            // SecurityException will be thrown if there's no permission.
            serviceBinder.enforceMediaContentControlPermission();
            if (!serviceBinder.verifyPackageName(clientPackageName)) {
            // verifyPackageExists throws SecurityException if the caller doesn't hold
            // MEDIA_CONTENT_CONTROL permission.
            if (!serviceBinder.verifyPackageExists(clientPackageName)) {
                Log.e(TAG, "Package " + clientPackageName + " not found. Ignoring.");
                return null;
            }
+13 −20
Original line number Diff line number Diff line
@@ -169,10 +169,17 @@ class MediaRouter2ServiceImpl {
    // Start of methods that implement MediaRouter2 operations.

    @NonNull
    public boolean verifyPackageName(@NonNull String clientPackageName) {
    public boolean verifyPackageExists(@NonNull String clientPackageName) {
        final int pid = Binder.getCallingPid();
        final int uid = Binder.getCallingUid();
        final long token = Binder.clearCallingIdentity();

        try {
            mContext.enforcePermission(
                    Manifest.permission.MEDIA_CONTENT_CONTROL,
                    pid,
                    uid,
                    "Must hold MEDIA_CONTENT_CONTROL permission.");
            PackageManager pm = mContext.getPackageManager();
            pm.getPackageInfo(clientPackageName, PackageManager.PackageInfoFlags.of(0));
            return true;
@@ -183,20 +190,6 @@ class MediaRouter2ServiceImpl {
        }
    }

    @NonNull
    public void enforceMediaContentControlPermission() {
        final int pid = Binder.getCallingPid();
        final int uid = Binder.getCallingUid();
        final long token = Binder.clearCallingIdentity();

        try {
            mContext.enforcePermission(Manifest.permission.MEDIA_CONTENT_CONTROL, pid, uid,
                    "Must hold MEDIA_CONTENT_CONTROL permission.");
        } finally {
            Binder.restoreCallingIdentity(token);
        }
    }

    @NonNull
    public List<MediaRoute2Info> getSystemRoutes() {
        final int uid = Binder.getCallingUid();
@@ -1959,12 +1952,12 @@ class MediaRouter2ServiceImpl {
                @NonNull RoutingSessionInfo oldSession, @NonNull MediaRoute2Info route) {
            try {
                if (route.isSystemRoute() && !routerRecord.mHasModifyAudioRoutingPermission) {
                    routerRecord.mRouter.requestCreateSessionByManager(uniqueRequestId,
                            oldSession, mSystemProvider.getDefaultRoute());
                } else {
                    routerRecord.mRouter.requestCreateSessionByManager(uniqueRequestId,
                            oldSession, route);
                    // The router lacks permission to modify system routing, so we hide system
                    // route info from them.
                    route = mSystemProvider.getDefaultRoute();
                }
                routerRecord.mRouter.requestCreateSessionByManager(
                        uniqueRequestId, oldSession, route);
            } catch (RemoteException ex) {
                Slog.w(TAG, "getSessionHintsForCreatingSessionOnHandler: "
                        + "Failed to request. Router probably died.", ex);
+2 −8
Original line number Diff line number Diff line
@@ -380,14 +380,8 @@ public final class MediaRouterService extends IMediaRouterService.Stub

    // Binder call
    @Override
    public boolean verifyPackageName(String clientPackageName) {
        return mService2.verifyPackageName(clientPackageName);
    }

    // Binder call
    @Override
    public void enforceMediaContentControlPermission() {
        mService2.enforceMediaContentControlPermission();
    public boolean verifyPackageExists(String clientPackageName) {
        return mService2.verifyPackageExists(clientPackageName);
    }

    // Binder call