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

Commit 7ef7f2fb authored by Jaewan Kim's avatar Jaewan Kim Committed by android-build-merger
Browse files

Merge "MediaSession2: Ask server whether a controller is trusted" into pi-dev

am: b9332a43

Change-Id: I2933c572f9960dc1d39c7608c99914d79a06acff
parents d27836d3 b9332a43
Loading
Loading
Loading
Loading
+6 −24
Original line number Diff line number Diff line
@@ -974,31 +974,13 @@ public class MediaSession2Impl implements MediaSession2Provider {
            mInstance = instance;
            mUid = uid;
            mPackageName = packageName;

            // TODO(jaewan): Remove this workaround
            if ("com.android.server.media".equals(packageName)) {
                mIsTrusted = true;
            } else if (context.checkPermission(permission.MEDIA_CONTENT_CONTROL, pid, uid) ==
                    PackageManager.PERMISSION_GRANTED) {
                mIsTrusted = true;
            } else {
                // TODO(jaewan): Also consider enabled notification listener.
                mIsTrusted = false;
                // System apps may bind across the user so uid can be differ.
                // Skip sanity check for the system app.
                try {
                    int uidForPackage = context.getPackageManager().getPackageUid(packageName, 0);
                    if (uid != uidForPackage) {
                        throw new IllegalArgumentException("Illegal call from uid=" + uid +
                                ", pkg=" + packageName + ". Expected uid" + uidForPackage);
                    }
                } catch (NameNotFoundException e) {
                    // Rethrow exception with different name because binder methods only accept
                    // RemoteException.
                    throw new IllegalArgumentException(e);
                }
            }
            mControllerBinder = callback;
            MediaSessionManager manager =
                  (MediaSessionManager) context.getSystemService(Context.MEDIA_SESSION_SERVICE);
            // Ask server whether the controller is trusted.
            // App cannot know this because apps cannot query enabled notification listener for
            // another package, but system server can do.
            mIsTrusted = manager.isTrusted(uid, packageName);
        }

        @Override