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

Commit 9b766c8c authored by Matt Gilbride's avatar Matt Gilbride Committed by Android (Google) Code Review
Browse files

Merge "@EnforcePermission migrations - MediaProjectionManagerService"

parents c30e3a93 c2d36e41
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ interface IMediaProjection {
    boolean canProjectVideo();
    boolean canProjectSecureVideo();

    @EnforcePermission("MANAGE_MEDIA_PROJECTION")
    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    int applyVirtualDisplayFlags(int flags);
@@ -40,6 +41,7 @@ interface IMediaProjection {
     * Returns the {@link android.os.IBinder} identifying the task to record, or {@code null} if
     * there is none.
     */
    @EnforcePermission("MANAGE_MEDIA_PROJECTION")
    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    IBinder getLaunchCookie();
@@ -48,6 +50,7 @@ interface IMediaProjection {
     * Updates the {@link android.os.IBinder} identifying the task to record, or {@code null} if
     * there is none.
     */
    @EnforcePermission("MANAGE_MEDIA_PROJECTION")
    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    void setLaunchCookie(in IBinder launchCookie);
@@ -62,6 +65,7 @@ interface IMediaProjection {
     * @throws IllegalStateException If the caller's target SDK is at least {@code U} and the
     * projection is not valid.
     */
    @EnforcePermission("MANAGE_MEDIA_PROJECTION")
    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    boolean isValid();
@@ -70,6 +74,7 @@ interface IMediaProjection {
     * Sets that {@link MediaProjection#createVirtualDisplay} has been invoked with this token (it
     * should only be called once).
     */
    @EnforcePermission("MANAGE_MEDIA_PROJECTION")
    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    void notifyVirtualDisplayCreated(int displayId);
+6 −0
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ interface IMediaProjectionManager {
     * Returns {@code true} if the given {@link IMediaProjection} corresponds to the current
     * projection, or {@code false} otherwise.
     */
    @EnforcePermission("MANAGE_MEDIA_PROJECTION")
    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    boolean isCurrentProjection(IMediaProjection projection);
@@ -83,6 +84,7 @@ interface IMediaProjectionManager {
     *
     * <p>Returns immediately but waits to start recording until user has reviewed their consent.
     */
    @EnforcePermission("MANAGE_MEDIA_PROJECTION")
    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    void requestConsentForInvalidProjection(in IMediaProjection projection);
@@ -91,14 +93,17 @@ interface IMediaProjectionManager {
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    MediaProjectionInfo getActiveProjectionInfo();

    @EnforcePermission("MANAGE_MEDIA_PROJECTION")
    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    void stopActiveProjection();

    @EnforcePermission("MANAGE_MEDIA_PROJECTION")
    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    void notifyActiveProjectionCapturedContentResized(int width, int height);

    @EnforcePermission("MANAGE_MEDIA_PROJECTION")
    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
                + ".permission.MANAGE_MEDIA_PROJECTION)")
    void notifyActiveProjectionCapturedContentVisibilityChanged(boolean isVisible);
@@ -123,6 +128,7 @@ interface IMediaProjectionManager {
     * @param projection      the non-null projection the session describes
     * @throws SecurityException If the provided projection is not current.
     */
  @EnforcePermission("MANAGE_MEDIA_PROJECTION")
  @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    boolean setContentRecordingSession(in ContentRecordingSession incomingSession,
+22 −55
Original line number Diff line number Diff line
@@ -588,13 +588,10 @@ public final class MediaProjectionManagerService extends SystemService
            return projection;
        }

        @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_MEDIA_PROJECTION)
        @Override // Binder call
        public boolean isCurrentProjection(IMediaProjection projection) {
            if (mContext.checkCallingOrSelfPermission(MANAGE_MEDIA_PROJECTION)
                    != PackageManager.PERMISSION_GRANTED) {
                throw new SecurityException("Requires MANAGE_MEDIA_PROJECTION in order to check "
                        + "if the given projection is current.");
            }
            isCurrentProjection_enforcePermission();
            return MediaProjectionManagerService.this.isCurrentProjection(
                    projection == null ? null : projection.asBinder());
        }
@@ -614,13 +611,10 @@ public final class MediaProjectionManagerService extends SystemService
            }
        }

        @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_MEDIA_PROJECTION)
        @Override // Binder call
        public void stopActiveProjection() {
            if (mContext.checkCallingOrSelfPermission(MANAGE_MEDIA_PROJECTION)
                    != PackageManager.PERMISSION_GRANTED) {
                throw new SecurityException("Requires MANAGE_MEDIA_PROJECTION in order to stop "
                        + "the active projection");
            }
            stopActiveProjection_enforcePermission();
            final long token = Binder.clearCallingIdentity();
            try {
                if (mProjectionGrant != null) {
@@ -631,13 +625,10 @@ public final class MediaProjectionManagerService extends SystemService
            }
        }

        @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_MEDIA_PROJECTION)
        @Override // Binder call
        public void notifyActiveProjectionCapturedContentResized(int width, int height) {
            if (mContext.checkCallingOrSelfPermission(MANAGE_MEDIA_PROJECTION)
                    != PackageManager.PERMISSION_GRANTED) {
                throw new SecurityException("Requires MANAGE_MEDIA_PROJECTION in order to notify "
                        + "on captured content resize");
            }
            notifyActiveProjectionCapturedContentResized_enforcePermission();
            if (!isCurrentProjection(mProjectionGrant)) {
                return;
            }
@@ -651,13 +642,10 @@ public final class MediaProjectionManagerService extends SystemService
            }
        }

        @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_MEDIA_PROJECTION)
        @Override
        public void notifyActiveProjectionCapturedContentVisibilityChanged(boolean isVisible) {
            if (mContext.checkCallingOrSelfPermission(MANAGE_MEDIA_PROJECTION)
                    != PackageManager.PERMISSION_GRANTED) {
                throw new SecurityException("Requires MANAGE_MEDIA_PROJECTION in order to notify "
                        + "on captured content visibility changed");
            }
            notifyActiveProjectionCapturedContentVisibilityChanged_enforcePermission();
            if (!isCurrentProjection(mProjectionGrant)) {
                return;
            }
@@ -701,14 +689,11 @@ public final class MediaProjectionManagerService extends SystemService
            }
        }

        @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_MEDIA_PROJECTION)
        @Override
        public boolean setContentRecordingSession(@Nullable ContentRecordingSession incomingSession,
                @NonNull IMediaProjection projection) {
            if (mContext.checkCallingOrSelfPermission(Manifest.permission.MANAGE_MEDIA_PROJECTION)
                    != PackageManager.PERMISSION_GRANTED) {
                throw new SecurityException("Requires MANAGE_MEDIA_PROJECTION to set session "
                        + "details.");
            }
            setContentRecordingSession_enforcePermission();
            if (!isCurrentProjection(projection)) {
                throw new SecurityException("Unable to set ContentRecordingSession on "
                        + "non-current MediaProjection");
@@ -722,13 +707,10 @@ public final class MediaProjectionManagerService extends SystemService
            }
        }

        @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_MEDIA_PROJECTION)
        @Override
        public void requestConsentForInvalidProjection(@NonNull IMediaProjection projection) {
            if (mContext.checkCallingOrSelfPermission(Manifest.permission.MANAGE_MEDIA_PROJECTION)
                    != PackageManager.PERMISSION_GRANTED) {
                throw new SecurityException("Requires MANAGE_MEDIA_PROJECTION to check if the given"
                        + "projection is valid.");
            }
            requestConsentForInvalidProjection_enforcePermission();
            if (!isCurrentProjection(projection)) {
                Slog.v(TAG, "Reusing token: Won't request consent again for a token that "
                        + "isn't current");
@@ -840,13 +822,10 @@ public final class MediaProjectionManagerService extends SystemService
                || mType == MediaProjectionManager.TYPE_SCREEN_CAPTURE;
        }

        @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_MEDIA_PROJECTION)
        @Override // Binder call
        public int applyVirtualDisplayFlags(int flags) {
            if (mContext.checkCallingOrSelfPermission(MANAGE_MEDIA_PROJECTION)
                    != PackageManager.PERMISSION_GRANTED) {
                throw new SecurityException("Requires MANAGE_MEDIA_PROJECTION to apply virtual "
                        + "display flags.");
            }
            applyVirtualDisplayFlags_enforcePermission();
            if (mType == MediaProjectionManager.TYPE_SCREEN_CAPTURE) {
                flags &= ~DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY;
                flags |= DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR
@@ -998,33 +977,24 @@ public final class MediaProjectionManagerService extends SystemService
            mCallbackDelegate.remove(callback);
        }

        @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_MEDIA_PROJECTION)
        @Override // Binder call
        public void setLaunchCookie(IBinder launchCookie) {
            if (mContext.checkCallingOrSelfPermission(MANAGE_MEDIA_PROJECTION)
                    != PackageManager.PERMISSION_GRANTED) {
                throw new SecurityException("Requires MANAGE_MEDIA_PROJECTION to set launch "
                        + "cookie.");
            }
            setLaunchCookie_enforcePermission();
            mLaunchCookie = launchCookie;
        }

        @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_MEDIA_PROJECTION)
        @Override // Binder call
        public IBinder getLaunchCookie() {
            if (mContext.checkCallingOrSelfPermission(MANAGE_MEDIA_PROJECTION)
                    != PackageManager.PERMISSION_GRANTED) {
                throw new SecurityException("Requires MANAGE_MEDIA_PROJECTION to get launch "
                        + "cookie.");
            }
            getLaunchCookie_enforcePermission();
            return mLaunchCookie;
        }

        @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_MEDIA_PROJECTION)
        @Override
        public boolean isValid() {
            if (mContext.checkCallingOrSelfPermission(Manifest.permission.MANAGE_MEDIA_PROJECTION)
                    != PackageManager.PERMISSION_GRANTED) {
                throw new SecurityException("Requires MANAGE_MEDIA_PROJECTION to check if this"
                        + "projection is valid.");
            }
            isValid_enforcePermission();
            synchronized (mLock) {
                final long curMs = mClock.uptimeMillis();
                final boolean hasTimedOut = curMs - mCreateTimeMs > mTimeoutMs;
@@ -1051,13 +1021,10 @@ public final class MediaProjectionManagerService extends SystemService
            }
        }

        @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_MEDIA_PROJECTION)
        @Override
        public void notifyVirtualDisplayCreated(int displayId) {
            if (mContext.checkCallingOrSelfPermission(Manifest.permission.MANAGE_MEDIA_PROJECTION)
                    != PackageManager.PERMISSION_GRANTED) {
                throw new SecurityException("Requires MANAGE_MEDIA_PROJECTION to notify virtual "
                        + "display created.");
            }
            notifyVirtualDisplayCreated_enforcePermission();
            synchronized (mLock) {
                mVirtualDisplayId = displayId;