diff options
author | Amith Yamasani <yamasani@google.com> | 2014-11-21 22:27:16 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-11-21 22:27:17 +0000 |
commit | efb2df698a4c2ed3d3371656cab199e5e3737fa9 (patch) | |
tree | 54868f02c33a65e690d5c13d49c50e49ad72f260 /packages/Keyguard/src/com/android | |
parent | 29dc496a42d49a37dcd99c0465f3cec18a47e6ff (diff) | |
parent | 3a3d212a51974ccec6100c1e117225291edc83cc (diff) | |
download | frameworks_base-efb2df698a4c2ed3d3371656cab199e5e3737fa9.zip frameworks_base-efb2df698a4c2ed3d3371656cab199e5e3737fa9.tar.gz frameworks_base-efb2df698a4c2ed3d3371656cab199e5e3737fa9.tar.bz2 |
Merge "Different messages when wiping user and not device" into lmp-mr1-dev
Diffstat (limited to 'packages/Keyguard/src/com/android')
-rw-r--r-- | packages/Keyguard/src/com/android/keyguard/KeyguardSecurityContainer.java | 73 |
1 files changed, 57 insertions, 16 deletions
diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardSecurityContainer.java b/packages/Keyguard/src/com/android/keyguard/KeyguardSecurityContainer.java index 119471b..979c377 100644 --- a/packages/Keyguard/src/com/android/keyguard/KeyguardSecurityContainer.java +++ b/packages/Keyguard/src/com/android/keyguard/KeyguardSecurityContainer.java @@ -17,7 +17,10 @@ package com.android.keyguard; import android.app.Activity; import android.app.AlertDialog; +import android.app.admin.DevicePolicyManager; import android.content.Context; +import android.os.UserHandle; +import android.os.UserManager; import android.util.AttributeSet; import android.util.Log; import android.util.Slog; @@ -32,6 +35,11 @@ import com.android.keyguard.KeyguardSecurityModel.SecurityMode; public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSecurityView { private static final boolean DEBUG = KeyguardConstants.DEBUG; private static final String TAG = "KeyguardSecurityView"; + + private static final int USER_TYPE_PRIMARY = 1; + private static final int USER_TYPE_WORK_PROFILE = 2; + private static final int USER_TYPE_SECONDARY_USER = 3; + private KeyguardSecurityModel mSecurityModel; private boolean mEnableFallback; // TODO: This should get the value from KeyguardPatternView private LockPatternUtils mLockPatternUtils; @@ -207,14 +215,41 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe } } - private void showAlmostAtWipeDialog(int attempts, int remaining) { - String message = mContext.getString(R.string.kg_failed_attempts_almost_at_wipe, - attempts, remaining); + private void showAlmostAtWipeDialog(int attempts, int remaining, int userType) { + String message = null; + switch (userType) { + case USER_TYPE_PRIMARY: + message = mContext.getString(R.string.kg_failed_attempts_almost_at_wipe, + attempts, remaining); + break; + case USER_TYPE_SECONDARY_USER: + message = mContext.getString(R.string.kg_failed_attempts_almost_at_erase_user, + attempts, remaining); + break; + case USER_TYPE_WORK_PROFILE: + message = mContext.getString(R.string.kg_failed_attempts_almost_at_erase_profile, + attempts, remaining); + break; + } showDialog(null, message); } - private void showWipeDialog(int attempts) { - String message = mContext.getString(R.string.kg_failed_attempts_now_wiping, attempts); + private void showWipeDialog(int attempts, int userType) { + String message = null; + switch (userType) { + case USER_TYPE_PRIMARY: + message = mContext.getString(R.string.kg_failed_attempts_now_wiping, + attempts); + break; + case USER_TYPE_SECONDARY_USER: + message = mContext.getString(R.string.kg_failed_attempts_now_erasing_user, + attempts); + break; + case USER_TYPE_WORK_PROFILE: + message = mContext.getString(R.string.kg_failed_attempts_now_erasing_profile, + attempts); + break; + } showDialog(null, message); } @@ -235,9 +270,10 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe SecurityMode mode = mSecurityModel.getSecurityMode(); final boolean usingPattern = mode == KeyguardSecurityModel.SecurityMode.Pattern; - - final int failedAttemptsBeforeWipe = mLockPatternUtils.getDevicePolicyManager() - .getMaximumFailedPasswordsForWipe(null, mLockPatternUtils.getCurrentUser()); + final int currentUser = mLockPatternUtils.getCurrentUser(); + final DevicePolicyManager dpm = mLockPatternUtils.getDevicePolicyManager(); + final int failedAttemptsBeforeWipe = + dpm.getMaximumFailedPasswordsForWipe(null, currentUser); final int failedAttemptWarning = LockPatternUtils.FAILED_ATTEMPTS_BEFORE_RESET - LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT; @@ -245,22 +281,27 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe final int remainingBeforeWipe = failedAttemptsBeforeWipe > 0 ? (failedAttemptsBeforeWipe - failedAttempts) : Integer.MAX_VALUE; // because DPM returns 0 if no restriction - boolean showTimeout = false; if (remainingBeforeWipe < LockPatternUtils.FAILED_ATTEMPTS_BEFORE_WIPE_GRACE) { // The user has installed a DevicePolicyManager that requests a user/profile to be wiped // N attempts. Once we get below the grace period, we post this dialog every time as a // clear warning until the deletion fires. - // - // TODO: Show a different dialog depending on whether the device will be completely - // wiped (i.e. policy is set for the primary profile of the USER_OWNER) or a single - // secondary user or managed profile will be removed. + // Check which profile has the strictest policy for failed password attempts + final int expiringUser = dpm.getProfileWithMinimumFailedPasswordsForWipe(currentUser); + int userType = USER_TYPE_PRIMARY; + if (expiringUser == currentUser) { + if (expiringUser != UserHandle.USER_OWNER) { + userType = USER_TYPE_SECONDARY_USER; + } + } else if (expiringUser != UserHandle.USER_NULL) { + userType = USER_TYPE_WORK_PROFILE; + } // If USER_NULL, which shouldn't happen, leave it as USER_TYPE_PRIMARY if (remainingBeforeWipe > 0) { - showAlmostAtWipeDialog(failedAttempts, remainingBeforeWipe); + showAlmostAtWipeDialog(failedAttempts, remainingBeforeWipe, userType); } else { // Too many attempts. The device will be wiped shortly. - Slog.i(TAG, "Too many unlock attempts; device will be wiped!"); - showWipeDialog(failedAttempts); + Slog.i(TAG, "Too many unlock attempts; user " + expiringUser + " will be wiped!"); + showWipeDialog(failedAttempts, userType); } } else { showTimeout = |