Loading media/tests/projection/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -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", Loading media/tests/projection/src/android/media/projection/FakeIMediaProjection.java +18 −0 Original line number Diff line number Diff line Loading @@ -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; /** Loading @@ -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; Loading Loading @@ -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; } Loading @@ -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(); } } media/tests/projection/src/android/media/projection/MediaProjectionTest.java +6 −2 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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); Loading Loading
media/tests/projection/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -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", Loading
media/tests/projection/src/android/media/projection/FakeIMediaProjection.java +18 −0 Original line number Diff line number Diff line Loading @@ -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; /** Loading @@ -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; Loading Loading @@ -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; } Loading @@ -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(); } }
media/tests/projection/src/android/media/projection/MediaProjectionTest.java +6 −2 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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); Loading