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

Commit d6aa6cb0 authored by Adrian Roos's avatar Adrian Roos
Browse files

Remove LockPatternUtils.getCurrentUser()

Bug: 18931518
Change-Id: I177eefe466c12217cf64c85b872f71bc23c7bf05
parent 8150d2a2
Loading
Loading
Loading
Loading
+2 −38
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.internal.widget;

import android.Manifest;
import android.app.ActivityManager;
import android.app.ActivityManagerNative;
import android.app.admin.DevicePolicyManager;
import android.app.trust.TrustManager;
@@ -143,11 +144,6 @@ public class LockPatternUtils {
    private DevicePolicyManager mDevicePolicyManager;
    private ILockSettings mLockSettingsService;

    private final boolean mMultiUserMode;

    // The current user is set by KeyguardViewMediator and shared by all LockPatternUtils.
    private static volatile int sCurrentUserId = UserHandle.USER_NULL;

    public DevicePolicyManager getDevicePolicyManager() {
        if (mDevicePolicyManager == null) {
            mDevicePolicyManager =
@@ -172,12 +168,6 @@ public class LockPatternUtils {
    public LockPatternUtils(Context context) {
        mContext = context;
        mContentResolver = context.getContentResolver();

        // If this is being called by the system or by an application like keyguard that
        // has permision INTERACT_ACROSS_USERS, then LockPatternUtils will operate in multi-user
        // mode where calls are for the current user rather than the user of the calling process.
        mMultiUserMode = context.checkCallingOrSelfPermission(
            Manifest.permission.INTERACT_ACROSS_USERS_FULL) == PackageManager.PERMISSION_GRANTED;
    }

    private ILockSettings getLockSettings() {
@@ -240,32 +230,6 @@ public class LockPatternUtils {
        getTrustManager().reportUnlockAttempt(true /* authenticated */, userId);
    }

    public void setCurrentUser(int userId) {
        sCurrentUserId = userId;
    }

    public int getCurrentUser() {
        if (sCurrentUserId != UserHandle.USER_NULL) {
            // Someone is regularly updating using setCurrentUser() use that value.
            return sCurrentUserId;
        }
        try {
            return ActivityManagerNative.getDefault().getCurrentUser().id;
        } catch (RemoteException re) {
            return UserHandle.USER_OWNER;
        }
    }

//    private int getCurrentOrCallingUserId() {
//        if (mMultiUserMode) {
//            // TODO: This is a little inefficient. See if all users of this are able to
//            // handle USER_CURRENT and pass that instead.
//            return getCurrentUser();
//        } else {
//            return UserHandle.getCallingUserId();
//        }
//    }

    /**
     * Check to see if a pattern matches the saved pattern.
     * If pattern matches, return an opaque attestation that the challenge
@@ -1129,7 +1093,7 @@ public class LockPatternUtils {
    }

    public void setCredentialRequiredToDecrypt(boolean required) {
        if (getCurrentUser() != UserHandle.USER_OWNER) {
        if (ActivityManager.getCurrentUser() != UserHandle.USER_OWNER) {
            Log.w(TAG, "Only device owner may call setCredentialRequiredForDecrypt()");
            return;
        }
+2 −2
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ public class EmergencyButton extends Button {
            KeyguardUpdateMonitor.getInstance(mContext).reportEmergencyCallAction(
                    true /* bypassHandler */);
            getContext().startActivityAsUser(INTENT_EMERGENCY_DIAL,
                    new UserHandle(mLockPatternUtils.getCurrentUser()));
                    new UserHandle(KeyguardUpdateMonitor.getCurrentUser()));
        }
    }

@@ -138,7 +138,7 @@ public class EmergencyButton extends Button {
                    visible = mEnableEmergencyCallWhileSimLocked;
                } else {
                    // Only show if there is a secure screen (pin/pattern/SIM pin/SIM puk);
                    visible = mLockPatternUtils.isSecure(mLockPatternUtils.getCurrentUser());
                    visible = mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser());
                }
            }
        }
+3 −3
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout
        resetPasswordText(false /* animate */);
        // if the user is currently locked out, enforce it.
        long deadline = mLockPatternUtils.getLockoutAttemptDeadline(
                mLockPatternUtils.getCurrentUser());
                KeyguardUpdateMonitor.getCurrentUser());
        if (shouldLockout(deadline)) {
            handleAttemptLockout(deadline);
        } else {
@@ -107,7 +107,7 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout

    protected void verifyPasswordAndUnlock() {
        String entry = getPasswordText();
        if (mLockPatternUtils.checkPassword(entry, mLockPatternUtils.getCurrentUser())) {
        if (mLockPatternUtils.checkPassword(entry, KeyguardUpdateMonitor.getCurrentUser())) {
            mCallback.reportUnlockAttempt(true);
            mCallback.dismiss(true);
        } else {
@@ -118,7 +118,7 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout
                int attempts = KeyguardUpdateMonitor.getInstance(mContext).getFailedUnlockAttempts();
                if (0 == (attempts % LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT)) {
                    long deadline = mLockPatternUtils.setLockoutAttemptDeadline(
                            mLockPatternUtils.getCurrentUser());
                            KeyguardUpdateMonitor.getCurrentUser());
                    handleAttemptLockout(deadline);
                }
            }
+1 −1
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ public class KeyguardHostView extends FrameLayout implements SecurityCallback {

        @Override
        public void onTrustGrantedWithFlags(int flags, int userId) {
            if (userId != mLockPatternUtils.getCurrentUser()) return;
            if (userId != KeyguardUpdateMonitor.getCurrentUser()) return;
            if (!isAttachedToWindow()) return;
            boolean bouncerVisible = isVisibleToUser();
            boolean initiatedByUser =
+4 −4
Original line number Diff line number Diff line
@@ -131,7 +131,7 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit

        // stealth mode will be the same for the life of this screen
        mLockPatternView.setInStealthMode(!mLockPatternUtils.isVisiblePatternEnabled(
                mLockPatternUtils.getCurrentUser()));
                KeyguardUpdateMonitor.getCurrentUser()));

        // vibrate mode will be the same for the life of this screen
        mLockPatternView.setTactileFeedbackEnabled(mLockPatternUtils.isTactileFeedbackEnabled());
@@ -178,7 +178,7 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit

        // if the user is currently locked out, enforce it.
        long deadline = mLockPatternUtils.getLockoutAttemptDeadline(
                mLockPatternUtils.getCurrentUser());
                KeyguardUpdateMonitor.getCurrentUser());
        if (deadline != 0) {
            handleAttemptLockout(deadline);
        } else {
@@ -215,7 +215,7 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit
        }

        public void onPatternDetected(List<LockPatternView.Cell> pattern) {
            if (mLockPatternUtils.checkPattern(pattern, mLockPatternUtils.getCurrentUser())) {
            if (mLockPatternUtils.checkPattern(pattern, KeyguardUpdateMonitor.getCurrentUser())) {
                mCallback.reportUnlockAttempt(true);
                mLockPatternView.setDisplayMode(LockPatternView.DisplayMode.Correct);
                mCallback.dismiss(true);
@@ -233,7 +233,7 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit
                if (registeredAttempt &&
                        0 == (attempts % LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT)) {
                    long deadline = mLockPatternUtils.setLockoutAttemptDeadline(
                            mLockPatternUtils.getCurrentUser());
                            KeyguardUpdateMonitor.getCurrentUser());
                    handleAttemptLockout(deadline);
                } else {
                    mSecurityMessageDisplay.setMessage(R.string.kg_wrong_pattern, true);
Loading