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