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

Commit 9bc77872 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Treat cross-user MediaProjection as INTERACT_ACROSS_USERS_FULL" into main

parents 7b0323c5 2db9fda5
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -53,8 +53,9 @@ interface IMediaProjectionManager {
     *
     * @param processUid the process UID as returned by {@link android.os.Process.myUid()}.
     */
    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(anyOf = {"
            + "android.Manifest.permission.MANAGE_MEDIA_PROJECTION,"
            + "android.Manifest.permission.INTERACT_ACROSS_USERS_FULL}, conditional = true)")
    IMediaProjection createProjection(int processUid, String packageName, int type,
            boolean permanentGrant, int displayId);

+10 −5
Original line number Diff line number Diff line
@@ -663,13 +663,12 @@ public final class MediaProjectionManagerService extends SystemService
            String packageName,
            int type,
            boolean isPermanentGrant,
            UserHandle callingUser,
            int displayId) {
        MediaProjection projection;
        ApplicationInfo ai;
        try {
            ai = mPackageManager.getApplicationInfoAsUser(packageName, ApplicationInfoFlags.of(0),
                    callingUser);
                    UserHandle.getUserHandleForUid(uid));
        } catch (NameNotFoundException e) {
            throw new IllegalArgumentException("No package matching: " + packageName);
        }
@@ -813,9 +812,15 @@ public final class MediaProjectionManagerService extends SystemService
            if (packageName == null || packageName.isEmpty()) {
                throw new IllegalArgumentException("package name must not be empty");
            }
            final UserHandle callingUser = Binder.getCallingUserHandle();
            // If the package UID and calling UID don't belong to the same user, we need to use the
            // package UID for lookups - but only if the caller has the appropriate permission.
            if (UserHandle.getUserId(processUid) != UserHandle.getCallingUserId()) {
                mContext.enforceCallingOrSelfPermission(
                        android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
                        "createProjection");
            }
            return createProjectionInternal(
                    processUid, packageName, type, isPermanentGrant, callingUser, displayId);
                    processUid, packageName, type, isPermanentGrant, displayId);
        }

        @Override // Binder call
+0 −7
Original line number Diff line number Diff line
@@ -453,7 +453,6 @@ public class MediaProjectionManagerServiceTest {
                        PACKAGE_NAME + "foo",
                        TYPE_MIRRORING,
                        /* isPermanentGrant= */ true,
                        UserHandle.CURRENT,
                        Display.DEFAULT_DISPLAY);

        assertThat(secondProjection).isNotNull();
@@ -1250,7 +1249,6 @@ public class MediaProjectionManagerServiceTest {
                        PACKAGE_NAME,
                        TYPE_SCREEN_CAPTURE,
                        /* isPermanentGrant= */ false,
                        UserHandle.CURRENT,
                        DEFAULT_DISPLAY);

        doReturn(AppOpsManager.MODE_DEFAULT).when(mAppOpsManager).unsafeCheckOpRawNoThrow(
@@ -1276,7 +1274,6 @@ public class MediaProjectionManagerServiceTest {
                        PACKAGE_NAME,
                        TYPE_SCREEN_CAPTURE,
                        /* isPermanentGrant= */ false,
                        UserHandle.CURRENT,
                        DEFAULT_DISPLAY);

        doReturn(AppOpsManager.MODE_DEFAULT).when(mAppOpsManager).unsafeCheckOpRawNoThrow(
@@ -1308,7 +1305,6 @@ public class MediaProjectionManagerServiceTest {
                        packageName,
                        TYPE_SCREEN_CAPTURE,
                        /* isPermanentGrant= */ false,
                        UserHandle.CURRENT,
                        DEFAULT_DISPLAY);
        projection.setRecordingOverlay(true);

@@ -1341,7 +1337,6 @@ public class MediaProjectionManagerServiceTest {
                        PACKAGE_NAME,
                        TYPE_SCREEN_CAPTURE,
                        /* isPermanentGrant= */ false,
                        UserHandle.CURRENT,
                        DEFAULT_DISPLAY);

        doReturn(AppOpsManager.MODE_DEFAULT).when(mAppOpsManager).unsafeCheckOpRawNoThrow(
@@ -1367,7 +1362,6 @@ public class MediaProjectionManagerServiceTest {
                        PACKAGE_NAME,
                        TYPE_SCREEN_CAPTURE,
                        /* isPermanentGrant= */ false,
                        UserHandle.CURRENT,
                        DEFAULT_DISPLAY);

        // Start MediaProjection from a different UID
@@ -1396,7 +1390,6 @@ public class MediaProjectionManagerServiceTest {
                PACKAGE_NAME,
                TYPE_MIRRORING,
                /* isPermanentGrant= */ false,
                UserHandle.CURRENT,
                displayId);
    }

+1 −2
Original line number Diff line number Diff line
@@ -420,7 +420,6 @@ public class MediaProjectionStopControllerTest {
        doReturn(mAppInfo).when(mPackageManager).getApplicationInfoAsUser(Mockito.isNull(),
                any(ApplicationInfoFlags.class), any(UserHandle.class));
        return mService.createProjectionInternal(UID, packageName,
                MediaProjectionManager.TYPE_SCREEN_CAPTURE, false, mContext.getUser(),
                INVALID_DISPLAY);
                MediaProjectionManager.TYPE_SCREEN_CAPTURE, false, INVALID_DISPLAY);
    }
}