Loading core/java/com/android/internal/widget/LockPatternUtils.java +51 −186 Original line number Diff line number Diff line Loading @@ -17,9 +17,11 @@ 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; import android.bluetooth.BluetoothClass; import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; Loading Loading @@ -142,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 = Loading @@ -171,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() { Loading @@ -188,93 +179,55 @@ public class LockPatternUtils { return mLockSettingsService; } public int getRequestedMinimumPasswordLength() { return getDevicePolicyManager().getPasswordMinimumLength(null, getCurrentOrCallingUserId()); public int getRequestedMinimumPasswordLength(int userId) { return getDevicePolicyManager().getPasswordMinimumLength(null, userId); } /** * Gets the device policy password mode. If the mode is non-specific, returns * MODE_PATTERN which allows the user to choose anything. */ public int getRequestedPasswordQuality() { return getDevicePolicyManager().getPasswordQuality(null, getCurrentOrCallingUserId()); } public int getRequestedPasswordHistoryLength() { return getRequestedPasswordHistoryLength(getCurrentOrCallingUserId()); public int getRequestedPasswordQuality(int userId) { return getDevicePolicyManager().getPasswordQuality(null, userId); } private int getRequestedPasswordHistoryLength(int userId) { return getDevicePolicyManager().getPasswordHistoryLength(null, userId); } public int getRequestedPasswordMinimumLetters() { return getDevicePolicyManager().getPasswordMinimumLetters(null, getCurrentOrCallingUserId()); public int getRequestedPasswordMinimumLetters(int userId) { return getDevicePolicyManager().getPasswordMinimumLetters(null, userId); } public int getRequestedPasswordMinimumUpperCase() { return getDevicePolicyManager().getPasswordMinimumUpperCase(null, getCurrentOrCallingUserId()); public int getRequestedPasswordMinimumUpperCase(int userId) { return getDevicePolicyManager().getPasswordMinimumUpperCase(null, userId); } public int getRequestedPasswordMinimumLowerCase() { return getDevicePolicyManager().getPasswordMinimumLowerCase(null, getCurrentOrCallingUserId()); public int getRequestedPasswordMinimumLowerCase(int userId) { return getDevicePolicyManager().getPasswordMinimumLowerCase(null, userId); } public int getRequestedPasswordMinimumNumeric() { return getDevicePolicyManager().getPasswordMinimumNumeric(null, getCurrentOrCallingUserId()); public int getRequestedPasswordMinimumNumeric(int userId) { return getDevicePolicyManager().getPasswordMinimumNumeric(null, userId); } public int getRequestedPasswordMinimumSymbols() { return getDevicePolicyManager().getPasswordMinimumSymbols(null, getCurrentOrCallingUserId()); public int getRequestedPasswordMinimumSymbols(int userId) { return getDevicePolicyManager().getPasswordMinimumSymbols(null, userId); } public int getRequestedPasswordMinimumNonLetter() { return getDevicePolicyManager().getPasswordMinimumNonLetter(null, getCurrentOrCallingUserId()); public int getRequestedPasswordMinimumNonLetter(int userId) { return getDevicePolicyManager().getPasswordMinimumNonLetter(null, userId); } public void reportFailedPasswordAttempt() { int userId = getCurrentOrCallingUserId(); public void reportFailedPasswordAttempt(int userId) { getDevicePolicyManager().reportFailedPasswordAttempt(userId); getTrustManager().reportUnlockAttempt(false /* authenticated */, userId); getTrustManager().reportRequireCredentialEntry(userId); } public void reportSuccessfulPasswordAttempt() { getDevicePolicyManager().reportSuccessfulPasswordAttempt(getCurrentOrCallingUserId()); getTrustManager().reportUnlockAttempt(true /* authenticated */, getCurrentOrCallingUserId()); } 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(); } public void reportSuccessfulPasswordAttempt(int userId) { getDevicePolicyManager().reportSuccessfulPasswordAttempt(userId); getTrustManager().reportUnlockAttempt(true /* authenticated */, userId); } /** Loading @@ -286,8 +239,7 @@ public class LockPatternUtils { * @param challenge The challenge to verify against the pattern * @return the attestation that the challenge was verified, or null. */ public byte[] verifyPattern(List<LockPatternView.Cell> pattern, long challenge) { final int userId = getCurrentOrCallingUserId(); public byte[] verifyPattern(List<LockPatternView.Cell> pattern, long challenge, int userId) { try { return getLockSettings().verifyPattern(patternToString(pattern), challenge, userId); } catch (RemoteException re) { Loading @@ -301,8 +253,7 @@ public class LockPatternUtils { * @param pattern The pattern to check. * @return Whether the pattern matches the stored one. */ public boolean checkPattern(List<LockPatternView.Cell> pattern) { final int userId = getCurrentOrCallingUserId(); public boolean checkPattern(List<LockPatternView.Cell> pattern, int userId) { try { return getLockSettings().checkPattern(patternToString(pattern), userId); } catch (RemoteException re) { Loading @@ -319,8 +270,7 @@ public class LockPatternUtils { * @param challenge The challenge to verify against the password * @return the attestation that the challenge was verified, or null. */ public byte[] verifyPassword(String password, long challenge) { final int userId = getCurrentOrCallingUserId(); public byte[] verifyPassword(String password, long challenge, int userId) { try { return getLockSettings().verifyPassword(password, challenge, userId); } catch (RemoteException re) { Loading @@ -334,8 +284,7 @@ public class LockPatternUtils { * @param password The password to check. * @return Whether the password matches the stored one. */ public boolean checkPassword(String password) { final int userId = getCurrentOrCallingUserId(); public boolean checkPassword(String password, int userId) { try { return getLockSettings().checkPassword(password, userId); } catch (RemoteException re) { Loading @@ -348,8 +297,7 @@ public class LockPatternUtils { * Note that this also clears vold's copy of the password. * @return Whether the vold password matches or not. */ public boolean checkVoldPassword() { final int userId = getCurrentOrCallingUserId(); public boolean checkVoldPassword(int userId) { try { return getLockSettings().checkVoldPassword(userId); } catch (RemoteException re) { Loading @@ -364,8 +312,7 @@ public class LockPatternUtils { * @param password The password to check. * @return Whether the password matches any in the history. */ public boolean checkPasswordHistory(String password) { int userId = getCurrentOrCallingUserId(); public boolean checkPasswordHistory(String password, int userId) { String passwordHashString = new String( passwordToHash(password, userId), StandardCharsets.UTF_8); String passwordHistory = getString(PASSWORD_HISTORY_KEY, userId); Loading @@ -374,7 +321,7 @@ public class LockPatternUtils { } // Password History may be too long... int passwordHashLength = passwordHashString.length(); int passwordHistoryLength = getRequestedPasswordHistoryLength(); int passwordHistoryLength = getRequestedPasswordHistoryLength(userId); if(passwordHistoryLength == 0) { return false; } Loading Loading @@ -416,16 +363,8 @@ public class LockPatternUtils { * * @return True if the user has ever chosen a pattern. */ public boolean isPatternEverChosen() { return getBoolean(PATTERN_EVER_CHOSEN_KEY, false, getCurrentOrCallingUserId()); } /** * Used by device policy manager to validate the current password * information it has. */ public int getActivePasswordQuality() { return getActivePasswordQuality(getCurrentOrCallingUserId()); public boolean isPatternEverChosen(int userId) { return getBoolean(PATTERN_EVER_CHOSEN_KEY, false, userId); } /** Loading @@ -448,10 +387,6 @@ public class LockPatternUtils { return DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; } public void clearLock() { clearLock(getCurrentOrCallingUserId()); } /** * Clear any lock pattern or password. */ Loading @@ -478,16 +413,6 @@ public class LockPatternUtils { onAfterChangingPassword(userHandle); } /** * Disable showing lock screen at all when the DevicePolicyManager allows it. * This is only meaningful if pattern, pin or password are not set. * * @param disable Disables lock screen when true */ public void setLockScreenDisabled(boolean disable) { setLockScreenDisabled(disable, getCurrentOrCallingUserId()); } /** * Disable showing lock screen at all for a given user. * This is only meaningful if pattern, pin or password are not set. Loading @@ -505,21 +430,16 @@ public class LockPatternUtils { * * @return true if lock screen is disabled */ public boolean isLockScreenDisabled() { return !isSecure() && getBoolean(DISABLE_LOCKSCREEN_KEY, false, getCurrentOrCallingUserId()); public boolean isLockScreenDisabled(int userId) { return !isSecure(userId) && getBoolean(DISABLE_LOCKSCREEN_KEY, false, userId); } /** * Save a lock pattern. * @param pattern The new pattern to save. * @param savedPattern The previously saved pattern, or null if none * @param userId the user whose pattern is to be saved. */ public void saveLockPattern(List<LockPatternView.Cell> pattern, String savedPattern) { this.saveLockPattern(pattern, savedPattern, getCurrentOrCallingUserId()); } public void saveLockPattern(List<LockPatternView.Cell> pattern, int userId) { this.saveLockPattern(pattern, null, userId); } Loading Loading @@ -588,8 +508,7 @@ public class LockPatternUtils { updateCryptoUserInfo(userId); } public void setOwnerInfoEnabled(boolean enabled) { int userId = getCurrentOrCallingUserId(); public void setOwnerInfoEnabled(boolean enabled, int userId) { setBoolean(LOCK_SCREEN_OWNER_INFO_ENABLED, enabled, userId); updateCryptoUserInfo(userId); } Loading @@ -598,11 +517,7 @@ public class LockPatternUtils { return getString(LOCK_SCREEN_OWNER_INFO, userId); } public boolean isOwnerInfoEnabled() { return isOwnerInfoEnabled(getCurrentOrCallingUserId()); } private boolean isOwnerInfoEnabled(int userId) { public boolean isOwnerInfoEnabled(int userId) { return getBoolean(LOCK_SCREEN_OWNER_INFO_ENABLED, false, userId); } Loading Loading @@ -724,21 +639,10 @@ public class LockPatternUtils { /** * Save a lock password. Does not ensure that the password is as good * as the requested mode, but will adjust the mode to be as good as the * pattern. * password. * @param password The password to save * @param savedPassword The previously saved lock password, or null if none * @param quality {@see DevicePolicyManager#getPasswordQuality(android.content.ComponentName)} */ public void saveLockPassword(String password, String savedPassword, int quality) { saveLockPassword(password, savedPassword, quality, getCurrentOrCallingUserId()); } /** * Save a lock password. Does not ensure that the password is as good * as the requested mode, but will adjust the mode to be as good as the * pattern. * @param password The password to save * @param quality {@see DevicePolicyManager#getPasswordQuality(android.content.ComponentName)} * @param userHandle The userId of the user to change the password for */ public void saveLockPassword(String password, String savedPassword, int quality, Loading Loading @@ -864,16 +768,6 @@ public class LockPatternUtils { updateEncryptionPassword(StorageManager.CRYPT_TYPE_DEFAULT, null); } /** * Retrieves the quality mode we're in. * {@see DevicePolicyManager#getPasswordQuality(android.content.ComponentName)} * * @return stored password quality */ public int getKeyguardStoredPasswordQuality() { return getKeyguardStoredPasswordQuality(getCurrentOrCallingUserId()); } /** * Retrieves the quality mode for {@param userHandle}. * {@see DevicePolicyManager#getPasswordQuality(android.content.ComponentName)} Loading Loading @@ -996,13 +890,6 @@ public class LockPatternUtils { } } /** * @return Whether the lock screen is secured. */ public boolean isSecure() { return isSecure(getCurrentOrCallingUserId()); } /** * @param userId the user for which to report the value * @return Whether the lock screen is secured. Loading @@ -1012,13 +899,6 @@ public class LockPatternUtils { return isLockPatternEnabled(mode, userId) || isLockPasswordEnabled(mode, userId); } /** * @return Whether the lock password is enabled */ public boolean isLockPasswordEnabled() { return isLockPasswordEnabled(getCurrentOrCallingUserId()); } public boolean isLockPasswordEnabled(int userId) { return isLockPasswordEnabled(getKeyguardStoredPasswordQuality(userId), userId); } Loading @@ -1035,10 +915,6 @@ public class LockPatternUtils { /** * @return Whether the lock pattern is enabled */ public boolean isLockPatternEnabled() { return isLockPatternEnabled(getCurrentOrCallingUserId()); } public boolean isLockPatternEnabled(int userId) { return isLockPatternEnabled(getKeyguardStoredPasswordQuality(userId), userId); } Loading @@ -1051,16 +927,14 @@ public class LockPatternUtils { /** * @return Whether the visible pattern is enabled. */ public boolean isVisiblePatternEnabled() { return getBoolean(Settings.Secure.LOCK_PATTERN_VISIBLE, false, getCurrentOrCallingUserId()); public boolean isVisiblePatternEnabled(int userId) { return getBoolean(Settings.Secure.LOCK_PATTERN_VISIBLE, false, userId); } /** * Set whether the visible pattern is enabled. */ public void setVisiblePatternEnabled(boolean enabled) { int userId = getCurrentOrCallingUserId(); public void setVisiblePatternEnabled(boolean enabled, int userId) { setBoolean(Settings.Secure.LOCK_PATTERN_VISIBLE, enabled, userId); // Update for crypto if owner Loading Loading @@ -1095,9 +969,9 @@ public class LockPatternUtils { * pattern until the deadline has passed. * @return the chosen deadline. */ public long setLockoutAttemptDeadline() { public long setLockoutAttemptDeadline(int userId) { final long deadline = SystemClock.elapsedRealtime() + FAILED_ATTEMPT_TIMEOUT_MS; setLong(LOCKOUT_ATTEMPT_DEADLINE, deadline, getCurrentOrCallingUserId()); setLong(LOCKOUT_ATTEMPT_DEADLINE, deadline, userId); return deadline; } Loading @@ -1106,8 +980,8 @@ public class LockPatternUtils { * attempt to enter his/her lock pattern, or 0 if the user is welcome to * enter a pattern. */ public long getLockoutAttemptDeadline() { final long deadline = getLong(LOCKOUT_ATTEMPT_DEADLINE, 0L, getCurrentOrCallingUserId()); public long getLockoutAttemptDeadline(int userId) { final long deadline = getLong(LOCKOUT_ATTEMPT_DEADLINE, 0L, userId); final long now = SystemClock.elapsedRealtime(); if (deadline < now || deadline > (now + FAILED_ATTEMPT_TIMEOUT_MS)) { return 0L; Loading Loading @@ -1166,21 +1040,12 @@ public class LockPatternUtils { } } public void setPowerButtonInstantlyLocks(boolean enabled) { setBoolean(LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS, enabled, getCurrentOrCallingUserId()); } public boolean getPowerButtonInstantlyLocks() { return getBoolean(LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS, true, getCurrentOrCallingUserId()); } public void setEnabledTrustAgents(Collection<ComponentName> activeTrustAgents) { setEnabledTrustAgents(activeTrustAgents, getCurrentOrCallingUserId()); public void setPowerButtonInstantlyLocks(boolean enabled, int userId) { setBoolean(LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS, enabled, userId); } public List<ComponentName> getEnabledTrustAgents() { return getEnabledTrustAgents(getCurrentOrCallingUserId()); public boolean getPowerButtonInstantlyLocks(int userId) { return getBoolean(LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS, true, userId); } public void setEnabledTrustAgents(Collection<ComponentName> activeTrustAgents, int userId) { Loading @@ -1192,7 +1057,7 @@ public class LockPatternUtils { sb.append(cn.flattenToShortString()); } setString(ENABLED_TRUST_AGENTS, sb.toString(), userId); getTrustManager().reportEnabledTrustAgentsChanged(getCurrentOrCallingUserId()); getTrustManager().reportEnabledTrustAgentsChanged(userId); } public List<ComponentName> getEnabledTrustAgents(int userId) { Loading Loading @@ -1228,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; } Loading packages/Keyguard/src/com/android/keyguard/EmergencyButton.java +2 −2 Original line number Diff line number Diff line Loading @@ -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())); } } Loading @@ -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(); visible = mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser()); } } } Loading packages/Keyguard/src/com/android/keyguard/KeyguardAbsKeyInputView.java +5 −3 Original line number Diff line number Diff line Loading @@ -63,7 +63,8 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout // start fresh resetPasswordText(false /* animate */); // if the user is currently locked out, enforce it. long deadline = mLockPatternUtils.getLockoutAttemptDeadline(); long deadline = mLockPatternUtils.getLockoutAttemptDeadline( KeyguardUpdateMonitor.getCurrentUser()); if (shouldLockout(deadline)) { handleAttemptLockout(deadline); } else { Loading Loading @@ -106,7 +107,7 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout protected void verifyPasswordAndUnlock() { String entry = getPasswordText(); if (mLockPatternUtils.checkPassword(entry)) { if (mLockPatternUtils.checkPassword(entry, KeyguardUpdateMonitor.getCurrentUser())) { mCallback.reportUnlockAttempt(true); mCallback.dismiss(true); } else { Loading @@ -116,7 +117,8 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout mCallback.reportUnlockAttempt(false); int attempts = KeyguardUpdateMonitor.getInstance(mContext).getFailedUnlockAttempts(); if (0 == (attempts % LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT)) { long deadline = mLockPatternUtils.setLockoutAttemptDeadline(); long deadline = mLockPatternUtils.setLockoutAttemptDeadline( KeyguardUpdateMonitor.getCurrentUser()); handleAttemptLockout(deadline); } } Loading packages/Keyguard/src/com/android/keyguard/KeyguardHostView.java +1 −1 Original line number Diff line number Diff line Loading @@ -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 = Loading packages/Keyguard/src/com/android/keyguard/KeyguardPatternView.java +7 −4 Original line number Diff line number Diff line Loading @@ -130,7 +130,8 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit mLockPatternView.setOnPatternListener(new UnlockPatternListener()); // stealth mode will be the same for the life of this screen mLockPatternView.setInStealthMode(!mLockPatternUtils.isVisiblePatternEnabled()); mLockPatternView.setInStealthMode(!mLockPatternUtils.isVisiblePatternEnabled( KeyguardUpdateMonitor.getCurrentUser())); // vibrate mode will be the same for the life of this screen mLockPatternView.setTactileFeedbackEnabled(mLockPatternUtils.isTactileFeedbackEnabled()); Loading Loading @@ -176,7 +177,8 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit mLockPatternView.clearPattern(); // if the user is currently locked out, enforce it. long deadline = mLockPatternUtils.getLockoutAttemptDeadline(); long deadline = mLockPatternUtils.getLockoutAttemptDeadline( KeyguardUpdateMonitor.getCurrentUser()); if (deadline != 0) { handleAttemptLockout(deadline); } else { Loading Loading @@ -213,7 +215,7 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit } public void onPatternDetected(List<LockPatternView.Cell> pattern) { if (mLockPatternUtils.checkPattern(pattern)) { if (mLockPatternUtils.checkPattern(pattern, KeyguardUpdateMonitor.getCurrentUser())) { mCallback.reportUnlockAttempt(true); mLockPatternView.setDisplayMode(LockPatternView.DisplayMode.Correct); mCallback.dismiss(true); Loading @@ -230,7 +232,8 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit int attempts = mKeyguardUpdateMonitor.getFailedUnlockAttempts(); if (registeredAttempt && 0 == (attempts % LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT)) { long deadline = mLockPatternUtils.setLockoutAttemptDeadline(); long deadline = mLockPatternUtils.setLockoutAttemptDeadline( KeyguardUpdateMonitor.getCurrentUser()); handleAttemptLockout(deadline); } else { mSecurityMessageDisplay.setMessage(R.string.kg_wrong_pattern, true); Loading Loading
core/java/com/android/internal/widget/LockPatternUtils.java +51 −186 Original line number Diff line number Diff line Loading @@ -17,9 +17,11 @@ 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; import android.bluetooth.BluetoothClass; import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; Loading Loading @@ -142,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 = Loading @@ -171,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() { Loading @@ -188,93 +179,55 @@ public class LockPatternUtils { return mLockSettingsService; } public int getRequestedMinimumPasswordLength() { return getDevicePolicyManager().getPasswordMinimumLength(null, getCurrentOrCallingUserId()); public int getRequestedMinimumPasswordLength(int userId) { return getDevicePolicyManager().getPasswordMinimumLength(null, userId); } /** * Gets the device policy password mode. If the mode is non-specific, returns * MODE_PATTERN which allows the user to choose anything. */ public int getRequestedPasswordQuality() { return getDevicePolicyManager().getPasswordQuality(null, getCurrentOrCallingUserId()); } public int getRequestedPasswordHistoryLength() { return getRequestedPasswordHistoryLength(getCurrentOrCallingUserId()); public int getRequestedPasswordQuality(int userId) { return getDevicePolicyManager().getPasswordQuality(null, userId); } private int getRequestedPasswordHistoryLength(int userId) { return getDevicePolicyManager().getPasswordHistoryLength(null, userId); } public int getRequestedPasswordMinimumLetters() { return getDevicePolicyManager().getPasswordMinimumLetters(null, getCurrentOrCallingUserId()); public int getRequestedPasswordMinimumLetters(int userId) { return getDevicePolicyManager().getPasswordMinimumLetters(null, userId); } public int getRequestedPasswordMinimumUpperCase() { return getDevicePolicyManager().getPasswordMinimumUpperCase(null, getCurrentOrCallingUserId()); public int getRequestedPasswordMinimumUpperCase(int userId) { return getDevicePolicyManager().getPasswordMinimumUpperCase(null, userId); } public int getRequestedPasswordMinimumLowerCase() { return getDevicePolicyManager().getPasswordMinimumLowerCase(null, getCurrentOrCallingUserId()); public int getRequestedPasswordMinimumLowerCase(int userId) { return getDevicePolicyManager().getPasswordMinimumLowerCase(null, userId); } public int getRequestedPasswordMinimumNumeric() { return getDevicePolicyManager().getPasswordMinimumNumeric(null, getCurrentOrCallingUserId()); public int getRequestedPasswordMinimumNumeric(int userId) { return getDevicePolicyManager().getPasswordMinimumNumeric(null, userId); } public int getRequestedPasswordMinimumSymbols() { return getDevicePolicyManager().getPasswordMinimumSymbols(null, getCurrentOrCallingUserId()); public int getRequestedPasswordMinimumSymbols(int userId) { return getDevicePolicyManager().getPasswordMinimumSymbols(null, userId); } public int getRequestedPasswordMinimumNonLetter() { return getDevicePolicyManager().getPasswordMinimumNonLetter(null, getCurrentOrCallingUserId()); public int getRequestedPasswordMinimumNonLetter(int userId) { return getDevicePolicyManager().getPasswordMinimumNonLetter(null, userId); } public void reportFailedPasswordAttempt() { int userId = getCurrentOrCallingUserId(); public void reportFailedPasswordAttempt(int userId) { getDevicePolicyManager().reportFailedPasswordAttempt(userId); getTrustManager().reportUnlockAttempt(false /* authenticated */, userId); getTrustManager().reportRequireCredentialEntry(userId); } public void reportSuccessfulPasswordAttempt() { getDevicePolicyManager().reportSuccessfulPasswordAttempt(getCurrentOrCallingUserId()); getTrustManager().reportUnlockAttempt(true /* authenticated */, getCurrentOrCallingUserId()); } 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(); } public void reportSuccessfulPasswordAttempt(int userId) { getDevicePolicyManager().reportSuccessfulPasswordAttempt(userId); getTrustManager().reportUnlockAttempt(true /* authenticated */, userId); } /** Loading @@ -286,8 +239,7 @@ public class LockPatternUtils { * @param challenge The challenge to verify against the pattern * @return the attestation that the challenge was verified, or null. */ public byte[] verifyPattern(List<LockPatternView.Cell> pattern, long challenge) { final int userId = getCurrentOrCallingUserId(); public byte[] verifyPattern(List<LockPatternView.Cell> pattern, long challenge, int userId) { try { return getLockSettings().verifyPattern(patternToString(pattern), challenge, userId); } catch (RemoteException re) { Loading @@ -301,8 +253,7 @@ public class LockPatternUtils { * @param pattern The pattern to check. * @return Whether the pattern matches the stored one. */ public boolean checkPattern(List<LockPatternView.Cell> pattern) { final int userId = getCurrentOrCallingUserId(); public boolean checkPattern(List<LockPatternView.Cell> pattern, int userId) { try { return getLockSettings().checkPattern(patternToString(pattern), userId); } catch (RemoteException re) { Loading @@ -319,8 +270,7 @@ public class LockPatternUtils { * @param challenge The challenge to verify against the password * @return the attestation that the challenge was verified, or null. */ public byte[] verifyPassword(String password, long challenge) { final int userId = getCurrentOrCallingUserId(); public byte[] verifyPassword(String password, long challenge, int userId) { try { return getLockSettings().verifyPassword(password, challenge, userId); } catch (RemoteException re) { Loading @@ -334,8 +284,7 @@ public class LockPatternUtils { * @param password The password to check. * @return Whether the password matches the stored one. */ public boolean checkPassword(String password) { final int userId = getCurrentOrCallingUserId(); public boolean checkPassword(String password, int userId) { try { return getLockSettings().checkPassword(password, userId); } catch (RemoteException re) { Loading @@ -348,8 +297,7 @@ public class LockPatternUtils { * Note that this also clears vold's copy of the password. * @return Whether the vold password matches or not. */ public boolean checkVoldPassword() { final int userId = getCurrentOrCallingUserId(); public boolean checkVoldPassword(int userId) { try { return getLockSettings().checkVoldPassword(userId); } catch (RemoteException re) { Loading @@ -364,8 +312,7 @@ public class LockPatternUtils { * @param password The password to check. * @return Whether the password matches any in the history. */ public boolean checkPasswordHistory(String password) { int userId = getCurrentOrCallingUserId(); public boolean checkPasswordHistory(String password, int userId) { String passwordHashString = new String( passwordToHash(password, userId), StandardCharsets.UTF_8); String passwordHistory = getString(PASSWORD_HISTORY_KEY, userId); Loading @@ -374,7 +321,7 @@ public class LockPatternUtils { } // Password History may be too long... int passwordHashLength = passwordHashString.length(); int passwordHistoryLength = getRequestedPasswordHistoryLength(); int passwordHistoryLength = getRequestedPasswordHistoryLength(userId); if(passwordHistoryLength == 0) { return false; } Loading Loading @@ -416,16 +363,8 @@ public class LockPatternUtils { * * @return True if the user has ever chosen a pattern. */ public boolean isPatternEverChosen() { return getBoolean(PATTERN_EVER_CHOSEN_KEY, false, getCurrentOrCallingUserId()); } /** * Used by device policy manager to validate the current password * information it has. */ public int getActivePasswordQuality() { return getActivePasswordQuality(getCurrentOrCallingUserId()); public boolean isPatternEverChosen(int userId) { return getBoolean(PATTERN_EVER_CHOSEN_KEY, false, userId); } /** Loading @@ -448,10 +387,6 @@ public class LockPatternUtils { return DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; } public void clearLock() { clearLock(getCurrentOrCallingUserId()); } /** * Clear any lock pattern or password. */ Loading @@ -478,16 +413,6 @@ public class LockPatternUtils { onAfterChangingPassword(userHandle); } /** * Disable showing lock screen at all when the DevicePolicyManager allows it. * This is only meaningful if pattern, pin or password are not set. * * @param disable Disables lock screen when true */ public void setLockScreenDisabled(boolean disable) { setLockScreenDisabled(disable, getCurrentOrCallingUserId()); } /** * Disable showing lock screen at all for a given user. * This is only meaningful if pattern, pin or password are not set. Loading @@ -505,21 +430,16 @@ public class LockPatternUtils { * * @return true if lock screen is disabled */ public boolean isLockScreenDisabled() { return !isSecure() && getBoolean(DISABLE_LOCKSCREEN_KEY, false, getCurrentOrCallingUserId()); public boolean isLockScreenDisabled(int userId) { return !isSecure(userId) && getBoolean(DISABLE_LOCKSCREEN_KEY, false, userId); } /** * Save a lock pattern. * @param pattern The new pattern to save. * @param savedPattern The previously saved pattern, or null if none * @param userId the user whose pattern is to be saved. */ public void saveLockPattern(List<LockPatternView.Cell> pattern, String savedPattern) { this.saveLockPattern(pattern, savedPattern, getCurrentOrCallingUserId()); } public void saveLockPattern(List<LockPatternView.Cell> pattern, int userId) { this.saveLockPattern(pattern, null, userId); } Loading Loading @@ -588,8 +508,7 @@ public class LockPatternUtils { updateCryptoUserInfo(userId); } public void setOwnerInfoEnabled(boolean enabled) { int userId = getCurrentOrCallingUserId(); public void setOwnerInfoEnabled(boolean enabled, int userId) { setBoolean(LOCK_SCREEN_OWNER_INFO_ENABLED, enabled, userId); updateCryptoUserInfo(userId); } Loading @@ -598,11 +517,7 @@ public class LockPatternUtils { return getString(LOCK_SCREEN_OWNER_INFO, userId); } public boolean isOwnerInfoEnabled() { return isOwnerInfoEnabled(getCurrentOrCallingUserId()); } private boolean isOwnerInfoEnabled(int userId) { public boolean isOwnerInfoEnabled(int userId) { return getBoolean(LOCK_SCREEN_OWNER_INFO_ENABLED, false, userId); } Loading Loading @@ -724,21 +639,10 @@ public class LockPatternUtils { /** * Save a lock password. Does not ensure that the password is as good * as the requested mode, but will adjust the mode to be as good as the * pattern. * password. * @param password The password to save * @param savedPassword The previously saved lock password, or null if none * @param quality {@see DevicePolicyManager#getPasswordQuality(android.content.ComponentName)} */ public void saveLockPassword(String password, String savedPassword, int quality) { saveLockPassword(password, savedPassword, quality, getCurrentOrCallingUserId()); } /** * Save a lock password. Does not ensure that the password is as good * as the requested mode, but will adjust the mode to be as good as the * pattern. * @param password The password to save * @param quality {@see DevicePolicyManager#getPasswordQuality(android.content.ComponentName)} * @param userHandle The userId of the user to change the password for */ public void saveLockPassword(String password, String savedPassword, int quality, Loading Loading @@ -864,16 +768,6 @@ public class LockPatternUtils { updateEncryptionPassword(StorageManager.CRYPT_TYPE_DEFAULT, null); } /** * Retrieves the quality mode we're in. * {@see DevicePolicyManager#getPasswordQuality(android.content.ComponentName)} * * @return stored password quality */ public int getKeyguardStoredPasswordQuality() { return getKeyguardStoredPasswordQuality(getCurrentOrCallingUserId()); } /** * Retrieves the quality mode for {@param userHandle}. * {@see DevicePolicyManager#getPasswordQuality(android.content.ComponentName)} Loading Loading @@ -996,13 +890,6 @@ public class LockPatternUtils { } } /** * @return Whether the lock screen is secured. */ public boolean isSecure() { return isSecure(getCurrentOrCallingUserId()); } /** * @param userId the user for which to report the value * @return Whether the lock screen is secured. Loading @@ -1012,13 +899,6 @@ public class LockPatternUtils { return isLockPatternEnabled(mode, userId) || isLockPasswordEnabled(mode, userId); } /** * @return Whether the lock password is enabled */ public boolean isLockPasswordEnabled() { return isLockPasswordEnabled(getCurrentOrCallingUserId()); } public boolean isLockPasswordEnabled(int userId) { return isLockPasswordEnabled(getKeyguardStoredPasswordQuality(userId), userId); } Loading @@ -1035,10 +915,6 @@ public class LockPatternUtils { /** * @return Whether the lock pattern is enabled */ public boolean isLockPatternEnabled() { return isLockPatternEnabled(getCurrentOrCallingUserId()); } public boolean isLockPatternEnabled(int userId) { return isLockPatternEnabled(getKeyguardStoredPasswordQuality(userId), userId); } Loading @@ -1051,16 +927,14 @@ public class LockPatternUtils { /** * @return Whether the visible pattern is enabled. */ public boolean isVisiblePatternEnabled() { return getBoolean(Settings.Secure.LOCK_PATTERN_VISIBLE, false, getCurrentOrCallingUserId()); public boolean isVisiblePatternEnabled(int userId) { return getBoolean(Settings.Secure.LOCK_PATTERN_VISIBLE, false, userId); } /** * Set whether the visible pattern is enabled. */ public void setVisiblePatternEnabled(boolean enabled) { int userId = getCurrentOrCallingUserId(); public void setVisiblePatternEnabled(boolean enabled, int userId) { setBoolean(Settings.Secure.LOCK_PATTERN_VISIBLE, enabled, userId); // Update for crypto if owner Loading Loading @@ -1095,9 +969,9 @@ public class LockPatternUtils { * pattern until the deadline has passed. * @return the chosen deadline. */ public long setLockoutAttemptDeadline() { public long setLockoutAttemptDeadline(int userId) { final long deadline = SystemClock.elapsedRealtime() + FAILED_ATTEMPT_TIMEOUT_MS; setLong(LOCKOUT_ATTEMPT_DEADLINE, deadline, getCurrentOrCallingUserId()); setLong(LOCKOUT_ATTEMPT_DEADLINE, deadline, userId); return deadline; } Loading @@ -1106,8 +980,8 @@ public class LockPatternUtils { * attempt to enter his/her lock pattern, or 0 if the user is welcome to * enter a pattern. */ public long getLockoutAttemptDeadline() { final long deadline = getLong(LOCKOUT_ATTEMPT_DEADLINE, 0L, getCurrentOrCallingUserId()); public long getLockoutAttemptDeadline(int userId) { final long deadline = getLong(LOCKOUT_ATTEMPT_DEADLINE, 0L, userId); final long now = SystemClock.elapsedRealtime(); if (deadline < now || deadline > (now + FAILED_ATTEMPT_TIMEOUT_MS)) { return 0L; Loading Loading @@ -1166,21 +1040,12 @@ public class LockPatternUtils { } } public void setPowerButtonInstantlyLocks(boolean enabled) { setBoolean(LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS, enabled, getCurrentOrCallingUserId()); } public boolean getPowerButtonInstantlyLocks() { return getBoolean(LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS, true, getCurrentOrCallingUserId()); } public void setEnabledTrustAgents(Collection<ComponentName> activeTrustAgents) { setEnabledTrustAgents(activeTrustAgents, getCurrentOrCallingUserId()); public void setPowerButtonInstantlyLocks(boolean enabled, int userId) { setBoolean(LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS, enabled, userId); } public List<ComponentName> getEnabledTrustAgents() { return getEnabledTrustAgents(getCurrentOrCallingUserId()); public boolean getPowerButtonInstantlyLocks(int userId) { return getBoolean(LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS, true, userId); } public void setEnabledTrustAgents(Collection<ComponentName> activeTrustAgents, int userId) { Loading @@ -1192,7 +1057,7 @@ public class LockPatternUtils { sb.append(cn.flattenToShortString()); } setString(ENABLED_TRUST_AGENTS, sb.toString(), userId); getTrustManager().reportEnabledTrustAgentsChanged(getCurrentOrCallingUserId()); getTrustManager().reportEnabledTrustAgentsChanged(userId); } public List<ComponentName> getEnabledTrustAgents(int userId) { Loading Loading @@ -1228,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; } Loading
packages/Keyguard/src/com/android/keyguard/EmergencyButton.java +2 −2 Original line number Diff line number Diff line Loading @@ -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())); } } Loading @@ -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(); visible = mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser()); } } } Loading
packages/Keyguard/src/com/android/keyguard/KeyguardAbsKeyInputView.java +5 −3 Original line number Diff line number Diff line Loading @@ -63,7 +63,8 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout // start fresh resetPasswordText(false /* animate */); // if the user is currently locked out, enforce it. long deadline = mLockPatternUtils.getLockoutAttemptDeadline(); long deadline = mLockPatternUtils.getLockoutAttemptDeadline( KeyguardUpdateMonitor.getCurrentUser()); if (shouldLockout(deadline)) { handleAttemptLockout(deadline); } else { Loading Loading @@ -106,7 +107,7 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout protected void verifyPasswordAndUnlock() { String entry = getPasswordText(); if (mLockPatternUtils.checkPassword(entry)) { if (mLockPatternUtils.checkPassword(entry, KeyguardUpdateMonitor.getCurrentUser())) { mCallback.reportUnlockAttempt(true); mCallback.dismiss(true); } else { Loading @@ -116,7 +117,8 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout mCallback.reportUnlockAttempt(false); int attempts = KeyguardUpdateMonitor.getInstance(mContext).getFailedUnlockAttempts(); if (0 == (attempts % LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT)) { long deadline = mLockPatternUtils.setLockoutAttemptDeadline(); long deadline = mLockPatternUtils.setLockoutAttemptDeadline( KeyguardUpdateMonitor.getCurrentUser()); handleAttemptLockout(deadline); } } Loading
packages/Keyguard/src/com/android/keyguard/KeyguardHostView.java +1 −1 Original line number Diff line number Diff line Loading @@ -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 = Loading
packages/Keyguard/src/com/android/keyguard/KeyguardPatternView.java +7 −4 Original line number Diff line number Diff line Loading @@ -130,7 +130,8 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit mLockPatternView.setOnPatternListener(new UnlockPatternListener()); // stealth mode will be the same for the life of this screen mLockPatternView.setInStealthMode(!mLockPatternUtils.isVisiblePatternEnabled()); mLockPatternView.setInStealthMode(!mLockPatternUtils.isVisiblePatternEnabled( KeyguardUpdateMonitor.getCurrentUser())); // vibrate mode will be the same for the life of this screen mLockPatternView.setTactileFeedbackEnabled(mLockPatternUtils.isTactileFeedbackEnabled()); Loading Loading @@ -176,7 +177,8 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit mLockPatternView.clearPattern(); // if the user is currently locked out, enforce it. long deadline = mLockPatternUtils.getLockoutAttemptDeadline(); long deadline = mLockPatternUtils.getLockoutAttemptDeadline( KeyguardUpdateMonitor.getCurrentUser()); if (deadline != 0) { handleAttemptLockout(deadline); } else { Loading Loading @@ -213,7 +215,7 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit } public void onPatternDetected(List<LockPatternView.Cell> pattern) { if (mLockPatternUtils.checkPattern(pattern)) { if (mLockPatternUtils.checkPattern(pattern, KeyguardUpdateMonitor.getCurrentUser())) { mCallback.reportUnlockAttempt(true); mLockPatternView.setDisplayMode(LockPatternView.DisplayMode.Correct); mCallback.dismiss(true); Loading @@ -230,7 +232,8 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit int attempts = mKeyguardUpdateMonitor.getFailedUnlockAttempts(); if (registeredAttempt && 0 == (attempts % LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT)) { long deadline = mLockPatternUtils.setLockoutAttemptDeadline(); long deadline = mLockPatternUtils.setLockoutAttemptDeadline( KeyguardUpdateMonitor.getCurrentUser()); handleAttemptLockout(deadline); } else { mSecurityMessageDisplay.setMessage(R.string.kg_wrong_pattern, true); Loading