1341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette/* 2341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette * Copyright (C) 2009 The Android Open Source Project 3341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette * 4341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette * Licensed under the Apache License, Version 2.0 (the "License"); 5341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette * you may not use this file except in compliance with the License. 6341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette * You may obtain a copy of the License at 7341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette * 8341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette * http://www.apache.org/licenses/LICENSE-2.0 9341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette * 10341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette * Unless required by applicable law or agreed to in writing, software 11341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette * distributed under the License is distributed on an "AS IS" BASIS, 12341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette * See the License for the specific language governing permissions and 14341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette * limitations under the License. 15341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette */ 16341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 17341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverettepackage com.android.settings.accessibility; 18341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 19341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport android.accessibilityservice.AccessibilityServiceInfo; 20341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport android.app.ActivityManagerNative; 21333f2bc71a0866053f8e2fce8efbfb0bcec68811Kenny Guyimport android.app.admin.DevicePolicyManager; 22341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport android.content.ComponentName; 23341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport android.content.Context; 24b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslavimport android.content.pm.PackageManager; 25341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport android.content.pm.ResolveInfo; 26341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport android.content.pm.ServiceInfo; 27341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport android.content.res.Configuration; 28341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport android.net.Uri; 29341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport android.os.Bundle; 30341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport android.os.Handler; 31341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport android.os.RemoteException; 32333f2bc71a0866053f8e2fce8efbfb0bcec68811Kenny Guyimport android.os.UserHandle; 33341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport android.preference.ListPreference; 34341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport android.preference.Preference; 35341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport android.preference.PreferenceCategory; 36341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport android.preference.PreferenceScreen; 3704e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viveretteimport android.preference.SwitchPreference; 38b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslavimport android.provider.SearchIndexableResource; 39341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport android.provider.Settings; 40341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport android.text.TextUtils; 41341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport android.text.TextUtils.SimpleStringSplitter; 42341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport android.view.KeyCharacterMap; 43341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport android.view.KeyEvent; 44341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport android.view.accessibility.AccessibilityManager; 45341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport com.android.internal.content.PackageMonitor; 468a963babe2e36b7a41f77b8d2598c97658196e58Chris Wrenimport com.android.internal.logging.MetricsLogger; 47341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport com.android.internal.view.RotationPolicy; 48341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport com.android.internal.view.RotationPolicy.RotationPolicyListener; 49341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport com.android.settings.DialogCreatable; 50341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport com.android.settings.R; 51341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport com.android.settings.SettingsPreferenceFragment; 52341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport com.android.settings.Utils; 53b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslavimport com.android.settings.search.BaseSearchIndexProvider; 54b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslavimport com.android.settings.search.Indexable; 55b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslavimport com.android.settings.search.SearchIndexableRaw; 56341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 57b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslavimport java.util.ArrayList; 58341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport java.util.HashMap; 59341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport java.util.HashSet; 60341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport java.util.List; 61341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport java.util.Map; 62341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport java.util.Set; 63341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 64341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette/** 65341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette * Activity with the accessibility settings. 66341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette */ 67341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverettepublic class AccessibilitySettings extends SettingsPreferenceFragment implements DialogCreatable, 68b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav Preference.OnPreferenceChangeListener, Indexable { 69341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 70341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private static final float LARGE_FONT_SCALE = 1.3f; 71341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 72341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette static final char ENABLED_ACCESSIBILITY_SERVICES_SEPARATOR = ':'; 73341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 74341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // Preference categories 75341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private static final String SERVICES_CATEGORY = "services_category"; 76341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private static final String SYSTEM_CATEGORY = "system_category"; 77341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 78341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // Preferences 79341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private static final String TOGGLE_LARGE_TEXT_PREFERENCE = 80341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette "toggle_large_text_preference"; 81fc72424cd7c3bbb6d45afb77e5ffb619d38ef641Chris Craik private static final String TOGGLE_HIGH_TEXT_CONTRAST_PREFERENCE = 82fc72424cd7c3bbb6d45afb77e5ffb619d38ef641Chris Craik "toggle_high_text_contrast_preference"; 8304e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette private static final String TOGGLE_INVERSION_PREFERENCE = 8404e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette "toggle_inversion_preference"; 85341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private static final String TOGGLE_POWER_BUTTON_ENDS_CALL_PREFERENCE = 86341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette "toggle_power_button_ends_call_preference"; 87341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private static final String TOGGLE_LOCK_SCREEN_ROTATION_PREFERENCE = 88341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette "toggle_lock_screen_rotation_preference"; 89341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private static final String TOGGLE_SPEAK_PASSWORD_PREFERENCE = 90341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette "toggle_speak_password_preference"; 91341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private static final String SELECT_LONG_PRESS_TIMEOUT_PREFERENCE = 92341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette "select_long_press_timeout_preference"; 93341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private static final String ENABLE_ACCESSIBILITY_GESTURE_PREFERENCE_SCREEN = 94341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette "enable_global_gesture_preference_screen"; 95cc0e782871eb6b946ded880e391866f27953654bAlan Viverette private static final String CAPTIONING_PREFERENCE_SCREEN = 96cc0e782871eb6b946ded880e391866f27953654bAlan Viverette "captioning_preference_screen"; 97341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private static final String DISPLAY_MAGNIFICATION_PREFERENCE_SCREEN = 98341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette "screen_magnification_preference_screen"; 99fc0ab213b8637f4d9177ff5f08c4fdc155bbb941Alan Viverette private static final String DISPLAY_DALTONIZER_PREFERENCE_SCREEN = 100fc0ab213b8637f4d9177ff5f08c4fdc155bbb941Alan Viverette "daltonizer_preference_screen"; 101341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 102341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // Extras passed to sub-fragments. 103341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette static final String EXTRA_PREFERENCE_KEY = "preference_key"; 104341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette static final String EXTRA_CHECKED = "checked"; 105341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette static final String EXTRA_TITLE = "title"; 106341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette static final String EXTRA_SUMMARY = "summary"; 107341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette static final String EXTRA_SETTINGS_TITLE = "settings_title"; 108341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette static final String EXTRA_COMPONENT_NAME = "component_name"; 109341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette static final String EXTRA_SETTINGS_COMPONENT_NAME = "settings_component_name"; 110341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 111341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // Timeout before we update the services if packages are added/removed 112341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // since the AccessibilityManagerService has to do that processing first 113341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // to generate the AccessibilityServiceInfo we need for proper 114341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // presentation. 115341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private static final long DELAY_UPDATE_SERVICES_MILLIS = 1000; 116341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 117341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // Auxiliary members. 118341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette final static SimpleStringSplitter sStringColonSplitter = 119341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette new SimpleStringSplitter(ENABLED_ACCESSIBILITY_SERVICES_SEPARATOR); 120341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 121341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette static final Set<ComponentName> sInstalledServices = new HashSet<ComponentName>(); 122341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 123341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private final Map<String, String> mLongPressTimeoutValuetoTitleMap = 124341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette new HashMap<String, String>(); 125341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 126341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private final Configuration mCurConfig = new Configuration(); 127341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 128341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private final Handler mHandler = new Handler(); 129341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 130341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private final Runnable mUpdateRunnable = new Runnable() { 131341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette @Override 132341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette public void run() { 133341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette loadInstalledServices(); 134341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette updateServicesPreferences(); 135341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 136341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette }; 137341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 138341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private final PackageMonitor mSettingsPackageMonitor = new PackageMonitor() { 139341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette @Override 140341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette public void onPackageAdded(String packageName, int uid) { 141341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette sendUpdate(); 142341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 143341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 144341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette @Override 145341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette public void onPackageAppeared(String packageName, int reason) { 146341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette sendUpdate(); 147341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 148341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 149341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette @Override 150341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette public void onPackageDisappeared(String packageName, int reason) { 151341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette sendUpdate(); 152341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 153341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 154341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette @Override 155341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette public void onPackageRemoved(String packageName, int uid) { 156341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette sendUpdate(); 157341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 158341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 159341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private void sendUpdate() { 160341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mHandler.postDelayed(mUpdateRunnable, DELAY_UPDATE_SERVICES_MILLIS); 161341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 162341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette }; 163341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 164341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private final SettingsContentObserver mSettingsContentObserver = 165341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette new SettingsContentObserver(mHandler) { 166341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette @Override 167341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette public void onChange(boolean selfChange, Uri uri) { 168341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette loadInstalledServices(); 169341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette updateServicesPreferences(); 170341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 171341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette }; 172341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 173341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private final RotationPolicyListener mRotationPolicyListener = new RotationPolicyListener() { 174341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette @Override 175341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette public void onChange() { 176341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette updateLockScreenRotationCheckbox(); 177341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 178341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette }; 179341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 180341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // Preference controls. 181341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private PreferenceCategory mServicesCategory; 182341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private PreferenceCategory mSystemsCategory; 183341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 184d8ae35ea50464da2f5c1933e831e0aced933d3b4Fabrice Di Meglio private SwitchPreference mToggleLargeTextPreference; 185d8ae35ea50464da2f5c1933e831e0aced933d3b4Fabrice Di Meglio private SwitchPreference mToggleHighTextContrastPreference; 186d8ae35ea50464da2f5c1933e831e0aced933d3b4Fabrice Di Meglio private SwitchPreference mTogglePowerButtonEndsCallPreference; 187d8ae35ea50464da2f5c1933e831e0aced933d3b4Fabrice Di Meglio private SwitchPreference mToggleLockScreenRotationPreference; 188d8ae35ea50464da2f5c1933e831e0aced933d3b4Fabrice Di Meglio private SwitchPreference mToggleSpeakPasswordPreference; 189341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private ListPreference mSelectLongPressTimeoutPreference; 190341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private Preference mNoServicesMessagePreference; 191cc0e782871eb6b946ded880e391866f27953654bAlan Viverette private PreferenceScreen mCaptioningPreferenceScreen; 192341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private PreferenceScreen mDisplayMagnificationPreferenceScreen; 193341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private PreferenceScreen mGlobalGesturePreferenceScreen; 194fc0ab213b8637f4d9177ff5f08c4fdc155bbb941Alan Viverette private PreferenceScreen mDisplayDaltonizerPreferenceScreen; 19504e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette private SwitchPreference mToggleInversionPreference; 196341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 197341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private int mLongPressTimeoutDefault; 198341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 199333f2bc71a0866053f8e2fce8efbfb0bcec68811Kenny Guy private DevicePolicyManager mDpm; 200333f2bc71a0866053f8e2fce8efbfb0bcec68811Kenny Guy 201341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette @Override 2028a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren protected int getMetricsCategory() { 2038a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren return MetricsLogger.ACCESSIBILITY; 2048a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren } 2058a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren 2068a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren @Override 20723acc2bb8af7da000d72a8c1d8c28a2792200348Jason Monk protected int getHelpResource() { 20823acc2bb8af7da000d72a8c1d8c28a2792200348Jason Monk return R.string.help_uri_accessibility; 20923acc2bb8af7da000d72a8c1d8c28a2792200348Jason Monk } 21023acc2bb8af7da000d72a8c1d8c28a2792200348Jason Monk 21123acc2bb8af7da000d72a8c1d8c28a2792200348Jason Monk @Override 212341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette public void onCreate(Bundle icicle) { 213341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette super.onCreate(icicle); 214341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette addPreferencesFromResource(R.xml.accessibility_settings); 215341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette initializeAllPreferences(); 216333f2bc71a0866053f8e2fce8efbfb0bcec68811Kenny Guy mDpm = (DevicePolicyManager) (getActivity() 217333f2bc71a0866053f8e2fce8efbfb0bcec68811Kenny Guy .getSystemService(Context.DEVICE_POLICY_SERVICE)); 218341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 219341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 220341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette @Override 221341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette public void onResume() { 222341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette super.onResume(); 223341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette loadInstalledServices(); 224341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette updateAllPreferences(); 225341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 226341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mSettingsPackageMonitor.register(getActivity(), getActivity().getMainLooper(), false); 227341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mSettingsContentObserver.register(getContentResolver()); 228341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette if (RotationPolicy.isRotationSupported(getActivity())) { 229341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette RotationPolicy.registerRotationPolicyListener(getActivity(), 230341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mRotationPolicyListener); 231341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 232341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 233341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 234341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette @Override 235341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette public void onPause() { 236341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mSettingsPackageMonitor.unregister(); 237341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mSettingsContentObserver.unregister(getContentResolver()); 238341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette if (RotationPolicy.isRotationSupported(getActivity())) { 239341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette RotationPolicy.unregisterRotationPolicyListener(getActivity(), 240341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mRotationPolicyListener); 241341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 242341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette super.onPause(); 243341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 244341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 245341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette @Override 246341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette public boolean onPreferenceChange(Preference preference, Object newValue) { 24704e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette if (mSelectLongPressTimeoutPreference == preference) { 24804e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette handleLongPressTimeoutPreferenceChange((String) newValue); 24904e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette return true; 25004e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette } else if (mToggleInversionPreference == preference) { 25104e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette handleToggleInversionPreferenceChange((Boolean) newValue); 252341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette return true; 253341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 254341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette return false; 255341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 256341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 25704e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette private void handleLongPressTimeoutPreferenceChange(String stringValue) { 25804e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette Settings.Secure.putInt(getContentResolver(), 25904e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette Settings.Secure.LONG_PRESS_TIMEOUT, Integer.parseInt(stringValue)); 26004e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette mSelectLongPressTimeoutPreference.setSummary( 26104e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette mLongPressTimeoutValuetoTitleMap.get(stringValue)); 26204e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette } 26304e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette 26404e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette private void handleToggleInversionPreferenceChange(boolean checked) { 26504e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette Settings.Secure.putInt(getContentResolver(), 26604e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, (checked ? 1 : 0)); 26704e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette } 26804e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette 269341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette @Override 270341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { 271341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette if (mToggleLargeTextPreference == preference) { 272341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette handleToggleLargeTextPreferenceClick(); 273341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette return true; 274fc72424cd7c3bbb6d45afb77e5ffb619d38ef641Chris Craik } else if (mToggleHighTextContrastPreference == preference) { 275fc72424cd7c3bbb6d45afb77e5ffb619d38ef641Chris Craik handleToggleTextContrastPreferenceClick(); 276fc72424cd7c3bbb6d45afb77e5ffb619d38ef641Chris Craik return true; 277341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } else if (mTogglePowerButtonEndsCallPreference == preference) { 278341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette handleTogglePowerButtonEndsCallPreferenceClick(); 279341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette return true; 280341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } else if (mToggleLockScreenRotationPreference == preference) { 281341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette handleLockScreenRotationPreferenceClick(); 282341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette return true; 283341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } else if (mToggleSpeakPasswordPreference == preference) { 284341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette handleToggleSpeakPasswordPreferenceClick(); 285341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette return true; 286341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } else if (mGlobalGesturePreferenceScreen == preference) { 28704e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette handleToggleEnableAccessibilityGesturePreferenceClick(); 288341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette return true; 289341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } else if (mDisplayMagnificationPreferenceScreen == preference) { 290341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette handleDisplayMagnificationPreferenceScreenClick(); 291341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette return true; 292341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 293341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette return super.onPreferenceTreeClick(preferenceScreen, preference); 294341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 295341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 296341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private void handleToggleLargeTextPreferenceClick() { 297341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette try { 298341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mCurConfig.fontScale = mToggleLargeTextPreference.isChecked() ? LARGE_FONT_SCALE : 1; 299341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette ActivityManagerNative.getDefault().updatePersistentConfiguration(mCurConfig); 300341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } catch (RemoteException re) { 301341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette /* ignore */ 302341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 303341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 304341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 305fc72424cd7c3bbb6d45afb77e5ffb619d38ef641Chris Craik private void handleToggleTextContrastPreferenceClick() { 306fc72424cd7c3bbb6d45afb77e5ffb619d38ef641Chris Craik Settings.Secure.putInt(getContentResolver(), 307fc72424cd7c3bbb6d45afb77e5ffb619d38ef641Chris Craik Settings.Secure.ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED, 308fc72424cd7c3bbb6d45afb77e5ffb619d38ef641Chris Craik (mToggleHighTextContrastPreference.isChecked() ? 1 : 0)); 309fc72424cd7c3bbb6d45afb77e5ffb619d38ef641Chris Craik } 310fc72424cd7c3bbb6d45afb77e5ffb619d38ef641Chris Craik 311341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private void handleTogglePowerButtonEndsCallPreferenceClick() { 312341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette Settings.Secure.putInt(getContentResolver(), 313341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, 314341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette (mTogglePowerButtonEndsCallPreference.isChecked() 315341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette ? Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP 316341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette : Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_SCREEN_OFF)); 317341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 318341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 319341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private void handleLockScreenRotationPreferenceClick() { 320341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette RotationPolicy.setRotationLockForAccessibility(getActivity(), 321341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette !mToggleLockScreenRotationPreference.isChecked()); 322341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 323341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 324341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private void handleToggleSpeakPasswordPreferenceClick() { 325341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette Settings.Secure.putInt(getContentResolver(), 326341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD, 327341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mToggleSpeakPasswordPreference.isChecked() ? 1 : 0); 328341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 329341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 33004e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette private void handleToggleEnableAccessibilityGesturePreferenceClick() { 331341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette Bundle extras = mGlobalGesturePreferenceScreen.getExtras(); 332341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette extras.putString(EXTRA_TITLE, getString( 333341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette R.string.accessibility_global_gesture_preference_title)); 334341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette extras.putString(EXTRA_SUMMARY, getString( 335341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette R.string.accessibility_global_gesture_preference_description)); 336341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette extras.putBoolean(EXTRA_CHECKED, Settings.Global.getInt(getContentResolver(), 337341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1); 338341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette super.onPreferenceTreeClick(mGlobalGesturePreferenceScreen, 339341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mGlobalGesturePreferenceScreen); 340341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 341341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 342341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private void handleDisplayMagnificationPreferenceScreenClick() { 343341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette Bundle extras = mDisplayMagnificationPreferenceScreen.getExtras(); 344341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette extras.putString(EXTRA_TITLE, getString( 345341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette R.string.accessibility_screen_magnification_title)); 346341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette extras.putCharSequence(EXTRA_SUMMARY, getActivity().getResources().getText( 347341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette R.string.accessibility_screen_magnification_summary)); 348341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette extras.putBoolean(EXTRA_CHECKED, Settings.Secure.getInt(getContentResolver(), 349341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, 0) == 1); 350341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette super.onPreferenceTreeClick(mDisplayMagnificationPreferenceScreen, 351341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mDisplayMagnificationPreferenceScreen); 352341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 353341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 354341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private void initializeAllPreferences() { 355341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mServicesCategory = (PreferenceCategory) findPreference(SERVICES_CATEGORY); 356341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mSystemsCategory = (PreferenceCategory) findPreference(SYSTEM_CATEGORY); 357341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 358341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // Large text. 359341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mToggleLargeTextPreference = 360d8ae35ea50464da2f5c1933e831e0aced933d3b4Fabrice Di Meglio (SwitchPreference) findPreference(TOGGLE_LARGE_TEXT_PREFERENCE); 361341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 362fc72424cd7c3bbb6d45afb77e5ffb619d38ef641Chris Craik // Text contrast. 363fc72424cd7c3bbb6d45afb77e5ffb619d38ef641Chris Craik mToggleHighTextContrastPreference = 364d8ae35ea50464da2f5c1933e831e0aced933d3b4Fabrice Di Meglio (SwitchPreference) findPreference(TOGGLE_HIGH_TEXT_CONTRAST_PREFERENCE); 365fc72424cd7c3bbb6d45afb77e5ffb619d38ef641Chris Craik 36604e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette // Display inversion. 36704e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette mToggleInversionPreference = (SwitchPreference) findPreference(TOGGLE_INVERSION_PREFERENCE); 36804e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette mToggleInversionPreference.setOnPreferenceChangeListener(this); 36904e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette 370341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // Power button ends calls. 371341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mTogglePowerButtonEndsCallPreference = 372d8ae35ea50464da2f5c1933e831e0aced933d3b4Fabrice Di Meglio (SwitchPreference) findPreference(TOGGLE_POWER_BUTTON_ENDS_CALL_PREFERENCE); 373341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette if (!KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_POWER) 374341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette || !Utils.isVoiceCapable(getActivity())) { 375341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mSystemsCategory.removePreference(mTogglePowerButtonEndsCallPreference); 376341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 377341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 378341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // Lock screen rotation. 379341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mToggleLockScreenRotationPreference = 380d8ae35ea50464da2f5c1933e831e0aced933d3b4Fabrice Di Meglio (SwitchPreference) findPreference(TOGGLE_LOCK_SCREEN_ROTATION_PREFERENCE); 381341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette if (!RotationPolicy.isRotationSupported(getActivity())) { 382341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mSystemsCategory.removePreference(mToggleLockScreenRotationPreference); 383341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 384341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 385341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // Speak passwords. 386341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mToggleSpeakPasswordPreference = 387d8ae35ea50464da2f5c1933e831e0aced933d3b4Fabrice Di Meglio (SwitchPreference) findPreference(TOGGLE_SPEAK_PASSWORD_PREFERENCE); 388341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 389341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // Long press timeout. 390341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mSelectLongPressTimeoutPreference = 391341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette (ListPreference) findPreference(SELECT_LONG_PRESS_TIMEOUT_PREFERENCE); 392341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mSelectLongPressTimeoutPreference.setOnPreferenceChangeListener(this); 393341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette if (mLongPressTimeoutValuetoTitleMap.size() == 0) { 394341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette String[] timeoutValues = getResources().getStringArray( 395341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette R.array.long_press_timeout_selector_values); 396341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mLongPressTimeoutDefault = Integer.parseInt(timeoutValues[0]); 397341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette String[] timeoutTitles = getResources().getStringArray( 398341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette R.array.long_press_timeout_selector_titles); 399341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette final int timeoutValueCount = timeoutValues.length; 400341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette for (int i = 0; i < timeoutValueCount; i++) { 401341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mLongPressTimeoutValuetoTitleMap.put(timeoutValues[i], timeoutTitles[i]); 402341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 403341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 404341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 405cc0e782871eb6b946ded880e391866f27953654bAlan Viverette // Captioning. 406cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mCaptioningPreferenceScreen = (PreferenceScreen) findPreference( 407cc0e782871eb6b946ded880e391866f27953654bAlan Viverette CAPTIONING_PREFERENCE_SCREEN); 408cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 409341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // Display magnification. 410341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mDisplayMagnificationPreferenceScreen = (PreferenceScreen) findPreference( 411341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette DISPLAY_MAGNIFICATION_PREFERENCE_SCREEN); 412341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 413fc0ab213b8637f4d9177ff5f08c4fdc155bbb941Alan Viverette // Display color adjustments. 414fc0ab213b8637f4d9177ff5f08c4fdc155bbb941Alan Viverette mDisplayDaltonizerPreferenceScreen = (PreferenceScreen) findPreference( 415fc0ab213b8637f4d9177ff5f08c4fdc155bbb941Alan Viverette DISPLAY_DALTONIZER_PREFERENCE_SCREEN); 416fc0ab213b8637f4d9177ff5f08c4fdc155bbb941Alan Viverette 417341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // Global gesture. 418341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mGlobalGesturePreferenceScreen = 419341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette (PreferenceScreen) findPreference(ENABLE_ACCESSIBILITY_GESTURE_PREFERENCE_SCREEN); 420341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette final int longPressOnPowerBehavior = getActivity().getResources().getInteger( 421341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette com.android.internal.R.integer.config_longPressOnPowerBehavior); 422341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; 423341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette if (!KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_POWER) 424341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette || longPressOnPowerBehavior != LONG_PRESS_POWER_GLOBAL_ACTIONS) { 425341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // Remove accessibility shortcut if power key is not present 426341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // nor long press power does not show global actions menu. 427341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mSystemsCategory.removePreference(mGlobalGesturePreferenceScreen); 428341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 429341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 430341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 431341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private void updateAllPreferences() { 432341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette updateServicesPreferences(); 433341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette updateSystemPreferences(); 434341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 435341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 436341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private void updateServicesPreferences() { 437341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // Since services category is auto generated we have to do a pass 438341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // to generate it since services can come and go and then based on 439341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // the global accessibility state to decided whether it is enabled. 440341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 441341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // Generate. 442341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mServicesCategory.removeAll(); 443341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 444341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette AccessibilityManager accessibilityManager = AccessibilityManager.getInstance(getActivity()); 445341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 446341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette List<AccessibilityServiceInfo> installedServices = 447341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette accessibilityManager.getInstalledAccessibilityServiceList(); 448341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette Set<ComponentName> enabledServices = AccessibilityUtils.getEnabledServicesFromSettings( 449341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette getActivity()); 450333f2bc71a0866053f8e2fce8efbfb0bcec68811Kenny Guy List<String> permittedServices = mDpm.getPermittedAccessibilityServices( 451333f2bc71a0866053f8e2fce8efbfb0bcec68811Kenny Guy UserHandle.myUserId()); 452341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette final boolean accessibilityEnabled = Settings.Secure.getInt(getContentResolver(), 453341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1; 454341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 455341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette for (int i = 0, count = installedServices.size(); i < count; ++i) { 456341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette AccessibilityServiceInfo info = installedServices.get(i); 457341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 458341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette PreferenceScreen preference = getPreferenceManager().createPreferenceScreen( 459341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette getActivity()); 460341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette String title = info.getResolveInfo().loadLabel(getPackageManager()).toString(); 461341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 462341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette ServiceInfo serviceInfo = info.getResolveInfo().serviceInfo; 463341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette ComponentName componentName = new ComponentName(serviceInfo.packageName, 464341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette serviceInfo.name); 465341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 466341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette preference.setKey(componentName.flattenToString()); 467341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 468341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette preference.setTitle(title); 469341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette final boolean serviceEnabled = accessibilityEnabled 470341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette && enabledServices.contains(componentName); 471333f2bc71a0866053f8e2fce8efbfb0bcec68811Kenny Guy String serviceEnabledString; 472341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette if (serviceEnabled) { 473333f2bc71a0866053f8e2fce8efbfb0bcec68811Kenny Guy serviceEnabledString = getString(R.string.accessibility_feature_state_on); 474341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } else { 475333f2bc71a0866053f8e2fce8efbfb0bcec68811Kenny Guy serviceEnabledString = getString(R.string.accessibility_feature_state_off); 476333f2bc71a0866053f8e2fce8efbfb0bcec68811Kenny Guy } 477333f2bc71a0866053f8e2fce8efbfb0bcec68811Kenny Guy 478333f2bc71a0866053f8e2fce8efbfb0bcec68811Kenny Guy // Disable all accessibility services that are not permitted. 479333f2bc71a0866053f8e2fce8efbfb0bcec68811Kenny Guy String packageName = serviceInfo.packageName; 480333f2bc71a0866053f8e2fce8efbfb0bcec68811Kenny Guy boolean serviceAllowed = 481333f2bc71a0866053f8e2fce8efbfb0bcec68811Kenny Guy permittedServices == null || permittedServices.contains(packageName); 482333f2bc71a0866053f8e2fce8efbfb0bcec68811Kenny Guy preference.setEnabled(serviceAllowed || serviceEnabled); 483333f2bc71a0866053f8e2fce8efbfb0bcec68811Kenny Guy 484333f2bc71a0866053f8e2fce8efbfb0bcec68811Kenny Guy String summaryString; 485333f2bc71a0866053f8e2fce8efbfb0bcec68811Kenny Guy if (serviceAllowed) { 486333f2bc71a0866053f8e2fce8efbfb0bcec68811Kenny Guy summaryString = serviceEnabledString; 487333f2bc71a0866053f8e2fce8efbfb0bcec68811Kenny Guy } else { 488333f2bc71a0866053f8e2fce8efbfb0bcec68811Kenny Guy summaryString = getString(R.string.accessibility_feature_or_input_method_not_allowed); 489341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 490333f2bc71a0866053f8e2fce8efbfb0bcec68811Kenny Guy preference.setSummary(summaryString); 491341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 492341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette preference.setOrder(i); 493341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette preference.setFragment(ToggleAccessibilityServicePreferenceFragment.class.getName()); 494341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette preference.setPersistent(true); 495341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 496341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette Bundle extras = preference.getExtras(); 497341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette extras.putString(EXTRA_PREFERENCE_KEY, preference.getKey()); 498341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette extras.putBoolean(EXTRA_CHECKED, serviceEnabled); 499341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette extras.putString(EXTRA_TITLE, title); 500341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 501341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette String description = info.loadDescription(getPackageManager()); 502341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette if (TextUtils.isEmpty(description)) { 503341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette description = getString(R.string.accessibility_service_default_description); 504341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 505341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette extras.putString(EXTRA_SUMMARY, description); 506341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 507341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette String settingsClassName = info.getSettingsActivityName(); 508341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette if (!TextUtils.isEmpty(settingsClassName)) { 509341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette extras.putString(EXTRA_SETTINGS_TITLE, 510341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette getString(R.string.accessibility_menu_item_settings)); 511341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette extras.putString(EXTRA_SETTINGS_COMPONENT_NAME, 512341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette new ComponentName(info.getResolveInfo().serviceInfo.packageName, 513341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette settingsClassName).flattenToString()); 514341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 515341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 516341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette extras.putParcelable(EXTRA_COMPONENT_NAME, componentName); 517341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 518341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mServicesCategory.addPreference(preference); 519341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 520341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 521341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette if (mServicesCategory.getPreferenceCount() == 0) { 522341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette if (mNoServicesMessagePreference == null) { 52389b170aa0526d13602ad64f308b38ddf514a2206Fabrice Di Meglio mNoServicesMessagePreference = new Preference(getActivity()); 524341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mNoServicesMessagePreference.setPersistent(false); 525341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mNoServicesMessagePreference.setLayoutResource( 526341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette R.layout.text_description_preference); 527341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mNoServicesMessagePreference.setSelectable(false); 52889b170aa0526d13602ad64f308b38ddf514a2206Fabrice Di Meglio mNoServicesMessagePreference.setSummary( 52989b170aa0526d13602ad64f308b38ddf514a2206Fabrice Di Meglio getString(R.string.accessibility_no_services_installed)); 530341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 531341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mServicesCategory.addPreference(mNoServicesMessagePreference); 532341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 533341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 534341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 535341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private void updateSystemPreferences() { 536341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // Large text. 537341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette try { 538341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mCurConfig.updateFrom(ActivityManagerNative.getDefault().getConfiguration()); 539341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } catch (RemoteException re) { 540341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette /* ignore */ 541341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 542341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mToggleLargeTextPreference.setChecked(mCurConfig.fontScale == LARGE_FONT_SCALE); 543341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 544fc72424cd7c3bbb6d45afb77e5ffb619d38ef641Chris Craik mToggleHighTextContrastPreference.setChecked( 54522c7f58b65b057495e640ed6a975f481463b7e06Chris Craik Settings.Secure.getInt(getContentResolver(), 54622c7f58b65b057495e640ed6a975f481463b7e06Chris Craik Settings.Secure.ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED, 0) == 1); 547fc72424cd7c3bbb6d45afb77e5ffb619d38ef641Chris Craik 54804e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette // If the quick setting is enabled, the preference MUST be enabled. 54904e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette mToggleInversionPreference.setChecked(Settings.Secure.getInt(getContentResolver(), 55004e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, 0) == 1); 55104e1acc12b9d09cd98fa551267abc292d82d4c37Alan Viverette 552341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // Power button ends calls. 553341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette if (KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_POWER) 554341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette && Utils.isVoiceCapable(getActivity())) { 555341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette final int incallPowerBehavior = Settings.Secure.getInt(getContentResolver(), 556341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, 557341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT); 558341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette final boolean powerButtonEndsCall = 559341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette (incallPowerBehavior == Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP); 560341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mTogglePowerButtonEndsCallPreference.setChecked(powerButtonEndsCall); 561341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 562341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 563341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // Auto-rotate screen 564341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette updateLockScreenRotationCheckbox(); 565341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 566341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // Speak passwords. 567341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette final boolean speakPasswordEnabled = Settings.Secure.getInt(getContentResolver(), 568341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD, 0) != 0; 569341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mToggleSpeakPasswordPreference.setChecked(speakPasswordEnabled); 570341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 571341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // Long press timeout. 572341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette final int longPressTimeout = Settings.Secure.getInt(getContentResolver(), 573341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette Settings.Secure.LONG_PRESS_TIMEOUT, mLongPressTimeoutDefault); 574341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette String value = String.valueOf(longPressTimeout); 575341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mSelectLongPressTimeoutPreference.setValue(value); 576341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mSelectLongPressTimeoutPreference.setSummary(mLongPressTimeoutValuetoTitleMap.get(value)); 577341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 578fc0ab213b8637f4d9177ff5f08c4fdc155bbb941Alan Viverette updateFeatureSummary(Settings.Secure.ACCESSIBILITY_CAPTIONING_ENABLED, 579fc0ab213b8637f4d9177ff5f08c4fdc155bbb941Alan Viverette mCaptioningPreferenceScreen); 580fc0ab213b8637f4d9177ff5f08c4fdc155bbb941Alan Viverette updateFeatureSummary(Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, 581fc0ab213b8637f4d9177ff5f08c4fdc155bbb941Alan Viverette mDisplayMagnificationPreferenceScreen); 582fc0ab213b8637f4d9177ff5f08c4fdc155bbb941Alan Viverette updateFeatureSummary(Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 583fc0ab213b8637f4d9177ff5f08c4fdc155bbb941Alan Viverette mDisplayDaltonizerPreferenceScreen); 584341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 585341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette // Global gesture 586341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette final boolean globalGestureEnabled = Settings.Global.getInt(getContentResolver(), 587341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1; 588341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette if (globalGestureEnabled) { 589341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mGlobalGesturePreferenceScreen.setSummary( 590341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette R.string.accessibility_global_gesture_preference_summary_on); 591341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } else { 592341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mGlobalGesturePreferenceScreen.setSummary( 593341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette R.string.accessibility_global_gesture_preference_summary_off); 594341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 595341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 596341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 597fc0ab213b8637f4d9177ff5f08c4fdc155bbb941Alan Viverette private void updateFeatureSummary(String prefKey, Preference pref) { 598fc0ab213b8637f4d9177ff5f08c4fdc155bbb941Alan Viverette final boolean enabled = Settings.Secure.getInt(getContentResolver(), prefKey, 0) == 1; 599fc0ab213b8637f4d9177ff5f08c4fdc155bbb941Alan Viverette pref.setSummary(enabled ? R.string.accessibility_feature_state_on 600fc0ab213b8637f4d9177ff5f08c4fdc155bbb941Alan Viverette : R.string.accessibility_feature_state_off); 601fc0ab213b8637f4d9177ff5f08c4fdc155bbb941Alan Viverette } 602fc0ab213b8637f4d9177ff5f08c4fdc155bbb941Alan Viverette 603341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private void updateLockScreenRotationCheckbox() { 604341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette Context context = getActivity(); 605341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette if (context != null) { 606341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette mToggleLockScreenRotationPreference.setChecked( 607341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette !RotationPolicy.isRotationLocked(context)); 608341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 609341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 610341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 611341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette private void loadInstalledServices() { 612341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette Set<ComponentName> installedServices = sInstalledServices; 613341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette installedServices.clear(); 614341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 615341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette List<AccessibilityServiceInfo> installedServiceInfos = 616341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette AccessibilityManager.getInstance(getActivity()) 617341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette .getInstalledAccessibilityServiceList(); 618341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette if (installedServiceInfos == null) { 619341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette return; 620341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 621341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette 622341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette final int installedServiceInfoCount = installedServiceInfos.size(); 623341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette for (int i = 0; i < installedServiceInfoCount; i++) { 624341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette ResolveInfo resolveInfo = installedServiceInfos.get(i).getResolveInfo(); 625341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette ComponentName installedService = new ComponentName( 626341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette resolveInfo.serviceInfo.packageName, 627341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette resolveInfo.serviceInfo.name); 628341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette installedServices.add(installedService); 629341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 630341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette } 631b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav 632b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 633b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav new BaseSearchIndexProvider() { 634b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav @Override 635b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) { 636b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav List<SearchIndexableRaw> indexables = new ArrayList<SearchIndexableRaw>(); 637b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav 638b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav PackageManager packageManager = context.getPackageManager(); 639b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav AccessibilityManager accessibilityManager = (AccessibilityManager) 640b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav context.getSystemService(Context.ACCESSIBILITY_SERVICE); 641b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav 642b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav String screenTitle = context.getResources().getString( 643b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav R.string.accessibility_services_title); 644b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav 645bb26141ddfc0c53a7dcb0cedf0499d9b214897ebFabrice Di Meglio // Indexing all services, regardless if enabled. 646b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav List<AccessibilityServiceInfo> services = accessibilityManager 647b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav .getInstalledAccessibilityServiceList(); 648b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav final int serviceCount = services.size(); 649b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav for (int i = 0; i < serviceCount; i++) { 650b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav AccessibilityServiceInfo service = services.get(i); 6510bae067a9932b27d6b740ef3d4ec00c8136cfabdFabrice Di Meglio if (service == null || service.getResolveInfo() == null) { 6520bae067a9932b27d6b740ef3d4ec00c8136cfabdFabrice Di Meglio continue; 6530bae067a9932b27d6b740ef3d4ec00c8136cfabdFabrice Di Meglio } 654bb26141ddfc0c53a7dcb0cedf0499d9b214897ebFabrice Di Meglio 655bb26141ddfc0c53a7dcb0cedf0499d9b214897ebFabrice Di Meglio ServiceInfo serviceInfo = service.getResolveInfo().serviceInfo; 656bb26141ddfc0c53a7dcb0cedf0499d9b214897ebFabrice Di Meglio ComponentName componentName = new ComponentName(serviceInfo.packageName, 657bb26141ddfc0c53a7dcb0cedf0499d9b214897ebFabrice Di Meglio serviceInfo.name); 658bb26141ddfc0c53a7dcb0cedf0499d9b214897ebFabrice Di Meglio 659b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav SearchIndexableRaw indexable = new SearchIndexableRaw(context); 660bb26141ddfc0c53a7dcb0cedf0499d9b214897ebFabrice Di Meglio indexable.key = componentName.flattenToString(); 661b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav indexable.title = service.getResolveInfo().loadLabel(packageManager).toString(); 662b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav indexable.summaryOn = context.getString(R.string.accessibility_feature_state_on); 663b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav indexable.summaryOff = context.getString(R.string.accessibility_feature_state_off); 664b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav indexable.screenTitle = screenTitle; 665b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav indexables.add(indexable); 666b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav } 667b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav 668b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav return indexables; 669b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav } 670b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav 671b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav @Override 672b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav public List<SearchIndexableResource> getXmlResourcesToIndex(Context context, 673b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav boolean enabled) { 674b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav List<SearchIndexableResource> indexables = new ArrayList<SearchIndexableResource>(); 675b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav SearchIndexableResource indexable = new SearchIndexableResource(context); 676b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav indexable.xmlResId = R.xml.accessibility_settings; 677b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav indexables.add(indexable); 678b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav return indexables; 679b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav } 680b4b30828e9a15540bae6676f4b7a1910aaa9254eSvetoslav }; 681341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette} 682