diff options
author | Roman Birg <roman@cyngn.com> | 2015-05-20 10:31:13 -0700 |
---|---|---|
committer | Roman Birg <roman@cyngn.com> | 2015-12-11 10:36:34 -0800 |
commit | c342389b2d3df588ceec5d0e877096f29103ee65 (patch) | |
tree | 10afce145296b1acd1efddf9f783ae3098a67972 | |
parent | 35761ffce2089e037e0f37999704819b3e1ce11e (diff) | |
download | packages_apps_Settings-c342389b2d3df588ceec5d0e877096f29103ee65.zip packages_apps_Settings-c342389b2d3df588ceec5d0e877096f29103ee65.tar.gz packages_apps_Settings-c342389b2d3df588ceec5d0e877096f29103ee65.tar.bz2 |
CryptKeeper improvements
- Status text was used enough to warrant it being a field variable
instead of looking for the view every time
- Display proper text after changing pattern sizes (to input a pattern,
not a password)
- Disable changing pattern sizes while validaing pattern
REFS: LETTUCE-557, LETTUCE-352
Change-Id: Ib4ecf04a58da8d1648d514d9650d69c33d9587a7
Signed-off-by: Roman Birg <roman@cyngn.com>
-rw-r--r-- | res/layout/crypt_keeper_pattern_sizes.xml | 4 | ||||
-rw-r--r-- | src/com/android/settings/CryptKeeper.java | 83 |
2 files changed, 55 insertions, 32 deletions
diff --git a/res/layout/crypt_keeper_pattern_sizes.xml b/res/layout/crypt_keeper_pattern_sizes.xml index acbb238..b493d14 100644 --- a/res/layout/crypt_keeper_pattern_sizes.xml +++ b/res/layout/crypt_keeper_pattern_sizes.xml @@ -26,7 +26,6 @@ android:text="@string/lock_pattern_size_3" android:textColor="@color/text_color_white" android:layout_weight="1" - android:onClick="onPatternButtonClick" style="?android:attr/borderlessButtonStyle"/> <Button @@ -39,7 +38,6 @@ android:text="@string/lock_pattern_size_4" android:textColor="@color/text_color_white" android:layout_weight="1" - android:onClick="onPatternButtonClick" style="?android:attr/borderlessButtonStyle"/> <Button @@ -52,7 +50,6 @@ android:text="@string/lock_pattern_size_5" android:textColor="@color/text_color_white" android:layout_weight="1" - android:onClick="onPatternButtonClick" style="?android:attr/borderlessButtonStyle"/> <Button @@ -65,7 +62,6 @@ android:text="@string/lock_pattern_size_6" android:textColor="@color/text_color_white" android:layout_weight="1" - android:onClick="onPatternButtonClick" style="?android:attr/borderlessButtonStyle"/> diff --git a/src/com/android/settings/CryptKeeper.java b/src/com/android/settings/CryptKeeper.java index 7c0e8f0..cfb27e1 100644 --- a/src/com/android/settings/CryptKeeper.java +++ b/src/com/android/settings/CryptKeeper.java @@ -68,6 +68,7 @@ import com.android.internal.widget.LockPatternUtils; import com.android.internal.widget.LockPatternView; import com.android.internal.widget.LockPatternView.Cell; +import java.util.ArrayList; import java.util.List; import static com.android.internal.widget.LockPatternView.DisplayMode; @@ -86,7 +87,7 @@ import static com.android.internal.widget.LockPatternView.DisplayMode; * </pre> */ public class CryptKeeper extends Activity implements TextView.OnEditorActionListener, - OnKeyListener, OnTouchListener, TextWatcher { + OnKeyListener, OnTouchListener, TextWatcher, OnClickListener { private static final String TAG = "CryptKeeper"; private static final String DECRYPT_STATE = "trigger_restart_framework"; @@ -127,6 +128,15 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList PowerManager.WakeLock mWakeLock; private EditText mPasswordEntry; private LockPatternView mLockPatternView; + private TextView mStatusText; + private List<Button> mLockPatternButtons = new ArrayList<>(); + private static final int[] LOCK_BUTTON_IDS = new int[] { + R.id.lock_pattern_size_3, + R.id.lock_pattern_size_4, + R.id.lock_pattern_size_5, + R.id.lock_pattern_size_6 + }; + /** Number of calls to {@link #notifyUser()} to ignore before notifying. */ private int mNotificationCountdown = 0; /** Number of calls to {@link #notifyUser()} before we release the wakelock */ @@ -206,8 +216,7 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList mLockPatternView.removeCallbacks(mClearPatternRunnable); mLockPatternView.postDelayed(mClearPatternRunnable, RIGHT_PATTERN_CLEAR_TIMEOUT_MS); } - final TextView status = (TextView) findViewById(R.id.status); - status.setText(R.string.starting_android); + mStatusText.setText(R.string.starting_android); hide(R.id.passwordEntry); hide(R.id.switch_ime_button); hide(R.id.lockPattern); @@ -245,8 +254,7 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList } private void beginAttempt() { - final TextView status = (TextView) findViewById(R.id.status); - status.setText(R.string.checking_decryption); + mStatusText.setText(R.string.checking_decryption); } private void handleBadAttempt(Integer failedAttempts) { @@ -262,14 +270,12 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList // at this point. cooldown(); } else { - final TextView status = (TextView) findViewById(R.id.status); - int remainingAttempts = MAX_FAILED_ATTEMPTS - failedAttempts; if (remainingAttempts < COOL_DOWN_ATTEMPTS) { CharSequence warningTemplate = getText(R.string.crypt_keeper_warn_wipe); CharSequence warning = TextUtils.expandTemplate(warningTemplate, Integer.toString(remainingAttempts)); - status.setText(warning); + mStatusText.setText(warning); } else { int passwordType = StorageManager.CRYPT_TYPE_PASSWORD; try { @@ -280,17 +286,18 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList } if (passwordType == StorageManager.CRYPT_TYPE_PIN) { - status.setText(R.string.cryptkeeper_wrong_pin); + mStatusText.setText(R.string.cryptkeeper_wrong_pin); } else if (passwordType == StorageManager.CRYPT_TYPE_PATTERN) { - status.setText(R.string.cryptkeeper_wrong_pattern); + mStatusText.setText(R.string.cryptkeeper_wrong_pattern); } else { - status.setText(R.string.cryptkeeper_wrong_password); + mStatusText.setText(R.string.cryptkeeper_wrong_password); } } if (mLockPatternView != null) { mLockPatternView.setDisplayMode(DisplayMode.Wrong); mLockPatternView.setEnabled(true); + setPatternButtonsEnabled(true); } // Reenable the password entry @@ -533,8 +540,7 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList setContentView(R.layout.crypt_keeper_password_entry); mStatusString = R.string.enter_password; } - final TextView status = (TextView) findViewById(R.id.status); - status.setText(mStatusString); + mStatusText.setText(mStatusString); final TextView ownerInfo = (TextView) findViewById(R.id.owner_info); ownerInfo.setText(owner_info); @@ -593,6 +599,12 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList } } + @Override + public void setContentView(int layoutResID) { + super.setContentView(layoutResID); + mStatusText = (TextView) findViewById(R.id.status); + } + /** * Start encrypting the device. */ @@ -705,9 +717,8 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList // Will happen if no time etc - show percentage } - final TextView tv = (TextView) findViewById(R.id.status); - if (tv != null) { - tv.setText(TextUtils.expandTemplate(status, progress)); + if (mStatusText != null) { + mStatusText.setText(TextUtils.expandTemplate(status, progress)); } // Check the progress every 1 seconds @@ -724,16 +735,12 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList mPasswordEntry.setEnabled(false); } - final ViewGroup sizes = (ViewGroup) findViewById(R.id.status); if (mLockPatternView != null) { mLockPatternView.setEnabled(false); - if (sizes != null) { - sizes.setEnabled(false); - } + setPatternButtonsEnabled(false); } - final TextView status = (TextView) findViewById(R.id.status); - status.setText(R.string.crypt_keeper_force_power_cycle); + mStatusText.setText(R.string.crypt_keeper_force_power_cycle); } /** @@ -758,11 +765,13 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList @Override public void onPatternStart() { + setPatternButtonsEnabled(false); mLockPatternView.removeCallbacks(mClearPatternRunnable); } @Override public void onPatternCleared() { + setPatternButtonsEnabled(true); } @Override @@ -794,10 +803,18 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList mPasswordEntry.addTextChangedListener(this); } + mLockPatternButtons.clear(); // Pattern case mLockPatternView = (LockPatternView) findViewById(R.id.lockPattern); if (mLockPatternView != null) { mLockPatternView.setOnPatternListener(mChooseNewLockPatternListener); + for (int id : LOCK_BUTTON_IDS) { + Button btn = (Button) findViewById(id); + if (btn != null) { + btn.setOnClickListener(this); + mLockPatternButtons.add(btn); + } + } } // Disable the Emergency call button if the device has no voice telephone capability @@ -1078,7 +1095,11 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList PackageManager.DONT_KILL_APP); } - public void onPatternButtonClick(View v) { + @Override + public void onClick(View v) { + if (mLockPatternView == null || !mLockPatternView.isEnabled()) { + return; + } byte size; switch (v.getId()) { default: @@ -1095,11 +1116,17 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList size = 6; break; } - if (mLockPatternView != null) { - setContentView(R.layout.crypt_keeper_pattern_entry); - passwordEntryInit(); - mLockPatternView.setLockPatternSize(size); - mLockPatternView.postInvalidate(); + setContentView(R.layout.crypt_keeper_pattern_entry); + passwordEntryInit(); + + mStatusText.setText(mStatusString = R.string.enter_pattern); + mLockPatternView.setLockPatternSize(size); + mLockPatternView.postInvalidate(); + } + + private void setPatternButtonsEnabled(boolean enabled) { + for (Button btn : mLockPatternButtons) { + btn.setEnabled(enabled); } } } |