CryptKeeper.java revision 384d8e52b6750b2be7079f8828e4d2f038e22180
18fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks/* 28fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks * Copyright (C) 2011 The Android Open Source Project 38fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks * 48fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks * Licensed under the Apache License, Version 2.0 (the "License"); 58fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks * you may not use this file except in compliance with the License. 68fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks * You may obtain a copy of the License at 78fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks * 88fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks * http://www.apache.org/licenses/LICENSE-2.0 98fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks * 108fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks * Unless required by applicable law or agreed to in writing, software 118fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks * distributed under the License is distributed on an "AS IS" BASIS, 128fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 138fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks * See the License for the specific language governing permissions and 148fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks * limitations under the License. 158fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks */ 168fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks 178fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parkspackage com.android.settings; 188fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks 198fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parksimport android.app.Activity; 208fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parksimport android.app.StatusBarManager; 218fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parksimport android.content.ComponentName; 228fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parksimport android.content.Context; 23ec5a45e79cb7161adfabf475342c1e1b25994276Jason parksimport android.content.Intent; 247ae20e3ce98543888cfccbef6b1254d060bc30caPaul Lawrenceimport android.content.pm.ActivityInfo; 258fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parksimport android.content.pm.PackageManager; 267ae20e3ce98543888cfccbef6b1254d060bc30caPaul Lawrenceimport android.content.res.Resources.NotFoundException; 27de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwalimport android.media.AudioManager; 2806c5ff4a46686d3f599e40df0768177d3d88913cJason parksimport android.os.AsyncTask; 298fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parksimport android.os.Bundle; 30ec5a45e79cb7161adfabf475342c1e1b25994276Jason parksimport android.os.Handler; 318fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parksimport android.os.IBinder; 32ec5a45e79cb7161adfabf475342c1e1b25994276Jason parksimport android.os.Message; 3335933812b16f0b4221280bbcc3c32f6540996bf2Jason parksimport android.os.PowerManager; 348373b451692a39abdfd12444241c016831e1a4a4David Brownimport android.os.RemoteException; 358fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parksimport android.os.ServiceManager; 368fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parksimport android.os.SystemProperties; 376a5929b086a61a955a4a2f43f5fa251e8754ff4aChristopher Tateimport android.os.UserHandle; 388fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parksimport android.os.storage.IMountService; 39b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrenceimport android.os.storage.StorageManager; 4035230e9ed76de518c7ea46d9277bdc8fa765efd8Santos Cordon 4135230e9ed76de518c7ea46d9277bdc8fa765efd8Santos Cordonimport android.phone.PhoneManager; 426ebbd30e18ca514ca9ee87ffa428c55c9fd92a8cVikram Aggarwalimport android.provider.Settings; 438373b451692a39abdfd12444241c016831e1a4a4David Brownimport android.telephony.TelephonyManager; 44d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwalimport android.text.Editable; 45ec5a45e79cb7161adfabf475342c1e1b25994276Jason parksimport android.text.TextUtils; 46d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwalimport android.text.TextWatcher; 47b15c68fbf19c021eb0a3bed1ccc4dd7fda384ec7Paul Lawrenceimport android.text.format.DateUtils; 488fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parksimport android.util.Log; 498fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parksimport android.view.KeyEvent; 50d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwalimport android.view.MotionEvent; 5113d62049f7c96c47356f23eaee7f0997612fdf9fAndy Stadlerimport android.view.View; 52fb3d5cad48876dbd366fd8b562529d355d2428dbJim Millerimport android.view.WindowManager; 5313d62049f7c96c47356f23eaee7f0997612fdf9fAndy Stadlerimport android.view.View.OnClickListener; 54d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwalimport android.view.View.OnKeyListener; 55d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwalimport android.view.View.OnTouchListener; 568fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parksimport android.view.inputmethod.EditorInfo; 579fcb6a7fac02aef85085c2db616556257e1642f5Ben Komaloimport android.view.inputmethod.InputMethodInfo; 5875c085ee890744cdd4b90c72f8b50e6aeeb31e88Jason parksimport android.view.inputmethod.InputMethodManager; 599fcb6a7fac02aef85085c2db616556257e1642f5Ben Komaloimport android.view.inputmethod.InputMethodSubtype; 6013d62049f7c96c47356f23eaee7f0997612fdf9fAndy Stadlerimport android.widget.Button; 61ec5a45e79cb7161adfabf475342c1e1b25994276Jason parksimport android.widget.EditText; 62ec5a45e79cb7161adfabf475342c1e1b25994276Jason parksimport android.widget.ProgressBar; 638fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parksimport android.widget.TextView; 648fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks 65bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwalimport com.android.internal.statusbar.StatusBarIcon; 66ea1186db19e673b44084b43b6a70bbdb07480aa9Vikram Aggarwalimport com.android.internal.telephony.Phone; 675543404ae0ec9635b59d37fa01074ea598d539ebWink Savilleimport com.android.internal.telephony.PhoneConstants; 68b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrenceimport com.android.internal.widget.LockPatternUtils; 69b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrenceimport com.android.internal.widget.LockPatternView; 70b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrenceimport com.android.internal.widget.LockPatternView.Cell; 719fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo 72f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrenceimport static com.android.internal.widget.LockPatternView.DisplayMode; 73f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence 749fcb6a7fac02aef85085c2db616556257e1642f5Ben Komaloimport java.util.List; 7591a2f0566afb91549cbda9289b516154a6467624Ben Komalo 7691a2f0566afb91549cbda9289b516154a6467624Ben Komalo/** 7791a2f0566afb91549cbda9289b516154a6467624Ben Komalo * Settings screens to show the UI flows for encrypting/decrypting the device. 7891a2f0566afb91549cbda9289b516154a6467624Ben Komalo * 7991a2f0566afb91549cbda9289b516154a6467624Ben Komalo * This may be started via adb for debugging the UI layout, without having to go through 8091a2f0566afb91549cbda9289b516154a6467624Ben Komalo * encryption flows everytime. It should be noted that starting the activity in this manner 8191a2f0566afb91549cbda9289b516154a6467624Ben Komalo * is only useful for verifying UI-correctness - the behavior will not be identical. 8291a2f0566afb91549cbda9289b516154a6467624Ben Komalo * <pre> 8391a2f0566afb91549cbda9289b516154a6467624Ben Komalo * $ adb shell pm enable com.android.settings/.CryptKeeper 8491a2f0566afb91549cbda9289b516154a6467624Ben Komalo * $ adb shell am start \ 8591a2f0566afb91549cbda9289b516154a6467624Ben Komalo * -e "com.android.settings.CryptKeeper.DEBUG_FORCE_VIEW" "progress" \ 8691a2f0566afb91549cbda9289b516154a6467624Ben Komalo * -n com.android.settings/.CryptKeeper 8791a2f0566afb91549cbda9289b516154a6467624Ben Komalo * </pre> 8891a2f0566afb91549cbda9289b516154a6467624Ben Komalo */ 89d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwalpublic class CryptKeeper extends Activity implements TextView.OnEditorActionListener, 90d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal OnKeyListener, OnTouchListener, TextWatcher { 91ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks private static final String TAG = "CryptKeeper"; 9235933812b16f0b4221280bbcc3c32f6540996bf2Jason parks 938fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks private static final String DECRYPT_STATE = "trigger_restart_framework"; 94de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal /** Message sent to us to indicate encryption update progress. */ 95de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal private static final int MESSAGE_UPDATE_PROGRESS = 1; 96de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal /** Message sent to us to cool-down (waste user's time between password attempts) */ 97de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal private static final int MESSAGE_COOLDOWN = 2; 98de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal /** Message sent to us to indicate alerting the user that we are waiting for password entry */ 99de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal private static final int MESSAGE_NOTIFY = 3; 100de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal 101de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal // Constants used to control policy. 102ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks private static final int MAX_FAILED_ATTEMPTS = 30; 103ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks private static final int COOL_DOWN_ATTEMPTS = 10; 104ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks private static final int COOL_DOWN_INTERVAL = 30; // 30 seconds 105ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks 1068373b451692a39abdfd12444241c016831e1a4a4David Brown // Intent action for launching the Emergency Dialer activity. 1078373b451692a39abdfd12444241c016831e1a4a4David Brown static final String ACTION_EMERGENCY_DIAL = "com.android.phone.EmergencyDialer.DIAL"; 1088373b451692a39abdfd12444241c016831e1a4a4David Brown 10991a2f0566afb91549cbda9289b516154a6467624Ben Komalo // Debug Intent extras so that this Activity may be started via adb for debugging UI layouts 11091a2f0566afb91549cbda9289b516154a6467624Ben Komalo private static final String EXTRA_FORCE_VIEW = 11191a2f0566afb91549cbda9289b516154a6467624Ben Komalo "com.android.settings.CryptKeeper.DEBUG_FORCE_VIEW"; 11291a2f0566afb91549cbda9289b516154a6467624Ben Komalo private static final String FORCE_VIEW_PROGRESS = "progress"; 11391a2f0566afb91549cbda9289b516154a6467624Ben Komalo private static final String FORCE_VIEW_ERROR = "error"; 114de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal private static final String FORCE_VIEW_PASSWORD = "password"; 11591a2f0566afb91549cbda9289b516154a6467624Ben Komalo 116bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal /** When encryption is detected, this flag indicates whether or not we've checked for errors. */ 1170e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo private boolean mValidationComplete; 118d4758efef6d6564d7b4b0b747d0a9ae9b44a38c7Ben Komalo private boolean mValidationRequested; 1190e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo /** A flag to indicate that the volume is in a bad state (e.g. partially encrypted). */ 1200e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo private boolean mEncryptionGoneBad; 121de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal /** A flag to indicate when the back event should be ignored */ 122de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal private boolean mIgnoreBack = false; 1231499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler private int mCooldown; 1241499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler PowerManager.WakeLock mWakeLock; 12506c5ff4a46686d3f599e40df0768177d3d88913cJason parks private EditText mPasswordEntry; 126b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrence private LockPatternView mLockPatternView; 127d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal /** Number of calls to {@link #notifyUser()} to ignore before notifying. */ 128d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal private int mNotificationCountdown = 0; 12973456acfb45beb7a95b5aee5a1f7566d3b803a86Paul Lawrence /** Number of calls to {@link #notifyUser()} before we release the wakelock */ 13073456acfb45beb7a95b5aee5a1f7566d3b803a86Paul Lawrence private int mReleaseWakeLockCountdown = 0; 1315a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence private int mStatusString = R.string.enter_password; 1321499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler 133f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence // how long we wait to clear a wrong pattern 134f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence private static final int WRONG_PATTERN_CLEAR_TIMEOUT_MS = 1500; 135f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence 136f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence private Runnable mClearPatternRunnable = new Runnable() { 137f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence public void run() { 138f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence mLockPatternView.clearPattern(); 139f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence } 140f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence }; 141f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence 1421499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler /** 1431499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler * Used to propagate state through configuration changes (e.g. screen rotation) 1441499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler */ 1451499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler private static class NonConfigurationInstanceState { 1461499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler final PowerManager.WakeLock wakelock; 1471499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler 1481499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler NonConfigurationInstanceState(PowerManager.WakeLock _wakelock) { 1491499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler wakelock = _wakelock; 1501499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler } 1511499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler } 1521499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler 15306c5ff4a46686d3f599e40df0768177d3d88913cJason parks private class DecryptTask extends AsyncTask<String, Void, Integer> { 15406c5ff4a46686d3f599e40df0768177d3d88913cJason parks @Override 15506c5ff4a46686d3f599e40df0768177d3d88913cJason parks protected Integer doInBackground(String... params) { 156de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal final IMountService service = getMountService(); 15706c5ff4a46686d3f599e40df0768177d3d88913cJason parks try { 15806c5ff4a46686d3f599e40df0768177d3d88913cJason parks return service.decryptStorage(params[0]); 15906c5ff4a46686d3f599e40df0768177d3d88913cJason parks } catch (Exception e) { 16006c5ff4a46686d3f599e40df0768177d3d88913cJason parks Log.e(TAG, "Error while decrypting...", e); 16106c5ff4a46686d3f599e40df0768177d3d88913cJason parks return -1; 16206c5ff4a46686d3f599e40df0768177d3d88913cJason parks } 16306c5ff4a46686d3f599e40df0768177d3d88913cJason parks } 16406c5ff4a46686d3f599e40df0768177d3d88913cJason parks 16506c5ff4a46686d3f599e40df0768177d3d88913cJason parks @Override 16606c5ff4a46686d3f599e40df0768177d3d88913cJason parks protected void onPostExecute(Integer failedAttempts) { 16706c5ff4a46686d3f599e40df0768177d3d88913cJason parks if (failedAttempts == 0) { 16889c7570dd42ce6945ce8e092892a22ec79c30c82Paul Lawrence // The password was entered successfully. Simply do nothing 16989c7570dd42ce6945ce8e092892a22ec79c30c82Paul Lawrence // and wait for the service restart to switch to surfacefligner 17006c5ff4a46686d3f599e40df0768177d3d88913cJason parks } else if (failedAttempts == MAX_FAILED_ATTEMPTS) { 17106c5ff4a46686d3f599e40df0768177d3d88913cJason parks // Factory reset the device. 17206c5ff4a46686d3f599e40df0768177d3d88913cJason parks sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR")); 173384d8e52b6750b2be7079f8828e4d2f038e22180Paul Lawrence } else if (failedAttempts == -1) { 174384d8e52b6750b2be7079f8828e4d2f038e22180Paul Lawrence // Right password, but decryption failed. Tell user bad news ... 175384d8e52b6750b2be7079f8828e4d2f038e22180Paul Lawrence setContentView(R.layout.crypt_keeper_progress); 176384d8e52b6750b2be7079f8828e4d2f038e22180Paul Lawrence showFactoryReset(true); 177384d8e52b6750b2be7079f8828e4d2f038e22180Paul Lawrence return; 17806c5ff4a46686d3f599e40df0768177d3d88913cJason parks } else { 179f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence // Wrong entry. Handle pattern case. 1802daf2641d364683c21bcbae08a3358d0f3c6af94Paul Lawrence if (mLockPatternView != null) { 181f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence mLockPatternView.setDisplayMode(DisplayMode.Wrong); 182f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence mLockPatternView.removeCallbacks(mClearPatternRunnable); 183f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence mLockPatternView.postDelayed(mClearPatternRunnable, WRONG_PATTERN_CLEAR_TIMEOUT_MS); 184f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence } 185f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence if ((failedAttempts % COOL_DOWN_ATTEMPTS) == 0) { 186f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence mCooldown = COOL_DOWN_INTERVAL; 187f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence cooldown(); 188f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence } else { 189f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence final TextView status = (TextView) findViewById(R.id.status); 190bd4c3210e1e0d6f58b2a5857032a2dacb316be98Paul Lawrence 191bd4c3210e1e0d6f58b2a5857032a2dacb316be98Paul Lawrence int remainingAttempts = MAX_FAILED_ATTEMPTS - failedAttempts; 192bd4c3210e1e0d6f58b2a5857032a2dacb316be98Paul Lawrence if (remainingAttempts < COOL_DOWN_ATTEMPTS) { 193bd4c3210e1e0d6f58b2a5857032a2dacb316be98Paul Lawrence CharSequence warningTemplate = getText(R.string.crypt_keeper_warn_wipe); 194bd4c3210e1e0d6f58b2a5857032a2dacb316be98Paul Lawrence CharSequence warning = TextUtils.expandTemplate(warningTemplate, 195bd4c3210e1e0d6f58b2a5857032a2dacb316be98Paul Lawrence Integer.toString(remainingAttempts)); 196bd4c3210e1e0d6f58b2a5857032a2dacb316be98Paul Lawrence status.setText(warning); 197bd4c3210e1e0d6f58b2a5857032a2dacb316be98Paul Lawrence } else { 198bd4c3210e1e0d6f58b2a5857032a2dacb316be98Paul Lawrence status.setText(R.string.try_again); 199bd4c3210e1e0d6f58b2a5857032a2dacb316be98Paul Lawrence } 200bd4c3210e1e0d6f58b2a5857032a2dacb316be98Paul Lawrence 201f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence if (mLockPatternView != null) { 202f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence mLockPatternView.setDisplayMode(DisplayMode.Wrong); 203f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence } 204f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence // Reenable the password entry 205f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence if (mPasswordEntry != null) { 206f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence mPasswordEntry.setEnabled(true); 2075a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence final InputMethodManager imm = (InputMethodManager) getSystemService( 2085a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence Context.INPUT_METHOD_SERVICE); 2095a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence imm.showSoftInput(mPasswordEntry, 0); 21008c6ab0feaf459029d470b5c7a50fb55be763365Paul Lawrence setBackFunctionality(true); 211f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence } 212f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence if (mLockPatternView != null) { 213f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence mLockPatternView.setEnabled(true); 214f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence } 2152daf2641d364683c21bcbae08a3358d0f3c6af94Paul Lawrence } 21606c5ff4a46686d3f599e40df0768177d3d88913cJason parks } 21706c5ff4a46686d3f599e40df0768177d3d88913cJason parks } 21806c5ff4a46686d3f599e40df0768177d3d88913cJason parks } 21975c085ee890744cdd4b90c72f8b50e6aeeb31e88Jason parks 2200e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo private class ValidationTask extends AsyncTask<Void, Void, Boolean> { 2210e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo @Override 2220e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo protected Boolean doInBackground(Void... params) { 223de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal final IMountService service = getMountService(); 2240e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo try { 225d4758efef6d6564d7b4b0b747d0a9ae9b44a38c7Ben Komalo Log.d(TAG, "Validating encryption state."); 2260e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo int state = service.getEncryptionState(); 2270e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo if (state == IMountService.ENCRYPTION_STATE_NONE) { 2280e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo Log.w(TAG, "Unexpectedly in CryptKeeper even though there is no encryption."); 2290e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo return true; // Unexpected, but fine, I guess... 2300e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo } 2310e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo return state == IMountService.ENCRYPTION_STATE_OK; 2320e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo } catch (RemoteException e) { 2330e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo Log.w(TAG, "Unable to get encryption state properly"); 2340e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo return true; 2350e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo } 2360e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo } 2370e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo 2380e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo @Override 2390e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo protected void onPostExecute(Boolean result) { 2400e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo mValidationComplete = true; 2410e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo if (Boolean.FALSE.equals(result)) { 2420e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo Log.w(TAG, "Incomplete, or corrupted encryption detected. Prompting user to wipe."); 2430e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo mEncryptionGoneBad = true; 244d4758efef6d6564d7b4b0b747d0a9ae9b44a38c7Ben Komalo } else { 245d4758efef6d6564d7b4b0b747d0a9ae9b44a38c7Ben Komalo Log.d(TAG, "Encryption state validated. Proceeding to configure UI"); 2460e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo } 2470e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo setupUi(); 2480e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo } 2490e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo } 2500e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo 25191a2f0566afb91549cbda9289b516154a6467624Ben Komalo private final Handler mHandler = new Handler() { 252ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks @Override 253ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks public void handleMessage(Message msg) { 254ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks switch (msg.what) { 255de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal case MESSAGE_UPDATE_PROGRESS: 256f8217304073b5cd13823a0602568394be93bf310Jason parks updateProgress(); 257ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks break; 25835933812b16f0b4221280bbcc3c32f6540996bf2Jason parks 259de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal case MESSAGE_COOLDOWN: 260f8217304073b5cd13823a0602568394be93bf310Jason parks cooldown(); 261ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks break; 262de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal 263de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal case MESSAGE_NOTIFY: 264de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal notifyUser(); 265de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal break; 266ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks } 267ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks } 268ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks }; 26935933812b16f0b4221280bbcc3c32f6540996bf2Jason parks 270de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal private AudioManager mAudioManager; 271bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal /** The status bar where back/home/recent buttons are shown. */ 272bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal private StatusBarManager mStatusBar; 273bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal 274bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal /** All the widgets to disable in the status bar */ 275bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal final private static int sWidgetsToDisable = StatusBarManager.DISABLE_EXPAND 276bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal | StatusBarManager.DISABLE_NOTIFICATION_ICONS 277bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal | StatusBarManager.DISABLE_NOTIFICATION_ALERTS 278bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal | StatusBarManager.DISABLE_SYSTEM_INFO 279bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal | StatusBarManager.DISABLE_HOME 28066d050bb4b6bf899e363f3e67d1eb5774de744b5Alon Albert | StatusBarManager.DISABLE_SEARCH 281bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal | StatusBarManager.DISABLE_RECENT; 282de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal 28391a2f0566afb91549cbda9289b516154a6467624Ben Komalo /** @return whether or not this Activity was started for debugging the UI only. */ 28491a2f0566afb91549cbda9289b516154a6467624Ben Komalo private boolean isDebugView() { 28591a2f0566afb91549cbda9289b516154a6467624Ben Komalo return getIntent().hasExtra(EXTRA_FORCE_VIEW); 28691a2f0566afb91549cbda9289b516154a6467624Ben Komalo } 28791a2f0566afb91549cbda9289b516154a6467624Ben Komalo 28891a2f0566afb91549cbda9289b516154a6467624Ben Komalo /** @return whether or not this Activity was started for debugging the specific UI view only. */ 28991a2f0566afb91549cbda9289b516154a6467624Ben Komalo private boolean isDebugView(String viewType /* non-nullable */) { 29091a2f0566afb91549cbda9289b516154a6467624Ben Komalo return viewType.equals(getIntent().getStringExtra(EXTRA_FORCE_VIEW)); 29191a2f0566afb91549cbda9289b516154a6467624Ben Komalo } 29291a2f0566afb91549cbda9289b516154a6467624Ben Komalo 293de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal /** 294de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal * Notify the user that we are awaiting input. Currently this sends an audio alert. 295de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal */ 296de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal private void notifyUser() { 297d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal if (mNotificationCountdown > 0) { 298d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal --mNotificationCountdown; 299d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal } else if (mAudioManager != null) { 300de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal try { 301de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal // Play the standard keypress sound at full volume. This should be available on 302de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal // every device. We cannot play a ringtone here because media services aren't 303de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal // available yet. A DTMF-style tone is too soft to be noticed, and might not exist 304de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal // on tablet devices. The idea is to alert the user that something is needed: this 305de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal // does not have to be pleasing. 306de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal mAudioManager.playSoundEffect(AudioManager.FX_KEYPRESS_STANDARD, 100); 307de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal } catch (Exception e) { 308de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal Log.w(TAG, "notifyUser: Exception while playing sound: " + e); 309de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal } 310de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal } 31186b93937fa417647d22ee15d3a0aff7a751be17aVikram Aggarwal // Notify the user again in 5 seconds. 312de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal mHandler.removeMessages(MESSAGE_NOTIFY); 31386b93937fa417647d22ee15d3a0aff7a751be17aVikram Aggarwal mHandler.sendEmptyMessageDelayed(MESSAGE_NOTIFY, 5 * 1000); 31473456acfb45beb7a95b5aee5a1f7566d3b803a86Paul Lawrence 31573456acfb45beb7a95b5aee5a1f7566d3b803a86Paul Lawrence if (mWakeLock.isHeld()) { 31673456acfb45beb7a95b5aee5a1f7566d3b803a86Paul Lawrence if (mReleaseWakeLockCountdown > 0) { 31773456acfb45beb7a95b5aee5a1f7566d3b803a86Paul Lawrence --mReleaseWakeLockCountdown; 31873456acfb45beb7a95b5aee5a1f7566d3b803a86Paul Lawrence } else { 31973456acfb45beb7a95b5aee5a1f7566d3b803a86Paul Lawrence mWakeLock.release(); 32073456acfb45beb7a95b5aee5a1f7566d3b803a86Paul Lawrence } 32173456acfb45beb7a95b5aee5a1f7566d3b803a86Paul Lawrence } 322de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal } 323de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal 324de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal /** 325de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal * Ignore back events after the user has entered the decrypt screen and while the device is 326de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal * encrypting. 327de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal */ 328de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal @Override 329de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal public void onBackPressed() { 330bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal // In the rare case that something pressed back even though we were disabled. 331de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal if (mIgnoreBack) 332de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal return; 333de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal super.onBackPressed(); 334de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal } 335de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal 3368fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks @Override 3378fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks public void onCreate(Bundle savedInstanceState) { 3388fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks super.onCreate(savedInstanceState); 33935933812b16f0b4221280bbcc3c32f6540996bf2Jason parks 3409597406aa1b83867b03a47d1a5162969b924f2fcAndy Stadler // If we are not encrypted or encrypting, get out quickly. 341de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal final String state = SystemProperties.get("vold.decrypt"); 34291a2f0566afb91549cbda9289b516154a6467624Ben Komalo if (!isDebugView() && ("".equals(state) || DECRYPT_STATE.equals(state))) { 34335933812b16f0b4221280bbcc3c32f6540996bf2Jason parks // Disable the crypt keeper. 3448fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks PackageManager pm = getPackageManager(); 3458fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks ComponentName name = new ComponentName(this, CryptKeeper.class); 346140f6c6cf705f020c0ee6a2843cf1691cc68e729Dianne Hackborn pm.setComponentEnabledSetting(name, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 347140f6c6cf705f020c0ee6a2843cf1691cc68e729Dianne Hackborn PackageManager.DONT_KILL_APP); 348140f6c6cf705f020c0ee6a2843cf1691cc68e729Dianne Hackborn // Typically CryptKeeper is launched as the home app. We didn't 349644fa4243b4c288c85845b3f86aab25135635729Dianne Hackborn // want to be running, so need to finish this activity. We can count 350644fa4243b4c288c85845b3f86aab25135635729Dianne Hackborn // on the activity manager re-launching the new home app upon finishing 351644fa4243b4c288c85845b3f86aab25135635729Dianne Hackborn // this one, since this will leave the activity stack empty. 352140f6c6cf705f020c0ee6a2843cf1691cc68e729Dianne Hackborn // NOTE: This is really grungy. I think it would be better for the 353140f6c6cf705f020c0ee6a2843cf1691cc68e729Dianne Hackborn // activity manager to explicitly launch the crypt keeper instead of 354140f6c6cf705f020c0ee6a2843cf1691cc68e729Dianne Hackborn // home in the situation where we need to decrypt the device 355140f6c6cf705f020c0ee6a2843cf1691cc68e729Dianne Hackborn finish(); 3568fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks return; 3578fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks } 35835933812b16f0b4221280bbcc3c32f6540996bf2Jason parks 3597ae20e3ce98543888cfccbef6b1254d060bc30caPaul Lawrence try { 3607ae20e3ce98543888cfccbef6b1254d060bc30caPaul Lawrence if (getResources().getBoolean(R.bool.crypt_keeper_allow_rotation)) { 3617ae20e3ce98543888cfccbef6b1254d060bc30caPaul Lawrence setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); 3627ae20e3ce98543888cfccbef6b1254d060bc30caPaul Lawrence } 3637ae20e3ce98543888cfccbef6b1254d060bc30caPaul Lawrence } catch (NotFoundException e) { 3647ae20e3ce98543888cfccbef6b1254d060bc30caPaul Lawrence } 3657ae20e3ce98543888cfccbef6b1254d060bc30caPaul Lawrence 366b96b35a62b1f092b6322643c3568f3e712543e53Vikram Aggarwal // Disable the status bar, but do NOT disable back because the user needs a way to go 367b96b35a62b1f092b6322643c3568f3e712543e53Vikram Aggarwal // from keyboard settings and back to the password screen. 368bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal mStatusBar = (StatusBarManager) getSystemService(Context.STATUS_BAR_SERVICE); 369bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal mStatusBar.disable(sWidgetsToDisable); 3701499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler 371ea1186db19e673b44084b43b6a70bbdb07480aa9Vikram Aggarwal setAirplaneModeIfNecessary(); 372de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); 3731499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler // Check for (and recover) retained instance data 374de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal final Object lastInstance = getLastNonConfigurationInstance(); 3751499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler if (lastInstance instanceof NonConfigurationInstanceState) { 3761499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler NonConfigurationInstanceState retained = (NonConfigurationInstanceState) lastInstance; 3771499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler mWakeLock = retained.wakelock; 3780460675b7c0d5a9b02dae01578c64ff0453e4fb7Ben Komalo Log.d(TAG, "Restoring wakelock from NonConfigurationInstanceState"); 3791499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler } 380ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks } 38135933812b16f0b4221280bbcc3c32f6540996bf2Jason parks 3829597406aa1b83867b03a47d1a5162969b924f2fcAndy Stadler /** 3839597406aa1b83867b03a47d1a5162969b924f2fcAndy Stadler * Note, we defer the state check and screen setup to onStart() because this will be 3849597406aa1b83867b03a47d1a5162969b924f2fcAndy Stadler * re-run if the user clicks the power button (sleeping/waking the screen), and this is 3859597406aa1b83867b03a47d1a5162969b924f2fcAndy Stadler * especially important if we were to lose the wakelock for any reason. 3869597406aa1b83867b03a47d1a5162969b924f2fcAndy Stadler */ 3879597406aa1b83867b03a47d1a5162969b924f2fcAndy Stadler @Override 3889597406aa1b83867b03a47d1a5162969b924f2fcAndy Stadler public void onStart() { 3899597406aa1b83867b03a47d1a5162969b924f2fcAndy Stadler super.onStart(); 390d4758efef6d6564d7b4b0b747d0a9ae9b44a38c7Ben Komalo setupUi(); 3910e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo } 3920e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo 3930e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo /** 3940e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo * Initializes the UI based on the current state of encryption. 3950e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo * This is idempotent - calling repeatedly will simply re-initialize the UI. 3960e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo */ 3970e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo private void setupUi() { 3980e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo if (mEncryptionGoneBad || isDebugView(FORCE_VIEW_ERROR)) { 3990e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo setContentView(R.layout.crypt_keeper_progress); 400384d8e52b6750b2be7079f8828e4d2f038e22180Paul Lawrence showFactoryReset(false); 4010e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo return; 4020e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo } 4030e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo 404de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal final String progress = SystemProperties.get("vold.encrypt_progress"); 4050e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo if (!"".equals(progress) || isDebugView(FORCE_VIEW_PROGRESS)) { 4069597406aa1b83867b03a47d1a5162969b924f2fcAndy Stadler setContentView(R.layout.crypt_keeper_progress); 4079597406aa1b83867b03a47d1a5162969b924f2fcAndy Stadler encryptionProgressInit(); 408de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal } else if (mValidationComplete || isDebugView(FORCE_VIEW_PASSWORD)) { 4099ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence new AsyncTask<Void, Void, Void>() { 4109ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence int type = StorageManager.CRYPT_TYPE_PASSWORD; 4119ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence String owner_info; 4129ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence 4139ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence @Override 4149ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence public Void doInBackground(Void... v) { 4159ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence try { 4169ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence final IMountService service = getMountService(); 4179ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence type = service.getPasswordType(); 4189ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence owner_info = service.getField("OwnerInfo"); 4199ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence } catch (Exception e) { 4209ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence Log.e(TAG, "Error calling mount service " + e); 4219ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence } 4229ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence 4239ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence return null; 4249ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence } 425b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrence 4269ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence @Override 4279ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence public void onPostExecute(java.lang.Void v) { 4289ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence if(type == StorageManager.CRYPT_TYPE_PIN) { 4299ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence setContentView(R.layout.crypt_keeper_pin_entry); 4305a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence mStatusString = R.string.enter_pin; 4319ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence } else if (type == StorageManager.CRYPT_TYPE_PATTERN) { 4329ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence setContentView(R.layout.crypt_keeper_pattern_entry); 4339ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence setBackFunctionality(false); 4345a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence mStatusString = R.string.enter_pattern; 4359ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence } else { 4369ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence setContentView(R.layout.crypt_keeper_password_entry); 4375a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence mStatusString = R.string.enter_password; 4389ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence } 4395a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence final TextView status = (TextView) findViewById(R.id.status); 4405a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence status.setText(mStatusString); 4415a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence 4425a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence final TextView ownerInfo = (TextView) findViewById(R.id.owner_info); 4435a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence ownerInfo.setText(owner_info); 4445a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence ownerInfo.setSelected(true); // Required for marquee'ing to work 4459ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence 4469ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence passwordEntryInit(); 4475a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence 4485a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence if (mCooldown > 0) { 4495a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence setBackFunctionality(false); 4505a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence cooldown(); // in case we are cooling down and coming back from emergency dialler 4515a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence } 4529ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence } 4539ac2d81d9fd155240e02284894148c6dcbe486ecPaul Lawrence }.execute(); 454d4758efef6d6564d7b4b0b747d0a9ae9b44a38c7Ben Komalo } else if (!mValidationRequested) { 455d4758efef6d6564d7b4b0b747d0a9ae9b44a38c7Ben Komalo // We're supposed to be encrypted, but no validation has been done. 456d4758efef6d6564d7b4b0b747d0a9ae9b44a38c7Ben Komalo new ValidationTask().execute((Void[]) null); 457d4758efef6d6564d7b4b0b747d0a9ae9b44a38c7Ben Komalo mValidationRequested = true; 4589597406aa1b83867b03a47d1a5162969b924f2fcAndy Stadler } 4599597406aa1b83867b03a47d1a5162969b924f2fcAndy Stadler } 4609597406aa1b83867b03a47d1a5162969b924f2fcAndy Stadler 461f8217304073b5cd13823a0602568394be93bf310Jason parks @Override 462f8217304073b5cd13823a0602568394be93bf310Jason parks public void onStop() { 463f8217304073b5cd13823a0602568394be93bf310Jason parks super.onStop(); 464de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal mHandler.removeMessages(MESSAGE_COOLDOWN); 465de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal mHandler.removeMessages(MESSAGE_UPDATE_PROGRESS); 466de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal mHandler.removeMessages(MESSAGE_NOTIFY); 4671499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler } 4681499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler 4691499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler /** 4701499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler * Reconfiguring, so propagate the wakelock to the next instance. This runs between onStop() 4711499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler * and onDestroy() and only if we are changing configuration (e.g. rotation). Also clears 4721499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler * mWakeLock so the subsequent call to onDestroy does not release it. 4731499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler */ 4741499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler @Override 4751499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler public Object onRetainNonConfigurationInstance() { 4761499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler NonConfigurationInstanceState state = new NonConfigurationInstanceState(mWakeLock); 4770460675b7c0d5a9b02dae01578c64ff0453e4fb7Ben Komalo Log.d(TAG, "Handing wakelock off to NonConfigurationInstanceState"); 4781499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler mWakeLock = null; 4791499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler return state; 4801499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler } 4811499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler 4821499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler @Override 4831499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler public void onDestroy() { 4841499740c13af5fbd5766a87825c3e789b37bab24Andy Stadler super.onDestroy(); 485f8217304073b5cd13823a0602568394be93bf310Jason parks 486f8217304073b5cd13823a0602568394be93bf310Jason parks if (mWakeLock != null) { 4870460675b7c0d5a9b02dae01578c64ff0453e4fb7Ben Komalo Log.d(TAG, "Releasing and destroying wakelock"); 488f8217304073b5cd13823a0602568394be93bf310Jason parks mWakeLock.release(); 489f8217304073b5cd13823a0602568394be93bf310Jason parks mWakeLock = null; 490f8217304073b5cd13823a0602568394be93bf310Jason parks } 491f8217304073b5cd13823a0602568394be93bf310Jason parks } 492f8217304073b5cd13823a0602568394be93bf310Jason parks 493de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal /** 494de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal * Start encrypting the device. 495de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal */ 496ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks private void encryptionProgressInit() { 49735933812b16f0b4221280bbcc3c32f6540996bf2Jason parks // Accquire a partial wakelock to prevent the device from sleeping. Note 49835933812b16f0b4221280bbcc3c32f6540996bf2Jason parks // we never release this wakelock as we will be restarted after the device 49935933812b16f0b4221280bbcc3c32f6540996bf2Jason parks // is encrypted. 5000460675b7c0d5a9b02dae01578c64ff0453e4fb7Ben Komalo Log.d(TAG, "Encryption progress screen initializing."); 5019ee164f44ea1ad66fa16ed702eb885e36ade0d8bBen Komalo if (mWakeLock == null) { 5020460675b7c0d5a9b02dae01578c64ff0453e4fb7Ben Komalo Log.d(TAG, "Acquiring wakelock."); 5030460675b7c0d5a9b02dae01578c64ff0453e4fb7Ben Komalo PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); 5040460675b7c0d5a9b02dae01578c64ff0453e4fb7Ben Komalo mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, TAG); 5050460675b7c0d5a9b02dae01578c64ff0453e4fb7Ben Komalo mWakeLock.acquire(); 5060460675b7c0d5a9b02dae01578c64ff0453e4fb7Ben Komalo } 507f8217304073b5cd13823a0602568394be93bf310Jason parks 508bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal ((ProgressBar) findViewById(R.id.progress_bar)).setIndeterminate(true); 509de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal // Ignore all back presses from now, both hard and soft keys. 510bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal setBackFunctionality(false); 511de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal // Start the first run of progress manually. This method sets up messages to occur at 512de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal // repeated intervals. 513f8217304073b5cd13823a0602568394be93bf310Jason parks updateProgress(); 514f8217304073b5cd13823a0602568394be93bf310Jason parks } 515f8217304073b5cd13823a0602568394be93bf310Jason parks 516384d8e52b6750b2be7079f8828e4d2f038e22180Paul Lawrence /** 517384d8e52b6750b2be7079f8828e4d2f038e22180Paul Lawrence * Show factory reset screen allowing the user to reset their phone when 518384d8e52b6750b2be7079f8828e4d2f038e22180Paul Lawrence * there is nothing else we can do 519384d8e52b6750b2be7079f8828e4d2f038e22180Paul Lawrence * @param corrupt true if userdata is corrupt, false if encryption failed 520384d8e52b6750b2be7079f8828e4d2f038e22180Paul Lawrence * partway through 521384d8e52b6750b2be7079f8828e4d2f038e22180Paul Lawrence */ 522384d8e52b6750b2be7079f8828e4d2f038e22180Paul Lawrence private void showFactoryReset(boolean corrupt) { 52313d62049f7c96c47356f23eaee7f0997612fdf9fAndy Stadler // Hide the encryption-bot to make room for the "factory reset" button 52413d62049f7c96c47356f23eaee7f0997612fdf9fAndy Stadler findViewById(R.id.encroid).setVisibility(View.GONE); 52513d62049f7c96c47356f23eaee7f0997612fdf9fAndy Stadler 52613d62049f7c96c47356f23eaee7f0997612fdf9fAndy Stadler // Show the reset button, failure text, and a divider 527bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal final Button button = (Button) findViewById(R.id.factory_reset); 52813d62049f7c96c47356f23eaee7f0997612fdf9fAndy Stadler button.setVisibility(View.VISIBLE); 52913d62049f7c96c47356f23eaee7f0997612fdf9fAndy Stadler button.setOnClickListener(new OnClickListener() { 530bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal @Override 53113d62049f7c96c47356f23eaee7f0997612fdf9fAndy Stadler public void onClick(View v) { 53213d62049f7c96c47356f23eaee7f0997612fdf9fAndy Stadler // Factory reset the device. 53313d62049f7c96c47356f23eaee7f0997612fdf9fAndy Stadler sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR")); 53413d62049f7c96c47356f23eaee7f0997612fdf9fAndy Stadler } 53513d62049f7c96c47356f23eaee7f0997612fdf9fAndy Stadler }); 53613d62049f7c96c47356f23eaee7f0997612fdf9fAndy Stadler 537bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal // Alert the user of the failure. 538384d8e52b6750b2be7079f8828e4d2f038e22180Paul Lawrence if (corrupt) { 539384d8e52b6750b2be7079f8828e4d2f038e22180Paul Lawrence ((TextView) findViewById(R.id.title)).setText(R.string.crypt_keeper_data_corrupt_title); 540384d8e52b6750b2be7079f8828e4d2f038e22180Paul Lawrence ((TextView) findViewById(R.id.status)).setText(R.string.crypt_keeper_data_corrupt_summary); 541384d8e52b6750b2be7079f8828e4d2f038e22180Paul Lawrence } else { 542384d8e52b6750b2be7079f8828e4d2f038e22180Paul Lawrence ((TextView) findViewById(R.id.title)).setText(R.string.crypt_keeper_failed_title); 543384d8e52b6750b2be7079f8828e4d2f038e22180Paul Lawrence ((TextView) findViewById(R.id.status)).setText(R.string.crypt_keeper_failed_summary); 544384d8e52b6750b2be7079f8828e4d2f038e22180Paul Lawrence } 54513d62049f7c96c47356f23eaee7f0997612fdf9fAndy Stadler 546bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal final View view = findViewById(R.id.bottom_divider); 547bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal // TODO(viki): Why would the bottom divider be missing in certain layouts? Investigate. 548f0104df823a93ef4c3336118ddb02a0924e520daBen Komalo if (view != null) { 549f0104df823a93ef4c3336118ddb02a0924e520daBen Komalo view.setVisibility(View.VISIBLE); 550f0104df823a93ef4c3336118ddb02a0924e520daBen Komalo } 55113d62049f7c96c47356f23eaee7f0997612fdf9fAndy Stadler } 55213d62049f7c96c47356f23eaee7f0997612fdf9fAndy Stadler 553f8217304073b5cd13823a0602568394be93bf310Jason parks private void updateProgress() { 554bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal final String state = SystemProperties.get("vold.encrypt_progress"); 555f8217304073b5cd13823a0602568394be93bf310Jason parks 5560e66609c95047ba7e5c0408bdc88af4315fd35b1Ben Komalo if ("error_partially_encrypted".equals(state)) { 557384d8e52b6750b2be7079f8828e4d2f038e22180Paul Lawrence showFactoryReset(false); 55813d62049f7c96c47356f23eaee7f0997612fdf9fAndy Stadler return; 55913d62049f7c96c47356f23eaee7f0997612fdf9fAndy Stadler } 56013d62049f7c96c47356f23eaee7f0997612fdf9fAndy Stadler 561b15c68fbf19c021eb0a3bed1ccc4dd7fda384ec7Paul Lawrence // Get status as percentage first 562b15c68fbf19c021eb0a3bed1ccc4dd7fda384ec7Paul Lawrence CharSequence status = getText(R.string.crypt_keeper_setup_description); 563b15c68fbf19c021eb0a3bed1ccc4dd7fda384ec7Paul Lawrence int percent = 0; 564f8217304073b5cd13823a0602568394be93bf310Jason parks try { 56591a2f0566afb91549cbda9289b516154a6467624Ben Komalo // Force a 50% progress state when debugging the view. 566b15c68fbf19c021eb0a3bed1ccc4dd7fda384ec7Paul Lawrence percent = isDebugView() ? 50 : Integer.parseInt(state); 567f8217304073b5cd13823a0602568394be93bf310Jason parks } catch (Exception e) { 568f8217304073b5cd13823a0602568394be93bf310Jason parks Log.w(TAG, "Error parsing progress: " + e.toString()); 569f8217304073b5cd13823a0602568394be93bf310Jason parks } 570b15c68fbf19c021eb0a3bed1ccc4dd7fda384ec7Paul Lawrence String progress = Integer.toString(percent); 57135933812b16f0b4221280bbcc3c32f6540996bf2Jason parks 572b15c68fbf19c021eb0a3bed1ccc4dd7fda384ec7Paul Lawrence // Now try to get status as time remaining and replace as appropriate 5730460675b7c0d5a9b02dae01578c64ff0453e4fb7Ben Komalo Log.v(TAG, "Encryption progress: " + progress); 574b15c68fbf19c021eb0a3bed1ccc4dd7fda384ec7Paul Lawrence try { 575b15c68fbf19c021eb0a3bed1ccc4dd7fda384ec7Paul Lawrence final String timeProperty = SystemProperties.get("vold.encrypt_time_remaining"); 576b15c68fbf19c021eb0a3bed1ccc4dd7fda384ec7Paul Lawrence int time = Integer.parseInt(timeProperty); 577b15c68fbf19c021eb0a3bed1ccc4dd7fda384ec7Paul Lawrence if (time >= 0) { 578b15c68fbf19c021eb0a3bed1ccc4dd7fda384ec7Paul Lawrence // Round up to multiple of 10 - this way display is less jerky 579b15c68fbf19c021eb0a3bed1ccc4dd7fda384ec7Paul Lawrence time = (time + 9) / 10 * 10; 580b15c68fbf19c021eb0a3bed1ccc4dd7fda384ec7Paul Lawrence progress = DateUtils.formatElapsedTime(time); 581b15c68fbf19c021eb0a3bed1ccc4dd7fda384ec7Paul Lawrence status = getText(R.string.crypt_keeper_setup_time_remaining); 582b15c68fbf19c021eb0a3bed1ccc4dd7fda384ec7Paul Lawrence } 583b15c68fbf19c021eb0a3bed1ccc4dd7fda384ec7Paul Lawrence } catch (Exception e) { 584b15c68fbf19c021eb0a3bed1ccc4dd7fda384ec7Paul Lawrence // Will happen if no time etc - show percentage 585b15c68fbf19c021eb0a3bed1ccc4dd7fda384ec7Paul Lawrence } 586b15c68fbf19c021eb0a3bed1ccc4dd7fda384ec7Paul Lawrence 587bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal final TextView tv = (TextView) findViewById(R.id.status); 588de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal if (tv != null) { 589b15c68fbf19c021eb0a3bed1ccc4dd7fda384ec7Paul Lawrence tv.setText(TextUtils.expandTemplate(status, progress)); 590de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal } 591b15c68fbf19c021eb0a3bed1ccc4dd7fda384ec7Paul Lawrence 592b15c68fbf19c021eb0a3bed1ccc4dd7fda384ec7Paul Lawrence // Check the progress every 1 seconds 593de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal mHandler.removeMessages(MESSAGE_UPDATE_PROGRESS); 594b15c68fbf19c021eb0a3bed1ccc4dd7fda384ec7Paul Lawrence mHandler.sendEmptyMessageDelayed(MESSAGE_UPDATE_PROGRESS, 1000); 595f8217304073b5cd13823a0602568394be93bf310Jason parks } 596f8217304073b5cd13823a0602568394be93bf310Jason parks 597de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal /** Disable password input for a while to force the user to waste time between retries */ 598f8217304073b5cd13823a0602568394be93bf310Jason parks private void cooldown() { 599bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal final TextView status = (TextView) findViewById(R.id.status); 60013d62049f7c96c47356f23eaee7f0997612fdf9fAndy Stadler 601f8217304073b5cd13823a0602568394be93bf310Jason parks if (mCooldown <= 0) { 602de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal // Re-enable the password entry and back presses. 6032daf2641d364683c21bcbae08a3358d0f3c6af94Paul Lawrence if (mPasswordEntry != null) { 6042daf2641d364683c21bcbae08a3358d0f3c6af94Paul Lawrence mPasswordEntry.setEnabled(true); 6055a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence final InputMethodManager imm = (InputMethodManager) getSystemService( 6065a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence Context.INPUT_METHOD_SERVICE); 6075a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence imm.showSoftInput(mPasswordEntry, 0); 6082daf2641d364683c21bcbae08a3358d0f3c6af94Paul Lawrence setBackFunctionality(true); 6092daf2641d364683c21bcbae08a3358d0f3c6af94Paul Lawrence } 6102daf2641d364683c21bcbae08a3358d0f3c6af94Paul Lawrence if (mLockPatternView != null) { 6112daf2641d364683c21bcbae08a3358d0f3c6af94Paul Lawrence mLockPatternView.setEnabled(true); 6122daf2641d364683c21bcbae08a3358d0f3c6af94Paul Lawrence } 6135a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence status.setText(mStatusString); 614f8217304073b5cd13823a0602568394be93bf310Jason parks } else { 6155a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence // Disable the password entry and back presses. 6165a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence if (mPasswordEntry != null) { 6175a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence mPasswordEntry.setEnabled(false); 6185a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence } 6195a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence if (mLockPatternView != null) { 6205a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence mLockPatternView.setEnabled(false); 6215a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence } 6225a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence 62313d62049f7c96c47356f23eaee7f0997612fdf9fAndy Stadler CharSequence template = getText(R.string.crypt_keeper_cooldown); 624bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal status.setText(TextUtils.expandTemplate(template, Integer.toString(mCooldown))); 62513d62049f7c96c47356f23eaee7f0997612fdf9fAndy Stadler 626f8217304073b5cd13823a0602568394be93bf310Jason parks mCooldown--; 627de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal mHandler.removeMessages(MESSAGE_COOLDOWN); 628de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal mHandler.sendEmptyMessageDelayed(MESSAGE_COOLDOWN, 1000); // Tick every second 629f8217304073b5cd13823a0602568394be93bf310Jason parks } 630ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks } 63135933812b16f0b4221280bbcc3c32f6540996bf2Jason parks 632bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal /** 633bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal * Sets the back status: enabled or disabled according to the parameter. 634bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal * @param isEnabled true if back is enabled, false otherwise. 635bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal */ 636bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal private final void setBackFunctionality(boolean isEnabled) { 637bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal mIgnoreBack = !isEnabled; 638bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal if (isEnabled) { 639bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal mStatusBar.disable(sWidgetsToDisable); 640bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal } else { 641bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal mStatusBar.disable(sWidgetsToDisable | StatusBarManager.DISABLE_BACK); 642bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal } 643bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal } 644bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal 645b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrence protected LockPatternView.OnPatternListener mChooseNewLockPatternListener = 646f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence new LockPatternView.OnPatternListener() { 647b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrence 648f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence @Override 649f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence public void onPatternStart() { 650f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence mLockPatternView.removeCallbacks(mClearPatternRunnable); 651f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence } 652b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrence 653f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence @Override 654f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence public void onPatternCleared() { 655f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence } 656b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrence 657f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence @Override 658f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence public void onPatternDetected(List<LockPatternView.Cell> pattern) { 659f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence mLockPatternView.setEnabled(false); 660f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence new DecryptTask().execute(LockPatternUtils.patternToString(pattern)); 661f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence } 662b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrence 663f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence @Override 664f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence public void onPatternCellAdded(List<Cell> pattern) { 665f6cda3b176d097f8360b5c34c6ba746cd10b4004Paul Lawrence } 666b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrence }; 667b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrence 668b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrence private void passwordEntryInit() { 669b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrence // Password/pin case 67006c5ff4a46686d3f599e40df0768177d3d88913cJason parks mPasswordEntry = (EditText) findViewById(R.id.passwordEntry); 671b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrence if (mPasswordEntry != null){ 672b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrence mPasswordEntry.setOnEditorActionListener(this); 673b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrence mPasswordEntry.requestFocus(); 674b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrence // Become quiet when the user interacts with the Edit text screen. 675b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrence mPasswordEntry.setOnKeyListener(this); 676b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrence mPasswordEntry.setOnTouchListener(this); 677b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrence mPasswordEntry.addTextChangedListener(this); 678b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrence } 679b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrence 680b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrence // Pattern case 681b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrence mLockPatternView = (LockPatternView) findViewById(R.id.lockPattern); 682b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrence if (mLockPatternView != null) { 683b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrence mLockPatternView.setOnPatternListener(mChooseNewLockPatternListener); 684b05f39d186d8ce1b53bb4da3cb4c2cd22986f513Paul Lawrence } 6859fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo 686c62d321e8dcb023e8c7299802a75a271b7ca98d9Vikram Aggarwal // Disable the Emergency call button if the device has no voice telephone capability 6873afbdf006057c93f930694e26306a3cc9cea34e4Santos Cordon if (!getTelephonyManager().isVoiceCapable()) { 688c62d321e8dcb023e8c7299802a75a271b7ca98d9Vikram Aggarwal final View emergencyCall = findViewById(R.id.emergencyCallButton); 689c62d321e8dcb023e8c7299802a75a271b7ca98d9Vikram Aggarwal if (emergencyCall != null) { 690c62d321e8dcb023e8c7299802a75a271b7ca98d9Vikram Aggarwal Log.d(TAG, "Removing the emergency Call button"); 691c62d321e8dcb023e8c7299802a75a271b7ca98d9Vikram Aggarwal emergencyCall.setVisibility(View.GONE); 692c62d321e8dcb023e8c7299802a75a271b7ca98d9Vikram Aggarwal } 693c62d321e8dcb023e8c7299802a75a271b7ca98d9Vikram Aggarwal } 694c62d321e8dcb023e8c7299802a75a271b7ca98d9Vikram Aggarwal 695bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal final View imeSwitcher = findViewById(R.id.switch_ime_button); 6969fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo final InputMethodManager imm = (InputMethodManager) getSystemService( 6979fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo Context.INPUT_METHOD_SERVICE); 6989fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo if (imeSwitcher != null && hasMultipleEnabledIMEsOrSubtypes(imm, false)) { 6999fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo imeSwitcher.setVisibility(View.VISIBLE); 7009fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo imeSwitcher.setOnClickListener(new OnClickListener() { 701bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal @Override 7029fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo public void onClick(View v) { 7039fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo imm.showInputMethodPicker(); 7049fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo } 7059fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo }); 7069fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo } 7079fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo 708de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal // We want to keep the screen on while waiting for input. In minimal boot mode, the device 709de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal // is completely non-functional, and we want the user to notice the device and enter a 710de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal // password. 711de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal if (mWakeLock == null) { 712de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal Log.d(TAG, "Acquiring wakelock."); 713de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); 714de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal if (pm != null) { 715de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, TAG); 716de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal mWakeLock.acquire(); 71773456acfb45beb7a95b5aee5a1f7566d3b803a86Paul Lawrence // Keep awake for 10 minutes - if the user hasn't been alerted by then 71873456acfb45beb7a95b5aee5a1f7566d3b803a86Paul Lawrence // best not to just drain their battery 7195a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence mReleaseWakeLockCountdown = 96; // 96 * 5 secs per click + 120 secs before we show this = 600 720de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal } 721de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal } 72273456acfb45beb7a95b5aee5a1f7566d3b803a86Paul Lawrence 7239fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo // Asynchronously throw up the IME, since there are issues with requesting it to be shown 7249fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo // immediately. 7255a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence if (mLockPatternView == null && mCooldown <= 0) { 726e54e9323ed423d68f0567dcf05f45c62187ad8ddPaul Lawrence mHandler.postDelayed(new Runnable() { 727e54e9323ed423d68f0567dcf05f45c62187ad8ddPaul Lawrence @Override public void run() { 728e54e9323ed423d68f0567dcf05f45c62187ad8ddPaul Lawrence imm.showSoftInputUnchecked(0, null); 729e54e9323ed423d68f0567dcf05f45c62187ad8ddPaul Lawrence } 730e54e9323ed423d68f0567dcf05f45c62187ad8ddPaul Lawrence }, 0); 731e54e9323ed423d68f0567dcf05f45c62187ad8ddPaul Lawrence } 7329fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo 7339fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo updateEmergencyCallButtonState(); 734d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal // Notify the user in 120 seconds that we are waiting for him to enter the password. 73586b93937fa417647d22ee15d3a0aff7a751be17aVikram Aggarwal mHandler.removeMessages(MESSAGE_NOTIFY); 736d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal mHandler.sendEmptyMessageDelayed(MESSAGE_NOTIFY, 120 * 1000); 737fb3d5cad48876dbd366fd8b562529d355d2428dbJim Miller 738fb3d5cad48876dbd366fd8b562529d355d2428dbJim Miller // Dismiss keyguard while this screen is showing. 739fb3d5cad48876dbd366fd8b562529d355d2428dbJim Miller getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); 7409fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo } 74135933812b16f0b4221280bbcc3c32f6540996bf2Jason parks 7429fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo /** 7439fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo * Method adapted from com.android.inputmethod.latin.Utils 7449fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo * 7459fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo * @param imm The input method manager 7469fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo * @param shouldIncludeAuxiliarySubtypes 7479fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo * @return true if we have multiple IMEs to choose from 7489fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo */ 7499fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo private boolean hasMultipleEnabledIMEsOrSubtypes(InputMethodManager imm, 7509fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo final boolean shouldIncludeAuxiliarySubtypes) { 7519fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo final List<InputMethodInfo> enabledImis = imm.getEnabledInputMethodList(); 7529fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo 7539fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo // Number of the filtered IMEs 7549fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo int filteredImisCount = 0; 7559fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo 7569fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo for (InputMethodInfo imi : enabledImis) { 7579fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo // We can return true immediately after we find two or more filtered IMEs. 7589fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo if (filteredImisCount > 1) return true; 7599fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo final List<InputMethodSubtype> subtypes = 7609fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo imm.getEnabledInputMethodSubtypeList(imi, true); 7619fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo // IMEs that have no subtypes should be counted. 7629fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo if (subtypes.isEmpty()) { 7639fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo ++filteredImisCount; 7649fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo continue; 7659fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo } 76635933812b16f0b4221280bbcc3c32f6540996bf2Jason parks 7679fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo int auxCount = 0; 7689fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo for (InputMethodSubtype subtype : subtypes) { 7699fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo if (subtype.isAuxiliary()) { 7709fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo ++auxCount; 7719fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo } 7729fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo } 7739fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo final int nonAuxCount = subtypes.size() - auxCount; 7749fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo 7759fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo // IMEs that have one or more non-auxiliary subtypes should be counted. 7769fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo // If shouldIncludeAuxiliarySubtypes is true, IMEs that have two or more auxiliary 7779fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo // subtypes should be counted as well. 7789fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo if (nonAuxCount > 0 || (shouldIncludeAuxiliarySubtypes && auxCount > 1)) { 7799fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo ++filteredImisCount; 7809fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo continue; 7819fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo } 78200046d6e176eb05c3e3b0d13d38a8da7491bba5eJason parks } 7838373b451692a39abdfd12444241c016831e1a4a4David Brown 7849fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo return filteredImisCount > 1 7859fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo // imm.getEnabledInputMethodSubtypeList(null, false) will return the current IME's enabled 7869fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo // input method subtype (The current IME should be LatinIME.) 7879fcb6a7fac02aef85085c2db616556257e1642f5Ben Komalo || imm.getEnabledInputMethodSubtypeList(null, false).size() > 1; 7888fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks } 7898fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks 7908fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks private IMountService getMountService() { 791bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal final IBinder service = ServiceManager.getService("mount"); 7928fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks if (service != null) { 7938fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks return IMountService.Stub.asInterface(service); 7948fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks } 7958fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks return null; 7968fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks } 7978fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks 7988fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks @Override 7998fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 80000046d6e176eb05c3e3b0d13d38a8da7491bba5eJason parks if (actionId == EditorInfo.IME_NULL || actionId == EditorInfo.IME_ACTION_DONE) { 8018fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks // Get the password 802bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal final String password = v.getText().toString(); 8038fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks 804ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks if (TextUtils.isEmpty(password)) { 805ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks return true; 806ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks } 80735933812b16f0b4221280bbcc3c32f6540996bf2Jason parks 8088fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks // Now that we have the password clear the password field. 8098fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks v.setText(null); 8108fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks 811de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal // Disable the password entry and back keypress while checking the password. These 812de3c9cb412688eb841993ad971d06039d8a952c3Vikram Aggarwal // we either be re-enabled if the password was wrong or after the cooldown period. 81306c5ff4a46686d3f599e40df0768177d3d88913cJason parks mPasswordEntry.setEnabled(false); 814bf459dafdc5d97d8f2103c1d2a9cb65f5096e4f8Vikram Aggarwal setBackFunctionality(false); 81506c5ff4a46686d3f599e40df0768177d3d88913cJason parks 8160460675b7c0d5a9b02dae01578c64ff0453e4fb7Ben Komalo Log.d(TAG, "Attempting to send command to decrypt"); 81706c5ff4a46686d3f599e40df0768177d3d88913cJason parks new DecryptTask().execute(password); 81835933812b16f0b4221280bbcc3c32f6540996bf2Jason parks 8198fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks return true; 8208fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks } 8218fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks return false; 8228fd5bc9e6ff0d02012df670a6bf4bcdaf903c09dJason parks } 8238373b451692a39abdfd12444241c016831e1a4a4David Brown 824bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal /** 825ea1186db19e673b44084b43b6a70bbdb07480aa9Vikram Aggarwal * Set airplane mode on the device if it isn't an LTE device. 826ea1186db19e673b44084b43b6a70bbdb07480aa9Vikram Aggarwal * Full story: In minimal boot mode, we cannot save any state. In particular, we cannot save 827ea1186db19e673b44084b43b6a70bbdb07480aa9Vikram Aggarwal * any incoming SMS's. So SMSs that are received here will be silently dropped to the floor. 828ea1186db19e673b44084b43b6a70bbdb07480aa9Vikram Aggarwal * That is bad. Also, we cannot receive any telephone calls in this state. So to avoid 829ea1186db19e673b44084b43b6a70bbdb07480aa9Vikram Aggarwal * both these problems, we turn the radio off. However, on certain networks turning on and 830ea1186db19e673b44084b43b6a70bbdb07480aa9Vikram Aggarwal * off the radio takes a long time. In such cases, we are better off leaving the radio 831ea1186db19e673b44084b43b6a70bbdb07480aa9Vikram Aggarwal * running so the latency of an E911 call is short. 832ea1186db19e673b44084b43b6a70bbdb07480aa9Vikram Aggarwal * The behavior after this is: 833ea1186db19e673b44084b43b6a70bbdb07480aa9Vikram Aggarwal * 1. Emergency dialing: the emergency dialer has logic to force the device out of 834ea1186db19e673b44084b43b6a70bbdb07480aa9Vikram Aggarwal * airplane mode and restart the radio. 835ea1186db19e673b44084b43b6a70bbdb07480aa9Vikram Aggarwal * 2. Full boot: we read the persistent settings from the previous boot and restore the 836ea1186db19e673b44084b43b6a70bbdb07480aa9Vikram Aggarwal * radio to whatever it was before it restarted. This also happens when rebooting a 837ea1186db19e673b44084b43b6a70bbdb07480aa9Vikram Aggarwal * phone that has no encryption. 838ea1186db19e673b44084b43b6a70bbdb07480aa9Vikram Aggarwal */ 839ea1186db19e673b44084b43b6a70bbdb07480aa9Vikram Aggarwal private final void setAirplaneModeIfNecessary() { 840ea1186db19e673b44084b43b6a70bbdb07480aa9Vikram Aggarwal final boolean isLteDevice = 8413afbdf006057c93f930694e26306a3cc9cea34e4Santos Cordon getTelephonyManager().getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_TRUE; 842ea1186db19e673b44084b43b6a70bbdb07480aa9Vikram Aggarwal if (!isLteDevice) { 843ea1186db19e673b44084b43b6a70bbdb07480aa9Vikram Aggarwal Log.d(TAG, "Going into airplane mode."); 8446a5929b086a61a955a4a2f43f5fa251e8754ff4aChristopher Tate Settings.Global.putInt(getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1); 845ea1186db19e673b44084b43b6a70bbdb07480aa9Vikram Aggarwal final Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); 846ea1186db19e673b44084b43b6a70bbdb07480aa9Vikram Aggarwal intent.putExtra("state", true); 8476a5929b086a61a955a4a2f43f5fa251e8754ff4aChristopher Tate sendBroadcastAsUser(intent, UserHandle.ALL); 848ea1186db19e673b44084b43b6a70bbdb07480aa9Vikram Aggarwal } 849ea1186db19e673b44084b43b6a70bbdb07480aa9Vikram Aggarwal } 850ea1186db19e673b44084b43b6a70bbdb07480aa9Vikram Aggarwal 851ea1186db19e673b44084b43b6a70bbdb07480aa9Vikram Aggarwal /** 852bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal * Code to update the state of, and handle clicks from, the "Emergency call" button. 853bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal * 854bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal * This code is mostly duplicated from the corresponding code in 855bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal * LockPatternUtils and LockPatternKeyguardView under frameworks/base. 856bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal */ 8578373b451692a39abdfd12444241c016831e1a4a4David Brown private void updateEmergencyCallButtonState() { 858bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal final Button emergencyCall = (Button) findViewById(R.id.emergencyCallButton); 8598373b451692a39abdfd12444241c016831e1a4a4David Brown // The button isn't present at all in some configurations. 860bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal if (emergencyCall == null) 861bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal return; 8628373b451692a39abdfd12444241c016831e1a4a4David Brown 8638373b451692a39abdfd12444241c016831e1a4a4David Brown if (isEmergencyCallCapable()) { 864bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal emergencyCall.setVisibility(View.VISIBLE); 865bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal emergencyCall.setOnClickListener(new View.OnClickListener() { 866bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal @Override 867bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal 8688373b451692a39abdfd12444241c016831e1a4a4David Brown public void onClick(View v) { 8698373b451692a39abdfd12444241c016831e1a4a4David Brown takeEmergencyCallAction(); 8708373b451692a39abdfd12444241c016831e1a4a4David Brown } 8718373b451692a39abdfd12444241c016831e1a4a4David Brown }); 8728373b451692a39abdfd12444241c016831e1a4a4David Brown } else { 873bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal emergencyCall.setVisibility(View.GONE); 8748373b451692a39abdfd12444241c016831e1a4a4David Brown return; 8758373b451692a39abdfd12444241c016831e1a4a4David Brown } 8768373b451692a39abdfd12444241c016831e1a4a4David Brown 8778373b451692a39abdfd12444241c016831e1a4a4David Brown int textId; 87835230e9ed76de518c7ea46d9277bdc8fa765efd8Santos Cordon if (getPhoneManager().isInAPhoneCall()) { 87989c7570dd42ce6945ce8e092892a22ec79c30c82Paul Lawrence // Show "return to call" 8808373b451692a39abdfd12444241c016831e1a4a4David Brown textId = R.string.cryptkeeper_return_to_call; 8818373b451692a39abdfd12444241c016831e1a4a4David Brown } else { 8828373b451692a39abdfd12444241c016831e1a4a4David Brown textId = R.string.cryptkeeper_emergency_call; 8838373b451692a39abdfd12444241c016831e1a4a4David Brown } 884bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal emergencyCall.setText(textId); 8858373b451692a39abdfd12444241c016831e1a4a4David Brown } 8868373b451692a39abdfd12444241c016831e1a4a4David Brown 8878373b451692a39abdfd12444241c016831e1a4a4David Brown private boolean isEmergencyCallCapable() { 8888373b451692a39abdfd12444241c016831e1a4a4David Brown return getResources().getBoolean(com.android.internal.R.bool.config_voice_capable); 8898373b451692a39abdfd12444241c016831e1a4a4David Brown } 8908373b451692a39abdfd12444241c016831e1a4a4David Brown 8918373b451692a39abdfd12444241c016831e1a4a4David Brown private void takeEmergencyCallAction() { 89235230e9ed76de518c7ea46d9277bdc8fa765efd8Santos Cordon PhoneManager phoneManager = getPhoneManager(); 89335230e9ed76de518c7ea46d9277bdc8fa765efd8Santos Cordon if (phoneManager.isInAPhoneCall()) { 89435230e9ed76de518c7ea46d9277bdc8fa765efd8Santos Cordon phoneManager.showCallScreen(false /* showDialpad */); 8958373b451692a39abdfd12444241c016831e1a4a4David Brown } else { 8968373b451692a39abdfd12444241c016831e1a4a4David Brown launchEmergencyDialer(); 8978373b451692a39abdfd12444241c016831e1a4a4David Brown } 8988373b451692a39abdfd12444241c016831e1a4a4David Brown } 8998373b451692a39abdfd12444241c016831e1a4a4David Brown 9008373b451692a39abdfd12444241c016831e1a4a4David Brown 9018373b451692a39abdfd12444241c016831e1a4a4David Brown private void launchEmergencyDialer() { 902bfa3a64310162c8f29eae208220988380ffeea6eVikram Aggarwal final Intent intent = new Intent(ACTION_EMERGENCY_DIAL); 9038373b451692a39abdfd12444241c016831e1a4a4David Brown intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 9048373b451692a39abdfd12444241c016831e1a4a4David Brown | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); 9055a70f05e0d86443cd97b186d2a5101eb4c7eed81Paul Lawrence setBackFunctionality(true); 9068373b451692a39abdfd12444241c016831e1a4a4David Brown startActivity(intent); 9078373b451692a39abdfd12444241c016831e1a4a4David Brown } 908d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal 9093afbdf006057c93f930694e26306a3cc9cea34e4Santos Cordon private TelephonyManager getTelephonyManager() { 9103afbdf006057c93f930694e26306a3cc9cea34e4Santos Cordon return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); 9113afbdf006057c93f930694e26306a3cc9cea34e4Santos Cordon } 9123afbdf006057c93f930694e26306a3cc9cea34e4Santos Cordon 91335230e9ed76de518c7ea46d9277bdc8fa765efd8Santos Cordon private PhoneManager getPhoneManager() { 91435230e9ed76de518c7ea46d9277bdc8fa765efd8Santos Cordon return (PhoneManager) getSystemService(Context.PHONE_SERVICE); 91535230e9ed76de518c7ea46d9277bdc8fa765efd8Santos Cordon } 91635230e9ed76de518c7ea46d9277bdc8fa765efd8Santos Cordon 917d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal /** 918d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal * Listen to key events so we can disable sounds when we get a keyinput in EditText. 919d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal */ 920d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal private void delayAudioNotification() { 921d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal mNotificationCountdown = 20; 922d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal } 923d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal 924d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal @Override 925d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal public boolean onKey(View v, int keyCode, KeyEvent event) { 926d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal delayAudioNotification(); 927d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal return false; 928d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal } 929d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal 930d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal @Override 931d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal public boolean onTouch(View v, MotionEvent event) { 932d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal delayAudioNotification(); 933d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal return false; 934d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal } 935d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal 936d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal @Override 937d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal public void beforeTextChanged(CharSequence s, int start, int count, int after) { 938d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal return; 939d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal } 940d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal 941d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal @Override 942d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal public void onTextChanged(CharSequence s, int start, int before, int count) { 943d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal delayAudioNotification(); 944d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal } 945d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal 946d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal @Override 947d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal public void afterTextChanged(Editable s) { 948d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal return; 949d1147250dd5fb7022b01a5c899d365069bb625f8Vikram Aggarwal } 9508373b451692a39abdfd12444241c016831e1a4a4David Brown} 951