blob: 2af212cf2589ae82c701bea18130fe4a4d6875db [file] [log] [blame]
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.settings;
18
19
Jim Miller86624a22010-08-30 22:07:58 -070020import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
21
Danielle Millett487b16f2011-11-02 11:12:21 -040022import android.app.Activity;
Gilles Debunne2c88a872011-06-21 12:47:17 -070023import android.app.AlertDialog;
Dianne Hackborn4037c7f2010-02-26 17:26:55 -080024import android.app.admin.DevicePolicyManager;
Michael Jurka8227e302012-09-07 09:24:03 -070025import android.appwidget.AppWidgetHost;
26import android.appwidget.AppWidgetManager;
27import android.appwidget.AppWidgetProviderInfo;
28import android.content.ActivityNotFoundException;
29import android.content.ComponentName;
Dianne Hackbornabc3dc62010-01-20 13:40:19 -080030import android.content.Context;
Gilles Debunne2c88a872011-06-21 12:47:17 -070031import android.content.DialogInterface;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080032import android.content.Intent;
rich canningsbfbdcef2012-09-09 12:48:50 -070033import android.content.pm.PackageManager;
34import android.content.pm.ResolveInfo;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080035import android.os.Bundle;
Dianne Hackbornbb06a422012-08-16 11:01:57 -070036import android.os.UserHandle;
Amith Yamasaniedac9af2010-11-17 09:08:21 -080037import android.os.Vibrator;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080038import android.preference.CheckBoxPreference;
Jim Miller86624a22010-08-30 22:07:58 -070039import android.preference.ListPreference;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080040import android.preference.Preference;
Mathew Inwoodf8b25792010-10-21 18:43:35 +010041import android.preference.Preference.OnPreferenceChangeListener;
Mathew Inwoodf8b25792010-10-21 18:43:35 +010042import android.preference.PreferenceGroup;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080043import android.preference.PreferenceScreen;
44import android.provider.Settings;
Chia-chi Yeh9cec6982009-09-22 23:59:01 +080045import android.security.KeyStore;
Oscar Montemayor56e15262009-11-30 10:39:07 -080046import android.telephony.TelephonyManager;
Jim Miller86624a22010-08-30 22:07:58 -070047import android.util.Log;
Michael Jurka8227e302012-09-07 09:24:03 -070048import android.widget.Toast;
Amith Yamasanif06d8692009-06-11 22:32:33 -070049
Gilles Debunnea6a8a142011-06-09 11:56:17 -070050import com.android.internal.widget.LockPatternUtils;
51
Jim Miller86624a22010-08-30 22:07:58 -070052import java.util.ArrayList;
rich canningsbfbdcef2012-09-09 12:48:50 -070053import java.util.List;
Mike Lockwood5ed2c4a2009-06-07 23:07:20 -040054
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080055/**
56 * Gesture lock pattern settings.
57 */
Jim Miller36972bb2010-11-30 19:47:38 -080058public class SecuritySettings extends SettingsPreferenceFragment
Gilles Debunne2c88a872011-06-21 12:47:17 -070059 implements OnPreferenceChangeListener, DialogInterface.OnClickListener {
Michael Jurka8227e302012-09-07 09:24:03 -070060 static final String TAG = "SecuritySettings";
Jason parks6f8fb432011-01-07 09:02:14 -060061
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080062 // Lock Settings
Chia-chi Yeh91d65a22011-01-20 18:46:01 +080063 private static final String KEY_UNLOCK_SET_OR_CHANGE = "unlock_set_or_change";
Michael Jurka091477b2012-09-20 19:03:35 -070064 private static final String KEY_CHOOSE_LOCKSCREEN_STATUS_WIDGET =
65 "choose_lockscreen_status_widget";
Michael Jurka8227e302012-09-07 09:24:03 -070066 private static final String KEY_CHOOSE_USER_SELECTED_LOCKSCREEN_WIDGET =
67 "choose_user_selected_lockscreen_widget";
Danielle Millett487b16f2011-11-02 11:12:21 -040068 private static final String KEY_BIOMETRIC_WEAK_IMPROVE_MATCHING =
69 "biometric_weak_improve_matching";
Danielle Milletta87a25b2012-03-19 18:05:26 -040070 private static final String KEY_BIOMETRIC_WEAK_LIVELINESS = "biometric_weak_liveliness";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080071 private static final String KEY_LOCK_ENABLED = "lockenabled";
72 private static final String KEY_VISIBLE_PATTERN = "visiblepattern";
Jim Miller9e61b9f2010-02-18 19:56:04 -080073 private static final String KEY_TACTILE_FEEDBACK_ENABLED = "unlock_tactile_feedback";
Amith Yamasaniedac9af2010-11-17 09:08:21 -080074 private static final String KEY_SECURITY_CATEGORY = "security_category";
Chia-chi Yeh91d65a22011-01-20 18:46:01 +080075 private static final String KEY_LOCK_AFTER_TIMEOUT = "lock_after_timeout";
Michael Jurka8227e302012-09-07 09:24:03 -070076 private static final String EXTRA_NO_WIDGET = "com.android.settings.NO_WIDGET";
Michael Jurka091477b2012-09-20 19:03:35 -070077 private static final String EXTRA_DEFAULT_WIDGET = "com.android.settings.DEFAULT_WIDGET";
Chia-chi Yeh91d65a22011-01-20 18:46:01 +080078 private static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST = 123;
Danielle Millett790e0c32012-03-23 15:17:50 -040079 private static final int CONFIRM_EXISTING_FOR_BIOMETRIC_WEAK_IMPROVE_REQUEST = 124;
Danielle Millett4a3e40d2012-06-06 13:54:11 -040080 private static final int CONFIRM_EXISTING_FOR_BIOMETRIC_WEAK_LIVELINESS_OFF = 125;
Michael Jurka091477b2012-09-20 19:03:35 -070081 private static final int REQUEST_PICK_USER_SELECTED_APPWIDGET = 126;
82 private static final int REQUEST_PICK_STATUS_APPWIDGET = 127;
83 private static final int REQUEST_CREATE_USER_SELECTED_APPWIDGET = 128;
84 private static final int REQUEST_CREATE_STATUS_APPWIDGET = 129;
Hung-ying Tyan7031ab02009-07-02 00:26:46 +080085
Chia-chi Yeh91d65a22011-01-20 18:46:01 +080086 // Misc Settings
87 private static final String KEY_SIM_LOCK = "sim_lock";
88 private static final String KEY_SHOW_PASSWORD = "show_password";
Chia-chi Yeh91d65a22011-01-20 18:46:01 +080089 private static final String KEY_RESET_CREDENTIALS = "reset_credentials";
Gilles Debunne2c88a872011-06-21 12:47:17 -070090 private static final String KEY_TOGGLE_INSTALL_APPLICATIONS = "toggle_install_applications";
rich canningsd5d60652012-09-07 13:20:44 -070091 private static final String KEY_TOGGLE_VERIFY_APPLICATIONS = "toggle_verify_applications";
Jim Miller071742d2012-01-06 18:28:09 -080092 private static final String KEY_POWER_INSTANTLY_LOCKS = "power_button_instantly_locks";
Amith Yamasani7fb4f852012-09-25 22:17:33 -070093 private static final String KEY_CREDENTIALS_MANAGER = "credentials_management";
rich canningsbfbdcef2012-09-09 12:48:50 -070094 private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive";
Jim Miller47d380f2010-01-20 13:37:14 -080095
Dianne Hackbornabc3dc62010-01-20 13:40:19 -080096 DevicePolicyManager mDPM;
Jim Miller122b6c82010-02-10 19:53:58 -080097
Jim Miller00d24762009-12-22 19:04:57 -080098 private ChooseLockSettingsHelper mChooseLockSettingsHelper;
Michael Jurka8227e302012-09-07 09:24:03 -070099 private Preference mUserSelectedWidget;
Jim Miller122b6c82010-02-10 19:53:58 -0800100 private LockPatternUtils mLockPatternUtils;
Jim Miller86624a22010-08-30 22:07:58 -0700101 private ListPreference mLockAfter;
Jim Miller36972bb2010-11-30 19:47:38 -0800102
Danielle Millett4a3e40d2012-06-06 13:54:11 -0400103 private CheckBoxPreference mBiometricWeakLiveliness;
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800104 private CheckBoxPreference mVisiblePattern;
105 private CheckBoxPreference mTactileFeedback;
106
107 private CheckBoxPreference mShowPassword;
108
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800109 private Preference mResetCredentials;
Mike Lockwood5ed2c4a2009-06-07 23:07:20 -0400110
Gilles Debunne2c88a872011-06-21 12:47:17 -0700111 private CheckBoxPreference mToggleAppInstallation;
112 private DialogInterface mWarnInstallApps;
rich canningsd5d60652012-09-07 13:20:44 -0700113 private CheckBoxPreference mToggleVerifyApps;
Jim Miller071742d2012-01-06 18:28:09 -0800114 private CheckBoxPreference mPowerButtonInstantlyLocks;
Gilles Debunne2c88a872011-06-21 12:47:17 -0700115
Amith Yamasani7fb4f852012-09-25 22:17:33 -0700116 private boolean mIsPrimary;
117
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800118 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700119 public void onCreate(Bundle savedInstanceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800120 super.onCreate(savedInstanceState);
Jim Miller122b6c82010-02-10 19:53:58 -0800121
Amith Yamasanid7993472010-08-18 13:59:28 -0700122 mLockPatternUtils = new LockPatternUtils(getActivity());
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800123
Dianne Hackbornabc3dc62010-01-20 13:40:19 -0800124 mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
Jim Miller122b6c82010-02-10 19:53:58 -0800125
Amith Yamasanid7993472010-08-18 13:59:28 -0700126 mChooseLockSettingsHelper = new ChooseLockSettingsHelper(getActivity());
Amith Yamasani02cf71a2010-09-21 15:48:52 -0700127 }
Mike Lockwood5ed2c4a2009-06-07 23:07:20 -0400128
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800129 private PreferenceScreen createPreferenceHierarchy() {
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800130 PreferenceScreen root = getPreferenceScreen();
Jim Miller122b6c82010-02-10 19:53:58 -0800131 if (root != null) {
132 root.removeAll();
133 }
134 addPreferencesFromResource(R.xml.security_settings);
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800135 root = getPreferenceScreen();
Jim Miller122b6c82010-02-10 19:53:58 -0800136
Jim Miller36972bb2010-11-30 19:47:38 -0800137 // Add options for lock/unlock screen
138 int resid = 0;
Jim Miller122b6c82010-02-10 19:53:58 -0800139 if (!mLockPatternUtils.isSecure()) {
Jim Miller36972bb2010-11-30 19:47:38 -0800140 if (mLockPatternUtils.isLockScreenDisabled()) {
141 resid = R.xml.security_settings_lockscreen;
142 } else {
143 resid = R.xml.security_settings_chooser;
144 }
Danielle Millett0fb158a2011-09-30 13:49:14 -0400145 } else if (mLockPatternUtils.usingBiometricWeak() &&
146 mLockPatternUtils.isBiometricWeakInstalled()) {
Jim Miller5541a862011-09-02 17:33:53 -0700147 resid = R.xml.security_settings_biometric_weak;
Jim Miller122b6c82010-02-10 19:53:58 -0800148 } else {
Jim Milleraf366a32010-03-25 18:45:22 -0700149 switch (mLockPatternUtils.getKeyguardStoredPasswordQuality()) {
150 case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
Jim Miller36972bb2010-11-30 19:47:38 -0800151 resid = R.xml.security_settings_pattern;
Jim Milleraf366a32010-03-25 18:45:22 -0700152 break;
153 case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
Jim Miller36972bb2010-11-30 19:47:38 -0800154 resid = R.xml.security_settings_pin;
Jim Milleraf366a32010-03-25 18:45:22 -0700155 break;
156 case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
157 case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
Konstantin Lopyrev57fbf692010-05-27 16:01:41 -0700158 case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
Jim Miller36972bb2010-11-30 19:47:38 -0800159 resid = R.xml.security_settings_password;
Jim Milleraf366a32010-03-25 18:45:22 -0700160 break;
Jim Miller00d24762009-12-22 19:04:57 -0800161 }
Jim Miller122b6c82010-02-10 19:53:58 -0800162 }
Jim Miller36972bb2010-11-30 19:47:38 -0800163 addPreferencesFromResource(resid);
Jim Miller122b6c82010-02-10 19:53:58 -0800164
Jason parks41121992011-01-25 09:26:55 -0600165
166 // Add options for device encryption
Jason parksf8217302011-01-26 13:11:42 -0600167 DevicePolicyManager dpm =
168 (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
Jason parks41121992011-01-25 09:26:55 -0600169
Amith Yamasani7fb4f852012-09-25 22:17:33 -0700170 mIsPrimary = UserHandle.myUserId() == UserHandle.USER_OWNER;
171
172 if (mIsPrimary) {
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700173 switch (dpm.getStorageEncryptionStatus()) {
174 case DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE:
175 // The device is currently encrypted.
176 addPreferencesFromResource(R.xml.security_settings_encrypted);
177 break;
178 case DevicePolicyManager.ENCRYPTION_STATUS_INACTIVE:
179 // This device supports encryption but isn't encrypted.
180 addPreferencesFromResource(R.xml.security_settings_unencrypted);
181 break;
182 }
Jason parks41121992011-01-25 09:26:55 -0600183 }
184
Jim Miller86624a22010-08-30 22:07:58 -0700185 // lock after preference
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800186 mLockAfter = (ListPreference) root.findPreference(KEY_LOCK_AFTER_TIMEOUT);
187 if (mLockAfter != null) {
188 setupLockAfterPreference();
189 updateLockAfterPreferenceSummary();
190 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800191
Danielle Milletta87a25b2012-03-19 18:05:26 -0400192 // biometric weak liveliness
193 mBiometricWeakLiveliness =
Danielle Millett4a3e40d2012-06-06 13:54:11 -0400194 (CheckBoxPreference) root.findPreference(KEY_BIOMETRIC_WEAK_LIVELINESS);
Danielle Milletta87a25b2012-03-19 18:05:26 -0400195
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800196 // visible pattern
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800197 mVisiblePattern = (CheckBoxPreference) root.findPreference(KEY_VISIBLE_PATTERN);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800198
Jim Miller071742d2012-01-06 18:28:09 -0800199 // lock instantly on power key press
200 mPowerButtonInstantlyLocks = (CheckBoxPreference) root.findPreference(
201 KEY_POWER_INSTANTLY_LOCKS);
202
Danielle Millett81234932011-10-19 13:58:30 -0400203 // don't display visible pattern if biometric and backup is not pattern
204 if (resid == R.xml.security_settings_biometric_weak &&
205 mLockPatternUtils.getKeyguardStoredPasswordQuality() !=
206 DevicePolicyManager.PASSWORD_QUALITY_SOMETHING) {
207 PreferenceGroup securityCategory = (PreferenceGroup)
208 root.findPreference(KEY_SECURITY_CATEGORY);
209 if (securityCategory != null && mVisiblePattern != null) {
210 securityCategory.removePreference(root.findPreference(KEY_VISIBLE_PATTERN));
211 }
212 }
213
Jim Miller122b6c82010-02-10 19:53:58 -0800214 // tactile feedback. Should be common to all unlock preference screens.
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800215 mTactileFeedback = (CheckBoxPreference) root.findPreference(KEY_TACTILE_FEEDBACK_ENABLED);
Amith Yamasaniedac9af2010-11-17 09:08:21 -0800216 if (!((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).hasVibrator()) {
217 PreferenceGroup securityCategory = (PreferenceGroup)
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800218 root.findPreference(KEY_SECURITY_CATEGORY);
Amith Yamasaniedac9af2010-11-17 09:08:21 -0800219 if (securityCategory != null && mTactileFeedback != null) {
220 securityCategory.removePreference(mTactileFeedback);
221 }
222 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800223
Michael Jurka091477b2012-09-20 19:03:35 -0700224 mUserSelectedWidget = root.findPreference(KEY_CHOOSE_LOCKSCREEN_STATUS_WIDGET);
225 if (mUserSelectedWidget != null) {
226 AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getActivity());
227 int appWidgetId = getStatusAppWidgetId();
228 if (appWidgetId == -1) {
229 mUserSelectedWidget.setSummary(getResources().getString(R.string.widget_default));
230 } else {
231 AppWidgetProviderInfo appWidget = appWidgetManager.getAppWidgetInfo(appWidgetId);
232 if (appWidget != null) {
233 mUserSelectedWidget.setSummary(appWidget.label);
234 }
235 }
236 }
237
Michael Jurka8227e302012-09-07 09:24:03 -0700238 mUserSelectedWidget = root.findPreference(KEY_CHOOSE_USER_SELECTED_LOCKSCREEN_WIDGET);
Michael Jurkace72ec72012-09-14 14:09:16 -0700239 if (mUserSelectedWidget != null) {
240 AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getActivity());
Michael Jurka30280512012-09-17 17:46:49 -0700241 int appWidgetId = getUserSelectedAppWidgetId();
Michael Jurkace72ec72012-09-14 14:09:16 -0700242 if (appWidgetId == -1) {
243 mUserSelectedWidget.setSummary(getResources().getString(R.string.widget_none));
244 } else {
245 AppWidgetProviderInfo appWidget = appWidgetManager.getAppWidgetInfo(appWidgetId);
246 if (appWidget != null) {
247 mUserSelectedWidget.setSummary(appWidget.label);
248 }
Michael Jurka8227e302012-09-07 09:24:03 -0700249 }
250 }
251
Amith Yamasani7fb4f852012-09-25 22:17:33 -0700252 // Append the rest of the settings
253 addPreferencesFromResource(R.xml.security_settings_misc);
254
255 // Do not display SIM lock for devices without an Icc card
256 TelephonyManager tm = TelephonyManager.getDefault();
257 if (!mIsPrimary || !tm.hasIccCard()) {
258 root.removePreference(root.findPreference(KEY_SIM_LOCK));
259 } else {
260 // Disable SIM lock if sim card is missing or unknown
261 if ((TelephonyManager.getDefault().getSimState() ==
262 TelephonyManager.SIM_STATE_ABSENT) ||
263 (TelephonyManager.getDefault().getSimState() ==
264 TelephonyManager.SIM_STATE_UNKNOWN)) {
265 root.findPreference(KEY_SIM_LOCK).setEnabled(false);
266 }
267 }
268
269 // Show password
270 mShowPassword = (CheckBoxPreference) root.findPreference(KEY_SHOW_PASSWORD);
271
272 // Credential storage, only for primary user
273 if (mIsPrimary) {
274 mResetCredentials = root.findPreference(KEY_RESET_CREDENTIALS);
275 } else {
276 removePreference(KEY_CREDENTIALS_MANAGER);
277 }
278
279 mToggleAppInstallation = (CheckBoxPreference) findPreference(
280 KEY_TOGGLE_INSTALL_APPLICATIONS);
281 mToggleAppInstallation.setChecked(isNonMarketAppsAllowed());
282
283 // Package verification, only visible to primary user and if enabled
284 mToggleVerifyApps = (CheckBoxPreference) findPreference(KEY_TOGGLE_VERIFY_APPLICATIONS);
285 if (mIsPrimary && showVerifierSetting()) {
286 if (isVerifierInstalled()) {
287 mToggleVerifyApps.setChecked(isVerifyAppsEnabled());
288 } else {
289 mToggleVerifyApps.setChecked(false);
290 mToggleVerifyApps.setEnabled(false);
291 }
292 } else if (mToggleVerifyApps != null) {
293 mToggleVerifyApps.setEnabled(false);
294 }
295
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800296 return root;
297 }
298
Michael Jurka091477b2012-09-20 19:03:35 -0700299 private int getStatusAppWidgetId() {
300 int appWidgetId = -1;
301 String appWidgetIdString = Settings.Secure.getString(
302 getContentResolver(), Settings.Secure.LOCK_SCREEN_STATUS_APPWIDGET_ID);
303 if (appWidgetIdString != null) {;
304 appWidgetId = (int) Integer.decode(appWidgetIdString);
305 }
306 return appWidgetId;
307 }
308
Michael Jurka30280512012-09-17 17:46:49 -0700309 private int getUserSelectedAppWidgetId() {
310 int appWidgetId = -1;
311 String appWidgetIdString = Settings.Secure.getString(
312 getContentResolver(), Settings.Secure.LOCK_SCREEN_USER_SELECTED_APPWIDGET_ID);
313 if (appWidgetIdString != null) {;
314 appWidgetId = (int) Integer.decode(appWidgetIdString);
315 }
316 return appWidgetId;
317 }
318
Gilles Debunne2c88a872011-06-21 12:47:17 -0700319 private boolean isNonMarketAppsAllowed() {
Christopher Tate5a64c732012-09-07 13:35:31 -0700320 return Settings.Global.getInt(getContentResolver(),
321 Settings.Global.INSTALL_NON_MARKET_APPS, 0) > 0;
Gilles Debunne2c88a872011-06-21 12:47:17 -0700322 }
323
324 private void setNonMarketAppsAllowed(boolean enabled) {
325 // Change the system setting
Christopher Tate5a64c732012-09-07 13:35:31 -0700326 Settings.Global.putInt(getContentResolver(), Settings.Global.INSTALL_NON_MARKET_APPS,
Gilles Debunne2c88a872011-06-21 12:47:17 -0700327 enabled ? 1 : 0);
328 }
329
rich canningsd5d60652012-09-07 13:20:44 -0700330 private boolean isVerifyAppsEnabled() {
331 return Settings.Global.getInt(getContentResolver(),
332 Settings.Global.PACKAGE_VERIFIER_ENABLE, 1) > 0;
333 }
334
rich canningsbfbdcef2012-09-09 12:48:50 -0700335 private boolean isVerifierInstalled() {
336 final PackageManager pm = getPackageManager();
337 final Intent verification = new Intent(Intent.ACTION_PACKAGE_NEEDS_VERIFICATION);
338 verification.setType(PACKAGE_MIME_TYPE);
339 verification.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
340 final List<ResolveInfo> receivers = pm.queryBroadcastReceivers(verification, 0);
341 return (receivers.size() > 0) ? true : false;
342 }
343
rich canningsbbc30452012-09-16 13:58:07 -0700344 private boolean showVerifierSetting() {
345 return Settings.Global.getInt(getContentResolver(),
346 Settings.Global.PACKAGE_VERIFIER_SETTING_VISIBLE, 1) > 0;
347 }
348
Gilles Debunne2c88a872011-06-21 12:47:17 -0700349 private void warnAppInstallation() {
350 // TODO: DialogFragment?
351 mWarnInstallApps = new AlertDialog.Builder(getActivity()).setTitle(
352 getResources().getString(R.string.error_title))
353 .setIcon(com.android.internal.R.drawable.ic_dialog_alert)
354 .setMessage(getResources().getString(R.string.install_all_warning))
355 .setPositiveButton(android.R.string.yes, this)
356 .setNegativeButton(android.R.string.no, null)
357 .show();
358 }
359
360 public void onClick(DialogInterface dialog, int which) {
361 if (dialog == mWarnInstallApps && which == DialogInterface.BUTTON_POSITIVE) {
362 setNonMarketAppsAllowed(true);
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700363 if (mToggleAppInstallation != null) {
364 mToggleAppInstallation.setChecked(true);
365 }
Gilles Debunne2c88a872011-06-21 12:47:17 -0700366 }
367 }
368
369 @Override
370 public void onDestroy() {
371 super.onDestroy();
372 if (mWarnInstallApps != null) {
373 mWarnInstallApps.dismiss();
374 }
375 }
376
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800377 private void setupLockAfterPreference() {
378 // Compatible with pre-Froyo
379 long currentTimeout = Settings.Secure.getLong(getContentResolver(),
380 Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT, 5000);
381 mLockAfter.setValue(String.valueOf(currentTimeout));
382 mLockAfter.setOnPreferenceChangeListener(this);
383 final long adminTimeout = (mDPM != null ? mDPM.getMaximumTimeToLock(null) : 0);
384 final long displayTimeout = Math.max(0,
385 Settings.System.getInt(getContentResolver(), SCREEN_OFF_TIMEOUT, 0));
386 if (adminTimeout > 0) {
387 // This setting is a slave to display timeout when a device policy is enforced.
388 // As such, maxLockTimeout = adminTimeout - displayTimeout.
389 // If there isn't enough time, shows "immediately" setting.
390 disableUnusableTimeouts(Math.max(0, adminTimeout - displayTimeout));
Jim Miller86624a22010-08-30 22:07:58 -0700391 }
Jim Miller86624a22010-08-30 22:07:58 -0700392 }
393
Jim Millerc9787072011-01-09 18:00:28 -0800394 private void updateLockAfterPreferenceSummary() {
Jim Millerc9787072011-01-09 18:00:28 -0800395 // Update summary message with current value
396 long currentTimeout = Settings.Secure.getLong(getContentResolver(),
Amith Yamasani58bca8f2011-07-22 12:16:16 -0700397 Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT, 5000);
Jim Millerc9787072011-01-09 18:00:28 -0800398 final CharSequence[] entries = mLockAfter.getEntries();
399 final CharSequence[] values = mLockAfter.getEntryValues();
400 int best = 0;
401 for (int i = 0; i < values.length; i++) {
402 long timeout = Long.valueOf(values[i].toString());
403 if (currentTimeout >= timeout) {
404 best = i;
405 }
406 }
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800407 mLockAfter.setSummary(getString(R.string.lock_after_timeout_summary, entries[best]));
Jim Millerc9787072011-01-09 18:00:28 -0800408 }
409
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800410 private void disableUnusableTimeouts(long maxTimeout) {
411 final CharSequence[] entries = mLockAfter.getEntries();
412 final CharSequence[] values = mLockAfter.getEntryValues();
Jim Miller86624a22010-08-30 22:07:58 -0700413 ArrayList<CharSequence> revisedEntries = new ArrayList<CharSequence>();
414 ArrayList<CharSequence> revisedValues = new ArrayList<CharSequence>();
415 for (int i = 0; i < values.length; i++) {
416 long timeout = Long.valueOf(values[i].toString());
417 if (timeout <= maxTimeout) {
418 revisedEntries.add(entries[i]);
419 revisedValues.add(values[i]);
420 }
421 }
422 if (revisedEntries.size() != entries.length || revisedValues.size() != values.length) {
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800423 mLockAfter.setEntries(
Jim Miller86624a22010-08-30 22:07:58 -0700424 revisedEntries.toArray(new CharSequence[revisedEntries.size()]));
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800425 mLockAfter.setEntryValues(
Jim Miller86624a22010-08-30 22:07:58 -0700426 revisedValues.toArray(new CharSequence[revisedValues.size()]));
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800427 final int userPreference = Integer.valueOf(mLockAfter.getValue());
Jim Miller86624a22010-08-30 22:07:58 -0700428 if (userPreference <= maxTimeout) {
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800429 mLockAfter.setValue(String.valueOf(userPreference));
Jim Miller86624a22010-08-30 22:07:58 -0700430 } else {
431 // There will be no highlighted selection since nothing in the list matches
432 // maxTimeout. The user can still select anything less than maxTimeout.
433 // TODO: maybe append maxTimeout to the list and mark selected.
434 }
435 }
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800436 mLockAfter.setEnabled(revisedEntries.size() > 0);
Jim Miller86624a22010-08-30 22:07:58 -0700437 }
438
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800439 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700440 public void onResume() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800441 super.onResume();
442
Jim Miller86624a22010-08-30 22:07:58 -0700443 // Make sure we reload the preference hierarchy since some of these settings
444 // depend on others...
445 createPreferenceHierarchy();
446
Jim Miller00d24762009-12-22 19:04:57 -0800447 final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();
Danielle Milletta87a25b2012-03-19 18:05:26 -0400448 if (mBiometricWeakLiveliness != null) {
Danielle Millett4a3e40d2012-06-06 13:54:11 -0400449 mBiometricWeakLiveliness.setChecked(
450 lockPatternUtils.isBiometricWeakLivelinessEnabled());
Danielle Milletta87a25b2012-03-19 18:05:26 -0400451 }
Jim Miller122b6c82010-02-10 19:53:58 -0800452 if (mVisiblePattern != null) {
Jim Miller122b6c82010-02-10 19:53:58 -0800453 mVisiblePattern.setChecked(lockPatternUtils.isVisiblePatternEnabled());
454 }
455 if (mTactileFeedback != null) {
Jim Miller122b6c82010-02-10 19:53:58 -0800456 mTactileFeedback.setChecked(lockPatternUtils.isTactileFeedbackEnabled());
457 }
Jim Miller071742d2012-01-06 18:28:09 -0800458 if (mPowerButtonInstantlyLocks != null) {
459 mPowerButtonInstantlyLocks.setChecked(lockPatternUtils.getPowerButtonInstantlyLocks());
460 }
Hung-ying Tyan7031ab02009-07-02 00:26:46 +0800461
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700462 if (mShowPassword != null) {
463 mShowPassword.setChecked(Settings.System.getInt(getContentResolver(),
464 Settings.System.TEXT_SHOW_PASSWORD, 1) != 0);
465 }
Hung-ying Tyanb0883cb2009-09-30 11:56:05 +0800466
Brian Carlstromd4023b72011-05-25 13:24:20 -0700467 KeyStore.State state = KeyStore.getInstance().state();
Amith Yamasanib810a0d2012-03-25 10:12:26 -0700468 if (mResetCredentials != null) {
469 mResetCredentials.setEnabled(state != KeyStore.State.UNINITIALIZED);
470 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800471 }
472
Michael Jurka8227e302012-09-07 09:24:03 -0700473 void startActivityForResultSafely(Intent intent, int requestCode) {
474 try {
475 startActivityForResult(intent, requestCode);
476 } catch (ActivityNotFoundException e) {
477 Toast.makeText(getActivity(), R.string.activity_not_found, Toast.LENGTH_SHORT).show();
478 } catch (SecurityException e) {
479 Toast.makeText(getActivity(), R.string.activity_not_found, Toast.LENGTH_SHORT).show();
480 Log.e(TAG, "Settings does not have the permission to launch " + intent, e);
481 }
482 }
483
Michael Jurka16398c92012-09-24 17:30:17 -0700484 private void launchPickActivityIntent(int featuresFilter, int defaultLabelId, int defaultIconId,
485 ComponentName defaultComponentName, String defaultTag) {
486 // Create intent to pick widget
487 Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
488
489 // Found in KeyguardHostView.java
490 final int KEYGUARD_HOST_ID = 0x4B455947;
491 int appWidgetId = AppWidgetHost.allocateAppWidgetIdForSystem(KEYGUARD_HOST_ID);
492 if (appWidgetId != -1) {
493 pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
494 pickIntent.putExtra(AppWidgetManager.EXTRA_CUSTOM_SORT, false);
495 pickIntent.putExtra(AppWidgetManager.EXTRA_CATEGORY_FILTER,
496 AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD);
497 if (featuresFilter != AppWidgetProviderInfo.WIDGET_FEATURES_NONE) {
498 pickIntent.putExtra(AppWidgetManager.EXTRA_FEATURES_FILTER, featuresFilter);
499 }
500
501 // Add an entry for "none" to let someone select no widget
502 AppWidgetProviderInfo defaultInfo = new AppWidgetProviderInfo();
503 ArrayList<AppWidgetProviderInfo> extraInfos = new ArrayList<AppWidgetProviderInfo>();
504 defaultInfo.label = getResources().getString(defaultLabelId);
505 defaultInfo.icon = defaultIconId;
506 defaultInfo.provider = defaultComponentName;
507 extraInfos.add(defaultInfo);
508
509 ArrayList<Bundle> extraExtras = new ArrayList<Bundle>();
510 Bundle b = new Bundle();
511 b.putBoolean(defaultTag, true);
512 extraExtras.add(b);
513
514 // Launch the widget picker
515 pickIntent.putExtra(AppWidgetManager.EXTRA_CUSTOM_INFO, extraInfos);
516 pickIntent.putExtra(AppWidgetManager.EXTRA_CUSTOM_EXTRAS, extraExtras);
517 pickIntent.putExtra(Intent.EXTRA_INTENT, getBaseIntent());
518 startActivityForResult(pickIntent, REQUEST_PICK_USER_SELECTED_APPWIDGET);
519 } else {
520 Log.e(TAG, "Unable to allocate an AppWidget id in lock screen");
521 }
522 }
523
Adam Cohen85d4b5f2012-09-24 13:15:14 -0700524 private Intent getBaseIntent() {
525 Intent baseIntent = new Intent(Intent.ACTION_MAIN, null);
526 baseIntent.addCategory(Intent.CATEGORY_DEFAULT);
527
528 Bundle options = new Bundle();
529 options.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
530 AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD);
531 baseIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
532 return baseIntent;
533 }
534
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800535 @Override
Gilles Debunnea6a8a142011-06-09 11:56:17 -0700536 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800537 final String key = preference.getKey();
538
Jim Miller00d24762009-12-22 19:04:57 -0800539 final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();
Jim Millerbbb4afa2010-04-08 19:40:19 -0700540 if (KEY_UNLOCK_SET_OR_CHANGE.equals(key)) {
Jim Miller17e9e192010-12-07 20:41:41 -0800541 startFragment(this, "com.android.settings.ChooseLockGeneric$ChooseLockGenericFragment",
542 SET_OR_CHANGE_LOCK_METHOD_REQUEST, null);
Michael Jurka8227e302012-09-07 09:24:03 -0700543 } else if (KEY_CHOOSE_USER_SELECTED_LOCKSCREEN_WIDGET.equals(key)) {
Michael Jurka16398c92012-09-24 17:30:17 -0700544 launchPickActivityIntent(AppWidgetProviderInfo.WIDGET_FEATURES_NONE,
545 R.string.widget_none, 0, new ComponentName("", ""), EXTRA_NO_WIDGET);
Michael Jurka091477b2012-09-20 19:03:35 -0700546 } else if (KEY_CHOOSE_LOCKSCREEN_STATUS_WIDGET.equals(key)) {
Michael Jurka16398c92012-09-24 17:30:17 -0700547 int defaultIconId;
548 ComponentName clock = new ComponentName(
549 "com.google.android.deskclock", "com.android.deskclock.DeskClock");
550 try {
551 defaultIconId = getActivity().getPackageManager().getActivityInfo(clock, 0).icon;
552 } catch (PackageManager.NameNotFoundException e) {
553 defaultIconId = 0;
Michael Jurka8227e302012-09-07 09:24:03 -0700554 }
Michael Jurka16398c92012-09-24 17:30:17 -0700555 launchPickActivityIntent(AppWidgetProviderInfo.WIDGET_FEATURES_STATUS,
556 R.string.widget_default, defaultIconId, clock, EXTRA_DEFAULT_WIDGET);
Danielle Millett487b16f2011-11-02 11:12:21 -0400557 } else if (KEY_BIOMETRIC_WEAK_IMPROVE_MATCHING.equals(key)) {
558 ChooseLockSettingsHelper helper =
559 new ChooseLockSettingsHelper(this.getActivity(), this);
560 if (!helper.launchConfirmationActivity(
Danielle Millett790e0c32012-03-23 15:17:50 -0400561 CONFIRM_EXISTING_FOR_BIOMETRIC_WEAK_IMPROVE_REQUEST, null, null)) {
562 // If this returns false, it means no password confirmation is required, so
563 // go ahead and start improve.
564 // Note: currently a backup is required for biometric_weak so this code path
565 // can't be reached, but is here in case things change in the future
566 startBiometricWeakImprove();
Danielle Millett487b16f2011-11-02 11:12:21 -0400567 }
Danielle Millett4a3e40d2012-06-06 13:54:11 -0400568 } else if (KEY_BIOMETRIC_WEAK_LIVELINESS.equals(key)) {
569 if (isToggled(preference)) {
570 lockPatternUtils.setBiometricWeakLivelinessEnabled(true);
571 } else {
572 // In this case the user has just unchecked the checkbox, but this action requires
573 // them to confirm their password. We need to re-check the checkbox until
574 // they've confirmed their password
575 mBiometricWeakLiveliness.setChecked(true);
576 ChooseLockSettingsHelper helper =
577 new ChooseLockSettingsHelper(this.getActivity(), this);
578 if (!helper.launchConfirmationActivity(
579 CONFIRM_EXISTING_FOR_BIOMETRIC_WEAK_LIVELINESS_OFF, null, null)) {
580 // If this returns false, it means no password confirmation is required, so
581 // go ahead and uncheck it here.
582 // Note: currently a backup is required for biometric_weak so this code path
583 // can't be reached, but is here in case things change in the future
584 lockPatternUtils.setBiometricWeakLivelinessEnabled(false);
585 mBiometricWeakLiveliness.setChecked(false);
586 }
587 }
Jim Miller122b6c82010-02-10 19:53:58 -0800588 } else if (KEY_LOCK_ENABLED.equals(key)) {
Jim Miller00d24762009-12-22 19:04:57 -0800589 lockPatternUtils.setLockPatternEnabled(isToggled(preference));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800590 } else if (KEY_VISIBLE_PATTERN.equals(key)) {
Jim Miller00d24762009-12-22 19:04:57 -0800591 lockPatternUtils.setVisiblePatternEnabled(isToggled(preference));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800592 } else if (KEY_TACTILE_FEEDBACK_ENABLED.equals(key)) {
Jim Miller00d24762009-12-22 19:04:57 -0800593 lockPatternUtils.setTactileFeedbackEnabled(isToggled(preference));
Jim Miller071742d2012-01-06 18:28:09 -0800594 } else if (KEY_POWER_INSTANTLY_LOCKS.equals(key)) {
595 lockPatternUtils.setPowerButtonInstantlyLocks(isToggled(preference));
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800596 } else if (preference == mShowPassword) {
597 Settings.System.putInt(getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD,
598 mShowPassword.isChecked() ? 1 : 0);
Gilles Debunne2c88a872011-06-21 12:47:17 -0700599 } else if (preference == mToggleAppInstallation) {
600 if (mToggleAppInstallation.isChecked()) {
601 mToggleAppInstallation.setChecked(false);
602 warnAppInstallation();
603 } else {
604 setNonMarketAppsAllowed(false);
605 }
rich canningsd5d60652012-09-07 13:20:44 -0700606 } else if (KEY_TOGGLE_VERIFY_APPLICATIONS.equals(key)) {
607 Settings.Global.putInt(getContentResolver(), Settings.Global.PACKAGE_VERIFIER_ENABLE,
608 mToggleVerifyApps.isChecked() ? 1 : 0);
Jim Miller36972bb2010-11-30 19:47:38 -0800609 } else {
610 // If we didn't handle it, let preferences handle it.
611 return super.onPreferenceTreeClick(preferenceScreen, preference);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800612 }
Amith Yamasani4bfdcd32009-04-02 11:40:25 -0700613
Jim Miller36972bb2010-11-30 19:47:38 -0800614 return true;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800615 }
616
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800617 private boolean isToggled(Preference pref) {
618 return ((CheckBoxPreference) pref).isChecked();
619 }
620
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800621 /**
Gilles Debunnea6a8a142011-06-09 11:56:17 -0700622 * see confirmPatternThenDisableAndClear
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800623 */
624 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700625 public void onActivityResult(int requestCode, int resultCode, Intent data) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800626 super.onActivityResult(requestCode, resultCode, data);
Danielle Millett790e0c32012-03-23 15:17:50 -0400627 if (requestCode == CONFIRM_EXISTING_FOR_BIOMETRIC_WEAK_IMPROVE_REQUEST &&
Danielle Millett487b16f2011-11-02 11:12:21 -0400628 resultCode == Activity.RESULT_OK) {
629 startBiometricWeakImprove();
630 return;
Danielle Millett4a3e40d2012-06-06 13:54:11 -0400631 } else if (requestCode == CONFIRM_EXISTING_FOR_BIOMETRIC_WEAK_LIVELINESS_OFF &&
632 resultCode == Activity.RESULT_OK) {
633 final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();
634 lockPatternUtils.setBiometricWeakLivelinessEnabled(false);
Michael Jurka8227e302012-09-07 09:24:03 -0700635 // Setting the mBiometricWeakLiveliness checked value to false is handled when onResume
636 // is called by grabbing the value from lockPatternUtils. We can't set it here
637 // because mBiometricWeakLiveliness could be null
Danielle Millett4a3e40d2012-06-06 13:54:11 -0400638 return;
Michael Jurka091477b2012-09-20 19:03:35 -0700639 } else if (requestCode == REQUEST_PICK_USER_SELECTED_APPWIDGET ||
640 requestCode == REQUEST_PICK_STATUS_APPWIDGET ||
641 requestCode == REQUEST_CREATE_USER_SELECTED_APPWIDGET ||
642 requestCode == REQUEST_CREATE_STATUS_APPWIDGET) {
Michael Jurka8227e302012-09-07 09:24:03 -0700643 int appWidgetId = (data == null) ? -1 : data.getIntExtra(
644 AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurka091477b2012-09-20 19:03:35 -0700645 if ((requestCode == REQUEST_PICK_USER_SELECTED_APPWIDGET ||
646 requestCode == REQUEST_PICK_STATUS_APPWIDGET) &&
647 resultCode == Activity.RESULT_OK) {
Michael Jurka8227e302012-09-07 09:24:03 -0700648 AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getActivity());
Michael Jurka091477b2012-09-20 19:03:35 -0700649 boolean defaultOrNoWidget = data.getBooleanExtra(EXTRA_NO_WIDGET, false) ||
650 data.getBooleanExtra(EXTRA_DEFAULT_WIDGET, false);
Michael Jurka8227e302012-09-07 09:24:03 -0700651
652 AppWidgetProviderInfo appWidget = null;
Michael Jurka091477b2012-09-20 19:03:35 -0700653 if (!defaultOrNoWidget) {
Michael Jurka8227e302012-09-07 09:24:03 -0700654 appWidget = appWidgetManager.getAppWidgetInfo(appWidgetId);
655 }
656
Michael Jurka091477b2012-09-20 19:03:35 -0700657 int newRequestCode = requestCode == REQUEST_PICK_USER_SELECTED_APPWIDGET ?
658 REQUEST_CREATE_USER_SELECTED_APPWIDGET :
659 REQUEST_CREATE_STATUS_APPWIDGET;
660 if (!defaultOrNoWidget && appWidget.configure != null) {
Michael Jurka8227e302012-09-07 09:24:03 -0700661 // Launch over to configure widget, if needed
662 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
663 intent.setComponent(appWidget.configure);
664 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
665
Michael Jurka091477b2012-09-20 19:03:35 -0700666 startActivityForResultSafely(intent, newRequestCode);
Michael Jurka8227e302012-09-07 09:24:03 -0700667 } else {
668 // Otherwise just add it
Michael Jurka091477b2012-09-20 19:03:35 -0700669 if (defaultOrNoWidget) {
Michael Jurka30280512012-09-17 17:46:49 -0700670 // If we selected "none", delete the allocated id
Adam Cohen1dd00242012-09-18 13:26:29 -0700671 AppWidgetHost.deleteAppWidgetIdForSystem(appWidgetId);
Michael Jurka8227e302012-09-07 09:24:03 -0700672 data.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
673 }
Michael Jurka091477b2012-09-20 19:03:35 -0700674 onActivityResult(newRequestCode, Activity.RESULT_OK, data);
Michael Jurka8227e302012-09-07 09:24:03 -0700675 }
Michael Jurka091477b2012-09-20 19:03:35 -0700676 } else if ((requestCode == REQUEST_CREATE_USER_SELECTED_APPWIDGET ||
677 requestCode == REQUEST_CREATE_STATUS_APPWIDGET) &&
678 resultCode == Activity.RESULT_OK) {
Michael Jurka30280512012-09-17 17:46:49 -0700679 // If a widget existed before, delete it
Michael Jurka091477b2012-09-20 19:03:35 -0700680 int oldAppWidgetId = requestCode == REQUEST_CREATE_USER_SELECTED_APPWIDGET ?
681 getUserSelectedAppWidgetId() : getStatusAppWidgetId();
Michael Jurka30280512012-09-17 17:46:49 -0700682 if (oldAppWidgetId != -1) {
Adam Cohen1dd00242012-09-18 13:26:29 -0700683 AppWidgetHost.deleteAppWidgetIdForSystem(oldAppWidgetId);
Michael Jurka30280512012-09-17 17:46:49 -0700684 }
Michael Jurka8227e302012-09-07 09:24:03 -0700685 Settings.Secure.putString(getContentResolver(),
Michael Jurka091477b2012-09-20 19:03:35 -0700686 (requestCode == REQUEST_CREATE_USER_SELECTED_APPWIDGET ?
687 Settings.Secure.LOCK_SCREEN_USER_SELECTED_APPWIDGET_ID :
688 Settings.Secure.LOCK_SCREEN_STATUS_APPWIDGET_ID),
Michael Jurka8227e302012-09-07 09:24:03 -0700689 Integer.toString(appWidgetId));
Michael Jurka8227e302012-09-07 09:24:03 -0700690 } else {
Adam Cohen1dd00242012-09-18 13:26:29 -0700691 AppWidgetHost.deleteAppWidgetIdForSystem(appWidgetId);
Michael Jurka8227e302012-09-07 09:24:03 -0700692 }
Danielle Millett487b16f2011-11-02 11:12:21 -0400693 }
Jim Miller122b6c82010-02-10 19:53:58 -0800694 createPreferenceHierarchy();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800695 }
Amith Yamasanif06d8692009-06-11 22:32:33 -0700696
Jim Miller86624a22010-08-30 22:07:58 -0700697 public boolean onPreferenceChange(Preference preference, Object value) {
698 if (preference == mLockAfter) {
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800699 int timeout = Integer.parseInt((String) value);
Jim Miller86624a22010-08-30 22:07:58 -0700700 try {
701 Settings.Secure.putInt(getContentResolver(),
Chia-chi Yeh91d65a22011-01-20 18:46:01 +0800702 Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT, timeout);
Jim Miller86624a22010-08-30 22:07:58 -0700703 } catch (NumberFormatException e) {
704 Log.e("SecuritySettings", "could not persist lockAfter timeout setting", e);
705 }
Jim Millerc9787072011-01-09 18:00:28 -0800706 updateLockAfterPreferenceSummary();
Jim Miller86624a22010-08-30 22:07:58 -0700707 }
708 return true;
709 }
Danielle Millett487b16f2011-11-02 11:12:21 -0400710
711 public void startBiometricWeakImprove(){
712 Intent intent = new Intent();
713 intent.setClassName("com.android.facelock", "com.android.facelock.AddToSetup");
714 startActivity(intent);
715 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800716}