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