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

Commit 5ed626f0 authored by Matt Gilbride's avatar Matt Gilbride
Browse files

Migrate MediaProjectionManager#addCallback to @EnforcePermission

Use the recommended mechanism for permission enforcement in services.
This change is not *technically* behavior preserving because the manual
implementation used checkCallingPermission (as opposed to
checkCalling*orSelf*Permission.

It is safe to make this change since MANAGE_MEDIA_PROJECTION is very
locked down and orSelf simply covers calls within system server.

Bug: 275368789
Test: TH
Change-Id: I603dce46dab1a18c12bc5c25e796bf4e64e46fab
parent 3f1d5b58
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -108,6 +108,7 @@ interface IMediaProjectionManager {
                + ".permission.MANAGE_MEDIA_PROJECTION)")
    void notifyActiveProjectionCapturedContentVisibilityChanged(boolean isVisible);

    @EnforcePermission("MANAGE_MEDIA_PROJECTION")
    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
                + ".permission.MANAGE_MEDIA_PROJECTION)")
    void addCallback(IMediaProjectionWatcherCallback callback);
+2 −5
Original line number Diff line number Diff line
@@ -735,12 +735,9 @@ public final class MediaProjectionManagerService extends SystemService
        }

        @Override //Binder call
        @EnforcePermission(MANAGE_MEDIA_PROJECTION)
        public void addCallback(final IMediaProjectionWatcherCallback callback) {
            if (mContext.checkCallingPermission(MANAGE_MEDIA_PROJECTION)
                        != PackageManager.PERMISSION_GRANTED) {
                throw new SecurityException("Requires MANAGE_MEDIA_PROJECTION in order to add "
                        + "projection callbacks");
            }
            addCallback_enforcePermission();
            final long token = Binder.clearCallingIdentity();
            try {
                MediaProjectionManagerService.this.addCallback(callback);