diff options
author | Konstantin Lopyrev <klopyrev@google.com> | 2010-05-27 16:01:41 -0700 |
---|---|---|
committer | Konstantin Lopyrev <klopyrev@google.com> | 2010-05-27 16:04:49 -0700 |
commit | 57fbf694a53afb9c1924d81272179dceb3acfa4d (patch) | |
tree | 7e3b444006920eea89fd87cd3392eeff668ea124 /src | |
parent | dfa18503b694c57fbdd677906768246629a3ddeb (diff) | |
download | packages_apps_settings-57fbf694a53afb9c1924d81272179dceb3acfa4d.zip packages_apps_settings-57fbf694a53afb9c1924d81272179dceb3acfa4d.tar.gz packages_apps_settings-57fbf694a53afb9c1924d81272179dceb3acfa4d.tar.bz2 |
Change I546ee2fb: Fix 2677197: Adding minimum complex character support.
Change-Id: I5590ec2743b84e34098871507dbcc2f49e5a4e9f
Diffstat (limited to 'src')
5 files changed, 74 insertions, 29 deletions
diff --git a/src/com/android/settings/ChooseLockGeneric.java b/src/com/android/settings/ChooseLockGeneric.java index 0672ad9..5247e79 100644 --- a/src/com/android/settings/ChooseLockGeneric.java +++ b/src/com/android/settings/ChooseLockGeneric.java @@ -138,7 +138,7 @@ public class ChooseLockGeneric extends PreferenceActivity { } else if (KEY_UNLOCK_SET_PIN.equals(key)) { enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_NUMERIC; } else if (KEY_UNLOCK_SET_PASSWORD.equals(key)) { - enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC; + enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_COMPLEX; } if (!enabled) { pref.setSummary(R.string.unlock_set_unlock_disabled_summary); diff --git a/src/com/android/settings/ChooseLockPassword.java b/src/com/android/settings/ChooseLockPassword.java index 97b1317..13c9836 100644 --- a/src/com/android/settings/ChooseLockPassword.java +++ b/src/com/android/settings/ChooseLockPassword.java @@ -48,6 +48,11 @@ public class ChooseLockPassword extends Activity implements OnClickListener, OnE private TextView mPasswordEntry; private int mPasswordMinLength = 4; private int mPasswordMaxLength = 16; + private int mPasswordMinLetters = 0; + private int mPasswordMinUpperCase = 0; + private int mPasswordMinLowerCase = 0; + private int mPasswordMinSymbols = 0; + private int mPasswordMinNumeric = 0; private LockPatternUtils mLockPatternUtils; private int mRequestedQuality = DevicePolicyManager.PASSWORD_QUALITY_NUMERIC; private ChooseLockSettingsHelper mChooseLockSettingsHelper; @@ -61,6 +66,11 @@ public class ChooseLockPassword extends Activity implements OnClickListener, OnE private Button mNextButton; public static final String PASSWORD_MIN_KEY = "lockscreen.password_min"; public static final String PASSWORD_MAX_KEY = "lockscreen.password_max"; + public static final String PASSWORD_MIN_LETTERS_KEY = "lockscreen.password_min_letters"; + public static final String PASSWORD_MIN_LOWERCASE_KEY = "lockscreen.password_min_lowercase"; + public static final String PASSWORD_MIN_UPPERCASE_KEY = "lockscreen.password_min_uppercase"; + public static final String PASSWORD_MIN_NUMERIC_KEY = "lockscreen.password_min_numeric"; + public static final String PASSWORD_MIN_SYMBOLS_KEY = "lockscreen.password_min_symbols"; private static Handler mHandler = new Handler(); private static final int CONFIRM_EXISTING_REQUEST = 58; static final int RESULT_FINISHED = RESULT_FIRST_USER; @@ -101,19 +111,25 @@ public class ChooseLockPassword extends Activity implements OnClickListener, OnE protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mLockPatternUtils = new LockPatternUtils(this); - mRequestedQuality = getIntent().getIntExtra(LockPatternUtils.PASSWORD_TYPE_KEY, mRequestedQuality); - mPasswordMinLength = getIntent().getIntExtra(PASSWORD_MIN_KEY, mPasswordMinLength); + mRequestedQuality = Math.max(getIntent().getIntExtra(LockPatternUtils.PASSWORD_TYPE_KEY, + mRequestedQuality), mLockPatternUtils.getRequestedPasswordQuality()); + mPasswordMinLength = Math.max( + getIntent().getIntExtra(PASSWORD_MIN_KEY, mPasswordMinLength), mLockPatternUtils + .getRequestedMinimumPasswordLength()); mPasswordMaxLength = getIntent().getIntExtra(PASSWORD_MAX_KEY, mPasswordMaxLength); - + mPasswordMinLetters = Math.max(getIntent().getIntExtra(PASSWORD_MIN_LETTERS_KEY, + mPasswordMinLetters), mLockPatternUtils.getRequestedPasswordMinimumLetters()); + mPasswordMinUpperCase = Math.max(getIntent().getIntExtra(PASSWORD_MIN_UPPERCASE_KEY, + mPasswordMinUpperCase), mLockPatternUtils.getRequestedPasswordMinimumUpperCase()); + mPasswordMinLowerCase = Math.max(getIntent().getIntExtra(PASSWORD_MIN_LOWERCASE_KEY, + mPasswordMinLowerCase), mLockPatternUtils.getRequestedPasswordMinimumLowerCase()); + mPasswordMinNumeric = Math.max(getIntent().getIntExtra(PASSWORD_MIN_NUMERIC_KEY, + mPasswordMinNumeric), mLockPatternUtils.getRequestedPasswordMinimumNumeric()); + mPasswordMinSymbols = Math.max(getIntent().getIntExtra(PASSWORD_MIN_SYMBOLS_KEY, + mPasswordMinSymbols), mLockPatternUtils.getRequestedPasswordMinimumSymbols()); final boolean confirmCredentials = getIntent().getBooleanExtra("confirm_credentials", true); - int minMode = mLockPatternUtils.getRequestedPasswordQuality(); - if (mRequestedQuality < minMode) { - mRequestedQuality = minMode; - } - int minLength = mLockPatternUtils.getRequestedMinimumPasswordLength(); - if (mPasswordMinLength < minLength) { - mPasswordMinLength = minLength; - } + + initViews(); mChooseLockSettingsHelper = new ChooseLockSettingsHelper(this); if (savedInstanceState == null) { @@ -142,7 +158,8 @@ public class ChooseLockPassword extends Activity implements OnClickListener, OnE mPasswordEntry.addTextChangedListener(this); mIsAlphaMode = DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC == mRequestedQuality - || DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC == mRequestedQuality; + || DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC == mRequestedQuality + || DevicePolicyManager.PASSWORD_QUALITY_COMPLEX == mRequestedQuality; mKeyboardHelper = new PasswordEntryKeyboardHelper(this, mKeyboardView, mPasswordEntry); mKeyboardHelper.setKeyboardMode(mIsAlphaMode ? PasswordEntryKeyboardHelper.KEYBOARD_MODE_ALPHA @@ -212,9 +229,11 @@ public class ChooseLockPassword extends Activity implements OnClickListener, OnE R.string.lockpassword_password_too_long : R.string.lockpassword_pin_too_long, mPasswordMaxLength); } - boolean hasAlpha = false; - boolean hasDigit = false; - boolean hasSymbol = false; + int letters = 0; + int numbers = 0; + int lowercase = 0; + int symbols = 0; + int uppercase = 0; for (int i = 0; i < password.length(); i++) { char c = password.charAt(i); // allow non white space Latin-1 characters only @@ -222,32 +241,55 @@ public class ChooseLockPassword extends Activity implements OnClickListener, OnE return getString(R.string.lockpassword_illegal_character); } if (c >= '0' && c <= '9') { - hasDigit = true; - } else if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) { - hasAlpha = true; + numbers++; + } else if (c >= 'A' && c <= 'Z') { + letters++; + uppercase++; + } else if (c >= 'a' && c <= 'z') { + letters++; + lowercase++; } else { - hasSymbol = true; + symbols++; } } if (DevicePolicyManager.PASSWORD_QUALITY_NUMERIC == mRequestedQuality - && (hasAlpha | hasSymbol)) { - // This shouldn't be possible unless user finds some way to bring up soft keyboard + && (letters > 0 || symbols > 0)) { + // This shouldn't be possible unless user finds some way to bring up + // soft keyboard return getString(R.string.lockpassword_pin_contains_non_digits); + } else if (DevicePolicyManager.PASSWORD_QUALITY_COMPLEX == mRequestedQuality) { + if (letters < mPasswordMinLetters) { + return String.format(getResources().getQuantityString( + R.plurals.lockpassword_password_requires_letters, mPasswordMinLetters), + mPasswordMinLetters); + } else if (numbers < mPasswordMinNumeric) { + return String.format(getResources().getQuantityString( + R.plurals.lockpassword_password_requires_numeric, mPasswordMinNumeric), + mPasswordMinNumeric); + } else if (lowercase < mPasswordMinLowerCase) { + return String.format(getResources().getQuantityString( + R.plurals.lockpassword_password_requires_lowercase, mPasswordMinLowerCase), + mPasswordMinLowerCase); + } else if (uppercase < mPasswordMinUpperCase) { + return String.format(getResources().getQuantityString( + R.plurals.lockpassword_password_requires_uppercase, mPasswordMinUpperCase), + mPasswordMinUpperCase); + } else if (symbols < mPasswordMinSymbols) { + return String.format(getResources().getQuantityString( + R.plurals.lockpassword_password_requires_symbols, mPasswordMinSymbols), + mPasswordMinSymbols); + } } else { final boolean alphabetic = DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC == mRequestedQuality; final boolean alphanumeric = DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC == mRequestedQuality; - final boolean symbolic = false; // not yet - if ((alphabetic || alphanumeric) && !hasAlpha) { + if ((alphabetic || alphanumeric) && letters == 0) { return getString(R.string.lockpassword_password_requires_alpha); } - if (alphanumeric && !hasDigit) { + if (alphanumeric && numbers == 0) { return getString(R.string.lockpassword_password_requires_digit); } - if (symbolic && !hasSymbol) { - return getString(R.string.lockpassword_password_requires_symbol); - } } if(mLockPatternUtils.checkPasswordHistory(password)) { return getString(mIsAlphaMode ? R.string.lockpassword_password_recently_used diff --git a/src/com/android/settings/ChooseLockSettingsHelper.java b/src/com/android/settings/ChooseLockSettingsHelper.java index ba83f8e..abcfc05 100644 --- a/src/com/android/settings/ChooseLockSettingsHelper.java +++ b/src/com/android/settings/ChooseLockSettingsHelper.java @@ -52,6 +52,7 @@ public class ChooseLockSettingsHelper { case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC: case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC: case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC: + case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX: // TODO: update UI layout for ConfirmPassword to show message and details launched = confirmPassword(request); break; diff --git a/src/com/android/settings/ConfirmLockPassword.java b/src/com/android/settings/ConfirmLockPassword.java index 6bc135b..0e893fa 100644 --- a/src/com/android/settings/ConfirmLockPassword.java +++ b/src/com/android/settings/ConfirmLockPassword.java @@ -65,7 +65,8 @@ public class ConfirmLockPassword extends Activity implements OnClickListener, mKeyboardView = (PasswordEntryKeyboardView) findViewById(R.id.keyboard); mHeaderText = (TextView) findViewById(R.id.headerText); final boolean isAlpha = DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC == storedQuality - || DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC == storedQuality; + || DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC == storedQuality + || DevicePolicyManager.PASSWORD_QUALITY_COMPLEX == storedQuality; mHeaderText.setText(isAlpha ? R.string.lockpassword_confirm_your_password_header : R.string.lockpassword_confirm_your_pin_header); mKeyboardHelper = new PasswordEntryKeyboardHelper(this, mKeyboardView, mPasswordEntry); diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java index 05a655a..312c84a 100644 --- a/src/com/android/settings/SecuritySettings.java +++ b/src/com/android/settings/SecuritySettings.java @@ -155,6 +155,7 @@ public class SecuritySettings extends PreferenceActivity { break; case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC: case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC: + case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX: addPreferencesFromResource(R.xml.security_settings_password); break; } |