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

Commit 8ef2cdc1 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Handle screen capture disabled state for multiple users" into tm-dev...

Merge "Handle screen capture disabled state for multiple users" into tm-dev am: 925eb31c am: 51ef433f

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/25262286



Change-Id: I0e9516621b788765005fba57027258bfae28029b
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 3a57ab91 51ef433f
Loading
Loading
Loading
Loading
+23 −3
Original line number Diff line number Diff line
@@ -25,6 +25,9 @@ import android.util.SparseIntArray;

import com.android.internal.annotations.GuardedBy;

import java.util.HashSet;
import java.util.Set;

/**
 * Implementation of {@link DevicePolicyCache}, to which {@link DevicePolicyManagerService} pushes
 * policies.
@@ -45,6 +48,13 @@ public class DevicePolicyCacheImpl extends DevicePolicyCache {
    @GuardedBy("mLock")
    private int mScreenCaptureDisallowedUser = UserHandle.USER_NULL;

    /**
     * Indicates if screen capture is disallowed on a specific user or all users if
     * it contains {@link UserHandle#USER_ALL}.
     */
    @GuardedBy("mLock")
    private Set<Integer> mScreenCaptureDisallowedUsers = new HashSet<>();

    @GuardedBy("mLock")
    private final SparseIntArray mPasswordQuality = new SparseIntArray();

@@ -71,8 +81,8 @@ public class DevicePolicyCacheImpl extends DevicePolicyCache {
    @Override
    public boolean isScreenCaptureAllowed(int userHandle) {
        synchronized (mLock) {
            return mScreenCaptureDisallowedUser != UserHandle.USER_ALL
                    && mScreenCaptureDisallowedUser != userHandle;
            return !mScreenCaptureDisallowedUsers.contains(userHandle)
                    && !mScreenCaptureDisallowedUsers.contains(UserHandle.USER_ALL);
        }
    }

@@ -88,6 +98,16 @@ public class DevicePolicyCacheImpl extends DevicePolicyCache {
        }
    }

    public void setScreenCaptureDisallowedUser(int userHandle, boolean disallowed) {
        synchronized (mLock) {
            if (disallowed) {
                mScreenCaptureDisallowedUsers.add(userHandle);
            } else {
                mScreenCaptureDisallowedUsers.remove(userHandle);
            }
        }
    }

    @Override
    public int getPasswordQuality(@UserIdInt int userHandle) {
        synchronized (mLock) {
@@ -136,7 +156,7 @@ public class DevicePolicyCacheImpl extends DevicePolicyCache {
    public void dump(IndentingPrintWriter pw) {
        pw.println("Device policy cache:");
        pw.increaseIndent();
        pw.println("Screen capture disallowed user: " + mScreenCaptureDisallowedUser);
        pw.println("Screen capture disallowed users: " + mScreenCaptureDisallowedUsers);
        pw.println("Password quality: " + mPasswordQuality.toString());
        pw.println("Permission policy: " + mPermissionPolicy.toString());
        pw.println("Admin can grant sensors permission: "
+9 −19
Original line number Diff line number Diff line
@@ -7712,30 +7712,20 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    // be disabled device-wide.
    private void pushScreenCapturePolicy(int adminUserId) {
        // Update screen capture device-wide if disabled by the DO or COPE PO on the parent profile.
        ActiveAdmin admin =
                getDeviceOwnerOrProfileOwnerOfOrganizationOwnedDeviceParentLocked(
        // Always do this regardless which user this method is called with. Probably a little
        // wasteful but still safe.
        ActiveAdmin admin = getDeviceOwnerOrProfileOwnerOfOrganizationOwnedDeviceParentLocked(
                        UserHandle.USER_SYSTEM);
        if (admin != null && admin.disableScreenCapture) {
            setScreenCaptureDisabled(UserHandle.USER_ALL);
        } else {
            // Otherwise, update screen capture only for the calling user.
        setScreenCaptureDisabled(UserHandle.USER_ALL, admin != null && admin.disableScreenCapture);
        // Update screen capture only for the calling user.
        admin = getProfileOwnerAdminLocked(adminUserId);
            if (admin != null && admin.disableScreenCapture) {
                setScreenCaptureDisabled(adminUserId);
            } else {
                setScreenCaptureDisabled(UserHandle.USER_NULL);
            }
        }
        setScreenCaptureDisabled(adminUserId, admin != null && admin.disableScreenCapture);
    }
    // Set the latest screen capture policy, overriding any existing ones.
    // userHandle can be one of USER_ALL, USER_NULL or a concrete userId.
    private void setScreenCaptureDisabled(int userHandle) {
        int current = mPolicyCache.getScreenCaptureDisallowedUser();
        if (userHandle == current) {
            return;
        }
        mPolicyCache.setScreenCaptureDisallowedUser(userHandle);
    private void setScreenCaptureDisabled(int userHandle, boolean disabled) {
        mPolicyCache.setScreenCaptureDisallowedUser(userHandle, disabled);
        updateScreenCaptureDisabled();
    }
+1 −1
Original line number Diff line number Diff line
@@ -5058,7 +5058,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
        // Refresh strong auth timeout
        verify(getServices().lockSettingsInternal).refreshStrongAuthTimeout(UserHandle.USER_SYSTEM);
        // Refresh screen capture
        verify(getServices().iwindowManager).refreshScreenCaptureDisabled();
        verify(getServices().iwindowManager, times(2)).refreshScreenCaptureDisabled();
        // Unsuspend personal apps
        verify(getServices().packageManagerInternal)
                .unsuspendForSuspendingPackage(PLATFORM_PACKAGE_NAME, UserHandle.USER_SYSTEM);