X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=src%2Fcom%2Fandroid%2Fsettings%2FSecuritySettings.java;h=adf8c3776919e052e9a7c58c0fe7e96934db1789;hb=071742d838f9b0c312af309c87eaf2c444aeeab8;hp=fc91e78492fe959680649b3caee9857a4e856296;hpb=a6a8a1479b970d8a84395453703348fe42d17438;p=android-x86%2Fpackages-apps-Settings.git diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java index fc91e78492..adf8c37769 100644 --- a/src/com/android/settings/SecuritySettings.java +++ b/src/com/android/settings/SecuritySettings.java @@ -19,8 +19,11 @@ package com.android.settings; import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT; +import android.app.Activity; +import android.app.AlertDialog; import android.app.admin.DevicePolicyManager; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.os.Vibrator; @@ -35,6 +38,7 @@ import android.security.KeyStore; import android.telephony.TelephonyManager; import android.util.Log; +import com.android.internal.telephony.Phone; import com.android.internal.widget.LockPatternUtils; import java.util.ArrayList; @@ -43,21 +47,26 @@ import java.util.ArrayList; * Gesture lock pattern settings. */ public class SecuritySettings extends SettingsPreferenceFragment - implements OnPreferenceChangeListener { + implements OnPreferenceChangeListener, DialogInterface.OnClickListener { // Lock Settings private static final String KEY_UNLOCK_SET_OR_CHANGE = "unlock_set_or_change"; + private static final String KEY_BIOMETRIC_WEAK_IMPROVE_MATCHING = + "biometric_weak_improve_matching"; private static final String KEY_LOCK_ENABLED = "lockenabled"; private static final String KEY_VISIBLE_PATTERN = "visiblepattern"; private static final String KEY_TACTILE_FEEDBACK_ENABLED = "unlock_tactile_feedback"; private static final String KEY_SECURITY_CATEGORY = "security_category"; private static final String KEY_LOCK_AFTER_TIMEOUT = "lock_after_timeout"; private static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST = 123; + private static final int CONFIRM_EXISTING_FOR_BIOMETRIC_IMPROVE_REQUEST = 124; // Misc Settings private static final String KEY_SIM_LOCK = "sim_lock"; private static final String KEY_SHOW_PASSWORD = "show_password"; private static final String KEY_RESET_CREDENTIALS = "reset_credentials"; + private static final String KEY_TOGGLE_INSTALL_APPLICATIONS = "toggle_install_applications"; + private static final String KEY_POWER_INSTANTLY_LOCKS = "power_button_instantly_locks"; DevicePolicyManager mDPM; @@ -72,6 +81,10 @@ public class SecuritySettings extends SettingsPreferenceFragment private Preference mResetCredentials; + private CheckBoxPreference mToggleAppInstallation; + private DialogInterface mWarnInstallApps; + private CheckBoxPreference mPowerButtonInstantlyLocks; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -99,6 +112,9 @@ public class SecuritySettings extends SettingsPreferenceFragment } else { resid = R.xml.security_settings_chooser; } + } else if (mLockPatternUtils.usingBiometricWeak() && + mLockPatternUtils.isBiometricWeakInstalled()) { + resid = R.xml.security_settings_biometric_weak; } else { switch (mLockPatternUtils.getKeyguardStoredPasswordQuality()) { case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING: @@ -142,6 +158,21 @@ public class SecuritySettings extends SettingsPreferenceFragment // visible pattern mVisiblePattern = (CheckBoxPreference) root.findPreference(KEY_VISIBLE_PATTERN); + // lock instantly on power key press + mPowerButtonInstantlyLocks = (CheckBoxPreference) root.findPreference( + KEY_POWER_INSTANTLY_LOCKS); + + // don't display visible pattern if biometric and backup is not pattern + if (resid == R.xml.security_settings_biometric_weak && + mLockPatternUtils.getKeyguardStoredPasswordQuality() != + DevicePolicyManager.PASSWORD_QUALITY_SOMETHING) { + PreferenceGroup securityCategory = (PreferenceGroup) + root.findPreference(KEY_SECURITY_CATEGORY); + if (securityCategory != null && mVisiblePattern != null) { + securityCategory.removePreference(root.findPreference(KEY_VISIBLE_PATTERN)); + } + } + // tactile feedback. Should be common to all unlock preference screens. mTactileFeedback = (CheckBoxPreference) root.findPreference(KEY_TACTILE_FEEDBACK_ENABLED); if (!((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).hasVibrator()) { @@ -156,9 +187,18 @@ public class SecuritySettings extends SettingsPreferenceFragment addPreferencesFromResource(R.xml.security_settings_misc); // Do not display SIM lock for CDMA phone - if (TelephonyManager.PHONE_TYPE_CDMA == - TelephonyManager.getDefault().getCurrentPhoneType()) { + TelephonyManager tm = TelephonyManager.getDefault(); + if ((TelephonyManager.PHONE_TYPE_CDMA == tm.getCurrentPhoneType()) && + (tm.getLteOnCdmaMode() != Phone.LTE_ON_CDMA_TRUE)) { root.removePreference(root.findPreference(KEY_SIM_LOCK)); + } else { + // Disable SIM lock if sim card is missing or unknown + if ((TelephonyManager.getDefault().getSimState() == + TelephonyManager.SIM_STATE_ABSENT) || + (TelephonyManager.getDefault().getSimState() == + TelephonyManager.SIM_STATE_UNKNOWN)) { + root.findPreference(KEY_SIM_LOCK).setEnabled(false); + } } // Show password @@ -167,9 +207,50 @@ public class SecuritySettings extends SettingsPreferenceFragment // Credential storage mResetCredentials = root.findPreference(KEY_RESET_CREDENTIALS); + mToggleAppInstallation = (CheckBoxPreference) findPreference( + KEY_TOGGLE_INSTALL_APPLICATIONS); + mToggleAppInstallation.setChecked(isNonMarketAppsAllowed()); + return root; } + private boolean isNonMarketAppsAllowed() { + return Settings.Secure.getInt(getContentResolver(), + Settings.Secure.INSTALL_NON_MARKET_APPS, 0) > 0; + } + + private void setNonMarketAppsAllowed(boolean enabled) { + // Change the system setting + Settings.Secure.putInt(getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS, + enabled ? 1 : 0); + } + + private void warnAppInstallation() { + // TODO: DialogFragment? + mWarnInstallApps = new AlertDialog.Builder(getActivity()).setTitle( + getResources().getString(R.string.error_title)) + .setIcon(com.android.internal.R.drawable.ic_dialog_alert) + .setMessage(getResources().getString(R.string.install_all_warning)) + .setPositiveButton(android.R.string.yes, this) + .setNegativeButton(android.R.string.no, null) + .show(); + } + + public void onClick(DialogInterface dialog, int which) { + if (dialog == mWarnInstallApps && which == DialogInterface.BUTTON_POSITIVE) { + setNonMarketAppsAllowed(true); + mToggleAppInstallation.setChecked(true); + } + } + + @Override + public void onDestroy() { + super.onDestroy(); + if (mWarnInstallApps != null) { + mWarnInstallApps.dismiss(); + } + } + private void setupLockAfterPreference() { // Compatible with pre-Froyo long currentTimeout = Settings.Secure.getLong(getContentResolver(), @@ -190,7 +271,7 @@ public class SecuritySettings extends SettingsPreferenceFragment private void updateLockAfterPreferenceSummary() { // Update summary message with current value long currentTimeout = Settings.Secure.getLong(getContentResolver(), - Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT, 0); + Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT, 5000); final CharSequence[] entries = mLockAfter.getEntries(); final CharSequence[] values = mLockAfter.getEntryValues(); int best = 0; @@ -247,6 +328,9 @@ public class SecuritySettings extends SettingsPreferenceFragment if (mTactileFeedback != null) { mTactileFeedback.setChecked(lockPatternUtils.isTactileFeedbackEnabled()); } + if (mPowerButtonInstantlyLocks != null) { + mPowerButtonInstantlyLocks.setChecked(lockPatternUtils.getPowerButtonInstantlyLocks()); + } mShowPassword.setChecked(Settings.System.getInt(getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD, 1) != 0); @@ -263,15 +347,31 @@ public class SecuritySettings extends SettingsPreferenceFragment if (KEY_UNLOCK_SET_OR_CHANGE.equals(key)) { startFragment(this, "com.android.settings.ChooseLockGeneric$ChooseLockGenericFragment", SET_OR_CHANGE_LOCK_METHOD_REQUEST, null); + } else if (KEY_BIOMETRIC_WEAK_IMPROVE_MATCHING.equals(key)) { + ChooseLockSettingsHelper helper = + new ChooseLockSettingsHelper(this.getActivity(), this); + if (!helper.launchConfirmationActivity( + CONFIRM_EXISTING_FOR_BIOMETRIC_IMPROVE_REQUEST, null, null)) { + startBiometricWeakImprove(); // no password set, so no need to confirm + } } else if (KEY_LOCK_ENABLED.equals(key)) { lockPatternUtils.setLockPatternEnabled(isToggled(preference)); } else if (KEY_VISIBLE_PATTERN.equals(key)) { lockPatternUtils.setVisiblePatternEnabled(isToggled(preference)); } else if (KEY_TACTILE_FEEDBACK_ENABLED.equals(key)) { lockPatternUtils.setTactileFeedbackEnabled(isToggled(preference)); + } else if (KEY_POWER_INSTANTLY_LOCKS.equals(key)) { + lockPatternUtils.setPowerButtonInstantlyLocks(isToggled(preference)); } else if (preference == mShowPassword) { Settings.System.putInt(getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD, mShowPassword.isChecked() ? 1 : 0); + } else if (preference == mToggleAppInstallation) { + if (mToggleAppInstallation.isChecked()) { + mToggleAppInstallation.setChecked(false); + warnAppInstallation(); + } else { + setNonMarketAppsAllowed(false); + } } else { // If we didn't handle it, let preferences handle it. return super.onPreferenceTreeClick(preferenceScreen, preference); @@ -290,6 +390,11 @@ public class SecuritySettings extends SettingsPreferenceFragment @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); + if (requestCode == CONFIRM_EXISTING_FOR_BIOMETRIC_IMPROVE_REQUEST && + resultCode == Activity.RESULT_OK) { + startBiometricWeakImprove(); + return; + } createPreferenceHierarchy(); } @@ -306,4 +411,10 @@ public class SecuritySettings extends SettingsPreferenceFragment } return true; } + + public void startBiometricWeakImprove(){ + Intent intent = new Intent(); + intent.setClassName("com.android.facelock", "com.android.facelock.AddToSetup"); + startActivity(intent); + } }