Search in sources :

Example 6 with GearPreference

use of com.android.settings.widget.GearPreference in project android_packages_apps_Settings by crdroidandroid.

the class CurrentDreamPreferenceControllerTest method gearShowsIfActiveDreamInfoHasOptions.

@Test
public void gearShowsIfActiveDreamInfoHasOptions() {
    mDreamInfo.settingsComponentName = mock(ComponentName.class);
    mDreamInfo.isActive = true;
    when(mBackend.getDreamInfos()).thenReturn(new ArrayList<>(Arrays.asList(mDreamInfo)));
    GearPreference mockPref = mock(GearPreference.class);
    ArgumentCaptor<GearPreference.OnGearClickListener> captor = ArgumentCaptor.forClass(GearPreference.OnGearClickListener.class);
    // verify that updateState sets a non-null gear click listener
    mController.updateState(mockPref);
    verify(mockPref).setOnGearClickListener(captor.capture());
    captor.getAllValues().forEach(listener -> assertThat(listener).isNotNull());
}
Also used : GearPreference(com.android.settings.widget.GearPreference) ComponentName(android.content.ComponentName) Test(org.junit.Test)

Example 7 with GearPreference

use of com.android.settings.widget.GearPreference in project android_packages_apps_Settings by crdroidandroid.

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();
    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 8 with GearPreference

use of com.android.settings.widget.GearPreference in project android_packages_apps_Settings by SudaMod.

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();
    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 9 with GearPreference

use of com.android.settings.widget.GearPreference in project android_packages_apps_Settings by SudaMod.

the class CurrentDreamPreferenceControllerTest method gearHidesIfActiveDreamInfoHasNoOptions.

@Test
public void gearHidesIfActiveDreamInfoHasNoOptions() {
    mDreamInfo.settingsComponentName = null;
    mDreamInfo.isActive = true;
    when(mBackend.getDreamInfos()).thenReturn(new ArrayList<>(Arrays.asList(mDreamInfo)));
    GearPreference mockPref = mock(GearPreference.class);
    ArgumentCaptor<GearPreference.OnGearClickListener> captor = ArgumentCaptor.forClass(GearPreference.OnGearClickListener.class);
    // setting a null onGearClickListener removes the gear from view
    mController.updateState(mockPref);
    verify(mockPref).setOnGearClickListener(captor.capture());
    captor.getAllValues().forEach(listener -> assertThat(listener).isNull());
}
Also used : GearPreference(com.android.settings.widget.GearPreference) Test(org.junit.Test)

Example 10 with GearPreference

use of com.android.settings.widget.GearPreference in project android_packages_apps_Settings by SudaMod.

the class TextToSpeechSettings method initSettings.

private void initSettings() {
    final ContentResolver resolver = getContentResolver();
    // Set up the default rate and pitch.
    mDefaultRate = android.provider.Settings.Secure.getInt(resolver, TTS_DEFAULT_RATE, TextToSpeech.Engine.DEFAULT_RATE);
    mDefaultPitch = android.provider.Settings.Secure.getInt(resolver, TTS_DEFAULT_PITCH, TextToSpeech.Engine.DEFAULT_PITCH);
    mDefaultRatePref.setProgress(getSeekBarProgressFromValue(KEY_DEFAULT_RATE, mDefaultRate));
    mDefaultRatePref.setOnPreferenceChangeListener(this);
    mDefaultRatePref.setMax(getSeekBarProgressFromValue(KEY_DEFAULT_RATE, MAX_SPEECH_RATE));
    mDefaultPitchPref.setProgress(getSeekBarProgressFromValue(KEY_DEFAULT_PITCH, mDefaultPitch));
    mDefaultPitchPref.setOnPreferenceChangeListener(this);
    mDefaultPitchPref.setMax(getSeekBarProgressFromValue(KEY_DEFAULT_PITCH, MAX_SPEECH_PITCH));
    if (mTts != null) {
        mCurrentEngine = mTts.getCurrentEngine();
        mTts.setSpeechRate(mDefaultRate / 100.0f);
        mTts.setPitch(mDefaultPitch / 100.0f);
    }
    SettingsActivity activity = null;
    if (getActivity() instanceof SettingsActivity) {
        activity = (SettingsActivity) getActivity();
    } else {
        throw new IllegalStateException("TextToSpeechSettings used outside a " + "Settings");
    }
    if (mCurrentEngine != null) {
        EngineInfo info = mEnginesHelper.getEngineInfo(mCurrentEngine);
        Preference mEnginePreference = findPreference(KEY_TTS_ENGINE_PREFERENCE);
        ((GearPreference) mEnginePreference).setOnGearClickListener(this);
        mEnginePreference.setSummary(info.label);
    }
    checkVoiceData(mCurrentEngine);
}
Also used : GearPreference(com.android.settings.widget.GearPreference) EngineInfo(android.speech.tts.TextToSpeech.EngineInfo) SeekBarPreference(com.android.settings.widget.SeekBarPreference) ListPreference(android.support.v7.preference.ListPreference) LayoutPreference(com.android.settings.applications.LayoutPreference) GearPreference(com.android.settings.widget.GearPreference) Preference(android.support.v7.preference.Preference) SettingsActivity(com.android.settings.SettingsActivity) ContentResolver(android.content.ContentResolver)

Aggregations

GearPreference (com.android.settings.widget.GearPreference)34 Test (org.junit.Test)14 Preference (android.support.v7.preference.Preference)11 ComponentName (android.content.ComponentName)7 ContentResolver (android.content.ContentResolver)7 EngineInfo (android.speech.tts.TextToSpeech.EngineInfo)7 SettingsActivity (com.android.settings.SettingsActivity)7 SeekBarPreference (com.android.settings.widget.SeekBarPreference)7 DreamInfo (com.android.settingslib.dream.DreamBackend.DreamInfo)7 ListPreference (android.support.v7.preference.ListPreference)6 LayoutPreference (com.android.settings.applications.LayoutPreference)6 Activity (android.app.Activity)5 PersistableBundle (android.os.PersistableBundle)5 UserManager (android.os.UserManager)5 SwitchPreference (android.support.v14.preference.SwitchPreference)5 PreferenceGroup (android.support.v7.preference.PreferenceGroup)5 PreferenceScreen (android.support.v7.preference.PreferenceScreen)5 CarrierConfigManager (android.telephony.CarrierConfigManager)5 TelephonyManager (android.telephony.TelephonyManager)5 RestrictedPreference (com.android.settingslib.RestrictedPreference)5