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

Commit e9c6faec authored by Pavel Grafov's avatar Pavel Grafov
Browse files

Remove dead code + trivial refactoring

Atomic is unnecessary here, boolean reads and writes are already atomic
and with "volatile" will always use main memory, so all writes will be
immediately visible to all threads. Atomic is also slower.

Bug: 335663055
Flag: EXEMPT removing dead code + trivial refactoring
Test: TreeHugger
Change-Id: I73e2e4674f81fea7bf790b6230c7281b783bb3c0
parent e735e89e
Loading
Loading
Loading
Loading
+5 −30
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ import com.android.internal.annotations.GuardedBy;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * Implementation of {@link DevicePolicyCache}, to which {@link DevicePolicyManagerService} pushes
@@ -47,19 +46,12 @@ public class DevicePolicyCacheImpl extends DevicePolicyCache {
     */
    private final Object mLock = new Object();

    /**
     * Indicates which user is screen capture disallowed on. Can be {@link UserHandle#USER_NULL},
     * {@link UserHandle#USER_ALL} or a concrete user ID.
     */
    @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<>();
    private final Set<Integer> mScreenCaptureDisallowedUsers = new HashSet<>();

    @GuardedBy("mLock")
    private final SparseIntArray mPasswordQuality = new SparseIntArray();
@@ -70,9 +62,8 @@ public class DevicePolicyCacheImpl extends DevicePolicyCache {
    @GuardedBy("mLock")
    private ArrayMap<String, String> mLauncherShortcutOverrides = new ArrayMap<>();


    /** Maps to {@code ActiveAdmin.mAdminCanGrantSensorsPermissions}. */
    private final AtomicBoolean mCanGrantSensorsPermissions = new AtomicBoolean(false);
    private volatile boolean mCanGrantSensorsPermissions = false;

    @GuardedBy("mLock")
    private final SparseIntArray mContentProtectionPolicy = new SparseIntArray();
@@ -87,10 +78,6 @@ public class DevicePolicyCacheImpl extends DevicePolicyCache {

    @Override
    public boolean isScreenCaptureAllowed(int userHandle) {
        return isScreenCaptureAllowedInPolicyEngine(userHandle);
    }

    private boolean isScreenCaptureAllowedInPolicyEngine(int userHandle) {
        // This won't work if resolution mechanism is not strictest applies, but it's ok for now.
        synchronized (mLock) {
            return !mScreenCaptureDisallowedUsers.contains(userHandle)
@@ -98,18 +85,6 @@ public class DevicePolicyCacheImpl extends DevicePolicyCache {
        }
    }

    public int getScreenCaptureDisallowedUser() {
        synchronized (mLock) {
            return mScreenCaptureDisallowedUser;
        }
    }

    public void setScreenCaptureDisallowedUser(int userHandle) {
        synchronized (mLock) {
            mScreenCaptureDisallowedUser = userHandle;
        }
    }

    public void setScreenCaptureDisallowedUser(int userHandle, boolean disallowed) {
        synchronized (mLock) {
            if (disallowed) {
@@ -170,12 +145,12 @@ public class DevicePolicyCacheImpl extends DevicePolicyCache {

    @Override
    public boolean canAdminGrantSensorsPermissions() {
        return mCanGrantSensorsPermissions.get();
        return mCanGrantSensorsPermissions;
    }

    /** Sets admin control over permission grants. */
    public void setAdminCanGrantSensorsPermissions(boolean canGrant) {
        mCanGrantSensorsPermissions.set(canGrant);
        mCanGrantSensorsPermissions = canGrant;
    }

    @Override
@@ -205,7 +180,7 @@ public class DevicePolicyCacheImpl extends DevicePolicyCache {
            pw.println("Password quality: " + mPasswordQuality);
            pw.println("Permission policy: " + mPermissionPolicy);
            pw.println("Content protection policy: " + mContentProtectionPolicy);
            pw.println("Admin can grant sensors permission: " + mCanGrantSensorsPermissions.get());
            pw.println("Admin can grant sensors permission: " + mCanGrantSensorsPermissions);
            pw.print("Shortcuts overrides: ");
            pw.println(mLauncherShortcutOverrides);
            pw.decreaseIndent();