• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.accessibility;
18 
19 import static com.android.internal.accessibility.AccessibilityShortcutController.MAGNIFICATION_CONTROLLER_NAME;
20 import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
21 import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
22 
23 import android.app.Dialog;
24 import android.app.settings.SettingsEnums;
25 import android.content.ContentResolver;
26 import android.content.Context;
27 import android.content.DialogInterface;
28 import android.icu.text.CaseMap;
29 import android.net.Uri;
30 import android.os.Bundle;
31 import android.provider.Settings;
32 import android.text.TextUtils;
33 import android.view.LayoutInflater;
34 import android.view.View;
35 import android.view.ViewGroup;
36 import android.view.accessibility.AccessibilityManager;
37 import android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener;
38 import android.widget.CheckBox;
39 
40 import androidx.appcompat.app.AlertDialog;
41 
42 import com.android.internal.annotations.VisibleForTesting;
43 import com.android.settings.R;
44 import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
45 
46 import java.util.ArrayList;
47 import java.util.HashSet;
48 import java.util.List;
49 import java.util.Locale;
50 import java.util.Set;
51 import java.util.StringJoiner;
52 import java.util.stream.Collectors;
53 
54 /**
55  * Fragment that shows the actual UI for providing basic magnification accessibility service setup
56  * and does not have toggle bar to turn on service to use.
57  */
58 public class ToggleScreenMagnificationPreferenceFragment extends
59         ToggleFeaturePreferenceFragment {
60 
61     private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type";
62     private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
63     private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
64     private int mUserShortcutType = UserShortcutType.EMPTY;
65     private CheckBox mSoftwareTypeCheckBox;
66     private CheckBox mHardwareTypeCheckBox;
67     private CheckBox mTripleTapTypeCheckBox;
68 
69     // TODO(b/147021230): Will move common functions and variables to
70     //  android/internal/accessibility folder. For now, magnification need to be treated
71     //  individually.
72     private static final char COMPONENT_NAME_SEPARATOR = ':';
73     private static final TextUtils.SimpleStringSplitter sStringColonSplitter =
74             new TextUtils.SimpleStringSplitter(COMPONENT_NAME_SEPARATOR);
75 
76     @Override
onCreate(Bundle savedInstanceState)77     public void onCreate(Bundle savedInstanceState) {
78         super.onCreate(savedInstanceState);
79         getActivity().setTitle(R.string.accessibility_screen_magnification_title);
80     }
81 
82     @Override
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)83     public View onCreateView(LayoutInflater inflater, ViewGroup container,
84             Bundle savedInstanceState) {
85         mPackageName = getString(R.string.accessibility_screen_magnification_title);
86         mImageUri = new Uri.Builder().scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
87                 .authority(getPrefContext().getPackageName())
88                 .appendPath(String.valueOf(R.drawable.accessibility_magnification_banner))
89                 .build();
90         mTouchExplorationStateChangeListener = isTouchExplorationEnabled -> {
91             removeDialog(DialogEnums.EDIT_SHORTCUT);
92             mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
93         };
94         return super.onCreateView(inflater, container, savedInstanceState);
95     }
96 
97     @Override
onViewCreated(View view, Bundle savedInstanceState)98     public void onViewCreated(View view, Bundle savedInstanceState) {
99         initShortcutPreference();
100 
101         super.onViewCreated(view, savedInstanceState);
102     }
103 
104     @Override
onSaveInstanceState(Bundle outState)105     public void onSaveInstanceState(Bundle outState) {
106         outState.putInt(EXTRA_SHORTCUT_TYPE, mUserShortcutTypesCache);
107         super.onSaveInstanceState(outState);
108     }
109 
110     @Override
onResume()111     public void onResume() {
112         super.onResume();
113 
114         final AccessibilityManager am = getPrefContext().getSystemService(
115                 AccessibilityManager.class);
116         am.addTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
117 
118         updateShortcutPreferenceData();
119         updateShortcutPreference();
120     }
121 
122     @Override
onPause()123     public void onPause() {
124         final AccessibilityManager am = getPrefContext().getSystemService(
125                 AccessibilityManager.class);
126         am.removeTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
127 
128         super.onPause();
129     }
130 
131     @Override
onCreateDialog(int dialogId)132     public Dialog onCreateDialog(int dialogId) {
133         final AlertDialog dialog;
134         switch (dialogId) {
135             case DialogEnums.GESTURE_NAVIGATION_TUTORIAL:
136                 return AccessibilityGestureNavigationTutorial
137                         .showGestureNavigationTutorialDialog(getPrefContext());
138             case DialogEnums.MAGNIFICATION_EDIT_SHORTCUT:
139                 final CharSequence dialogTitle = getPrefContext().getString(
140                         R.string.accessibility_shortcut_title, mPackageName);
141                 dialog = AccessibilityEditDialogUtils.showMagnificationEditShortcutDialog(
142                                 getPrefContext(), dialogTitle,
143                                 this::callOnAlertDialogCheckboxClicked);
144                 initializeDialogCheckBox(dialog);
145                 return dialog;
146             default:
147                 return super.onCreateDialog(dialogId);
148         }
149     }
150 
setDialogTextAreaClickListener(View dialogView, CheckBox checkBox)151     private void setDialogTextAreaClickListener(View dialogView, CheckBox checkBox) {
152         final View dialogTextArea = dialogView.findViewById(R.id.container);
153         dialogTextArea.setOnClickListener(v -> {
154             checkBox.toggle();
155             updateUserShortcutType(/* saveChanges= */ false);
156         });
157     }
158 
initializeDialogCheckBox(AlertDialog dialog)159     private void initializeDialogCheckBox(AlertDialog dialog) {
160         final View dialogSoftwareView = dialog.findViewById(R.id.software_shortcut);
161         mSoftwareTypeCheckBox = dialogSoftwareView.findViewById(R.id.checkbox);
162         setDialogTextAreaClickListener(dialogSoftwareView, mSoftwareTypeCheckBox);
163 
164         final View dialogHardwareView = dialog.findViewById(R.id.hardware_shortcut);
165         mHardwareTypeCheckBox = dialogHardwareView.findViewById(R.id.checkbox);
166         setDialogTextAreaClickListener(dialogHardwareView, mHardwareTypeCheckBox);
167 
168         final View dialogTripleTapView = dialog.findViewById(R.id.triple_tap_shortcut);
169         mTripleTapTypeCheckBox = dialogTripleTapView.findViewById(R.id.checkbox);
170         setDialogTextAreaClickListener(dialogTripleTapView, mTripleTapTypeCheckBox);
171 
172         final View advancedView = dialog.findViewById(R.id.advanced_shortcut);
173         updateAlertDialogCheckState();
174 
175         // Window magnification mode doesn't support advancedView.
176         if (isWindowMagnification(getPrefContext())) {
177             advancedView.setVisibility(View.GONE);
178             return;
179         }
180         // Shows the triple tap checkbox directly if clicked.
181         if (mTripleTapTypeCheckBox.isChecked()) {
182             advancedView.setVisibility(View.GONE);
183             dialogTripleTapView.setVisibility(View.VISIBLE);
184         }
185     }
186 
updateAlertDialogCheckState()187     private void updateAlertDialogCheckState() {
188         if (mUserShortcutTypesCache != UserShortcutType.EMPTY) {
189             updateCheckStatus(mSoftwareTypeCheckBox, UserShortcutType.SOFTWARE);
190             updateCheckStatus(mHardwareTypeCheckBox, UserShortcutType.HARDWARE);
191             updateCheckStatus(mTripleTapTypeCheckBox, UserShortcutType.TRIPLETAP);
192         }
193     }
194 
updateCheckStatus(CheckBox checkBox, @UserShortcutType int type)195     private void updateCheckStatus(CheckBox checkBox, @UserShortcutType int type) {
196         checkBox.setChecked((mUserShortcutTypesCache & type) == type);
197     }
198 
updateUserShortcutType(boolean saveChanges)199     private void updateUserShortcutType(boolean saveChanges) {
200         mUserShortcutTypesCache = UserShortcutType.EMPTY;
201         if (mSoftwareTypeCheckBox.isChecked()) {
202             mUserShortcutTypesCache |= UserShortcutType.SOFTWARE;
203         }
204         if (mHardwareTypeCheckBox.isChecked()) {
205             mUserShortcutTypesCache |= UserShortcutType.HARDWARE;
206         }
207         if (mTripleTapTypeCheckBox.isChecked()) {
208             mUserShortcutTypesCache |= UserShortcutType.TRIPLETAP;
209         }
210 
211         if (saveChanges) {
212             final boolean isChanged = (mUserShortcutTypesCache != UserShortcutType.EMPTY);
213             if (isChanged) {
214                 setUserShortcutType(getPrefContext(), mUserShortcutTypesCache);
215             }
216             mUserShortcutType = mUserShortcutTypesCache;
217         }
218     }
219 
setUserShortcutType(Context context, int type)220     private void setUserShortcutType(Context context, int type) {
221         Set<String> info = SharedPreferenceUtils.getUserShortcutTypes(context);
222         if (info.isEmpty()) {
223             info = new HashSet<>();
224         } else {
225             final Set<String> filtered = info.stream().filter(
226                     str -> str.contains(MAGNIFICATION_CONTROLLER_NAME)).collect(
227                     Collectors.toSet());
228             info.removeAll(filtered);
229         }
230         final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(
231                 MAGNIFICATION_CONTROLLER_NAME, type);
232         info.add(shortcut.flattenToString());
233         SharedPreferenceUtils.setUserShortcutType(context, info);
234     }
235 
236     @Override
getShortcutTypeSummary(Context context)237     protected CharSequence getShortcutTypeSummary(Context context) {
238         if (!mShortcutPreference.isChecked()) {
239             return context.getText(R.string.switch_off_text);
240         }
241 
242         final int shortcutType = getUserShortcutTypes(context, UserShortcutType.EMPTY);
243         int resId = R.string.accessibility_shortcut_edit_summary_software;
244         if (AccessibilityUtil.isGestureNavigateEnabled(context)) {
245             resId = AccessibilityUtil.isTouchExploreEnabled(context)
246                     ? R.string.accessibility_shortcut_edit_dialog_title_software_gesture_talkback
247                     : R.string.accessibility_shortcut_edit_dialog_title_software_gesture;
248         }
249         final CharSequence softwareTitle = context.getText(resId);
250 
251         List<CharSequence> list = new ArrayList<>();
252         if ((shortcutType & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
253             list.add(softwareTitle);
254         }
255         if ((shortcutType & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE) {
256             final CharSequence hardwareTitle = context.getText(
257                     R.string.accessibility_shortcut_hardware_keyword);
258             list.add(hardwareTitle);
259         }
260 
261         if ((shortcutType & UserShortcutType.TRIPLETAP) == UserShortcutType.TRIPLETAP) {
262             final CharSequence tripleTapTitle = context.getText(
263                     R.string.accessibility_shortcut_triple_tap_keyword);
264             list.add(tripleTapTitle);
265         }
266 
267         // Show software shortcut if first time to use.
268         if (list.isEmpty()) {
269             list.add(softwareTitle);
270         }
271         final String joinStrings = TextUtils.join(/* delimiter= */", ", list);
272 
273         return CaseMap.toTitle().wholeString().noLowercase().apply(Locale.getDefault(), /* iter= */
274                 null, joinStrings);
275     }
276 
277     @Override
getUserShortcutTypes(Context context, @UserShortcutType int defaultValue)278     protected int getUserShortcutTypes(Context context, @UserShortcutType int defaultValue) {
279         final Set<String> info = SharedPreferenceUtils.getUserShortcutTypes(context);
280         final Set<String> filtered = info.stream().filter(
281                 str -> str.contains(MAGNIFICATION_CONTROLLER_NAME)).collect(
282                 Collectors.toSet());
283         if (filtered.isEmpty()) {
284             return defaultValue;
285         }
286 
287         final String str = (String) filtered.toArray()[0];
288         final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(str);
289         return shortcut.getType();
290     }
291 
292     @Override
callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which)293     protected void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) {
294         updateUserShortcutType(/* saveChanges= */ true);
295         optInAllMagnificationValuesToSettings(getPrefContext(), mUserShortcutType);
296         optOutAllMagnificationValuesFromSettings(getPrefContext(), ~mUserShortcutType);
297         mShortcutPreference.setChecked(mUserShortcutType != UserShortcutType.EMPTY);
298         mShortcutPreference.setSummary(
299                 getShortcutTypeSummary(getPrefContext()));
300     }
301 
302     @Override
getMetricsCategory()303     public int getMetricsCategory() {
304         // TODO: Distinguish between magnification modes
305         return SettingsEnums.ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFICATION;
306     }
307 
308     @Override
getDialogMetricsCategory(int dialogId)309     public int getDialogMetricsCategory(int dialogId) {
310         switch (dialogId) {
311             case DialogEnums.GESTURE_NAVIGATION_TUTORIAL:
312                 return SettingsEnums.DIALOG_TOGGLE_SCREEN_MAGNIFICATION_GESTURE_NAVIGATION;
313             case DialogEnums.ACCESSIBILITY_BUTTON_TUTORIAL:
314                 return SettingsEnums.DIALOG_TOGGLE_SCREEN_MAGNIFICATION_ACCESSIBILITY_BUTTON;
315             case DialogEnums.MAGNIFICATION_EDIT_SHORTCUT:
316                 return SettingsEnums.DIALOG_MAGNIFICATION_EDIT_SHORTCUT;
317             default:
318                 return super.getDialogMetricsCategory(dialogId);
319         }
320     }
321 
322     @Override
getUserShortcutTypes()323     int getUserShortcutTypes() {
324         return getUserShortcutTypeFromSettings(getPrefContext());
325     }
326 
327     @Override
onPreferenceToggled(String preferenceKey, boolean enabled)328     protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
329         if (enabled && TextUtils.equals(
330                 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED,
331                 preferenceKey)) {
332             showDialog(DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL);
333         }
334         MagnificationPreferenceFragment.setChecked(getContentResolver(), preferenceKey, enabled);
335     }
336 
337     @Override
onInstallSwitchPreferenceToggleSwitch()338     protected void onInstallSwitchPreferenceToggleSwitch() {
339         super.onInstallSwitchPreferenceToggleSwitch();
340         mToggleServiceDividerSwitchPreference.setVisible(false);
341     }
342 
343     @Override
onToggleClicked(ShortcutPreference preference)344     public void onToggleClicked(ShortcutPreference preference) {
345         final int shortcutTypes = getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE);
346         if (preference.isChecked()) {
347             optInAllMagnificationValuesToSettings(getPrefContext(), shortcutTypes);
348             showDialog(DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL);
349         } else {
350             optOutAllMagnificationValuesFromSettings(getPrefContext(), shortcutTypes);
351         }
352         mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
353     }
354 
355     @Override
onSettingsClicked(ShortcutPreference preference)356     public void onSettingsClicked(ShortcutPreference preference) {
357         // Do not restore shortcut in shortcut chooser dialog when shortcutPreference is turned off.
358         mUserShortcutTypesCache = mShortcutPreference.isChecked()
359                 ? getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE)
360                 : UserShortcutType.EMPTY;
361         showDialog(DialogEnums.MAGNIFICATION_EDIT_SHORTCUT);
362     }
363 
364     @Override
updateShortcutPreferenceData()365     protected void updateShortcutPreferenceData() {
366         // Get the user shortcut type from settings provider.
367         mUserShortcutType = getUserShortcutTypeFromSettings(getPrefContext());
368         if (mUserShortcutType != UserShortcutType.EMPTY) {
369             setUserShortcutType(getPrefContext(), mUserShortcutType);
370         } else {
371             //  Get the user shortcut type from shared_prefs if cannot get from settings provider.
372             mUserShortcutType = getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE);
373         }
374     }
375 
initShortcutPreference()376     private void initShortcutPreference() {
377         mShortcutPreference = new ShortcutPreference(getPrefContext(), null);
378         mShortcutPreference.setPersistent(false);
379         mShortcutPreference.setKey(KEY_SHORTCUT_PREFERENCE);
380         mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
381         mShortcutPreference.setOnClickCallback(this);
382 
383         final CharSequence title = getString(R.string.accessibility_shortcut_title, mPackageName);
384         mShortcutPreference.setTitle(title);
385     }
386 
387     @Override
updateShortcutPreference()388     protected void updateShortcutPreference() {
389         final int shortcutTypes = getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE);
390         mShortcutPreference.setChecked(
391                 hasMagnificationValuesInSettings(getPrefContext(), shortcutTypes));
392         mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
393     }
394 
395     @VisibleForTesting
optInAllMagnificationValuesToSettings(Context context, int shortcutTypes)396     static void optInAllMagnificationValuesToSettings(Context context, int shortcutTypes) {
397         if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
398             optInMagnificationValueToSettings(context, UserShortcutType.SOFTWARE);
399         }
400         if (((shortcutTypes & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE)) {
401             optInMagnificationValueToSettings(context, UserShortcutType.HARDWARE);
402         }
403         if (((shortcutTypes & UserShortcutType.TRIPLETAP) == UserShortcutType.TRIPLETAP)) {
404             optInMagnificationValueToSettings(context, UserShortcutType.TRIPLETAP);
405         }
406     }
407 
optInMagnificationValueToSettings(Context context, @UserShortcutType int shortcutType)408     private static void optInMagnificationValueToSettings(Context context,
409             @UserShortcutType int shortcutType) {
410         if (shortcutType == UserShortcutType.TRIPLETAP) {
411             Settings.Secure.putInt(context.getContentResolver(),
412                     Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, ON);
413             return;
414         }
415 
416         if (hasMagnificationValueInSettings(context, shortcutType)) {
417             return;
418         }
419 
420         final String targetKey = AccessibilityUtil.convertKeyFromSettings(shortcutType);
421         final String targetString = Settings.Secure.getString(context.getContentResolver(),
422                 targetKey);
423         final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR));
424 
425         if (!TextUtils.isEmpty(targetString)) {
426             joiner.add(targetString);
427         }
428         joiner.add(MAGNIFICATION_CONTROLLER_NAME);
429 
430         Settings.Secure.putString(context.getContentResolver(), targetKey, joiner.toString());
431     }
432 
433     @VisibleForTesting
optOutAllMagnificationValuesFromSettings(Context context, int shortcutTypes)434     static void optOutAllMagnificationValuesFromSettings(Context context,
435             int shortcutTypes) {
436         if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
437             optOutMagnificationValueFromSettings(context, UserShortcutType.SOFTWARE);
438         }
439         if (((shortcutTypes & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE)) {
440             optOutMagnificationValueFromSettings(context, UserShortcutType.HARDWARE);
441         }
442         if (((shortcutTypes & UserShortcutType.TRIPLETAP) == UserShortcutType.TRIPLETAP)) {
443             optOutMagnificationValueFromSettings(context, UserShortcutType.TRIPLETAP);
444         }
445     }
446 
optOutMagnificationValueFromSettings(Context context, @UserShortcutType int shortcutType)447     private static void optOutMagnificationValueFromSettings(Context context,
448             @UserShortcutType int shortcutType) {
449         if (shortcutType == UserShortcutType.TRIPLETAP) {
450             Settings.Secure.putInt(context.getContentResolver(),
451                     Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, OFF);
452             return;
453         }
454 
455         final String targetKey = AccessibilityUtil.convertKeyFromSettings(shortcutType);
456         final String targetString = Settings.Secure.getString(context.getContentResolver(),
457                 targetKey);
458 
459         if (TextUtils.isEmpty(targetString)) {
460             return;
461         }
462 
463         final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR));
464 
465         sStringColonSplitter.setString(targetString);
466         while (sStringColonSplitter.hasNext()) {
467             final String name = sStringColonSplitter.next();
468             if (TextUtils.isEmpty(name) || MAGNIFICATION_CONTROLLER_NAME.equals(name)) {
469                 continue;
470             }
471             joiner.add(name);
472         }
473 
474         Settings.Secure.putString(context.getContentResolver(), targetKey, joiner.toString());
475     }
476 
477     @VisibleForTesting
hasMagnificationValuesInSettings(Context context, int shortcutTypes)478     static boolean hasMagnificationValuesInSettings(Context context, int shortcutTypes) {
479         boolean exist = false;
480 
481         if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
482             exist = hasMagnificationValueInSettings(context, UserShortcutType.SOFTWARE);
483         }
484         if (((shortcutTypes & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE)) {
485             exist |= hasMagnificationValueInSettings(context, UserShortcutType.HARDWARE);
486         }
487         if (((shortcutTypes & UserShortcutType.TRIPLETAP) == UserShortcutType.TRIPLETAP)) {
488             exist |= hasMagnificationValueInSettings(context, UserShortcutType.TRIPLETAP);
489         }
490         return exist;
491     }
492 
hasMagnificationValueInSettings(Context context, @UserShortcutType int shortcutType)493     private static boolean hasMagnificationValueInSettings(Context context,
494             @UserShortcutType int shortcutType) {
495         if (shortcutType == UserShortcutType.TRIPLETAP) {
496             return Settings.Secure.getInt(context.getContentResolver(),
497                     Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, OFF) == ON;
498         }
499 
500         final String targetKey = AccessibilityUtil.convertKeyFromSettings(shortcutType);
501         final String targetString = Settings.Secure.getString(context.getContentResolver(),
502                 targetKey);
503 
504         if (TextUtils.isEmpty(targetString)) {
505             return false;
506         }
507 
508         sStringColonSplitter.setString(targetString);
509         while (sStringColonSplitter.hasNext()) {
510             final String name = sStringColonSplitter.next();
511             if (MAGNIFICATION_CONTROLLER_NAME.equals(name)) {
512                 return true;
513             }
514         }
515         return false;
516     }
517 
isWindowMagnification(Context context)518     private boolean isWindowMagnification(Context context) {
519         final int mode = Settings.Secure.getIntForUser(
520                 context.getContentResolver(),
521                 Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE,
522                 Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN,
523                 context.getContentResolver().getUserId());
524         return mode == Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW;
525     }
526 
getUserShortcutTypeFromSettings(Context context)527     private static int getUserShortcutTypeFromSettings(Context context) {
528         int shortcutTypes = UserShortcutType.EMPTY;
529         if (hasMagnificationValuesInSettings(context, UserShortcutType.SOFTWARE)) {
530             shortcutTypes |= UserShortcutType.SOFTWARE;
531         }
532         if (hasMagnificationValuesInSettings(context, UserShortcutType.HARDWARE)) {
533             shortcutTypes |= UserShortcutType.HARDWARE;
534         }
535         if (hasMagnificationValuesInSettings(context, UserShortcutType.TRIPLETAP)) {
536             shortcutTypes |= UserShortcutType.TRIPLETAP;
537         }
538         return shortcutTypes;
539     }
540 
541     /**
542      * Gets the service summary of magnification.
543      *
544      * @param context The current context.
545      */
getServiceSummary(Context context)546     public static CharSequence getServiceSummary(Context context) {
547         // Get the user shortcut type from settings provider.
548         final int uerShortcutType = getUserShortcutTypeFromSettings(context);
549         return (uerShortcutType != AccessibilityUtil.UserShortcutType.EMPTY)
550                 ? context.getText(R.string.accessibility_summary_shortcut_enabled)
551                 : context.getText(R.string.accessibility_summary_shortcut_disabled);
552     }
553 }
554