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

Commit 6f9e9d45 authored by Rhed Jao's avatar Rhed Jao
Browse files

Add package visibility tests for createProjection API

Bug: 243792935
Test: atest AppEnumerationInternalTests
Change-Id: I0d7995d819258345f32cfdd01e373302756ebdb7
parent 4be8a404
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ android_test {
        "Harrier",
    ],
    platform_apis: true,
    certificate: "platform",
    test_suites: ["device-tests"],
    data: [
        ":AppEnumerationCrossUserPackageVisibilityTestApp",
+1 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@

    <!-- It's merged from Harrier library. Remove it since this test should not hold it. -->
    <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" tools:node="remove" />
    <uses-permission android:name="android.permission.MANAGE_MEDIA_PROJECTION" />

    <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
                     android:targetPackage="com.android.server.pm.test.appenumeration"
+30 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.pm.test.appenumeration;

import static android.content.Context.MEDIA_PROJECTION_SERVICE;

import static com.android.compatibility.common.util.ShellUtils.runShellCommand;

import static com.google.common.truth.Truth.assertThat;
@@ -26,7 +28,10 @@ import android.content.Context;
import android.content.IntentSender;
import android.content.pm.IPackageManager;
import android.content.pm.ProviderInfo;
import android.media.projection.IMediaProjectionManager;
import android.media.projection.MediaProjectionManager;
import android.os.Process;
import android.os.ServiceManager;
import android.os.UserHandle;

import androidx.test.platform.app.InstrumentationRegistry;
@@ -160,6 +165,31 @@ public class AppEnumerationInternalTests {
                        null /* onFinished */, null /* handler */));
    }

    @Test
    public void mediaProjectionManager_createProjection_canSeeForceQueryable()
            throws Exception {
        installPackage(SHARED_USER_APK_PATH, true /* forceQueryable */);
        final IMediaProjectionManager mediaProjectionManager =
                IMediaProjectionManager.Stub.asInterface(
                        ServiceManager.getService(MEDIA_PROJECTION_SERVICE));

        assertThat(mediaProjectionManager.createProjection(0 /* uid */, TARGET_SHARED_USER,
                MediaProjectionManager.TYPE_SCREEN_CAPTURE, false /* permanentGrant */))
                .isNotNull();
    }

    @Test
    public void mediaProjectionManager_createProjection_cannotSeeTarget() {
        installPackage(SHARED_USER_APK_PATH, false /* forceQueryable */);
        final IMediaProjectionManager mediaProjectionManager =
                IMediaProjectionManager.Stub.asInterface(
                        ServiceManager.getService(MEDIA_PROJECTION_SERVICE));

        Assert.assertThrows(IllegalArgumentException.class,
                () -> mediaProjectionManager.createProjection(0 /* uid */, TARGET_SHARED_USER,
                        MediaProjectionManager.TYPE_SCREEN_CAPTURE, false /* permanentGrant */));
    }

    private static void installPackage(String apkPath, boolean forceQueryable) {
        final StringBuilder cmd = new StringBuilder("pm install ");
        if (forceQueryable) {