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