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

Commit 21b5c2f8 authored by Marvin Ramin's avatar Marvin Ramin
Browse files

Don't stop MediaProjection sessions without display

When device lock would otherwise stop MediaProjection.

Bug: 370108833
Test: atest MediaProjectionManagerServiceTest
Flag: android.companion.virtualdevice.flags.media_projection_keyguard_restrictions
Change-Id: Ic5179113180d3bb71d813aeed02ae2a302190965
parent 894f27ff
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -237,7 +237,8 @@ public final class MediaProjectionManagerService extends SystemService
    void onKeyguardLockedStateChanged(boolean isKeyguardLocked) {
        if (!isKeyguardLocked) return;
        synchronized (mLock) {
            if (mProjectionGrant != null && !canCaptureKeyguard()) {
            if (mProjectionGrant != null && !canCaptureKeyguard()
                    && mProjectionGrant.mVirtualDisplayId != INVALID_DISPLAY) {
                Slog.d(TAG, "Content Recording: Stopped MediaProjection"
                        + " due to keyguard lock");
                mProjectionGrant.stop();
+19 −0
Original line number Diff line number Diff line
@@ -401,6 +401,23 @@ public class MediaProjectionManagerServiceTest {
        }
    }

    @EnableFlags(android.companion.virtualdevice.flags
            .Flags.FLAG_MEDIA_PROJECTION_KEYGUARD_RESTRICTIONS)
    @Test
    public void testCreateProjection_keyguardLocked_noDisplayCreated()
            throws NameNotFoundException {
        MediaProjectionManagerService.MediaProjection projection = startProjectionPreconditions();
        doReturn(true).when(mKeyguardManager).isKeyguardLocked();

        doReturn(PackageManager.PERMISSION_DENIED).when(mPackageManager).checkPermission(
                RECORD_SENSITIVE_CONTENT, projection.packageName);

        projection.start(mIMediaProjectionCallback);

        // The projection was started because it was allowed to capture the keyguard.
        assertThat(mService.getActiveProjectionInfo()).isNotNull();
    }

    @Test
    public void testCreateProjection_attemptReuse_noPriorProjectionGrant()
            throws NameNotFoundException {
@@ -514,6 +531,7 @@ public class MediaProjectionManagerServiceTest {
        MediaProjectionManagerService.MediaProjection projection =
                startProjectionPreconditions(service);
        projection.start(mIMediaProjectionCallback);
        projection.notifyVirtualDisplayCreated(10);

        assertThat(service.getActiveProjectionInfo()).isNotNull();

@@ -536,6 +554,7 @@ public class MediaProjectionManagerServiceTest {
        MediaProjectionManagerService.MediaProjection projection =
                startProjectionPreconditions(service);
        projection.start(mIMediaProjectionCallback);
        projection.notifyVirtualDisplayCreated(10);

        assertThat(service.getActiveProjectionInfo()).isNotNull();