Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.settings; |
| 18 | |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 19 | import android.app.Activity; |
| 20 | import android.app.StatusBarManager; |
| 21 | import android.content.ComponentName; |
| 22 | import android.content.Context; |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 23 | import android.content.Intent; |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 24 | import android.content.pm.PackageManager; |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 25 | import android.media.AudioManager; |
Jason parks | 06c5ff4 | 2011-03-01 10:17:40 -0600 | [diff] [blame] | 26 | import android.os.AsyncTask; |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 27 | import android.os.Bundle; |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 28 | import android.os.Handler; |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 29 | import android.os.IBinder; |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 30 | import android.os.Message; |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 31 | import android.os.PowerManager; |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 32 | import android.os.RemoteException; |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 33 | import android.os.ServiceManager; |
| 34 | import android.os.SystemProperties; |
| 35 | import android.os.storage.IMountService; |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 36 | import android.telephony.TelephonyManager; |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 37 | import android.text.TextUtils; |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 38 | import android.util.Log; |
| 39 | import android.view.KeyEvent; |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 40 | import android.view.View; |
| 41 | import android.view.View.OnClickListener; |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 42 | import android.view.inputmethod.EditorInfo; |
Ben Komalo | 9fcb6a7 | 2011-08-26 14:40:18 -0700 | [diff] [blame] | 43 | import android.view.inputmethod.InputMethodInfo; |
Jason parks | 75c085e | 2011-02-10 14:03:47 -0600 | [diff] [blame] | 44 | import android.view.inputmethod.InputMethodManager; |
Ben Komalo | 9fcb6a7 | 2011-08-26 14:40:18 -0700 | [diff] [blame] | 45 | import android.view.inputmethod.InputMethodSubtype; |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 46 | import android.widget.Button; |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 47 | import android.widget.EditText; |
| 48 | import android.widget.ProgressBar; |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 49 | import android.widget.TextView; |
| 50 | |
Ben Komalo | 91a2f05 | 2011-08-16 17:48:25 -0700 | [diff] [blame] | 51 | import com.android.internal.telephony.ITelephony; |
Ben Komalo | 9fcb6a7 | 2011-08-26 14:40:18 -0700 | [diff] [blame] | 52 | |
| 53 | import java.util.List; |
Ben Komalo | 91a2f05 | 2011-08-16 17:48:25 -0700 | [diff] [blame] | 54 | |
| 55 | /** |
| 56 | * Settings screens to show the UI flows for encrypting/decrypting the device. |
| 57 | * |
| 58 | * This may be started via adb for debugging the UI layout, without having to go through |
| 59 | * encryption flows everytime. It should be noted that starting the activity in this manner |
| 60 | * is only useful for verifying UI-correctness - the behavior will not be identical. |
| 61 | * <pre> |
| 62 | * $ adb shell pm enable com.android.settings/.CryptKeeper |
| 63 | * $ adb shell am start \ |
| 64 | * -e "com.android.settings.CryptKeeper.DEBUG_FORCE_VIEW" "progress" \ |
| 65 | * -n com.android.settings/.CryptKeeper |
| 66 | * </pre> |
| 67 | */ |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 68 | public class CryptKeeper extends Activity implements TextView.OnEditorActionListener { |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 69 | private static final String TAG = "CryptKeeper"; |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 70 | |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 71 | private static final String DECRYPT_STATE = "trigger_restart_framework"; |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 72 | /** Message sent to us to indicate encryption update progress. */ |
| 73 | private static final int MESSAGE_UPDATE_PROGRESS = 1; |
| 74 | /** Message sent to us to cool-down (waste user's time between password attempts) */ |
| 75 | private static final int MESSAGE_COOLDOWN = 2; |
| 76 | /** Message sent to us to indicate alerting the user that we are waiting for password entry */ |
| 77 | private static final int MESSAGE_NOTIFY = 3; |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 78 | |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 79 | // Constants used to control policy. |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 80 | private static final int MAX_FAILED_ATTEMPTS = 30; |
| 81 | private static final int COOL_DOWN_ATTEMPTS = 10; |
| 82 | private static final int COOL_DOWN_INTERVAL = 30; // 30 seconds |
| 83 | |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 84 | // Intent action for launching the Emergency Dialer activity. |
| 85 | static final String ACTION_EMERGENCY_DIAL = "com.android.phone.EmergencyDialer.DIAL"; |
| 86 | |
Ben Komalo | 91a2f05 | 2011-08-16 17:48:25 -0700 | [diff] [blame] | 87 | // Debug Intent extras so that this Activity may be started via adb for debugging UI layouts |
| 88 | private static final String EXTRA_FORCE_VIEW = |
| 89 | "com.android.settings.CryptKeeper.DEBUG_FORCE_VIEW"; |
| 90 | private static final String FORCE_VIEW_PROGRESS = "progress"; |
Ben Komalo | 91a2f05 | 2011-08-16 17:48:25 -0700 | [diff] [blame] | 91 | private static final String FORCE_VIEW_ERROR = "error"; |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 92 | private static final String FORCE_VIEW_PASSWORD = "password"; |
Ben Komalo | 91a2f05 | 2011-08-16 17:48:25 -0700 | [diff] [blame] | 93 | |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 94 | /** When encryption is detected, this flag indicates whether or not we've checked for errors. */ |
Ben Komalo | 0e66609 | 2011-09-01 15:42:00 -0700 | [diff] [blame] | 95 | private boolean mValidationComplete; |
Ben Komalo | d4758ef | 2011-09-08 14:36:08 -0700 | [diff] [blame] | 96 | private boolean mValidationRequested; |
Ben Komalo | 0e66609 | 2011-09-01 15:42:00 -0700 | [diff] [blame] | 97 | /** A flag to indicate that the volume is in a bad state (e.g. partially encrypted). */ |
| 98 | private boolean mEncryptionGoneBad; |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 99 | /** A flag to indicate when the back event should be ignored */ |
| 100 | private boolean mIgnoreBack = false; |
Andy Stadler | 1499740 | 2011-02-01 15:34:59 -0800 | [diff] [blame] | 101 | private int mCooldown; |
| 102 | PowerManager.WakeLock mWakeLock; |
Jason parks | 06c5ff4 | 2011-03-01 10:17:40 -0600 | [diff] [blame] | 103 | private EditText mPasswordEntry; |
Andy Stadler | 1499740 | 2011-02-01 15:34:59 -0800 | [diff] [blame] | 104 | |
| 105 | /** |
| 106 | * Used to propagate state through configuration changes (e.g. screen rotation) |
| 107 | */ |
| 108 | private static class NonConfigurationInstanceState { |
| 109 | final PowerManager.WakeLock wakelock; |
| 110 | |
| 111 | NonConfigurationInstanceState(PowerManager.WakeLock _wakelock) { |
| 112 | wakelock = _wakelock; |
| 113 | } |
| 114 | } |
| 115 | |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 116 | /** |
| 117 | * Activity used to fade the screen to black after the password is entered. |
| 118 | */ |
Vikram Aggarwal | 9f55ae2 | 2012-04-02 13:36:35 -0700 | [diff] [blame] | 119 | public static class FadeToBlack extends Activity { |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 120 | @Override |
| 121 | public void onCreate(Bundle savedInstanceState) { |
| 122 | super.onCreate(savedInstanceState); |
| 123 | setContentView(R.layout.crypt_keeper_blank); |
| 124 | } |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 125 | /** Ignore all back events. */ |
| 126 | @Override |
| 127 | public void onBackPressed() { |
| 128 | return; |
| 129 | } |
Jason parks | f1dbf55 | 2011-01-24 16:19:28 -0600 | [diff] [blame] | 130 | } |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 131 | |
Jason parks | 06c5ff4 | 2011-03-01 10:17:40 -0600 | [diff] [blame] | 132 | private class DecryptTask extends AsyncTask<String, Void, Integer> { |
| 133 | @Override |
| 134 | protected Integer doInBackground(String... params) { |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 135 | final IMountService service = getMountService(); |
Jason parks | 06c5ff4 | 2011-03-01 10:17:40 -0600 | [diff] [blame] | 136 | try { |
| 137 | return service.decryptStorage(params[0]); |
| 138 | } catch (Exception e) { |
| 139 | Log.e(TAG, "Error while decrypting...", e); |
| 140 | return -1; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | @Override |
| 145 | protected void onPostExecute(Integer failedAttempts) { |
| 146 | if (failedAttempts == 0) { |
| 147 | // The password was entered successfully. Start the Blank activity |
| 148 | // so this activity animates to black before the devices starts. Note |
| 149 | // It has 1 second to complete the animation or it will be frozen |
| 150 | // until the boot animation comes back up. |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 151 | Intent intent = new Intent(CryptKeeper.this, FadeToBlack.class); |
Jason parks | 06c5ff4 | 2011-03-01 10:17:40 -0600 | [diff] [blame] | 152 | finish(); |
| 153 | startActivity(intent); |
| 154 | } else if (failedAttempts == MAX_FAILED_ATTEMPTS) { |
| 155 | // Factory reset the device. |
| 156 | sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR")); |
| 157 | } else if ((failedAttempts % COOL_DOWN_ATTEMPTS) == 0) { |
| 158 | mCooldown = COOL_DOWN_INTERVAL; |
| 159 | cooldown(); |
| 160 | } else { |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 161 | final TextView status = (TextView) findViewById(R.id.status); |
| 162 | status.setText(R.string.try_again); |
| 163 | status.setVisibility(View.VISIBLE); |
Jason parks | 06c5ff4 | 2011-03-01 10:17:40 -0600 | [diff] [blame] | 164 | |
| 165 | // Reenable the password entry |
| 166 | mPasswordEntry.setEnabled(true); |
| 167 | } |
| 168 | } |
| 169 | } |
Jason parks | 75c085e | 2011-02-10 14:03:47 -0600 | [diff] [blame] | 170 | |
Ben Komalo | 0e66609 | 2011-09-01 15:42:00 -0700 | [diff] [blame] | 171 | private class ValidationTask extends AsyncTask<Void, Void, Boolean> { |
| 172 | @Override |
| 173 | protected Boolean doInBackground(Void... params) { |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 174 | final IMountService service = getMountService(); |
Ben Komalo | 0e66609 | 2011-09-01 15:42:00 -0700 | [diff] [blame] | 175 | try { |
Ben Komalo | d4758ef | 2011-09-08 14:36:08 -0700 | [diff] [blame] | 176 | Log.d(TAG, "Validating encryption state."); |
Ben Komalo | 0e66609 | 2011-09-01 15:42:00 -0700 | [diff] [blame] | 177 | int state = service.getEncryptionState(); |
| 178 | if (state == IMountService.ENCRYPTION_STATE_NONE) { |
| 179 | Log.w(TAG, "Unexpectedly in CryptKeeper even though there is no encryption."); |
| 180 | return true; // Unexpected, but fine, I guess... |
| 181 | } |
| 182 | return state == IMountService.ENCRYPTION_STATE_OK; |
| 183 | } catch (RemoteException e) { |
| 184 | Log.w(TAG, "Unable to get encryption state properly"); |
| 185 | return true; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | @Override |
| 190 | protected void onPostExecute(Boolean result) { |
| 191 | mValidationComplete = true; |
| 192 | if (Boolean.FALSE.equals(result)) { |
| 193 | Log.w(TAG, "Incomplete, or corrupted encryption detected. Prompting user to wipe."); |
| 194 | mEncryptionGoneBad = true; |
Ben Komalo | d4758ef | 2011-09-08 14:36:08 -0700 | [diff] [blame] | 195 | } else { |
| 196 | Log.d(TAG, "Encryption state validated. Proceeding to configure UI"); |
Ben Komalo | 0e66609 | 2011-09-01 15:42:00 -0700 | [diff] [blame] | 197 | } |
| 198 | setupUi(); |
| 199 | } |
| 200 | } |
| 201 | |
Ben Komalo | 91a2f05 | 2011-08-16 17:48:25 -0700 | [diff] [blame] | 202 | private final Handler mHandler = new Handler() { |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 203 | @Override |
| 204 | public void handleMessage(Message msg) { |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 205 | switch (msg.what) { |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 206 | case MESSAGE_UPDATE_PROGRESS: |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 207 | updateProgress(); |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 208 | break; |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 209 | |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 210 | case MESSAGE_COOLDOWN: |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 211 | cooldown(); |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 212 | break; |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 213 | |
| 214 | case MESSAGE_NOTIFY: |
| 215 | notifyUser(); |
| 216 | break; |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | }; |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 220 | |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 221 | private AudioManager mAudioManager; |
| 222 | |
Ben Komalo | 91a2f05 | 2011-08-16 17:48:25 -0700 | [diff] [blame] | 223 | /** @return whether or not this Activity was started for debugging the UI only. */ |
| 224 | private boolean isDebugView() { |
| 225 | return getIntent().hasExtra(EXTRA_FORCE_VIEW); |
| 226 | } |
| 227 | |
| 228 | /** @return whether or not this Activity was started for debugging the specific UI view only. */ |
| 229 | private boolean isDebugView(String viewType /* non-nullable */) { |
| 230 | return viewType.equals(getIntent().getStringExtra(EXTRA_FORCE_VIEW)); |
| 231 | } |
| 232 | |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 233 | /** |
| 234 | * Notify the user that we are awaiting input. Currently this sends an audio alert. |
| 235 | */ |
| 236 | private void notifyUser() { |
| 237 | Log.d(TAG, "Notifying user that we are waiting for input..."); |
| 238 | if (mAudioManager != null) { |
| 239 | try { |
| 240 | // Play the standard keypress sound at full volume. This should be available on |
| 241 | // every device. We cannot play a ringtone here because media services aren't |
| 242 | // available yet. A DTMF-style tone is too soft to be noticed, and might not exist |
| 243 | // on tablet devices. The idea is to alert the user that something is needed: this |
| 244 | // does not have to be pleasing. |
| 245 | mAudioManager.playSoundEffect(AudioManager.FX_KEYPRESS_STANDARD, 100); |
| 246 | } catch (Exception e) { |
| 247 | Log.w(TAG, "notifyUser: Exception while playing sound: " + e); |
| 248 | } |
| 249 | } |
Vikram Aggarwal | 86b9393 | 2012-05-01 16:46:06 -0700 | [diff] [blame] | 250 | // Notify the user again in 5 seconds. |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 251 | mHandler.removeMessages(MESSAGE_NOTIFY); |
Vikram Aggarwal | 86b9393 | 2012-05-01 16:46:06 -0700 | [diff] [blame] | 252 | mHandler.sendEmptyMessageDelayed(MESSAGE_NOTIFY, 5 * 1000); |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Ignore back events after the user has entered the decrypt screen and while the device is |
| 257 | * encrypting. |
| 258 | */ |
| 259 | @Override |
| 260 | public void onBackPressed() { |
| 261 | if (mIgnoreBack) |
| 262 | return; |
| 263 | super.onBackPressed(); |
| 264 | } |
| 265 | |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 266 | @Override |
| 267 | public void onCreate(Bundle savedInstanceState) { |
| 268 | super.onCreate(savedInstanceState); |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 269 | |
Andy Stadler | 9597406 | 2011-02-01 17:35:20 -0800 | [diff] [blame] | 270 | // If we are not encrypted or encrypting, get out quickly. |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 271 | final String state = SystemProperties.get("vold.decrypt"); |
Ben Komalo | 91a2f05 | 2011-08-16 17:48:25 -0700 | [diff] [blame] | 272 | if (!isDebugView() && ("".equals(state) || DECRYPT_STATE.equals(state))) { |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 273 | // Disable the crypt keeper. |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 274 | PackageManager pm = getPackageManager(); |
| 275 | ComponentName name = new ComponentName(this, CryptKeeper.class); |
Dianne Hackborn | 140f6c6 | 2011-10-16 11:49:00 -0700 | [diff] [blame] | 276 | pm.setComponentEnabledSetting(name, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, |
| 277 | PackageManager.DONT_KILL_APP); |
| 278 | // Typically CryptKeeper is launched as the home app. We didn't |
Dianne Hackborn | 644fa42 | 2011-10-18 13:38:03 -0700 | [diff] [blame] | 279 | // want to be running, so need to finish this activity. We can count |
| 280 | // on the activity manager re-launching the new home app upon finishing |
| 281 | // this one, since this will leave the activity stack empty. |
Dianne Hackborn | 140f6c6 | 2011-10-16 11:49:00 -0700 | [diff] [blame] | 282 | // NOTE: This is really grungy. I think it would be better for the |
| 283 | // activity manager to explicitly launch the crypt keeper instead of |
| 284 | // home in the situation where we need to decrypt the device |
| 285 | finish(); |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 286 | return; |
| 287 | } |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 288 | |
Vikram Aggarwal | b96b35a | 2012-05-01 11:09:39 -0700 | [diff] [blame] | 289 | // Disable the status bar, but do NOT disable back because the user needs a way to go |
| 290 | // from keyboard settings and back to the password screen. |
Jason parks | 39f1e04 | 2011-01-20 23:29:28 -0600 | [diff] [blame] | 291 | StatusBarManager sbm = (StatusBarManager) getSystemService(Context.STATUS_BAR_SERVICE); |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 292 | sbm.disable(StatusBarManager.DISABLE_EXPAND |
| 293 | | StatusBarManager.DISABLE_NOTIFICATION_ICONS |
Jason parks | 39f1e04 | 2011-01-20 23:29:28 -0600 | [diff] [blame] | 294 | | StatusBarManager.DISABLE_NOTIFICATION_ALERTS |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 295 | | StatusBarManager.DISABLE_SYSTEM_INFO |
Daniel Sandler | 4d2bfd1 | 2011-10-12 15:34:23 -0400 | [diff] [blame] | 296 | | StatusBarManager.DISABLE_HOME |
Vikram Aggarwal | b96b35a | 2012-05-01 11:09:39 -0700 | [diff] [blame] | 297 | | StatusBarManager.DISABLE_RECENT); |
Andy Stadler | 1499740 | 2011-02-01 15:34:59 -0800 | [diff] [blame] | 298 | |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 299 | mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); |
Andy Stadler | 1499740 | 2011-02-01 15:34:59 -0800 | [diff] [blame] | 300 | // Check for (and recover) retained instance data |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 301 | final Object lastInstance = getLastNonConfigurationInstance(); |
Andy Stadler | 1499740 | 2011-02-01 15:34:59 -0800 | [diff] [blame] | 302 | if (lastInstance instanceof NonConfigurationInstanceState) { |
| 303 | NonConfigurationInstanceState retained = (NonConfigurationInstanceState) lastInstance; |
| 304 | mWakeLock = retained.wakelock; |
Ben Komalo | 0460675 | 2011-08-18 14:50:26 -0700 | [diff] [blame] | 305 | Log.d(TAG, "Restoring wakelock from NonConfigurationInstanceState"); |
Andy Stadler | 1499740 | 2011-02-01 15:34:59 -0800 | [diff] [blame] | 306 | } |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 307 | } |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 308 | |
Andy Stadler | 9597406 | 2011-02-01 17:35:20 -0800 | [diff] [blame] | 309 | /** |
| 310 | * Note, we defer the state check and screen setup to onStart() because this will be |
| 311 | * re-run if the user clicks the power button (sleeping/waking the screen), and this is |
| 312 | * especially important if we were to lose the wakelock for any reason. |
| 313 | */ |
| 314 | @Override |
| 315 | public void onStart() { |
| 316 | super.onStart(); |
Ben Komalo | d4758ef | 2011-09-08 14:36:08 -0700 | [diff] [blame] | 317 | setupUi(); |
Ben Komalo | 0e66609 | 2011-09-01 15:42:00 -0700 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | /** |
| 321 | * Initializes the UI based on the current state of encryption. |
| 322 | * This is idempotent - calling repeatedly will simply re-initialize the UI. |
| 323 | */ |
| 324 | private void setupUi() { |
| 325 | if (mEncryptionGoneBad || isDebugView(FORCE_VIEW_ERROR)) { |
| 326 | setContentView(R.layout.crypt_keeper_progress); |
| 327 | showFactoryReset(); |
| 328 | return; |
| 329 | } |
| 330 | |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 331 | final String progress = SystemProperties.get("vold.encrypt_progress"); |
Ben Komalo | 0e66609 | 2011-09-01 15:42:00 -0700 | [diff] [blame] | 332 | if (!"".equals(progress) || isDebugView(FORCE_VIEW_PROGRESS)) { |
Andy Stadler | 9597406 | 2011-02-01 17:35:20 -0800 | [diff] [blame] | 333 | setContentView(R.layout.crypt_keeper_progress); |
| 334 | encryptionProgressInit(); |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 335 | } else if (mValidationComplete || isDebugView(FORCE_VIEW_PASSWORD)) { |
Andy Stadler | 9597406 | 2011-02-01 17:35:20 -0800 | [diff] [blame] | 336 | setContentView(R.layout.crypt_keeper_password_entry); |
| 337 | passwordEntryInit(); |
Ben Komalo | d4758ef | 2011-09-08 14:36:08 -0700 | [diff] [blame] | 338 | } else if (!mValidationRequested) { |
| 339 | // We're supposed to be encrypted, but no validation has been done. |
| 340 | new ValidationTask().execute((Void[]) null); |
| 341 | mValidationRequested = true; |
Andy Stadler | 9597406 | 2011-02-01 17:35:20 -0800 | [diff] [blame] | 342 | } |
| 343 | } |
| 344 | |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 345 | @Override |
| 346 | public void onStop() { |
| 347 | super.onStop(); |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 348 | mHandler.removeMessages(MESSAGE_COOLDOWN); |
| 349 | mHandler.removeMessages(MESSAGE_UPDATE_PROGRESS); |
| 350 | mHandler.removeMessages(MESSAGE_NOTIFY); |
Andy Stadler | 1499740 | 2011-02-01 15:34:59 -0800 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | /** |
| 354 | * Reconfiguring, so propagate the wakelock to the next instance. This runs between onStop() |
| 355 | * and onDestroy() and only if we are changing configuration (e.g. rotation). Also clears |
| 356 | * mWakeLock so the subsequent call to onDestroy does not release it. |
| 357 | */ |
| 358 | @Override |
| 359 | public Object onRetainNonConfigurationInstance() { |
| 360 | NonConfigurationInstanceState state = new NonConfigurationInstanceState(mWakeLock); |
Ben Komalo | 0460675 | 2011-08-18 14:50:26 -0700 | [diff] [blame] | 361 | Log.d(TAG, "Handing wakelock off to NonConfigurationInstanceState"); |
Andy Stadler | 1499740 | 2011-02-01 15:34:59 -0800 | [diff] [blame] | 362 | mWakeLock = null; |
| 363 | return state; |
| 364 | } |
| 365 | |
| 366 | @Override |
| 367 | public void onDestroy() { |
| 368 | super.onDestroy(); |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 369 | |
| 370 | if (mWakeLock != null) { |
Ben Komalo | 0460675 | 2011-08-18 14:50:26 -0700 | [diff] [blame] | 371 | Log.d(TAG, "Releasing and destroying wakelock"); |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 372 | mWakeLock.release(); |
| 373 | mWakeLock = null; |
| 374 | } |
| 375 | } |
| 376 | |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 377 | /** |
| 378 | * Start encrypting the device. |
| 379 | */ |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 380 | private void encryptionProgressInit() { |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 381 | // Accquire a partial wakelock to prevent the device from sleeping. Note |
| 382 | // we never release this wakelock as we will be restarted after the device |
| 383 | // is encrypted. |
Ben Komalo | 0460675 | 2011-08-18 14:50:26 -0700 | [diff] [blame] | 384 | Log.d(TAG, "Encryption progress screen initializing."); |
Ben Komalo | 9ee164f | 2011-09-21 10:40:50 -0700 | [diff] [blame] | 385 | if (mWakeLock == null) { |
Ben Komalo | 0460675 | 2011-08-18 14:50:26 -0700 | [diff] [blame] | 386 | Log.d(TAG, "Acquiring wakelock."); |
| 387 | PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); |
| 388 | mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, TAG); |
| 389 | mWakeLock.acquire(); |
| 390 | } |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 391 | |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 392 | ((ProgressBar) findViewById(R.id.progress_bar)).setIndeterminate(true); |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 393 | // Ignore all back presses from now, both hard and soft keys. |
| 394 | mIgnoreBack = true; |
| 395 | // Start the first run of progress manually. This method sets up messages to occur at |
| 396 | // repeated intervals. |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 397 | updateProgress(); |
| 398 | } |
| 399 | |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 400 | private void showFactoryReset() { |
| 401 | // Hide the encryption-bot to make room for the "factory reset" button |
| 402 | findViewById(R.id.encroid).setVisibility(View.GONE); |
| 403 | |
| 404 | // Show the reset button, failure text, and a divider |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 405 | final Button button = (Button) findViewById(R.id.factory_reset); |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 406 | button.setVisibility(View.VISIBLE); |
| 407 | button.setOnClickListener(new OnClickListener() { |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 408 | @Override |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 409 | public void onClick(View v) { |
| 410 | // Factory reset the device. |
| 411 | sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR")); |
| 412 | } |
| 413 | }); |
| 414 | |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 415 | // Alert the user of the failure. |
| 416 | ((TextView) findViewById(R.id.title)).setText(R.string.crypt_keeper_failed_title); |
| 417 | ((TextView) findViewById(R.id.status)).setText(R.string.crypt_keeper_failed_summary); |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 418 | |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 419 | final View view = findViewById(R.id.bottom_divider); |
| 420 | // TODO(viki): Why would the bottom divider be missing in certain layouts? Investigate. |
Ben Komalo | f0104df | 2011-08-16 17:48:42 -0700 | [diff] [blame] | 421 | if (view != null) { |
| 422 | view.setVisibility(View.VISIBLE); |
| 423 | } |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 424 | } |
| 425 | |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 426 | private void updateProgress() { |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 427 | final String state = SystemProperties.get("vold.encrypt_progress"); |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 428 | |
Ben Komalo | 0e66609 | 2011-09-01 15:42:00 -0700 | [diff] [blame] | 429 | if ("error_partially_encrypted".equals(state)) { |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 430 | showFactoryReset(); |
| 431 | return; |
| 432 | } |
| 433 | |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 434 | int progress = 0; |
| 435 | try { |
Ben Komalo | 91a2f05 | 2011-08-16 17:48:25 -0700 | [diff] [blame] | 436 | // Force a 50% progress state when debugging the view. |
| 437 | progress = isDebugView() ? 50 : Integer.parseInt(state); |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 438 | } catch (Exception e) { |
| 439 | Log.w(TAG, "Error parsing progress: " + e.toString()); |
| 440 | } |
| 441 | |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 442 | final CharSequence status = getText(R.string.crypt_keeper_setup_description); |
Ben Komalo | 0460675 | 2011-08-18 14:50:26 -0700 | [diff] [blame] | 443 | Log.v(TAG, "Encryption progress: " + progress); |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 444 | final TextView tv = (TextView) findViewById(R.id.status); |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 445 | if (tv != null) { |
| 446 | tv.setText(TextUtils.expandTemplate(status, Integer.toString(progress))); |
| 447 | } |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 448 | // Check the progress every 5 seconds |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 449 | mHandler.removeMessages(MESSAGE_UPDATE_PROGRESS); |
| 450 | mHandler.sendEmptyMessageDelayed(MESSAGE_UPDATE_PROGRESS, 5000); |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 451 | } |
| 452 | |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 453 | /** Disable password input for a while to force the user to waste time between retries */ |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 454 | private void cooldown() { |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 455 | final TextView status = (TextView) findViewById(R.id.status); |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 456 | |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 457 | if (mCooldown <= 0) { |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 458 | // Re-enable the password entry and back presses. |
Jason parks | 06c5ff4 | 2011-03-01 10:17:40 -0600 | [diff] [blame] | 459 | mPasswordEntry.setEnabled(true); |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 460 | mIgnoreBack = false; |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 461 | status.setVisibility(View.GONE); |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 462 | } else { |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 463 | CharSequence template = getText(R.string.crypt_keeper_cooldown); |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 464 | status.setText(TextUtils.expandTemplate(template, Integer.toString(mCooldown))); |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 465 | |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 466 | status.setVisibility(View.VISIBLE); |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 467 | |
| 468 | mCooldown--; |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 469 | mHandler.removeMessages(MESSAGE_COOLDOWN); |
| 470 | mHandler.sendEmptyMessageDelayed(MESSAGE_COOLDOWN, 1000); // Tick every second |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 471 | } |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 472 | } |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 473 | |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 474 | private void passwordEntryInit() { |
Jason parks | 06c5ff4 | 2011-03-01 10:17:40 -0600 | [diff] [blame] | 475 | mPasswordEntry = (EditText) findViewById(R.id.passwordEntry); |
| 476 | mPasswordEntry.setOnEditorActionListener(this); |
Ben Komalo | 9fcb6a7 | 2011-08-26 14:40:18 -0700 | [diff] [blame] | 477 | mPasswordEntry.requestFocus(); |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 478 | |
Vikram Aggarwal | c62d321 | 2012-05-02 16:29:10 -0700 | [diff] [blame^] | 479 | // Disable the Emergency call button if the device has no voice telephone capability |
| 480 | final TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); |
| 481 | if (!tm.isVoiceCapable()) { |
| 482 | final View emergencyCall = findViewById(R.id.emergencyCallButton); |
| 483 | if (emergencyCall != null) { |
| 484 | Log.d(TAG, "Removing the emergency Call button"); |
| 485 | emergencyCall.setVisibility(View.GONE); |
| 486 | } |
| 487 | } |
| 488 | |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 489 | final View imeSwitcher = findViewById(R.id.switch_ime_button); |
Ben Komalo | 9fcb6a7 | 2011-08-26 14:40:18 -0700 | [diff] [blame] | 490 | final InputMethodManager imm = (InputMethodManager) getSystemService( |
| 491 | Context.INPUT_METHOD_SERVICE); |
| 492 | if (imeSwitcher != null && hasMultipleEnabledIMEsOrSubtypes(imm, false)) { |
| 493 | imeSwitcher.setVisibility(View.VISIBLE); |
| 494 | imeSwitcher.setOnClickListener(new OnClickListener() { |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 495 | @Override |
Ben Komalo | 9fcb6a7 | 2011-08-26 14:40:18 -0700 | [diff] [blame] | 496 | public void onClick(View v) { |
| 497 | imm.showInputMethodPicker(); |
| 498 | } |
| 499 | }); |
Jason parks | 00046d6 | 2011-06-13 17:38:45 -0500 | [diff] [blame] | 500 | } |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 501 | |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 502 | // We want to keep the screen on while waiting for input. In minimal boot mode, the device |
| 503 | // is completely non-functional, and we want the user to notice the device and enter a |
| 504 | // password. |
| 505 | if (mWakeLock == null) { |
| 506 | Log.d(TAG, "Acquiring wakelock."); |
| 507 | final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); |
| 508 | if (pm != null) { |
| 509 | mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, TAG); |
| 510 | mWakeLock.acquire(); |
| 511 | } |
| 512 | } |
Ben Komalo | 9fcb6a7 | 2011-08-26 14:40:18 -0700 | [diff] [blame] | 513 | // Asynchronously throw up the IME, since there are issues with requesting it to be shown |
| 514 | // immediately. |
| 515 | mHandler.postDelayed(new Runnable() { |
| 516 | @Override public void run() { |
| 517 | imm.showSoftInputUnchecked(0, null); |
| 518 | } |
| 519 | }, 0); |
| 520 | |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 521 | updateEmergencyCallButtonState(); |
Vikram Aggarwal | 86b9393 | 2012-05-01 16:46:06 -0700 | [diff] [blame] | 522 | // Notify the user in 30 seconds that we are waiting for him to enter the password. |
| 523 | mHandler.removeMessages(MESSAGE_NOTIFY); |
| 524 | mHandler.sendEmptyMessageDelayed(MESSAGE_NOTIFY, 30 * 1000); |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 525 | } |
| 526 | |
Ben Komalo | 9fcb6a7 | 2011-08-26 14:40:18 -0700 | [diff] [blame] | 527 | /** |
| 528 | * Method adapted from com.android.inputmethod.latin.Utils |
| 529 | * |
| 530 | * @param imm The input method manager |
| 531 | * @param shouldIncludeAuxiliarySubtypes |
| 532 | * @return true if we have multiple IMEs to choose from |
| 533 | */ |
| 534 | private boolean hasMultipleEnabledIMEsOrSubtypes(InputMethodManager imm, |
| 535 | final boolean shouldIncludeAuxiliarySubtypes) { |
| 536 | final List<InputMethodInfo> enabledImis = imm.getEnabledInputMethodList(); |
| 537 | |
| 538 | // Number of the filtered IMEs |
| 539 | int filteredImisCount = 0; |
| 540 | |
| 541 | for (InputMethodInfo imi : enabledImis) { |
| 542 | // We can return true immediately after we find two or more filtered IMEs. |
| 543 | if (filteredImisCount > 1) return true; |
| 544 | final List<InputMethodSubtype> subtypes = |
| 545 | imm.getEnabledInputMethodSubtypeList(imi, true); |
| 546 | // IMEs that have no subtypes should be counted. |
| 547 | if (subtypes.isEmpty()) { |
| 548 | ++filteredImisCount; |
| 549 | continue; |
| 550 | } |
| 551 | |
| 552 | int auxCount = 0; |
| 553 | for (InputMethodSubtype subtype : subtypes) { |
| 554 | if (subtype.isAuxiliary()) { |
| 555 | ++auxCount; |
| 556 | } |
| 557 | } |
| 558 | final int nonAuxCount = subtypes.size() - auxCount; |
| 559 | |
| 560 | // IMEs that have one or more non-auxiliary subtypes should be counted. |
| 561 | // If shouldIncludeAuxiliarySubtypes is true, IMEs that have two or more auxiliary |
| 562 | // subtypes should be counted as well. |
| 563 | if (nonAuxCount > 0 || (shouldIncludeAuxiliarySubtypes && auxCount > 1)) { |
| 564 | ++filteredImisCount; |
| 565 | continue; |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | return filteredImisCount > 1 |
| 570 | // imm.getEnabledInputMethodSubtypeList(null, false) will return the current IME's enabled |
| 571 | // input method subtype (The current IME should be LatinIME.) |
| 572 | || imm.getEnabledInputMethodSubtypeList(null, false).size() > 1; |
| 573 | } |
| 574 | |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 575 | private IMountService getMountService() { |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 576 | final IBinder service = ServiceManager.getService("mount"); |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 577 | if (service != null) { |
| 578 | return IMountService.Stub.asInterface(service); |
| 579 | } |
| 580 | return null; |
| 581 | } |
| 582 | |
| 583 | @Override |
| 584 | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { |
Jason parks | 00046d6 | 2011-06-13 17:38:45 -0500 | [diff] [blame] | 585 | if (actionId == EditorInfo.IME_NULL || actionId == EditorInfo.IME_ACTION_DONE) { |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 586 | // Get the password |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 587 | final String password = v.getText().toString(); |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 588 | |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 589 | if (TextUtils.isEmpty(password)) { |
| 590 | return true; |
| 591 | } |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 592 | |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 593 | // Now that we have the password clear the password field. |
| 594 | v.setText(null); |
| 595 | |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 596 | // Disable the password entry and back keypress while checking the password. These |
| 597 | // we either be re-enabled if the password was wrong or after the cooldown period. |
Jason parks | 06c5ff4 | 2011-03-01 10:17:40 -0600 | [diff] [blame] | 598 | mPasswordEntry.setEnabled(false); |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 599 | mIgnoreBack = true; |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 600 | |
Ben Komalo | 0460675 | 2011-08-18 14:50:26 -0700 | [diff] [blame] | 601 | Log.d(TAG, "Attempting to send command to decrypt"); |
Jason parks | 06c5ff4 | 2011-03-01 10:17:40 -0600 | [diff] [blame] | 602 | new DecryptTask().execute(password); |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 603 | |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 604 | return true; |
| 605 | } |
| 606 | return false; |
| 607 | } |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 608 | |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 609 | /** |
| 610 | * Code to update the state of, and handle clicks from, the "Emergency call" button. |
| 611 | * |
| 612 | * This code is mostly duplicated from the corresponding code in |
| 613 | * LockPatternUtils and LockPatternKeyguardView under frameworks/base. |
| 614 | */ |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 615 | private void updateEmergencyCallButtonState() { |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 616 | final Button emergencyCall = (Button) findViewById(R.id.emergencyCallButton); |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 617 | // The button isn't present at all in some configurations. |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 618 | if (emergencyCall == null) |
| 619 | return; |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 620 | |
| 621 | if (isEmergencyCallCapable()) { |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 622 | emergencyCall.setVisibility(View.VISIBLE); |
| 623 | emergencyCall.setOnClickListener(new View.OnClickListener() { |
| 624 | @Override |
| 625 | |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 626 | public void onClick(View v) { |
| 627 | takeEmergencyCallAction(); |
| 628 | } |
| 629 | }); |
| 630 | } else { |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 631 | emergencyCall.setVisibility(View.GONE); |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 632 | return; |
| 633 | } |
| 634 | |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 635 | final int newState = TelephonyManager.getDefault().getCallState(); |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 636 | int textId; |
| 637 | if (newState == TelephonyManager.CALL_STATE_OFFHOOK) { |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 638 | // Show "return to call" text and show phone icon |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 639 | textId = R.string.cryptkeeper_return_to_call; |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 640 | final int phoneCallIcon = R.drawable.stat_sys_phone_call; |
| 641 | emergencyCall.setCompoundDrawablesWithIntrinsicBounds(phoneCallIcon, 0, 0, 0); |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 642 | } else { |
| 643 | textId = R.string.cryptkeeper_emergency_call; |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 644 | final int emergencyIcon = R.drawable.ic_emergency; |
| 645 | emergencyCall.setCompoundDrawablesWithIntrinsicBounds(emergencyIcon, 0, 0, 0); |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 646 | } |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 647 | emergencyCall.setText(textId); |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | private boolean isEmergencyCallCapable() { |
| 651 | return getResources().getBoolean(com.android.internal.R.bool.config_voice_capable); |
| 652 | } |
| 653 | |
| 654 | private void takeEmergencyCallAction() { |
| 655 | if (TelephonyManager.getDefault().getCallState() == TelephonyManager.CALL_STATE_OFFHOOK) { |
| 656 | resumeCall(); |
| 657 | } else { |
| 658 | launchEmergencyDialer(); |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | private void resumeCall() { |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 663 | final ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone")); |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 664 | if (phone != null) { |
| 665 | try { |
| 666 | phone.showCallScreen(); |
| 667 | } catch (RemoteException e) { |
| 668 | Log.e(TAG, "Error calling ITelephony service: " + e); |
| 669 | } |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | private void launchEmergencyDialer() { |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 674 | final Intent intent = new Intent(ACTION_EMERGENCY_DIAL); |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 675 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 676 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 677 | startActivity(intent); |
| 678 | } |
| 679 | } |