Skip to content
Snippets Groups Projects
Commit e62b29a4 authored by Thiébaud Weksteen's avatar Thiébaud Weksteen
Browse files

Add permission annotation to FakeIMediaProjection

All the service implementations require the annotations, even for tests.
Add the annotations and use a fake to grant the permission by default.

Bug: 285807496
Test: atest MediaProjectionTests
Change-Id: Icb90d506b1e424a85df14c0474ad6d139a8da45d
parent 2e8974e2
No related branches found
No related tags found
No related merge requests found
......@@ -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",
......
......@@ -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();
}
}
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment