• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 android.accessibilityservice.AccessibilityServiceInfo;
20 import android.content.DialogInterface;
21 
22 import com.android.settingslib.accessibility.AccessibilityUtils;
23 
24 /**
25  * Fragment that does not have toggle bar to turn on service to use.
26  *
27  * <p>The child {@link ToggleAccessibilityServicePreferenceFragment} shows the actual UI for
28  * providing basic accessibility service setup.
29  *
30  * <p>For accessibility services that target SDK > Q, and
31  * {@link AccessibilityServiceInfo#FLAG_REQUEST_ACCESSIBILITY_BUTTON} is set.
32  */
33 public class InvisibleToggleAccessibilityServicePreferenceFragment extends
34         ToggleAccessibilityServicePreferenceFragment implements ShortcutPreference.OnClickCallback {
35 
36     @Override
onInstallSwitchPreferenceToggleSwitch()37     protected void onInstallSwitchPreferenceToggleSwitch() {
38         super.onInstallSwitchPreferenceToggleSwitch();
39         mToggleServiceSwitchPreference.setVisible(false);
40     }
41 
42     /**
43      * {@inheritDoc}
44      *
45      * Enables accessibility service only when user had allowed permission. Disables
46      * accessibility service when shortcutPreference is unchecked.
47      */
48     @Override
onToggleClicked(ShortcutPreference preference)49     public void onToggleClicked(ShortcutPreference preference) {
50         super.onToggleClicked(preference);
51         boolean enabled = getArguments().getBoolean(AccessibilitySettings.EXTRA_CHECKED)
52                 && preference.isChecked();
53         AccessibilityUtils.setAccessibilityServiceState(getContext(), mComponentName, enabled);
54     }
55 
56     /**
57      * {@inheritDoc}
58      *
59      * Enables accessibility service when user clicks permission allow button.
60      */
61     @Override
onAllowButtonFromShortcutToggleClicked()62     void onAllowButtonFromShortcutToggleClicked() {
63         super.onAllowButtonFromShortcutToggleClicked();
64         AccessibilityUtils.setAccessibilityServiceState(getContext(), mComponentName, true);
65     }
66 
67     /**
68      * {@inheritDoc}
69      *
70      * Enables accessibility service when shortcutPreference is checked.
71      */
72     @Override
callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which)73     protected void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) {
74         super.callOnAlertDialogCheckboxClicked(dialog, which);
75 
76         final boolean enabled = mShortcutPreference.isChecked();
77         AccessibilityUtils.setAccessibilityServiceState(getContext(), mComponentName, enabled);
78     }
79 }
80