• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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.systemui.keyboard.shortcut.data.source
18 
19 import android.content.res.Resources
20 import android.hardware.input.InputSettings
21 import android.view.KeyEvent.KEYCODE_3
22 import android.view.KeyEvent.KEYCODE_4
23 import android.view.KeyEvent.KEYCODE_5
24 import android.view.KeyEvent.KEYCODE_6
25 import android.view.KeyEvent.KEYCODE_M
26 import android.view.KeyEvent.KEYCODE_S
27 import android.view.KeyEvent.KEYCODE_T
28 import android.view.KeyEvent.KEYCODE_V
29 import android.view.KeyEvent.META_ALT_ON
30 import android.view.KeyEvent.META_META_ON
31 import android.view.KeyboardShortcutGroup
32 import android.view.KeyboardShortcutInfo
33 import com.android.hardware.input.Flags.enableTalkbackAndMagnifierKeyGestures
34 import com.android.hardware.input.Flags.enableVoiceAccessKeyGestures
35 import com.android.hardware.input.Flags.keyboardA11yShortcutControl
36 import com.android.systemui.dagger.qualifiers.Main
37 import com.android.systemui.keyboard.shortcut.data.model.shortcutInfo
38 import com.android.systemui.res.R
39 import javax.inject.Inject
40 
41 class AccessibilityShortcutsSource @Inject constructor(@Main private val resources: Resources) :
42     KeyboardShortcutGroupsSource {
shortcutGroupsnull43     override suspend fun shortcutGroups(deviceId: Int): List<KeyboardShortcutGroup> =
44         listOf(
45             KeyboardShortcutGroup(
46                 /* label= */ resources.getString(R.string.shortcutHelper_category_accessibility),
47                 accessibilityShortcuts(),
48             )
49         )
50 
51     private fun accessibilityShortcuts(): List<KeyboardShortcutInfo> {
52         val shortcuts = mutableListOf<KeyboardShortcutInfo>()
53 
54         if (keyboardA11yShortcutControl()) {
55             shortcuts.add(
56                 // Toggle bounce keys:
57                 //  - Meta + Alt + 3
58                 shortcutInfo(
59                     resources.getString(R.string.group_accessibility_toggle_bounce_keys)
60                 ) {
61                     command(META_META_ON or META_ALT_ON, KEYCODE_3)
62                 }
63             )
64             if (InputSettings.isAccessibilityMouseKeysFeatureFlagEnabled()) {
65                 shortcuts.add(
66                     // Toggle mouse keys:
67                     //  - Meta + Alt + 4
68                     shortcutInfo(
69                         resources.getString(R.string.group_accessibility_toggle_mouse_keys)
70                     ) {
71                         command(META_META_ON or META_ALT_ON, KEYCODE_4)
72                     }
73                 )
74             }
75             shortcuts.add(
76                 // Toggle sticky keys:
77                 //  - Meta + Alt + 5
78                 shortcutInfo(
79                     resources.getString(R.string.group_accessibility_toggle_sticky_keys)
80                 ) {
81                     command(META_META_ON or META_ALT_ON, KEYCODE_5)
82                 }
83             )
84             shortcuts.add(
85                 // Toggle slow keys:
86                 //  - Meta + Alt + 6
87                 shortcutInfo(
88                     resources.getString(R.string.group_accessibility_toggle_slow_keys)
89                 ) {
90                     command(META_META_ON or META_ALT_ON, KEYCODE_6)
91                 }
92             )
93         }
94 
95         if (enableVoiceAccessKeyGestures()) {
96             shortcuts.add(
97                 // Toggle voice access:
98                 //  - Meta + Alt + V
99                 shortcutInfo(
100                     resources.getString(R.string.group_accessibility_toggle_voice_access)
101                 ) {
102                     command(META_META_ON or META_ALT_ON, KEYCODE_V)
103                 }
104             )
105         }
106 
107         if (enableTalkbackAndMagnifierKeyGestures()) {
108             shortcuts.add(
109                 // Toggle talkback:
110                 //  - Meta + Alt + T
111                 shortcutInfo(resources.getString(R.string.group_accessibility_toggle_talkback)) {
112                     command(META_META_ON or META_ALT_ON, KEYCODE_T)
113                 }
114             )
115             shortcuts.add(
116                 // Toggle magnification:
117                 //  - Meta + Alt + M
118                 shortcutInfo(
119                     resources.getString(R.string.group_accessibility_toggle_magnification)
120                 ) {
121                     command(META_META_ON or META_ALT_ON, KEYCODE_M)
122                 }
123             )
124             shortcuts.add(
125                 // Activate Select to Speak:
126                 //  - Meta + Alt + S
127                 shortcutInfo(
128                     resources.getString(R.string.group_accessibility_activate_select_to_speak)
129                 ) {
130                     command(META_META_ON or META_ALT_ON, KEYCODE_S)
131                 }
132             )
133         }
134 
135         return shortcuts
136     }
137 }
138