use of android.view.accessibility.AccessibilityManager in project android_packages_apps_Settings by crdroidandroid.
the class AccessibilitySettings method updateServicePreferences.
private void updateServicePreferences() {
// 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.
ArrayList<Preference> servicePreferences = new ArrayList<>(mServicePreferenceToPreferenceCategoryMap.keySet());
for (int i = 0; i < servicePreferences.size(); i++) {
Preference service = servicePreferences.get(i);
PreferenceCategory category = mServicePreferenceToPreferenceCategoryMap.get(service);
category.removePreference(service);
}
initializePreBundledServicesMapFromArray(CATEGORY_SCREEN_READER, R.array.config_preinstalled_screen_reader_services);
initializePreBundledServicesMapFromArray(CATEGORY_AUDIO_AND_CAPTIONS, R.array.config_preinstalled_audio_and_caption_services);
initializePreBundledServicesMapFromArray(CATEGORY_DISPLAY, R.array.config_preinstalled_display_services);
initializePreBundledServicesMapFromArray(CATEGORY_INTERACTION_CONTROL, R.array.config_preinstalled_interaction_control_services);
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;
PreferenceCategory downloadedServicesCategory = mCategoryToPrefCategoryMap.get(CATEGORY_DOWNLOADED_SERVICES);
// Temporarily add the downloaded services category back if it was previously removed.
if (findPreference(CATEGORY_DOWNLOADED_SERVICES) == null) {
getPreferenceScreen().addPreference(downloadedServicesCategory);
}
for (int i = 0, count = installedServices.size(); i < count; ++i) {
AccessibilityServiceInfo info = installedServices.get(i);
RestrictedPreference preference = new RestrictedPreference(downloadedServicesCategory.getContext());
String title = info.getResolveInfo().loadLabel(getPackageManager()).toString();
Drawable icon;
if (info.getResolveInfo().getIconResource() == 0) {
icon = ContextCompat.getDrawable(getContext(), R.mipmap.ic_accessibility_generic);
} else {
icon = info.getResolveInfo().loadIcon(getPackageManager());
}
ServiceInfo serviceInfo = info.getResolveInfo().serviceInfo;
String packageName = serviceInfo.packageName;
ComponentName componentName = new ComponentName(packageName, serviceInfo.name);
String componentNameKey = componentName.flattenToString();
preference.setKey(componentName.flattenToString());
preference.setTitle(title);
preference.setIcon(icon);
final boolean serviceEnabled = accessibilityEnabled && enabledServices.contains(componentName);
final String serviceState = serviceEnabled ? getString(R.string.accessibility_summary_state_enabled) : getString(R.string.accessibility_summary_state_disabled);
final CharSequence serviceSummary = info.loadSummary(getPackageManager());
final String stateSummaryCombo = getString(R.string.preference_summary_default_combination, serviceState, serviceSummary);
preference.setSummary((TextUtils.isEmpty(serviceSummary)) ? serviceState : stateSummaryCombo);
// Disable all accessibility services that are not permitted.
boolean serviceAllowed = permittedServices == null || permittedServices.contains(packageName);
if (!serviceAllowed && !serviceEnabled) {
EnforcedAdmin admin = RestrictedLockUtils.checkIfAccessibilityServiceDisallowed(getActivity(), packageName, UserHandle.myUserId());
if (admin != null) {
preference.setDisabledByAdmin(admin);
} else {
preference.setEnabled(false);
}
} else {
preference.setEnabled(true);
}
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(packageName, settingsClassName).flattenToString());
}
extras.putParcelable(EXTRA_COMPONENT_NAME, componentName);
PreferenceCategory prefCategory = downloadedServicesCategory;
// Set the appropriate category if the service comes pre-installed.
if (mPreBundledServiceComponentToCategoryMap.containsKey(componentName)) {
prefCategory = mPreBundledServiceComponentToCategoryMap.get(componentName);
}
preference.setOrder(FIRST_PREFERENCE_IN_CATEGORY_INDEX);
prefCategory.addPreference(preference);
mServicePreferenceToPreferenceCategoryMap.put(preference, prefCategory);
}
// If the user has not installed any additional services, hide the category.
if (downloadedServicesCategory.getPreferenceCount() == 0) {
PreferenceScreen screen = getPreferenceScreen();
screen.removePreference(downloadedServicesCategory);
}
}
use of android.view.accessibility.AccessibilityManager in project android_packages_apps_Settings by crdroidandroid.
the class AccessibilitySettingsForSetupWizard method findService.
private AccessibilityServiceInfo findService(String packageName, String serviceName) {
final AccessibilityManager manager = getActivity().getSystemService(AccessibilityManager.class);
final List<AccessibilityServiceInfo> accessibilityServices = manager.getInstalledAccessibilityServiceList();
for (AccessibilityServiceInfo info : accessibilityServices) {
ServiceInfo serviceInfo = info.getResolveInfo().serviceInfo;
if (packageName.equals(serviceInfo.packageName) && serviceName.equals(serviceInfo.name)) {
return info;
}
}
return null;
}
use of android.view.accessibility.AccessibilityManager in project android_packages_apps_Settings by SudaMod.
the class MagnificationPreferenceFragment method getConfigurationWarningStringForSecureSettingsKey.
static CharSequence getConfigurationWarningStringForSecureSettingsKey(String key, Context context) {
if (!Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED.equals(key)) {
return null;
}
if (Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, 0) == 0) {
return null;
}
final AccessibilityManager am = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
final String assignedId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ACCESSIBILITY_BUTTON_TARGET_COMPONENT);
if (!TextUtils.isEmpty(assignedId) && !MAGNIFICATION_COMPONENT_ID.equals(assignedId)) {
final ComponentName assignedComponentName = ComponentName.unflattenFromString(assignedId);
final List<AccessibilityServiceInfo> activeServices = am.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_ALL_MASK);
final int serviceCount = activeServices.size();
for (int i = 0; i < serviceCount; i++) {
final AccessibilityServiceInfo info = activeServices.get(i);
if (info.getComponentName().equals(assignedComponentName)) {
final CharSequence assignedServiceName = info.getResolveInfo().loadLabel(context.getPackageManager());
return context.getString(R.string.accessibility_screen_magnification_navbar_configuration_warning, assignedServiceName);
}
}
}
return null;
}
use of android.view.accessibility.AccessibilityManager in project android_packages_apps_Settings by SudaMod.
the class ShortcutServicePickerFragment method getCandidates.
@Override
protected List<? extends DefaultAppInfo> getCandidates() {
final AccessibilityManager accessibilityManager = getContext().getSystemService(AccessibilityManager.class);
final List<AccessibilityServiceInfo> installedServices = accessibilityManager.getInstalledAccessibilityServiceList();
final int numInstalledServices = installedServices.size();
List<DefaultAppInfo> candidates = new ArrayList<>(numInstalledServices);
for (int i = 0; i < numInstalledServices; i++) {
AccessibilityServiceInfo installedServiceInfo = installedServices.get(i);
candidates.add(new DefaultAppInfo(mPm, UserHandle.myUserId(), installedServiceInfo.getComponentName(), (String) installedServiceInfo.loadSummary(mPm.getPackageManager()), true));
}
return candidates;
}
use of android.view.accessibility.AccessibilityManager in project android_packages_apps_Settings by DirtyUnicorns.
the class MagnificationPreferenceFragment method getConfigurationWarningStringForSecureSettingsKey.
static CharSequence getConfigurationWarningStringForSecureSettingsKey(String key, Context context) {
if (!Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED.equals(key)) {
return null;
}
if (Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, 0) == 0) {
return null;
}
final AccessibilityManager am = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
final String assignedId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ACCESSIBILITY_BUTTON_TARGET_COMPONENT);
if (!TextUtils.isEmpty(assignedId) && !MAGNIFICATION_COMPONENT_ID.equals(assignedId)) {
final ComponentName assignedComponentName = ComponentName.unflattenFromString(assignedId);
final List<AccessibilityServiceInfo> activeServices = am.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_ALL_MASK);
final int serviceCount = activeServices.size();
for (int i = 0; i < serviceCount; i++) {
final AccessibilityServiceInfo info = activeServices.get(i);
if (info.getComponentName().equals(assignedComponentName)) {
final CharSequence assignedServiceName = info.getResolveInfo().loadLabel(context.getPackageManager());
return context.getString(R.string.accessibility_screen_magnification_navbar_configuration_warning, assignedServiceName);
}
}
}
return null;
}
Aggregations