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

Commit cb67c593 authored by Daniel Akinola's avatar Daniel Akinola Committed by Android (Google) Code Review
Browse files

Merge "Add permission annotation to FakeIMediaProjection" into main

parents 8b437376 e62b29a4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ android_test {
        "androidx.test.runner",
        "androidx.test.rules",
        "androidx.test.ext.junit",
        "frameworks-base-testutils",
        "mockito-target-extended-minus-junit4",
        "platform-test-annotations",
        "testng",
+18 −0
Original line number Diff line number Diff line
@@ -16,7 +16,11 @@

package android.media.projection;

import static android.Manifest.permission.MANAGE_MEDIA_PROJECTION;

import android.annotation.EnforcePermission;
import android.os.IBinder;
import android.os.PermissionEnforcer;
import android.os.RemoteException;

/**
@@ -28,6 +32,10 @@ public final class FakeIMediaProjection extends IMediaProjection.Stub {
    IBinder mLaunchCookie = null;
    IMediaProjectionCallback mIMediaProjectionCallback = null;

    FakeIMediaProjection(PermissionEnforcer enforcer) {
        super(enforcer);
    }

    @Override
    public void start(IMediaProjectionCallback callback) throws RemoteException {
        mIMediaProjectionCallback = callback;
@@ -56,7 +64,9 @@ public final class FakeIMediaProjection extends IMediaProjection.Stub {
    }

    @Override
    @EnforcePermission(MANAGE_MEDIA_PROJECTION)
    public int applyVirtualDisplayFlags(int flags) throws RemoteException {
        applyVirtualDisplayFlags_enforcePermission();
        return 0;
    }

@@ -69,22 +79,30 @@ public final class FakeIMediaProjection extends IMediaProjection.Stub {
    }

    @Override
    @EnforcePermission(MANAGE_MEDIA_PROJECTION)
    public IBinder getLaunchCookie() throws RemoteException {
        getLaunchCookie_enforcePermission();
        return mLaunchCookie;
    }

    @Override
    @EnforcePermission(MANAGE_MEDIA_PROJECTION)
    public void setLaunchCookie(IBinder launchCookie) throws RemoteException {
        setLaunchCookie_enforcePermission();
        mLaunchCookie = launchCookie;
    }

    @Override
    @EnforcePermission(MANAGE_MEDIA_PROJECTION)
    public boolean isValid() throws RemoteException {
        isValid_enforcePermission();
        return true;
    }


    @Override
    @EnforcePermission(MANAGE_MEDIA_PROJECTION)
    public void notifyVirtualDisplayCreated(int displayId) throws RemoteException {
        notifyVirtualDisplayCreated_enforcePermission();
    }
}
+6 −2
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

package android.media.projection;


import static android.Manifest.permission.MANAGE_MEDIA_PROJECTION;
import static android.media.projection.MediaProjection.MEDIA_PROJECTION_REQUIRES_CALLBACK;
import static android.view.Display.DEFAULT_DISPLAY;

@@ -42,6 +42,7 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;
import android.os.test.FakePermissionEnforcer;
import android.platform.test.annotations.Presubmit;
import android.testing.TestableContext;
import android.view.Display;
@@ -80,7 +81,7 @@ public class MediaProjectionTest {

    private final Handler mHandler = new Handler(Looper.getMainLooper());
    // Fake the connection to the system server.
    private final FakeIMediaProjection mFakeIMediaProjection = new FakeIMediaProjection();
    private FakeIMediaProjection mFakeIMediaProjection;
    // Callback registered by an app.
    private MediaProjection mMediaProjection;

@@ -112,7 +113,10 @@ public class MediaProjectionTest {
                        .strictness(Strictness.LENIENT)
                        .startMocking();

        FakePermissionEnforcer permissionEnforcer = new FakePermissionEnforcer();
        permissionEnforcer.grant(MANAGE_MEDIA_PROJECTION);
        // Support the MediaProjection instance.
        mFakeIMediaProjection = new FakeIMediaProjection(permissionEnforcer);
        mFakeIMediaProjection.setLaunchCookie(mock(IBinder.class));
        mMediaProjection = new MediaProjection(mTestableContext, mFakeIMediaProjection,
                mDisplayManager);