FileDocCategorySizeDatePackage
SecuritySettings.javaAPI DocAndroid 1.5 API12358Wed May 06 22:42:48 BST 2009com.android.settings

SecuritySettings

public class SecuritySettings extends android.preference.PreferenceActivity implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener
Gesture lock pattern settings.

Fields Summary
private static final String
KEY_LOCK_ENABLED
private static final String
KEY_VISIBLE_PATTERN
private static final String
KEY_TACTILE_FEEDBACK_ENABLED
private static final int
CONFIRM_PATTERN_THEN_DISABLE_AND_CLEAR_REQUEST_CODE
private com.android.internal.widget.LockPatternUtils
mLockPatternUtils
private android.preference.CheckBoxPreference
mLockEnabled
private android.preference.CheckBoxPreference
mVisiblePattern
private android.preference.CheckBoxPreference
mTactileFeedback
private android.preference.Preference
mChoosePattern
private android.preference.CheckBoxPreference
mShowPassword
private static final String
LOCATION_NETWORK
private static final String
LOCATION_GPS
private android.preference.CheckBoxPreference
mNetwork
private android.preference.CheckBoxPreference
mGps
private android.location.LocationManager
mLocationManager
private boolean
mOkClicked
Constructors Summary
Methods Summary
private voidconfirmPatternThenDisableAndClear()
Launch screen to confirm the existing lock pattern.

see
#onActivityResult(int, int, android.content.Intent)

        final Intent intent = new Intent();
        intent.setClassName("com.android.settings", "com.android.settings.ConfirmLockPattern");
        startActivityForResult(intent, CONFIRM_PATTERN_THEN_DISABLE_AND_CLEAR_REQUEST_CODE);
    
private android.preference.PreferenceScreencreatePreferenceHierarchy()

        // Root
        PreferenceScreen root = this.getPreferenceScreen();

        // Inline preferences
        PreferenceCategory inlinePrefCat = new PreferenceCategory(this);
        inlinePrefCat.setTitle(R.string.lock_settings_title);
        root.addPreference(inlinePrefCat);

        // autolock toggle
        mLockEnabled = new LockEnabledPref(this);
        mLockEnabled.setTitle(R.string.lockpattern_settings_enable_title);
        mLockEnabled.setSummary(R.string.lockpattern_settings_enable_summary);
        mLockEnabled.setKey(KEY_LOCK_ENABLED);
        inlinePrefCat.addPreference(mLockEnabled);

        // visible pattern
        mVisiblePattern = new CheckBoxPreference(this);
        mVisiblePattern.setKey(KEY_VISIBLE_PATTERN);
        mVisiblePattern.setTitle(R.string.lockpattern_settings_enable_visible_pattern_title);
        inlinePrefCat.addPreference(mVisiblePattern);

        // tactile feedback
        mTactileFeedback = new CheckBoxPreference(this);
        mTactileFeedback.setKey(KEY_TACTILE_FEEDBACK_ENABLED);
        mTactileFeedback.setTitle(R.string.lockpattern_settings_enable_tactile_feedback_title);
        inlinePrefCat.addPreference(mTactileFeedback);

        // change pattern lock
        Intent intent = new Intent();
        intent.setClassName("com.android.settings",
                    "com.android.settings.ChooseLockPatternTutorial");
        mChoosePattern = getPreferenceManager().createPreferenceScreen(this);
        mChoosePattern.setIntent(intent);
        inlinePrefCat.addPreference(mChoosePattern);
        
        PreferenceScreen simLockPreferences = getPreferenceManager()
                .createPreferenceScreen(this);
        simLockPreferences.setTitle(R.string.sim_lock_settings_category);
        // Intent to launch SIM lock settings
        intent = new Intent();
        intent.setClassName("com.android.settings", "com.android.settings.SimLockSettings");
        simLockPreferences.setIntent(intent);
        
        PreferenceCategory simLockCat = new PreferenceCategory(this);
        simLockCat.setTitle(R.string.sim_lock_settings_title);
        root.addPreference(simLockCat);
        simLockCat.addPreference(simLockPreferences);

        // Passwords
        PreferenceCategory passwordsCat = new PreferenceCategory(this);
        passwordsCat.setTitle(R.string.security_passwords_title);
        root.addPreference(passwordsCat);
        
        CheckBoxPreference showPassword = mShowPassword = new CheckBoxPreference(this);
        showPassword.setKey("show_password");
        showPassword.setTitle(R.string.show_password);
        showPassword.setSummary(R.string.show_password_summary);
        showPassword.setPersistent(false);
        passwordsCat.addPreference(showPassword);
        
        return root;
    
private java.lang.StringgetAllowedProviders()

return
string containing a list of providers that have been enabled for use

        String allowedProviders =
            Settings.Secure.getString(getContentResolver(),
                Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
        if (allowedProviders == null) {
            allowedProviders = "";
        }
        return allowedProviders;
    
private booleanisToggled(android.preference.Preference pref)

        return ((CheckBoxPreference) pref).isChecked();
    
protected voidonActivityResult(int requestCode, int resultCode, android.content.Intent data)

see
#confirmPatternThenDisableAndClear

        super.onActivityResult(requestCode, resultCode, data);

        final boolean resultOk = resultCode == Activity.RESULT_OK;

        if ((requestCode == CONFIRM_PATTERN_THEN_DISABLE_AND_CLEAR_REQUEST_CODE) && resultOk) {
            mLockPatternUtils.setLockPatternEnabled(false);
            mLockPatternUtils.saveLockPattern(null);
        }
    
public voidonClick(android.content.DialogInterface dialog, int which)

        if (which == DialogInterface.BUTTON_POSITIVE) {
            updateProviders();
            mOkClicked = true;
        } else {
            // Reset the toggle
            mNetwork.setChecked(false);
        }
    
protected voidonCreate(android.os.Bundle savedInstanceState)


    
        
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.security_settings);

        mLockPatternUtils = new LockPatternUtils(getContentResolver());

        createPreferenceHierarchy();
        
        // Get the available location providers
        mLocationManager = (LocationManager)
            getSystemService(Context.LOCATION_SERVICE);

        mNetwork = (CheckBoxPreference) getPreferenceScreen().findPreference(LOCATION_NETWORK);
        mGps = (CheckBoxPreference) getPreferenceScreen().findPreference(LOCATION_GPS);
        updateToggles();
    
public voidonDismiss(android.content.DialogInterface dialog)

        // Assuming that onClick gets called first
        if (!mOkClicked) {
            mNetwork.setChecked(false);
        }
    
public booleanonPreferenceTreeClick(android.preference.PreferenceScreen preferenceScreen, android.preference.Preference preference)

        final String key = preference.getKey();

        if (KEY_LOCK_ENABLED.equals(key)) {
            mLockPatternUtils.setLockPatternEnabled(isToggled(preference));
        } else if (KEY_VISIBLE_PATTERN.equals(key)) {
            mLockPatternUtils.setVisiblePatternEnabled(isToggled(preference));
        } else if (KEY_TACTILE_FEEDBACK_ENABLED.equals(key)) {
            mLockPatternUtils.setTactileFeedbackEnabled(isToggled(preference));
        } else if (preference == mShowPassword) {
            Settings.System.putInt(getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD,
                    mShowPassword.isChecked() ? 1 : 0);
        } else if (preference == mNetwork) {
            //normally called on the toggle click
            if (mNetwork.isChecked()) {
                // Show a warning to the user that location data will be shared 
                mOkClicked = false;
                new AlertDialog.Builder(this).setMessage(
                        getResources().getString(R.string.location_warning_message))
                        .setTitle(R.string.location_warning_title)
                        .setIcon(android.R.drawable.ic_dialog_alert)
                        .setPositiveButton(R.string.agree, this)
                        .setNegativeButton(R.string.disagree, this)
                        .show()
                        .setOnDismissListener(this);
            } else {
                updateProviders();
            }
        } else if (preference == mGps) {
            updateProviders();
        }

        return false;
    
protected voidonResume()

        super.onResume();

        boolean patternExists = mLockPatternUtils.savedPatternExists();
        mLockEnabled.setEnabled(patternExists);
        mVisiblePattern.setEnabled(patternExists);
        mTactileFeedback.setEnabled(patternExists);

        mLockEnabled.setChecked(mLockPatternUtils.isLockPatternEnabled());
        mVisiblePattern.setChecked(mLockPatternUtils.isVisiblePatternEnabled());
        mTactileFeedback.setChecked(mLockPatternUtils.isTactileFeedbackEnabled());

        int chooseStringRes = mLockPatternUtils.savedPatternExists() ?
                R.string.lockpattern_settings_change_lock_pattern :
                R.string.lockpattern_settings_choose_lock_pattern;
        mChoosePattern.setTitle(chooseStringRes);
        
        mShowPassword
                .setChecked(Settings.System.getInt(getContentResolver(),
                Settings.System.TEXT_SHOW_PASSWORD, 1) != 0);
    
private voidsetProviders(java.lang.String providers)

        // Update the secure setting LOCATION_PROVIDERS_ALLOWED
        Settings.Secure.putString(getContentResolver(),
            Settings.Secure.LOCATION_PROVIDERS_ALLOWED, providers);
        if (Config.LOGV) {
            Log.v("Location Accuracy", "Setting LOCATION_PROVIDERS_ALLOWED = " + providers);
        }
        // Inform the location manager about the changes
        mLocationManager.updateProviders();
    
private voidupdateProviders()

        String preferredProviders = "";
        if (mNetwork.isChecked()) {
            preferredProviders += LocationManager.NETWORK_PROVIDER;
        }
        if (mGps.isChecked()) {
            preferredProviders += "," + LocationManager.GPS_PROVIDER;
        }
        setProviders(preferredProviders);
    
private voidupdateToggles()

        String providers = getAllowedProviders();
        mNetwork.setChecked(providers.contains(LocationManager.NETWORK_PROVIDER));
        mGps.setChecked(providers.contains(LocationManager.GPS_PROVIDER));