The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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 | |
| 19 | |
Danielle Millett | 487b16f | 2011-11-02 11:12:21 -0400 | [diff] [blame] | 20 | import android.app.Activity; |
Gilles Debunne | 2c88a87 | 2011-06-21 12:47:17 -0700 | [diff] [blame] | 21 | import android.app.AlertDialog; |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 22 | import android.app.Dialog; |
| 23 | import android.app.DialogFragment; |
| 24 | import android.app.FragmentManager; |
Dianne Hackborn | 4037c7f | 2010-02-26 17:26:55 -0800 | [diff] [blame] | 25 | import android.app.admin.DevicePolicyManager; |
Ido Ofir | 524a63b | 2014-06-12 14:18:23 -0700 | [diff] [blame] | 26 | import android.content.ComponentName; |
Dianne Hackborn | abc3dc6 | 2010-01-20 13:40:19 -0800 | [diff] [blame] | 27 | import android.content.Context; |
Gilles Debunne | 2c88a87 | 2011-06-21 12:47:17 -0700 | [diff] [blame] | 28 | import android.content.DialogInterface; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 29 | import android.content.Intent; |
rich cannings | bfbdcef | 2012-09-09 12:48:50 -0700 | [diff] [blame] | 30 | import android.content.pm.PackageManager; |
| 31 | import android.content.pm.ResolveInfo; |
Clara Bayarri | 6934a04 | 2015-10-14 11:07:35 +0100 | [diff] [blame] | 32 | import android.content.pm.UserInfo; |
Fabrice Di Meglio | d1d2f02 | 2014-04-11 16:09:11 -0700 | [diff] [blame] | 33 | import android.content.res.Resources; |
Jason Monk | 3bcd76c | 2015-04-21 11:20:20 -0400 | [diff] [blame] | 34 | import android.hardware.fingerprint.FingerprintManager; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 35 | import android.os.Bundle; |
Junda Liu | 80753bc | 2015-06-17 10:15:34 -0700 | [diff] [blame] | 36 | import android.os.PersistableBundle; |
Dianne Hackborn | bb06a42 | 2012-08-16 11:01:57 -0700 | [diff] [blame] | 37 | import android.os.UserHandle; |
Jim Miller | 783ea85 | 2012-11-01 19:39:21 -0700 | [diff] [blame] | 38 | import android.os.UserManager; |
Fabrice Di Meglio | d1d2f02 | 2014-04-11 16:09:11 -0700 | [diff] [blame] | 39 | import android.provider.SearchIndexableResource; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 40 | import android.provider.Settings; |
Chia-chi Yeh | 9cec698 | 2009-09-22 23:59:01 +0800 | [diff] [blame] | 41 | import android.security.KeyStore; |
Ido Ofir | 6f48244 | 2014-05-09 14:47:15 -0700 | [diff] [blame] | 42 | import android.service.trust.TrustAgentService; |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 43 | import android.support.v14.preference.SwitchPreference; |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 44 | import android.support.v7.preference.Preference; |
| 45 | import android.support.v7.preference.Preference.OnPreferenceChangeListener; |
| 46 | import android.support.v7.preference.Preference.OnPreferenceClickListener; |
| 47 | import android.support.v7.preference.PreferenceGroup; |
| 48 | import android.support.v7.preference.PreferenceScreen; |
Junda Liu | 80753bc | 2015-06-17 10:15:34 -0700 | [diff] [blame] | 49 | import android.telephony.CarrierConfigManager; |
Wink Saville | ca75661 | 2014-11-08 10:47:12 -0800 | [diff] [blame] | 50 | import android.telephony.SubscriptionInfo; |
Jason Monk | 3bcd76c | 2015-04-21 11:20:20 -0400 | [diff] [blame] | 51 | import android.telephony.SubscriptionManager; |
| 52 | import android.telephony.TelephonyManager; |
Ido Ofir | 524a63b | 2014-06-12 14:18:23 -0700 | [diff] [blame] | 53 | import android.text.TextUtils; |
Jim Miller | 86624a2 | 2010-08-30 22:07:58 -0700 | [diff] [blame] | 54 | import android.util.Log; |
Amith Yamasani | f06d869 | 2009-06-11 22:32:33 -0700 | [diff] [blame] | 55 | |
Chris Wren | 9d1bfd1 | 2016-01-26 18:04:01 -0500 | [diff] [blame] | 56 | import com.android.internal.logging.MetricsProto.MetricsEvent; |
Gilles Debunne | a6a8a14 | 2011-06-09 11:56:17 -0700 | [diff] [blame] | 57 | import com.android.internal.widget.LockPatternUtils; |
Sudheer Shanka | 550d068 | 2016-01-13 15:16:55 +0000 | [diff] [blame] | 58 | import com.android.settings.RestrictedListPreference; |
Jim Miller | fe76559 | 2014-07-31 15:30:29 -0700 | [diff] [blame] | 59 | import com.android.settings.TrustAgentUtils.TrustAgentComponentInfo; |
Jorim Jaggi | 5ad75f0 | 2015-04-22 16:17:23 -0700 | [diff] [blame] | 60 | import com.android.settings.fingerprint.FingerprintSettings; |
Fabrice Di Meglio | d1d2f02 | 2014-04-11 16:09:11 -0700 | [diff] [blame] | 61 | import com.android.settings.search.BaseSearchIndexProvider; |
Jim Miller | fe76559 | 2014-07-31 15:30:29 -0700 | [diff] [blame] | 62 | import com.android.settings.search.Index; |
Fabrice Di Meglio | d1d2f02 | 2014-04-11 16:09:11 -0700 | [diff] [blame] | 63 | import com.android.settings.search.Indexable; |
| 64 | import com.android.settings.search.SearchIndexableRaw; |
Sudheer Shanka | 550d068 | 2016-01-13 15:16:55 +0000 | [diff] [blame] | 65 | import com.android.settingslib.RestrictedLockUtils; |
Sudheer Shanka | 9c32468 | 2016-01-18 11:17:23 +0000 | [diff] [blame] | 66 | import com.android.settingslib.RestrictedPreference; |
Sudheer Shanka | 6610435 | 2016-01-12 17:43:20 +0000 | [diff] [blame] | 67 | import com.android.settingslib.RestrictedSwitchPreference; |
Gilles Debunne | a6a8a14 | 2011-06-09 11:56:17 -0700 | [diff] [blame] | 68 | |
Jim Miller | 86624a2 | 2010-08-30 22:07:58 -0700 | [diff] [blame] | 69 | import java.util.ArrayList; |
rich cannings | bfbdcef | 2012-09-09 12:48:50 -0700 | [diff] [blame] | 70 | import java.util.List; |
Mike Lockwood | 5ed2c4a | 2009-06-07 23:07:20 -0400 | [diff] [blame] | 71 | |
Selim Cinek | ec85004 | 2015-06-11 18:59:54 -0700 | [diff] [blame] | 72 | import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT; |
| 73 | |
Sudheer Shanka | 550d068 | 2016-01-13 15:16:55 +0000 | [diff] [blame] | 74 | import static com.android.settings.RestrictedListPreference.RestrictedItem; |
| 75 | import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; |
| 76 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 77 | /** |
| 78 | * Gesture lock pattern settings. |
| 79 | */ |
Julia Reynolds | 565653c | 2014-06-12 11:49:12 -0400 | [diff] [blame] | 80 | public class SecuritySettings extends SettingsPreferenceFragment |
Adrian Roos | 62775bf | 2016-01-28 13:23:53 -0800 | [diff] [blame] | 81 | implements OnPreferenceChangeListener, DialogInterface.OnClickListener, Indexable, |
| 82 | GearPreference.OnGearClickListener { |
Jim Miller | 9218687 | 2015-03-04 18:07:32 -0800 | [diff] [blame] | 83 | |
| 84 | private static final String TAG = "SecuritySettings"; |
Jim Miller | 250b9be | 2014-09-05 18:48:18 -0700 | [diff] [blame] | 85 | private static final String TRUST_AGENT_CLICK_INTENT = "trust_agent_click_intent"; |
Ido Ofir | 6f48244 | 2014-05-09 14:47:15 -0700 | [diff] [blame] | 86 | private static final Intent TRUST_AGENT_INTENT = |
| 87 | new Intent(TrustAgentService.SERVICE_INTERFACE); |
Jason parks | 6f8fb43 | 2011-01-07 09:02:14 -0600 | [diff] [blame] | 88 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 89 | // Lock Settings |
Chia-chi Yeh | 91d65a2 | 2011-01-20 18:46:01 +0800 | [diff] [blame] | 90 | private static final String KEY_UNLOCK_SET_OR_CHANGE = "unlock_set_or_change"; |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 91 | private static final String KEY_UNLOCK_SET_OR_CHANGE_PROFILE = "unlock_set_or_change_profile"; |
| 92 | private static final String KEY_VISIBLE_PATTERN_PROFILE = "visiblepattern_profile"; |
Amith Yamasani | edac9af | 2010-11-17 09:08:21 -0800 | [diff] [blame] | 93 | private static final String KEY_SECURITY_CATEGORY = "security_category"; |
rich cannings | f042114 | 2012-09-25 16:20:36 -0700 | [diff] [blame] | 94 | private static final String KEY_DEVICE_ADMIN_CATEGORY = "device_admin_category"; |
Jim Miller | fe76559 | 2014-07-31 15:30:29 -0700 | [diff] [blame] | 95 | private static final String KEY_ADVANCED_SECURITY = "advanced_security"; |
| 96 | private static final String KEY_MANAGE_TRUST_AGENTS = "manage_trust_agents"; |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 97 | private static final String KEY_UNIFICATION = "unification"; |
Jim Miller | ef3e701 | 2013-08-20 19:03:30 -0700 | [diff] [blame] | 98 | |
Chia-chi Yeh | 91d65a2 | 2011-01-20 18:46:01 +0800 | [diff] [blame] | 99 | private static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST = 123; |
Ido Ofir | 6f48244 | 2014-05-09 14:47:15 -0700 | [diff] [blame] | 100 | private static final int CHANGE_TRUST_AGENT_SETTINGS = 126; |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 101 | private static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST_PROFILE = 127; |
| 102 | private static final int UNIFY_LOCK_CONFIRM_DEVICE_REQUEST = 128; |
| 103 | private static final int UNIFY_LOCK_CONFIRM_PROFILE_REQUEST = 129; |
| 104 | private static final String TAG_UNIFICATION_DIALOG = "unification_dialog"; |
Hung-ying Tyan | 7031ab0 | 2009-07-02 00:26:46 +0800 | [diff] [blame] | 105 | |
Chia-chi Yeh | 91d65a2 | 2011-01-20 18:46:01 +0800 | [diff] [blame] | 106 | // Misc Settings |
| 107 | private static final String KEY_SIM_LOCK = "sim_lock"; |
| 108 | private static final String KEY_SHOW_PASSWORD = "show_password"; |
Kenny Root | 028634b | 2013-03-29 11:12:55 -0700 | [diff] [blame] | 109 | private static final String KEY_CREDENTIAL_STORAGE_TYPE = "credential_storage_type"; |
Julia Reynolds | 233ccd0 | 2014-06-23 09:43:09 -0400 | [diff] [blame] | 110 | private static final String KEY_RESET_CREDENTIALS = "credentials_reset"; |
Geoffrey Borggaard | 6e1102d | 2013-08-07 14:57:43 -0400 | [diff] [blame] | 111 | private static final String KEY_CREDENTIALS_INSTALL = "credentials_install"; |
Gilles Debunne | 2c88a87 | 2011-06-21 12:47:17 -0700 | [diff] [blame] | 112 | private static final String KEY_TOGGLE_INSTALL_APPLICATIONS = "toggle_install_applications"; |
Amith Yamasani | 7fb4f85 | 2012-09-25 22:17:33 -0700 | [diff] [blame] | 113 | private static final String KEY_CREDENTIALS_MANAGER = "credentials_management"; |
rich cannings | bfbdcef | 2012-09-09 12:48:50 -0700 | [diff] [blame] | 114 | private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive"; |
Ido Ofir | 6f48244 | 2014-05-09 14:47:15 -0700 | [diff] [blame] | 115 | private static final String KEY_TRUST_AGENT = "trust_agent"; |
Jason Monk | 27d7ea5 | 2014-07-18 09:55:41 -0400 | [diff] [blame] | 116 | private static final String KEY_SCREEN_PINNING = "screen_pinning_settings"; |
Jim Miller | 47d380f | 2010-01-20 13:37:14 -0800 | [diff] [blame] | 117 | |
Jim Miller | 4a9065e | 2014-08-08 15:25:31 -0700 | [diff] [blame] | 118 | // These switch preferences need special handling since they're not all stored in Settings. |
Adrian Roos | 62775bf | 2016-01-28 13:23:53 -0800 | [diff] [blame] | 119 | private static final String SWITCH_PREFERENCE_KEYS[] = { |
Clara Bayarri | 56462d6 | 2016-02-12 13:55:36 +0000 | [diff] [blame] | 120 | KEY_SHOW_PASSWORD, KEY_TOGGLE_INSTALL_APPLICATIONS, KEY_UNIFICATION }; |
Jim Miller | 4a9065e | 2014-08-08 15:25:31 -0700 | [diff] [blame] | 121 | |
Jim Miller | fe76559 | 2014-07-31 15:30:29 -0700 | [diff] [blame] | 122 | // Only allow one trust agent on the platform. |
| 123 | private static final boolean ONLY_ONE_TRUST_AGENT = true; |
| 124 | |
Adrian Roos | 5437588 | 2015-04-16 17:11:22 -0700 | [diff] [blame] | 125 | private static final int MY_USER_ID = UserHandle.myUserId(); |
| 126 | |
Maggie Benthall | f48206e | 2013-08-20 11:03:05 -0400 | [diff] [blame] | 127 | private DevicePolicyManager mDPM; |
Wink Saville | 0183fb5 | 2014-11-22 10:11:39 -0800 | [diff] [blame] | 128 | private SubscriptionManager mSubscriptionManager; |
Xiaohui Chen | 44879a3 | 2015-07-22 13:53:22 -0700 | [diff] [blame] | 129 | private UserManager mUm; |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 130 | |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 131 | private ChooseLockSettingsHelper mChooseLockSettingsHelper; |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 132 | private LockPatternUtils mLockPatternUtils; |
Chia-chi Yeh | 91d65a2 | 2011-01-20 18:46:01 +0800 | [diff] [blame] | 133 | |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 134 | private SwitchPreference mVisiblePatternProfile; |
Clara Bayarri | 56462d6 | 2016-02-12 13:55:36 +0000 | [diff] [blame] | 135 | private SwitchPreference mUnifyProfile; |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 136 | |
Jim Miller | 4a9065e | 2014-08-08 15:25:31 -0700 | [diff] [blame] | 137 | private SwitchPreference mShowPassword; |
Chia-chi Yeh | 91d65a2 | 2011-01-20 18:46:01 +0800 | [diff] [blame] | 138 | |
Kenny Root | 028634b | 2013-03-29 11:12:55 -0700 | [diff] [blame] | 139 | private KeyStore mKeyStore; |
Sudheer Shanka | 9c32468 | 2016-01-18 11:17:23 +0000 | [diff] [blame] | 140 | private RestrictedPreference mResetCredentials; |
Mike Lockwood | 5ed2c4a | 2009-06-07 23:07:20 -0400 | [diff] [blame] | 141 | |
Sudheer Shanka | 9159fe9 | 2015-11-23 12:07:05 +0000 | [diff] [blame] | 142 | private RestrictedSwitchPreference mToggleAppInstallation; |
Gilles Debunne | 2c88a87 | 2011-06-21 12:47:17 -0700 | [diff] [blame] | 143 | private DialogInterface mWarnInstallApps; |
| 144 | |
Xiaohui Chen | 44879a3 | 2015-07-22 13:53:22 -0700 | [diff] [blame] | 145 | private boolean mIsAdmin; |
Amith Yamasani | 7fb4f85 | 2012-09-25 22:17:33 -0700 | [diff] [blame] | 146 | |
Jim Miller | 250b9be | 2014-09-05 18:48:18 -0700 | [diff] [blame] | 147 | private Intent mTrustAgentClickIntent; |
Ido Ofir | 1682a0d | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 148 | |
Clara Bayarri | 6934a04 | 2015-10-14 11:07:35 +0100 | [diff] [blame] | 149 | private int mProfileChallengeUserId; |
| 150 | |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 151 | private String mCurrentDevicePassword; |
| 152 | private String mCurrentProfilePassword; |
| 153 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 154 | @Override |
Chris Wren | 8a963ba | 2015-03-20 10:29:14 -0400 | [diff] [blame] | 155 | protected int getMetricsCategory() { |
Chris Wren | 9d1bfd1 | 2016-01-26 18:04:01 -0500 | [diff] [blame] | 156 | return MetricsEvent.SECURITY; |
Chris Wren | 8a963ba | 2015-03-20 10:29:14 -0400 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 160 | public void onCreate(Bundle savedInstanceState) { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 161 | super.onCreate(savedInstanceState); |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 162 | |
Wink Saville | 0183fb5 | 2014-11-22 10:11:39 -0800 | [diff] [blame] | 163 | mSubscriptionManager = SubscriptionManager.from(getActivity()); |
| 164 | |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 165 | mLockPatternUtils = new LockPatternUtils(getActivity()); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 166 | |
Dianne Hackborn | abc3dc6 | 2010-01-20 13:40:19 -0800 | [diff] [blame] | 167 | mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE); |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 168 | |
Xiaohui Chen | 44879a3 | 2015-07-22 13:53:22 -0700 | [diff] [blame] | 169 | mUm = UserManager.get(getActivity()); |
| 170 | |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 171 | mChooseLockSettingsHelper = new ChooseLockSettingsHelper(getActivity()); |
Jim Miller | 250b9be | 2014-09-05 18:48:18 -0700 | [diff] [blame] | 172 | |
| 173 | if (savedInstanceState != null |
| 174 | && savedInstanceState.containsKey(TRUST_AGENT_CLICK_INTENT)) { |
| 175 | mTrustAgentClickIntent = savedInstanceState.getParcelable(TRUST_AGENT_CLICK_INTENT); |
| 176 | } |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 177 | } |
Mike Lockwood | 5ed2c4a | 2009-06-07 23:07:20 -0400 | [diff] [blame] | 178 | |
Fabrice Di Meglio | d1d2f02 | 2014-04-11 16:09:11 -0700 | [diff] [blame] | 179 | private static int getResIdForLockUnlockScreen(Context context, |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 180 | LockPatternUtils lockPatternUtils, int userId) { |
| 181 | final boolean isMyUser = userId == MY_USER_ID; |
Jim Miller | 36972bb | 2010-11-30 19:47:38 -0800 | [diff] [blame] | 182 | int resid = 0; |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 183 | if (!lockPatternUtils.isSecure(userId)) { |
| 184 | if (!isMyUser) { |
| 185 | resid = R.xml.security_settings_lockscreen_profile; |
| 186 | } else if (lockPatternUtils.isLockScreenDisabled(userId)) { |
Jim Miller | 36972bb | 2010-11-30 19:47:38 -0800 | [diff] [blame] | 187 | resid = R.xml.security_settings_lockscreen; |
| 188 | } else { |
| 189 | resid = R.xml.security_settings_chooser; |
| 190 | } |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 191 | } else { |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 192 | switch (lockPatternUtils.getKeyguardStoredPasswordQuality(userId)) { |
Jim Miller | af366a3 | 2010-03-25 18:45:22 -0700 | [diff] [blame] | 193 | case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING: |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 194 | resid = isMyUser ? R.xml.security_settings_pattern |
| 195 | : R.xml.security_settings_pattern_profile; |
Jim Miller | af366a3 | 2010-03-25 18:45:22 -0700 | [diff] [blame] | 196 | break; |
| 197 | case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC: |
Nicolas Prevot | 8fd852e | 2014-01-25 01:02:04 +0000 | [diff] [blame] | 198 | case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX: |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 199 | resid = isMyUser ? R.xml.security_settings_pin |
| 200 | : R.xml.security_settings_pin_profile; |
Jim Miller | af366a3 | 2010-03-25 18:45:22 -0700 | [diff] [blame] | 201 | break; |
| 202 | case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC: |
| 203 | case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC: |
Konstantin Lopyrev | 57fbf69 | 2010-05-27 16:01:41 -0700 | [diff] [blame] | 204 | case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX: |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 205 | resid = isMyUser ? R.xml.security_settings_password |
| 206 | : R.xml.security_settings_password_profile; |
Jim Miller | af366a3 | 2010-03-25 18:45:22 -0700 | [diff] [blame] | 207 | break; |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 208 | } |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 209 | } |
Fabrice Di Meglio | d1d2f02 | 2014-04-11 16:09:11 -0700 | [diff] [blame] | 210 | return resid; |
| 211 | } |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 212 | |
Fabrice Di Meglio | d1d2f02 | 2014-04-11 16:09:11 -0700 | [diff] [blame] | 213 | /** |
| 214 | * Important! |
| 215 | * |
Ido Ofir | 6f48244 | 2014-05-09 14:47:15 -0700 | [diff] [blame] | 216 | * Don't forget to update the SecuritySearchIndexProvider if you are doing any change in the |
Fabrice Di Meglio | d1d2f02 | 2014-04-11 16:09:11 -0700 | [diff] [blame] | 217 | * logic or adding/removing preferences here. |
| 218 | */ |
| 219 | private PreferenceScreen createPreferenceHierarchy() { |
| 220 | PreferenceScreen root = getPreferenceScreen(); |
| 221 | if (root != null) { |
| 222 | root.removeAll(); |
| 223 | } |
| 224 | addPreferencesFromResource(R.xml.security_settings); |
| 225 | root = getPreferenceScreen(); |
| 226 | |
| 227 | // Add options for lock/unlock screen |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 228 | final int resid = getResIdForLockUnlockScreen(getActivity(), mLockPatternUtils, MY_USER_ID); |
Fabrice Di Meglio | d1d2f02 | 2014-04-11 16:09:11 -0700 | [diff] [blame] | 229 | addPreferencesFromResource(resid); |
Jason parks | 4112199 | 2011-01-25 09:26:55 -0600 | [diff] [blame] | 230 | |
Clara Bayarri | 462cce1 | 2016-02-18 12:09:21 +0000 | [diff] [blame^] | 231 | mProfileChallengeUserId = Utils.getManagedProfileId(mUm, MY_USER_ID); |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 232 | if (mProfileChallengeUserId != UserHandle.USER_NULL |
| 233 | && mLockPatternUtils.isSeparateProfileChallengeAllowed(mProfileChallengeUserId)) { |
| 234 | addPreferencesFromResource(R.xml.security_settings_profile); |
| 235 | final int profileResid = getResIdForLockUnlockScreen( |
| 236 | getActivity(), mLockPatternUtils, mProfileChallengeUserId); |
| 237 | addPreferencesFromResource(profileResid); |
| 238 | maybeAddFingerprintPreference(root, mProfileChallengeUserId); |
Clara Bayarri | 56462d6 | 2016-02-12 13:55:36 +0000 | [diff] [blame] | 239 | addPreferencesFromResource(R.xml.security_settings_unification); |
| 240 | if (!mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileChallengeUserId)) { |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 241 | Preference lockPreference = root.findPreference(KEY_UNLOCK_SET_OR_CHANGE_PROFILE); |
| 242 | String summary = getContext().getString( |
| 243 | R.string.lock_settings_profile_unified_summary); |
| 244 | lockPreference.setSummary(summary); |
Clara Bayarri | 56462d6 | 2016-02-12 13:55:36 +0000 | [diff] [blame] | 245 | lockPreference.setEnabled(false); |
Clara Bayarri | 6934a04 | 2015-10-14 11:07:35 +0100 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | |
Adrian Roos | 62775bf | 2016-01-28 13:23:53 -0800 | [diff] [blame] | 249 | Preference unlockSetOrChange = findPreference(KEY_UNLOCK_SET_OR_CHANGE); |
| 250 | if (unlockSetOrChange instanceof GearPreference) { |
| 251 | ((GearPreference) unlockSetOrChange).setOnGearClickListener(this); |
| 252 | } |
| 253 | |
Jason parks | 4112199 | 2011-01-25 09:26:55 -0600 | [diff] [blame] | 254 | // Add options for device encryption |
Xiaohui Chen | 44879a3 | 2015-07-22 13:53:22 -0700 | [diff] [blame] | 255 | mIsAdmin = mUm.isAdminUser(); |
Amith Yamasani | 7fb4f85 | 2012-09-25 22:17:33 -0700 | [diff] [blame] | 256 | |
Xiaohui Chen | 44879a3 | 2015-07-22 13:53:22 -0700 | [diff] [blame] | 257 | if (mIsAdmin) { |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 258 | if (LockPatternUtils.isDeviceEncryptionEnabled()) { |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 259 | // The device is currently encrypted. |
| 260 | addPreferencesFromResource(R.xml.security_settings_encrypted); |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 261 | } else { |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 262 | // This device supports encryption but isn't encrypted. |
| 263 | addPreferencesFromResource(R.xml.security_settings_unencrypted); |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 264 | } |
Jason parks | 4112199 | 2011-01-25 09:26:55 -0600 | [diff] [blame] | 265 | } |
| 266 | |
Jim Miller | 94d4bd9 | 2015-02-19 21:04:57 -0800 | [diff] [blame] | 267 | // Fingerprint and trust agents |
Ido Ofir | 1682a0d | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 268 | PreferenceGroup securityCategory = (PreferenceGroup) |
| 269 | root.findPreference(KEY_SECURITY_CATEGORY); |
Jim Miller | 9d25005 | 2014-08-21 19:24:47 -0700 | [diff] [blame] | 270 | if (securityCategory != null) { |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 271 | maybeAddFingerprintPreference(securityCategory, UserHandle.myUserId()); |
Jim Miller | 94d4bd9 | 2015-02-19 21:04:57 -0800 | [diff] [blame] | 272 | addTrustAgentSettings(securityCategory); |
Ido Ofir | 1682a0d | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 273 | } |
| 274 | |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 275 | mVisiblePatternProfile = |
| 276 | (SwitchPreference) root.findPreference(KEY_VISIBLE_PATTERN_PROFILE); |
Clara Bayarri | 56462d6 | 2016-02-12 13:55:36 +0000 | [diff] [blame] | 277 | mUnifyProfile = (SwitchPreference) root.findPreference(KEY_UNIFICATION); |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 278 | |
Amith Yamasani | 7fb4f85 | 2012-09-25 22:17:33 -0700 | [diff] [blame] | 279 | // Append the rest of the settings |
| 280 | addPreferencesFromResource(R.xml.security_settings_misc); |
| 281 | |
| 282 | // Do not display SIM lock for devices without an Icc card |
| 283 | TelephonyManager tm = TelephonyManager.getDefault(); |
Junda Liu | 80753bc | 2015-06-17 10:15:34 -0700 | [diff] [blame] | 284 | CarrierConfigManager cfgMgr = (CarrierConfigManager) |
| 285 | getActivity().getSystemService(Context.CARRIER_CONFIG_SERVICE); |
| 286 | PersistableBundle b = cfgMgr.getConfig(); |
Xiaohui Chen | 44879a3 | 2015-07-22 13:53:22 -0700 | [diff] [blame] | 287 | if (!mIsAdmin || !isSimIccReady() || |
Junda Liu | 80753bc | 2015-06-17 10:15:34 -0700 | [diff] [blame] | 288 | b.getBoolean(CarrierConfigManager.KEY_HIDE_SIM_LOCK_SETTINGS_BOOL)) { |
Amith Yamasani | 7fb4f85 | 2012-09-25 22:17:33 -0700 | [diff] [blame] | 289 | root.removePreference(root.findPreference(KEY_SIM_LOCK)); |
| 290 | } else { |
PauloftheWest | 50e6eca | 2014-10-03 11:07:14 -0700 | [diff] [blame] | 291 | // Disable SIM lock if there is no ready SIM card. |
| 292 | root.findPreference(KEY_SIM_LOCK).setEnabled(isSimReady()); |
Amith Yamasani | 7fb4f85 | 2012-09-25 22:17:33 -0700 | [diff] [blame] | 293 | } |
Jason Monk | b08853a | 2014-08-13 09:43:58 -0400 | [diff] [blame] | 294 | if (Settings.System.getInt(getContentResolver(), |
| 295 | Settings.System.LOCK_TO_APP_ENABLED, 0) != 0) { |
| 296 | root.findPreference(KEY_SCREEN_PINNING).setSummary( |
| 297 | getResources().getString(R.string.switch_on_text)); |
Jason Monk | 27d7ea5 | 2014-07-18 09:55:41 -0400 | [diff] [blame] | 298 | } |
Amith Yamasani | 7fb4f85 | 2012-09-25 22:17:33 -0700 | [diff] [blame] | 299 | |
| 300 | // Show password |
Jim Miller | 4a9065e | 2014-08-08 15:25:31 -0700 | [diff] [blame] | 301 | mShowPassword = (SwitchPreference) root.findPreference(KEY_SHOW_PASSWORD); |
Sudheer Shanka | 9c32468 | 2016-01-18 11:17:23 +0000 | [diff] [blame] | 302 | mResetCredentials = (RestrictedPreference) root.findPreference(KEY_RESET_CREDENTIALS); |
Amith Yamasani | 7fb4f85 | 2012-09-25 22:17:33 -0700 | [diff] [blame] | 303 | |
Kenny Root | c5550c2 | 2013-04-08 09:56:05 -0700 | [diff] [blame] | 304 | // Credential storage |
Emily Bernier | 11bd33a | 2013-04-11 16:24:56 -0400 | [diff] [blame] | 305 | final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE); |
Maggie Benthall | f48206e | 2013-08-20 11:03:05 -0400 | [diff] [blame] | 306 | mKeyStore = KeyStore.getInstance(); // needs to be initialized for onResume() |
Kenny Root | 028634b | 2013-03-29 11:12:55 -0700 | [diff] [blame] | 307 | |
Sudheer Shanka | 9e9e63b | 2016-02-11 18:48:14 +0000 | [diff] [blame] | 308 | if (!RestrictedLockUtils.hasBaseUserRestriction(getActivity(), |
| 309 | UserManager.DISALLOW_CONFIG_CREDENTIALS, MY_USER_ID)) { |
| 310 | RestrictedPreference credentialStorageType = (RestrictedPreference) root.findPreference( |
| 311 | KEY_CREDENTIAL_STORAGE_TYPE); |
| 312 | credentialStorageType.checkRestrictionAndSetDisabled( |
| 313 | UserManager.DISALLOW_CONFIG_CREDENTIALS); |
| 314 | RestrictedPreference installCredentials = (RestrictedPreference) root.findPreference( |
| 315 | KEY_CREDENTIALS_INSTALL); |
| 316 | installCredentials.checkRestrictionAndSetDisabled( |
| 317 | UserManager.DISALLOW_CONFIG_CREDENTIALS); |
| 318 | mResetCredentials.checkRestrictionAndSetDisabled( |
| 319 | UserManager.DISALLOW_CONFIG_CREDENTIALS); |
Sudheer Shanka | 9c32468 | 2016-01-18 11:17:23 +0000 | [diff] [blame] | 320 | |
Sudheer Shanka | 9e9e63b | 2016-02-11 18:48:14 +0000 | [diff] [blame] | 321 | final int storageSummaryRes = |
| 322 | mKeyStore.isHardwareBacked() ? R.string.credential_storage_type_hardware |
| 323 | : R.string.credential_storage_type_software; |
| 324 | credentialStorageType.setSummary(storageSummaryRes); |
| 325 | } else { |
| 326 | PreferenceGroup credentialsManager = (PreferenceGroup) |
| 327 | root.findPreference(KEY_CREDENTIALS_MANAGER); |
| 328 | credentialsManager.removePreference(root.findPreference(KEY_RESET_CREDENTIALS)); |
| 329 | credentialsManager.removePreference(root.findPreference(KEY_CREDENTIALS_INSTALL)); |
| 330 | credentialsManager.removePreference(root.findPreference(KEY_CREDENTIAL_STORAGE_TYPE)); |
| 331 | } |
Sudheer Shanka | 9c32468 | 2016-01-18 11:17:23 +0000 | [diff] [blame] | 332 | |
Amith Yamasani | 7fb4f85 | 2012-09-25 22:17:33 -0700 | [diff] [blame] | 333 | |
Kenny Root | c5550c2 | 2013-04-08 09:56:05 -0700 | [diff] [blame] | 334 | // Application install |
Ido Ofir | 6f48244 | 2014-05-09 14:47:15 -0700 | [diff] [blame] | 335 | PreferenceGroup deviceAdminCategory = (PreferenceGroup) |
Maggie Benthall | 0c5a401 | 2013-03-14 17:41:27 -0400 | [diff] [blame] | 336 | root.findPreference(KEY_DEVICE_ADMIN_CATEGORY); |
Sudheer Shanka | 9159fe9 | 2015-11-23 12:07:05 +0000 | [diff] [blame] | 337 | mToggleAppInstallation = (RestrictedSwitchPreference) findPreference( |
Amith Yamasani | 7fb4f85 | 2012-09-25 22:17:33 -0700 | [diff] [blame] | 338 | KEY_TOGGLE_INSTALL_APPLICATIONS); |
| 339 | mToggleAppInstallation.setChecked(isNonMarketAppsAllowed()); |
Maggie Benthall | 0c5a401 | 2013-03-14 17:41:27 -0400 | [diff] [blame] | 340 | // Side loading of apps. |
Amith Yamasani | ceceb2a | 2014-11-11 15:36:15 -0800 | [diff] [blame] | 341 | // Disable for restricted profiles. For others, check if policy disallows it. |
Adrian Roos | 5437588 | 2015-04-16 17:11:22 -0700 | [diff] [blame] | 342 | mToggleAppInstallation.setEnabled(!um.getUserInfo(MY_USER_ID).isRestricted()); |
Sudheer Shanka | 9e9e63b | 2016-02-11 18:48:14 +0000 | [diff] [blame] | 343 | if (RestrictedLockUtils.hasBaseUserRestriction(getActivity(), |
| 344 | UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES, MY_USER_ID) |
| 345 | || RestrictedLockUtils.hasBaseUserRestriction(getActivity(), |
| 346 | UserManager.DISALLOW_INSTALL_APPS, MY_USER_ID)) { |
| 347 | mToggleAppInstallation.setEnabled(false); |
| 348 | } |
Sudheer Shanka | 9159fe9 | 2015-11-23 12:07:05 +0000 | [diff] [blame] | 349 | if (mToggleAppInstallation.isEnabled()) { |
| 350 | mToggleAppInstallation.checkRestrictionAndSetDisabled( |
| 351 | UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES); |
| 352 | if (!mToggleAppInstallation.isDisabledByAdmin()) { |
| 353 | mToggleAppInstallation.checkRestrictionAndSetDisabled( |
| 354 | UserManager.DISALLOW_INSTALL_APPS); |
| 355 | } |
Julia Reynolds | 565653c | 2014-06-12 11:49:12 -0400 | [diff] [blame] | 356 | } |
Maggie Benthall | 0c5a401 | 2013-03-14 17:41:27 -0400 | [diff] [blame] | 357 | |
Jim Miller | fe76559 | 2014-07-31 15:30:29 -0700 | [diff] [blame] | 358 | // Advanced Security features |
| 359 | PreferenceGroup advancedCategory = |
| 360 | (PreferenceGroup)root.findPreference(KEY_ADVANCED_SECURITY); |
Jim Miller | 9d25005 | 2014-08-21 19:24:47 -0700 | [diff] [blame] | 361 | if (advancedCategory != null) { |
Jim Miller | fe76559 | 2014-07-31 15:30:29 -0700 | [diff] [blame] | 362 | Preference manageAgents = advancedCategory.findPreference(KEY_MANAGE_TRUST_AGENTS); |
Adrian Roos | 5437588 | 2015-04-16 17:11:22 -0700 | [diff] [blame] | 363 | if (manageAgents != null && !mLockPatternUtils.isSecure(MY_USER_ID)) { |
Jim Miller | 9d25005 | 2014-08-21 19:24:47 -0700 | [diff] [blame] | 364 | manageAgents.setEnabled(false); |
| 365 | manageAgents.setSummary(R.string.disabled_because_no_backup_security); |
| 366 | } |
Jim Miller | fe76559 | 2014-07-31 15:30:29 -0700 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | // The above preferences come and go based on security state, so we need to update |
| 370 | // the index. This call is expected to be fairly cheap, but we may want to do something |
| 371 | // smarter in the future. |
| 372 | Index.getInstance(getActivity()) |
| 373 | .updateFromClassNameResource(SecuritySettings.class.getName(), true, true); |
| 374 | |
Jim Miller | 4a9065e | 2014-08-08 15:25:31 -0700 | [diff] [blame] | 375 | for (int i = 0; i < SWITCH_PREFERENCE_KEYS.length; i++) { |
| 376 | final Preference pref = findPreference(SWITCH_PREFERENCE_KEYS[i]); |
| 377 | if (pref != null) pref.setOnPreferenceChangeListener(this); |
| 378 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 379 | return root; |
| 380 | } |
| 381 | |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 382 | private void maybeAddFingerprintPreference(PreferenceGroup securityCategory, int userId) { |
Clara Bayarri | 40db4bb | 2016-01-07 17:10:27 +0000 | [diff] [blame] | 383 | Preference fingerprintPreference = |
| 384 | FingerprintSettings.getFingerprintPreferenceForUser( |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 385 | securityCategory.getContext(), userId); |
Clara Bayarri | 40db4bb | 2016-01-07 17:10:27 +0000 | [diff] [blame] | 386 | if (fingerprintPreference != null) { |
| 387 | securityCategory.addPreference(fingerprintPreference); |
Jim Miller | 94d4bd9 | 2015-02-19 21:04:57 -0800 | [diff] [blame] | 388 | } |
Jim Miller | 94d4bd9 | 2015-02-19 21:04:57 -0800 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | private void addTrustAgentSettings(PreferenceGroup securityCategory) { |
Adrian Roos | 5437588 | 2015-04-16 17:11:22 -0700 | [diff] [blame] | 392 | final boolean hasSecurity = mLockPatternUtils.isSecure(MY_USER_ID); |
Jim Miller | 94d4bd9 | 2015-02-19 21:04:57 -0800 | [diff] [blame] | 393 | ArrayList<TrustAgentComponentInfo> agents = |
Sudheer Shanka | ec1052d | 2016-02-03 00:24:52 +0000 | [diff] [blame] | 394 | getActiveTrustAgents(getActivity(), mLockPatternUtils, mDPM); |
Jim Miller | 94d4bd9 | 2015-02-19 21:04:57 -0800 | [diff] [blame] | 395 | for (int i = 0; i < agents.size(); i++) { |
| 396 | final TrustAgentComponentInfo agent = agents.get(i); |
Sudheer Shanka | ec1052d | 2016-02-03 00:24:52 +0000 | [diff] [blame] | 397 | RestrictedPreference trustAgentPreference = |
| 398 | new RestrictedPreference(securityCategory.getContext()); |
Jim Miller | 94d4bd9 | 2015-02-19 21:04:57 -0800 | [diff] [blame] | 399 | trustAgentPreference.setKey(KEY_TRUST_AGENT); |
| 400 | trustAgentPreference.setTitle(agent.title); |
| 401 | trustAgentPreference.setSummary(agent.summary); |
| 402 | // Create intent for this preference. |
| 403 | Intent intent = new Intent(); |
| 404 | intent.setComponent(agent.componentName); |
| 405 | intent.setAction(Intent.ACTION_MAIN); |
| 406 | trustAgentPreference.setIntent(intent); |
| 407 | // Add preference to the settings menu. |
| 408 | securityCategory.addPreference(trustAgentPreference); |
Adrian Roos | 088de47 | 2015-04-07 14:09:39 +0200 | [diff] [blame] | 409 | |
Sudheer Shanka | ec1052d | 2016-02-03 00:24:52 +0000 | [diff] [blame] | 410 | trustAgentPreference.setDisabledByAdmin(agent.admin); |
| 411 | if (!trustAgentPreference.isDisabledByAdmin() && !hasSecurity) { |
Jim Miller | 94d4bd9 | 2015-02-19 21:04:57 -0800 | [diff] [blame] | 412 | trustAgentPreference.setEnabled(false); |
| 413 | trustAgentPreference.setSummary(R.string.disabled_because_no_backup_security); |
| 414 | } |
| 415 | } |
| 416 | } |
| 417 | |
PauloftheWest | 0b8788a | 2014-12-08 13:49:35 -0800 | [diff] [blame] | 418 | /* Return true if a there is a Slot that has Icc. |
| 419 | */ |
| 420 | private boolean isSimIccReady() { |
| 421 | TelephonyManager tm = TelephonyManager.getDefault(); |
| 422 | final List<SubscriptionInfo> subInfoList = |
| 423 | mSubscriptionManager.getActiveSubscriptionInfoList(); |
| 424 | |
| 425 | if (subInfoList != null) { |
| 426 | for (SubscriptionInfo subInfo : subInfoList) { |
Sanket Padawe | 2478420 | 2015-01-14 14:48:27 -0800 | [diff] [blame] | 427 | if (tm.hasIccCard(subInfo.getSimSlotIndex())) { |
PauloftheWest | 0b8788a | 2014-12-08 13:49:35 -0800 | [diff] [blame] | 428 | return true; |
| 429 | } |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | return false; |
| 434 | } |
| 435 | |
PauloftheWest | 50e6eca | 2014-10-03 11:07:14 -0700 | [diff] [blame] | 436 | /* Return true if a SIM is ready for locking. |
| 437 | * TODO: consider adding to TelephonyManager or SubscritpionManasger. |
| 438 | */ |
Wink Saville | 0183fb5 | 2014-11-22 10:11:39 -0800 | [diff] [blame] | 439 | private boolean isSimReady() { |
PauloftheWest | 50e6eca | 2014-10-03 11:07:14 -0700 | [diff] [blame] | 440 | int simState = TelephonyManager.SIM_STATE_UNKNOWN; |
Wink Saville | 0183fb5 | 2014-11-22 10:11:39 -0800 | [diff] [blame] | 441 | final List<SubscriptionInfo> subInfoList = |
| 442 | mSubscriptionManager.getActiveSubscriptionInfoList(); |
PauloftheWest | 50e6eca | 2014-10-03 11:07:14 -0700 | [diff] [blame] | 443 | if (subInfoList != null) { |
Wink Saville | ca75661 | 2014-11-08 10:47:12 -0800 | [diff] [blame] | 444 | for (SubscriptionInfo subInfo : subInfoList) { |
Stuart Scott | 3ada2ec | 2014-10-31 14:11:24 -0700 | [diff] [blame] | 445 | simState = TelephonyManager.getDefault().getSimState(subInfo.getSimSlotIndex()); |
PauloftheWest | 50e6eca | 2014-10-03 11:07:14 -0700 | [diff] [blame] | 446 | if((simState != TelephonyManager.SIM_STATE_ABSENT) && |
| 447 | (simState != TelephonyManager.SIM_STATE_UNKNOWN)){ |
| 448 | return true; |
| 449 | } |
| 450 | } |
| 451 | } |
| 452 | return false; |
| 453 | } |
| 454 | |
Jim Miller | fe76559 | 2014-07-31 15:30:29 -0700 | [diff] [blame] | 455 | private static ArrayList<TrustAgentComponentInfo> getActiveTrustAgents( |
Sudheer Shanka | ec1052d | 2016-02-03 00:24:52 +0000 | [diff] [blame] | 456 | Context context, LockPatternUtils utils, DevicePolicyManager dpm) { |
| 457 | PackageManager pm = context.getPackageManager(); |
Jim Miller | fe76559 | 2014-07-31 15:30:29 -0700 | [diff] [blame] | 458 | ArrayList<TrustAgentComponentInfo> result = new ArrayList<TrustAgentComponentInfo>(); |
| 459 | List<ResolveInfo> resolveInfos = pm.queryIntentServices(TRUST_AGENT_INTENT, |
| 460 | PackageManager.GET_META_DATA); |
Adrian Roos | 5437588 | 2015-04-16 17:11:22 -0700 | [diff] [blame] | 461 | List<ComponentName> enabledTrustAgents = utils.getEnabledTrustAgents(MY_USER_ID); |
Adrian Roos | 088de47 | 2015-04-07 14:09:39 +0200 | [diff] [blame] | 462 | |
Sudheer Shanka | ec1052d | 2016-02-03 00:24:52 +0000 | [diff] [blame] | 463 | EnforcedAdmin admin = RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(context, |
| 464 | DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS, UserHandle.myUserId()); |
Adrian Roos | 088de47 | 2015-04-07 14:09:39 +0200 | [diff] [blame] | 465 | |
Jim Miller | fe76559 | 2014-07-31 15:30:29 -0700 | [diff] [blame] | 466 | if (enabledTrustAgents != null && !enabledTrustAgents.isEmpty()) { |
| 467 | for (int i = 0; i < resolveInfos.size(); i++) { |
| 468 | ResolveInfo resolveInfo = resolveInfos.get(i); |
| 469 | if (resolveInfo.serviceInfo == null) continue; |
| 470 | if (!TrustAgentUtils.checkProvidePermission(resolveInfo, pm)) continue; |
| 471 | TrustAgentComponentInfo trustAgentComponentInfo = |
| 472 | TrustAgentUtils.getSettingsComponent(pm, resolveInfo); |
| 473 | if (trustAgentComponentInfo.componentName == null || |
| 474 | !enabledTrustAgents.contains( |
| 475 | TrustAgentUtils.getComponentName(resolveInfo)) || |
| 476 | TextUtils.isEmpty(trustAgentComponentInfo.title)) continue; |
Sudheer Shanka | ec1052d | 2016-02-03 00:24:52 +0000 | [diff] [blame] | 477 | if (admin != null && dpm.getTrustAgentConfiguration( |
Adrian Roos | 088de47 | 2015-04-07 14:09:39 +0200 | [diff] [blame] | 478 | null, TrustAgentUtils.getComponentName(resolveInfo)) == null) { |
Sudheer Shanka | ec1052d | 2016-02-03 00:24:52 +0000 | [diff] [blame] | 479 | trustAgentComponentInfo.admin = admin; |
Adrian Roos | 088de47 | 2015-04-07 14:09:39 +0200 | [diff] [blame] | 480 | } |
Jim Miller | fe76559 | 2014-07-31 15:30:29 -0700 | [diff] [blame] | 481 | result.add(trustAgentComponentInfo); |
| 482 | if (ONLY_ONE_TRUST_AGENT) break; |
| 483 | } |
| 484 | } |
| 485 | return result; |
| 486 | } |
| 487 | |
Gilles Debunne | 2c88a87 | 2011-06-21 12:47:17 -0700 | [diff] [blame] | 488 | private boolean isNonMarketAppsAllowed() { |
Christopher Tate | 5a64c73 | 2012-09-07 13:35:31 -0700 | [diff] [blame] | 489 | return Settings.Global.getInt(getContentResolver(), |
| 490 | Settings.Global.INSTALL_NON_MARKET_APPS, 0) > 0; |
Gilles Debunne | 2c88a87 | 2011-06-21 12:47:17 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | private void setNonMarketAppsAllowed(boolean enabled) { |
Maggie Benthall | 0c5a401 | 2013-03-14 17:41:27 -0400 | [diff] [blame] | 494 | final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE); |
| 495 | if (um.hasUserRestriction(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES)) { |
| 496 | return; |
| 497 | } |
Gilles Debunne | 2c88a87 | 2011-06-21 12:47:17 -0700 | [diff] [blame] | 498 | // Change the system setting |
Christopher Tate | 5a64c73 | 2012-09-07 13:35:31 -0700 | [diff] [blame] | 499 | Settings.Global.putInt(getContentResolver(), Settings.Global.INSTALL_NON_MARKET_APPS, |
Gilles Debunne | 2c88a87 | 2011-06-21 12:47:17 -0700 | [diff] [blame] | 500 | enabled ? 1 : 0); |
| 501 | } |
| 502 | |
| 503 | private void warnAppInstallation() { |
| 504 | // TODO: DialogFragment? |
| 505 | mWarnInstallApps = new AlertDialog.Builder(getActivity()).setTitle( |
| 506 | getResources().getString(R.string.error_title)) |
| 507 | .setIcon(com.android.internal.R.drawable.ic_dialog_alert) |
| 508 | .setMessage(getResources().getString(R.string.install_all_warning)) |
| 509 | .setPositiveButton(android.R.string.yes, this) |
arete | 1722482 | 2014-08-14 13:45:36 -0700 | [diff] [blame] | 510 | .setNegativeButton(android.R.string.no, this) |
Gilles Debunne | 2c88a87 | 2011-06-21 12:47:17 -0700 | [diff] [blame] | 511 | .show(); |
| 512 | } |
| 513 | |
Maggie Benthall | 0c5a401 | 2013-03-14 17:41:27 -0400 | [diff] [blame] | 514 | @Override |
Gilles Debunne | 2c88a87 | 2011-06-21 12:47:17 -0700 | [diff] [blame] | 515 | public void onClick(DialogInterface dialog, int which) { |
arete | 1722482 | 2014-08-14 13:45:36 -0700 | [diff] [blame] | 516 | if (dialog == mWarnInstallApps) { |
| 517 | boolean turnOn = which == DialogInterface.BUTTON_POSITIVE; |
| 518 | setNonMarketAppsAllowed(turnOn); |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 519 | if (mToggleAppInstallation != null) { |
arete | 1722482 | 2014-08-14 13:45:36 -0700 | [diff] [blame] | 520 | mToggleAppInstallation.setChecked(turnOn); |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 521 | } |
Gilles Debunne | 2c88a87 | 2011-06-21 12:47:17 -0700 | [diff] [blame] | 522 | } |
| 523 | } |
| 524 | |
| 525 | @Override |
Adrian Roos | 62775bf | 2016-01-28 13:23:53 -0800 | [diff] [blame] | 526 | public void onGearClick(GearPreference p) { |
| 527 | if (KEY_UNLOCK_SET_OR_CHANGE.equals(p.getKey())) { |
| 528 | startFragment(this, SecuritySubSettings.class.getName(), 0, 0, null); |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | @Override |
Gilles Debunne | 2c88a87 | 2011-06-21 12:47:17 -0700 | [diff] [blame] | 533 | public void onDestroy() { |
| 534 | super.onDestroy(); |
| 535 | if (mWarnInstallApps != null) { |
| 536 | mWarnInstallApps.dismiss(); |
| 537 | } |
| 538 | } |
| 539 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 540 | @Override |
Jim Miller | 250b9be | 2014-09-05 18:48:18 -0700 | [diff] [blame] | 541 | public void onSaveInstanceState(Bundle outState) { |
| 542 | super.onSaveInstanceState(outState); |
| 543 | if (mTrustAgentClickIntent != null) { |
| 544 | outState.putParcelable(TRUST_AGENT_CLICK_INTENT, mTrustAgentClickIntent); |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 549 | public void onResume() { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 550 | super.onResume(); |
| 551 | |
Jim Miller | 86624a2 | 2010-08-30 22:07:58 -0700 | [diff] [blame] | 552 | // Make sure we reload the preference hierarchy since some of these settings |
| 553 | // depend on others... |
| 554 | createPreferenceHierarchy(); |
| 555 | |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 556 | if (mVisiblePatternProfile != null) { |
Clara Bayarri | 56462d6 | 2016-02-12 13:55:36 +0000 | [diff] [blame] | 557 | mVisiblePatternProfile.setChecked(mLockPatternUtils.isVisiblePatternEnabled( |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 558 | mProfileChallengeUserId)); |
| 559 | } |
| 560 | |
Clara Bayarri | 56462d6 | 2016-02-12 13:55:36 +0000 | [diff] [blame] | 561 | updateUnificationPreference(); |
| 562 | |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 563 | if (mShowPassword != null) { |
| 564 | mShowPassword.setChecked(Settings.System.getInt(getContentResolver(), |
| 565 | Settings.System.TEXT_SHOW_PASSWORD, 1) != 0); |
| 566 | } |
Hung-ying Tyan | b0883cb | 2009-09-30 11:56:05 +0800 | [diff] [blame] | 567 | |
Sudheer Shanka | 28eab08 | 2016-02-10 21:35:54 +0000 | [diff] [blame] | 568 | if (mResetCredentials != null && !mResetCredentials.isDisabledByAdmin()) { |
Kenny Root | c4372c3 | 2013-04-22 13:41:18 -0700 | [diff] [blame] | 569 | mResetCredentials.setEnabled(!mKeyStore.isEmpty()); |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 570 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 571 | } |
| 572 | |
Clara Bayarri | 56462d6 | 2016-02-12 13:55:36 +0000 | [diff] [blame] | 573 | private void updateUnificationPreference() { |
| 574 | if (mUnifyProfile != null) { |
| 575 | mUnifyProfile.setChecked(!mLockPatternUtils.isSeparateProfileChallengeEnabled( |
| 576 | mProfileChallengeUserId)); |
| 577 | } |
| 578 | } |
| 579 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 580 | @Override |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 581 | public boolean onPreferenceTreeClick(Preference preference) { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 582 | final String key = preference.getKey(); |
Jim Miller | bbb4afa | 2010-04-08 19:40:19 -0700 | [diff] [blame] | 583 | if (KEY_UNLOCK_SET_OR_CHANGE.equals(key)) { |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 584 | startFragment(this, "com.android.settings.ChooseLockGeneric$ChooseLockGenericFragment", |
Fabrice Di Meglio | 5bdf042 | 2014-07-01 15:15:18 -0700 | [diff] [blame] | 585 | R.string.lock_settings_picker_title, SET_OR_CHANGE_LOCK_METHOD_REQUEST, null); |
Clara Bayarri | 6934a04 | 2015-10-14 11:07:35 +0100 | [diff] [blame] | 586 | } else if (KEY_UNLOCK_SET_OR_CHANGE_PROFILE.equals(key)) { |
| 587 | Bundle extras = new Bundle(); |
| 588 | extras.putInt(Intent.EXTRA_USER_ID, mProfileChallengeUserId); |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 589 | startFragment(this, "com.android.settings.ChooseLockGeneric$ChooseLockGenericFragment", |
| 590 | R.string.lock_settings_picker_title_profile, |
| 591 | SET_OR_CHANGE_LOCK_METHOD_REQUEST_PROFILE, extras); |
Ido Ofir | 6f48244 | 2014-05-09 14:47:15 -0700 | [diff] [blame] | 592 | } else if (KEY_TRUST_AGENT.equals(key)) { |
| 593 | ChooseLockSettingsHelper helper = |
| 594 | new ChooseLockSettingsHelper(this.getActivity(), this); |
Jim Miller | 250b9be | 2014-09-05 18:48:18 -0700 | [diff] [blame] | 595 | mTrustAgentClickIntent = preference.getIntent(); |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 596 | boolean confirmationLaunched = helper.launchConfirmationActivity( |
| 597 | CHANGE_TRUST_AGENT_SETTINGS, preference.getTitle()); |
| 598 | if (!confirmationLaunched&& mTrustAgentClickIntent != null) { |
Ido Ofir | 6f48244 | 2014-05-09 14:47:15 -0700 | [diff] [blame] | 599 | // If this returns false, it means no password confirmation is required. |
Jim Miller | 250b9be | 2014-09-05 18:48:18 -0700 | [diff] [blame] | 600 | startActivity(mTrustAgentClickIntent); |
| 601 | mTrustAgentClickIntent = null; |
Ido Ofir | 6f48244 | 2014-05-09 14:47:15 -0700 | [diff] [blame] | 602 | } |
Jim Miller | 36972bb | 2010-11-30 19:47:38 -0800 | [diff] [blame] | 603 | } else { |
| 604 | // If we didn't handle it, let preferences handle it. |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 605 | return super.onPreferenceTreeClick(preference); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 606 | } |
Jim Miller | 36972bb | 2010-11-30 19:47:38 -0800 | [diff] [blame] | 607 | return true; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 608 | } |
| 609 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 610 | /** |
Gilles Debunne | a6a8a14 | 2011-06-09 11:56:17 -0700 | [diff] [blame] | 611 | * see confirmPatternThenDisableAndClear |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 612 | */ |
| 613 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 614 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 615 | super.onActivityResult(requestCode, resultCode, data); |
Adrian Roos | f788718 | 2015-01-07 20:51:57 +0100 | [diff] [blame] | 616 | if (requestCode == CHANGE_TRUST_AGENT_SETTINGS && resultCode == Activity.RESULT_OK) { |
Jim Miller | 250b9be | 2014-09-05 18:48:18 -0700 | [diff] [blame] | 617 | if (mTrustAgentClickIntent != null) { |
| 618 | startActivity(mTrustAgentClickIntent); |
| 619 | mTrustAgentClickIntent = null; |
Ido Ofir | 6f48244 | 2014-05-09 14:47:15 -0700 | [diff] [blame] | 620 | } |
Jim Miller | 250b9be | 2014-09-05 18:48:18 -0700 | [diff] [blame] | 621 | return; |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 622 | } else if (requestCode == UNIFY_LOCK_CONFIRM_DEVICE_REQUEST |
| 623 | && resultCode == Activity.RESULT_OK) { |
| 624 | mCurrentDevicePassword = |
| 625 | data.getStringExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD); |
| 626 | launchConfirmProfileLockForUnification(); |
| 627 | return; |
| 628 | } else if (requestCode == UNIFY_LOCK_CONFIRM_PROFILE_REQUEST |
| 629 | && resultCode == Activity.RESULT_OK) { |
| 630 | mCurrentProfilePassword = |
| 631 | data.getStringExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD); |
| 632 | unifyLocks(); |
| 633 | return; |
Danielle Millett | 487b16f | 2011-11-02 11:12:21 -0400 | [diff] [blame] | 634 | } |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 635 | createPreferenceHierarchy(); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 636 | } |
Amith Yamasani | f06d869 | 2009-06-11 22:32:33 -0700 | [diff] [blame] | 637 | |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 638 | private void launchConfirmDeviceLockForUnification() { |
| 639 | final String title = getActivity().getString( |
| 640 | R.string.lock_settings_profile_screen_lock_title); |
| 641 | final ChooseLockSettingsHelper helper = |
| 642 | new ChooseLockSettingsHelper(getActivity(), this); |
| 643 | if (!helper.launchConfirmationActivity( |
| 644 | UNIFY_LOCK_CONFIRM_DEVICE_REQUEST, title, true, UserHandle.myUserId())) { |
| 645 | launchConfirmProfileLockForUnification(); |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | private void launchConfirmProfileLockForUnification() { |
| 650 | final String title = getActivity().getString( |
| 651 | R.string.lock_settings_profile_screen_lock_title); |
| 652 | final ChooseLockSettingsHelper helper = |
| 653 | new ChooseLockSettingsHelper(getActivity(), this); |
| 654 | if (!helper.launchConfirmationActivity( |
| 655 | UNIFY_LOCK_CONFIRM_PROFILE_REQUEST, title, true, mProfileChallengeUserId)) { |
| 656 | unifyLocks(); |
| 657 | createPreferenceHierarchy(); |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | private void unifyLocks() { |
| 662 | int profileQuality = |
| 663 | mLockPatternUtils.getKeyguardStoredPasswordQuality(mProfileChallengeUserId); |
| 664 | mLockPatternUtils.clearLock(mProfileChallengeUserId); |
| 665 | mLockPatternUtils.setSeparateProfileChallengeEnabled(mProfileChallengeUserId, false); |
| 666 | if (profileQuality == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING) { |
| 667 | mLockPatternUtils.saveLockPattern( |
| 668 | LockPatternUtils.stringToPattern(mCurrentProfilePassword), |
| 669 | mCurrentDevicePassword, UserHandle.myUserId()); |
| 670 | } else { |
| 671 | mLockPatternUtils.saveLockPassword( |
| 672 | mCurrentProfilePassword, mCurrentDevicePassword, |
| 673 | profileQuality, UserHandle.myUserId()); |
| 674 | } |
| 675 | mCurrentDevicePassword = null; |
| 676 | mCurrentProfilePassword = null; |
| 677 | } |
| 678 | |
Clara Bayarri | 56462d6 | 2016-02-12 13:55:36 +0000 | [diff] [blame] | 679 | private void unifyUncompliantLocks() { |
| 680 | mLockPatternUtils.clearLock(mProfileChallengeUserId); |
| 681 | mLockPatternUtils.setSeparateProfileChallengeEnabled(mProfileChallengeUserId, false); |
| 682 | startFragment(this, "com.android.settings.ChooseLockGeneric$ChooseLockGenericFragment", |
| 683 | R.string.lock_settings_picker_title, SET_OR_CHANGE_LOCK_METHOD_REQUEST, null); |
| 684 | } |
| 685 | |
Maggie Benthall | 0c5a401 | 2013-03-14 17:41:27 -0400 | [diff] [blame] | 686 | @Override |
Jim Miller | 86624a2 | 2010-08-30 22:07:58 -0700 | [diff] [blame] | 687 | public boolean onPreferenceChange(Preference preference, Object value) { |
arete | 300e920 | 2014-08-15 12:04:48 -0700 | [diff] [blame] | 688 | boolean result = true; |
Jim Miller | 4a9065e | 2014-08-08 15:25:31 -0700 | [diff] [blame] | 689 | final String key = preference.getKey(); |
| 690 | final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils(); |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 691 | if (KEY_VISIBLE_PATTERN_PROFILE.equals(key)) { |
| 692 | lockPatternUtils.setVisiblePatternEnabled((Boolean) value, mProfileChallengeUserId); |
Clara Bayarri | 56462d6 | 2016-02-12 13:55:36 +0000 | [diff] [blame] | 693 | } else if (KEY_UNIFICATION.equals(key)) { |
| 694 | if ((Boolean) value) { |
| 695 | final boolean compliantForDevice = |
| 696 | (mLockPatternUtils.getKeyguardStoredPasswordQuality(mProfileChallengeUserId) |
| 697 | >= DevicePolicyManager.PASSWORD_QUALITY_SOMETHING |
| 698 | && mLockPatternUtils.isSeparateProfileChallengeAllowedToUnify( |
| 699 | mProfileChallengeUserId)); |
| 700 | UnificationConfirmationDialog dialog = |
| 701 | UnificationConfirmationDialog.newIntance(compliantForDevice); |
| 702 | dialog.show(getChildFragmentManager(), TAG_UNIFICATION_DIALOG); |
| 703 | } else { |
| 704 | mLockPatternUtils.setSeparateProfileChallengeEnabled(mProfileChallengeUserId, true); |
| 705 | createPreferenceHierarchy(); |
| 706 | } |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 707 | } else if (KEY_SHOW_PASSWORD.equals(key)) { |
Jim Miller | 4a9065e | 2014-08-08 15:25:31 -0700 | [diff] [blame] | 708 | Settings.System.putInt(getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD, |
| 709 | ((Boolean) value) ? 1 : 0); |
Paul Lawrence | c04420c | 2015-05-18 13:25:01 -0700 | [diff] [blame] | 710 | lockPatternUtils.setVisiblePasswordEnabled((Boolean) value, MY_USER_ID); |
Jim Miller | 4a9065e | 2014-08-08 15:25:31 -0700 | [diff] [blame] | 711 | } else if (KEY_TOGGLE_INSTALL_APPLICATIONS.equals(key)) { |
| 712 | if ((Boolean) value) { |
| 713 | mToggleAppInstallation.setChecked(false); |
| 714 | warnAppInstallation(); |
arete | 300e920 | 2014-08-15 12:04:48 -0700 | [diff] [blame] | 715 | // Don't change Switch status until user makes choice in dialog, so return false. |
| 716 | result = false; |
Jim Miller | 4a9065e | 2014-08-08 15:25:31 -0700 | [diff] [blame] | 717 | } else { |
| 718 | setNonMarketAppsAllowed(false); |
| 719 | } |
Jim Miller | 86624a2 | 2010-08-30 22:07:58 -0700 | [diff] [blame] | 720 | } |
arete | 300e920 | 2014-08-15 12:04:48 -0700 | [diff] [blame] | 721 | return result; |
Jim Miller | 86624a2 | 2010-08-30 22:07:58 -0700 | [diff] [blame] | 722 | } |
Danielle Millett | 487b16f | 2011-11-02 11:12:21 -0400 | [diff] [blame] | 723 | |
rich cannings | 93c0ee5 | 2012-09-30 13:54:26 -0700 | [diff] [blame] | 724 | @Override |
| 725 | protected int getHelpResource() { |
| 726 | return R.string.help_url_security; |
| 727 | } |
| 728 | |
Fabrice Di Meglio | d1d2f02 | 2014-04-11 16:09:11 -0700 | [diff] [blame] | 729 | /** |
| 730 | * For Search. Please keep it in sync when updating "createPreferenceHierarchy()" |
| 731 | */ |
| 732 | public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = |
| 733 | new SecuritySearchIndexProvider(); |
| 734 | |
Jim Miller | fe76559 | 2014-07-31 15:30:29 -0700 | [diff] [blame] | 735 | private static class SecuritySearchIndexProvider extends BaseSearchIndexProvider { |
Fabrice Di Meglio | d1d2f02 | 2014-04-11 16:09:11 -0700 | [diff] [blame] | 736 | |
Fabrice Di Meglio | d1d2f02 | 2014-04-11 16:09:11 -0700 | [diff] [blame] | 737 | @Override |
| 738 | public List<SearchIndexableResource> getXmlResourcesToIndex( |
| 739 | Context context, boolean enabled) { |
| 740 | |
| 741 | List<SearchIndexableResource> result = new ArrayList<SearchIndexableResource>(); |
| 742 | |
| 743 | LockPatternUtils lockPatternUtils = new LockPatternUtils(context); |
| 744 | // Add options for lock/unlock screen |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 745 | int resId = getResIdForLockUnlockScreen(context, lockPatternUtils, MY_USER_ID); |
Fabrice Di Meglio | d1d2f02 | 2014-04-11 16:09:11 -0700 | [diff] [blame] | 746 | |
| 747 | SearchIndexableResource sir = new SearchIndexableResource(context); |
| 748 | sir.xmlResId = resId; |
| 749 | result.add(sir); |
| 750 | |
Xiaohui Chen | 44879a3 | 2015-07-22 13:53:22 -0700 | [diff] [blame] | 751 | final UserManager um = UserManager.get(context); |
Clara Bayarri | 462cce1 | 2016-02-18 12:09:21 +0000 | [diff] [blame^] | 752 | final int profileUserId = Utils.getManagedProfileId(um, MY_USER_ID); |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 753 | if (profileUserId != UserHandle.USER_NULL |
| 754 | && lockPatternUtils.isSeparateProfileChallengeAllowed(profileUserId)) { |
| 755 | sir = new SearchIndexableResource(context); |
| 756 | sir.xmlResId = getResIdForLockUnlockScreen( |
| 757 | context, lockPatternUtils, profileUserId); |
| 758 | result.add(sir); |
Clara Bayarri | 6934a04 | 2015-10-14 11:07:35 +0100 | [diff] [blame] | 759 | } |
| 760 | |
Xiaohui Chen | 44879a3 | 2015-07-22 13:53:22 -0700 | [diff] [blame] | 761 | if (um.isAdminUser()) { |
Fabrice Di Meglio | d1d2f02 | 2014-04-11 16:09:11 -0700 | [diff] [blame] | 762 | DevicePolicyManager dpm = (DevicePolicyManager) |
| 763 | context.getSystemService(Context.DEVICE_POLICY_SERVICE); |
| 764 | |
| 765 | switch (dpm.getStorageEncryptionStatus()) { |
| 766 | case DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE: |
| 767 | // The device is currently encrypted. |
| 768 | resId = R.xml.security_settings_encrypted; |
| 769 | break; |
| 770 | case DevicePolicyManager.ENCRYPTION_STATUS_INACTIVE: |
| 771 | // This device supports encryption but isn't encrypted. |
| 772 | resId = R.xml.security_settings_unencrypted; |
| 773 | break; |
| 774 | } |
| 775 | |
| 776 | sir = new SearchIndexableResource(context); |
| 777 | sir.xmlResId = resId; |
| 778 | result.add(sir); |
| 779 | } |
| 780 | |
Adrian Roos | 62775bf | 2016-01-28 13:23:53 -0800 | [diff] [blame] | 781 | sir = new SearchIndexableResource(context); |
| 782 | sir.xmlResId = SecuritySubSettings.getResIdForLockUnlockSubScreen(context, |
| 783 | lockPatternUtils); |
| 784 | sir.className = SecuritySubSettings.class.getName(); |
| 785 | result.add(sir); |
| 786 | |
Fabrice Di Meglio | d1d2f02 | 2014-04-11 16:09:11 -0700 | [diff] [blame] | 787 | // Append the rest of the settings |
| 788 | sir = new SearchIndexableResource(context); |
| 789 | sir.xmlResId = R.xml.security_settings_misc; |
| 790 | result.add(sir); |
| 791 | |
| 792 | return result; |
| 793 | } |
| 794 | |
| 795 | @Override |
| 796 | public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) { |
| 797 | final List<SearchIndexableRaw> result = new ArrayList<SearchIndexableRaw>(); |
| 798 | final Resources res = context.getResources(); |
| 799 | |
| 800 | final String screenTitle = res.getString(R.string.security_settings_title); |
| 801 | |
Fabrice Di Meglio | d729029 | 2014-07-01 14:32:03 -0700 | [diff] [blame] | 802 | SearchIndexableRaw data = new SearchIndexableRaw(context); |
| 803 | data.title = screenTitle; |
| 804 | data.screenTitle = screenTitle; |
| 805 | result.add(data); |
Fabrice Di Meglio | d1d2f02 | 2014-04-11 16:09:11 -0700 | [diff] [blame] | 806 | |
Xiaohui Chen | 44879a3 | 2015-07-22 13:53:22 -0700 | [diff] [blame] | 807 | final UserManager um = UserManager.get(context); |
| 808 | if (!um.isAdminUser()) { |
| 809 | int resId = um.isLinkedUser() ? |
Fabrice Di Meglio | d1d2f02 | 2014-04-11 16:09:11 -0700 | [diff] [blame] | 810 | R.string.profile_info_settings_title : R.string.user_info_settings_title; |
| 811 | |
| 812 | data = new SearchIndexableRaw(context); |
| 813 | data.title = res.getString(resId); |
| 814 | data.screenTitle = screenTitle; |
| 815 | result.add(data); |
| 816 | } |
| 817 | |
Julia Reynolds | f516e7d | 2015-07-16 15:33:22 -0400 | [diff] [blame] | 818 | // Fingerprint |
| 819 | FingerprintManager fpm = |
| 820 | (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE); |
Jim Miller | b528b26 | 2016-02-04 17:10:44 -0800 | [diff] [blame] | 821 | if (fpm != null && fpm.isHardwareDetected()) { |
Jim Miller | c5fa6e2 | 2015-09-22 18:30:13 -0700 | [diff] [blame] | 822 | // This catches the title which can be overloaded in an overlay |
Julia Reynolds | f516e7d | 2015-07-16 15:33:22 -0400 | [diff] [blame] | 823 | data = new SearchIndexableRaw(context); |
| 824 | data.title = res.getString(R.string.security_settings_fingerprint_preference_title); |
| 825 | data.screenTitle = screenTitle; |
| 826 | result.add(data); |
Jim Miller | c5fa6e2 | 2015-09-22 18:30:13 -0700 | [diff] [blame] | 827 | // Fallback for when the above doesn't contain "fingerprint" |
| 828 | data = new SearchIndexableRaw(context); |
| 829 | data.title = res.getString(R.string.fingerprint_manage_category_title); |
| 830 | data.screenTitle = screenTitle; |
| 831 | result.add(data); |
Julia Reynolds | f516e7d | 2015-07-16 15:33:22 -0400 | [diff] [blame] | 832 | } |
| 833 | |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 834 | final LockPatternUtils lockPatternUtils = new LockPatternUtils(context); |
Clara Bayarri | 462cce1 | 2016-02-18 12:09:21 +0000 | [diff] [blame^] | 835 | final int profileUserId = Utils.getManagedProfileId(um, MY_USER_ID); |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 836 | if (profileUserId != UserHandle.USER_NULL |
| 837 | && lockPatternUtils.isSeparateProfileChallengeAllowed(profileUserId)) { |
| 838 | if (lockPatternUtils.getKeyguardStoredPasswordQuality(profileUserId) |
| 839 | >= DevicePolicyManager.PASSWORD_QUALITY_SOMETHING |
| 840 | && lockPatternUtils.isSeparateProfileChallengeAllowedToUnify( |
| 841 | profileUserId)) { |
| 842 | data = new SearchIndexableRaw(context); |
| 843 | data.title = res.getString(R.string.lock_settings_profile_unification_title); |
| 844 | data.screenTitle = screenTitle; |
| 845 | result.add(data); |
| 846 | } |
| 847 | } |
| 848 | |
Fabrice Di Meglio | d1d2f02 | 2014-04-11 16:09:11 -0700 | [diff] [blame] | 849 | // Credential storage |
Fabrice Di Meglio | d1d2f02 | 2014-04-11 16:09:11 -0700 | [diff] [blame] | 850 | if (!um.hasUserRestriction(UserManager.DISALLOW_CONFIG_CREDENTIALS)) { |
| 851 | KeyStore keyStore = KeyStore.getInstance(); |
| 852 | |
| 853 | final int storageSummaryRes = keyStore.isHardwareBacked() ? |
| 854 | R.string.credential_storage_type_hardware : |
| 855 | R.string.credential_storage_type_software; |
| 856 | |
| 857 | data = new SearchIndexableRaw(context); |
| 858 | data.title = res.getString(storageSummaryRes); |
| 859 | data.screenTitle = screenTitle; |
| 860 | result.add(data); |
| 861 | } |
| 862 | |
Jim Miller | fe76559 | 2014-07-31 15:30:29 -0700 | [diff] [blame] | 863 | // Advanced |
Adrian Roos | 5437588 | 2015-04-16 17:11:22 -0700 | [diff] [blame] | 864 | if (lockPatternUtils.isSecure(MY_USER_ID)) { |
Jim Miller | fe76559 | 2014-07-31 15:30:29 -0700 | [diff] [blame] | 865 | ArrayList<TrustAgentComponentInfo> agents = |
Sudheer Shanka | ec1052d | 2016-02-03 00:24:52 +0000 | [diff] [blame] | 866 | getActiveTrustAgents(context, lockPatternUtils, |
Adrian Roos | 088de47 | 2015-04-07 14:09:39 +0200 | [diff] [blame] | 867 | context.getSystemService(DevicePolicyManager.class)); |
Jim Miller | fe76559 | 2014-07-31 15:30:29 -0700 | [diff] [blame] | 868 | for (int i = 0; i < agents.size(); i++) { |
| 869 | final TrustAgentComponentInfo agent = agents.get(i); |
| 870 | data = new SearchIndexableRaw(context); |
| 871 | data.title = agent.title; |
| 872 | data.screenTitle = screenTitle; |
| 873 | result.add(data); |
| 874 | } |
| 875 | } |
Fabrice Di Meglio | d1d2f02 | 2014-04-11 16:09:11 -0700 | [diff] [blame] | 876 | return result; |
| 877 | } |
| 878 | |
| 879 | @Override |
| 880 | public List<String> getNonIndexableKeys(Context context) { |
| 881 | final List<String> keys = new ArrayList<String>(); |
| 882 | |
| 883 | LockPatternUtils lockPatternUtils = new LockPatternUtils(context); |
Fabrice Di Meglio | d1d2f02 | 2014-04-11 16:09:11 -0700 | [diff] [blame] | 884 | |
Fabrice Di Meglio | d1d2f02 | 2014-04-11 16:09:11 -0700 | [diff] [blame] | 885 | // Do not display SIM lock for devices without an Icc card |
Xiaohui Chen | 44879a3 | 2015-07-22 13:53:22 -0700 | [diff] [blame] | 886 | final UserManager um = UserManager.get(context); |
| 887 | final TelephonyManager tm = TelephonyManager.from(context); |
| 888 | if (!um.isAdminUser() || !tm.hasIccCard()) { |
Fabrice Di Meglio | d1d2f02 | 2014-04-11 16:09:11 -0700 | [diff] [blame] | 889 | keys.add(KEY_SIM_LOCK); |
| 890 | } |
| 891 | |
Fabrice Di Meglio | d1d2f02 | 2014-04-11 16:09:11 -0700 | [diff] [blame] | 892 | if (um.hasUserRestriction(UserManager.DISALLOW_CONFIG_CREDENTIALS)) { |
| 893 | keys.add(KEY_CREDENTIALS_MANAGER); |
| 894 | } |
| 895 | |
Jim Miller | fe76559 | 2014-07-31 15:30:29 -0700 | [diff] [blame] | 896 | // TrustAgent settings disappear when the user has no primary security. |
Adrian Roos | 5437588 | 2015-04-16 17:11:22 -0700 | [diff] [blame] | 897 | if (!lockPatternUtils.isSecure(MY_USER_ID)) { |
Jim Miller | fe76559 | 2014-07-31 15:30:29 -0700 | [diff] [blame] | 898 | keys.add(KEY_TRUST_AGENT); |
| 899 | keys.add(KEY_MANAGE_TRUST_AGENTS); |
| 900 | } |
| 901 | |
Adrian Roos | 62775bf | 2016-01-28 13:23:53 -0800 | [diff] [blame] | 902 | if (!SecuritySubSettings.canChangeRequireCredentialBeforeStartup(context)) { |
| 903 | keys.add(SecuritySubSettings.KEY_REQUIRE_CRED_BEFORE_STARTUP); |
| 904 | } |
| 905 | |
Fabrice Di Meglio | d1d2f02 | 2014-04-11 16:09:11 -0700 | [diff] [blame] | 906 | return keys; |
| 907 | } |
| 908 | } |
| 909 | |
Adrian Roos | 62775bf | 2016-01-28 13:23:53 -0800 | [diff] [blame] | 910 | public static class SecuritySubSettings extends SettingsPreferenceFragment |
| 911 | implements OnPreferenceChangeListener { |
| 912 | |
| 913 | private static final String KEY_VISIBLE_PATTERN = "visiblepattern"; |
| 914 | private static final String KEY_LOCK_AFTER_TIMEOUT = "lock_after_timeout"; |
| 915 | private static final String KEY_OWNER_INFO_SETTINGS = "owner_info_settings"; |
| 916 | private static final String KEY_POWER_INSTANTLY_LOCKS = "power_button_instantly_locks"; |
| 917 | private static final String KEY_REQUIRE_CRED_BEFORE_STARTUP = "require_cred_before_startup"; |
| 918 | |
| 919 | public static final int REQUEST_CHANGE_REQUIRE_CRED_FOR_START = 2; |
| 920 | |
| 921 | // These switch preferences need special handling since they're not all stored in Settings. |
| 922 | private static final String SWITCH_PREFERENCE_KEYS[] = { KEY_LOCK_AFTER_TIMEOUT, |
| 923 | KEY_VISIBLE_PATTERN, KEY_POWER_INSTANTLY_LOCKS, KEY_REQUIRE_CRED_BEFORE_STARTUP }; |
| 924 | |
| 925 | private RestrictedListPreference mLockAfter; |
| 926 | private SwitchPreference mVisiblePattern; |
| 927 | private SwitchPreference mPowerButtonInstantlyLocks; |
Sudheer Shanka | ec1052d | 2016-02-03 00:24:52 +0000 | [diff] [blame] | 928 | private RestrictedPreference mOwnerInfoPref; |
Adrian Roos | 62775bf | 2016-01-28 13:23:53 -0800 | [diff] [blame] | 929 | |
| 930 | private LockPatternUtils mLockPatternUtils; |
| 931 | private DevicePolicyManager mDPM; |
| 932 | |
| 933 | @Override |
| 934 | protected int getMetricsCategory() { |
| 935 | return MetricsEvent.SECURITY; |
| 936 | } |
| 937 | |
| 938 | @Override |
| 939 | public void onCreate(Bundle icicle) { |
| 940 | super.onCreate(icicle); |
| 941 | mLockPatternUtils = new LockPatternUtils(getContext()); |
| 942 | mDPM = getContext().getSystemService(DevicePolicyManager.class); |
| 943 | } |
| 944 | |
| 945 | @Override |
| 946 | public void onResume() { |
| 947 | super.onResume(); |
| 948 | |
| 949 | createPreferenceHierarchy(); |
| 950 | |
Adrian Roos | 62775bf | 2016-01-28 13:23:53 -0800 | [diff] [blame] | 951 | if (mVisiblePattern != null) { |
Clara Bayarri | 56462d6 | 2016-02-12 13:55:36 +0000 | [diff] [blame] | 952 | mVisiblePattern.setChecked(mLockPatternUtils.isVisiblePatternEnabled( |
Adrian Roos | 62775bf | 2016-01-28 13:23:53 -0800 | [diff] [blame] | 953 | MY_USER_ID)); |
| 954 | } |
| 955 | if (mPowerButtonInstantlyLocks != null) { |
Clara Bayarri | 56462d6 | 2016-02-12 13:55:36 +0000 | [diff] [blame] | 956 | mPowerButtonInstantlyLocks.setChecked(mLockPatternUtils.getPowerButtonInstantlyLocks( |
Adrian Roos | 62775bf | 2016-01-28 13:23:53 -0800 | [diff] [blame] | 957 | MY_USER_ID)); |
| 958 | } |
| 959 | |
| 960 | updateOwnerInfo(); |
| 961 | } |
| 962 | |
| 963 | @Override |
| 964 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 965 | super.onActivityResult(requestCode, resultCode, data); |
| 966 | |
| 967 | createPreferenceHierarchy(); |
| 968 | } |
| 969 | |
| 970 | private void createPreferenceHierarchy() { |
| 971 | PreferenceScreen root = getPreferenceScreen(); |
| 972 | if (root != null) { |
| 973 | root.removeAll(); |
| 974 | } |
| 975 | root = null; |
| 976 | |
| 977 | final int resid = getResIdForLockUnlockSubScreen(getActivity(), |
| 978 | new LockPatternUtils(getContext())); |
| 979 | addPreferencesFromResource(resid); |
| 980 | |
| 981 | // lock after preference |
| 982 | mLockAfter = (RestrictedListPreference) findPreference(KEY_LOCK_AFTER_TIMEOUT); |
| 983 | if (mLockAfter != null) { |
| 984 | setupLockAfterPreference(); |
| 985 | updateLockAfterPreferenceSummary(); |
| 986 | } |
| 987 | |
| 988 | // visible pattern |
| 989 | mVisiblePattern = (SwitchPreference) findPreference(KEY_VISIBLE_PATTERN); |
| 990 | |
| 991 | // lock instantly on power key press |
| 992 | mPowerButtonInstantlyLocks = (SwitchPreference) findPreference( |
| 993 | KEY_POWER_INSTANTLY_LOCKS); |
| 994 | Preference trustAgentPreference = findPreference(KEY_TRUST_AGENT); |
| 995 | if (mPowerButtonInstantlyLocks != null && |
| 996 | trustAgentPreference != null && |
| 997 | trustAgentPreference.getTitle().length() > 0) { |
| 998 | mPowerButtonInstantlyLocks.setSummary(getString( |
| 999 | R.string.lockpattern_settings_power_button_instantly_locks_summary, |
| 1000 | trustAgentPreference.getTitle())); |
| 1001 | } |
| 1002 | |
Sudheer Shanka | ec1052d | 2016-02-03 00:24:52 +0000 | [diff] [blame] | 1003 | mOwnerInfoPref = (RestrictedPreference) findPreference(KEY_OWNER_INFO_SETTINGS); |
Adrian Roos | 62775bf | 2016-01-28 13:23:53 -0800 | [diff] [blame] | 1004 | if (mOwnerInfoPref != null) { |
Sudheer Shanka | ec1052d | 2016-02-03 00:24:52 +0000 | [diff] [blame] | 1005 | if (mLockPatternUtils.isDeviceOwnerInfoEnabled()) { |
| 1006 | EnforcedAdmin admin = RestrictedLockUtils.getDeviceOwner(getActivity()); |
| 1007 | mOwnerInfoPref.setDisabledByAdmin(admin); |
| 1008 | } else { |
| 1009 | mOwnerInfoPref.setDisabledByAdmin(null); |
| 1010 | mOwnerInfoPref.setEnabled(!mLockPatternUtils.isLockScreenDisabled(MY_USER_ID)); |
| 1011 | if (mOwnerInfoPref.isEnabled()) { |
| 1012 | mOwnerInfoPref.setOnPreferenceClickListener( |
| 1013 | new OnPreferenceClickListener() { |
| 1014 | @Override |
| 1015 | public boolean onPreferenceClick(Preference preference) { |
| 1016 | OwnerInfoSettings.show(SecuritySubSettings.this); |
| 1017 | return true; |
| 1018 | } |
| 1019 | }); |
| 1020 | } |
Adrian Roos | 62775bf | 2016-01-28 13:23:53 -0800 | [diff] [blame] | 1021 | } |
| 1022 | } |
| 1023 | |
| 1024 | Preference requireCredForStartup = findPreference(KEY_REQUIRE_CRED_BEFORE_STARTUP); |
| 1025 | if (requireCredForStartup instanceof SwitchPreference) { |
| 1026 | ((SwitchPreference) requireCredForStartup).setChecked( |
| 1027 | mLockPatternUtils.isCredentialRequiredToDecrypt(false)); |
| 1028 | if (!canChangeRequireCredentialBeforeStartup(getContext())) { |
| 1029 | removePreference(KEY_REQUIRE_CRED_BEFORE_STARTUP); |
| 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | for (int i = 0; i < SWITCH_PREFERENCE_KEYS.length; i++) { |
| 1034 | final Preference pref = findPreference(SWITCH_PREFERENCE_KEYS[i]); |
| 1035 | if (pref != null) pref.setOnPreferenceChangeListener(this); |
| 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | static boolean canChangeRequireCredentialBeforeStartup(Context context) { |
| 1040 | DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class); |
| 1041 | return UserManager.get(context).isAdminUser() |
Adrian Roos | 77181e9 | 2016-02-25 15:43:24 -0800 | [diff] [blame] | 1042 | && UserManager.get(context).isPrimaryUser() |
Adrian Roos | 62775bf | 2016-01-28 13:23:53 -0800 | [diff] [blame] | 1043 | && LockPatternUtils.isDeviceEncryptionEnabled() |
| 1044 | && !dpm.getDoNotAskCredentialsOnBoot(); |
| 1045 | } |
| 1046 | |
| 1047 | private void setupLockAfterPreference() { |
| 1048 | // Compatible with pre-Froyo |
| 1049 | long currentTimeout = Settings.Secure.getLong(getContentResolver(), |
| 1050 | Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT, 5000); |
| 1051 | mLockAfter.setValue(String.valueOf(currentTimeout)); |
| 1052 | mLockAfter.setOnPreferenceChangeListener(this); |
| 1053 | final EnforcedAdmin admin = RestrictedLockUtils.checkIfMaximumTimeToLockIsSet( |
| 1054 | getActivity()); |
| 1055 | if (admin != null) { |
| 1056 | final long adminTimeout = (mDPM != null ? mDPM.getMaximumTimeToLock(null) : 0); |
| 1057 | final long displayTimeout = Math.max(0, |
| 1058 | Settings.System.getInt(getContentResolver(), SCREEN_OFF_TIMEOUT, 0)); |
| 1059 | if (adminTimeout > 0) { |
| 1060 | // This setting is a slave to display timeout when a device policy is enforced. |
| 1061 | // As such, maxLockTimeout = adminTimeout - displayTimeout. |
| 1062 | // If there isn't enough time, shows "immediately" setting. |
| 1063 | disableUnusableTimeouts(Math.max(0, adminTimeout - displayTimeout), admin); |
| 1064 | } |
| 1065 | } |
| 1066 | } |
| 1067 | |
| 1068 | private void updateLockAfterPreferenceSummary() { |
| 1069 | final String summary; |
| 1070 | if (mLockAfter.isDisabledByAdmin()) { |
| 1071 | summary = getString(R.string.disabled_by_policy_title); |
| 1072 | } else { |
| 1073 | // Update summary message with current value |
| 1074 | long currentTimeout = Settings.Secure.getLong(getContentResolver(), |
| 1075 | Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT, 5000); |
| 1076 | final CharSequence[] entries = mLockAfter.getEntries(); |
| 1077 | final CharSequence[] values = mLockAfter.getEntryValues(); |
| 1078 | int best = 0; |
| 1079 | for (int i = 0; i < values.length; i++) { |
| 1080 | if (mLockAfter.isRestrictedForEntry(entries[i])) { |
| 1081 | break; |
| 1082 | } |
| 1083 | long timeout = Long.valueOf(values[i].toString()); |
| 1084 | if (currentTimeout >= timeout) { |
| 1085 | best = i; |
| 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | Preference preference = findPreference(KEY_TRUST_AGENT); |
| 1090 | if (preference != null && preference.getTitle().length() > 0) { |
| 1091 | if (Long.valueOf(values[best].toString()) == 0) { |
| 1092 | summary = getString(R.string.lock_immediately_summary_with_exception, |
| 1093 | preference.getTitle()); |
| 1094 | } else { |
| 1095 | summary = getString(R.string.lock_after_timeout_summary_with_exception, |
| 1096 | entries[best], preference.getTitle()); |
| 1097 | } |
| 1098 | } else { |
| 1099 | summary = getString(R.string.lock_after_timeout_summary, entries[best]); |
| 1100 | } |
| 1101 | } |
| 1102 | mLockAfter.setSummary(summary); |
| 1103 | } |
| 1104 | |
| 1105 | private void disableUnusableTimeouts(long maxTimeout, EnforcedAdmin admin) { |
| 1106 | final CharSequence[] entries = mLockAfter.getEntries(); |
| 1107 | final CharSequence[] values = mLockAfter.getEntryValues(); |
| 1108 | long maxTimeoutSelectable = 0; |
| 1109 | int maxTimeoutEntryIndex = -1; |
| 1110 | for (int i = 0; i < values.length; i++) { |
| 1111 | long timeout = Long.parseLong(values[i].toString()); |
| 1112 | if (timeout > maxTimeout) { |
| 1113 | break; |
| 1114 | } |
| 1115 | maxTimeoutSelectable = timeout; |
| 1116 | maxTimeoutEntryIndex = i; |
| 1117 | } |
| 1118 | // If there are no possible options for the user, then set this preference as |
| 1119 | // disabled by admin, otherwise remove the padlock in case it was set earlier. |
| 1120 | if (maxTimeoutSelectable == 0) { |
| 1121 | mLockAfter.setDisabledByAdmin(admin); |
| 1122 | return; |
| 1123 | } else { |
| 1124 | mLockAfter.setDisabledByAdmin(null); |
| 1125 | } |
| 1126 | |
| 1127 | mLockAfter.clearRestrictedItems(); |
| 1128 | // Set all the entries after the maximum selectable timeout as disabled by admin. |
| 1129 | for (int i = maxTimeoutEntryIndex + 1; i < values.length; i++) { |
| 1130 | mLockAfter.addRestrictedItem( |
| 1131 | new RestrictedItem(entries[i], values[i], admin)); |
| 1132 | } |
| 1133 | |
| 1134 | final int userPreference = Integer.valueOf(mLockAfter.getValue()); |
| 1135 | if (userPreference <= maxTimeout) { |
| 1136 | mLockAfter.setValue(String.valueOf(userPreference)); |
| 1137 | } else if (maxTimeoutSelectable == maxTimeout) { |
| 1138 | mLockAfter.setValue(String.valueOf(maxTimeout)); |
| 1139 | } else { |
| 1140 | // There will be no highlighted selection since nothing in the list matches |
| 1141 | // maxTimeout. The user can still select anything less than maxTimeout. |
| 1142 | // TODO: maybe append maxTimeout to the list and mark selected. |
| 1143 | } |
| 1144 | } |
| 1145 | |
| 1146 | public void updateOwnerInfo() { |
| 1147 | if (mOwnerInfoPref != null) { |
| 1148 | if (mLockPatternUtils.isDeviceOwnerInfoEnabled()) { |
Sudheer Shanka | ec1052d | 2016-02-03 00:24:52 +0000 | [diff] [blame] | 1149 | mOwnerInfoPref.setSummary( |
| 1150 | mLockPatternUtils.getDeviceOwnerInfo()); |
Adrian Roos | 62775bf | 2016-01-28 13:23:53 -0800 | [diff] [blame] | 1151 | } else { |
| 1152 | mOwnerInfoPref.setSummary(mLockPatternUtils.isOwnerInfoEnabled(MY_USER_ID) |
| 1153 | ? mLockPatternUtils.getOwnerInfo(MY_USER_ID) |
| 1154 | : getString(R.string.owner_info_settings_summary)); |
| 1155 | } |
| 1156 | } |
| 1157 | } |
| 1158 | |
| 1159 | private static int getResIdForLockUnlockSubScreen(Context context, |
| 1160 | LockPatternUtils lockPatternUtils) { |
| 1161 | if (lockPatternUtils.isSecure(MY_USER_ID)) { |
| 1162 | switch (lockPatternUtils.getKeyguardStoredPasswordQuality(MY_USER_ID)) { |
| 1163 | case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING: |
| 1164 | return R.xml.security_settings_pattern_sub; |
| 1165 | case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC: |
| 1166 | case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX: |
| 1167 | return R.xml.security_settings_pin_sub; |
| 1168 | case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC: |
| 1169 | case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC: |
| 1170 | case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX: |
| 1171 | return R.xml.security_settings_password_sub; |
| 1172 | } |
| 1173 | } else if (!lockPatternUtils.isLockScreenDisabled(MY_USER_ID)) { |
| 1174 | return R.xml.security_settings_slide_sub; |
| 1175 | } |
| 1176 | return 0; |
| 1177 | } |
| 1178 | |
| 1179 | @Override |
| 1180 | public boolean onPreferenceChange(Preference preference, Object value) { |
| 1181 | String key = preference.getKey(); |
| 1182 | if (KEY_POWER_INSTANTLY_LOCKS.equals(key)) { |
| 1183 | mLockPatternUtils.setPowerButtonInstantlyLocks((Boolean) value, MY_USER_ID); |
| 1184 | } else if (KEY_LOCK_AFTER_TIMEOUT.equals(key)) { |
| 1185 | int timeout = Integer.parseInt((String) value); |
| 1186 | try { |
| 1187 | Settings.Secure.putInt(getContentResolver(), |
| 1188 | Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT, timeout); |
| 1189 | } catch (NumberFormatException e) { |
| 1190 | Log.e("SecuritySettings", "could not persist lockAfter timeout setting", e); |
| 1191 | } |
| 1192 | updateLockAfterPreferenceSummary(); |
| 1193 | } else if (KEY_VISIBLE_PATTERN.equals(key)) { |
| 1194 | mLockPatternUtils.setVisiblePatternEnabled((Boolean) value, MY_USER_ID); |
| 1195 | } else if (KEY_REQUIRE_CRED_BEFORE_STARTUP.equals(key)) { |
| 1196 | Bundle extras = new Bundle(); |
| 1197 | extras.putBoolean( |
| 1198 | ChooseLockSettingsHelper.EXTRA_KEY_FOR_CHANGE_CRED_REQUIRED_FOR_BOOT, true); |
| 1199 | startFragment(this, |
| 1200 | "com.android.settings.ChooseLockGeneric$ChooseLockGenericFragment", |
| 1201 | R.string.lock_settings_picker_title, REQUEST_CHANGE_REQUIRE_CRED_FOR_START, |
| 1202 | extras); |
| 1203 | return false; |
| 1204 | } |
| 1205 | return true; |
| 1206 | } |
| 1207 | } |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 1208 | |
| 1209 | public static class UnificationConfirmationDialog extends DialogFragment { |
Clara Bayarri | 56462d6 | 2016-02-12 13:55:36 +0000 | [diff] [blame] | 1210 | private static final String EXTRA_COMPLIANT = "compliant"; |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 1211 | |
Clara Bayarri | 56462d6 | 2016-02-12 13:55:36 +0000 | [diff] [blame] | 1212 | public static UnificationConfirmationDialog newIntance(boolean compliant) { |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 1213 | UnificationConfirmationDialog dialog = new UnificationConfirmationDialog(); |
Clara Bayarri | 56462d6 | 2016-02-12 13:55:36 +0000 | [diff] [blame] | 1214 | Bundle args = new Bundle(); |
| 1215 | args.putBoolean(EXTRA_COMPLIANT, compliant); |
| 1216 | dialog.setArguments(args); |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 1217 | return dialog; |
| 1218 | } |
| 1219 | |
| 1220 | @Override |
| 1221 | public void show(FragmentManager manager, String tag) { |
| 1222 | if (manager.findFragmentByTag(tag) == null) { |
| 1223 | // Prevent opening multiple dialogs if tapped on button quickly |
| 1224 | super.show(manager, tag); |
| 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | @Override |
| 1229 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 1230 | final SecuritySettings parentFragment = ((SecuritySettings) getParentFragment()); |
Clara Bayarri | 56462d6 | 2016-02-12 13:55:36 +0000 | [diff] [blame] | 1231 | final boolean compliant = getArguments().getBoolean(EXTRA_COMPLIANT); |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 1232 | return new AlertDialog.Builder(getActivity()) |
| 1233 | .setTitle(R.string.lock_settings_profile_unification_dialog_title) |
Clara Bayarri | 56462d6 | 2016-02-12 13:55:36 +0000 | [diff] [blame] | 1234 | .setMessage(compliant ? R.string.lock_settings_profile_unification_dialog_body |
| 1235 | : R.string.lock_settings_profile_unification_dialog_uncompliant_body) |
| 1236 | .setPositiveButton(compliant ? R.string.okay |
| 1237 | : R.string.lock_settings_profile_unification_dialog_uncompliant_confirm, |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 1238 | new DialogInterface.OnClickListener() { |
| 1239 | @Override |
| 1240 | public void onClick(DialogInterface dialog, int whichButton) { |
Clara Bayarri | 56462d6 | 2016-02-12 13:55:36 +0000 | [diff] [blame] | 1241 | if (compliant) { |
| 1242 | parentFragment.launchConfirmDeviceLockForUnification(); |
| 1243 | } else { |
| 1244 | parentFragment.unifyUncompliantLocks(); |
| 1245 | } |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 1246 | } |
| 1247 | } |
| 1248 | ) |
| 1249 | .setNegativeButton(R.string.cancel, |
| 1250 | new DialogInterface.OnClickListener() { |
| 1251 | @Override |
| 1252 | public void onClick(DialogInterface dialog, int whichButton) { |
Clara Bayarri | 56462d6 | 2016-02-12 13:55:36 +0000 | [diff] [blame] | 1253 | parentFragment.updateUnificationPreference(); |
Clara Bayarri | 52681ec | 2016-01-28 11:11:35 +0000 | [diff] [blame] | 1254 | dismiss(); |
| 1255 | } |
| 1256 | } |
| 1257 | ) |
| 1258 | .create(); |
| 1259 | } |
| 1260 | } |
| 1261 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 1262 | } |