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