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

Commit 6a1d3eb0 authored by Chris Göllner's avatar Chris Göllner Committed by Android (Google) Code Review
Browse files

Merge "[Media Projection] SystemUI ScreenRecorder - Pass correct UID to service" into main

parents 087713f8 ec92f5e2
Loading
Loading
Loading
Loading
+27 −17
Original line number Diff line number Diff line
@@ -37,31 +37,41 @@ interface IMediaProjectionManager {
    const String EXTRA_PACKAGE_REUSING_GRANTED_CONSENT =
            "extra_media_projection_package_reusing_consent";

    /**
     * Returns whether a combination of process UID and package has the projection permission.
     *
     * @param processUid the process UID as returned by {@link android.os.Process.myUid()}.
     */
    @UnsupportedAppUsage
    boolean hasProjectionPermission(int uid, String packageName);
    boolean hasProjectionPermission(int processUid, String packageName);

    /**
     * Returns a new {@link IMediaProjection} instance associated with the given package.
     *
     * @param processUid the process UID as returned by {@link android.os.Process.myUid()}.
     */
    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    IMediaProjection createProjection(int uid, String packageName, int type,
    IMediaProjection createProjection(int processUid, String packageName, int type,
            boolean permanentGrant);

    /**
     * Returns the current {@link IMediaProjection} instance associated with the given
     * package, or {@code null} if it is not possible to re-use the current projection.
     * package and process UID, or {@code null} if it is not possible to re-use the current
     * projection.
     *
     * <p>Should only be invoked when the user has reviewed consent for a re-used projection token.
     * Requires that there is a prior session waiting for the user to review consent, and the given
     * package details match those on the current projection.
     *
     * @see {@link #isCurrentProjection}
     *
     * @param processUid the process UID as returned by {@link android.os.Process.myUid()}.
     */
    @EnforcePermission("android.Manifest.permission.MANAGE_MEDIA_PROJECTION")
    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    IMediaProjection getProjection(int uid, String packageName);
    IMediaProjection getProjection(int processUid, String packageName);

    /**
     * Returns {@code true} if the given {@link IMediaProjection} corresponds to the current
@@ -162,8 +172,8 @@ interface IMediaProjectionManager {
     *
     * <p>Only used for emitting atoms.
     *
     * @param hostUid               The uid of the process requesting consent to capture, may be an app or
     *                              SystemUI.
     * @param hostProcessUid        The uid of the process requesting consent to capture, may be an
     *                              app or SystemUI.
     * @param sessionCreationSource Only set if the state is MEDIA_PROJECTION_STATE_INITIATED.
     *                              Indicates the entry point for requesting the permission. Must be
     *                              a valid state defined
@@ -172,49 +182,49 @@ interface IMediaProjectionManager {
    @EnforcePermission("android.Manifest.permission.MANAGE_MEDIA_PROJECTION")
    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    oneway void notifyPermissionRequestInitiated(int hostUid, int sessionCreationSource);
    oneway void notifyPermissionRequestInitiated(int hostProcessUid, int sessionCreationSource);

    /**
     * Notifies system server that the permission request was displayed.
     *
     * <p>Only used for emitting atoms.
     *
     * @param hostUid The uid of the process requesting consent to capture, may be an app or
     * @param hostProcessUid The uid of the process requesting consent to capture, may be an app or
     *                       SystemUI.
     */
    @EnforcePermission("android.Manifest.permission.MANAGE_MEDIA_PROJECTION")
    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    oneway void notifyPermissionRequestDisplayed(int hostUid);
    oneway void notifyPermissionRequestDisplayed(int hostProcessUid);

    /**
     * Notifies system server that the permission request was cancelled.
     *
     * <p>Only used for emitting atoms.
     *
     * @param hostUid The uid of the process requesting consent to capture, may be an app or
     * @param hostProcessUid The uid of the process requesting consent to capture, may be an app or
     *                       SystemUI.
     */
    @EnforcePermission("android.Manifest.permission.MANAGE_MEDIA_PROJECTION")
    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    oneway void notifyPermissionRequestCancelled(int hostUid);
    oneway void notifyPermissionRequestCancelled(int hostProcessUid);

    /**
     * Notifies system server that the app selector was displayed.
     *
     * <p>Only used for emitting atoms.
     *
     * @param hostUid The uid of the process requesting consent to capture, may be an app or
     * @param hostProcessUid The uid of the process requesting consent to capture, may be an app or
     *                       SystemUI.
     */
    @EnforcePermission("android.Manifest.permission.MANAGE_MEDIA_PROJECTION")
    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    oneway void notifyAppSelectorDisplayed(int hostUid);
    oneway void notifyAppSelectorDisplayed(int hostProcessUid);

    @EnforcePermission("MANAGE_MEDIA_PROJECTION")
    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    void notifyWindowingModeChanged(int contentToRecord, int targetUid, int windowingMode);
    void notifyWindowingModeChanged(int contentToRecord, int targetProcessUid, int windowingMode);
}
+3 −1
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Process;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.UserHandle;
@@ -143,6 +144,7 @@ public class RecordingService extends Service implements ScreenMediaRecorderList
        channel.enableVibration(true);
        mNotificationManager.createNotificationChannel(channel);

        int currentUid = Process.myUid();
        int currentUserId = mUserContextTracker.getUserContext().getUserId();
        UserHandle currentUser = new UserHandle(currentUserId);
        switch (action) {
@@ -166,7 +168,7 @@ public class RecordingService extends Service implements ScreenMediaRecorderList
                mRecorder = new ScreenMediaRecorder(
                        mUserContextTracker.getUserContext(),
                        mMainHandler,
                        currentUserId,
                        currentUid,
                        mAudioSource,
                        captureTarget,
                        this
+4 −4
Original line number Diff line number Diff line
@@ -83,7 +83,7 @@ public class ScreenMediaRecorder extends MediaProjection.Callback {
    private Surface mInputSurface;
    private VirtualDisplay mVirtualDisplay;
    private MediaRecorder mMediaRecorder;
    private int mUser;
    private int mUid;
    private ScreenRecordingMuxer mMuxer;
    private ScreenInternalAudioRecorder mAudio;
    private ScreenRecordingAudioSource mAudioSource;
@@ -94,12 +94,12 @@ public class ScreenMediaRecorder extends MediaProjection.Callback {
    ScreenMediaRecorderListener mListener;

    public ScreenMediaRecorder(Context context, Handler handler,
            int user, ScreenRecordingAudioSource audioSource,
            int uid, ScreenRecordingAudioSource audioSource,
            MediaProjectionCaptureTarget captureRegion,
            ScreenMediaRecorderListener listener) {
        mContext = context;
        mHandler = handler;
        mUser = user;
        mUid = uid;
        mCaptureRegion = captureRegion;
        mListener = listener;
        mAudioSource = audioSource;
@@ -111,7 +111,7 @@ public class ScreenMediaRecorder extends MediaProjection.Callback {
        IMediaProjectionManager mediaService =
                IMediaProjectionManager.Stub.asInterface(b);
        IMediaProjection proj = null;
        proj = mediaService.createProjection(mUser, mContext.getPackageName(),
        proj = mediaService.createProjection(mUid, mContext.getPackageName(),
                    MediaProjectionManager.TYPE_SCREEN_CAPTURE, false);
        IMediaProjection projection = IMediaProjection.Stub.asInterface(proj.asBinder());
        if (mCaptureRegion != null) {
+17 −16
Original line number Diff line number Diff line
@@ -653,14 +653,14 @@ public final class MediaProjectionManagerService extends SystemService
        }

        @Override // Binder call
        public boolean hasProjectionPermission(int uid, String packageName) {
        public boolean hasProjectionPermission(int processUid, String packageName) {
            final long token = Binder.clearCallingIdentity();
            boolean hasPermission = false;
            try {
                hasPermission |= checkPermission(packageName,
                        android.Manifest.permission.CAPTURE_VIDEO_OUTPUT)
                        || mAppOps.noteOpNoThrow(
                                AppOpsManager.OP_PROJECT_MEDIA, uid, packageName)
                                AppOpsManager.OP_PROJECT_MEDIA, processUid, packageName)
                        == AppOpsManager.MODE_ALLOWED;
            } finally {
                Binder.restoreCallingIdentity(token);
@@ -669,7 +669,7 @@ public final class MediaProjectionManagerService extends SystemService
        }

        @Override // Binder call
        public IMediaProjection createProjection(int uid, String packageName, int type,
        public IMediaProjection createProjection(int processUid, String packageName, int type,
                boolean isPermanentGrant) {
            if (mContext.checkCallingPermission(MANAGE_MEDIA_PROJECTION)
                        != PackageManager.PERMISSION_GRANTED) {
@@ -680,13 +680,13 @@ public final class MediaProjectionManagerService extends SystemService
                throw new IllegalArgumentException("package name must not be empty");
            }
            final UserHandle callingUser = Binder.getCallingUserHandle();
            return createProjectionInternal(uid, packageName, type, isPermanentGrant,
            return createProjectionInternal(processUid, packageName, type, isPermanentGrant,
                    callingUser);
        }

        @Override // Binder call
        @EnforcePermission(MANAGE_MEDIA_PROJECTION)
        public IMediaProjection getProjection(int uid, String packageName) {
        public IMediaProjection getProjection(int processUid, String packageName) {
            getProjection_enforcePermission();
            if (packageName == null || packageName.isEmpty()) {
                throw new IllegalArgumentException("package name must not be empty");
@@ -695,7 +695,7 @@ public final class MediaProjectionManagerService extends SystemService
            MediaProjection projection;
            final long callingToken = Binder.clearCallingIdentity();
            try {
                projection = getProjectionInternal(uid, packageName);
                projection = getProjectionInternal(processUid, packageName);
            } finally {
                Binder.restoreCallingIdentity(callingToken);
            }
@@ -869,12 +869,13 @@ public final class MediaProjectionManagerService extends SystemService

        @Override // Binder call
        @EnforcePermission(MANAGE_MEDIA_PROJECTION)
        public void notifyPermissionRequestInitiated(int hostUid, int sessionCreationSource) {
        public void notifyPermissionRequestInitiated(
                int hostProcessUid, int sessionCreationSource) {
            notifyPermissionRequestInitiated_enforcePermission();
            final long token = Binder.clearCallingIdentity();
            try {
                MediaProjectionManagerService.this.notifyPermissionRequestInitiated(
                        hostUid, sessionCreationSource);
                        hostProcessUid, sessionCreationSource);
            } finally {
                Binder.restoreCallingIdentity(token);
            }
@@ -882,11 +883,11 @@ public final class MediaProjectionManagerService extends SystemService

        @Override // Binder call
        @EnforcePermission(MANAGE_MEDIA_PROJECTION)
        public void notifyPermissionRequestDisplayed(int hostUid) {
        public void notifyPermissionRequestDisplayed(int hostProcessUid) {
            notifyPermissionRequestDisplayed_enforcePermission();
            final long token = Binder.clearCallingIdentity();
            try {
                MediaProjectionManagerService.this.notifyPermissionRequestDisplayed(hostUid);
                MediaProjectionManagerService.this.notifyPermissionRequestDisplayed(hostProcessUid);
            } finally {
                Binder.restoreCallingIdentity(token);
            }
@@ -894,11 +895,11 @@ public final class MediaProjectionManagerService extends SystemService

        @Override // Binder call
        @EnforcePermission(MANAGE_MEDIA_PROJECTION)
        public void notifyPermissionRequestCancelled(int hostUid) {
        public void notifyPermissionRequestCancelled(int hostProcessUid) {
            notifyPermissionRequestCancelled_enforcePermission();
            final long token = Binder.clearCallingIdentity();
            try {
                MediaProjectionManagerService.this.notifyPermissionRequestCancelled(hostUid);
                MediaProjectionManagerService.this.notifyPermissionRequestCancelled(hostProcessUid);
            } finally {
                Binder.restoreCallingIdentity(token);
            }
@@ -906,11 +907,11 @@ public final class MediaProjectionManagerService extends SystemService

        @Override // Binder call
        @EnforcePermission(MANAGE_MEDIA_PROJECTION)
        public void notifyAppSelectorDisplayed(int hostUid) {
        public void notifyAppSelectorDisplayed(int hostProcessUid) {
            notifyAppSelectorDisplayed_enforcePermission();
            final long token = Binder.clearCallingIdentity();
            try {
                MediaProjectionManagerService.this.notifyAppSelectorDisplayed(hostUid);
                MediaProjectionManagerService.this.notifyAppSelectorDisplayed(hostProcessUid);
            } finally {
                Binder.restoreCallingIdentity(token);
            }
@@ -919,12 +920,12 @@ public final class MediaProjectionManagerService extends SystemService
        @Override // Binder call
        @EnforcePermission(MANAGE_MEDIA_PROJECTION)
        public void notifyWindowingModeChanged(
                int contentToRecord, int targetUid, int windowingMode) {
                int contentToRecord, int targetProcessUid, int windowingMode) {
            notifyWindowingModeChanged_enforcePermission();
            final long token = Binder.clearCallingIdentity();
            try {
                MediaProjectionManagerService.this.notifyWindowingModeChanged(
                        contentToRecord, targetUid, windowingMode);
                        contentToRecord, targetProcessUid, windowingMode);
            } finally {
                Binder.restoreCallingIdentity(token);
            }