Search in sources :

Example 1 with RestrictedPreference

use of com.android.settingslib.RestrictedPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SoundSettings method onResume.

@Override
public void onResume() {
    super.onResume();
    lookupRingtoneNames();
    mSettingsObserver.register(true);
    mReceiver.register(true);
    updateRingOrNotificationPreference();
    updateEffectsSuppressor();
    for (VolumeSeekBarPreference volumePref : mVolumePrefs) {
        volumePref.onActivityResume();
    }
    if (mIncreasingRingVolume != null) {
        mIncreasingRingVolume.onActivityResume();
    }
    final EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(mContext, UserManager.DISALLOW_ADJUST_VOLUME, UserHandle.myUserId());
    final boolean hasBaseRestriction = RestrictedLockUtils.hasBaseUserRestriction(mContext, UserManager.DISALLOW_ADJUST_VOLUME, UserHandle.myUserId());
    for (String key : RESTRICTED_KEYS) {
        Preference pref = findPreference(key);
        if (pref != null) {
            pref.setEnabled(!hasBaseRestriction);
        }
        if (pref instanceof RestrictedPreference && !hasBaseRestriction) {
            ((RestrictedPreference) pref).setDisabledByAdmin(admin);
        }
    }
}
Also used : RestrictedPreference(com.android.settingslib.RestrictedPreference) RestrictedPreference(com.android.settingslib.RestrictedPreference) TwoStatePreference(android.support.v7.preference.TwoStatePreference) Preference(android.support.v7.preference.Preference) RingtonePreference(com.android.settings.RingtonePreference) EnforcedAdmin(com.android.settingslib.RestrictedLockUtils.EnforcedAdmin)

Example 2 with RestrictedPreference

use of com.android.settingslib.RestrictedPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WirelessSettings method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
        mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG);
    }
    log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage);
    mContext = getActivity();
    mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    mPm = getPackageManager();
    mUm = (UserManager) getSystemService(Context.USER_SERVICE);
    addPreferencesFromResource(R.xml.wireless_settings);
    final boolean isAdmin = mUm.isAdminUser();
    final Activity activity = getActivity();
    mAirplaneModePreference = (SwitchPreference) findPreference(KEY_TOGGLE_AIRPLANE);
    SwitchPreference nfc = (SwitchPreference) findPreference(KEY_TOGGLE_NFC);
    RestrictedPreference androidBeam = (RestrictedPreference) findPreference(KEY_ANDROID_BEAM_SETTINGS);
    PreferenceScreen nfcPayment = (PreferenceScreen) findPreference(KEY_NFC_PAYMENT_SETTINGS);
    PreferenceCategory nfcCategory = (PreferenceCategory) findPreference(KEY_NFC_CATEGORY_SETTINGS);
    mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
    mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam, nfcPayment);
    mButtonWfc = (PreferenceScreen) findPreference(KEY_WFC_SETTINGS);
    String toggleable = Settings.Global.getString(activity.getContentResolver(), Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
    //enable/disable wimax depending on the value in config.xml
    final boolean isWimaxEnabled = isAdmin && this.getResources().getBoolean(com.android.internal.R.bool.config_wimaxEnabled);
    if (!isWimaxEnabled || RestrictedLockUtils.hasBaseUserRestriction(activity, UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS, UserHandle.myUserId())) {
        PreferenceScreen root = getPreferenceScreen();
        Preference ps = findPreference(KEY_WIMAX_SETTINGS);
        if (ps != null)
            root.removePreference(ps);
    } else {
        if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX) && isWimaxEnabled) {
            Preference ps = findPreference(KEY_WIMAX_SETTINGS);
            ps.setDependency(KEY_TOGGLE_AIRPLANE);
        }
    }
    // Manually set dependencies for Wifi when not toggleable.
    if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
        findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
    }
    // TODO: http://b/23693383
    if (!isAdmin || RestrictedLockUtils.hasBaseUserRestriction(activity, UserManager.DISALLOW_CONFIG_VPN, UserHandle.myUserId())) {
        removePreference(KEY_VPN_SETTINGS);
    }
    // Manually set dependencies for Bluetooth when not toggleable.
    if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
    // No bluetooth-dependent items in the list. Code kept in case one is added later.
    }
    // Manually set dependencies for NFC when not toggleable.
    if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
        findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
        findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
        findPreference(KEY_NFC_PAYMENT_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
    }
    // Remove NFC if not available
    mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
    if (mNfcAdapter == null) {
        getPreferenceScreen().removePreference(nfcCategory);
        mNfcEnabler = null;
    } else if (!mPm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
        // Only show if we have the HCE feature
        nfcCategory.removePreference(nfcPayment);
    }
    // if it's a wifi-only device, or for MSIM devices
    if (!isAdmin || Utils.isWifiOnly(getActivity()) || Utils.showSimCardTile(getActivity()) || RestrictedLockUtils.hasBaseUserRestriction(activity, UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS, UserHandle.myUserId())) {
        removePreference(KEY_MOBILE_NETWORK_SETTINGS);
        removePreference(KEY_MANAGE_MOBILE_PLAN);
    }
    // Remove Mobile Network Settings and Manage Mobile Plan
    // if config_show_mobile_plan sets false.
    final boolean isMobilePlanEnabled = this.getResources().getBoolean(R.bool.config_show_mobile_plan);
    if (!isMobilePlanEnabled) {
        Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN);
        if (pref != null) {
            removePreference(KEY_MANAGE_MOBILE_PLAN);
        }
    }
    // Remove Airplane Mode settings if it's a stationary device such as a TV.
    if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
        removePreference(KEY_TOGGLE_AIRPLANE);
    }
    // Enable Proxy selector settings if allowed.
    Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
    final DevicePolicyManager mDPM = (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
    // proxy UI disabled until we have better app support
    getPreferenceScreen().removePreference(mGlobalProxy);
    mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
    // Disable Tethering if it's not allowed or if it's a wifi-only device
    final ConnectivityManager cm = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
    final boolean adminDisallowedTetherConfig = RestrictedLockUtils.checkIfRestrictionEnforced(activity, UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId()) != null;
    if ((!cm.isTetheringSupported() && !adminDisallowedTetherConfig) || RestrictedLockUtils.hasBaseUserRestriction(activity, UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId())) {
        getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
    } else if (!adminDisallowedTetherConfig) {
        Preference p = findPreference(KEY_TETHER_SETTINGS);
        p.setTitle(com.android.settingslib.Utils.getTetheringLabel(cm));
        // Grey out if provisioning is not available.
        p.setEnabled(!TetherSettings.isProvisioningNeededButUnavailable(getActivity()));
    }
    // Remove network reset if not allowed
    if (RestrictedLockUtils.hasBaseUserRestriction(activity, UserManager.DISALLOW_NETWORK_RESET, UserHandle.myUserId())) {
        removePreference(KEY_NETWORK_RESET);
    }
    // Enable link to CMAS app settings depending on the value in config.xml.
    boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean(com.android.internal.R.bool.config_cellBroadcastAppLinks);
    try {
        if (isCellBroadcastAppLinkEnabled) {
            if (mPm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver") == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
                // CMAS app disabled
                isCellBroadcastAppLinkEnabled = false;
            }
        }
    } catch (IllegalArgumentException ignored) {
        // CMAS app not installed
        isCellBroadcastAppLinkEnabled = false;
    }
    if (!mUm.isAdminUser() || !isCellBroadcastAppLinkEnabled || RestrictedLockUtils.hasBaseUserRestriction(mContext, UserManager.DISALLOW_CONFIG_CELL_BROADCASTS, UserHandle.myUserId())) {
        removePreference(KEY_CELL_BROADCAST_SETTINGS);
    }
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) PreferenceScreen(android.support.v7.preference.PreferenceScreen) SwitchPreference(android.support.v14.preference.SwitchPreference) NfcEnabler(com.android.settings.nfc.NfcEnabler) ConnectivityManager(android.net.ConnectivityManager) Activity(android.app.Activity) RestrictedPreference(com.android.settingslib.RestrictedPreference) PreferenceCategory(android.support.v7.preference.PreferenceCategory) RestrictedPreference(com.android.settingslib.RestrictedPreference) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference)

Example 3 with RestrictedPreference

use of com.android.settingslib.RestrictedPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SecuritySettings method addTrustAgentSettings.

private void addTrustAgentSettings(PreferenceGroup securityCategory) {
    final boolean hasSecurity = mLockPatternUtils.isSecure(MY_USER_ID);
    ArrayList<TrustAgentComponentInfo> agents = getActiveTrustAgents(getActivity(), mLockPatternUtils, mDPM);
    for (int i = 0; i < agents.size(); i++) {
        final TrustAgentComponentInfo agent = agents.get(i);
        RestrictedPreference trustAgentPreference = new RestrictedPreference(securityCategory.getContext());
        trustAgentPreference.setKey(KEY_TRUST_AGENT);
        trustAgentPreference.setTitle(agent.title);
        trustAgentPreference.setSummary(agent.summary);
        // Create intent for this preference.
        Intent intent = new Intent();
        intent.setComponent(agent.componentName);
        intent.setAction(Intent.ACTION_MAIN);
        trustAgentPreference.setIntent(intent);
        // Add preference to the settings menu.
        securityCategory.addPreference(trustAgentPreference);
        trustAgentPreference.setDisabledByAdmin(agent.admin);
        if (!trustAgentPreference.isDisabledByAdmin() && !hasSecurity) {
            trustAgentPreference.setEnabled(false);
            trustAgentPreference.setSummary(R.string.disabled_because_no_backup_security);
        }
    }
}
Also used : RestrictedPreference(com.android.settingslib.RestrictedPreference) TrustAgentComponentInfo(com.android.settings.TrustAgentUtils.TrustAgentComponentInfo) Intent(android.content.Intent)

Example 4 with RestrictedPreference

use of com.android.settingslib.RestrictedPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SecuritySettings method disableIfPasswordQualityManaged.

/*
     * Sets the preference as disabled by admin if PASSWORD_QUALITY_MANAGED is set.
     * The preference must be a RestrictedPreference.
     */
private void disableIfPasswordQualityManaged(String preferenceKey, int userId) {
    final EnforcedAdmin admin = RestrictedLockUtils.checkIfPasswordQualityIsSet(getActivity(), userId);
    if (admin != null && mDPM.getPasswordQuality(admin.component, userId) == DevicePolicyManager.PASSWORD_QUALITY_MANAGED) {
        final RestrictedPreference pref = (RestrictedPreference) getPreferenceScreen().findPreference(preferenceKey);
        pref.setDisabledByAdmin(admin);
    }
}
Also used : RestrictedPreference(com.android.settingslib.RestrictedPreference) EnforcedAdmin(com.android.settingslib.RestrictedLockUtils.EnforcedAdmin)

Example 5 with RestrictedPreference

use of com.android.settingslib.RestrictedPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AccessibilitySettings method updateServicesPreferences.

private void updateServicesPreferences() {
    // Since services category is auto generated we have to do a pass
    // to generate it since services can come and go and then based on
    // the global accessibility state to decided whether it is enabled.
    // Generate.
    mServicesCategory.removeAll();
    AccessibilityManager accessibilityManager = AccessibilityManager.getInstance(getActivity());
    List<AccessibilityServiceInfo> installedServices = accessibilityManager.getInstalledAccessibilityServiceList();
    Set<ComponentName> enabledServices = AccessibilityUtils.getEnabledServicesFromSettings(getActivity());
    List<String> permittedServices = mDpm.getPermittedAccessibilityServices(UserHandle.myUserId());
    final boolean accessibilityEnabled = Settings.Secure.getInt(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1;
    for (int i = 0, count = installedServices.size(); i < count; ++i) {
        AccessibilityServiceInfo info = installedServices.get(i);
        RestrictedPreference preference = new RestrictedPreference(getActivity());
        String title = info.getResolveInfo().loadLabel(getPackageManager()).toString();
        ServiceInfo serviceInfo = info.getResolveInfo().serviceInfo;
        ComponentName componentName = new ComponentName(serviceInfo.packageName, serviceInfo.name);
        preference.setKey(componentName.flattenToString());
        preference.setTitle(title);
        final boolean serviceEnabled = accessibilityEnabled && enabledServices.contains(componentName);
        String serviceEnabledString;
        if (serviceEnabled) {
            serviceEnabledString = getString(R.string.accessibility_feature_state_on);
        } else {
            serviceEnabledString = getString(R.string.accessibility_feature_state_off);
        }
        // Disable all accessibility services that are not permitted.
        String packageName = serviceInfo.packageName;
        boolean serviceAllowed = permittedServices == null || permittedServices.contains(packageName);
        if (!serviceAllowed && !serviceEnabled) {
            EnforcedAdmin admin = RestrictedLockUtils.checkIfAccessibilityServiceDisallowed(getActivity(), serviceInfo.packageName, UserHandle.myUserId());
            if (admin != null) {
                preference.setDisabledByAdmin(admin);
            } else {
                preference.setEnabled(false);
            }
        } else {
            preference.setEnabled(true);
        }
        preference.setSummary(serviceEnabledString);
        preference.setOrder(i);
        preference.setFragment(ToggleAccessibilityServicePreferenceFragment.class.getName());
        preference.setPersistent(true);
        Bundle extras = preference.getExtras();
        extras.putString(EXTRA_PREFERENCE_KEY, preference.getKey());
        extras.putBoolean(EXTRA_CHECKED, serviceEnabled);
        extras.putString(EXTRA_TITLE, title);
        String description = info.loadDescription(getPackageManager());
        if (TextUtils.isEmpty(description)) {
            description = getString(R.string.accessibility_service_default_description);
        }
        extras.putString(EXTRA_SUMMARY, description);
        String settingsClassName = info.getSettingsActivityName();
        if (!TextUtils.isEmpty(settingsClassName)) {
            extras.putString(EXTRA_SETTINGS_TITLE, getString(R.string.accessibility_menu_item_settings));
            extras.putString(EXTRA_SETTINGS_COMPONENT_NAME, new ComponentName(info.getResolveInfo().serviceInfo.packageName, settingsClassName).flattenToString());
        }
        extras.putParcelable(EXTRA_COMPONENT_NAME, componentName);
        mServicesCategory.addPreference(preference);
    }
    if (mServicesCategory.getPreferenceCount() == 0) {
        if (mNoServicesMessagePreference == null) {
            mNoServicesMessagePreference = new Preference(getPrefContext());
            mNoServicesMessagePreference.setPersistent(false);
            mNoServicesMessagePreference.setLayoutResource(R.layout.text_description_preference);
            mNoServicesMessagePreference.setSelectable(false);
            mNoServicesMessagePreference.setSummary(getString(R.string.accessibility_no_services_installed));
        }
        mServicesCategory.addPreference(mNoServicesMessagePreference);
    }
}
Also used : Bundle(android.os.Bundle) EnforcedAdmin(com.android.settingslib.RestrictedLockUtils.EnforcedAdmin) AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) ServiceInfo(android.content.pm.ServiceInfo) AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) AccessibilityManager(android.view.accessibility.AccessibilityManager) RestrictedPreference(com.android.settingslib.RestrictedPreference) ListPreference(android.support.v7.preference.ListPreference) RestrictedPreference(com.android.settingslib.RestrictedPreference) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) ComponentName(android.content.ComponentName)

Aggregations

RestrictedPreference (com.android.settingslib.RestrictedPreference)7 Preference (android.support.v7.preference.Preference)4 SwitchPreference (android.support.v14.preference.SwitchPreference)3 EnforcedAdmin (com.android.settingslib.RestrictedLockUtils.EnforcedAdmin)3 Intent (android.content.Intent)2 PreferenceScreen (android.support.v7.preference.PreferenceScreen)2 AccessibilityServiceInfo (android.accessibilityservice.AccessibilityServiceInfo)1 Activity (android.app.Activity)1 DevicePolicyManager (android.app.admin.DevicePolicyManager)1 ComponentName (android.content.ComponentName)1 Context (android.content.Context)1 ServiceInfo (android.content.pm.ServiceInfo)1 ConnectivityManager (android.net.ConnectivityManager)1 Bundle (android.os.Bundle)1 PersistableBundle (android.os.PersistableBundle)1 UserManager (android.os.UserManager)1 Settings (android.provider.Settings)1 ListPreference (android.support.v7.preference.ListPreference)1 PreferenceCategory (android.support.v7.preference.PreferenceCategory)1 PreferenceGroup (android.support.v7.preference.PreferenceGroup)1