blob: 6e679b6e72037de7f84f47a3c0aa1829e408ee77 [file] [log] [blame]
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001/*
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
17package com.android.settings;
18
19
Danielle Millett487b16f2011-11-02 11:12:21 -040020import android.app.Activity;
Gilles Debunne2c88a872011-06-21 12:47:17 -070021import android.app.AlertDialog;
Dianne Hackborn4037c7f2010-02-26 17:26:55 -080022import android.app.admin.DevicePolicyManager;
Ido Ofir524a63b2014-06-12 14:18:23 -070023import android.content.ComponentName;
Dianne Hackbornabc3dc62010-01-20 13:40:19 -080024import android.content.Context;
Gilles Debunne2c88a872011-06-21 12:47:17 -070025import android.content.DialogInterface;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080026import android.content.Intent;
rich canningsbfbdcef2012-09-09 12:48:50 -070027import android.content.pm.PackageManager;
28import android.content.pm.ResolveInfo;
Fabrice Di Megliod1d2f022014-04-11 16:09:11 -070029import android.content.res.Resources;
Jason Monk3bcd76c2015-04-21 11:20:20 -040030import android.hardware.fingerprint.Fingerprint;
31import android.hardware.fingerprint.FingerprintManager;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080032import android.os.Bundle;
Junda Liu80753bc2015-06-17 10:15:34 -070033import android.os.PersistableBundle;
Dianne Hackbornbb06a422012-08-16 11:01:57 -070034import android.os.UserHandle;
Jim Miller783ea852012-11-01 19:39:21 -070035import android.os.UserManager;
Jim Miller86624a22010-08-30 22:07:58 -070036import android.preference.ListPreference;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080037import android.preference.Preference;
Mathew Inwoodf8b25792010-10-21 18:43:35 +010038import android.preference.Preference.OnPreferenceChangeListener;
Jason Monk3bcd76c2015-04-21 11:20:20 -040039import android.preference.Preference.OnPreferenceClickListener;
Mathew Inwoodf8b25792010-10-21 18:43:35 +010040import android.preference.PreferenceGroup;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080041import android.preference.PreferenceScreen;
Jason Monk3bcd76c2015-04-21 11:20:20 -040042import android.preference.SwitchPreference;
Fabrice Di Megliod1d2f022014-04-11 16:09:11 -070043import android.provider.SearchIndexableResource;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080044import android.provider.Settings;
Chia-chi Yeh9cec6982009-09-22 23:59:01 +080045import android.security.KeyStore;
Ido Ofir6f482442014-05-09 14:47:15 -070046import android.service.trust.TrustAgentService;
Junda Liu80753bc2015-06-17 10:15:34 -070047import android.telephony.CarrierConfigManager;
Wink Savilleca756612014-11-08 10:47:12 -080048import android.telephony.SubscriptionInfo;
Jason Monk3bcd76c2015-04-21 11:20:20 -040049import android.telephony.SubscriptionManager;
50import android.telephony.TelephonyManager;
Ido Ofir524a63b2014-06-12 14:18:23 -070051import android.text.TextUtils;
Jim Miller86624a22010-08-30 22:07:58 -070052import android.util.Log;
Amith Yamasanif06d8692009-06-11 22:32:33 -070053
Chris Wren8a963ba2015-03-20 10:29:14 -040054import com.android.internal.logging.MetricsLogger;
Gilles Debunnea6a8a142011-06-09 11:56:17 -070055import com.android.internal.widget.LockPatternUtils;
Jim Millerfe765592014-07-31 15:30:29 -070056import com.android.settings.TrustAgentUtils.TrustAgentComponentInfo;
Selim Cinekec850042015-06-11 18:59:54 -070057import com.android.settings.fingerprint.FingerprintEnrollIntroduction;
Jorim Jaggi5ad75f02015-04-22 16:17:23 -070058import com.android.settings.fingerprint.FingerprintSettings;
Fabrice Di Megliod1d2f022014-04-11 16:09:11 -070059import com.android.settings.search.BaseSearchIndexProvider;
Jim Millerfe765592014-07-31 15:30:29 -070060import com.android.settings.search.Index;
Fabrice Di Megliod1d2f022014-04-11 16:09:11 -070061import com.android.settings.search.Indexable;
62import com.android.settings.search.SearchIndexableRaw;
Gilles Debunnea6a8a142011-06-09 11:56:17 -070063
Jim Miller86624a22010-08-30 22:07:58 -070064import java.util.ArrayList;
rich canningsbfbdcef2012-09-09 12:48:50 -070065import java.util.List;
Mike Lockwood5ed2c4a2009-06-07 23:07:20 -040066
Selim Cinekec850042015-06-11 18:59:54 -070067import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
68
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080069/**
70 * Gesture lock pattern settings.
71 */
Julia Reynolds565653c2014-06-12 11:49:12 -040072public class SecuritySettings extends SettingsPreferenceFragment
Fabrice Di Megliod1d2f022014-04-11 16:09:11 -070073 implements OnPreferenceChangeListener, DialogInterface.OnClickListener, Indexable {
Jim Miller92186872015-03-04 18:07:32 -080074
75 private static final String TAG = "SecuritySettings";
Jim Miller250b9be2014-09-05 18:48:18 -070076 private static final String TRUST_AGENT_CLICK_INTENT = "trust_agent_click_intent";
Ido Ofir6f482442014-05-09 14:47:15 -070077 private static final Intent TRUST_AGENT_INTENT =
78 new Intent(TrustAgentService.SERVICE_INTERFACE);
Jason parks6f8fb432011-01-07 09:02:14 -060079
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080080 // Lock Settings
Chia-chi Yeh91d65a22011-01-20 18:46:01 +080081 private static final String KEY_UNLOCK_SET_OR_CHANGE = "unlock_set_or_change";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080082 private static final String KEY_VISIBLE_PATTERN = "visiblepattern";
Amith Yamasaniedac9af2010-11-17 09:08:21 -080083 private static final String KEY_SECURITY_CATEGORY = "security_category";
rich canningsf0421142012-09-25 16:20:36 -070084 private static final String KEY_DEVICE_ADMIN_CATEGORY = "device_admin_category";
Chia-chi Yeh91d65a22011-01-20 18:46:01 +080085 private static final String KEY_LOCK_AFTER_TIMEOUT = "lock_after_timeout";
Amith Yamasani8666b9e2012-09-27 14:50:13 -070086 private static final String KEY_OWNER_INFO_SETTINGS = "owner_info_settings";
Jim Millerfe765592014-07-31 15:30:29 -070087 private static final String KEY_ADVANCED_SECURITY = "advanced_security";
88 private static final String KEY_MANAGE_TRUST_AGENTS = "manage_trust_agents";
Jim Miller92186872015-03-04 18:07:32 -080089 private static final String KEY_FINGERPRINT_SETTINGS = "fingerprint_settings";
Jim Milleref3e7012013-08-20 19:03:30 -070090
Chia-chi Yeh91d65a22011-01-20 18:46:01 +080091 private static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST = 123;
Ido Ofir6f482442014-05-09 14:47:15 -070092 private static final int CHANGE_TRUST_AGENT_SETTINGS = 126;
Hung-ying Tyan7031ab02009-07-02 00:26:46 +080093
Chia-chi Yeh91d65a22011-01-20 18:46:01 +080094 // Misc Settings
95 private static final String KEY_SIM_LOCK = "sim_lock";
96 private static final String KEY_SHOW_PASSWORD = "show_password";
Kenny Root028634b2013-03-29 11:12:55 -070097 private static final String KEY_CREDENTIAL_STORAGE_TYPE = "credential_storage_type";
Julia Reynolds233ccd02014-06-23 09:43:09 -040098 private static final String KEY_RESET_CREDENTIALS = "credentials_reset";
Geoffrey Borggaard6e1102d2013-08-07 14:57:43 -040099 private static final String KEY_CREDENTIALS_INSTALL = "credentials_install";
Gilles Debunne2c88a872011-06-21 12:47:17 -0700100 private static final String KEY_TOGGLE_INSTALL_APPLICATIONS = "toggle_install_applications";
Jim Miller071742d2012-01-06 18:28:09 -0800101 private static final String KEY_POWER_INSTANTLY_LOCKS = "power_button_instantly_locks";
Amith Yamasani7fb4f852012-09-25 22:17:33 -0700102 private static final String KEY_CREDENTIALS_MANAGER = "credentials_management";
rich canningsbfbdcef2012-09-09 12:48:50 -0700103 private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive";
Ido Ofir6f482442014-05-09 14:47:15 -0700104 private static final String KEY_TRUST_AGENT = "trust_agent";
Jason Monk27d7ea52014-07-18 09:55:41 -0400105 private static final String KEY_SCREEN_PINNING = "screen_pinning_settings";
Jim Miller47d380f2010-01-20 13:37:14 -0800106
Jim Miller4a9065e2014-08-08 15:25:31 -0700107 // These switch preferences need special handling since they're not all stored in Settings.
108 private static final String SWITCH_PREFERENCE_KEYS[] = { KEY_LOCK_AFTER_TIMEOUT,
Adrian Roos6b879f52015-01-08 16:20:00 +0100109 KEY_VISIBLE_PATTERN, KEY_POWER_INSTANTLY_LOCKS, KEY_SHOW_PASSWORD,
110 KEY_TOGGLE_INSTALL_APPLICATIONS };
Jim Miller4a9065e2014-08-08 15:25:31 -0700111
Jim Millerfe765592014-07-31 15:30:29 -0700112 // Only allow one trust agent on the platform.
113 private static final boolean ONLY_ONE_TRUST_AGENT = true;
114
Adrian Roos54375882015-04-16 17:11:22 -0700115 private static final int MY_USER_ID = UserHandle.myUserId();
116
Maggie Benthallf48206e2013-08-20 11:03:05 -0400117 private DevicePolicyManager mDPM;
Wink Saville0183fb52014-11-22 10:11:39 -0800118 private SubscriptionManager mSubscriptionManager;
Jim Miller122b6c82010-02-10 19:53:58 -0800119
Jim Miller00d24762009-12-22 19:04:57 -0800120 private ChooseLockSettingsHelper mChooseLockSettingsHelper;
Jim Miller122b6c82010-02-10 19:53:58 -0800121 private LockPatternUtils mLockPatternUtils;
Jim Miller86624a22010-08-30 22:07:58 -0700122 private ListPreference mLockAfter;
Jim Miller36972bb2010-11-30 19:47:38 -0800123
Jim Miller4a9065e2014-08-08 15:25:31 -0700124 private SwitchPreference mVisiblePattern;
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800125
Jim Miller4a9065e2014-08-08 15:25:31 -0700126 private SwitchPreference mShowPassword;
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800127
Kenny Root028634b2013-03-29 11:12:55 -0700128 private KeyStore mKeyStore;
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800129 private Preference mResetCredentials;
Mike Lockwood5ed2c4a2009-06-07 23:07:20 -0400130
Jim Miller4a9065e2014-08-08 15:25:31 -0700131 private SwitchPreference mToggleAppInstallation;
Gilles Debunne2c88a872011-06-21 12:47:17 -0700132 private DialogInterface mWarnInstallApps;
Jim Miller4a9065e2014-08-08 15:25:31 -0700133 private SwitchPreference mPowerButtonInstantlyLocks;
Gilles Debunne2c88a872011-06-21 12:47:17 -0700134
Amith Yamasani7fb4f852012-09-25 22:17:33 -0700135 private boolean mIsPrimary;
136
Jim Miller250b9be2014-09-05 18:48:18 -0700137 private Intent mTrustAgentClickIntent;
Jason Monk3bcd76c2015-04-21 11:20:20 -0400138 private Preference mOwnerInfoPref;
Ido Ofir1682a0d2014-06-24 16:26:09 -0700139
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800140 @Override
Chris Wren8a963ba2015-03-20 10:29:14 -0400141 protected int getMetricsCategory() {
142 return MetricsLogger.SECURITY;
143 }
144
145 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700146 public void onCreate(Bundle savedInstanceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800147 super.onCreate(savedInstanceState);
Jim Miller122b6c82010-02-10 19:53:58 -0800148
Wink Saville0183fb52014-11-22 10:11:39 -0800149 mSubscriptionManager = SubscriptionManager.from(getActivity());
150
Amith Yamasanid7993472010-08-18 13:59:28 -0700151 mLockPatternUtils = new LockPatternUtils(getActivity());
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800152
Dianne Hackbornabc3dc62010-01-20 13:40:19 -0800153 mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
Jim Miller122b6c82010-02-10 19:53:58 -0800154
Amith Yamasanid7993472010-08-18 13:59:28 -0700155 mChooseLockSettingsHelper = new ChooseLockSettingsHelper(getActivity());
Jim Miller250b9be2014-09-05 18:48:18 -0700156
157 if (savedInstanceState != null
158 && savedInstanceState.containsKey(TRUST_AGENT_CLICK_INTENT)) {
159 mTrustAgentClickIntent = savedInstanceState.getParcelable(TRUST_AGENT_CLICK_INTENT);
160 }
Amith Yamasani02cf71a2010-09-21 15:48:52 -0700161 }
Mike Lockwood5ed2c4a2009-06-07 23:07:20 -0400162
Fabrice Di Megliod1d2f022014-04-11 16:09:11 -0700163 private static int getResIdForLockUnlockScreen(Context context,
164 LockPatternUtils lockPatternUtils) {
Jim Miller36972bb2010-11-30 19:47:38 -0800165 int resid = 0;
Adrian Roos54375882015-04-16 17:11:22 -0700166 if (!lockPatternUtils.isSecure(MY_USER_ID)) {
167 if (lockPatternUtils.isLockScreenDisabled(MY_USER_ID)) {
Jim Miller36972bb2010-11-30 19:47:38 -0800168 resid = R.xml.security_settings_lockscreen;
169 } else {
170 resid = R.xml.security_settings_chooser;
171 }
Jim Miller122b6c82010-02-10 19:53:58 -0800172 } else {
Adrian Roos54375882015-04-16 17:11:22 -0700173 switch (lockPatternUtils.getKeyguardStoredPasswordQuality(MY_USER_ID)) {
Jim Milleraf366a32010-03-25 18:45:22 -0700174 case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
Jim Miller36972bb2010-11-30 19:47:38 -0800175 resid = R.xml.security_settings_pattern;
Jim Milleraf366a32010-03-25 18:45:22 -0700176 break;
177 case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
Nicolas Prevot8fd852e2014-01-25 01:02:04 +0000178 case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX:
Jim Miller36972bb2010-11-30 19:47:38 -0800179 resid = R.xml.security_settings_pin;
Jim Milleraf366a32010-03-25 18:45:22 -0700180 break;
181 case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
182 case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
Konstantin Lopyrev57fbf692010-05-27 16:01:41 -0700183 case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
Jim Miller36972bb2010-11-30 19:47:38 -0800184 resid = R.xml.security_settings_password;
Jim Milleraf366a32010-03-25 18:45:22 -0700185 break;
Jim Miller00d24762009-12-22 19:04:57 -0800186 }
Jim Miller122b6c82010-02-10 19:53:58 -0800187 }
Fabrice Di Megliod1d2f022014-04-11 16:09:11 -0700188 return resid;
189 }
Jim Miller122b6c82010-02-10 19:53:58 -0800190
Fabrice Di Megliod1d2f022014-04-11 16:09:11 -0700191 /**
192 * Important!
193 *
Ido Ofir6f482442014-05-09 14:47:15 -0700194 * Don't forget to update the SecuritySearchIndexProvider if you are doing any change in the
Fabrice Di Megliod1d2f022014-04-11 16:09:11 -0700195 * logic or adding/removing preferences here.
196 */
197 private PreferenceScreen createPreferenceHierarchy() {
198 PreferenceScreen root = getPreferenceScreen();
199 if (root != null) {
200 root.removeAll();
201 }
202 addPreferencesFromResource(R.xml.security_settings);
203 root = getPreferenceScreen();
204
205 // Add options for lock/unlock screen
206 final int resid = getResIdForLockUnlockScreen(getActivity(), mLockPatternUtils);
207 addPreferencesFromResource(resid);
Jason parks41121992011-01-25 09:26:55 -0600208
209 // Add options for device encryption
Adrian Roos54375882015-04-16 17:11:22 -0700210 mIsPrimary = MY_USER_ID == UserHandle.USER_OWNER;
Amith Yamasani7fb4f852012-09-25 22:17:33 -0700211
Jason Monk3bcd76c2015-04-21 11:20:20 -0400212 mOwnerInfoPref = findPreference(KEY_OWNER_INFO_SETTINGS);
213 if (mOwnerInfoPref != null) {
214 mOwnerInfoPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
215 @Override
216 public boolean onPreferenceClick(Preference preference) {
217 OwnerInfoSettings.show(SecuritySettings.this);
218 return true;
Amith Yamasanib0171712013-04-28 22:13:22 -0700219 }
Jason Monk3bcd76c2015-04-21 11:20:20 -0400220 });
Amith Yamasani8666b9e2012-09-27 14:50:13 -0700221 }
222
Amith Yamasani7fb4f852012-09-25 22:17:33 -0700223 if (mIsPrimary) {
Jim Miller0698a212014-10-16 19:49:07 -0700224 if (LockPatternUtils.isDeviceEncryptionEnabled()) {
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700225 // The device is currently encrypted.
226 addPreferencesFromResource(R.xml.security_settings_encrypted);
Jim Miller0698a212014-10-16 19:49:07 -0700227 } else {
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700228 // This device supports encryption but isn't encrypted.
229 addPreferencesFromResource(R.xml.security_settings_unencrypted);
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700230 }
Jason parks41121992011-01-25 09:26:55 -0600231 }
232
Jim Miller94d4bd92015-02-19 21:04:57 -0800233 // Fingerprint and trust agents
Ido Ofir1682a0d2014-06-24 16:26:09 -0700234 PreferenceGroup securityCategory = (PreferenceGroup)
235 root.findPreference(KEY_SECURITY_CATEGORY);
Jim Miller9d250052014-08-21 19:24:47 -0700236 if (securityCategory != null) {
Jim Miller94d4bd92015-02-19 21:04:57 -0800237 maybeAddFingerprintPreference(securityCategory);
238 addTrustAgentSettings(securityCategory);
Ido Ofir1682a0d2014-06-24 16:26:09 -0700239 }
240
Jim Miller86624a22010-08-30 22:07:58 -0700241 // lock after preference
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800242 mLockAfter = (ListPreference) root.findPreference(KEY_LOCK_AFTER_TIMEOUT);
243 if (mLockAfter != null) {
244 setupLockAfterPreference();
245 updateLockAfterPreferenceSummary();
246 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800247
248 // visible pattern
Jim Miller4a9065e2014-08-08 15:25:31 -0700249 mVisiblePattern = (SwitchPreference) root.findPreference(KEY_VISIBLE_PATTERN);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800250
Jim Miller071742d2012-01-06 18:28:09 -0800251 // lock instantly on power key press
Jim Miller4a9065e2014-08-08 15:25:31 -0700252 mPowerButtonInstantlyLocks = (SwitchPreference) root.findPreference(
Jim Miller071742d2012-01-06 18:28:09 -0800253 KEY_POWER_INSTANTLY_LOCKS);
Ido Ofir1682a0d2014-06-24 16:26:09 -0700254 Preference trustAgentPreference = root.findPreference(KEY_TRUST_AGENT);
255 if (mPowerButtonInstantlyLocks != null &&
256 trustAgentPreference != null &&
257 trustAgentPreference.getTitle().length() > 0) {
258 mPowerButtonInstantlyLocks.setSummary(getString(
259 R.string.lockpattern_settings_power_button_instantly_locks_summary,
260 trustAgentPreference.getTitle()));
261 }
Jim Miller071742d2012-01-06 18:28:09 -0800262
Amith Yamasani7fb4f852012-09-25 22:17:33 -0700263 // Append the rest of the settings
264 addPreferencesFromResource(R.xml.security_settings_misc);
265
266 // Do not display SIM lock for devices without an Icc card
267 TelephonyManager tm = TelephonyManager.getDefault();
Junda Liu80753bc2015-06-17 10:15:34 -0700268 CarrierConfigManager cfgMgr = (CarrierConfigManager)
269 getActivity().getSystemService(Context.CARRIER_CONFIG_SERVICE);
270 PersistableBundle b = cfgMgr.getConfig();
271 if (!mIsPrimary || !isSimIccReady() ||
272 b.getBoolean(CarrierConfigManager.KEY_HIDE_SIM_LOCK_SETTINGS_BOOL)) {
Amith Yamasani7fb4f852012-09-25 22:17:33 -0700273 root.removePreference(root.findPreference(KEY_SIM_LOCK));
274 } else {
PauloftheWest50e6eca2014-10-03 11:07:14 -0700275 // Disable SIM lock if there is no ready SIM card.
276 root.findPreference(KEY_SIM_LOCK).setEnabled(isSimReady());
Amith Yamasani7fb4f852012-09-25 22:17:33 -0700277 }
Jason Monkb08853a2014-08-13 09:43:58 -0400278 if (Settings.System.getInt(getContentResolver(),
279 Settings.System.LOCK_TO_APP_ENABLED, 0) != 0) {
280 root.findPreference(KEY_SCREEN_PINNING).setSummary(
281 getResources().getString(R.string.switch_on_text));
Jason Monk27d7ea52014-07-18 09:55:41 -0400282 }
Amith Yamasani7fb4f852012-09-25 22:17:33 -0700283
284 // Show password
Jim Miller4a9065e2014-08-08 15:25:31 -0700285 mShowPassword = (SwitchPreference) root.findPreference(KEY_SHOW_PASSWORD);
Geoffrey Borggaard6e1102d2013-08-07 14:57:43 -0400286 mResetCredentials = root.findPreference(KEY_RESET_CREDENTIALS);
Amith Yamasani7fb4f852012-09-25 22:17:33 -0700287
Kenny Rootc5550c22013-04-08 09:56:05 -0700288 // Credential storage
Emily Bernier11bd33a2013-04-11 16:24:56 -0400289 final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
Maggie Benthallf48206e2013-08-20 11:03:05 -0400290 mKeyStore = KeyStore.getInstance(); // needs to be initialized for onResume()
Emily Bernier11bd33a2013-04-11 16:24:56 -0400291 if (!um.hasUserRestriction(UserManager.DISALLOW_CONFIG_CREDENTIALS)) {
Emily Bernier11bd33a2013-04-11 16:24:56 -0400292 Preference credentialStorageType = root.findPreference(KEY_CREDENTIAL_STORAGE_TYPE);
Kenny Root028634b2013-03-29 11:12:55 -0700293
Emily Bernier11bd33a2013-04-11 16:24:56 -0400294 final int storageSummaryRes =
Kenny Rootc5550c22013-04-08 09:56:05 -0700295 mKeyStore.isHardwareBacked() ? R.string.credential_storage_type_hardware
296 : R.string.credential_storage_type_software;
Emily Bernier11bd33a2013-04-11 16:24:56 -0400297 credentialStorageType.setSummary(storageSummaryRes);
Emily Bernier11bd33a2013-04-11 16:24:56 -0400298 } else {
Julia Reynolds233ccd02014-06-23 09:43:09 -0400299 PreferenceGroup credentialsManager = (PreferenceGroup)
300 root.findPreference(KEY_CREDENTIALS_MANAGER);
301 credentialsManager.removePreference(root.findPreference(KEY_RESET_CREDENTIALS));
302 credentialsManager.removePreference(root.findPreference(KEY_CREDENTIALS_INSTALL));
303 credentialsManager.removePreference(root.findPreference(KEY_CREDENTIAL_STORAGE_TYPE));
Emily Bernier11bd33a2013-04-11 16:24:56 -0400304 }
Amith Yamasani7fb4f852012-09-25 22:17:33 -0700305
Kenny Rootc5550c22013-04-08 09:56:05 -0700306 // Application install
Ido Ofir6f482442014-05-09 14:47:15 -0700307 PreferenceGroup deviceAdminCategory = (PreferenceGroup)
Maggie Benthall0c5a4012013-03-14 17:41:27 -0400308 root.findPreference(KEY_DEVICE_ADMIN_CATEGORY);
Jim Miller4a9065e2014-08-08 15:25:31 -0700309 mToggleAppInstallation = (SwitchPreference) findPreference(
Amith Yamasani7fb4f852012-09-25 22:17:33 -0700310 KEY_TOGGLE_INSTALL_APPLICATIONS);
311 mToggleAppInstallation.setChecked(isNonMarketAppsAllowed());
Maggie Benthall0c5a4012013-03-14 17:41:27 -0400312 // Side loading of apps.
Amith Yamasaniceceb2a2014-11-11 15:36:15 -0800313 // Disable for restricted profiles. For others, check if policy disallows it.
Adrian Roos54375882015-04-16 17:11:22 -0700314 mToggleAppInstallation.setEnabled(!um.getUserInfo(MY_USER_ID).isRestricted());
Julia Reynolds565653c2014-06-12 11:49:12 -0400315 if (um.hasUserRestriction(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES)
316 || um.hasUserRestriction(UserManager.DISALLOW_INSTALL_APPS)) {
317 mToggleAppInstallation.setEnabled(false);
318 }
Maggie Benthall0c5a4012013-03-14 17:41:27 -0400319
Jim Millerfe765592014-07-31 15:30:29 -0700320 // Advanced Security features
321 PreferenceGroup advancedCategory =
322 (PreferenceGroup)root.findPreference(KEY_ADVANCED_SECURITY);
Jim Miller9d250052014-08-21 19:24:47 -0700323 if (advancedCategory != null) {
Jim Millerfe765592014-07-31 15:30:29 -0700324 Preference manageAgents = advancedCategory.findPreference(KEY_MANAGE_TRUST_AGENTS);
Adrian Roos54375882015-04-16 17:11:22 -0700325 if (manageAgents != null && !mLockPatternUtils.isSecure(MY_USER_ID)) {
Jim Miller9d250052014-08-21 19:24:47 -0700326 manageAgents.setEnabled(false);
327 manageAgents.setSummary(R.string.disabled_because_no_backup_security);
328 }
Jim Millerfe765592014-07-31 15:30:29 -0700329 }
330
331 // The above preferences come and go based on security state, so we need to update
332 // the index. This call is expected to be fairly cheap, but we may want to do something
333 // smarter in the future.
334 Index.getInstance(getActivity())
335 .updateFromClassNameResource(SecuritySettings.class.getName(), true, true);
336
Jim Miller4a9065e2014-08-08 15:25:31 -0700337 for (int i = 0; i < SWITCH_PREFERENCE_KEYS.length; i++) {
338 final Preference pref = findPreference(SWITCH_PREFERENCE_KEYS[i]);
339 if (pref != null) pref.setOnPreferenceChangeListener(this);
340 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800341 return root;
342 }
343
Jim Miller94d4bd92015-02-19 21:04:57 -0800344 private void maybeAddFingerprintPreference(PreferenceGroup securityCategory) {
345 FingerprintManager fpm = (FingerprintManager) getActivity().getSystemService(
346 Context.FINGERPRINT_SERVICE);
347 if (!fpm.isHardwareDetected()) {
348 Log.v(TAG, "No fingerprint hardware detected!!");
349 return;
350 }
351 Preference fingerprintPreference = new Preference(securityCategory.getContext());
Jim Miller92186872015-03-04 18:07:32 -0800352 fingerprintPreference.setKey(KEY_FINGERPRINT_SETTINGS);
Jim Miller94d4bd92015-02-19 21:04:57 -0800353 fingerprintPreference.setTitle(R.string.security_settings_fingerprint_preference_title);
354 Intent intent = new Intent();
Jim Millerd16c9b72015-03-24 16:02:59 -0700355 final List<Fingerprint> items = fpm.getEnrolledFingerprints();
356 final int fingerprintCount = items != null ? items.size() : 0;
Jim Miller92186872015-03-04 18:07:32 -0800357 final String clazz;
Jim Miller94d4bd92015-02-19 21:04:57 -0800358 if (fingerprintCount > 0) {
359 fingerprintPreference.setSummary(getResources().getQuantityString(
360 R.plurals.security_settings_fingerprint_preference_summary,
361 fingerprintCount, fingerprintCount));
Jim Miller92186872015-03-04 18:07:32 -0800362 clazz = FingerprintSettings.class.getName();
Jim Miller94d4bd92015-02-19 21:04:57 -0800363 } else {
Selim Cinekec850042015-06-11 18:59:54 -0700364 clazz = FingerprintEnrollIntroduction.class.getName();
Jim Miller94d4bd92015-02-19 21:04:57 -0800365 }
Jim Miller92186872015-03-04 18:07:32 -0800366 intent.setClassName("com.android.settings", clazz);
Jim Miller94d4bd92015-02-19 21:04:57 -0800367 fingerprintPreference.setIntent(intent);
368 securityCategory.addPreference(fingerprintPreference);
369 }
370
371 private void addTrustAgentSettings(PreferenceGroup securityCategory) {
Adrian Roos54375882015-04-16 17:11:22 -0700372 final boolean hasSecurity = mLockPatternUtils.isSecure(MY_USER_ID);
Jim Miller94d4bd92015-02-19 21:04:57 -0800373 ArrayList<TrustAgentComponentInfo> agents =
Adrian Roos088de472015-04-07 14:09:39 +0200374 getActiveTrustAgents(getPackageManager(), mLockPatternUtils, mDPM);
Jim Miller94d4bd92015-02-19 21:04:57 -0800375 for (int i = 0; i < agents.size(); i++) {
376 final TrustAgentComponentInfo agent = agents.get(i);
377 Preference trustAgentPreference =
378 new Preference(securityCategory.getContext());
379 trustAgentPreference.setKey(KEY_TRUST_AGENT);
380 trustAgentPreference.setTitle(agent.title);
381 trustAgentPreference.setSummary(agent.summary);
382 // Create intent for this preference.
383 Intent intent = new Intent();
384 intent.setComponent(agent.componentName);
385 intent.setAction(Intent.ACTION_MAIN);
386 trustAgentPreference.setIntent(intent);
387 // Add preference to the settings menu.
388 securityCategory.addPreference(trustAgentPreference);
Adrian Roos088de472015-04-07 14:09:39 +0200389
390 if (agent.disabledByAdministrator) {
391 trustAgentPreference.setEnabled(false);
392 trustAgentPreference.setSummary(R.string.trust_agent_disabled_device_admin);
393 } else if (!hasSecurity) {
Jim Miller94d4bd92015-02-19 21:04:57 -0800394 trustAgentPreference.setEnabled(false);
395 trustAgentPreference.setSummary(R.string.disabled_because_no_backup_security);
396 }
397 }
398 }
399
PauloftheWest0b8788a2014-12-08 13:49:35 -0800400 /* Return true if a there is a Slot that has Icc.
401 */
402 private boolean isSimIccReady() {
403 TelephonyManager tm = TelephonyManager.getDefault();
404 final List<SubscriptionInfo> subInfoList =
405 mSubscriptionManager.getActiveSubscriptionInfoList();
406
407 if (subInfoList != null) {
408 for (SubscriptionInfo subInfo : subInfoList) {
Sanket Padawe24784202015-01-14 14:48:27 -0800409 if (tm.hasIccCard(subInfo.getSimSlotIndex())) {
PauloftheWest0b8788a2014-12-08 13:49:35 -0800410 return true;
411 }
412 }
413 }
414
415 return false;
416 }
417
PauloftheWest50e6eca2014-10-03 11:07:14 -0700418 /* Return true if a SIM is ready for locking.
419 * TODO: consider adding to TelephonyManager or SubscritpionManasger.
420 */
Wink Saville0183fb52014-11-22 10:11:39 -0800421 private boolean isSimReady() {
PauloftheWest50e6eca2014-10-03 11:07:14 -0700422 int simState = TelephonyManager.SIM_STATE_UNKNOWN;
Wink Saville0183fb52014-11-22 10:11:39 -0800423 final List<SubscriptionInfo> subInfoList =
424 mSubscriptionManager.getActiveSubscriptionInfoList();
PauloftheWest50e6eca2014-10-03 11:07:14 -0700425 if (subInfoList != null) {
Wink Savilleca756612014-11-08 10:47:12 -0800426 for (SubscriptionInfo subInfo : subInfoList) {
Stuart Scott3ada2ec2014-10-31 14:11:24 -0700427 simState = TelephonyManager.getDefault().getSimState(subInfo.getSimSlotIndex());
PauloftheWest50e6eca2014-10-03 11:07:14 -0700428 if((simState != TelephonyManager.SIM_STATE_ABSENT) &&
429 (simState != TelephonyManager.SIM_STATE_UNKNOWN)){
430 return true;
431 }
432 }
433 }
434 return false;
435 }
436
Jim Millerfe765592014-07-31 15:30:29 -0700437 private static ArrayList<TrustAgentComponentInfo> getActiveTrustAgents(
Adrian Roos088de472015-04-07 14:09:39 +0200438 PackageManager pm, LockPatternUtils utils, DevicePolicyManager dpm) {
Jim Millerfe765592014-07-31 15:30:29 -0700439 ArrayList<TrustAgentComponentInfo> result = new ArrayList<TrustAgentComponentInfo>();
440 List<ResolveInfo> resolveInfos = pm.queryIntentServices(TRUST_AGENT_INTENT,
441 PackageManager.GET_META_DATA);
Adrian Roos54375882015-04-16 17:11:22 -0700442 List<ComponentName> enabledTrustAgents = utils.getEnabledTrustAgents(MY_USER_ID);
Adrian Roos088de472015-04-07 14:09:39 +0200443
444 boolean disableTrustAgents = (dpm.getKeyguardDisabledFeatures(null)
445 & DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS) != 0;
446
Jim Millerfe765592014-07-31 15:30:29 -0700447 if (enabledTrustAgents != null && !enabledTrustAgents.isEmpty()) {
448 for (int i = 0; i < resolveInfos.size(); i++) {
449 ResolveInfo resolveInfo = resolveInfos.get(i);
450 if (resolveInfo.serviceInfo == null) continue;
451 if (!TrustAgentUtils.checkProvidePermission(resolveInfo, pm)) continue;
452 TrustAgentComponentInfo trustAgentComponentInfo =
453 TrustAgentUtils.getSettingsComponent(pm, resolveInfo);
454 if (trustAgentComponentInfo.componentName == null ||
455 !enabledTrustAgents.contains(
456 TrustAgentUtils.getComponentName(resolveInfo)) ||
457 TextUtils.isEmpty(trustAgentComponentInfo.title)) continue;
Adrian Roos088de472015-04-07 14:09:39 +0200458 if (disableTrustAgents && dpm.getTrustAgentConfiguration(
459 null, TrustAgentUtils.getComponentName(resolveInfo)) == null) {
460 trustAgentComponentInfo.disabledByAdministrator = true;
461 }
Jim Millerfe765592014-07-31 15:30:29 -0700462 result.add(trustAgentComponentInfo);
463 if (ONLY_ONE_TRUST_AGENT) break;
464 }
465 }
466 return result;
467 }
468
Gilles Debunne2c88a872011-06-21 12:47:17 -0700469 private boolean isNonMarketAppsAllowed() {
Christopher Tate5a64c732012-09-07 13:35:31 -0700470 return Settings.Global.getInt(getContentResolver(),
471 Settings.Global.INSTALL_NON_MARKET_APPS, 0) > 0;
Gilles Debunne2c88a872011-06-21 12:47:17 -0700472 }
473
474 private void setNonMarketAppsAllowed(boolean enabled) {
Maggie Benthall0c5a4012013-03-14 17:41:27 -0400475 final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
476 if (um.hasUserRestriction(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES)) {
477 return;
478 }
Gilles Debunne2c88a872011-06-21 12:47:17 -0700479 // Change the system setting
Christopher Tate5a64c732012-09-07 13:35:31 -0700480 Settings.Global.putInt(getContentResolver(), Settings.Global.INSTALL_NON_MARKET_APPS,
Gilles Debunne2c88a872011-06-21 12:47:17 -0700481 enabled ? 1 : 0);
482 }
483
484 private void warnAppInstallation() {
485 // TODO: DialogFragment?
486 mWarnInstallApps = new AlertDialog.Builder(getActivity()).setTitle(
487 getResources().getString(R.string.error_title))
488 .setIcon(com.android.internal.R.drawable.ic_dialog_alert)
489 .setMessage(getResources().getString(R.string.install_all_warning))
490 .setPositiveButton(android.R.string.yes, this)
arete17224822014-08-14 13:45:36 -0700491 .setNegativeButton(android.R.string.no, this)
Gilles Debunne2c88a872011-06-21 12:47:17 -0700492 .show();
493 }
494
Maggie Benthall0c5a4012013-03-14 17:41:27 -0400495 @Override
Gilles Debunne2c88a872011-06-21 12:47:17 -0700496 public void onClick(DialogInterface dialog, int which) {
arete17224822014-08-14 13:45:36 -0700497 if (dialog == mWarnInstallApps) {
498 boolean turnOn = which == DialogInterface.BUTTON_POSITIVE;
499 setNonMarketAppsAllowed(turnOn);
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700500 if (mToggleAppInstallation != null) {
arete17224822014-08-14 13:45:36 -0700501 mToggleAppInstallation.setChecked(turnOn);
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700502 }
Gilles Debunne2c88a872011-06-21 12:47:17 -0700503 }
504 }
505
506 @Override
507 public void onDestroy() {
508 super.onDestroy();
509 if (mWarnInstallApps != null) {
510 mWarnInstallApps.dismiss();
511 }
512 }
513
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800514 private void setupLockAfterPreference() {
515 // Compatible with pre-Froyo
516 long currentTimeout = Settings.Secure.getLong(getContentResolver(),
517 Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT, 5000);
518 mLockAfter.setValue(String.valueOf(currentTimeout));
519 mLockAfter.setOnPreferenceChangeListener(this);
520 final long adminTimeout = (mDPM != null ? mDPM.getMaximumTimeToLock(null) : 0);
521 final long displayTimeout = Math.max(0,
522 Settings.System.getInt(getContentResolver(), SCREEN_OFF_TIMEOUT, 0));
523 if (adminTimeout > 0) {
524 // This setting is a slave to display timeout when a device policy is enforced.
525 // As such, maxLockTimeout = adminTimeout - displayTimeout.
526 // If there isn't enough time, shows "immediately" setting.
527 disableUnusableTimeouts(Math.max(0, adminTimeout - displayTimeout));
Jim Miller86624a22010-08-30 22:07:58 -0700528 }
Jim Miller86624a22010-08-30 22:07:58 -0700529 }
530
Jim Millerc9787072011-01-09 18:00:28 -0800531 private void updateLockAfterPreferenceSummary() {
Jim Millerc9787072011-01-09 18:00:28 -0800532 // Update summary message with current value
533 long currentTimeout = Settings.Secure.getLong(getContentResolver(),
Amith Yamasani58bca8f2011-07-22 12:16:16 -0700534 Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT, 5000);
Jim Millerc9787072011-01-09 18:00:28 -0800535 final CharSequence[] entries = mLockAfter.getEntries();
536 final CharSequence[] values = mLockAfter.getEntryValues();
537 int best = 0;
538 for (int i = 0; i < values.length; i++) {
539 long timeout = Long.valueOf(values[i].toString());
540 if (currentTimeout >= timeout) {
541 best = i;
542 }
543 }
Ido Ofir1682a0d2014-06-24 16:26:09 -0700544
545 Preference preference = getPreferenceScreen().findPreference(KEY_TRUST_AGENT);
546 if (preference != null && preference.getTitle().length() > 0) {
Jim Miller50d7d192015-06-16 16:21:27 -0700547 if (Long.valueOf(values[best].toString()) == 0) {
548 mLockAfter.setSummary(getString(R.string.lock_immediately_summary_with_exception,
549 preference.getTitle()));
550 } else {
551 mLockAfter.setSummary(getString(R.string.lock_after_timeout_summary_with_exception,
552 entries[best], preference.getTitle()));
553 }
Ido Ofir1682a0d2014-06-24 16:26:09 -0700554 } else {
555 mLockAfter.setSummary(getString(R.string.lock_after_timeout_summary, entries[best]));
556 }
Jim Millerc9787072011-01-09 18:00:28 -0800557 }
558
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800559 private void disableUnusableTimeouts(long maxTimeout) {
560 final CharSequence[] entries = mLockAfter.getEntries();
561 final CharSequence[] values = mLockAfter.getEntryValues();
Jim Miller86624a22010-08-30 22:07:58 -0700562 ArrayList<CharSequence> revisedEntries = new ArrayList<CharSequence>();
563 ArrayList<CharSequence> revisedValues = new ArrayList<CharSequence>();
564 for (int i = 0; i < values.length; i++) {
565 long timeout = Long.valueOf(values[i].toString());
566 if (timeout <= maxTimeout) {
567 revisedEntries.add(entries[i]);
568 revisedValues.add(values[i]);
569 }
570 }
571 if (revisedEntries.size() != entries.length || revisedValues.size() != values.length) {
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800572 mLockAfter.setEntries(
Jim Miller86624a22010-08-30 22:07:58 -0700573 revisedEntries.toArray(new CharSequence[revisedEntries.size()]));
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800574 mLockAfter.setEntryValues(
Jim Miller86624a22010-08-30 22:07:58 -0700575 revisedValues.toArray(new CharSequence[revisedValues.size()]));
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800576 final int userPreference = Integer.valueOf(mLockAfter.getValue());
Jim Miller86624a22010-08-30 22:07:58 -0700577 if (userPreference <= maxTimeout) {
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800578 mLockAfter.setValue(String.valueOf(userPreference));
Jim Miller86624a22010-08-30 22:07:58 -0700579 } else {
580 // There will be no highlighted selection since nothing in the list matches
581 // maxTimeout. The user can still select anything less than maxTimeout.
582 // TODO: maybe append maxTimeout to the list and mark selected.
583 }
584 }
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800585 mLockAfter.setEnabled(revisedEntries.size() > 0);
Jim Miller86624a22010-08-30 22:07:58 -0700586 }
587
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800588 @Override
Jim Miller250b9be2014-09-05 18:48:18 -0700589 public void onSaveInstanceState(Bundle outState) {
590 super.onSaveInstanceState(outState);
591 if (mTrustAgentClickIntent != null) {
592 outState.putParcelable(TRUST_AGENT_CLICK_INTENT, mTrustAgentClickIntent);
593 }
594 }
595
596 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700597 public void onResume() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800598 super.onResume();
599
Jim Miller86624a22010-08-30 22:07:58 -0700600 // Make sure we reload the preference hierarchy since some of these settings
601 // depend on others...
602 createPreferenceHierarchy();
603
Jim Miller00d24762009-12-22 19:04:57 -0800604 final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();
Jim Miller122b6c82010-02-10 19:53:58 -0800605 if (mVisiblePattern != null) {
Adrian Roos54375882015-04-16 17:11:22 -0700606 mVisiblePattern.setChecked(lockPatternUtils.isVisiblePatternEnabled(
607 MY_USER_ID));
Jim Miller122b6c82010-02-10 19:53:58 -0800608 }
Jim Miller071742d2012-01-06 18:28:09 -0800609 if (mPowerButtonInstantlyLocks != null) {
Adrian Roos54375882015-04-16 17:11:22 -0700610 mPowerButtonInstantlyLocks.setChecked(lockPatternUtils.getPowerButtonInstantlyLocks(
611 MY_USER_ID));
Jim Miller071742d2012-01-06 18:28:09 -0800612 }
Hung-ying Tyan7031ab02009-07-02 00:26:46 +0800613
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700614 if (mShowPassword != null) {
615 mShowPassword.setChecked(Settings.System.getInt(getContentResolver(),
616 Settings.System.TEXT_SHOW_PASSWORD, 1) != 0);
617 }
Hung-ying Tyanb0883cb2009-09-30 11:56:05 +0800618
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700619 if (mResetCredentials != null) {
Kenny Rootc4372c32013-04-22 13:41:18 -0700620 mResetCredentials.setEnabled(!mKeyStore.isEmpty());
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700621 }
Jason Monk3bcd76c2015-04-21 11:20:20 -0400622
623 updateOwnerInfo();
624 }
625
626 public void updateOwnerInfo() {
627 if (mOwnerInfoPref != null) {
Adrian Roos54375882015-04-16 17:11:22 -0700628 mOwnerInfoPref.setSummary(mLockPatternUtils.isOwnerInfoEnabled(MY_USER_ID)
629 ? mLockPatternUtils.getOwnerInfo(MY_USER_ID)
Jason Monk3bcd76c2015-04-21 11:20:20 -0400630 : getString(R.string.owner_info_settings_summary));
631 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800632 }
633
634 @Override
Gilles Debunnea6a8a142011-06-09 11:56:17 -0700635 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800636 final String key = preference.getKey();
Jim Millerbbb4afa2010-04-08 19:40:19 -0700637 if (KEY_UNLOCK_SET_OR_CHANGE.equals(key)) {
Jim Miller17e9e192010-12-07 20:41:41 -0800638 startFragment(this, "com.android.settings.ChooseLockGeneric$ChooseLockGenericFragment",
Fabrice Di Meglio5bdf0422014-07-01 15:15:18 -0700639 R.string.lock_settings_picker_title, SET_OR_CHANGE_LOCK_METHOD_REQUEST, null);
Ido Ofir6f482442014-05-09 14:47:15 -0700640 } else if (KEY_TRUST_AGENT.equals(key)) {
641 ChooseLockSettingsHelper helper =
642 new ChooseLockSettingsHelper(this.getActivity(), this);
Jim Miller250b9be2014-09-05 18:48:18 -0700643 mTrustAgentClickIntent = preference.getIntent();
Jorim Jaggi8a09b612015-04-06 17:47:18 -0700644 boolean confirmationLaunched = helper.launchConfirmationActivity(
645 CHANGE_TRUST_AGENT_SETTINGS, preference.getTitle());
646 if (!confirmationLaunched&& mTrustAgentClickIntent != null) {
Ido Ofir6f482442014-05-09 14:47:15 -0700647 // If this returns false, it means no password confirmation is required.
Jim Miller250b9be2014-09-05 18:48:18 -0700648 startActivity(mTrustAgentClickIntent);
649 mTrustAgentClickIntent = null;
Ido Ofir6f482442014-05-09 14:47:15 -0700650 }
Jim Miller36972bb2010-11-30 19:47:38 -0800651 } else {
652 // If we didn't handle it, let preferences handle it.
653 return super.onPreferenceTreeClick(preferenceScreen, preference);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800654 }
Jim Miller36972bb2010-11-30 19:47:38 -0800655 return true;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800656 }
657
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800658 /**
Gilles Debunnea6a8a142011-06-09 11:56:17 -0700659 * see confirmPatternThenDisableAndClear
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800660 */
661 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700662 public void onActivityResult(int requestCode, int resultCode, Intent data) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800663 super.onActivityResult(requestCode, resultCode, data);
Adrian Roosf7887182015-01-07 20:51:57 +0100664 if (requestCode == CHANGE_TRUST_AGENT_SETTINGS && resultCode == Activity.RESULT_OK) {
Jim Miller250b9be2014-09-05 18:48:18 -0700665 if (mTrustAgentClickIntent != null) {
666 startActivity(mTrustAgentClickIntent);
667 mTrustAgentClickIntent = null;
Ido Ofir6f482442014-05-09 14:47:15 -0700668 }
Jim Miller250b9be2014-09-05 18:48:18 -0700669 return;
Danielle Millett487b16f2011-11-02 11:12:21 -0400670 }
Jim Miller122b6c82010-02-10 19:53:58 -0800671 createPreferenceHierarchy();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800672 }
Amith Yamasanif06d8692009-06-11 22:32:33 -0700673
Maggie Benthall0c5a4012013-03-14 17:41:27 -0400674 @Override
Jim Miller86624a22010-08-30 22:07:58 -0700675 public boolean onPreferenceChange(Preference preference, Object value) {
arete300e9202014-08-15 12:04:48 -0700676 boolean result = true;
Jim Miller4a9065e2014-08-08 15:25:31 -0700677 final String key = preference.getKey();
678 final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();
679 if (KEY_LOCK_AFTER_TIMEOUT.equals(key)) {
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800680 int timeout = Integer.parseInt((String) value);
Jim Miller86624a22010-08-30 22:07:58 -0700681 try {
682 Settings.Secure.putInt(getContentResolver(),
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800683 Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT, timeout);
Jim Miller86624a22010-08-30 22:07:58 -0700684 } catch (NumberFormatException e) {
685 Log.e("SecuritySettings", "could not persist lockAfter timeout setting", e);
686 }
Jim Millerc9787072011-01-09 18:00:28 -0800687 updateLockAfterPreferenceSummary();
Jim Miller4a9065e2014-08-08 15:25:31 -0700688 } else if (KEY_VISIBLE_PATTERN.equals(key)) {
Adrian Roos54375882015-04-16 17:11:22 -0700689 lockPatternUtils.setVisiblePatternEnabled((Boolean) value, MY_USER_ID);
Jim Miller4a9065e2014-08-08 15:25:31 -0700690 } else if (KEY_POWER_INSTANTLY_LOCKS.equals(key)) {
Adrian Roos54375882015-04-16 17:11:22 -0700691 mLockPatternUtils.setPowerButtonInstantlyLocks((Boolean) value, MY_USER_ID);
Jim Miller4a9065e2014-08-08 15:25:31 -0700692 } else if (KEY_SHOW_PASSWORD.equals(key)) {
693 Settings.System.putInt(getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD,
694 ((Boolean) value) ? 1 : 0);
Paul Lawrencec04420c2015-05-18 13:25:01 -0700695 lockPatternUtils.setVisiblePasswordEnabled((Boolean) value, MY_USER_ID);
Jim Miller4a9065e2014-08-08 15:25:31 -0700696 } else if (KEY_TOGGLE_INSTALL_APPLICATIONS.equals(key)) {
697 if ((Boolean) value) {
698 mToggleAppInstallation.setChecked(false);
699 warnAppInstallation();
arete300e9202014-08-15 12:04:48 -0700700 // Don't change Switch status until user makes choice in dialog, so return false.
701 result = false;
Jim Miller4a9065e2014-08-08 15:25:31 -0700702 } else {
703 setNonMarketAppsAllowed(false);
704 }
Jim Miller86624a22010-08-30 22:07:58 -0700705 }
arete300e9202014-08-15 12:04:48 -0700706 return result;
Jim Miller86624a22010-08-30 22:07:58 -0700707 }
Danielle Millett487b16f2011-11-02 11:12:21 -0400708
rich cannings93c0ee52012-09-30 13:54:26 -0700709 @Override
710 protected int getHelpResource() {
711 return R.string.help_url_security;
712 }
713
Fabrice Di Megliod1d2f022014-04-11 16:09:11 -0700714 /**
715 * For Search. Please keep it in sync when updating "createPreferenceHierarchy()"
716 */
717 public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
718 new SecuritySearchIndexProvider();
719
Jim Millerfe765592014-07-31 15:30:29 -0700720 private static class SecuritySearchIndexProvider extends BaseSearchIndexProvider {
Fabrice Di Megliod1d2f022014-04-11 16:09:11 -0700721
722 boolean mIsPrimary;
723
724 public SecuritySearchIndexProvider() {
725 super();
726
Adrian Roos54375882015-04-16 17:11:22 -0700727 mIsPrimary = MY_USER_ID == UserHandle.USER_OWNER;
Fabrice Di Megliod1d2f022014-04-11 16:09:11 -0700728 }
729
730 @Override
731 public List<SearchIndexableResource> getXmlResourcesToIndex(
732 Context context, boolean enabled) {
733
734 List<SearchIndexableResource> result = new ArrayList<SearchIndexableResource>();
735
736 LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
737 // Add options for lock/unlock screen
738 int resId = getResIdForLockUnlockScreen(context, lockPatternUtils);
739
740 SearchIndexableResource sir = new SearchIndexableResource(context);
741 sir.xmlResId = resId;
742 result.add(sir);
743
744 if (mIsPrimary) {
745 DevicePolicyManager dpm = (DevicePolicyManager)
746 context.getSystemService(Context.DEVICE_POLICY_SERVICE);
747
748 switch (dpm.getStorageEncryptionStatus()) {
749 case DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE:
750 // The device is currently encrypted.
751 resId = R.xml.security_settings_encrypted;
752 break;
753 case DevicePolicyManager.ENCRYPTION_STATUS_INACTIVE:
754 // This device supports encryption but isn't encrypted.
755 resId = R.xml.security_settings_unencrypted;
756 break;
757 }
758
759 sir = new SearchIndexableResource(context);
760 sir.xmlResId = resId;
761 result.add(sir);
762 }
763
764 // Append the rest of the settings
765 sir = new SearchIndexableResource(context);
766 sir.xmlResId = R.xml.security_settings_misc;
767 result.add(sir);
768
769 return result;
770 }
771
772 @Override
773 public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) {
774 final List<SearchIndexableRaw> result = new ArrayList<SearchIndexableRaw>();
775 final Resources res = context.getResources();
776
777 final String screenTitle = res.getString(R.string.security_settings_title);
778
Fabrice Di Megliod7290292014-07-01 14:32:03 -0700779 SearchIndexableRaw data = new SearchIndexableRaw(context);
780 data.title = screenTitle;
781 data.screenTitle = screenTitle;
782 result.add(data);
Fabrice Di Megliod1d2f022014-04-11 16:09:11 -0700783
784 if (!mIsPrimary) {
785 int resId = (UserManager.get(context).isLinkedUser()) ?
786 R.string.profile_info_settings_title : R.string.user_info_settings_title;
787
788 data = new SearchIndexableRaw(context);
789 data.title = res.getString(resId);
790 data.screenTitle = screenTitle;
791 result.add(data);
792 }
793
Julia Reynoldsf516e7d2015-07-16 15:33:22 -0400794 // Fingerprint
795 FingerprintManager fpm =
796 (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
797 if (fpm.isHardwareDetected()) {
798 data = new SearchIndexableRaw(context);
799 data.title = res.getString(R.string.security_settings_fingerprint_preference_title);
800 data.screenTitle = screenTitle;
801 result.add(data);
802 }
803
Fabrice Di Megliod1d2f022014-04-11 16:09:11 -0700804 // Credential storage
805 final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
806
807 if (!um.hasUserRestriction(UserManager.DISALLOW_CONFIG_CREDENTIALS)) {
808 KeyStore keyStore = KeyStore.getInstance();
809
810 final int storageSummaryRes = keyStore.isHardwareBacked() ?
811 R.string.credential_storage_type_hardware :
812 R.string.credential_storage_type_software;
813
814 data = new SearchIndexableRaw(context);
815 data.title = res.getString(storageSummaryRes);
816 data.screenTitle = screenTitle;
817 result.add(data);
818 }
819
Jim Millerfe765592014-07-31 15:30:29 -0700820 // Advanced
821 final LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
Adrian Roos54375882015-04-16 17:11:22 -0700822 if (lockPatternUtils.isSecure(MY_USER_ID)) {
Jim Millerfe765592014-07-31 15:30:29 -0700823 ArrayList<TrustAgentComponentInfo> agents =
Adrian Roos088de472015-04-07 14:09:39 +0200824 getActiveTrustAgents(context.getPackageManager(), lockPatternUtils,
825 context.getSystemService(DevicePolicyManager.class));
Jim Millerfe765592014-07-31 15:30:29 -0700826 for (int i = 0; i < agents.size(); i++) {
827 final TrustAgentComponentInfo agent = agents.get(i);
828 data = new SearchIndexableRaw(context);
829 data.title = agent.title;
830 data.screenTitle = screenTitle;
831 result.add(data);
832 }
833 }
Fabrice Di Megliod1d2f022014-04-11 16:09:11 -0700834 return result;
835 }
836
837 @Override
838 public List<String> getNonIndexableKeys(Context context) {
839 final List<String> keys = new ArrayList<String>();
840
841 LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
842 // Add options for lock/unlock screen
843 int resId = getResIdForLockUnlockScreen(context, lockPatternUtils);
844
Fabrice Di Megliod1d2f022014-04-11 16:09:11 -0700845 // Do not display SIM lock for devices without an Icc card
846 TelephonyManager tm = TelephonyManager.getDefault();
847 if (!mIsPrimary || !tm.hasIccCard()) {
848 keys.add(KEY_SIM_LOCK);
849 }
850
Fabrice Di Megliod1d2f022014-04-11 16:09:11 -0700851 final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
852 if (um.hasUserRestriction(UserManager.DISALLOW_CONFIG_CREDENTIALS)) {
853 keys.add(KEY_CREDENTIALS_MANAGER);
854 }
855
Jim Millerfe765592014-07-31 15:30:29 -0700856 // TrustAgent settings disappear when the user has no primary security.
Adrian Roos54375882015-04-16 17:11:22 -0700857 if (!lockPatternUtils.isSecure(MY_USER_ID)) {
Jim Millerfe765592014-07-31 15:30:29 -0700858 keys.add(KEY_TRUST_AGENT);
859 keys.add(KEY_MANAGE_TRUST_AGENTS);
860 }
861
Fabrice Di Megliod1d2f022014-04-11 16:09:11 -0700862 return keys;
863 }
864 }
865
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800866}