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