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; |
Jason parks | 75c085e | 2011-02-10 14:03:47 -0600 | [diff] [blame] | 25 | import android.graphics.Rect; |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 26 | import android.inputmethodservice.KeyboardView; |
Jason parks | 06c5ff4 | 2011-03-01 10:17:40 -0600 | [diff] [blame] | 27 | import android.os.AsyncTask; |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 28 | import android.os.Bundle; |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 29 | import android.os.Handler; |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 30 | import android.os.IBinder; |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 31 | import android.os.Message; |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 32 | import android.os.PowerManager; |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 33 | import android.os.RemoteException; |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 34 | import android.os.ServiceManager; |
| 35 | import android.os.SystemProperties; |
| 36 | import android.os.storage.IMountService; |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 37 | import android.telephony.TelephonyManager; |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 38 | import android.text.TextUtils; |
Jason parks | 75c085e | 2011-02-10 14:03:47 -0600 | [diff] [blame] | 39 | import android.util.AttributeSet; |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 40 | import android.util.Log; |
| 41 | import android.view.KeyEvent; |
Jason parks | 75c085e | 2011-02-10 14:03:47 -0600 | [diff] [blame] | 42 | import android.view.MotionEvent; |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 43 | import android.view.View; |
| 44 | import android.view.View.OnClickListener; |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 45 | import android.view.inputmethod.EditorInfo; |
Jason parks | 75c085e | 2011-02-10 14:03:47 -0600 | [diff] [blame] | 46 | import android.view.inputmethod.InputMethodManager; |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 47 | import android.widget.Button; |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 48 | import android.widget.EditText; |
| 49 | import android.widget.ProgressBar; |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 50 | import android.widget.TextView; |
| 51 | |
Ben Komalo | 91a2f05 | 2011-08-16 17:48:25 -0700 | [diff] [blame] | 52 | import com.android.internal.telephony.ITelephony; |
| 53 | import com.android.internal.widget.PasswordEntryKeyboardHelper; |
| 54 | import com.android.internal.widget.PasswordEntryKeyboardView; |
| 55 | |
| 56 | /** |
| 57 | * Settings screens to show the UI flows for encrypting/decrypting the device. |
| 58 | * |
| 59 | * This may be started via adb for debugging the UI layout, without having to go through |
| 60 | * encryption flows everytime. It should be noted that starting the activity in this manner |
| 61 | * is only useful for verifying UI-correctness - the behavior will not be identical. |
| 62 | * <pre> |
| 63 | * $ adb shell pm enable com.android.settings/.CryptKeeper |
| 64 | * $ adb shell am start \ |
| 65 | * -e "com.android.settings.CryptKeeper.DEBUG_FORCE_VIEW" "progress" \ |
| 66 | * -n com.android.settings/.CryptKeeper |
| 67 | * </pre> |
| 68 | */ |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 69 | public class CryptKeeper extends Activity implements TextView.OnEditorActionListener { |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 70 | private static final String TAG = "CryptKeeper"; |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 71 | |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 72 | private static final String DECRYPT_STATE = "trigger_restart_framework"; |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 73 | |
| 74 | private static final int UPDATE_PROGRESS = 1; |
| 75 | private static final int COOLDOWN = 2; |
| 76 | |
| 77 | private static final int MAX_FAILED_ATTEMPTS = 30; |
| 78 | private static final int COOL_DOWN_ATTEMPTS = 10; |
| 79 | private static final int COOL_DOWN_INTERVAL = 30; // 30 seconds |
| 80 | |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 81 | // Intent action for launching the Emergency Dialer activity. |
| 82 | static final String ACTION_EMERGENCY_DIAL = "com.android.phone.EmergencyDialer.DIAL"; |
| 83 | |
Ben Komalo | 91a2f05 | 2011-08-16 17:48:25 -0700 | [diff] [blame] | 84 | // Debug Intent extras so that this Activity may be started via adb for debugging UI layouts |
| 85 | private static final String EXTRA_FORCE_VIEW = |
| 86 | "com.android.settings.CryptKeeper.DEBUG_FORCE_VIEW"; |
| 87 | private static final String FORCE_VIEW_PROGRESS = "progress"; |
| 88 | private static final String FORCE_VIEW_ENTRY = "entry"; |
| 89 | private static final String FORCE_VIEW_ERROR = "error"; |
| 90 | |
Andy Stadler | 1499740 | 2011-02-01 15:34:59 -0800 | [diff] [blame] | 91 | private int mCooldown; |
| 92 | PowerManager.WakeLock mWakeLock; |
Jason parks | 06c5ff4 | 2011-03-01 10:17:40 -0600 | [diff] [blame] | 93 | private EditText mPasswordEntry; |
Andy Stadler | 1499740 | 2011-02-01 15:34:59 -0800 | [diff] [blame] | 94 | |
| 95 | /** |
| 96 | * Used to propagate state through configuration changes (e.g. screen rotation) |
| 97 | */ |
| 98 | private static class NonConfigurationInstanceState { |
| 99 | final PowerManager.WakeLock wakelock; |
| 100 | |
| 101 | NonConfigurationInstanceState(PowerManager.WakeLock _wakelock) { |
| 102 | wakelock = _wakelock; |
| 103 | } |
| 104 | } |
| 105 | |
Jason parks | f1dbf55 | 2011-01-24 16:19:28 -0600 | [diff] [blame] | 106 | // This activity is used to fade the screen to black after the password is entered. |
| 107 | public static class Blank extends Activity { |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 108 | @Override |
| 109 | public void onCreate(Bundle savedInstanceState) { |
| 110 | super.onCreate(savedInstanceState); |
| 111 | setContentView(R.layout.crypt_keeper_blank); |
| 112 | } |
Jason parks | f1dbf55 | 2011-01-24 16:19:28 -0600 | [diff] [blame] | 113 | } |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 114 | |
Jason parks | 75c085e | 2011-02-10 14:03:47 -0600 | [diff] [blame] | 115 | // Use a custom EditText to prevent the input method from showing. |
| 116 | public static class CryptEditText extends EditText { |
| 117 | InputMethodManager imm; |
| 118 | |
| 119 | public CryptEditText(Context context, AttributeSet attrs) { |
| 120 | super(context, attrs); |
| 121 | imm = ((InputMethodManager) getContext(). |
| 122 | getSystemService(Context.INPUT_METHOD_SERVICE)); |
| 123 | } |
| 124 | |
| 125 | @Override |
| 126 | protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { |
| 127 | super.onFocusChanged(focused, direction, previouslyFocusedRect); |
| 128 | |
| 129 | if (focused && imm != null && imm.isActive(this)) { |
| 130 | imm.hideSoftInputFromWindow(getApplicationWindowToken(), 0); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public boolean onTouchEvent(MotionEvent event) { |
| 136 | boolean handled = super.onTouchEvent(event); |
| 137 | |
| 138 | if (imm != null && imm.isActive(this)) { |
| 139 | imm.hideSoftInputFromWindow(getApplicationWindowToken(), 0); |
| 140 | } |
| 141 | |
| 142 | return handled; |
| 143 | } |
| 144 | } |
| 145 | |
Jason parks | 06c5ff4 | 2011-03-01 10:17:40 -0600 | [diff] [blame] | 146 | private class DecryptTask extends AsyncTask<String, Void, Integer> { |
| 147 | @Override |
| 148 | protected Integer doInBackground(String... params) { |
| 149 | IMountService service = getMountService(); |
| 150 | try { |
| 151 | return service.decryptStorage(params[0]); |
| 152 | } catch (Exception e) { |
| 153 | Log.e(TAG, "Error while decrypting...", e); |
| 154 | return -1; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | @Override |
| 159 | protected void onPostExecute(Integer failedAttempts) { |
| 160 | if (failedAttempts == 0) { |
| 161 | // The password was entered successfully. Start the Blank activity |
| 162 | // so this activity animates to black before the devices starts. Note |
| 163 | // It has 1 second to complete the animation or it will be frozen |
| 164 | // until the boot animation comes back up. |
| 165 | Intent intent = new Intent(CryptKeeper.this, Blank.class); |
| 166 | finish(); |
| 167 | startActivity(intent); |
| 168 | } else if (failedAttempts == MAX_FAILED_ATTEMPTS) { |
| 169 | // Factory reset the device. |
| 170 | sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR")); |
| 171 | } else if ((failedAttempts % COOL_DOWN_ATTEMPTS) == 0) { |
| 172 | mCooldown = COOL_DOWN_INTERVAL; |
| 173 | cooldown(); |
| 174 | } else { |
| 175 | TextView tv = (TextView) findViewById(R.id.status); |
| 176 | tv.setText(R.string.try_again); |
| 177 | tv.setVisibility(View.VISIBLE); |
| 178 | |
| 179 | // Reenable the password entry |
| 180 | mPasswordEntry.setEnabled(true); |
| 181 | } |
| 182 | } |
| 183 | } |
Jason parks | 75c085e | 2011-02-10 14:03:47 -0600 | [diff] [blame] | 184 | |
Ben Komalo | 91a2f05 | 2011-08-16 17:48:25 -0700 | [diff] [blame] | 185 | private final Handler mHandler = new Handler() { |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 186 | @Override |
| 187 | public void handleMessage(Message msg) { |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 188 | switch (msg.what) { |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 189 | case UPDATE_PROGRESS: |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 190 | updateProgress(); |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 191 | break; |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 192 | |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 193 | case COOLDOWN: |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 194 | cooldown(); |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 195 | break; |
| 196 | } |
| 197 | } |
| 198 | }; |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 199 | |
Ben Komalo | 91a2f05 | 2011-08-16 17:48:25 -0700 | [diff] [blame] | 200 | /** @return whether or not this Activity was started for debugging the UI only. */ |
| 201 | private boolean isDebugView() { |
| 202 | return getIntent().hasExtra(EXTRA_FORCE_VIEW); |
| 203 | } |
| 204 | |
| 205 | /** @return whether or not this Activity was started for debugging the specific UI view only. */ |
| 206 | private boolean isDebugView(String viewType /* non-nullable */) { |
| 207 | return viewType.equals(getIntent().getStringExtra(EXTRA_FORCE_VIEW)); |
| 208 | } |
| 209 | |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 210 | @Override |
| 211 | public void onCreate(Bundle savedInstanceState) { |
| 212 | super.onCreate(savedInstanceState); |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 213 | |
Andy Stadler | 9597406 | 2011-02-01 17:35:20 -0800 | [diff] [blame] | 214 | // If we are not encrypted or encrypting, get out quickly. |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 215 | String state = SystemProperties.get("vold.decrypt"); |
Ben Komalo | 91a2f05 | 2011-08-16 17:48:25 -0700 | [diff] [blame] | 216 | if (!isDebugView() && ("".equals(state) || DECRYPT_STATE.equals(state))) { |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 217 | // Disable the crypt keeper. |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 218 | PackageManager pm = getPackageManager(); |
| 219 | ComponentName name = new ComponentName(this, CryptKeeper.class); |
| 220 | pm.setComponentEnabledSetting(name, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0); |
| 221 | return; |
| 222 | } |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 223 | |
Jason parks | 39f1e04 | 2011-01-20 23:29:28 -0600 | [diff] [blame] | 224 | // Disable the status bar |
| 225 | StatusBarManager sbm = (StatusBarManager) getSystemService(Context.STATUS_BAR_SERVICE); |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 226 | sbm.disable(StatusBarManager.DISABLE_EXPAND |
| 227 | | StatusBarManager.DISABLE_NOTIFICATION_ICONS |
Jason parks | 39f1e04 | 2011-01-20 23:29:28 -0600 | [diff] [blame] | 228 | | StatusBarManager.DISABLE_NOTIFICATION_ALERTS |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 229 | | StatusBarManager.DISABLE_SYSTEM_INFO |
| 230 | | StatusBarManager.DISABLE_NAVIGATION |
| 231 | | StatusBarManager.DISABLE_BACK); |
Andy Stadler | 1499740 | 2011-02-01 15:34:59 -0800 | [diff] [blame] | 232 | |
| 233 | // Check for (and recover) retained instance data |
| 234 | Object lastInstance = getLastNonConfigurationInstance(); |
| 235 | if (lastInstance instanceof NonConfigurationInstanceState) { |
| 236 | NonConfigurationInstanceState retained = (NonConfigurationInstanceState) lastInstance; |
| 237 | mWakeLock = retained.wakelock; |
Ben Komalo | 0460675 | 2011-08-18 14:50:26 -0700 | [diff] [blame^] | 238 | Log.d(TAG, "Restoring wakelock from NonConfigurationInstanceState"); |
Andy Stadler | 1499740 | 2011-02-01 15:34:59 -0800 | [diff] [blame] | 239 | } |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 240 | } |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 241 | |
Andy Stadler | 9597406 | 2011-02-01 17:35:20 -0800 | [diff] [blame] | 242 | /** |
| 243 | * Note, we defer the state check and screen setup to onStart() because this will be |
| 244 | * re-run if the user clicks the power button (sleeping/waking the screen), and this is |
| 245 | * especially important if we were to lose the wakelock for any reason. |
| 246 | */ |
| 247 | @Override |
| 248 | public void onStart() { |
| 249 | super.onStart(); |
| 250 | |
| 251 | // Check to see why we were started. |
| 252 | String progress = SystemProperties.get("vold.encrypt_progress"); |
Ben Komalo | 91a2f05 | 2011-08-16 17:48:25 -0700 | [diff] [blame] | 253 | if (!"".equals(progress) |
| 254 | || isDebugView(FORCE_VIEW_PROGRESS) |
| 255 | || isDebugView(FORCE_VIEW_ERROR)) { |
Andy Stadler | 9597406 | 2011-02-01 17:35:20 -0800 | [diff] [blame] | 256 | setContentView(R.layout.crypt_keeper_progress); |
| 257 | encryptionProgressInit(); |
| 258 | } else { |
| 259 | setContentView(R.layout.crypt_keeper_password_entry); |
| 260 | passwordEntryInit(); |
| 261 | } |
| 262 | } |
| 263 | |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 264 | @Override |
| 265 | public void onStop() { |
| 266 | super.onStop(); |
| 267 | |
| 268 | mHandler.removeMessages(COOLDOWN); |
| 269 | mHandler.removeMessages(UPDATE_PROGRESS); |
Andy Stadler | 1499740 | 2011-02-01 15:34:59 -0800 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | /** |
| 273 | * Reconfiguring, so propagate the wakelock to the next instance. This runs between onStop() |
| 274 | * and onDestroy() and only if we are changing configuration (e.g. rotation). Also clears |
| 275 | * mWakeLock so the subsequent call to onDestroy does not release it. |
| 276 | */ |
| 277 | @Override |
| 278 | public Object onRetainNonConfigurationInstance() { |
| 279 | NonConfigurationInstanceState state = new NonConfigurationInstanceState(mWakeLock); |
Ben Komalo | 0460675 | 2011-08-18 14:50:26 -0700 | [diff] [blame^] | 280 | Log.d(TAG, "Handing wakelock off to NonConfigurationInstanceState"); |
Andy Stadler | 1499740 | 2011-02-01 15:34:59 -0800 | [diff] [blame] | 281 | mWakeLock = null; |
| 282 | return state; |
| 283 | } |
| 284 | |
| 285 | @Override |
| 286 | public void onDestroy() { |
| 287 | super.onDestroy(); |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 288 | |
| 289 | if (mWakeLock != null) { |
Ben Komalo | 0460675 | 2011-08-18 14:50:26 -0700 | [diff] [blame^] | 290 | Log.d(TAG, "Releasing and destroying wakelock"); |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 291 | mWakeLock.release(); |
| 292 | mWakeLock = null; |
| 293 | } |
| 294 | } |
| 295 | |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 296 | private void encryptionProgressInit() { |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 297 | // Accquire a partial wakelock to prevent the device from sleeping. Note |
| 298 | // we never release this wakelock as we will be restarted after the device |
| 299 | // is encrypted. |
| 300 | |
Ben Komalo | 0460675 | 2011-08-18 14:50:26 -0700 | [diff] [blame^] | 301 | Log.d(TAG, "Encryption progress screen initializing."); |
| 302 | if (mWakeLock != null) { |
| 303 | Log.d(TAG, "Acquiring wakelock."); |
| 304 | PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); |
| 305 | mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, TAG); |
| 306 | mWakeLock.acquire(); |
| 307 | } |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 308 | |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 309 | ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress_bar); |
| 310 | progressBar.setIndeterminate(true); |
| 311 | |
| 312 | updateProgress(); |
| 313 | } |
| 314 | |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 315 | private void showFactoryReset() { |
| 316 | // Hide the encryption-bot to make room for the "factory reset" button |
| 317 | findViewById(R.id.encroid).setVisibility(View.GONE); |
| 318 | |
| 319 | // Show the reset button, failure text, and a divider |
| 320 | Button button = (Button) findViewById(R.id.factory_reset); |
| 321 | button.setVisibility(View.VISIBLE); |
| 322 | button.setOnClickListener(new OnClickListener() { |
| 323 | public void onClick(View v) { |
| 324 | // Factory reset the device. |
| 325 | sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR")); |
| 326 | } |
| 327 | }); |
| 328 | |
| 329 | TextView tv = (TextView) findViewById(R.id.title); |
| 330 | tv.setText(R.string.crypt_keeper_failed_title); |
| 331 | |
| 332 | tv = (TextView) findViewById(R.id.status); |
| 333 | tv.setText(R.string.crypt_keeper_failed_summary); |
| 334 | |
| 335 | View view = findViewById(R.id.bottom_divider); |
Ben Komalo | f0104df | 2011-08-16 17:48:42 -0700 | [diff] [blame] | 336 | if (view != null) { |
| 337 | view.setVisibility(View.VISIBLE); |
| 338 | } |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 339 | } |
| 340 | |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 341 | private void updateProgress() { |
| 342 | String state = SystemProperties.get("vold.encrypt_progress"); |
| 343 | |
Ben Komalo | 91a2f05 | 2011-08-16 17:48:25 -0700 | [diff] [blame] | 344 | if ("error_partially_encrypted".equals(state) || isDebugView(FORCE_VIEW_ERROR)) { |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 345 | showFactoryReset(); |
| 346 | return; |
| 347 | } |
| 348 | |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 349 | int progress = 0; |
| 350 | try { |
Ben Komalo | 91a2f05 | 2011-08-16 17:48:25 -0700 | [diff] [blame] | 351 | // Force a 50% progress state when debugging the view. |
| 352 | progress = isDebugView() ? 50 : Integer.parseInt(state); |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 353 | } catch (Exception e) { |
| 354 | Log.w(TAG, "Error parsing progress: " + e.toString()); |
| 355 | } |
| 356 | |
| 357 | CharSequence status = getText(R.string.crypt_keeper_setup_description); |
Ben Komalo | 0460675 | 2011-08-18 14:50:26 -0700 | [diff] [blame^] | 358 | Log.v(TAG, "Encryption progress: " + progress); |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 359 | TextView tv = (TextView) findViewById(R.id.status); |
| 360 | tv.setText(TextUtils.expandTemplate(status, Integer.toString(progress))); |
| 361 | |
| 362 | // Check the progress every 5 seconds |
| 363 | mHandler.removeMessages(UPDATE_PROGRESS); |
| 364 | mHandler.sendEmptyMessageDelayed(UPDATE_PROGRESS, 5000); |
| 365 | } |
| 366 | |
| 367 | private void cooldown() { |
| 368 | TextView tv = (TextView) findViewById(R.id.status); |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 369 | |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 370 | if (mCooldown <= 0) { |
| 371 | // Re-enable the password entry |
Jason parks | 06c5ff4 | 2011-03-01 10:17:40 -0600 | [diff] [blame] | 372 | mPasswordEntry.setEnabled(true); |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 373 | |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 374 | tv.setVisibility(View.GONE); |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 375 | } else { |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 376 | CharSequence template = getText(R.string.crypt_keeper_cooldown); |
| 377 | tv.setText(TextUtils.expandTemplate(template, Integer.toString(mCooldown))); |
| 378 | |
| 379 | tv.setVisibility(View.VISIBLE); |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 380 | |
| 381 | mCooldown--; |
| 382 | mHandler.removeMessages(COOLDOWN); |
| 383 | mHandler.sendEmptyMessageDelayed(COOLDOWN, 1000); // Tick every second |
| 384 | } |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 385 | } |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 386 | |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 387 | private void passwordEntryInit() { |
Jason parks | 06c5ff4 | 2011-03-01 10:17:40 -0600 | [diff] [blame] | 388 | mPasswordEntry = (EditText) findViewById(R.id.passwordEntry); |
| 389 | mPasswordEntry.setOnEditorActionListener(this); |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 390 | |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 391 | KeyboardView keyboardView = (PasswordEntryKeyboardView) findViewById(R.id.keyboard); |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 392 | |
Jason parks | 00046d6 | 2011-06-13 17:38:45 -0500 | [diff] [blame] | 393 | if (keyboardView != null) { |
| 394 | PasswordEntryKeyboardHelper keyboardHelper = new PasswordEntryKeyboardHelper(this, |
| 395 | keyboardView, mPasswordEntry, false); |
| 396 | keyboardHelper.setKeyboardMode(PasswordEntryKeyboardHelper.KEYBOARD_MODE_ALPHA); |
| 397 | } |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 398 | |
| 399 | updateEmergencyCallButtonState(); |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | private IMountService getMountService() { |
| 403 | IBinder service = ServiceManager.getService("mount"); |
| 404 | if (service != null) { |
| 405 | return IMountService.Stub.asInterface(service); |
| 406 | } |
| 407 | return null; |
| 408 | } |
| 409 | |
| 410 | @Override |
| 411 | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { |
Jason parks | 00046d6 | 2011-06-13 17:38:45 -0500 | [diff] [blame] | 412 | if (actionId == EditorInfo.IME_NULL || actionId == EditorInfo.IME_ACTION_DONE) { |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 413 | // Get the password |
| 414 | String password = v.getText().toString(); |
| 415 | |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 416 | if (TextUtils.isEmpty(password)) { |
| 417 | return true; |
| 418 | } |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 419 | |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 420 | // Now that we have the password clear the password field. |
| 421 | v.setText(null); |
| 422 | |
Jason parks | 06c5ff4 | 2011-03-01 10:17:40 -0600 | [diff] [blame] | 423 | // Disable the password entry while checking the password. This |
| 424 | // we either be reenabled if the password was wrong or after the |
| 425 | // cooldown period. |
| 426 | mPasswordEntry.setEnabled(false); |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 427 | |
Ben Komalo | 0460675 | 2011-08-18 14:50:26 -0700 | [diff] [blame^] | 428 | Log.d(TAG, "Attempting to send command to decrypt"); |
Jason parks | 06c5ff4 | 2011-03-01 10:17:40 -0600 | [diff] [blame] | 429 | new DecryptTask().execute(password); |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 430 | |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 431 | return true; |
| 432 | } |
| 433 | return false; |
| 434 | } |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 435 | |
| 436 | // |
| 437 | // Code to update the state of, and handle clicks from, the "Emergency call" button. |
| 438 | // |
| 439 | // This code is mostly duplicated from the corresponding code in |
| 440 | // LockPatternUtils and LockPatternKeyguardView under frameworks/base. |
| 441 | // |
| 442 | |
| 443 | private void updateEmergencyCallButtonState() { |
| 444 | Button button = (Button) findViewById(R.id.emergencyCallButton); |
| 445 | // The button isn't present at all in some configurations. |
| 446 | if (button == null) return; |
| 447 | |
| 448 | if (isEmergencyCallCapable()) { |
| 449 | button.setVisibility(View.VISIBLE); |
| 450 | button.setOnClickListener(new View.OnClickListener() { |
| 451 | public void onClick(View v) { |
| 452 | takeEmergencyCallAction(); |
| 453 | } |
| 454 | }); |
| 455 | } else { |
| 456 | button.setVisibility(View.GONE); |
| 457 | return; |
| 458 | } |
| 459 | |
| 460 | int newState = TelephonyManager.getDefault().getCallState(); |
| 461 | int textId; |
| 462 | if (newState == TelephonyManager.CALL_STATE_OFFHOOK) { |
| 463 | // show "return to call" text and show phone icon |
| 464 | textId = R.string.cryptkeeper_return_to_call; |
| 465 | int phoneCallIcon = R.drawable.stat_sys_phone_call; |
| 466 | button.setCompoundDrawablesWithIntrinsicBounds(phoneCallIcon, 0, 0, 0); |
| 467 | } else { |
| 468 | textId = R.string.cryptkeeper_emergency_call; |
| 469 | int emergencyIcon = R.drawable.ic_emergency; |
| 470 | button.setCompoundDrawablesWithIntrinsicBounds(emergencyIcon, 0, 0, 0); |
| 471 | } |
| 472 | button.setText(textId); |
| 473 | } |
| 474 | |
| 475 | private boolean isEmergencyCallCapable() { |
| 476 | return getResources().getBoolean(com.android.internal.R.bool.config_voice_capable); |
| 477 | } |
| 478 | |
| 479 | private void takeEmergencyCallAction() { |
| 480 | if (TelephonyManager.getDefault().getCallState() == TelephonyManager.CALL_STATE_OFFHOOK) { |
| 481 | resumeCall(); |
| 482 | } else { |
| 483 | launchEmergencyDialer(); |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | private void resumeCall() { |
| 488 | ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone")); |
| 489 | if (phone != null) { |
| 490 | try { |
| 491 | phone.showCallScreen(); |
| 492 | } catch (RemoteException e) { |
| 493 | Log.e(TAG, "Error calling ITelephony service: " + e); |
| 494 | } |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | private void launchEmergencyDialer() { |
| 499 | Intent intent = new Intent(ACTION_EMERGENCY_DIAL); |
| 500 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 501 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 502 | startActivity(intent); |
| 503 | } |
| 504 | } |