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