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

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

Merge "Fix MediaProjection UID check and tests" into main

parents 77e954ee 91c87efb
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1218,7 +1218,7 @@ public final class MediaProjectionManagerService extends SystemService
                    mCountStarts++;
                    return;
                }
                if (Flags.startUidCheck() && validateCallingPackageName(mContext, packageName)) {
                if (Flags.startUidCheck() && !validateCallingPackageName(mContext, packageName)) {
                    throw new SecurityException(
                            "This MediaProjection session was not granted to this application.");
                }
+5 −0
Original line number Diff line number Diff line
@@ -218,6 +218,11 @@ public class MediaProjectionManagerServiceTest {
        mWaitingDisplaySession.setVirtualDisplayId(5);

        mAppInfo.targetSdkVersion = 32;
        mAppInfo.packageName = PACKAGE_NAME;

        doReturn(mAppInfo).when(mPackageManager).getApplicationInfoAsUser(anyString(),
                any(ApplicationInfoFlags.class), any(UserHandle.class));
        doReturn(UID).when(mPackageManager).getPackageUidAsUser(anyString(), any(int.class));

        mService = new MediaProjectionManagerService(mContext);
    }
+7 −1
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import android.content.pm.PackageManager.ApplicationInfoFlags;
import android.content.pm.PackageManager.NameNotFoundException;
import android.media.projection.MediaProjectionManager;
import android.os.UserHandle;
import android.os.Process;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.annotations.Presubmit;
import android.platform.test.flag.junit.SetFlagsRule;
@@ -88,7 +89,7 @@ import java.util.function.Consumer;
@RunWith(AndroidJUnit4.class)
@SuppressLint({"UseCheckPermission", "VisibleForTests", "MissingPermission"})
public class MediaProjectionStopControllerTest {
    private static final int UID = 10;
    private static final int UID = Process.myUid();
    private static final String PACKAGE_NAME = "test.package";
    private final ApplicationInfo mAppInfo = new ApplicationInfo();
    @Rule
@@ -145,6 +146,11 @@ public class MediaProjectionStopControllerTest {
                mMediaProjectionMetricsLoggerInjector);

        mAppInfo.targetSdkVersion = 35;
        mAppInfo.packageName = PACKAGE_NAME;

        doReturn(mAppInfo).when(mPackageManager).getApplicationInfoAsUser(anyString(),
                any(ApplicationInfoFlags.class), any(UserHandle.class));
        doReturn(UID).when(mPackageManager).getPackageUidAsUser(anyString(), any(int.class));
    }

    private static AppOpsManager mockAppOpsManager() {