diff options
Diffstat (limited to 'src/com/android/settings/CryptKeeper.java')
-rw-r--r-- | src/com/android/settings/CryptKeeper.java | 117 |
1 files changed, 81 insertions, 36 deletions
diff --git a/src/com/android/settings/CryptKeeper.java b/src/com/android/settings/CryptKeeper.java index 4e20823..e9fed4f 100644 --- a/src/com/android/settings/CryptKeeper.java +++ b/src/com/android/settings/CryptKeeper.java @@ -65,6 +65,8 @@ import com.android.internal.widget.LockPatternUtils; import com.android.internal.widget.LockPatternView; import com.android.internal.widget.LockPatternView.Cell; +import static com.android.internal.widget.LockPatternView.DisplayMode; + import java.util.List; /** @@ -122,6 +124,16 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList private int mNotificationCountdown = 0; /** Number of calls to {@link #notifyUser()} before we release the wakelock */ private int mReleaseWakeLockCountdown = 0; + private int mStatusString = R.string.enter_password; + + // how long we wait to clear a wrong pattern + private static final int WRONG_PATTERN_CLEAR_TIMEOUT_MS = 1500; + + private Runnable mClearPatternRunnable = new Runnable() { + public void run() { + mLockPatternView.clearPattern(); + } + }; /** * Used to propagate state through configuration changes (e.g. screen rotation) @@ -175,21 +187,32 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList } else if (failedAttempts == MAX_FAILED_ATTEMPTS) { // Factory reset the device. sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR")); - } else if ((failedAttempts % COOL_DOWN_ATTEMPTS) == 0) { - if (mLockPatternView != null) { - mLockPatternView.clearPattern(); - } - mCooldown = COOL_DOWN_INTERVAL; - cooldown(); } else { - final TextView status = (TextView) findViewById(R.id.status); - status.setText(R.string.try_again); - // Reenable the password entry - if (mPasswordEntry != null) { - mPasswordEntry.setEnabled(true); - } + // Wrong entry. Handle pattern case. if (mLockPatternView != null) { - mLockPatternView.setEnabled(true); + mLockPatternView.setDisplayMode(DisplayMode.Wrong); + mLockPatternView.removeCallbacks(mClearPatternRunnable); + mLockPatternView.postDelayed(mClearPatternRunnable, WRONG_PATTERN_CLEAR_TIMEOUT_MS); + } + if ((failedAttempts % COOL_DOWN_ATTEMPTS) == 0) { + mCooldown = COOL_DOWN_INTERVAL; + cooldown(); + } else { + final TextView status = (TextView) findViewById(R.id.status); + status.setText(R.string.try_again); + if (mLockPatternView != null) { + mLockPatternView.setDisplayMode(DisplayMode.Wrong); + } + // Reenable the password entry + if (mPasswordEntry != null) { + mPasswordEntry.setEnabled(true); + final InputMethodManager imm = (InputMethodManager) getSystemService( + Context.INPUT_METHOD_SERVICE); + imm.showSoftInput(mPasswordEntry, 0); + } + if (mLockPatternView != null) { + mLockPatternView.setEnabled(true); + } } } } @@ -398,19 +421,28 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList public void onPostExecute(java.lang.Void v) { if(type == StorageManager.CRYPT_TYPE_PIN) { setContentView(R.layout.crypt_keeper_pin_entry); - ((TextView)findViewById(R.id.status)).setText(R.string.enter_pin); + mStatusString = R.string.enter_pin; } else if (type == StorageManager.CRYPT_TYPE_PATTERN) { setContentView(R.layout.crypt_keeper_pattern_entry); setBackFunctionality(false); - ((TextView)findViewById(R.id.status)).setText(R.string.enter_pattern); + mStatusString = R.string.enter_pattern; } else { setContentView(R.layout.crypt_keeper_password_entry); + mStatusString = R.string.enter_password; } + final TextView status = (TextView) findViewById(R.id.status); + status.setText(mStatusString); + + final TextView ownerInfo = (TextView) findViewById(R.id.owner_info); + ownerInfo.setText(owner_info); + ownerInfo.setSelected(true); // Required for marquee'ing to work - final TextView status = (TextView) findViewById(R.id.owner_info); - status.setText(owner_info); - status.setSelected(true); // Required for marquee'ing to work passwordEntryInit(); + + if (mCooldown > 0) { + setBackFunctionality(false); + cooldown(); // in case we are cooling down and coming back from emergency dialler + } } }.execute(); } else if (!mValidationRequested) { @@ -553,13 +585,24 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList // Re-enable the password entry and back presses. if (mPasswordEntry != null) { mPasswordEntry.setEnabled(true); + final InputMethodManager imm = (InputMethodManager) getSystemService( + Context.INPUT_METHOD_SERVICE); + imm.showSoftInput(mPasswordEntry, 0); setBackFunctionality(true); } if (mLockPatternView != null) { mLockPatternView.setEnabled(true); } - status.setText(R.string.enter_password); + status.setText(mStatusString); } else { + // Disable the password entry and back presses. + if (mPasswordEntry != null) { + mPasswordEntry.setEnabled(false); + } + if (mLockPatternView != null) { + mLockPatternView.setEnabled(false); + } + CharSequence template = getText(R.string.crypt_keeper_cooldown); status.setText(TextUtils.expandTemplate(template, Integer.toString(mCooldown))); @@ -583,25 +626,26 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList } protected LockPatternView.OnPatternListener mChooseNewLockPatternListener = - new LockPatternView.OnPatternListener() { + new LockPatternView.OnPatternListener() { - @Override - public void onPatternStart() { - } + @Override + public void onPatternStart() { + mLockPatternView.removeCallbacks(mClearPatternRunnable); + } - @Override - public void onPatternCleared() { - } + @Override + public void onPatternCleared() { + } - @Override - public void onPatternDetected(List<LockPatternView.Cell> pattern) { - mLockPatternView.setEnabled(false); - new DecryptTask().execute(LockPatternUtils.patternToString(pattern)); - } + @Override + public void onPatternDetected(List<LockPatternView.Cell> pattern) { + mLockPatternView.setEnabled(false); + new DecryptTask().execute(LockPatternUtils.patternToString(pattern)); + } - @Override - public void onPatternCellAdded(List<Cell> pattern) { - } + @Override + public void onPatternCellAdded(List<Cell> pattern) { + } }; private void passwordEntryInit() { @@ -655,13 +699,13 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList mWakeLock.acquire(); // Keep awake for 10 minutes - if the user hasn't been alerted by then // best not to just drain their battery - mReleaseWakeLockCountdown = 96; // 96 * 5 + 120 = 600 + mReleaseWakeLockCountdown = 96; // 96 * 5 secs per click + 120 secs before we show this = 600 } } // Asynchronously throw up the IME, since there are issues with requesting it to be shown // immediately. - if (mLockPatternView == null) { + if (mLockPatternView == null && mCooldown <= 0) { mHandler.postDelayed(new Runnable() { @Override public void run() { imm.showSoftInputUnchecked(0, null); @@ -846,6 +890,7 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList final Intent intent = new Intent(ACTION_EMERGENCY_DIAL); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); + setBackFunctionality(true); startActivity(intent); } |