Dianne Hackborn | abc3dc6 | 2010-01-20 13:40:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
Svetoslav | 5244844 | 2014-09-29 18:15:45 -0700 | [diff] [blame] | 19 | import android.accessibilityservice.AccessibilityServiceInfo; |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 20 | import android.app.Activity; |
Lucky Zhang | 3bcea02 | 2014-11-25 18:22:14 -0800 | [diff] [blame] | 21 | import android.app.AlertDialog; |
| 22 | import android.app.Dialog; |
| 23 | import android.app.DialogFragment; |
Maurice Lam | 52c75ba | 2014-11-25 14:06:38 -0800 | [diff] [blame] | 24 | import android.app.Fragment; |
Lucky Zhang | 3bcea02 | 2014-11-25 18:22:14 -0800 | [diff] [blame] | 25 | import android.app.FragmentManager; |
Dianne Hackborn | 4037c7f | 2010-02-26 17:26:55 -0800 | [diff] [blame] | 26 | import android.app.admin.DevicePolicyManager; |
Dianne Hackborn | abc3dc6 | 2010-01-20 13:40:19 -0800 | [diff] [blame] | 27 | import android.content.Context; |
Lucky Zhang | 3bcea02 | 2014-11-25 18:22:14 -0800 | [diff] [blame] | 28 | import android.content.DialogInterface; |
Dianne Hackborn | abc3dc6 | 2010-01-20 13:40:19 -0800 | [diff] [blame] | 29 | import android.content.Intent; |
| 30 | import android.os.Bundle; |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 31 | import android.os.Process; |
Adrian Roos | 5437588 | 2015-04-16 17:11:22 -0700 | [diff] [blame] | 32 | import android.os.UserHandle; |
Jim Miller | bbb4afa | 2010-04-08 19:40:19 -0700 | [diff] [blame] | 33 | import android.preference.Preference; |
Jim Miller | bbb4afa | 2010-04-08 19:40:19 -0700 | [diff] [blame] | 34 | import android.preference.PreferenceScreen; |
Brian Carlstrom | d4023b7 | 2011-05-25 13:24:20 -0700 | [diff] [blame] | 35 | import android.security.KeyStore; |
Jim Miller | 595982d | 2015-04-01 16:49:33 -0700 | [diff] [blame] | 36 | import android.hardware.fingerprint.Fingerprint; |
| 37 | import android.hardware.fingerprint.FingerprintManager; |
| 38 | import android.hardware.fingerprint.FingerprintManager.RemovalCallback; |
rich cannings | 27d6f8d | 2013-05-29 14:54:58 -0700 | [diff] [blame] | 39 | import android.util.EventLog; |
Lucky Zhang | 3bcea02 | 2014-11-25 18:22:14 -0800 | [diff] [blame] | 40 | import android.util.Log; |
Maurice Lam | 87fadbe | 2015-08-03 15:33:25 -0700 | [diff] [blame^] | 41 | import android.view.LayoutInflater; |
| 42 | import android.view.View; |
Svetoslav | 5244844 | 2014-09-29 18:15:45 -0700 | [diff] [blame] | 43 | import android.view.accessibility.AccessibilityManager; |
Maurice Lam | 87fadbe | 2015-08-03 15:33:25 -0700 | [diff] [blame^] | 44 | import android.widget.ListView; |
Jim Miller | d16c9b7 | 2015-03-24 16:02:59 -0700 | [diff] [blame] | 45 | import android.widget.Toast; |
| 46 | |
Chris Wren | 8a963ba | 2015-03-20 10:29:14 -0400 | [diff] [blame] | 47 | import com.android.internal.logging.MetricsLogger; |
Gilles Debunne | 6465054 | 2011-08-23 11:01:35 -0700 | [diff] [blame] | 48 | import com.android.internal.widget.LockPatternUtils; |
| 49 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 50 | public class ChooseLockGeneric extends SettingsActivity { |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 51 | public static final String CONFIRM_CREDENTIALS = "confirm_credentials"; |
Dianne Hackborn | abc3dc6 | 2010-01-20 13:40:19 -0800 | [diff] [blame] | 52 | |
| 53 | @Override |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 54 | public Intent getIntent() { |
| 55 | Intent modIntent = new Intent(super.getIntent()); |
Maurice Lam | 52c75ba | 2014-11-25 14:06:38 -0800 | [diff] [blame] | 56 | modIntent.putExtra(EXTRA_SHOW_FRAGMENT, getFragmentClass().getName()); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 57 | return modIntent; |
| 58 | } |
Jim Miller | bbb4afa | 2010-04-08 19:40:19 -0700 | [diff] [blame] | 59 | |
Amith Yamasani | a677ee2 | 2013-07-26 13:38:41 -0700 | [diff] [blame] | 60 | @Override |
| 61 | protected boolean isValidFragment(String fragmentName) { |
| 62 | if (ChooseLockGenericFragment.class.getName().equals(fragmentName)) return true; |
| 63 | return false; |
| 64 | } |
| 65 | |
Maurice Lam | 52c75ba | 2014-11-25 14:06:38 -0800 | [diff] [blame] | 66 | /* package */ Class<? extends Fragment> getFragmentClass() { |
| 67 | return ChooseLockGenericFragment.class; |
| 68 | } |
| 69 | |
Amith Yamasani | 6602677 | 2013-09-25 14:05:33 -0700 | [diff] [blame] | 70 | public static class InternalActivity extends ChooseLockGeneric { |
| 71 | } |
| 72 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 73 | public static class ChooseLockGenericFragment extends SettingsPreferenceFragment { |
Jim Miller | 3fb2fb8 | 2015-03-11 20:17:39 -0700 | [diff] [blame] | 74 | private static final String TAG = "ChooseLockGenericFragment"; |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 75 | private static final int MIN_PASSWORD_LENGTH = 4; |
| 76 | private static final String KEY_UNLOCK_SET_OFF = "unlock_set_off"; |
| 77 | private static final String KEY_UNLOCK_SET_NONE = "unlock_set_none"; |
| 78 | private static final String KEY_UNLOCK_SET_PIN = "unlock_set_pin"; |
| 79 | private static final String KEY_UNLOCK_SET_PASSWORD = "unlock_set_password"; |
| 80 | private static final String KEY_UNLOCK_SET_PATTERN = "unlock_set_pattern"; |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 81 | private static final String PASSWORD_CONFIRMED = "password_confirmed"; |
Jim Miller | 47f1cd4 | 2012-04-27 18:11:03 -0700 | [diff] [blame] | 82 | private static final String WAITING_FOR_CONFIRMATION = "waiting_for_confirmation"; |
Brian Carlstrom | d4023b7 | 2011-05-25 13:24:20 -0700 | [diff] [blame] | 83 | public static final String MINIMUM_QUALITY_KEY = "minimum_quality"; |
Jim Miller | 3fb2fb8 | 2015-03-11 20:17:39 -0700 | [diff] [blame] | 84 | public static final String HIDE_DISABLED_PREFS = "hide_disabled_prefs"; |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 85 | public static final String ENCRYPT_REQUESTED_QUALITY = "encrypt_requested_quality"; |
| 86 | public static final String ENCRYPT_REQUESTED_DISABLED = "encrypt_requested_disabled"; |
Lucky Zhang | 3bcea02 | 2014-11-25 18:22:14 -0800 | [diff] [blame] | 87 | public static final String TAG_FRP_WARNING_DIALOG = "frp_warning_dialog"; |
Jim Miller | bbb4afa | 2010-04-08 19:40:19 -0700 | [diff] [blame] | 88 | |
Jim Miller | 3fb2fb8 | 2015-03-11 20:17:39 -0700 | [diff] [blame] | 89 | private static final int CONFIRM_EXISTING_REQUEST = 100; |
| 90 | private static final int ENABLE_ENCRYPTION_REQUEST = 101; |
| 91 | private static final int CHOOSE_LOCK_REQUEST = 102; |
Danielle Millett | 80412e7 | 2011-10-17 19:21:19 -0400 | [diff] [blame] | 92 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 93 | private ChooseLockSettingsHelper mChooseLockSettingsHelper; |
| 94 | private DevicePolicyManager mDPM; |
Brian Carlstrom | d4023b7 | 2011-05-25 13:24:20 -0700 | [diff] [blame] | 95 | private KeyStore mKeyStore; |
Andres Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 96 | private boolean mHasChallenge = false; |
| 97 | private long mChallenge; |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 98 | private boolean mPasswordConfirmed = false; |
Jim Miller | 47f1cd4 | 2012-04-27 18:11:03 -0700 | [diff] [blame] | 99 | private boolean mWaitingForConfirmation = false; |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 100 | private int mEncryptionRequestQuality; |
| 101 | private boolean mEncryptionRequestDisabled; |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 102 | private boolean mRequirePassword; |
Maurice Lam | c0e7879 | 2015-07-20 14:49:29 -0700 | [diff] [blame] | 103 | private boolean mForFingerprint = false; |
Andres Morales | a0e1236 | 2015-04-02 09:00:41 -0700 | [diff] [blame] | 104 | private String mUserPassword; |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 105 | private LockPatternUtils mLockPatternUtils; |
Jim Miller | 9218687 | 2015-03-04 18:07:32 -0800 | [diff] [blame] | 106 | private FingerprintManager mFingerprintManager; |
Jim Miller | d16c9b7 | 2015-03-24 16:02:59 -0700 | [diff] [blame] | 107 | private RemovalCallback mRemovalCallback = new RemovalCallback() { |
| 108 | |
| 109 | @Override |
| 110 | public void onRemovalSucceeded(Fingerprint fingerprint) { |
| 111 | Log.v(TAG, "Fingerprint removed: " + fingerprint.getFingerId()); |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public void onRemovalError(Fingerprint fp, int errMsgId, CharSequence errString) { |
| 116 | Toast.makeText(getActivity(), errString, Toast.LENGTH_SHORT); |
| 117 | } |
| 118 | }; |
Jim Miller | bbb4afa | 2010-04-08 19:40:19 -0700 | [diff] [blame] | 119 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 120 | @Override |
Chris Wren | 8a963ba | 2015-03-20 10:29:14 -0400 | [diff] [blame] | 121 | protected int getMetricsCategory() { |
| 122 | return MetricsLogger.CHOOSE_LOCK_GENERIC; |
| 123 | } |
| 124 | |
| 125 | @Override |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 126 | public void onCreate(Bundle savedInstanceState) { |
| 127 | super.onCreate(savedInstanceState); |
| 128 | |
Jim Miller | 9218687 | 2015-03-04 18:07:32 -0800 | [diff] [blame] | 129 | mFingerprintManager = |
| 130 | (FingerprintManager) getActivity().getSystemService(Context.FINGERPRINT_SERVICE); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 131 | mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); |
Brian Carlstrom | d4023b7 | 2011-05-25 13:24:20 -0700 | [diff] [blame] | 132 | mKeyStore = KeyStore.getInstance(); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 133 | mChooseLockSettingsHelper = new ChooseLockSettingsHelper(this.getActivity()); |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 134 | mLockPatternUtils = new LockPatternUtils(getActivity()); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 135 | |
Danielle Millett | c474a88 | 2011-09-14 11:42:06 -0400 | [diff] [blame] | 136 | // Defaults to needing to confirm credentials |
| 137 | final boolean confirmCredentials = getActivity().getIntent() |
| 138 | .getBooleanExtra(CONFIRM_CREDENTIALS, true); |
Amith Yamasani | 6602677 | 2013-09-25 14:05:33 -0700 | [diff] [blame] | 139 | if (getActivity() instanceof ChooseLockGeneric.InternalActivity) { |
| 140 | mPasswordConfirmed = !confirmCredentials; |
| 141 | } |
Danielle Millett | c474a88 | 2011-09-14 11:42:06 -0400 | [diff] [blame] | 142 | |
Andres Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 143 | mHasChallenge = getActivity().getIntent().getBooleanExtra( |
| 144 | ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, false); |
| 145 | mChallenge = getActivity().getIntent().getLongExtra( |
| 146 | ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, 0); |
Maurice Lam | c0e7879 | 2015-07-20 14:49:29 -0700 | [diff] [blame] | 147 | mForFingerprint = getActivity().getIntent().getBooleanExtra( |
| 148 | ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, false); |
Andres Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 149 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 150 | if (savedInstanceState != null) { |
| 151 | mPasswordConfirmed = savedInstanceState.getBoolean(PASSWORD_CONFIRMED); |
Jim Miller | 47f1cd4 | 2012-04-27 18:11:03 -0700 | [diff] [blame] | 152 | mWaitingForConfirmation = savedInstanceState.getBoolean(WAITING_FOR_CONFIRMATION); |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 153 | mEncryptionRequestQuality = savedInstanceState.getInt(ENCRYPT_REQUESTED_QUALITY); |
| 154 | mEncryptionRequestDisabled = savedInstanceState.getBoolean( |
| 155 | ENCRYPT_REQUESTED_DISABLED); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 156 | } |
| 157 | |
Jim Miller | 47f1cd4 | 2012-04-27 18:11:03 -0700 | [diff] [blame] | 158 | if (mPasswordConfirmed) { |
| 159 | updatePreferencesOrFinish(); |
| 160 | } else if (!mWaitingForConfirmation) { |
Andy Stadler | 6370c87 | 2011-01-21 16:25:22 -0800 | [diff] [blame] | 161 | ChooseLockSettingsHelper helper = |
| 162 | new ChooseLockSettingsHelper(this.getActivity(), this); |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 163 | if (!helper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST, |
Andres Morales | a0e1236 | 2015-04-02 09:00:41 -0700 | [diff] [blame] | 164 | getString(R.string.unlock_set_unlock_launch_picker_title), true)) { |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 165 | mPasswordConfirmed = true; // no password set, so no need to confirm |
| 166 | updatePreferencesOrFinish(); |
Jim Miller | 47f1cd4 | 2012-04-27 18:11:03 -0700 | [diff] [blame] | 167 | } else { |
| 168 | mWaitingForConfirmation = true; |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 169 | } |
Jim Miller | bbb4afa | 2010-04-08 19:40:19 -0700 | [diff] [blame] | 170 | } |
Jim Miller | bbb4afa | 2010-04-08 19:40:19 -0700 | [diff] [blame] | 171 | } |
Jim Miller | bbb4afa | 2010-04-08 19:40:19 -0700 | [diff] [blame] | 172 | |
Amith Yamasani | c666c65 | 2012-10-24 10:27:05 -0700 | [diff] [blame] | 173 | @Override |
Maurice Lam | 87fadbe | 2015-08-03 15:33:25 -0700 | [diff] [blame^] | 174 | public void onViewCreated(View view, Bundle savedInstanceState) { |
| 175 | super.onViewCreated(view, savedInstanceState); |
| 176 | if (mForFingerprint) { |
| 177 | final LayoutInflater inflater = LayoutInflater.from(getContext()); |
| 178 | final ListView listView = getListView(); |
| 179 | final View fingerprintHeader = inflater.inflate( |
| 180 | R.layout.choose_lock_generic_fingerprint_header, listView, false); |
| 181 | listView.addHeaderView(fingerprintHeader, null, false); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | @Override |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 186 | public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, |
| 187 | Preference preference) { |
| 188 | final String key = preference.getKey(); |
rich cannings | 27d6f8d | 2013-05-29 14:54:58 -0700 | [diff] [blame] | 189 | |
Adrian Roos | 5437588 | 2015-04-16 17:11:22 -0700 | [diff] [blame] | 190 | if (!isUnlockMethodSecure(key) && mLockPatternUtils.isSecure(UserHandle.myUserId())) { |
Lucky Zhang | 3bcea02 | 2014-11-25 18:22:14 -0800 | [diff] [blame] | 191 | // Show the disabling FRP warning only when the user is switching from a secure |
| 192 | // unlock method to an insecure one |
| 193 | showFactoryResetProtectionWarningDialog(key); |
| 194 | return true; |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 195 | } else { |
Lucky Zhang | 3bcea02 | 2014-11-25 18:22:14 -0800 | [diff] [blame] | 196 | return setUnlockMethod(key); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 197 | } |
Jim Miller | bbb4afa | 2010-04-08 19:40:19 -0700 | [diff] [blame] | 198 | } |
Jim Miller | bbb4afa | 2010-04-08 19:40:19 -0700 | [diff] [blame] | 199 | |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 200 | /** |
| 201 | * If the device has encryption already enabled, then ask the user if they |
| 202 | * also want to encrypt the phone with this password. |
| 203 | * |
| 204 | * @param quality |
| 205 | * @param disabled |
| 206 | */ |
Andres Morales | a0e1236 | 2015-04-02 09:00:41 -0700 | [diff] [blame] | 207 | // TODO: why does this take disabled, its always called with a quality higher than |
| 208 | // what makes sense with disabled == true |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 209 | private void maybeEnableEncryption(int quality, boolean disabled) { |
Andrei Kapishnikov | 146fc11 | 2015-04-09 11:08:16 -0400 | [diff] [blame] | 210 | DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE); |
| 211 | if (Process.myUserHandle().isOwner() && LockPatternUtils.isDeviceEncryptionEnabled() |
| 212 | && !dpm.getDoNotAskCredentialsOnBoot()) { |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 213 | mEncryptionRequestQuality = quality; |
| 214 | mEncryptionRequestDisabled = disabled; |
Maurice Lam | ecd2b7b | 2014-12-01 10:41:49 -0800 | [diff] [blame] | 215 | final Context context = getActivity(); |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 216 | // If accessibility is enabled and the user hasn't seen this dialog before, set the |
| 217 | // default state to agree with that which is compatible with accessibility |
| 218 | // (password not required). |
Maurice Lam | ecd2b7b | 2014-12-01 10:41:49 -0800 | [diff] [blame] | 219 | final boolean accEn = AccessibilityManager.getInstance(context).isEnabled(); |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 220 | final boolean required = mLockPatternUtils.isCredentialRequiredToDecrypt(!accEn); |
Maurice Lam | ecd2b7b | 2014-12-01 10:41:49 -0800 | [diff] [blame] | 221 | Intent intent = getEncryptionInterstitialIntent(context, quality, required); |
Maurice Lam | c0e7879 | 2015-07-20 14:49:29 -0700 | [diff] [blame] | 222 | intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, |
| 223 | mForFingerprint); |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 224 | startActivityForResult(intent, ENABLE_ENCRYPTION_REQUEST); |
| 225 | } else { |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 226 | mRequirePassword = false; // device encryption not enabled or not device owner. |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 227 | updateUnlockMethodAndFinish(quality, disabled); |
| 228 | } |
| 229 | } |
| 230 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 231 | @Override |
| 232 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 233 | super.onActivityResult(requestCode, resultCode, data); |
Jim Miller | 47f1cd4 | 2012-04-27 18:11:03 -0700 | [diff] [blame] | 234 | mWaitingForConfirmation = false; |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 235 | if (requestCode == CONFIRM_EXISTING_REQUEST && resultCode == Activity.RESULT_OK) { |
| 236 | mPasswordConfirmed = true; |
Andres Morales | a0e1236 | 2015-04-02 09:00:41 -0700 | [diff] [blame] | 237 | mUserPassword = data.getStringExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 238 | updatePreferencesOrFinish(); |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 239 | } else if (requestCode == ENABLE_ENCRYPTION_REQUEST |
| 240 | && resultCode == Activity.RESULT_OK) { |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 241 | mRequirePassword = data.getBooleanExtra( |
| 242 | EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, true); |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 243 | updateUnlockMethodAndFinish(mEncryptionRequestQuality, mEncryptionRequestDisabled); |
Maurice Lam | 9066a5c | 2015-01-22 18:35:11 -0800 | [diff] [blame] | 244 | } else if (requestCode == CHOOSE_LOCK_REQUEST) { |
| 245 | getActivity().setResult(resultCode, data); |
| 246 | finish(); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 247 | } else { |
| 248 | getActivity().setResult(Activity.RESULT_CANCELED); |
| 249 | finish(); |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | @Override |
| 254 | public void onSaveInstanceState(Bundle outState) { |
| 255 | super.onSaveInstanceState(outState); |
| 256 | // Saved so we don't force user to re-enter their password if configuration changes |
| 257 | outState.putBoolean(PASSWORD_CONFIRMED, mPasswordConfirmed); |
Jim Miller | 47f1cd4 | 2012-04-27 18:11:03 -0700 | [diff] [blame] | 258 | outState.putBoolean(WAITING_FOR_CONFIRMATION, mWaitingForConfirmation); |
Jim Miller | 46c7f6d | 2014-10-13 18:15:17 -0700 | [diff] [blame] | 259 | outState.putInt(ENCRYPT_REQUESTED_QUALITY, mEncryptionRequestQuality); |
| 260 | outState.putBoolean(ENCRYPT_REQUESTED_DISABLED, mEncryptionRequestDisabled); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | private void updatePreferencesOrFinish() { |
Jim Miller | 5541a86 | 2011-09-02 17:33:53 -0700 | [diff] [blame] | 264 | Intent intent = getActivity().getIntent(); |
| 265 | int quality = intent.getIntExtra(LockPatternUtils.PASSWORD_TYPE_KEY, -1); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 266 | if (quality == -1) { |
Andy Stadler | 6370c87 | 2011-01-21 16:25:22 -0800 | [diff] [blame] | 267 | // If caller didn't specify password quality, show UI and allow the user to choose. |
Jim Miller | 5541a86 | 2011-09-02 17:33:53 -0700 | [diff] [blame] | 268 | quality = intent.getIntExtra(MINIMUM_QUALITY_KEY, -1); |
Adrian Roos | f788718 | 2015-01-07 20:51:57 +0100 | [diff] [blame] | 269 | quality = upgradeQuality(quality); |
Jim Miller | 3fb2fb8 | 2015-03-11 20:17:39 -0700 | [diff] [blame] | 270 | final boolean hideDisabledPrefs = intent.getBooleanExtra( |
| 271 | HIDE_DISABLED_PREFS, false); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 272 | final PreferenceScreen prefScreen = getPreferenceScreen(); |
| 273 | if (prefScreen != null) { |
| 274 | prefScreen.removeAll(); |
| 275 | } |
| 276 | addPreferencesFromResource(R.xml.security_settings_picker); |
Jim Miller | 3fb2fb8 | 2015-03-11 20:17:39 -0700 | [diff] [blame] | 277 | disableUnusablePreferences(quality, hideDisabledPrefs); |
Jason Monk | 9a64a42 | 2015-03-30 11:00:36 -0400 | [diff] [blame] | 278 | updateCurrentPreference(); |
Svetoslav | 5244844 | 2014-09-29 18:15:45 -0700 | [diff] [blame] | 279 | updatePreferenceSummaryIfNeeded(); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 280 | } else { |
| 281 | updateUnlockMethodAndFinish(quality, false); |
| 282 | } |
| 283 | } |
| 284 | |
Jason Monk | 9a64a42 | 2015-03-30 11:00:36 -0400 | [diff] [blame] | 285 | private void updateCurrentPreference() { |
| 286 | String currentKey = getKeyForCurrent(); |
| 287 | Preference preference = findPreference(currentKey); |
| 288 | if (preference != null) { |
| 289 | preference.setSummary(R.string.current_screen_lock); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | private String getKeyForCurrent() { |
Adrian Roos | 5437588 | 2015-04-16 17:11:22 -0700 | [diff] [blame] | 294 | if (mLockPatternUtils.isLockScreenDisabled(UserHandle.myUserId())) { |
Jason Monk | 9a64a42 | 2015-03-30 11:00:36 -0400 | [diff] [blame] | 295 | return KEY_UNLOCK_SET_OFF; |
| 296 | } |
Adrian Roos | 5437588 | 2015-04-16 17:11:22 -0700 | [diff] [blame] | 297 | switch (mLockPatternUtils.getKeyguardStoredPasswordQuality(UserHandle.myUserId())) { |
Jason Monk | 9a64a42 | 2015-03-30 11:00:36 -0400 | [diff] [blame] | 298 | case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING: |
| 299 | return KEY_UNLOCK_SET_PATTERN; |
| 300 | case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC: |
| 301 | case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX: |
| 302 | return KEY_UNLOCK_SET_PIN; |
| 303 | case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC: |
| 304 | case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC: |
| 305 | return KEY_UNLOCK_SET_PASSWORD; |
| 306 | case DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED: |
| 307 | return KEY_UNLOCK_SET_NONE; |
| 308 | } |
| 309 | return null; |
| 310 | } |
| 311 | |
Adrian Roos | f788718 | 2015-01-07 20:51:57 +0100 | [diff] [blame] | 312 | /** increases the quality if necessary */ |
| 313 | private int upgradeQuality(int quality) { |
Brian Carlstrom | d4023b7 | 2011-05-25 13:24:20 -0700 | [diff] [blame] | 314 | quality = upgradeQualityForDPM(quality); |
Paul Lawrence | b05f39d | 2014-02-04 10:22:19 -0800 | [diff] [blame] | 315 | return quality; |
Brian Carlstrom | d4023b7 | 2011-05-25 13:24:20 -0700 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | private int upgradeQualityForDPM(int quality) { |
| 319 | // Compare min allowed password quality |
| 320 | int minQuality = mDPM.getPasswordQuality(null); |
| 321 | if (quality < minQuality) { |
| 322 | quality = minQuality; |
| 323 | } |
| 324 | return quality; |
| 325 | } |
| 326 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 327 | /*** |
Lucky Zhang | df8566a | 2014-12-05 15:00:20 -0800 | [diff] [blame] | 328 | * Disables preferences that are less secure than required quality. The actual |
| 329 | * implementation is in disableUnusablePreferenceImpl. |
| 330 | * |
| 331 | * @param quality the requested quality. |
Jim Miller | 3fb2fb8 | 2015-03-11 20:17:39 -0700 | [diff] [blame] | 332 | * @param hideDisabledPrefs if false preferences show why they were disabled; otherwise |
| 333 | * they're not shown at all. |
Lucky Zhang | df8566a | 2014-12-05 15:00:20 -0800 | [diff] [blame] | 334 | */ |
Jim Miller | 3fb2fb8 | 2015-03-11 20:17:39 -0700 | [diff] [blame] | 335 | protected void disableUnusablePreferences(final int quality, boolean hideDisabledPrefs) { |
| 336 | disableUnusablePreferencesImpl(quality, hideDisabledPrefs); |
Lucky Zhang | df8566a | 2014-12-05 15:00:20 -0800 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | /*** |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 340 | * Disables preferences that are less secure than required quality. |
| 341 | * |
| 342 | * @param quality the requested quality. |
Lucky Zhang | df8566a | 2014-12-05 15:00:20 -0800 | [diff] [blame] | 343 | * @param hideDisabled whether to hide disable screen lock options. |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 344 | */ |
Lucky Zhang | df8566a | 2014-12-05 15:00:20 -0800 | [diff] [blame] | 345 | protected void disableUnusablePreferencesImpl(final int quality, |
Adrian Roos | f788718 | 2015-01-07 20:51:57 +0100 | [diff] [blame] | 346 | boolean hideDisabled) { |
Amith Yamasani | cf26bb2 | 2011-09-26 10:27:43 -0700 | [diff] [blame] | 347 | final PreferenceScreen entries = getPreferenceScreen(); |
Jim Miller | 783ea85 | 2012-11-01 19:39:21 -0700 | [diff] [blame] | 348 | |
Amith Yamasani | cf26bb2 | 2011-09-26 10:27:43 -0700 | [diff] [blame] | 349 | for (int i = entries.getPreferenceCount() - 1; i >= 0; --i) { |
| 350 | Preference pref = entries.getPreference(i); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 351 | if (pref instanceof PreferenceScreen) { |
Adrian Roos | 591dc85 | 2015-04-07 16:55:29 +0200 | [diff] [blame] | 352 | final String key = pref.getKey(); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 353 | boolean enabled = true; |
Jim Miller | 5541a86 | 2011-09-02 17:33:53 -0700 | [diff] [blame] | 354 | boolean visible = true; |
Amith Yamasani | cf26bb2 | 2011-09-26 10:27:43 -0700 | [diff] [blame] | 355 | if (KEY_UNLOCK_SET_OFF.equals(key)) { |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 356 | enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; |
| 357 | } else if (KEY_UNLOCK_SET_NONE.equals(key)) { |
| 358 | enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; |
| 359 | } else if (KEY_UNLOCK_SET_PATTERN.equals(key)) { |
| 360 | enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_SOMETHING; |
| 361 | } else if (KEY_UNLOCK_SET_PIN.equals(key)) { |
Nicolas Prevot | 8fd852e | 2014-01-25 01:02:04 +0000 | [diff] [blame] | 362 | enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX; |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 363 | } else if (KEY_UNLOCK_SET_PASSWORD.equals(key)) { |
| 364 | enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_COMPLEX; |
| 365 | } |
Lucky Zhang | df8566a | 2014-12-05 15:00:20 -0800 | [diff] [blame] | 366 | if (hideDisabled) { |
Adrian Roos | 591dc85 | 2015-04-07 16:55:29 +0200 | [diff] [blame] | 367 | visible = enabled; |
Lucky Zhang | df8566a | 2014-12-05 15:00:20 -0800 | [diff] [blame] | 368 | } |
Adrian Roos | f788718 | 2015-01-07 20:51:57 +0100 | [diff] [blame] | 369 | if (!visible) { |
Amith Yamasani | cf26bb2 | 2011-09-26 10:27:43 -0700 | [diff] [blame] | 370 | entries.removePreference(pref); |
Jim Miller | 5541a86 | 2011-09-02 17:33:53 -0700 | [diff] [blame] | 371 | } else if (!enabled) { |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 372 | pref.setSummary(R.string.unlock_set_unlock_disabled_summary); |
| 373 | pref.setEnabled(false); |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | |
Svetoslav | 5244844 | 2014-09-29 18:15:45 -0700 | [diff] [blame] | 379 | private void updatePreferenceSummaryIfNeeded() { |
Svetoslav | 40ca78f | 2014-10-17 14:37:02 -0700 | [diff] [blame] | 380 | if (LockPatternUtils.isDeviceEncrypted()) { |
| 381 | return; |
| 382 | } |
| 383 | |
Svetoslav | 5244844 | 2014-09-29 18:15:45 -0700 | [diff] [blame] | 384 | if (AccessibilityManager.getInstance(getActivity()).getEnabledAccessibilityServiceList( |
| 385 | AccessibilityServiceInfo.FEEDBACK_ALL_MASK).isEmpty()) { |
| 386 | return; |
| 387 | } |
| 388 | |
| 389 | CharSequence summary = getString(R.string.secure_lock_encryption_warning); |
| 390 | |
| 391 | PreferenceScreen screen = getPreferenceScreen(); |
| 392 | final int preferenceCount = screen.getPreferenceCount(); |
| 393 | for (int i = 0; i < preferenceCount; i++) { |
| 394 | Preference preference = screen.getPreference(i); |
| 395 | switch (preference.getKey()) { |
| 396 | case KEY_UNLOCK_SET_PATTERN: |
| 397 | case KEY_UNLOCK_SET_PIN: |
| 398 | case KEY_UNLOCK_SET_PASSWORD: { |
| 399 | preference.setSummary(summary); |
| 400 | } break; |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | |
Maurice Lam | 6b19fa9 | 2014-11-25 19:25:56 -0800 | [diff] [blame] | 405 | protected Intent getLockPasswordIntent(Context context, int quality, |
Adrian Roos | f788718 | 2015-01-07 20:51:57 +0100 | [diff] [blame] | 406 | int minLength, final int maxLength, |
Maurice Lam | 6b19fa9 | 2014-11-25 19:25:56 -0800 | [diff] [blame] | 407 | boolean requirePasswordToDecrypt, boolean confirmCredentials) { |
Adrian Roos | f788718 | 2015-01-07 20:51:57 +0100 | [diff] [blame] | 408 | return ChooseLockPassword.createIntent(context, quality, minLength, |
Maurice Lam | 6b19fa9 | 2014-11-25 19:25:56 -0800 | [diff] [blame] | 409 | maxLength, requirePasswordToDecrypt, confirmCredentials); |
| 410 | } |
| 411 | |
Andres Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 412 | protected Intent getLockPasswordIntent(Context context, int quality, |
| 413 | int minLength, final int maxLength, |
| 414 | boolean requirePasswordToDecrypt, long challenge) { |
| 415 | return ChooseLockPassword.createIntent(context, quality, minLength, |
| 416 | maxLength, requirePasswordToDecrypt, challenge); |
| 417 | } |
| 418 | |
Maurice Lam | 3859643 | 2015-04-16 18:11:42 -0700 | [diff] [blame] | 419 | protected Intent getLockPasswordIntent(Context context, int quality, int minLength, |
Andres Morales | a0e1236 | 2015-04-02 09:00:41 -0700 | [diff] [blame] | 420 | final int maxLength, boolean requirePasswordToDecrypt, String password) { |
| 421 | return ChooseLockPassword.createIntent(context, quality, minLength, maxLength, |
| 422 | requirePasswordToDecrypt, password); |
| 423 | } |
| 424 | |
Adrian Roos | f788718 | 2015-01-07 20:51:57 +0100 | [diff] [blame] | 425 | protected Intent getLockPatternIntent(Context context, final boolean requirePassword, |
| 426 | final boolean confirmCredentials) { |
| 427 | return ChooseLockPattern.createIntent(context, requirePassword, |
Maurice Lam | 6b19fa9 | 2014-11-25 19:25:56 -0800 | [diff] [blame] | 428 | confirmCredentials); |
| 429 | } |
| 430 | |
Andres Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 431 | protected Intent getLockPatternIntent(Context context, final boolean requirePassword, |
| 432 | long challenge) { |
| 433 | return ChooseLockPattern.createIntent(context, requirePassword, challenge); |
| 434 | } |
| 435 | |
Maurice Lam | 3859643 | 2015-04-16 18:11:42 -0700 | [diff] [blame] | 436 | protected Intent getLockPatternIntent(Context context, final boolean requirePassword, |
Andres Morales | a0e1236 | 2015-04-02 09:00:41 -0700 | [diff] [blame] | 437 | final String pattern) { |
| 438 | return ChooseLockPattern.createIntent(context, requirePassword, pattern); |
| 439 | } |
| 440 | |
Maurice Lam | ecd2b7b | 2014-12-01 10:41:49 -0800 | [diff] [blame] | 441 | protected Intent getEncryptionInterstitialIntent(Context context, int quality, |
| 442 | boolean required) { |
| 443 | return EncryptionInterstitial.createStartIntent(context, quality, required); |
| 444 | } |
| 445 | |
Jim Miller | 5541a86 | 2011-09-02 17:33:53 -0700 | [diff] [blame] | 446 | /** |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 447 | * Invokes an activity to change the user's pattern, password or PIN based on given quality |
| 448 | * and minimum quality specified by DevicePolicyManager. If quality is |
| 449 | * {@link DevicePolicyManager#PASSWORD_QUALITY_UNSPECIFIED}, password is cleared. |
| 450 | * |
Andy Stadler | 6370c87 | 2011-01-21 16:25:22 -0800 | [diff] [blame] | 451 | * @param quality the desired quality. Ignored if DevicePolicyManager requires more security |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 452 | * @param disabled whether or not to show LockScreen at all. Only meaningful when quality is |
| 453 | * {@link DevicePolicyManager#PASSWORD_QUALITY_UNSPECIFIED} |
| 454 | */ |
| 455 | void updateUnlockMethodAndFinish(int quality, boolean disabled) { |
Andy Stadler | 6370c87 | 2011-01-21 16:25:22 -0800 | [diff] [blame] | 456 | // Sanity check. We should never get here without confirming user's existing password. |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 457 | if (!mPasswordConfirmed) { |
Andy Stadler | 6370c87 | 2011-01-21 16:25:22 -0800 | [diff] [blame] | 458 | throw new IllegalStateException("Tried to update password without confirming it"); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 459 | } |
| 460 | |
Adrian Roos | f788718 | 2015-01-07 20:51:57 +0100 | [diff] [blame] | 461 | quality = upgradeQuality(quality); |
Steven Ross | c620ba4 | 2011-09-28 15:43:41 -0400 | [diff] [blame] | 462 | |
Maurice Lam | 6b19fa9 | 2014-11-25 19:25:56 -0800 | [diff] [blame] | 463 | final Context context = getActivity(); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 464 | if (quality >= DevicePolicyManager.PASSWORD_QUALITY_NUMERIC) { |
| 465 | int minLength = mDPM.getPasswordMinimumLength(null); |
| 466 | if (minLength < MIN_PASSWORD_LENGTH) { |
| 467 | minLength = MIN_PASSWORD_LENGTH; |
| 468 | } |
| 469 | final int maxLength = mDPM.getPasswordMaximumLength(quality); |
Andres Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 470 | Intent intent; |
| 471 | if (mHasChallenge) { |
| 472 | intent = getLockPasswordIntent(context, quality, minLength, |
| 473 | maxLength, mRequirePassword, mChallenge); |
| 474 | } else { |
| 475 | intent = getLockPasswordIntent(context, quality, minLength, |
Andres Morales | a0e1236 | 2015-04-02 09:00:41 -0700 | [diff] [blame] | 476 | maxLength, mRequirePassword, mUserPassword); |
Andres Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 477 | } |
Maurice Lam | 9066a5c | 2015-01-22 18:35:11 -0800 | [diff] [blame] | 478 | startActivityForResult(intent, CHOOSE_LOCK_REQUEST); |
Adrian Roos | f788718 | 2015-01-07 20:51:57 +0100 | [diff] [blame] | 479 | } else if (quality == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING) { |
Andres Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 480 | Intent intent; |
| 481 | if (mHasChallenge) { |
| 482 | intent = getLockPatternIntent(context, mRequirePassword, |
| 483 | mChallenge); |
| 484 | } else { |
| 485 | intent = getLockPatternIntent(context, mRequirePassword, |
Andres Morales | a0e1236 | 2015-04-02 09:00:41 -0700 | [diff] [blame] | 486 | mUserPassword); |
Andres Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 487 | } |
Maurice Lam | 9066a5c | 2015-01-22 18:35:11 -0800 | [diff] [blame] | 488 | startActivityForResult(intent, CHOOSE_LOCK_REQUEST); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 489 | } else if (quality == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) { |
Adrian Roos | 5437588 | 2015-04-16 17:11:22 -0700 | [diff] [blame] | 490 | mChooseLockSettingsHelper.utils().clearLock(UserHandle.myUserId()); |
| 491 | mChooseLockSettingsHelper.utils().setLockScreenDisabled(disabled, |
| 492 | UserHandle.myUserId()); |
Jim Miller | 9218687 | 2015-03-04 18:07:32 -0800 | [diff] [blame] | 493 | removeAllFingerprintTemplates(); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 494 | getActivity().setResult(Activity.RESULT_OK); |
Amith Yamasani | c666c65 | 2012-10-24 10:27:05 -0700 | [diff] [blame] | 495 | finish(); |
| 496 | } else { |
Jim Miller | 9218687 | 2015-03-04 18:07:32 -0800 | [diff] [blame] | 497 | removeAllFingerprintTemplates(); |
Amith Yamasani | c666c65 | 2012-10-24 10:27:05 -0700 | [diff] [blame] | 498 | finish(); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 499 | } |
Jim Miller | bbb4afa | 2010-04-08 19:40:19 -0700 | [diff] [blame] | 500 | } |
Amith Yamasani | b0b37ae | 2012-04-23 15:35:36 -0700 | [diff] [blame] | 501 | |
Jim Miller | 9218687 | 2015-03-04 18:07:32 -0800 | [diff] [blame] | 502 | private void removeAllFingerprintTemplates() { |
Jim Miller | d52b577 | 2015-03-12 10:33:53 -0700 | [diff] [blame] | 503 | if (mFingerprintManager != null && mFingerprintManager.isHardwareDetected()) { |
Jim Miller | d16c9b7 | 2015-03-24 16:02:59 -0700 | [diff] [blame] | 504 | mFingerprintManager.remove(new Fingerprint(null, 0, 0, 0), mRemovalCallback); |
Jim Miller | 9218687 | 2015-03-04 18:07:32 -0800 | [diff] [blame] | 505 | } |
| 506 | } |
| 507 | |
| 508 | @Override |
| 509 | public void onDestroy() { |
| 510 | super.onDestroy(); |
Jim Miller | 9218687 | 2015-03-04 18:07:32 -0800 | [diff] [blame] | 511 | } |
| 512 | |
Amith Yamasani | b0b37ae | 2012-04-23 15:35:36 -0700 | [diff] [blame] | 513 | @Override |
| 514 | protected int getHelpResource() { |
| 515 | return R.string.help_url_choose_lockscreen; |
| 516 | } |
| 517 | |
Adrian Roos | 38c9b9e | 2015-07-24 11:30:14 -0700 | [diff] [blame] | 518 | private int getResIdForFactoryResetProtectionWarningMessage() { |
| 519 | boolean hasFingerprints = mFingerprintManager.hasEnrolledFingerprints(); |
Adrian Roos | 5437588 | 2015-04-16 17:11:22 -0700 | [diff] [blame] | 520 | switch (mLockPatternUtils.getKeyguardStoredPasswordQuality(UserHandle.myUserId())) { |
Lucky Zhang | 3bcea02 | 2014-11-25 18:22:14 -0800 | [diff] [blame] | 521 | case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING: |
Adrian Roos | 38c9b9e | 2015-07-24 11:30:14 -0700 | [diff] [blame] | 522 | return hasFingerprints |
| 523 | ? R.string.unlock_disable_frp_warning_content_pattern_fingerprint |
| 524 | : R.string.unlock_disable_frp_warning_content_pattern; |
Lucky Zhang | 3bcea02 | 2014-11-25 18:22:14 -0800 | [diff] [blame] | 525 | case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC: |
| 526 | case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX: |
Adrian Roos | 38c9b9e | 2015-07-24 11:30:14 -0700 | [diff] [blame] | 527 | return hasFingerprints |
| 528 | ? R.string.unlock_disable_frp_warning_content_pin_fingerprint |
| 529 | : R.string.unlock_disable_frp_warning_content_pin; |
Lucky Zhang | 3bcea02 | 2014-11-25 18:22:14 -0800 | [diff] [blame] | 530 | case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC: |
| 531 | case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC: |
| 532 | case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX: |
Adrian Roos | 38c9b9e | 2015-07-24 11:30:14 -0700 | [diff] [blame] | 533 | return hasFingerprints |
| 534 | ? R.string.unlock_disable_frp_warning_content_password_fingerprint |
| 535 | : R.string.unlock_disable_frp_warning_content_password; |
Lucky Zhang | 3bcea02 | 2014-11-25 18:22:14 -0800 | [diff] [blame] | 536 | default: |
Adrian Roos | 38c9b9e | 2015-07-24 11:30:14 -0700 | [diff] [blame] | 537 | return hasFingerprints |
| 538 | ? R.string.unlock_disable_frp_warning_content_unknown_fingerprint |
| 539 | : R.string.unlock_disable_frp_warning_content_unknown; |
Lucky Zhang | 3bcea02 | 2014-11-25 18:22:14 -0800 | [diff] [blame] | 540 | } |
| 541 | } |
| 542 | |
| 543 | private boolean isUnlockMethodSecure(String unlockMethod) { |
| 544 | return !(KEY_UNLOCK_SET_OFF.equals(unlockMethod) || |
| 545 | KEY_UNLOCK_SET_NONE.equals(unlockMethod)); |
| 546 | } |
| 547 | |
| 548 | private boolean setUnlockMethod(String unlockMethod) { |
| 549 | EventLog.writeEvent(EventLogTags.LOCK_SCREEN_TYPE, unlockMethod); |
| 550 | |
| 551 | if (KEY_UNLOCK_SET_OFF.equals(unlockMethod)) { |
| 552 | updateUnlockMethodAndFinish( |
| 553 | DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, true /* disabled */ ); |
| 554 | } else if (KEY_UNLOCK_SET_NONE.equals(unlockMethod)) { |
| 555 | updateUnlockMethodAndFinish( |
| 556 | DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, false /* disabled */ ); |
Lucky Zhang | 3bcea02 | 2014-11-25 18:22:14 -0800 | [diff] [blame] | 557 | } else if (KEY_UNLOCK_SET_PATTERN.equals(unlockMethod)) { |
| 558 | maybeEnableEncryption( |
| 559 | DevicePolicyManager.PASSWORD_QUALITY_SOMETHING, false); |
| 560 | } else if (KEY_UNLOCK_SET_PIN.equals(unlockMethod)) { |
| 561 | maybeEnableEncryption( |
| 562 | DevicePolicyManager.PASSWORD_QUALITY_NUMERIC, false); |
| 563 | } else if (KEY_UNLOCK_SET_PASSWORD.equals(unlockMethod)) { |
| 564 | maybeEnableEncryption( |
| 565 | DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC, false); |
| 566 | } else { |
| 567 | Log.e(TAG, "Encountered unknown unlock method to set: " + unlockMethod); |
| 568 | return false; |
| 569 | } |
| 570 | return true; |
| 571 | } |
| 572 | |
| 573 | private void showFactoryResetProtectionWarningDialog(String unlockMethodToSet) { |
Adrian Roos | 38c9b9e | 2015-07-24 11:30:14 -0700 | [diff] [blame] | 574 | int message = getResIdForFactoryResetProtectionWarningMessage(); |
Lucky Zhang | 3bcea02 | 2014-11-25 18:22:14 -0800 | [diff] [blame] | 575 | FactoryResetProtectionWarningDialog dialog = |
Adrian Roos | 38c9b9e | 2015-07-24 11:30:14 -0700 | [diff] [blame] | 576 | FactoryResetProtectionWarningDialog.newInstance(message, unlockMethodToSet); |
Lucky Zhang | 3bcea02 | 2014-11-25 18:22:14 -0800 | [diff] [blame] | 577 | dialog.show(getChildFragmentManager(), TAG_FRP_WARNING_DIALOG); |
| 578 | } |
| 579 | |
| 580 | public static class FactoryResetProtectionWarningDialog extends DialogFragment { |
| 581 | |
Adrian Roos | 38c9b9e | 2015-07-24 11:30:14 -0700 | [diff] [blame] | 582 | private static final String ARG_MESSAGE_RES = "messageRes"; |
Lucky Zhang | 3bcea02 | 2014-11-25 18:22:14 -0800 | [diff] [blame] | 583 | private static final String ARG_UNLOCK_METHOD_TO_SET = "unlockMethodToSet"; |
| 584 | |
Adrian Roos | 38c9b9e | 2015-07-24 11:30:14 -0700 | [diff] [blame] | 585 | public static FactoryResetProtectionWarningDialog newInstance(int messageRes, |
Lucky Zhang | 3bcea02 | 2014-11-25 18:22:14 -0800 | [diff] [blame] | 586 | String unlockMethodToSet) { |
| 587 | FactoryResetProtectionWarningDialog frag = |
| 588 | new FactoryResetProtectionWarningDialog(); |
| 589 | Bundle args = new Bundle(); |
Adrian Roos | 38c9b9e | 2015-07-24 11:30:14 -0700 | [diff] [blame] | 590 | args.putInt(ARG_MESSAGE_RES, messageRes); |
Lucky Zhang | 3bcea02 | 2014-11-25 18:22:14 -0800 | [diff] [blame] | 591 | args.putString(ARG_UNLOCK_METHOD_TO_SET, unlockMethodToSet); |
| 592 | frag.setArguments(args); |
| 593 | return frag; |
| 594 | } |
| 595 | |
| 596 | @Override |
| 597 | public void show(FragmentManager manager, String tag) { |
| 598 | if (manager.findFragmentByTag(tag) == null) { |
| 599 | // Prevent opening multiple dialogs if tapped on button quickly |
| 600 | super.show(manager, tag); |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | @Override |
| 605 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 606 | final Bundle args = getArguments(); |
| 607 | |
| 608 | return new AlertDialog.Builder(getActivity()) |
Adrian Roos | 38c9b9e | 2015-07-24 11:30:14 -0700 | [diff] [blame] | 609 | .setTitle(R.string.unlock_disable_frp_warning_title) |
| 610 | .setMessage(args.getInt(ARG_MESSAGE_RES)) |
| 611 | .setPositiveButton(R.string.unlock_disable_frp_warning_ok, |
Lucky Zhang | 3bcea02 | 2014-11-25 18:22:14 -0800 | [diff] [blame] | 612 | new DialogInterface.OnClickListener() { |
| 613 | @Override |
| 614 | public void onClick(DialogInterface dialog, int whichButton) { |
| 615 | ((ChooseLockGenericFragment) getParentFragment()) |
| 616 | .setUnlockMethod( |
| 617 | args.getString(ARG_UNLOCK_METHOD_TO_SET)); |
| 618 | } |
| 619 | } |
| 620 | ) |
| 621 | .setNegativeButton(R.string.cancel, |
| 622 | new DialogInterface.OnClickListener() { |
| 623 | @Override |
| 624 | public void onClick(DialogInterface dialog, int whichButton) { |
| 625 | dismiss(); |
| 626 | } |
| 627 | } |
| 628 | ) |
| 629 | .create(); |
| 630 | } |
| 631 | } |
Jim Miller | bbb4afa | 2010-04-08 19:40:19 -0700 | [diff] [blame] | 632 | } |
Dianne Hackborn | abc3dc6 | 2010-01-20 13:40:19 -0800 | [diff] [blame] | 633 | } |