Search in sources :

Example 51 with PreferenceGroup

use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by DirtyUnicorns.

the class TrustAgentSettings method updateAgents.

private void updateAgents() {
    final Context context = getActivity();
    if (mAvailableAgents == null) {
        mAvailableAgents = findAvailableTrustAgents();
    }
    if (mLockPatternUtils == null) {
        mLockPatternUtils = new LockPatternUtils(getActivity());
    }
    loadActiveAgents();
    PreferenceGroup category = (PreferenceGroup) getPreferenceScreen().findPreference("trust_agents");
    category.removeAll();
    final EnforcedAdmin admin = RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(context, DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS, UserHandle.myUserId());
    final int count = mAvailableAgents.size();
    for (int i = 0; i < count; i++) {
        AgentInfo agent = mAvailableAgents.valueAt(i);
        final RestrictedSwitchPreference preference = new RestrictedSwitchPreference(getPrefContext());
        preference.useAdminDisabledSummary(true);
        agent.preference = preference;
        preference.setPersistent(false);
        preference.setTitle(agent.label);
        preference.setIcon(agent.icon);
        preference.setPersistent(false);
        preference.setOnPreferenceChangeListener(this);
        preference.setChecked(mActiveAgents.contains(agent.component));
        if (admin != null && mDpm.getTrustAgentConfiguration(null, agent.component) == null) {
            preference.setChecked(false);
            preference.setDisabledByAdmin(admin);
        }
        category.addPreference(agent.preference);
    }
}
Also used : Context(android.content.Context) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) LockPatternUtils(com.android.internal.widget.LockPatternUtils) PreferenceGroup(android.support.v7.preference.PreferenceGroup) EnforcedAdmin(com.android.settingslib.RestrictedLockUtils.EnforcedAdmin)

Example 52 with PreferenceGroup

use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by DirtyUnicorns.

the class Utils method addAll.

private static void addAll(PreferenceGroup group, List<String> ret) {
    if (group == null)
        return;
    for (int i = 0; i < group.getPreferenceCount(); i++) {
        Preference pref = group.getPreference(i);
        ret.add(pref.getKey());
        if (pref instanceof PreferenceGroup) {
            addAll((PreferenceGroup) pref, ret);
        }
    }
}
Also used : Preference(android.support.v7.preference.Preference) PreferenceGroup(android.support.v7.preference.PreferenceGroup)

Example 53 with PreferenceGroup

use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by DirtyUnicorns.

the class SecuritySettings method createPreferenceHierarchy.

/**
 * Important!
 *
 * Don't forget to update the SecuritySearchIndexProvider if you are doing any change in the
 * logic or adding/removing preferences here.
 */
private PreferenceScreen createPreferenceHierarchy() {
    PreferenceScreen root = getPreferenceScreen();
    if (root != null) {
        root.removeAll();
    }
    addPreferencesFromResource(R.xml.security_settings);
    root = getPreferenceScreen();
    // Add category for security status
    addPreferencesFromResource(R.xml.security_settings_status);
    // Add options for lock/unlock screen
    final int resid = getResIdForLockUnlockScreen(getActivity(), mLockPatternUtils, mManagedPasswordProvider, MY_USER_ID);
    addPreferencesFromResource(resid);
    // DO or PO installed in the user may disallow to change password.
    disableIfPasswordQualityManaged(KEY_UNLOCK_SET_OR_CHANGE, MY_USER_ID);
    mProfileChallengeUserId = Utils.getManagedProfileId(mUm, MY_USER_ID);
    if (mProfileChallengeUserId != UserHandle.USER_NULL && mLockPatternUtils.isSeparateProfileChallengeAllowed(mProfileChallengeUserId)) {
        addPreferencesFromResource(R.xml.security_settings_profile);
        addPreferencesFromResource(R.xml.security_settings_unification);
        final int profileResid = getResIdForLockUnlockScreen(getActivity(), mLockPatternUtils, mManagedPasswordProvider, mProfileChallengeUserId);
        addPreferencesFromResource(profileResid);
        maybeAddFingerprintPreference(root, mProfileChallengeUserId);
        if (!mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileChallengeUserId)) {
            final Preference lockPreference = root.findPreference(KEY_UNLOCK_SET_OR_CHANGE_PROFILE);
            final String summary = getContext().getString(R.string.lock_settings_profile_unified_summary);
            lockPreference.setSummary(summary);
            lockPreference.setEnabled(false);
            // PO may disallow to change password for the profile, but screen lock and managed
            // profile's lock is the same. Disable main "Screen lock" menu.
            disableIfPasswordQualityManaged(KEY_UNLOCK_SET_OR_CHANGE, mProfileChallengeUserId);
        } else {
            // PO may disallow to change profile password, and the profile's password is
            // separated from screen lock password. Disable profile specific "Screen lock" menu.
            disableIfPasswordQualityManaged(KEY_UNLOCK_SET_OR_CHANGE_PROFILE, mProfileChallengeUserId);
        }
    }
    Preference unlockSetOrChange = findPreference(KEY_UNLOCK_SET_OR_CHANGE);
    if (unlockSetOrChange instanceof GearPreference) {
        ((GearPreference) unlockSetOrChange).setOnGearClickListener(this);
    }
    mIsAdmin = mUm.isAdminUser();
    // Fingerprint and trust agents
    int numberOfTrustAgent = 0;
    PreferenceGroup securityCategory = (PreferenceGroup) root.findPreference(KEY_SECURITY_CATEGORY);
    if (securityCategory != null) {
        maybeAddFingerprintPreference(securityCategory, UserHandle.myUserId());
        numberOfTrustAgent = addTrustAgentSettings(securityCategory);
        setLockscreenPreferencesSummary(securityCategory);
    }
    mVisiblePatternProfile = (SwitchPreference) root.findPreference(KEY_VISIBLE_PATTERN_PROFILE);
    mUnifyProfile = (SwitchPreference) root.findPreference(KEY_UNIFICATION);
    // Append the rest of the settings
    addPreferencesFromResource(R.xml.security_settings_misc);
    // Do not display SIM lock for devices without an Icc card
    TelephonyManager tm = TelephonyManager.getDefault();
    CarrierConfigManager cfgMgr = (CarrierConfigManager) getActivity().getSystemService(Context.CARRIER_CONFIG_SERVICE);
    PersistableBundle b = cfgMgr.getConfig();
    if (!mIsAdmin || !isSimIccReady() || b.getBoolean(CarrierConfigManager.KEY_HIDE_SIM_LOCK_SETTINGS_BOOL)) {
        root.removePreference(root.findPreference(KEY_SIM_LOCK));
    } else {
        // Disable SIM lock if there is no ready SIM card.
        root.findPreference(KEY_SIM_LOCK).setEnabled(isSimReady());
    }
    if (Settings.System.getInt(getContentResolver(), Settings.System.LOCK_TO_APP_ENABLED, 0) != 0) {
        root.findPreference(KEY_SCREEN_PINNING).setSummary(getResources().getString(R.string.switch_on_text));
    }
    // Encryption status of device
    if (LockPatternUtils.isDeviceEncryptionEnabled()) {
        root.findPreference(KEY_ENCRYPTION_AND_CREDENTIALS).setSummary(R.string.encryption_and_credential_settings_summary);
    } else {
        root.findPreference(KEY_ENCRYPTION_AND_CREDENTIALS).setSummary(R.string.summary_placeholder);
    }
    // Show password
    mShowPassword = (SwitchPreference) root.findPreference(KEY_SHOW_PASSWORD);
    // Credential storage
    final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
    // Advanced Security features
    initTrustAgentPreference(root, numberOfTrustAgent);
    // The above preferences come and go based on security state, so we need to update
    // the index. This call is expected to be fairly cheap, but we may want to do something
    // smarter in the future.
    final Activity activity = getActivity();
    FeatureFactory.getFactory(activity).getSearchFeatureProvider().getIndexingManager(activity).updateFromClassNameResource(SecuritySettings.class.getName(), true);
    PreferenceGroup securityStatusPreferenceGroup = (PreferenceGroup) root.findPreference(KEY_SECURITY_STATUS);
    final List<Preference> tilePrefs = mDashboardFeatureProvider.getPreferencesForCategory(getActivity(), getPrefContext(), getMetricsCategory(), CategoryKey.CATEGORY_SECURITY);
    int numSecurityStatusPrefs = 0;
    if (tilePrefs != null && !tilePrefs.isEmpty()) {
        for (Preference preference : tilePrefs) {
            if (!TextUtils.isEmpty(preference.getKey()) && preference.getKey().startsWith(SECURITY_STATUS_KEY_PREFIX)) {
                // Injected security status settings are placed under the Security status
                // category.
                securityStatusPreferenceGroup.addPreference(preference);
                numSecurityStatusPrefs++;
            } else {
                // Other injected settings are placed under the Security preference screen.
                root.addPreference(preference);
            }
        }
    }
    if (numSecurityStatusPrefs == 0) {
        root.removePreference(securityStatusPreferenceGroup);
    } else if (numSecurityStatusPrefs > 0) {
        // Update preference data with tile data. Security feature provider only updates the
        // data if it actually needs to be changed.
        mSecurityFeatureProvider.updatePreferences(getActivity(), root, mDashboardFeatureProvider.getTilesForCategory(CategoryKey.CATEGORY_SECURITY));
    }
    for (int i = 0; i < SWITCH_PREFERENCE_KEYS.length; i++) {
        final Preference pref = findPreference(SWITCH_PREFERENCE_KEYS[i]);
        if (pref != null)
            pref.setOnPreferenceChangeListener(this);
    }
    mLocationcontroller.displayPreference(root);
    mManageDeviceAdminPreferenceController.updateState(root.findPreference(KEY_MANAGE_DEVICE_ADMIN));
    mEnterprisePrivacyPreferenceController.displayPreference(root);
    mEnterprisePrivacyPreferenceController.onResume();
    final Preference encryptioncredential = root.findPreference(KEY_ENCRYPTION_AND_CREDENTIALS);
    if (LockPatternUtils.isDeviceEncryptionEnabled()) {
        final String summaryencrypt = getContext().getString(R.string.custom_encryption_and_credential_settings_summary_on);
        encryptioncredential.setSummary(summaryencrypt);
    } else {
        final String summarydecrypt = getContext().getString(R.string.custom_encryption_and_credential_settings_summary_off);
        encryptioncredential.setSummary(summarydecrypt);
    }
    return root;
}
Also used : GearPreference(com.android.settings.widget.GearPreference) CarrierConfigManager(android.telephony.CarrierConfigManager) PreferenceScreen(android.support.v7.preference.PreferenceScreen) Activity(android.app.Activity) PersistableBundle(android.os.PersistableBundle) RestrictedPreference(com.android.settingslib.RestrictedPreference) GearPreference(com.android.settings.widget.GearPreference) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) TelephonyManager(android.telephony.TelephonyManager) UserManager(android.os.UserManager) PreferenceGroup(android.support.v7.preference.PreferenceGroup)

Example 54 with PreferenceGroup

use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by DirtyUnicorns.

the class LegalSettings method onCreate.

public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    addPreferencesFromResource(R.xml.about_legal);
    final Activity act = getActivity();
    // These are contained in the "container" preference group
    PreferenceGroup parentPreference = getPreferenceScreen();
    Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_TERMS, Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
    Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_LICENSE, Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
    Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_COPYRIGHT, Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
    Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_WEBVIEW_LICENSE, Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
}
Also used : Activity(android.app.Activity) PreferenceGroup(android.support.v7.preference.PreferenceGroup)

Example 55 with PreferenceGroup

use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by DirtyUnicorns.

the class ProgressiveDisclosureMixin method findPreference.

/**
 * Finds preference by key, either from screen or from collapsed list.
 */
public Preference findPreference(PreferenceScreen screen, CharSequence key) {
    Preference preference = screen.findPreference(key);
    if (preference != null) {
        return preference;
    }
    for (int i = 0; i < mCollapsedPrefs.size(); i++) {
        final Preference pref = mCollapsedPrefs.get(i);
        if (TextUtils.equals(key, pref.getKey())) {
            return pref;
        }
        if (pref instanceof PreferenceGroup) {
            final Preference returnedPreference = ((PreferenceGroup) pref).findPreference(key);
            if (returnedPreference != null) {
                return returnedPreference;
            }
        }
    }
    Log.d(TAG, "Cannot find preference with key " + key);
    return null;
}
Also used : Preference(android.support.v7.preference.Preference) PreferenceGroup(android.support.v7.preference.PreferenceGroup)

Aggregations

PreferenceGroup (android.support.v7.preference.PreferenceGroup)104 Preference (android.support.v7.preference.Preference)70 Context (android.content.Context)28 PreferenceScreen (android.support.v7.preference.PreferenceScreen)28 Test (org.junit.Test)26 PreferenceManager (android.support.v7.preference.PreferenceManager)22 SwitchPreference (android.support.v14.preference.SwitchPreference)19 ArrayList (java.util.ArrayList)19 PreferenceCategory (android.support.v7.preference.PreferenceCategory)17 UserInfo (android.content.pm.UserInfo)16 Intent (android.content.Intent)14 AccessiblePreferenceCategory (com.android.settings.AccessiblePreferenceCategory)14 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)14 Account (android.accounts.Account)12 AuthenticatorDescription (android.accounts.AuthenticatorDescription)12 UserHandle (android.os.UserHandle)12 TelephonyManager (android.telephony.TelephonyManager)12 Activity (android.app.Activity)11 RestrictedPreference (com.android.settingslib.RestrictedPreference)11 RemoteException (android.os.RemoteException)8