• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 package com.android.settings.accessibility;
17 
18 import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.HARDWARE;
19 import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
20 import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
21 
22 import android.content.ContentResolver;
23 import android.content.Context;
24 import android.os.UserHandle;
25 import android.provider.Settings;
26 import android.view.accessibility.AccessibilityManager;
27 
28 import androidx.annotation.NonNull;
29 import androidx.preference.Preference;
30 
31 import com.android.settings.R;
32 import com.android.settings.core.TogglePreferenceController;
33 
34 import java.util.Locale;
35 
36 /**
37  * Setting to allow the hardware shortcut to turn on from the lock screen
38  */
39 public class HardwareShortcutFromLockscreenPreferenceController
40         extends TogglePreferenceController {
HardwareShortcutFromLockscreenPreferenceController( Context context, String preferenceKey)41     public HardwareShortcutFromLockscreenPreferenceController(
42             Context context, String preferenceKey) {
43         super(context, preferenceKey);
44     }
45 
46     @Override
isChecked()47     public boolean isChecked() {
48         final ContentResolver cr = mContext.getContentResolver();
49         // The shortcut is enabled by default on the lock screen as long as the user has
50         // enabled the shortcut with the warning dialog
51         final int dialogShown = Settings.Secure.getInt(
52                 cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN, OFF);
53         final boolean enabledFromLockScreen = Settings.Secure.getInt(
54                 cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN, dialogShown) == ON;
55         return enabledFromLockScreen;
56     }
57 
58     @Override
setChecked(boolean isChecked)59     public boolean setChecked(boolean isChecked) {
60         return Settings.Secure.putIntForUser(mContext.getContentResolver(),
61                 Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN, isChecked ? ON : OFF,
62                 UserHandle.USER_CURRENT);
63     }
64 
65     @Override
getAvailabilityStatus()66     public int getAvailabilityStatus() {
67         if (!com.android.settings.accessibility.Flags.fixA11ySettingsSearch()) {
68             return AVAILABLE;
69         } else {
70             if (mContext.getSystemService(AccessibilityManager.class)
71                     .getAccessibilityShortcutTargets(HARDWARE).isEmpty()) {
72                 return DISABLED_DEPENDENT_SETTING;
73             } else {
74                 return AVAILABLE;
75             }
76         }
77     }
78 
79     @Override
updateState(@onNull Preference preference)80     public void updateState(@NonNull Preference preference) {
81         super.updateState(preference);
82         refreshSummary(preference);
83     }
84 
85     @Override
getSummary()86     public @NonNull CharSequence getSummary() {
87         if (getAvailabilityStatus() == AVAILABLE) {
88             return mContext.getString(R.string.accessibility_shortcut_description);
89         } else {
90             return mContext.getString(
91                     R.string.accessibility_shortcut_unassigned_setting_unavailable_summary,
92                     AccessibilityUtil.getShortcutSummaryList(mContext, HARDWARE)
93                             .toString().toLowerCase(Locale.getDefault()));
94         }
95     }
96 
97     @Override
getSliceHighlightMenuRes()98     public int getSliceHighlightMenuRes() {
99         return R.string.menu_key_accessibility;
100     }
101 }
102