Search in sources :

Example 21 with EnforcedAdmin

use of com.android.settingslib.RestrictedLockUtils.EnforcedAdmin in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class LocationSettings method changeManagedProfileLocationAccessStatus.

private void changeManagedProfileLocationAccessStatus(boolean mainSwitchOn) {
    if (mManagedProfileSwitch == null) {
        return;
    }
    mManagedProfileSwitch.setOnPreferenceClickListener(null);
    final EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(getActivity(), UserManager.DISALLOW_SHARE_LOCATION, mManagedProfile.getIdentifier());
    final boolean isRestrictedByBase = isManagedProfileRestrictedByBase();
    if (!isRestrictedByBase && admin != null) {
        mManagedProfileSwitch.setDisabledByAdmin(admin);
        mManagedProfileSwitch.setChecked(false);
    } else {
        boolean enabled = mainSwitchOn;
        mManagedProfileSwitch.setEnabled(enabled);
        int summaryResId = R.string.switch_off_text;
        if (!enabled) {
            mManagedProfileSwitch.setChecked(false);
        } else {
            mManagedProfileSwitch.setChecked(!isRestrictedByBase);
            summaryResId = (isRestrictedByBase ? R.string.switch_off_text : R.string.switch_on_text);
            mManagedProfileSwitch.setOnPreferenceClickListener(mManagedProfileSwitchClickListener);
        }
        mManagedProfileSwitch.setSummary(summaryResId);
    }
}
Also used : EnforcedAdmin(com.android.settingslib.RestrictedLockUtils.EnforcedAdmin)

Example 22 with EnforcedAdmin

use of com.android.settingslib.RestrictedLockUtils.EnforcedAdmin 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)

Example 23 with EnforcedAdmin

use of com.android.settingslib.RestrictedLockUtils.EnforcedAdmin in project android_frameworks_base by crdroidandroid.

the class RestrictedPreferenceHelper method checkRestrictionAndSetDisabled.

/**
     * Set the user restriction that is used to disable this preference.
     *
     * @param userRestriction constant from {@link android.os.UserManager}
     * @param userId user to check the restriction for.
     */
public void checkRestrictionAndSetDisabled(String userRestriction, int userId) {
    EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(mContext, userRestriction, userId);
    setDisabledByAdmin(admin);
}
Also used : EnforcedAdmin(com.android.settingslib.RestrictedLockUtils.EnforcedAdmin)

Example 24 with EnforcedAdmin

use of com.android.settingslib.RestrictedLockUtils.EnforcedAdmin in project platform_frameworks_base by android.

the class UserSwitcherController method checkIfAddUserDisallowedByAdminOnly.

private void checkIfAddUserDisallowedByAdminOnly(UserRecord record) {
    EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(mContext, UserManager.DISALLOW_ADD_USER, ActivityManager.getCurrentUser());
    if (admin != null && !RestrictedLockUtils.hasBaseUserRestriction(mContext, UserManager.DISALLOW_ADD_USER, ActivityManager.getCurrentUser())) {
        record.isDisabledByAdmin = true;
        record.enforcedAdmin = admin;
    } else {
        record.isDisabledByAdmin = false;
        record.enforcedAdmin = null;
    }
}
Also used : EnforcedAdmin(com.android.settingslib.RestrictedLockUtils.EnforcedAdmin)

Example 25 with EnforcedAdmin

use of com.android.settingslib.RestrictedLockUtils.EnforcedAdmin in project platform_frameworks_base by android.

the class QSTile method checkIfRestrictionEnforcedByAdminOnly.

protected void checkIfRestrictionEnforcedByAdminOnly(State state, String userRestriction) {
    EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(mContext, userRestriction, ActivityManager.getCurrentUser());
    if (admin != null && !RestrictedLockUtils.hasBaseUserRestriction(mContext, userRestriction, ActivityManager.getCurrentUser())) {
        state.disabledByPolicy = true;
        state.enforcedAdmin = admin;
    } else {
        state.disabledByPolicy = false;
        state.enforcedAdmin = null;
    }
}
Also used : EnforcedAdmin(com.android.settingslib.RestrictedLockUtils.EnforcedAdmin)

Aggregations

EnforcedAdmin (com.android.settingslib.RestrictedLockUtils.EnforcedAdmin)42 View (android.view.View)5 Context (android.content.Context)4 UserManager (android.os.UserManager)3 RestrictedPreference (com.android.settingslib.RestrictedPreference)3 ComponentName (android.content.ComponentName)2 Intent (android.content.Intent)2 Drawable (android.graphics.drawable.Drawable)2 Preference (android.support.v7.preference.Preference)2 TextView (android.widget.TextView)2 AccessibilityServiceInfo (android.accessibilityservice.AccessibilityServiceInfo)1 Activity (android.app.Activity)1 DevicePolicyManager (android.app.admin.DevicePolicyManager)1 ContentResolver (android.content.ContentResolver)1 ActivityInfo (android.content.pm.ActivityInfo)1 PackageManager (android.content.pm.PackageManager)1 ResolveInfo (android.content.pm.ResolveInfo)1 ServiceInfo (android.content.pm.ServiceInfo)1 ConnectivityManager (android.net.ConnectivityManager)1 Bundle (android.os.Bundle)1