• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.settingslib.accessibility;
18 
19 import android.accessibilityservice.AccessibilityServiceInfo;
20 import android.content.Context;
21 import android.provider.Settings;
22 import android.view.accessibility.AccessibilityManager;
23 
24 import java.util.List;
25 
26 /**
27  * A helper class to assist determining the state of the accessibility button that can appear
28  * within the software-rendered navigation area.
29  */
30 public class AccessibilityButtonHelper {
isRequestedByMagnification(Context ctx)31     public static boolean isRequestedByMagnification(Context ctx) {
32         return Settings.Secure.getInt(ctx.getContentResolver(),
33                 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, 0) == 1;
34     }
35 
isRequestedByAccessibilityService(Context ctx)36     public static boolean isRequestedByAccessibilityService(Context ctx) {
37         final AccessibilityManager accessibilityManager = ctx.getSystemService(
38                 AccessibilityManager.class);
39         List<AccessibilityServiceInfo> services =
40                 accessibilityManager.getEnabledAccessibilityServiceList(
41                         AccessibilityServiceInfo.FEEDBACK_ALL_MASK);
42         if (services != null) {
43             for (int i = 0, size = services.size(); i < size; i++) {
44                 if ((services.get(i).flags
45                         & AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON)
46                         != 0) {
47                     return true;
48                 }
49             }
50         }
51         return false;
52     }
53 
isRequested(Context ctx)54     public static boolean isRequested(Context ctx) {
55         return isRequestedByMagnification(ctx) || isRequestedByAccessibilityService(ctx);
56     }
57 }
58