Fix 2332563: Update logic for lockscreen in Settings.
This commit is contained in:
@@ -34,15 +34,24 @@ import android.inputmethodservice.KeyboardView;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.Editable;
|
||||
import android.text.Selection;
|
||||
import android.text.Spannable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.TextView.OnEditorActionListener;
|
||||
|
||||
|
||||
public class ChooseLockPassword extends Activity implements OnClickListener {
|
||||
public class ChooseLockPassword extends Activity implements OnClickListener, OnEditorActionListener,
|
||||
TextWatcher {
|
||||
private static final String KEY_FIRST_PIN = "first_pin";
|
||||
private static final String KEY_UI_STAGE = "ui_stage";
|
||||
private TextView mPasswordEntry;
|
||||
private int mPasswordMinLength = 4;
|
||||
private int mPasswordMaxLength = 8;
|
||||
@@ -54,6 +63,9 @@ public class ChooseLockPassword extends Activity implements OnClickListener {
|
||||
private String mFirstPin;
|
||||
private KeyboardView mKeyboardView;
|
||||
private PasswordEntryKeyboardHelper mKeyboardHelper;
|
||||
private boolean mIsAlphaMode;
|
||||
private Button mCancelButton;
|
||||
private Button mNextButton;
|
||||
public static final String PASSWORD_MIN_KEY = "lockscreen.password_min";
|
||||
public static final String PASSWORD_MAX_KEY = "lockscreen.password_max";
|
||||
private static Handler mHandler = new Handler();
|
||||
@@ -66,19 +78,30 @@ public class ChooseLockPassword extends Activity implements OnClickListener {
|
||||
*/
|
||||
protected enum Stage {
|
||||
|
||||
Introduction(R.string.lockpassword_choose_your_password_header),
|
||||
NeedToConfirm(R.string.lockpassword_confirm_your_password_header),
|
||||
ConfirmWrong(R.string.lockpassword_confirm_passwords_dont_match),
|
||||
ChoiceConfirmed(R.string.lockpassword_password_confirmed_header);
|
||||
Introduction(R.string.lockpassword_choose_your_password_header,
|
||||
R.string.lockpassword_choose_your_pin_header,
|
||||
R.string.lockpassword_continue_label),
|
||||
|
||||
NeedToConfirm(R.string.lockpassword_confirm_your_password_header,
|
||||
R.string.lockpassword_confirm_your_pin_header,
|
||||
R.string.lockpassword_ok_label),
|
||||
|
||||
ConfirmWrong(R.string.lockpassword_confirm_passwords_dont_match,
|
||||
R.string.lockpassword_confirm_pins_dont_match,
|
||||
R.string.lockpassword_continue_label);
|
||||
|
||||
/**
|
||||
* @param headerMessage The message displayed at the top.
|
||||
*/
|
||||
Stage(int headerMessage) {
|
||||
this.headerMessage = headerMessage;
|
||||
Stage(int hintInAlpha, int hintInNumeric, int nextButtonText) {
|
||||
this.alphaHint = hintInAlpha;
|
||||
this.numericHint = hintInNumeric;
|
||||
this.buttonText = nextButtonText;
|
||||
}
|
||||
|
||||
final int headerMessage;
|
||||
public final int alphaHint;
|
||||
public final int numericHint;
|
||||
public final int buttonText;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -110,15 +133,20 @@ public class ChooseLockPassword extends Activity implements OnClickListener {
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
|
||||
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
|
||||
|
||||
findViewById(R.id.cancel_button).setOnClickListener(this);
|
||||
findViewById(R.id.next_button).setOnClickListener(this);
|
||||
mCancelButton = (Button) findViewById(R.id.cancel_button);
|
||||
mCancelButton.setOnClickListener(this);
|
||||
mNextButton = (Button) findViewById(R.id.next_button);
|
||||
mNextButton.setOnClickListener(this);
|
||||
|
||||
mKeyboardView = (PasswordEntryKeyboardView) findViewById(R.id.keyboard);
|
||||
mPasswordEntry = (TextView) findViewById(R.id.password_entry);
|
||||
mPasswordEntry.setOnEditorActionListener(this);
|
||||
mPasswordEntry.addTextChangedListener(this);
|
||||
|
||||
final boolean isAlpha = LockPatternUtils.MODE_PASSWORD == mRequestedMode;
|
||||
mIsAlphaMode = LockPatternUtils.MODE_PASSWORD == mRequestedMode;
|
||||
mKeyboardHelper = new PasswordEntryKeyboardHelper(this, mKeyboardView, mPasswordEntry);
|
||||
mKeyboardHelper.setKeyboardMode(isAlpha ? PasswordEntryKeyboardHelper.KEYBOARD_MODE_ALPHA
|
||||
mKeyboardHelper.setKeyboardMode(mIsAlphaMode ?
|
||||
PasswordEntryKeyboardHelper.KEYBOARD_MODE_ALPHA
|
||||
: PasswordEntryKeyboardHelper.KEYBOARD_MODE_NUMERIC);
|
||||
|
||||
mHeaderText = (TextView) findViewById(R.id.headerText);
|
||||
@@ -126,17 +154,28 @@ public class ChooseLockPassword extends Activity implements OnClickListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
updateStage(mUiStage);
|
||||
mKeyboardView.requestFocus();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
// TODO Auto-generated method stub
|
||||
super.onResume();
|
||||
updateStage(mUiStage);
|
||||
mKeyboardView.requestFocus();
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putString(KEY_UI_STAGE, mUiStage.name());
|
||||
outState.putString(KEY_FIRST_PIN, mFirstPin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
String state = savedInstanceState.getString(KEY_UI_STAGE);
|
||||
mFirstPin = savedInstanceState.getString(KEY_FIRST_PIN);
|
||||
if (state != null) {
|
||||
mUiStage = Stage.valueOf(state);
|
||||
updateStage(mUiStage);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -154,9 +193,8 @@ public class ChooseLockPassword extends Activity implements OnClickListener {
|
||||
}
|
||||
|
||||
protected void updateStage(Stage stage) {
|
||||
mHeaderText.setText(stage.headerMessage);
|
||||
mPasswordEntry.setText("");
|
||||
mUiStage = stage;
|
||||
updateUi();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,60 +204,76 @@ public class ChooseLockPassword extends Activity implements OnClickListener {
|
||||
*/
|
||||
private String validatePassword(String pin) {
|
||||
if (pin.length() < mPasswordMinLength) {
|
||||
return getString(R.string.pin_password_too_short, mPasswordMinLength);
|
||||
return getString(mIsAlphaMode ?
|
||||
R.string.lockpassword_password_too_short
|
||||
: R.string.lockpassword_pin_too_short, mPasswordMinLength);
|
||||
}
|
||||
if (pin.length() > mPasswordMaxLength) {
|
||||
return getString(R.string.pin_password_too_long, mPasswordMaxLength);
|
||||
return getString(mIsAlphaMode ?
|
||||
R.string.lockpassword_password_too_long
|
||||
: R.string.lockpassword_pin_too_long, mPasswordMaxLength);
|
||||
}
|
||||
if (LockPatternUtils.MODE_PIN == mRequestedMode) {
|
||||
Pattern p = Pattern.compile("[0-9]+");
|
||||
Matcher m = p.matcher(pin);
|
||||
if (!m.find()) {
|
||||
return getString(R.string.pin_password_contains_non_digits);
|
||||
boolean hasAlpha = false;
|
||||
boolean hasDigit = false;
|
||||
boolean hasSymbol = false;
|
||||
for (int i = 0; i < pin.length(); i++) {
|
||||
char c = pin.charAt(i);
|
||||
// allow non white space Latin-1 characters only
|
||||
if (c <= 32 || c > 127) {
|
||||
return getString(R.string.lockpassword_illegal_character);
|
||||
}
|
||||
} else if (LockPatternUtils.MODE_PASSWORD == mRequestedMode) {
|
||||
// allow Latin-1 characters only
|
||||
for (int i = 0; i < pin.length(); i++) {
|
||||
char c = pin.charAt(i);
|
||||
if (c <= 32 || c > 127) {
|
||||
return getString(R.string.pin_password_illegal_character);
|
||||
if (c >= '0' && c <= '9') {
|
||||
hasDigit = true;
|
||||
} else if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) {
|
||||
hasAlpha = true;
|
||||
} else {
|
||||
hasSymbol = true;
|
||||
}
|
||||
}
|
||||
if (LockPatternUtils.MODE_PIN == mRequestedMode && (hasAlpha | hasSymbol)) {
|
||||
return getString(R.string.lockpassword_pin_contains_non_digits);
|
||||
} else if (LockPatternUtils.MODE_PASSWORD == mRequestedMode && !hasAlpha) {
|
||||
// require at least 1 alpha character
|
||||
return getString(R.string.lockpassword_password_requires_alpha);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void handleNext() {
|
||||
final String pin = mPasswordEntry.getText().toString();
|
||||
if (TextUtils.isEmpty(pin)) {
|
||||
return;
|
||||
}
|
||||
String errorMsg = null;
|
||||
if (mUiStage == Stage.Introduction) {
|
||||
errorMsg = validatePassword(pin);
|
||||
if (errorMsg == null) {
|
||||
mFirstPin = pin;
|
||||
updateStage(Stage.NeedToConfirm);
|
||||
mPasswordEntry.setText("");
|
||||
}
|
||||
} else if (mUiStage == Stage.NeedToConfirm) {
|
||||
if (mFirstPin.equals(pin)) {
|
||||
mLockPatternUtils.clearLock();
|
||||
mLockPatternUtils.saveLockPassword(pin, mRequestedMode);
|
||||
finish();
|
||||
} else {
|
||||
updateStage(Stage.ConfirmWrong);
|
||||
CharSequence tmp = mPasswordEntry.getText();
|
||||
if (tmp != null) {
|
||||
Selection.setSelection((Spannable) tmp, 0, tmp.length());
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
if (errorMsg != null) {
|
||||
showError(errorMsg, mUiStage);
|
||||
}
|
||||
}
|
||||
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.next_button:
|
||||
{
|
||||
final String pin = mPasswordEntry.getText().toString();
|
||||
if (TextUtils.isEmpty(pin)) {
|
||||
break;
|
||||
}
|
||||
String errorMsg = null;
|
||||
if (mUiStage == Stage.Introduction) {
|
||||
errorMsg = validatePassword(pin);
|
||||
if (errorMsg == null) {
|
||||
mFirstPin = pin;
|
||||
updateStage(Stage.NeedToConfirm);
|
||||
}
|
||||
} else if (mUiStage == Stage.NeedToConfirm) {
|
||||
if (mFirstPin.equals(pin)) {
|
||||
// TODO: move these to LockPatternUtils
|
||||
mLockPatternUtils.setLockPatternEnabled(false);
|
||||
mLockPatternUtils.saveLockPattern(null);
|
||||
mLockPatternUtils.saveLockPassword(pin, mRequestedMode);
|
||||
finish();
|
||||
} else {
|
||||
int msg = R.string.lockpassword_confirm_passwords_dont_match;
|
||||
errorMsg = getString(msg);
|
||||
}
|
||||
}
|
||||
if (errorMsg != null) {
|
||||
showError(errorMsg, Stage.Introduction);
|
||||
}
|
||||
}
|
||||
handleNext();
|
||||
break;
|
||||
|
||||
case R.id.cancel_button:
|
||||
@@ -230,11 +284,57 @@ public class ChooseLockPassword extends Activity implements OnClickListener {
|
||||
|
||||
private void showError(String msg, final Stage next) {
|
||||
mHeaderText.setText(msg);
|
||||
mPasswordEntry.setText("");
|
||||
mHandler.postDelayed(new Runnable() {
|
||||
public void run() {
|
||||
updateStage(next);
|
||||
}
|
||||
}, ERROR_MESSAGE_TIMEOUT);
|
||||
}
|
||||
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
// Check if this was the result of hitting the enter key
|
||||
if (actionId == EditorInfo.IME_NULL) {
|
||||
handleNext();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the hint based on current Stage and length of password entry
|
||||
*/
|
||||
private void updateUi() {
|
||||
final int length = mPasswordEntry.getText().toString().length();
|
||||
if (mUiStage == Stage.Introduction && length > 0) {
|
||||
if (length < mPasswordMinLength) {
|
||||
String msg = getString(mIsAlphaMode ? R.string.lockpassword_password_too_short
|
||||
: R.string.lockpassword_pin_too_short, mPasswordMinLength);
|
||||
mHeaderText.setText(msg);
|
||||
mNextButton.setEnabled(false);
|
||||
} else {
|
||||
mHeaderText.setText(R.string.lockpassword_press_continue);
|
||||
mNextButton.setEnabled(true);
|
||||
}
|
||||
} else {
|
||||
mHeaderText.setText(mIsAlphaMode ? mUiStage.alphaHint : mUiStage.numericHint);
|
||||
mNextButton.setEnabled(length > 0);
|
||||
}
|
||||
mNextButton.setText(mUiStage.buttonText);
|
||||
}
|
||||
|
||||
public void afterTextChanged(Editable s) {
|
||||
// Changing the text while error displayed resets to NeedToConfirm state
|
||||
if (mUiStage == Stage.ConfirmWrong) {
|
||||
mUiStage = Stage.NeedToConfirm;
|
||||
}
|
||||
updateUi();
|
||||
}
|
||||
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -24,13 +24,17 @@ import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.Editable;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.TextView.OnEditorActionListener;
|
||||
|
||||
public class ConfirmLockPassword extends Activity implements OnClickListener {
|
||||
public class ConfirmLockPassword extends Activity implements OnClickListener,
|
||||
OnEditorActionListener {
|
||||
private static final long ERROR_MESSAGE_TIMEOUT = 3000;
|
||||
private TextView mPasswordEntry;
|
||||
private LockPatternUtils mLockPatternUtils;
|
||||
@@ -56,11 +60,13 @@ public class ConfirmLockPassword extends Activity implements OnClickListener {
|
||||
findViewById(R.id.cancel_button).setOnClickListener(this);
|
||||
findViewById(R.id.next_button).setOnClickListener(this);
|
||||
mPasswordEntry = (TextView) findViewById(R.id.password_entry);
|
||||
mPasswordEntry.setOnEditorActionListener(this);
|
||||
mKeyboardView = (PasswordEntryKeyboardView) findViewById(R.id.keyboard);
|
||||
mHeaderText = (TextView) findViewById(R.id.headerText);
|
||||
mHeaderText.setText(R.string.lockpassword_confirm_your_password_header);
|
||||
final boolean isAlpha =
|
||||
LockPatternUtils.MODE_PASSWORD == mLockPatternUtils.getPasswordMode();
|
||||
mHeaderText.setText(isAlpha ? R.string.lockpassword_confirm_your_password_header
|
||||
: R.string.lockpassword_confirm_your_pin_header);
|
||||
mKeyboardHelper = new PasswordEntryKeyboardHelper(this, mKeyboardView, mPasswordEntry);
|
||||
mKeyboardHelper.setKeyboardMode(isAlpha ? PasswordEntryKeyboardHelper.KEYBOARD_MODE_ALPHA
|
||||
: PasswordEntryKeyboardHelper.KEYBOARD_MODE_NUMERIC);
|
||||
@@ -80,18 +86,20 @@ public class ConfirmLockPassword extends Activity implements OnClickListener {
|
||||
mKeyboardView.requestFocus();
|
||||
}
|
||||
|
||||
private void handleNext() {
|
||||
final String pin = mPasswordEntry.getText().toString();
|
||||
if (mLockPatternUtils.checkPassword(pin)) {
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
} else {
|
||||
showError(R.string.lockpattern_need_to_unlock_wrong);
|
||||
}
|
||||
}
|
||||
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.next_button:
|
||||
{
|
||||
final String pin = mPasswordEntry.getText().toString();
|
||||
if (mLockPatternUtils.checkPassword(pin)) {
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
} else {
|
||||
showError(R.string.lockpattern_need_to_unlock_wrong);
|
||||
}
|
||||
}
|
||||
handleNext();
|
||||
break;
|
||||
|
||||
case R.id.cancel_button:
|
||||
@@ -110,4 +118,13 @@ public class ConfirmLockPassword extends Activity implements OnClickListener {
|
||||
}
|
||||
}, ERROR_MESSAGE_TIMEOUT);
|
||||
}
|
||||
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
// Check if this was the result of hitting the enter key
|
||||
if (actionId == EditorInfo.IME_NULL) {
|
||||
handleNext();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -57,6 +57,11 @@ import com.android.internal.widget.LockPatternUtils;
|
||||
*/
|
||||
public class SecuritySettings extends PreferenceActivity {
|
||||
|
||||
private static final String KEY_UNLOCK_SET_PASSWORD = "unlock_set_password";
|
||||
private static final String KEY_UNLOCK_SET_PIN = "unlock_set_pin";
|
||||
private static final String KEY_UNLOCK_SET_PATTERN = "unlock_set_pattern";
|
||||
private static final String KEY_UNLOCK_METHOD_CHANGE_CURRENT = "unlock_method_change_current";
|
||||
private static final String KEY_UNLOCK_METHOD_DISABLE = "unlock_method_disable";
|
||||
// Lock Settings
|
||||
private static final String PACKAGE = "com.android.settings";
|
||||
private static final String LOCK_PATTERN_TUTORIAL = PACKAGE + ".ChooseLockPatternTutorial";
|
||||
@@ -101,13 +106,15 @@ public class SecuritySettings extends PreferenceActivity {
|
||||
private CheckBoxPreference mAssistedGps;
|
||||
|
||||
DevicePolicyManager mDPM;
|
||||
|
||||
|
||||
// These provide support for receiving notification when Location Manager settings change.
|
||||
// This is necessary because the Network Location Provider can change settings
|
||||
// if the user does not confirm enabling the provider.
|
||||
private ContentQueryMap mContentQueryMap;
|
||||
private ListPreference mUnlockMethod;
|
||||
private ChooseLockSettingsHelper mChooseLockSettingsHelper;
|
||||
private LockPatternUtils mLockPatternUtils;
|
||||
private PreferenceScreen mDisableUnlock;
|
||||
private PreferenceScreen mChangeCurrent;
|
||||
private final class SettingsObserver implements Observer {
|
||||
public void update(Observable o, Object arg) {
|
||||
updateToggles();
|
||||
@@ -117,18 +124,15 @@ public class SecuritySettings extends PreferenceActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.security_settings);
|
||||
|
||||
mLockPatternUtils = new LockPatternUtils(this);
|
||||
|
||||
mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||
|
||||
|
||||
mChooseLockSettingsHelper = new ChooseLockSettingsHelper(this);
|
||||
|
||||
createPreferenceHierarchy();
|
||||
|
||||
mNetwork = (CheckBoxPreference) getPreferenceScreen().findPreference(LOCATION_NETWORK);
|
||||
mGps = (CheckBoxPreference) getPreferenceScreen().findPreference(LOCATION_GPS);
|
||||
mAssistedGps = (CheckBoxPreference) getPreferenceScreen().findPreference(ASSISTED_GPS);
|
||||
|
||||
updateToggles();
|
||||
|
||||
// listen for Location Manager settings changes
|
||||
@@ -141,26 +145,46 @@ public class SecuritySettings extends PreferenceActivity {
|
||||
}
|
||||
|
||||
private PreferenceScreen createPreferenceHierarchy() {
|
||||
// Root
|
||||
PreferenceScreen root = this.getPreferenceScreen();
|
||||
if (root != null) {
|
||||
root.removeAll();
|
||||
}
|
||||
addPreferencesFromResource(R.xml.security_settings);
|
||||
root = this.getPreferenceScreen();
|
||||
|
||||
mNetwork = (CheckBoxPreference) getPreferenceScreen().findPreference(LOCATION_NETWORK);
|
||||
mGps = (CheckBoxPreference) getPreferenceScreen().findPreference(LOCATION_GPS);
|
||||
mAssistedGps = (CheckBoxPreference) getPreferenceScreen().findPreference(ASSISTED_GPS);
|
||||
|
||||
PreferenceManager pm = getPreferenceManager();
|
||||
|
||||
mUnlockMethod = (ListPreference) pm.findPreference(KEY_UNLOCK_METHOD);
|
||||
mUnlockMethod.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
String value = (String) newValue;
|
||||
handleUpdateUnlockMethod(value);
|
||||
return false;
|
||||
// Lock screen
|
||||
if (!mLockPatternUtils.isSecure()) {
|
||||
addPreferencesFromResource(R.xml.security_settings_chooser);
|
||||
} else {
|
||||
final int currentMode = mLockPatternUtils.getPasswordMode();
|
||||
if (currentMode == LockPatternUtils.MODE_PATTERN) {
|
||||
addPreferencesFromResource(R.xml.security_settings_pattern);
|
||||
} else if (currentMode == LockPatternUtils.MODE_PIN) {
|
||||
addPreferencesFromResource(R.xml.security_settings_pin);
|
||||
} else if (currentMode == LockPatternUtils.MODE_PASSWORD) {
|
||||
addPreferencesFromResource(R.xml.security_settings_password);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// disable current pattern. Should be common to all unlock preference screens.
|
||||
mDisableUnlock = (PreferenceScreen) pm.findPreference(KEY_UNLOCK_METHOD_DISABLE);
|
||||
|
||||
// change current. Should be common to all unlock preference screens
|
||||
mChangeCurrent = (PreferenceScreen) pm.findPreference(KEY_UNLOCK_METHOD_CHANGE_CURRENT);
|
||||
|
||||
// visible pattern
|
||||
mVisiblePattern = (CheckBoxPreference) pm.findPreference(KEY_VISIBLE_PATTERN);
|
||||
|
||||
// tactile feedback
|
||||
// tactile feedback. Should be common to all unlock preference screens.
|
||||
mTactileFeedback = (CheckBoxPreference) pm.findPreference(KEY_TACTILE_FEEDBACK_ENABLED);
|
||||
|
||||
|
||||
int activePhoneType = TelephonyManager.getDefault().getPhoneType();
|
||||
|
||||
// do not display SIM lock for CDMA phone
|
||||
@@ -217,7 +241,21 @@ public class SecuritySettings extends PreferenceActivity {
|
||||
return root;
|
||||
}
|
||||
|
||||
protected void handleUpdateUnlockMethod(final String value) {
|
||||
protected void handleUpdateUnlockMethod(String value) {
|
||||
// NULL means update the current password/pattern/pin
|
||||
if (value == null) {
|
||||
int mode = mLockPatternUtils.getPasswordMode();
|
||||
if (LockPatternUtils.MODE_PATTERN == mode) {
|
||||
value = "pattern";
|
||||
} else if (LockPatternUtils.MODE_PASSWORD == mode) {
|
||||
value = "password";
|
||||
} else if (LockPatternUtils.MODE_PIN == mode) {
|
||||
value = "pin";
|
||||
} else {
|
||||
throw new IllegalStateException("Unknown password mode: " + value);
|
||||
}
|
||||
}
|
||||
|
||||
if ("none".equals(value)) {
|
||||
if (mDPM.getPasswordQuality(null) == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
|
||||
mChooseLockSettingsHelper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST);
|
||||
@@ -248,11 +286,14 @@ public class SecuritySettings extends PreferenceActivity {
|
||||
|
||||
final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();
|
||||
boolean patternExists = lockPatternUtils.savedPatternExists();
|
||||
mVisiblePattern.setEnabled(patternExists);
|
||||
mTactileFeedback.setEnabled(patternExists);
|
||||
|
||||
mVisiblePattern.setChecked(lockPatternUtils.isVisiblePatternEnabled());
|
||||
mTactileFeedback.setChecked(lockPatternUtils.isTactileFeedbackEnabled());
|
||||
if (mVisiblePattern != null) {
|
||||
mVisiblePattern.setEnabled(patternExists);
|
||||
mVisiblePattern.setChecked(lockPatternUtils.isVisiblePatternEnabled());
|
||||
}
|
||||
if (mTactileFeedback != null) {
|
||||
mTactileFeedback.setEnabled(patternExists);
|
||||
mTactileFeedback.setChecked(lockPatternUtils.isTactileFeedbackEnabled());
|
||||
}
|
||||
|
||||
mShowPassword.setChecked(Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.TEXT_SHOW_PASSWORD, 1) != 0);
|
||||
@@ -266,7 +307,17 @@ public class SecuritySettings extends PreferenceActivity {
|
||||
final String key = preference.getKey();
|
||||
|
||||
final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();
|
||||
if (KEY_LOCK_ENABLED.equals(key)) {
|
||||
if (KEY_UNLOCK_SET_PATTERN.equals(key)) {
|
||||
handleUpdateUnlockMethod("pattern");
|
||||
} else if (KEY_UNLOCK_SET_PIN.equals(key)) {
|
||||
handleUpdateUnlockMethod("pin");
|
||||
} else if (KEY_UNLOCK_SET_PASSWORD.equals(key)) {
|
||||
handleUpdateUnlockMethod("password");
|
||||
} else if (KEY_UNLOCK_METHOD_DISABLE.equals(key)) {
|
||||
handleUpdateUnlockMethod("none");
|
||||
} else if (KEY_UNLOCK_METHOD_CHANGE_CURRENT.equals(key)) {
|
||||
handleUpdateUnlockMethod(null);
|
||||
} else if (KEY_LOCK_ENABLED.equals(key)) {
|
||||
lockPatternUtils.setLockPatternEnabled(isToggled(preference));
|
||||
} else if (KEY_VISIBLE_PATTERN.equals(key)) {
|
||||
lockPatternUtils.setVisiblePatternEnabled(isToggled(preference));
|
||||
@@ -327,6 +378,7 @@ public class SecuritySettings extends PreferenceActivity {
|
||||
if ((requestCode == CONFIRM_EXISTING_REQUEST) && resultOk) {
|
||||
lockPatternUtils.clearLock();
|
||||
}
|
||||
createPreferenceHierarchy();
|
||||
}
|
||||
|
||||
private class CredentialStorage implements DialogInterface.OnClickListener,
|
||||
|
Reference in New Issue
Block a user