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; |
Paul Lawrence | 7ae20e3 | 2014-07-22 15:00:50 -0700 | [diff] [blame] | 24 | import android.content.pm.ActivityInfo; |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 25 | import android.content.pm.PackageManager; |
Paul Lawrence | 7ae20e3 | 2014-07-22 15:00:50 -0700 | [diff] [blame] | 26 | import android.content.res.Resources.NotFoundException; |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 27 | import android.media.AudioManager; |
Jason parks | 06c5ff4 | 2011-03-01 10:17:40 -0600 | [diff] [blame] | 28 | import android.os.AsyncTask; |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 29 | import android.os.Bundle; |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 30 | import android.os.Handler; |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 31 | import android.os.IBinder; |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 32 | import android.os.Message; |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 33 | import android.os.PowerManager; |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 34 | import android.os.RemoteException; |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 35 | import android.os.ServiceManager; |
| 36 | import android.os.SystemProperties; |
Christopher Tate | 6a5929b | 2012-09-10 15:39:05 -0700 | [diff] [blame] | 37 | import android.os.UserHandle; |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 38 | import android.os.storage.IMountService; |
Paul Lawrence | b05f39d | 2014-02-04 10:22:19 -0800 | [diff] [blame] | 39 | import android.os.storage.StorageManager; |
Vikram Aggarwal | 6ebbd30 | 2012-05-04 14:09:52 -0700 | [diff] [blame] | 40 | import android.provider.Settings; |
Tyler Gunn | 3e71b19 | 2014-09-10 15:21:33 -0700 | [diff] [blame] | 41 | import android.telecom.TelecomManager; |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 42 | import android.telephony.TelephonyManager; |
Vikram Aggarwal | d114725 | 2012-05-08 13:52:30 -0700 | [diff] [blame] | 43 | import android.text.Editable; |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 44 | import android.text.TextUtils; |
Vikram Aggarwal | d114725 | 2012-05-08 13:52:30 -0700 | [diff] [blame] | 45 | import android.text.TextWatcher; |
Paul Lawrence | b15c68f | 2014-06-05 07:24:23 -0700 | [diff] [blame] | 46 | import android.text.format.DateUtils; |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 47 | import android.util.Log; |
| 48 | import android.view.KeyEvent; |
Vikram Aggarwal | d114725 | 2012-05-08 13:52:30 -0700 | [diff] [blame] | 49 | import android.view.MotionEvent; |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 50 | import android.view.View; |
Jim Miller | fb3d5ca | 2013-11-14 14:40:22 -0800 | [diff] [blame] | 51 | import android.view.WindowManager; |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 52 | import android.view.View.OnClickListener; |
Vikram Aggarwal | d114725 | 2012-05-08 13:52:30 -0700 | [diff] [blame] | 53 | import android.view.View.OnKeyListener; |
| 54 | import android.view.View.OnTouchListener; |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 55 | import android.view.inputmethod.EditorInfo; |
Ben Komalo | 9fcb6a7 | 2011-08-26 14:40:18 -0700 | [diff] [blame] | 56 | import android.view.inputmethod.InputMethodInfo; |
Jason parks | 75c085e | 2011-02-10 14:03:47 -0600 | [diff] [blame] | 57 | import android.view.inputmethod.InputMethodManager; |
Ben Komalo | 9fcb6a7 | 2011-08-26 14:40:18 -0700 | [diff] [blame] | 58 | import android.view.inputmethod.InputMethodSubtype; |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 59 | import android.widget.Button; |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 60 | import android.widget.EditText; |
| 61 | import android.widget.ProgressBar; |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 62 | import android.widget.TextView; |
| 63 | |
Vikram Aggarwal | bf459da | 2012-11-08 16:54:59 -0800 | [diff] [blame] | 64 | import com.android.internal.statusbar.StatusBarIcon; |
Vikram Aggarwal | ea1186d | 2012-05-03 15:35:03 -0700 | [diff] [blame] | 65 | import com.android.internal.telephony.Phone; |
Wink Saville | 5543404 | 2012-06-14 12:33:43 -0700 | [diff] [blame] | 66 | import com.android.internal.telephony.PhoneConstants; |
Paul Lawrence | b05f39d | 2014-02-04 10:22:19 -0800 | [diff] [blame] | 67 | import com.android.internal.widget.LockPatternUtils; |
| 68 | import com.android.internal.widget.LockPatternView; |
| 69 | import com.android.internal.widget.LockPatternView.Cell; |
Ben Komalo | 9fcb6a7 | 2011-08-26 14:40:18 -0700 | [diff] [blame] | 70 | |
Paul Lawrence | f6cda3b | 2014-06-12 08:26:08 -0700 | [diff] [blame] | 71 | import static com.android.internal.widget.LockPatternView.DisplayMode; |
| 72 | |
Ben Komalo | 9fcb6a7 | 2011-08-26 14:40:18 -0700 | [diff] [blame] | 73 | import java.util.List; |
Ben Komalo | 91a2f05 | 2011-08-16 17:48:25 -0700 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * Settings screens to show the UI flows for encrypting/decrypting the device. |
| 77 | * |
| 78 | * This may be started via adb for debugging the UI layout, without having to go through |
| 79 | * encryption flows everytime. It should be noted that starting the activity in this manner |
| 80 | * is only useful for verifying UI-correctness - the behavior will not be identical. |
| 81 | * <pre> |
| 82 | * $ adb shell pm enable com.android.settings/.CryptKeeper |
| 83 | * $ adb shell am start \ |
| 84 | * -e "com.android.settings.CryptKeeper.DEBUG_FORCE_VIEW" "progress" \ |
| 85 | * -n com.android.settings/.CryptKeeper |
| 86 | * </pre> |
| 87 | */ |
Vikram Aggarwal | d114725 | 2012-05-08 13:52:30 -0700 | [diff] [blame] | 88 | public class CryptKeeper extends Activity implements TextView.OnEditorActionListener, |
| 89 | OnKeyListener, OnTouchListener, TextWatcher { |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 90 | private static final String TAG = "CryptKeeper"; |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 91 | |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 92 | private static final String DECRYPT_STATE = "trigger_restart_framework"; |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 93 | /** Message sent to us to indicate encryption update progress. */ |
| 94 | private static final int MESSAGE_UPDATE_PROGRESS = 1; |
| 95 | /** Message sent to us to cool-down (waste user's time between password attempts) */ |
| 96 | private static final int MESSAGE_COOLDOWN = 2; |
| 97 | /** Message sent to us to indicate alerting the user that we are waiting for password entry */ |
| 98 | private static final int MESSAGE_NOTIFY = 3; |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 99 | |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 100 | // Constants used to control policy. |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 101 | private static final int MAX_FAILED_ATTEMPTS = 30; |
| 102 | private static final int COOL_DOWN_ATTEMPTS = 10; |
| 103 | private static final int COOL_DOWN_INTERVAL = 30; // 30 seconds |
| 104 | |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 105 | // Intent action for launching the Emergency Dialer activity. |
| 106 | static final String ACTION_EMERGENCY_DIAL = "com.android.phone.EmergencyDialer.DIAL"; |
| 107 | |
Ben Komalo | 91a2f05 | 2011-08-16 17:48:25 -0700 | [diff] [blame] | 108 | // Debug Intent extras so that this Activity may be started via adb for debugging UI layouts |
| 109 | private static final String EXTRA_FORCE_VIEW = |
| 110 | "com.android.settings.CryptKeeper.DEBUG_FORCE_VIEW"; |
| 111 | private static final String FORCE_VIEW_PROGRESS = "progress"; |
Ben Komalo | 91a2f05 | 2011-08-16 17:48:25 -0700 | [diff] [blame] | 112 | private static final String FORCE_VIEW_ERROR = "error"; |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 113 | private static final String FORCE_VIEW_PASSWORD = "password"; |
Ben Komalo | 91a2f05 | 2011-08-16 17:48:25 -0700 | [diff] [blame] | 114 | |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 115 | /** 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] | 116 | private boolean mValidationComplete; |
Ben Komalo | d4758ef | 2011-09-08 14:36:08 -0700 | [diff] [blame] | 117 | private boolean mValidationRequested; |
Ben Komalo | 0e66609 | 2011-09-01 15:42:00 -0700 | [diff] [blame] | 118 | /** A flag to indicate that the volume is in a bad state (e.g. partially encrypted). */ |
| 119 | private boolean mEncryptionGoneBad; |
Paul Lawrence | 87abbd3 | 2014-08-28 15:56:38 -0700 | [diff] [blame] | 120 | /** If gone bad, should we show encryption failed (false) or corrupt (true)*/ |
| 121 | private boolean mCorrupt; |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 122 | /** A flag to indicate when the back event should be ignored */ |
| 123 | private boolean mIgnoreBack = false; |
Andy Stadler | 1499740 | 2011-02-01 15:34:59 -0800 | [diff] [blame] | 124 | private int mCooldown; |
| 125 | PowerManager.WakeLock mWakeLock; |
Jason parks | 06c5ff4 | 2011-03-01 10:17:40 -0600 | [diff] [blame] | 126 | private EditText mPasswordEntry; |
Paul Lawrence | b05f39d | 2014-02-04 10:22:19 -0800 | [diff] [blame] | 127 | private LockPatternView mLockPatternView; |
Vikram Aggarwal | d114725 | 2012-05-08 13:52:30 -0700 | [diff] [blame] | 128 | /** Number of calls to {@link #notifyUser()} to ignore before notifying. */ |
| 129 | private int mNotificationCountdown = 0; |
Paul Lawrence | 73456ac | 2014-05-16 07:56:04 -0700 | [diff] [blame] | 130 | /** Number of calls to {@link #notifyUser()} before we release the wakelock */ |
| 131 | private int mReleaseWakeLockCountdown = 0; |
Paul Lawrence | 5a70f05 | 2014-06-13 11:09:55 -0700 | [diff] [blame] | 132 | private int mStatusString = R.string.enter_password; |
Andy Stadler | 1499740 | 2011-02-01 15:34:59 -0800 | [diff] [blame] | 133 | |
Paul Lawrence | f6cda3b | 2014-06-12 08:26:08 -0700 | [diff] [blame] | 134 | // how long we wait to clear a wrong pattern |
| 135 | private static final int WRONG_PATTERN_CLEAR_TIMEOUT_MS = 1500; |
| 136 | |
Paul Lawrence | 0f11e15 | 2014-08-20 07:43:32 -0700 | [diff] [blame] | 137 | // how long we wait to clear a right pattern |
| 138 | private static final int RIGHT_PATTERN_CLEAR_TIMEOUT_MS = 500; |
| 139 | |
Paul Lawrence | f6cda3b | 2014-06-12 08:26:08 -0700 | [diff] [blame] | 140 | private Runnable mClearPatternRunnable = new Runnable() { |
| 141 | public void run() { |
| 142 | mLockPatternView.clearPattern(); |
| 143 | } |
| 144 | }; |
| 145 | |
Andy Stadler | 1499740 | 2011-02-01 15:34:59 -0800 | [diff] [blame] | 146 | /** |
| 147 | * Used to propagate state through configuration changes (e.g. screen rotation) |
| 148 | */ |
| 149 | private static class NonConfigurationInstanceState { |
| 150 | final PowerManager.WakeLock wakelock; |
| 151 | |
| 152 | NonConfigurationInstanceState(PowerManager.WakeLock _wakelock) { |
| 153 | wakelock = _wakelock; |
| 154 | } |
| 155 | } |
| 156 | |
Jason parks | 06c5ff4 | 2011-03-01 10:17:40 -0600 | [diff] [blame] | 157 | private class DecryptTask extends AsyncTask<String, Void, Integer> { |
| 158 | @Override |
| 159 | protected Integer doInBackground(String... params) { |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 160 | final IMountService service = getMountService(); |
Jason parks | 06c5ff4 | 2011-03-01 10:17:40 -0600 | [diff] [blame] | 161 | try { |
| 162 | return service.decryptStorage(params[0]); |
| 163 | } catch (Exception e) { |
| 164 | Log.e(TAG, "Error while decrypting...", e); |
| 165 | return -1; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | @Override |
| 170 | protected void onPostExecute(Integer failedAttempts) { |
| 171 | if (failedAttempts == 0) { |
Paul Lawrence | 89c7570 | 2014-07-11 07:34:44 -0700 | [diff] [blame] | 172 | // The password was entered successfully. Simply do nothing |
| 173 | // and wait for the service restart to switch to surfacefligner |
Paul Lawrence | 0f11e15 | 2014-08-20 07:43:32 -0700 | [diff] [blame] | 174 | if (mLockPatternView != null) { |
| 175 | mLockPatternView.removeCallbacks(mClearPatternRunnable); |
| 176 | mLockPatternView.postDelayed(mClearPatternRunnable, RIGHT_PATTERN_CLEAR_TIMEOUT_MS); |
| 177 | } |
Jason parks | 06c5ff4 | 2011-03-01 10:17:40 -0600 | [diff] [blame] | 178 | } else if (failedAttempts == MAX_FAILED_ATTEMPTS) { |
| 179 | // Factory reset the device. |
| 180 | sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR")); |
Paul Lawrence | 384d8e5 | 2014-08-08 15:11:36 -0700 | [diff] [blame] | 181 | } else if (failedAttempts == -1) { |
| 182 | // Right password, but decryption failed. Tell user bad news ... |
| 183 | setContentView(R.layout.crypt_keeper_progress); |
| 184 | showFactoryReset(true); |
| 185 | return; |
Jason parks | 06c5ff4 | 2011-03-01 10:17:40 -0600 | [diff] [blame] | 186 | } else { |
Paul Lawrence | f6cda3b | 2014-06-12 08:26:08 -0700 | [diff] [blame] | 187 | // Wrong entry. Handle pattern case. |
Paul Lawrence | 2daf264 | 2014-03-14 09:20:24 -0700 | [diff] [blame] | 188 | if (mLockPatternView != null) { |
Paul Lawrence | f6cda3b | 2014-06-12 08:26:08 -0700 | [diff] [blame] | 189 | mLockPatternView.setDisplayMode(DisplayMode.Wrong); |
| 190 | mLockPatternView.removeCallbacks(mClearPatternRunnable); |
| 191 | mLockPatternView.postDelayed(mClearPatternRunnable, WRONG_PATTERN_CLEAR_TIMEOUT_MS); |
| 192 | } |
| 193 | if ((failedAttempts % COOL_DOWN_ATTEMPTS) == 0) { |
| 194 | mCooldown = COOL_DOWN_INTERVAL; |
| 195 | cooldown(); |
| 196 | } else { |
| 197 | final TextView status = (TextView) findViewById(R.id.status); |
Paul Lawrence | bd4c321 | 2014-07-23 13:57:17 -0700 | [diff] [blame] | 198 | |
| 199 | int remainingAttempts = MAX_FAILED_ATTEMPTS - failedAttempts; |
| 200 | if (remainingAttempts < COOL_DOWN_ATTEMPTS) { |
| 201 | CharSequence warningTemplate = getText(R.string.crypt_keeper_warn_wipe); |
| 202 | CharSequence warning = TextUtils.expandTemplate(warningTemplate, |
| 203 | Integer.toString(remainingAttempts)); |
| 204 | status.setText(warning); |
| 205 | } else { |
| 206 | status.setText(R.string.try_again); |
| 207 | } |
| 208 | |
Paul Lawrence | f6cda3b | 2014-06-12 08:26:08 -0700 | [diff] [blame] | 209 | if (mLockPatternView != null) { |
| 210 | mLockPatternView.setDisplayMode(DisplayMode.Wrong); |
| 211 | } |
| 212 | // Reenable the password entry |
| 213 | if (mPasswordEntry != null) { |
| 214 | mPasswordEntry.setEnabled(true); |
Paul Lawrence | 5a70f05 | 2014-06-13 11:09:55 -0700 | [diff] [blame] | 215 | final InputMethodManager imm = (InputMethodManager) getSystemService( |
| 216 | Context.INPUT_METHOD_SERVICE); |
| 217 | imm.showSoftInput(mPasswordEntry, 0); |
Paul Lawrence | 08c6ab0 | 2014-06-19 13:34:58 -0700 | [diff] [blame] | 218 | setBackFunctionality(true); |
Paul Lawrence | f6cda3b | 2014-06-12 08:26:08 -0700 | [diff] [blame] | 219 | } |
| 220 | if (mLockPatternView != null) { |
| 221 | mLockPatternView.setEnabled(true); |
| 222 | } |
Paul Lawrence | 2daf264 | 2014-03-14 09:20:24 -0700 | [diff] [blame] | 223 | } |
Jason parks | 06c5ff4 | 2011-03-01 10:17:40 -0600 | [diff] [blame] | 224 | } |
| 225 | } |
| 226 | } |
Jason parks | 75c085e | 2011-02-10 14:03:47 -0600 | [diff] [blame] | 227 | |
Ben Komalo | 0e66609 | 2011-09-01 15:42:00 -0700 | [diff] [blame] | 228 | private class ValidationTask extends AsyncTask<Void, Void, Boolean> { |
Paul Lawrence | 87abbd3 | 2014-08-28 15:56:38 -0700 | [diff] [blame] | 229 | int state; |
| 230 | |
Ben Komalo | 0e66609 | 2011-09-01 15:42:00 -0700 | [diff] [blame] | 231 | @Override |
| 232 | protected Boolean doInBackground(Void... params) { |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 233 | final IMountService service = getMountService(); |
Ben Komalo | 0e66609 | 2011-09-01 15:42:00 -0700 | [diff] [blame] | 234 | try { |
Ben Komalo | d4758ef | 2011-09-08 14:36:08 -0700 | [diff] [blame] | 235 | Log.d(TAG, "Validating encryption state."); |
Paul Lawrence | 87abbd3 | 2014-08-28 15:56:38 -0700 | [diff] [blame] | 236 | state = service.getEncryptionState(); |
Ben Komalo | 0e66609 | 2011-09-01 15:42:00 -0700 | [diff] [blame] | 237 | if (state == IMountService.ENCRYPTION_STATE_NONE) { |
| 238 | Log.w(TAG, "Unexpectedly in CryptKeeper even though there is no encryption."); |
| 239 | return true; // Unexpected, but fine, I guess... |
| 240 | } |
| 241 | return state == IMountService.ENCRYPTION_STATE_OK; |
| 242 | } catch (RemoteException e) { |
| 243 | Log.w(TAG, "Unable to get encryption state properly"); |
| 244 | return true; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | @Override |
| 249 | protected void onPostExecute(Boolean result) { |
| 250 | mValidationComplete = true; |
| 251 | if (Boolean.FALSE.equals(result)) { |
| 252 | Log.w(TAG, "Incomplete, or corrupted encryption detected. Prompting user to wipe."); |
| 253 | mEncryptionGoneBad = true; |
Paul Lawrence | 87abbd3 | 2014-08-28 15:56:38 -0700 | [diff] [blame] | 254 | mCorrupt = state == IMountService.ENCRYPTION_STATE_ERROR_CORRUPT; |
Ben Komalo | d4758ef | 2011-09-08 14:36:08 -0700 | [diff] [blame] | 255 | } else { |
| 256 | Log.d(TAG, "Encryption state validated. Proceeding to configure UI"); |
Ben Komalo | 0e66609 | 2011-09-01 15:42:00 -0700 | [diff] [blame] | 257 | } |
| 258 | setupUi(); |
| 259 | } |
| 260 | } |
| 261 | |
Ben Komalo | 91a2f05 | 2011-08-16 17:48:25 -0700 | [diff] [blame] | 262 | private final Handler mHandler = new Handler() { |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 263 | @Override |
| 264 | public void handleMessage(Message msg) { |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 265 | switch (msg.what) { |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 266 | case MESSAGE_UPDATE_PROGRESS: |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 267 | updateProgress(); |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 268 | break; |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 269 | |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 270 | case MESSAGE_COOLDOWN: |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 271 | cooldown(); |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 272 | break; |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 273 | |
| 274 | case MESSAGE_NOTIFY: |
| 275 | notifyUser(); |
| 276 | break; |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | }; |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 280 | |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 281 | private AudioManager mAudioManager; |
Vikram Aggarwal | bf459da | 2012-11-08 16:54:59 -0800 | [diff] [blame] | 282 | /** The status bar where back/home/recent buttons are shown. */ |
| 283 | private StatusBarManager mStatusBar; |
| 284 | |
| 285 | /** All the widgets to disable in the status bar */ |
| 286 | final private static int sWidgetsToDisable = StatusBarManager.DISABLE_EXPAND |
| 287 | | StatusBarManager.DISABLE_NOTIFICATION_ICONS |
| 288 | | StatusBarManager.DISABLE_NOTIFICATION_ALERTS |
| 289 | | StatusBarManager.DISABLE_SYSTEM_INFO |
| 290 | | StatusBarManager.DISABLE_HOME |
Alon Albert | 66d050b | 2013-09-30 17:08:12 -0700 | [diff] [blame] | 291 | | StatusBarManager.DISABLE_SEARCH |
Vikram Aggarwal | bf459da | 2012-11-08 16:54:59 -0800 | [diff] [blame] | 292 | | StatusBarManager.DISABLE_RECENT; |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 293 | |
Ben Komalo | 91a2f05 | 2011-08-16 17:48:25 -0700 | [diff] [blame] | 294 | /** @return whether or not this Activity was started for debugging the UI only. */ |
| 295 | private boolean isDebugView() { |
| 296 | return getIntent().hasExtra(EXTRA_FORCE_VIEW); |
| 297 | } |
| 298 | |
| 299 | /** @return whether or not this Activity was started for debugging the specific UI view only. */ |
| 300 | private boolean isDebugView(String viewType /* non-nullable */) { |
| 301 | return viewType.equals(getIntent().getStringExtra(EXTRA_FORCE_VIEW)); |
| 302 | } |
| 303 | |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 304 | /** |
| 305 | * Notify the user that we are awaiting input. Currently this sends an audio alert. |
| 306 | */ |
| 307 | private void notifyUser() { |
Vikram Aggarwal | d114725 | 2012-05-08 13:52:30 -0700 | [diff] [blame] | 308 | if (mNotificationCountdown > 0) { |
Vikram Aggarwal | d114725 | 2012-05-08 13:52:30 -0700 | [diff] [blame] | 309 | --mNotificationCountdown; |
| 310 | } else if (mAudioManager != null) { |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 311 | try { |
| 312 | // Play the standard keypress sound at full volume. This should be available on |
| 313 | // every device. We cannot play a ringtone here because media services aren't |
| 314 | // available yet. A DTMF-style tone is too soft to be noticed, and might not exist |
| 315 | // on tablet devices. The idea is to alert the user that something is needed: this |
| 316 | // does not have to be pleasing. |
| 317 | mAudioManager.playSoundEffect(AudioManager.FX_KEYPRESS_STANDARD, 100); |
| 318 | } catch (Exception e) { |
| 319 | Log.w(TAG, "notifyUser: Exception while playing sound: " + e); |
| 320 | } |
| 321 | } |
Vikram Aggarwal | 86b9393 | 2012-05-01 16:46:06 -0700 | [diff] [blame] | 322 | // Notify the user again in 5 seconds. |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 323 | mHandler.removeMessages(MESSAGE_NOTIFY); |
Vikram Aggarwal | 86b9393 | 2012-05-01 16:46:06 -0700 | [diff] [blame] | 324 | mHandler.sendEmptyMessageDelayed(MESSAGE_NOTIFY, 5 * 1000); |
Paul Lawrence | 73456ac | 2014-05-16 07:56:04 -0700 | [diff] [blame] | 325 | |
| 326 | if (mWakeLock.isHeld()) { |
| 327 | if (mReleaseWakeLockCountdown > 0) { |
| 328 | --mReleaseWakeLockCountdown; |
| 329 | } else { |
| 330 | mWakeLock.release(); |
| 331 | } |
| 332 | } |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | /** |
| 336 | * Ignore back events after the user has entered the decrypt screen and while the device is |
| 337 | * encrypting. |
| 338 | */ |
| 339 | @Override |
| 340 | public void onBackPressed() { |
Vikram Aggarwal | bf459da | 2012-11-08 16:54:59 -0800 | [diff] [blame] | 341 | // In the rare case that something pressed back even though we were disabled. |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 342 | if (mIgnoreBack) |
| 343 | return; |
| 344 | super.onBackPressed(); |
| 345 | } |
| 346 | |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 347 | @Override |
| 348 | public void onCreate(Bundle savedInstanceState) { |
| 349 | super.onCreate(savedInstanceState); |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 350 | |
Andy Stadler | 9597406 | 2011-02-01 17:35:20 -0800 | [diff] [blame] | 351 | // If we are not encrypted or encrypting, get out quickly. |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 352 | final String state = SystemProperties.get("vold.decrypt"); |
Ben Komalo | 91a2f05 | 2011-08-16 17:48:25 -0700 | [diff] [blame] | 353 | if (!isDebugView() && ("".equals(state) || DECRYPT_STATE.equals(state))) { |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 354 | // Disable the crypt keeper. |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 355 | PackageManager pm = getPackageManager(); |
| 356 | ComponentName name = new ComponentName(this, CryptKeeper.class); |
Dianne Hackborn | 140f6c6 | 2011-10-16 11:49:00 -0700 | [diff] [blame] | 357 | pm.setComponentEnabledSetting(name, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, |
| 358 | PackageManager.DONT_KILL_APP); |
| 359 | // Typically CryptKeeper is launched as the home app. We didn't |
Dianne Hackborn | 644fa42 | 2011-10-18 13:38:03 -0700 | [diff] [blame] | 360 | // want to be running, so need to finish this activity. We can count |
| 361 | // on the activity manager re-launching the new home app upon finishing |
| 362 | // this one, since this will leave the activity stack empty. |
Dianne Hackborn | 140f6c6 | 2011-10-16 11:49:00 -0700 | [diff] [blame] | 363 | // NOTE: This is really grungy. I think it would be better for the |
| 364 | // activity manager to explicitly launch the crypt keeper instead of |
| 365 | // home in the situation where we need to decrypt the device |
| 366 | finish(); |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 367 | return; |
| 368 | } |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 369 | |
Paul Lawrence | 7ae20e3 | 2014-07-22 15:00:50 -0700 | [diff] [blame] | 370 | try { |
| 371 | if (getResources().getBoolean(R.bool.crypt_keeper_allow_rotation)) { |
| 372 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
| 373 | } |
| 374 | } catch (NotFoundException e) { |
| 375 | } |
| 376 | |
Vikram Aggarwal | b96b35a | 2012-05-01 11:09:39 -0700 | [diff] [blame] | 377 | // Disable the status bar, but do NOT disable back because the user needs a way to go |
| 378 | // from keyboard settings and back to the password screen. |
Vikram Aggarwal | bf459da | 2012-11-08 16:54:59 -0800 | [diff] [blame] | 379 | mStatusBar = (StatusBarManager) getSystemService(Context.STATUS_BAR_SERVICE); |
| 380 | mStatusBar.disable(sWidgetsToDisable); |
Andy Stadler | 1499740 | 2011-02-01 15:34:59 -0800 | [diff] [blame] | 381 | |
Vikram Aggarwal | ea1186d | 2012-05-03 15:35:03 -0700 | [diff] [blame] | 382 | setAirplaneModeIfNecessary(); |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 383 | mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); |
Andy Stadler | 1499740 | 2011-02-01 15:34:59 -0800 | [diff] [blame] | 384 | // Check for (and recover) retained instance data |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 385 | final Object lastInstance = getLastNonConfigurationInstance(); |
Andy Stadler | 1499740 | 2011-02-01 15:34:59 -0800 | [diff] [blame] | 386 | if (lastInstance instanceof NonConfigurationInstanceState) { |
| 387 | NonConfigurationInstanceState retained = (NonConfigurationInstanceState) lastInstance; |
| 388 | mWakeLock = retained.wakelock; |
Ben Komalo | 0460675 | 2011-08-18 14:50:26 -0700 | [diff] [blame] | 389 | Log.d(TAG, "Restoring wakelock from NonConfigurationInstanceState"); |
Andy Stadler | 1499740 | 2011-02-01 15:34:59 -0800 | [diff] [blame] | 390 | } |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 391 | } |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 392 | |
Andy Stadler | 9597406 | 2011-02-01 17:35:20 -0800 | [diff] [blame] | 393 | /** |
| 394 | * Note, we defer the state check and screen setup to onStart() because this will be |
| 395 | * re-run if the user clicks the power button (sleeping/waking the screen), and this is |
| 396 | * especially important if we were to lose the wakelock for any reason. |
| 397 | */ |
| 398 | @Override |
| 399 | public void onStart() { |
| 400 | super.onStart(); |
Ben Komalo | d4758ef | 2011-09-08 14:36:08 -0700 | [diff] [blame] | 401 | setupUi(); |
Ben Komalo | 0e66609 | 2011-09-01 15:42:00 -0700 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | /** |
| 405 | * Initializes the UI based on the current state of encryption. |
| 406 | * This is idempotent - calling repeatedly will simply re-initialize the UI. |
| 407 | */ |
| 408 | private void setupUi() { |
| 409 | if (mEncryptionGoneBad || isDebugView(FORCE_VIEW_ERROR)) { |
| 410 | setContentView(R.layout.crypt_keeper_progress); |
Paul Lawrence | 87abbd3 | 2014-08-28 15:56:38 -0700 | [diff] [blame] | 411 | showFactoryReset(mCorrupt); |
Ben Komalo | 0e66609 | 2011-09-01 15:42:00 -0700 | [diff] [blame] | 412 | return; |
| 413 | } |
| 414 | |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 415 | final String progress = SystemProperties.get("vold.encrypt_progress"); |
Ben Komalo | 0e66609 | 2011-09-01 15:42:00 -0700 | [diff] [blame] | 416 | if (!"".equals(progress) || isDebugView(FORCE_VIEW_PROGRESS)) { |
Andy Stadler | 9597406 | 2011-02-01 17:35:20 -0800 | [diff] [blame] | 417 | setContentView(R.layout.crypt_keeper_progress); |
| 418 | encryptionProgressInit(); |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 419 | } else if (mValidationComplete || isDebugView(FORCE_VIEW_PASSWORD)) { |
Paul Lawrence | 9ac2d81 | 2014-03-18 10:59:18 -0700 | [diff] [blame] | 420 | new AsyncTask<Void, Void, Void>() { |
| 421 | int type = StorageManager.CRYPT_TYPE_PASSWORD; |
| 422 | String owner_info; |
Paul Lawrence | 0f11e15 | 2014-08-20 07:43:32 -0700 | [diff] [blame] | 423 | boolean pattern_visible; |
Paul Lawrence | b05f39d | 2014-02-04 10:22:19 -0800 | [diff] [blame] | 424 | |
Paul Lawrence | 9ac2d81 | 2014-03-18 10:59:18 -0700 | [diff] [blame] | 425 | @Override |
| 426 | public Void doInBackground(Void... v) { |
| 427 | try { |
| 428 | final IMountService service = getMountService(); |
| 429 | type = service.getPasswordType(); |
| 430 | owner_info = service.getField("OwnerInfo"); |
Paul Lawrence | 0f11e15 | 2014-08-20 07:43:32 -0700 | [diff] [blame] | 431 | pattern_visible = !("0".equals(service.getField("PatternVisible"))); |
Paul Lawrence | 9ac2d81 | 2014-03-18 10:59:18 -0700 | [diff] [blame] | 432 | } catch (Exception e) { |
| 433 | Log.e(TAG, "Error calling mount service " + e); |
| 434 | } |
| 435 | |
| 436 | return null; |
| 437 | } |
| 438 | |
| 439 | @Override |
| 440 | public void onPostExecute(java.lang.Void v) { |
| 441 | if(type == StorageManager.CRYPT_TYPE_PIN) { |
| 442 | setContentView(R.layout.crypt_keeper_pin_entry); |
Paul Lawrence | 5a70f05 | 2014-06-13 11:09:55 -0700 | [diff] [blame] | 443 | mStatusString = R.string.enter_pin; |
Paul Lawrence | 9ac2d81 | 2014-03-18 10:59:18 -0700 | [diff] [blame] | 444 | } else if (type == StorageManager.CRYPT_TYPE_PATTERN) { |
| 445 | setContentView(R.layout.crypt_keeper_pattern_entry); |
| 446 | setBackFunctionality(false); |
Paul Lawrence | 5a70f05 | 2014-06-13 11:09:55 -0700 | [diff] [blame] | 447 | mStatusString = R.string.enter_pattern; |
Paul Lawrence | 9ac2d81 | 2014-03-18 10:59:18 -0700 | [diff] [blame] | 448 | } else { |
| 449 | setContentView(R.layout.crypt_keeper_password_entry); |
Paul Lawrence | 5a70f05 | 2014-06-13 11:09:55 -0700 | [diff] [blame] | 450 | mStatusString = R.string.enter_password; |
Paul Lawrence | 9ac2d81 | 2014-03-18 10:59:18 -0700 | [diff] [blame] | 451 | } |
Paul Lawrence | 5a70f05 | 2014-06-13 11:09:55 -0700 | [diff] [blame] | 452 | final TextView status = (TextView) findViewById(R.id.status); |
| 453 | status.setText(mStatusString); |
Paul Lawrence | 9ac2d81 | 2014-03-18 10:59:18 -0700 | [diff] [blame] | 454 | |
Paul Lawrence | 5a70f05 | 2014-06-13 11:09:55 -0700 | [diff] [blame] | 455 | final TextView ownerInfo = (TextView) findViewById(R.id.owner_info); |
| 456 | ownerInfo.setText(owner_info); |
| 457 | ownerInfo.setSelected(true); // Required for marquee'ing to work |
| 458 | |
Paul Lawrence | 9ac2d81 | 2014-03-18 10:59:18 -0700 | [diff] [blame] | 459 | passwordEntryInit(); |
Paul Lawrence | 5a70f05 | 2014-06-13 11:09:55 -0700 | [diff] [blame] | 460 | |
Paul Lawrence | 0f11e15 | 2014-08-20 07:43:32 -0700 | [diff] [blame] | 461 | if (mLockPatternView != null) { |
| 462 | mLockPatternView.setInStealthMode(!pattern_visible); |
| 463 | } |
| 464 | |
Paul Lawrence | 5a70f05 | 2014-06-13 11:09:55 -0700 | [diff] [blame] | 465 | if (mCooldown > 0) { |
| 466 | setBackFunctionality(false); |
| 467 | cooldown(); // in case we are cooling down and coming back from emergency dialler |
| 468 | } |
Paul Lawrence | 9ac2d81 | 2014-03-18 10:59:18 -0700 | [diff] [blame] | 469 | } |
| 470 | }.execute(); |
Ben Komalo | d4758ef | 2011-09-08 14:36:08 -0700 | [diff] [blame] | 471 | } else if (!mValidationRequested) { |
| 472 | // We're supposed to be encrypted, but no validation has been done. |
| 473 | new ValidationTask().execute((Void[]) null); |
| 474 | mValidationRequested = true; |
Andy Stadler | 9597406 | 2011-02-01 17:35:20 -0800 | [diff] [blame] | 475 | } |
| 476 | } |
| 477 | |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 478 | @Override |
| 479 | public void onStop() { |
| 480 | super.onStop(); |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 481 | mHandler.removeMessages(MESSAGE_COOLDOWN); |
| 482 | mHandler.removeMessages(MESSAGE_UPDATE_PROGRESS); |
| 483 | mHandler.removeMessages(MESSAGE_NOTIFY); |
Andy Stadler | 1499740 | 2011-02-01 15:34:59 -0800 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | /** |
| 487 | * Reconfiguring, so propagate the wakelock to the next instance. This runs between onStop() |
| 488 | * and onDestroy() and only if we are changing configuration (e.g. rotation). Also clears |
| 489 | * mWakeLock so the subsequent call to onDestroy does not release it. |
| 490 | */ |
| 491 | @Override |
| 492 | public Object onRetainNonConfigurationInstance() { |
| 493 | NonConfigurationInstanceState state = new NonConfigurationInstanceState(mWakeLock); |
Ben Komalo | 0460675 | 2011-08-18 14:50:26 -0700 | [diff] [blame] | 494 | Log.d(TAG, "Handing wakelock off to NonConfigurationInstanceState"); |
Andy Stadler | 1499740 | 2011-02-01 15:34:59 -0800 | [diff] [blame] | 495 | mWakeLock = null; |
| 496 | return state; |
| 497 | } |
| 498 | |
| 499 | @Override |
| 500 | public void onDestroy() { |
| 501 | super.onDestroy(); |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 502 | |
| 503 | if (mWakeLock != null) { |
Ben Komalo | 0460675 | 2011-08-18 14:50:26 -0700 | [diff] [blame] | 504 | Log.d(TAG, "Releasing and destroying wakelock"); |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 505 | mWakeLock.release(); |
| 506 | mWakeLock = null; |
| 507 | } |
| 508 | } |
| 509 | |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 510 | /** |
| 511 | * Start encrypting the device. |
| 512 | */ |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 513 | private void encryptionProgressInit() { |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 514 | // Accquire a partial wakelock to prevent the device from sleeping. Note |
| 515 | // we never release this wakelock as we will be restarted after the device |
| 516 | // is encrypted. |
Ben Komalo | 0460675 | 2011-08-18 14:50:26 -0700 | [diff] [blame] | 517 | Log.d(TAG, "Encryption progress screen initializing."); |
Ben Komalo | 9ee164f | 2011-09-21 10:40:50 -0700 | [diff] [blame] | 518 | if (mWakeLock == null) { |
Ben Komalo | 0460675 | 2011-08-18 14:50:26 -0700 | [diff] [blame] | 519 | Log.d(TAG, "Acquiring wakelock."); |
| 520 | PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); |
| 521 | mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, TAG); |
| 522 | mWakeLock.acquire(); |
| 523 | } |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 524 | |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 525 | ((ProgressBar) findViewById(R.id.progress_bar)).setIndeterminate(true); |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 526 | // Ignore all back presses from now, both hard and soft keys. |
Vikram Aggarwal | bf459da | 2012-11-08 16:54:59 -0800 | [diff] [blame] | 527 | setBackFunctionality(false); |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 528 | // Start the first run of progress manually. This method sets up messages to occur at |
| 529 | // repeated intervals. |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 530 | updateProgress(); |
| 531 | } |
| 532 | |
Paul Lawrence | 384d8e5 | 2014-08-08 15:11:36 -0700 | [diff] [blame] | 533 | /** |
| 534 | * Show factory reset screen allowing the user to reset their phone when |
| 535 | * there is nothing else we can do |
| 536 | * @param corrupt true if userdata is corrupt, false if encryption failed |
| 537 | * partway through |
| 538 | */ |
| 539 | private void showFactoryReset(boolean corrupt) { |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 540 | // Hide the encryption-bot to make room for the "factory reset" button |
| 541 | findViewById(R.id.encroid).setVisibility(View.GONE); |
| 542 | |
| 543 | // Show the reset button, failure text, and a divider |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 544 | final Button button = (Button) findViewById(R.id.factory_reset); |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 545 | button.setVisibility(View.VISIBLE); |
| 546 | button.setOnClickListener(new OnClickListener() { |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 547 | @Override |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 548 | public void onClick(View v) { |
| 549 | // Factory reset the device. |
| 550 | sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR")); |
| 551 | } |
| 552 | }); |
| 553 | |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 554 | // Alert the user of the failure. |
Paul Lawrence | 384d8e5 | 2014-08-08 15:11:36 -0700 | [diff] [blame] | 555 | if (corrupt) { |
| 556 | ((TextView) findViewById(R.id.title)).setText(R.string.crypt_keeper_data_corrupt_title); |
| 557 | ((TextView) findViewById(R.id.status)).setText(R.string.crypt_keeper_data_corrupt_summary); |
| 558 | } else { |
| 559 | ((TextView) findViewById(R.id.title)).setText(R.string.crypt_keeper_failed_title); |
| 560 | ((TextView) findViewById(R.id.status)).setText(R.string.crypt_keeper_failed_summary); |
| 561 | } |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 562 | |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 563 | final View view = findViewById(R.id.bottom_divider); |
| 564 | // 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] | 565 | if (view != null) { |
| 566 | view.setVisibility(View.VISIBLE); |
| 567 | } |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 568 | } |
| 569 | |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 570 | private void updateProgress() { |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 571 | final String state = SystemProperties.get("vold.encrypt_progress"); |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 572 | |
Ben Komalo | 0e66609 | 2011-09-01 15:42:00 -0700 | [diff] [blame] | 573 | if ("error_partially_encrypted".equals(state)) { |
Paul Lawrence | 384d8e5 | 2014-08-08 15:11:36 -0700 | [diff] [blame] | 574 | showFactoryReset(false); |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 575 | return; |
| 576 | } |
| 577 | |
Paul Lawrence | b15c68f | 2014-06-05 07:24:23 -0700 | [diff] [blame] | 578 | // Get status as percentage first |
| 579 | CharSequence status = getText(R.string.crypt_keeper_setup_description); |
| 580 | int percent = 0; |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 581 | try { |
Ben Komalo | 91a2f05 | 2011-08-16 17:48:25 -0700 | [diff] [blame] | 582 | // Force a 50% progress state when debugging the view. |
Paul Lawrence | b15c68f | 2014-06-05 07:24:23 -0700 | [diff] [blame] | 583 | percent = isDebugView() ? 50 : Integer.parseInt(state); |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 584 | } catch (Exception e) { |
| 585 | Log.w(TAG, "Error parsing progress: " + e.toString()); |
| 586 | } |
Paul Lawrence | b15c68f | 2014-06-05 07:24:23 -0700 | [diff] [blame] | 587 | String progress = Integer.toString(percent); |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 588 | |
Paul Lawrence | b15c68f | 2014-06-05 07:24:23 -0700 | [diff] [blame] | 589 | // Now try to get status as time remaining and replace as appropriate |
Ben Komalo | 0460675 | 2011-08-18 14:50:26 -0700 | [diff] [blame] | 590 | Log.v(TAG, "Encryption progress: " + progress); |
Paul Lawrence | b15c68f | 2014-06-05 07:24:23 -0700 | [diff] [blame] | 591 | try { |
| 592 | final String timeProperty = SystemProperties.get("vold.encrypt_time_remaining"); |
| 593 | int time = Integer.parseInt(timeProperty); |
| 594 | if (time >= 0) { |
| 595 | // Round up to multiple of 10 - this way display is less jerky |
| 596 | time = (time + 9) / 10 * 10; |
| 597 | progress = DateUtils.formatElapsedTime(time); |
| 598 | status = getText(R.string.crypt_keeper_setup_time_remaining); |
| 599 | } |
| 600 | } catch (Exception e) { |
| 601 | // Will happen if no time etc - show percentage |
| 602 | } |
| 603 | |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 604 | final TextView tv = (TextView) findViewById(R.id.status); |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 605 | if (tv != null) { |
Paul Lawrence | b15c68f | 2014-06-05 07:24:23 -0700 | [diff] [blame] | 606 | tv.setText(TextUtils.expandTemplate(status, progress)); |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 607 | } |
Paul Lawrence | b15c68f | 2014-06-05 07:24:23 -0700 | [diff] [blame] | 608 | |
| 609 | // Check the progress every 1 seconds |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 610 | mHandler.removeMessages(MESSAGE_UPDATE_PROGRESS); |
Paul Lawrence | b15c68f | 2014-06-05 07:24:23 -0700 | [diff] [blame] | 611 | mHandler.sendEmptyMessageDelayed(MESSAGE_UPDATE_PROGRESS, 1000); |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 612 | } |
| 613 | |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 614 | /** 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] | 615 | private void cooldown() { |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 616 | final TextView status = (TextView) findViewById(R.id.status); |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 617 | |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 618 | if (mCooldown <= 0) { |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 619 | // Re-enable the password entry and back presses. |
Paul Lawrence | 2daf264 | 2014-03-14 09:20:24 -0700 | [diff] [blame] | 620 | if (mPasswordEntry != null) { |
| 621 | mPasswordEntry.setEnabled(true); |
Paul Lawrence | 5a70f05 | 2014-06-13 11:09:55 -0700 | [diff] [blame] | 622 | final InputMethodManager imm = (InputMethodManager) getSystemService( |
| 623 | Context.INPUT_METHOD_SERVICE); |
| 624 | imm.showSoftInput(mPasswordEntry, 0); |
Paul Lawrence | 2daf264 | 2014-03-14 09:20:24 -0700 | [diff] [blame] | 625 | setBackFunctionality(true); |
| 626 | } |
| 627 | if (mLockPatternView != null) { |
| 628 | mLockPatternView.setEnabled(true); |
| 629 | } |
Paul Lawrence | 5a70f05 | 2014-06-13 11:09:55 -0700 | [diff] [blame] | 630 | status.setText(mStatusString); |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 631 | } else { |
Paul Lawrence | 5a70f05 | 2014-06-13 11:09:55 -0700 | [diff] [blame] | 632 | // Disable the password entry and back presses. |
| 633 | if (mPasswordEntry != null) { |
| 634 | mPasswordEntry.setEnabled(false); |
| 635 | } |
| 636 | if (mLockPatternView != null) { |
| 637 | mLockPatternView.setEnabled(false); |
| 638 | } |
| 639 | |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 640 | CharSequence template = getText(R.string.crypt_keeper_cooldown); |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 641 | status.setText(TextUtils.expandTemplate(template, Integer.toString(mCooldown))); |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 642 | |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 643 | mCooldown--; |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 644 | mHandler.removeMessages(MESSAGE_COOLDOWN); |
| 645 | mHandler.sendEmptyMessageDelayed(MESSAGE_COOLDOWN, 1000); // Tick every second |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 646 | } |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 647 | } |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 648 | |
Vikram Aggarwal | bf459da | 2012-11-08 16:54:59 -0800 | [diff] [blame] | 649 | /** |
| 650 | * Sets the back status: enabled or disabled according to the parameter. |
| 651 | * @param isEnabled true if back is enabled, false otherwise. |
| 652 | */ |
| 653 | private final void setBackFunctionality(boolean isEnabled) { |
| 654 | mIgnoreBack = !isEnabled; |
| 655 | if (isEnabled) { |
| 656 | mStatusBar.disable(sWidgetsToDisable); |
| 657 | } else { |
| 658 | mStatusBar.disable(sWidgetsToDisable | StatusBarManager.DISABLE_BACK); |
| 659 | } |
| 660 | } |
| 661 | |
Paul Lawrence | b05f39d | 2014-02-04 10:22:19 -0800 | [diff] [blame] | 662 | protected LockPatternView.OnPatternListener mChooseNewLockPatternListener = |
Paul Lawrence | f6cda3b | 2014-06-12 08:26:08 -0700 | [diff] [blame] | 663 | new LockPatternView.OnPatternListener() { |
Paul Lawrence | b05f39d | 2014-02-04 10:22:19 -0800 | [diff] [blame] | 664 | |
Paul Lawrence | f6cda3b | 2014-06-12 08:26:08 -0700 | [diff] [blame] | 665 | @Override |
| 666 | public void onPatternStart() { |
| 667 | mLockPatternView.removeCallbacks(mClearPatternRunnable); |
| 668 | } |
Paul Lawrence | b05f39d | 2014-02-04 10:22:19 -0800 | [diff] [blame] | 669 | |
Paul Lawrence | f6cda3b | 2014-06-12 08:26:08 -0700 | [diff] [blame] | 670 | @Override |
| 671 | public void onPatternCleared() { |
| 672 | } |
Paul Lawrence | b05f39d | 2014-02-04 10:22:19 -0800 | [diff] [blame] | 673 | |
Paul Lawrence | f6cda3b | 2014-06-12 08:26:08 -0700 | [diff] [blame] | 674 | @Override |
| 675 | public void onPatternDetected(List<LockPatternView.Cell> pattern) { |
| 676 | mLockPatternView.setEnabled(false); |
| 677 | new DecryptTask().execute(LockPatternUtils.patternToString(pattern)); |
| 678 | } |
Paul Lawrence | b05f39d | 2014-02-04 10:22:19 -0800 | [diff] [blame] | 679 | |
Paul Lawrence | f6cda3b | 2014-06-12 08:26:08 -0700 | [diff] [blame] | 680 | @Override |
| 681 | public void onPatternCellAdded(List<Cell> pattern) { |
| 682 | } |
Paul Lawrence | b05f39d | 2014-02-04 10:22:19 -0800 | [diff] [blame] | 683 | }; |
| 684 | |
| 685 | private void passwordEntryInit() { |
| 686 | // Password/pin case |
Jason parks | 06c5ff4 | 2011-03-01 10:17:40 -0600 | [diff] [blame] | 687 | mPasswordEntry = (EditText) findViewById(R.id.passwordEntry); |
Paul Lawrence | b05f39d | 2014-02-04 10:22:19 -0800 | [diff] [blame] | 688 | if (mPasswordEntry != null){ |
| 689 | mPasswordEntry.setOnEditorActionListener(this); |
| 690 | mPasswordEntry.requestFocus(); |
| 691 | // Become quiet when the user interacts with the Edit text screen. |
| 692 | mPasswordEntry.setOnKeyListener(this); |
| 693 | mPasswordEntry.setOnTouchListener(this); |
| 694 | mPasswordEntry.addTextChangedListener(this); |
| 695 | } |
| 696 | |
| 697 | // Pattern case |
| 698 | mLockPatternView = (LockPatternView) findViewById(R.id.lockPattern); |
| 699 | if (mLockPatternView != null) { |
| 700 | mLockPatternView.setOnPatternListener(mChooseNewLockPatternListener); |
| 701 | } |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 702 | |
Vikram Aggarwal | c62d321 | 2012-05-02 16:29:10 -0700 | [diff] [blame] | 703 | // Disable the Emergency call button if the device has no voice telephone capability |
Santos Cordon | 3afbdf0 | 2014-05-29 21:48:16 -0700 | [diff] [blame] | 704 | if (!getTelephonyManager().isVoiceCapable()) { |
Vikram Aggarwal | c62d321 | 2012-05-02 16:29:10 -0700 | [diff] [blame] | 705 | final View emergencyCall = findViewById(R.id.emergencyCallButton); |
| 706 | if (emergencyCall != null) { |
| 707 | Log.d(TAG, "Removing the emergency Call button"); |
| 708 | emergencyCall.setVisibility(View.GONE); |
| 709 | } |
| 710 | } |
| 711 | |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 712 | final View imeSwitcher = findViewById(R.id.switch_ime_button); |
Ben Komalo | 9fcb6a7 | 2011-08-26 14:40:18 -0700 | [diff] [blame] | 713 | final InputMethodManager imm = (InputMethodManager) getSystemService( |
| 714 | Context.INPUT_METHOD_SERVICE); |
| 715 | if (imeSwitcher != null && hasMultipleEnabledIMEsOrSubtypes(imm, false)) { |
| 716 | imeSwitcher.setVisibility(View.VISIBLE); |
| 717 | imeSwitcher.setOnClickListener(new OnClickListener() { |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 718 | @Override |
Ben Komalo | 9fcb6a7 | 2011-08-26 14:40:18 -0700 | [diff] [blame] | 719 | public void onClick(View v) { |
| 720 | imm.showInputMethodPicker(); |
| 721 | } |
| 722 | }); |
Jason parks | 00046d6 | 2011-06-13 17:38:45 -0500 | [diff] [blame] | 723 | } |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 724 | |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 725 | // We want to keep the screen on while waiting for input. In minimal boot mode, the device |
| 726 | // is completely non-functional, and we want the user to notice the device and enter a |
| 727 | // password. |
| 728 | if (mWakeLock == null) { |
| 729 | Log.d(TAG, "Acquiring wakelock."); |
| 730 | final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); |
| 731 | if (pm != null) { |
| 732 | mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, TAG); |
| 733 | mWakeLock.acquire(); |
Paul Lawrence | 73456ac | 2014-05-16 07:56:04 -0700 | [diff] [blame] | 734 | // Keep awake for 10 minutes - if the user hasn't been alerted by then |
| 735 | // best not to just drain their battery |
Paul Lawrence | 5a70f05 | 2014-06-13 11:09:55 -0700 | [diff] [blame] | 736 | mReleaseWakeLockCountdown = 96; // 96 * 5 secs per click + 120 secs before we show this = 600 |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 737 | } |
| 738 | } |
Paul Lawrence | 73456ac | 2014-05-16 07:56:04 -0700 | [diff] [blame] | 739 | |
Ben Komalo | 9fcb6a7 | 2011-08-26 14:40:18 -0700 | [diff] [blame] | 740 | // Asynchronously throw up the IME, since there are issues with requesting it to be shown |
| 741 | // immediately. |
Paul Lawrence | 5a70f05 | 2014-06-13 11:09:55 -0700 | [diff] [blame] | 742 | if (mLockPatternView == null && mCooldown <= 0) { |
Paul Lawrence | e54e932 | 2014-03-13 14:05:48 -0700 | [diff] [blame] | 743 | mHandler.postDelayed(new Runnable() { |
| 744 | @Override public void run() { |
| 745 | imm.showSoftInputUnchecked(0, null); |
| 746 | } |
| 747 | }, 0); |
| 748 | } |
Ben Komalo | 9fcb6a7 | 2011-08-26 14:40:18 -0700 | [diff] [blame] | 749 | |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 750 | updateEmergencyCallButtonState(); |
Vikram Aggarwal | d114725 | 2012-05-08 13:52:30 -0700 | [diff] [blame] | 751 | // Notify the user in 120 seconds that we are waiting for him to enter the password. |
Vikram Aggarwal | 86b9393 | 2012-05-01 16:46:06 -0700 | [diff] [blame] | 752 | mHandler.removeMessages(MESSAGE_NOTIFY); |
Vikram Aggarwal | d114725 | 2012-05-08 13:52:30 -0700 | [diff] [blame] | 753 | mHandler.sendEmptyMessageDelayed(MESSAGE_NOTIFY, 120 * 1000); |
Jim Miller | fb3d5ca | 2013-11-14 14:40:22 -0800 | [diff] [blame] | 754 | |
John Spurlock | 2c52651 | 2014-09-17 12:55:17 -0400 | [diff] [blame^] | 755 | // Dismiss secure & non-secure keyguards while this screen is showing. |
| 756 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 757 | | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 758 | } |
| 759 | |
Ben Komalo | 9fcb6a7 | 2011-08-26 14:40:18 -0700 | [diff] [blame] | 760 | /** |
| 761 | * Method adapted from com.android.inputmethod.latin.Utils |
| 762 | * |
| 763 | * @param imm The input method manager |
| 764 | * @param shouldIncludeAuxiliarySubtypes |
| 765 | * @return true if we have multiple IMEs to choose from |
| 766 | */ |
| 767 | private boolean hasMultipleEnabledIMEsOrSubtypes(InputMethodManager imm, |
| 768 | final boolean shouldIncludeAuxiliarySubtypes) { |
| 769 | final List<InputMethodInfo> enabledImis = imm.getEnabledInputMethodList(); |
| 770 | |
| 771 | // Number of the filtered IMEs |
| 772 | int filteredImisCount = 0; |
| 773 | |
| 774 | for (InputMethodInfo imi : enabledImis) { |
| 775 | // We can return true immediately after we find two or more filtered IMEs. |
| 776 | if (filteredImisCount > 1) return true; |
| 777 | final List<InputMethodSubtype> subtypes = |
| 778 | imm.getEnabledInputMethodSubtypeList(imi, true); |
| 779 | // IMEs that have no subtypes should be counted. |
| 780 | if (subtypes.isEmpty()) { |
| 781 | ++filteredImisCount; |
| 782 | continue; |
| 783 | } |
| 784 | |
| 785 | int auxCount = 0; |
| 786 | for (InputMethodSubtype subtype : subtypes) { |
| 787 | if (subtype.isAuxiliary()) { |
| 788 | ++auxCount; |
| 789 | } |
| 790 | } |
| 791 | final int nonAuxCount = subtypes.size() - auxCount; |
| 792 | |
| 793 | // IMEs that have one or more non-auxiliary subtypes should be counted. |
| 794 | // If shouldIncludeAuxiliarySubtypes is true, IMEs that have two or more auxiliary |
| 795 | // subtypes should be counted as well. |
| 796 | if (nonAuxCount > 0 || (shouldIncludeAuxiliarySubtypes && auxCount > 1)) { |
| 797 | ++filteredImisCount; |
| 798 | continue; |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | return filteredImisCount > 1 |
| 803 | // imm.getEnabledInputMethodSubtypeList(null, false) will return the current IME's enabled |
| 804 | // input method subtype (The current IME should be LatinIME.) |
| 805 | || imm.getEnabledInputMethodSubtypeList(null, false).size() > 1; |
| 806 | } |
| 807 | |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 808 | private IMountService getMountService() { |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 809 | final IBinder service = ServiceManager.getService("mount"); |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 810 | if (service != null) { |
| 811 | return IMountService.Stub.asInterface(service); |
| 812 | } |
| 813 | return null; |
| 814 | } |
| 815 | |
| 816 | @Override |
| 817 | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { |
Jason parks | 00046d6 | 2011-06-13 17:38:45 -0500 | [diff] [blame] | 818 | if (actionId == EditorInfo.IME_NULL || actionId == EditorInfo.IME_ACTION_DONE) { |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 819 | // Get the password |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 820 | final String password = v.getText().toString(); |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 821 | |
Jason parks | ec5a45e | 2011-01-18 15:28:36 -0600 | [diff] [blame] | 822 | if (TextUtils.isEmpty(password)) { |
| 823 | return true; |
| 824 | } |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 825 | |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 826 | // Now that we have the password clear the password field. |
| 827 | v.setText(null); |
| 828 | |
Vikram Aggarwal | de3c9cb | 2012-05-01 15:37:30 -0700 | [diff] [blame] | 829 | // Disable the password entry and back keypress while checking the password. These |
| 830 | // 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] | 831 | mPasswordEntry.setEnabled(false); |
Vikram Aggarwal | bf459da | 2012-11-08 16:54:59 -0800 | [diff] [blame] | 832 | setBackFunctionality(false); |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 833 | |
Ben Komalo | 0460675 | 2011-08-18 14:50:26 -0700 | [diff] [blame] | 834 | Log.d(TAG, "Attempting to send command to decrypt"); |
Jason parks | 06c5ff4 | 2011-03-01 10:17:40 -0600 | [diff] [blame] | 835 | new DecryptTask().execute(password); |
Jason parks | 3593381 | 2011-01-21 15:48:20 -0600 | [diff] [blame] | 836 | |
Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame] | 837 | return true; |
| 838 | } |
| 839 | return false; |
| 840 | } |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 841 | |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 842 | /** |
Vikram Aggarwal | ea1186d | 2012-05-03 15:35:03 -0700 | [diff] [blame] | 843 | * Set airplane mode on the device if it isn't an LTE device. |
| 844 | * Full story: In minimal boot mode, we cannot save any state. In particular, we cannot save |
| 845 | * any incoming SMS's. So SMSs that are received here will be silently dropped to the floor. |
| 846 | * That is bad. Also, we cannot receive any telephone calls in this state. So to avoid |
| 847 | * both these problems, we turn the radio off. However, on certain networks turning on and |
| 848 | * off the radio takes a long time. In such cases, we are better off leaving the radio |
| 849 | * running so the latency of an E911 call is short. |
| 850 | * The behavior after this is: |
| 851 | * 1. Emergency dialing: the emergency dialer has logic to force the device out of |
| 852 | * airplane mode and restart the radio. |
| 853 | * 2. Full boot: we read the persistent settings from the previous boot and restore the |
| 854 | * radio to whatever it was before it restarted. This also happens when rebooting a |
| 855 | * phone that has no encryption. |
| 856 | */ |
| 857 | private final void setAirplaneModeIfNecessary() { |
| 858 | final boolean isLteDevice = |
Santos Cordon | 3afbdf0 | 2014-05-29 21:48:16 -0700 | [diff] [blame] | 859 | getTelephonyManager().getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_TRUE; |
Vikram Aggarwal | ea1186d | 2012-05-03 15:35:03 -0700 | [diff] [blame] | 860 | if (!isLteDevice) { |
| 861 | Log.d(TAG, "Going into airplane mode."); |
Christopher Tate | 6a5929b | 2012-09-10 15:39:05 -0700 | [diff] [blame] | 862 | Settings.Global.putInt(getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1); |
Vikram Aggarwal | ea1186d | 2012-05-03 15:35:03 -0700 | [diff] [blame] | 863 | final Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); |
| 864 | intent.putExtra("state", true); |
Christopher Tate | 6a5929b | 2012-09-10 15:39:05 -0700 | [diff] [blame] | 865 | sendBroadcastAsUser(intent, UserHandle.ALL); |
Vikram Aggarwal | ea1186d | 2012-05-03 15:35:03 -0700 | [diff] [blame] | 866 | } |
| 867 | } |
| 868 | |
| 869 | /** |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 870 | * Code to update the state of, and handle clicks from, the "Emergency call" button. |
| 871 | * |
| 872 | * This code is mostly duplicated from the corresponding code in |
| 873 | * LockPatternUtils and LockPatternKeyguardView under frameworks/base. |
| 874 | */ |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 875 | private void updateEmergencyCallButtonState() { |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 876 | final Button emergencyCall = (Button) findViewById(R.id.emergencyCallButton); |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 877 | // The button isn't present at all in some configurations. |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 878 | if (emergencyCall == null) |
| 879 | return; |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 880 | |
| 881 | if (isEmergencyCallCapable()) { |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 882 | emergencyCall.setVisibility(View.VISIBLE); |
| 883 | emergencyCall.setOnClickListener(new View.OnClickListener() { |
| 884 | @Override |
| 885 | |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 886 | public void onClick(View v) { |
| 887 | takeEmergencyCallAction(); |
| 888 | } |
| 889 | }); |
| 890 | } else { |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 891 | emergencyCall.setVisibility(View.GONE); |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 892 | return; |
| 893 | } |
| 894 | |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 895 | int textId; |
Tyler Gunn | 3e71b19 | 2014-09-10 15:21:33 -0700 | [diff] [blame] | 896 | if (getTelecomManager().isInCall()) { |
Paul Lawrence | 89c7570 | 2014-07-11 07:34:44 -0700 | [diff] [blame] | 897 | // Show "return to call" |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 898 | textId = R.string.cryptkeeper_return_to_call; |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 899 | } else { |
| 900 | textId = R.string.cryptkeeper_emergency_call; |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 901 | } |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 902 | emergencyCall.setText(textId); |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | private boolean isEmergencyCallCapable() { |
| 906 | return getResources().getBoolean(com.android.internal.R.bool.config_voice_capable); |
| 907 | } |
| 908 | |
| 909 | private void takeEmergencyCallAction() { |
Tyler Gunn | 3e71b19 | 2014-09-10 15:21:33 -0700 | [diff] [blame] | 910 | TelecomManager telecomManager = getTelecomManager(); |
| 911 | if (telecomManager.isInCall()) { |
| 912 | telecomManager.showInCallScreen(false /* showDialpad */); |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 913 | } else { |
| 914 | launchEmergencyDialer(); |
| 915 | } |
| 916 | } |
| 917 | |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 918 | |
| 919 | private void launchEmergencyDialer() { |
Vikram Aggarwal | bfa3a64 | 2012-03-29 14:07:22 -0700 | [diff] [blame] | 920 | final Intent intent = new Intent(ACTION_EMERGENCY_DIAL); |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 921 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 922 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
Paul Lawrence | 5a70f05 | 2014-06-13 11:09:55 -0700 | [diff] [blame] | 923 | setBackFunctionality(true); |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 924 | startActivity(intent); |
| 925 | } |
Vikram Aggarwal | d114725 | 2012-05-08 13:52:30 -0700 | [diff] [blame] | 926 | |
Santos Cordon | 3afbdf0 | 2014-05-29 21:48:16 -0700 | [diff] [blame] | 927 | private TelephonyManager getTelephonyManager() { |
| 928 | return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); |
| 929 | } |
| 930 | |
Tyler Gunn | 3e71b19 | 2014-09-10 15:21:33 -0700 | [diff] [blame] | 931 | private TelecomManager getTelecomManager() { |
| 932 | return (TelecomManager) getSystemService(Context.TELECOM_SERVICE); |
Santos Cordon | 35230e9 | 2014-07-07 16:25:10 -0700 | [diff] [blame] | 933 | } |
| 934 | |
Vikram Aggarwal | d114725 | 2012-05-08 13:52:30 -0700 | [diff] [blame] | 935 | /** |
| 936 | * Listen to key events so we can disable sounds when we get a keyinput in EditText. |
| 937 | */ |
| 938 | private void delayAudioNotification() { |
Vikram Aggarwal | d114725 | 2012-05-08 13:52:30 -0700 | [diff] [blame] | 939 | mNotificationCountdown = 20; |
| 940 | } |
| 941 | |
| 942 | @Override |
| 943 | public boolean onKey(View v, int keyCode, KeyEvent event) { |
| 944 | delayAudioNotification(); |
| 945 | return false; |
| 946 | } |
| 947 | |
| 948 | @Override |
| 949 | public boolean onTouch(View v, MotionEvent event) { |
| 950 | delayAudioNotification(); |
| 951 | return false; |
| 952 | } |
| 953 | |
| 954 | @Override |
| 955 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| 956 | return; |
| 957 | } |
| 958 | |
| 959 | @Override |
| 960 | public void onTextChanged(CharSequence s, int start, int before, int count) { |
| 961 | delayAudioNotification(); |
| 962 | } |
| 963 | |
| 964 | @Override |
| 965 | public void afterTextChanged(Editable s) { |
| 966 | return; |
| 967 | } |
David Brown | 8373b45 | 2011-06-20 12:38:45 -0700 | [diff] [blame] | 968 | } |