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

Commit d422286d authored by Marvin Ramin's avatar Marvin Ramin Committed by Android Build Coastguard Worker
Browse files

Allow keyguard capture when screenshare protections are disabled

Bug: 348335290
Test: atest MediaProjectionManagerServiceTest
Flag: android.companion.virtualdevice.flags.media_projection_keyguard_restrictions
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:894f27ffef61c65ed8da4843a6517a4a35088a4d)
Merged-In: I57ddb1c3d64c19ba346e44f4e1e4cbb328d3620e
Change-Id: I57ddb1c3d64c19ba346e44f4e1e4cbb328d3620e
parent 95e5bffe
Loading
Loading
Loading
Loading
+11 −0
Original line number Original line Diff line number Diff line
@@ -28,6 +28,7 @@ import static android.media.projection.ReviewGrantedConsentResult.RECORD_CANCEL;
import static android.media.projection.ReviewGrantedConsentResult.RECORD_CONTENT_DISPLAY;
import static android.media.projection.ReviewGrantedConsentResult.RECORD_CONTENT_DISPLAY;
import static android.media.projection.ReviewGrantedConsentResult.RECORD_CONTENT_TASK;
import static android.media.projection.ReviewGrantedConsentResult.RECORD_CONTENT_TASK;
import static android.media.projection.ReviewGrantedConsentResult.UNKNOWN;
import static android.media.projection.ReviewGrantedConsentResult.UNKNOWN;
import static android.provider.Settings.Global.DISABLE_SCREEN_SHARE_PROTECTIONS_FOR_APPS_AND_NOTIFICATIONS;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.INVALID_DISPLAY;
import static android.view.Display.INVALID_DISPLAY;


@@ -73,6 +74,7 @@ import android.os.PermissionEnforcer;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.SystemClock;
import android.os.UserHandle;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.ArrayMap;
import android.util.ArrayMap;
import android.util.Slog;
import android.util.Slog;
import android.view.ContentRecordingSession;
import android.view.ContentRecordingSession;
@@ -195,6 +197,15 @@ public final class MediaProjectionManagerService extends SystemService
            if (mProjectionGrant == null || mProjectionGrant.packageName == null) {
            if (mProjectionGrant == null || mProjectionGrant.packageName == null) {
                return false;
                return false;
            }
            }
            boolean disableScreenShareProtections = Settings.Global.getInt(
                    getContext().getContentResolver(),
                    DISABLE_SCREEN_SHARE_PROTECTIONS_FOR_APPS_AND_NOTIFICATIONS, 0) != 0;
            if (disableScreenShareProtections) {
                Slog.v(TAG,
                        "Allowing keyguard capture as screenshare protections are disabled.");
                return true;
            }

            if (mPackageManager.checkPermission(RECORD_SENSITIVE_CONTENT,
            if (mPackageManager.checkPermission(RECORD_SENSITIVE_CONTENT,
                    mProjectionGrant.packageName)
                    mProjectionGrant.packageName)
                    == PackageManager.PERMISSION_GRANTED) {
                    == PackageManager.PERMISSION_GRANTED) {
+29 −0
Original line number Original line Diff line number Diff line
@@ -25,6 +25,7 @@ import static android.media.projection.ReviewGrantedConsentResult.RECORD_CANCEL;
import static android.media.projection.ReviewGrantedConsentResult.RECORD_CONTENT_DISPLAY;
import static android.media.projection.ReviewGrantedConsentResult.RECORD_CONTENT_DISPLAY;
import static android.media.projection.ReviewGrantedConsentResult.RECORD_CONTENT_TASK;
import static android.media.projection.ReviewGrantedConsentResult.RECORD_CONTENT_TASK;
import static android.media.projection.ReviewGrantedConsentResult.UNKNOWN;
import static android.media.projection.ReviewGrantedConsentResult.UNKNOWN;
import static android.provider.Settings.Global.DISABLE_SCREEN_SHARE_PROTECTIONS_FOR_APPS_AND_NOTIFICATIONS;
import static android.view.ContentRecordingSession.TARGET_UID_FULL_SCREEN;
import static android.view.ContentRecordingSession.TARGET_UID_FULL_SCREEN;
import static android.view.ContentRecordingSession.TARGET_UID_UNKNOWN;
import static android.view.ContentRecordingSession.TARGET_UID_UNKNOWN;
import static android.view.ContentRecordingSession.createDisplaySession;
import static android.view.ContentRecordingSession.createDisplaySession;
@@ -80,6 +81,7 @@ import android.os.test.TestLooper;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.annotations.Presubmit;
import android.platform.test.annotations.Presubmit;
import android.platform.test.flag.junit.SetFlagsRule;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import android.testing.TestableContext;
import android.testing.TestableContext;
import android.view.ContentRecordingSession;
import android.view.ContentRecordingSession;
import android.view.ContentRecordingSession.RecordContent;
import android.view.ContentRecordingSession.RecordContent;
@@ -372,6 +374,33 @@ public class MediaProjectionManagerServiceTest {
        });
        });
    }
    }


    @EnableFlags(android.companion.virtualdevice.flags
            .Flags.FLAG_MEDIA_PROJECTION_KEYGUARD_RESTRICTIONS)
    @Test
    public void testCreateProjection_keyguardLocked_screenshareProtectionsDisabled()
            throws NameNotFoundException {
        MediaProjectionManagerService.MediaProjection projection = startProjectionPreconditions();
        int value = Settings.Global.getInt(mContext.getContentResolver(),
                DISABLE_SCREEN_SHARE_PROTECTIONS_FOR_APPS_AND_NOTIFICATIONS, 0);
        try {
            Settings.Global.putInt(mContext.getContentResolver(),
                    DISABLE_SCREEN_SHARE_PROTECTIONS_FOR_APPS_AND_NOTIFICATIONS, 1);
            doReturn(true).when(mKeyguardManager).isKeyguardLocked();

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

            projection.start(mIMediaProjectionCallback);
            projection.notifyVirtualDisplayCreated(10);

            // The projection was started because it was allowed to capture the keyguard.
            assertThat(mService.getActiveProjectionInfo()).isNotNull();
        } finally {
            Settings.Global.putInt(mContext.getContentResolver(),
                    DISABLE_SCREEN_SHARE_PROTECTIONS_FOR_APPS_AND_NOTIFICATIONS, value);
        }
    }

    @Test
    @Test
    public void testCreateProjection_attemptReuse_noPriorProjectionGrant()
    public void testCreateProjection_attemptReuse_noPriorProjectionGrant()
            throws NameNotFoundException {
            throws NameNotFoundException {