diff options
author | Jason parks <jparks@google.com> | 2011-03-01 10:17:40 -0600 |
---|---|---|
committer | Jason parks <jparks@google.com> | 2011-03-01 10:17:57 -0600 |
commit | 06c5ff4a46686d3f599e40df0768177d3d88913c (patch) | |
tree | 65acbb2eee4302bdf1dfebcc2bf7a8dc5c45d24e | |
parent | e18897bc2242110782fca135e9e47fcdb5839d64 (diff) | |
download | packages_apps_Settings-06c5ff4a46686d3f599e40df0768177d3d88913c.tar.gz packages_apps_Settings-06c5ff4a46686d3f599e40df0768177d3d88913c.tar.bz2 packages_apps_Settings-06c5ff4a46686d3f599e40df0768177d3d88913c.zip |
Partial fix for Bug 3495575.
Move the decrypt attempt to a AsyncTask. This will
unblock the UI thread in order for the device to
still be "responsive". There is still the issue of
decrypt taking 3+ seconds before it returns to. The
delay is still there becfore the fade but the text
field is now cleared and you can tap on keys.
Bug: 3495575
Change-Id: Icec82e83d3a09b3c0f856aa77870925fc8469625
-rw-r--r-- | src/com/android/settings/CryptKeeper.java | 83 |
1 files changed, 50 insertions, 33 deletions
diff --git a/src/com/android/settings/CryptKeeper.java b/src/com/android/settings/CryptKeeper.java index 0374ba646..edf00d525 100644 --- a/src/com/android/settings/CryptKeeper.java +++ b/src/com/android/settings/CryptKeeper.java @@ -27,6 +27,7 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.Rect; import android.inputmethodservice.KeyboardView; +import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; @@ -63,6 +64,7 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList private int mCooldown; PowerManager.WakeLock mWakeLock; + private EditText mPasswordEntry; /** * Used to propagate state through configuration changes (e.g. screen rotation) @@ -115,6 +117,44 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList } } + private class DecryptTask extends AsyncTask<String, Void, Integer> { + @Override + protected Integer doInBackground(String... params) { + IMountService service = getMountService(); + try { + return service.decryptStorage(params[0]); + } catch (Exception e) { + Log.e(TAG, "Error while decrypting...", e); + return -1; + } + } + + @Override + protected void onPostExecute(Integer failedAttempts) { + if (failedAttempts == 0) { + // The password was entered successfully. Start the Blank activity + // so this activity animates to black before the devices starts. Note + // It has 1 second to complete the animation or it will be frozen + // until the boot animation comes back up. + Intent intent = new Intent(CryptKeeper.this, Blank.class); + finish(); + startActivity(intent); + } 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) { + mCooldown = COOL_DOWN_INTERVAL; + cooldown(); + } else { + TextView tv = (TextView) findViewById(R.id.status); + tv.setText(R.string.try_again); + tv.setVisibility(View.VISIBLE); + + // Reenable the password entry + mPasswordEntry.setEnabled(true); + } + } + } private Handler mHandler = new Handler() { @Override @@ -281,8 +321,7 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList if (mCooldown <= 0) { // Re-enable the password entry - EditText passwordEntry = (EditText) findViewById(R.id.passwordEntry); - passwordEntry.setEnabled(true); + mPasswordEntry.setEnabled(true); tv.setVisibility(View.GONE); } else { @@ -298,13 +337,13 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList } private void passwordEntryInit() { - TextView passwordEntry = (TextView) findViewById(R.id.passwordEntry); - passwordEntry.setOnEditorActionListener(this); + mPasswordEntry = (EditText) findViewById(R.id.passwordEntry); + mPasswordEntry.setOnEditorActionListener(this); KeyboardView keyboardView = (PasswordEntryKeyboardView) findViewById(R.id.keyboard); PasswordEntryKeyboardHelper keyboardHelper = new PasswordEntryKeyboardHelper(this, - keyboardView, passwordEntry, false); + keyboardView, mPasswordEntry, false); keyboardHelper.setKeyboardMode(PasswordEntryKeyboardHelper.KEYBOARD_MODE_ALPHA); } @@ -329,34 +368,12 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList // Now that we have the password clear the password field. v.setText(null); - IMountService service = getMountService(); - try { - int failedAttempts = service.decryptStorage(password); - - if (failedAttempts == 0) { - // The password was entered successfully. Start the Blank activity - // so this activity animates to black before the devices starts. Note - // It has 1 second to complete the animation or it will be frozen - // until the boot animation comes back up. - Intent intent = new Intent(this, Blank.class); - finish(); - startActivity(intent); - } 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) { - mCooldown = COOL_DOWN_INTERVAL; - EditText passwordEntry = (EditText) findViewById(R.id.passwordEntry); - passwordEntry.setEnabled(false); - cooldown(); - } else { - TextView tv = (TextView) findViewById(R.id.status); - tv.setText(R.string.try_again); - tv.setVisibility(View.VISIBLE); - } - } catch (Exception e) { - Log.e(TAG, "Error while decrypting...", e); - } + // Disable the password entry while checking the password. This + // we either be reenabled if the password was wrong or after the + // cooldown period. + mPasswordEntry.setEnabled(false); + + new DecryptTask().execute(password); return true; } |