Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 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 | |
| 17 | package com.android.systemui.accessibility; |
| 18 | |
Miranda Kephart | 7b2c313 | 2020-03-27 09:54:14 -0400 | [diff] [blame] | 19 | import static android.view.WindowManager.ScreenshotSource.SCREENSHOT_GLOBAL_ACTIONS; |
| 20 | |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 21 | import static com.android.internal.accessibility.common.ShortcutConstants.CHOOSER_PACKAGE_NAME; |
| 22 | |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 23 | import android.accessibilityservice.AccessibilityService; |
| 24 | import android.app.PendingIntent; |
| 25 | import android.app.RemoteAction; |
| 26 | import android.content.BroadcastReceiver; |
| 27 | import android.content.Context; |
| 28 | import android.content.Intent; |
| 29 | import android.content.IntentFilter; |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 30 | import android.content.res.Configuration; |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 31 | import android.graphics.drawable.Icon; |
| 32 | import android.hardware.input.InputManager; |
| 33 | import android.os.Handler; |
| 34 | import android.os.Looper; |
| 35 | import android.os.PowerManager; |
| 36 | import android.os.RemoteException; |
| 37 | import android.os.SystemClock; |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 38 | import android.os.UserHandle; |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 39 | import android.util.Log; |
| 40 | import android.view.Display; |
| 41 | import android.view.IWindowManager; |
| 42 | import android.view.InputDevice; |
| 43 | import android.view.KeyCharacterMap; |
| 44 | import android.view.KeyEvent; |
| 45 | import android.view.WindowManager; |
| 46 | import android.view.WindowManagerGlobal; |
| 47 | import android.view.accessibility.AccessibilityManager; |
| 48 | |
| 49 | import com.android.internal.R; |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 50 | import com.android.internal.accessibility.dialog.AccessibilityButtonChooserActivity; |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 51 | import com.android.internal.util.ScreenshotHelper; |
| 52 | import com.android.systemui.Dependency; |
| 53 | import com.android.systemui.SystemUI; |
| 54 | import com.android.systemui.recents.Recents; |
| 55 | import com.android.systemui.statusbar.phone.StatusBar; |
| 56 | |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 57 | import java.util.Locale; |
| 58 | |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 59 | import javax.inject.Inject; |
| 60 | import javax.inject.Singleton; |
| 61 | |
| 62 | /** |
| 63 | * Class to register system actions with accessibility framework. |
| 64 | */ |
| 65 | @Singleton |
| 66 | public class SystemActions extends SystemUI { |
| 67 | private static final String TAG = "SystemActions"; |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 68 | |
| 69 | /** |
| 70 | * Action ID to go back. |
| 71 | */ |
| 72 | private static final int SYSTEM_ACTION_ID_BACK = AccessibilityService.GLOBAL_ACTION_BACK; // = 1 |
| 73 | |
| 74 | /** |
| 75 | * Action ID to go home. |
| 76 | */ |
| 77 | private static final int SYSTEM_ACTION_ID_HOME = AccessibilityService.GLOBAL_ACTION_HOME; // = 2 |
| 78 | |
| 79 | /** |
| 80 | * Action ID to toggle showing the overview of recent apps. Will fail on platforms that don't |
| 81 | * show recent apps. |
| 82 | */ |
| 83 | private static final int SYSTEM_ACTION_ID_RECENTS = |
| 84 | AccessibilityService.GLOBAL_ACTION_RECENTS; // = 3 |
| 85 | |
| 86 | /** |
| 87 | * Action ID to open the notifications. |
| 88 | */ |
| 89 | private static final int SYSTEM_ACTION_ID_NOTIFICATIONS = |
| 90 | AccessibilityService.GLOBAL_ACTION_NOTIFICATIONS; // = 4 |
| 91 | |
| 92 | /** |
| 93 | * Action ID to open the quick settings. |
| 94 | */ |
| 95 | private static final int SYSTEM_ACTION_ID_QUICK_SETTINGS = |
| 96 | AccessibilityService.GLOBAL_ACTION_QUICK_SETTINGS; // = 5 |
| 97 | |
| 98 | /** |
| 99 | * Action ID to open the power long-press dialog. |
| 100 | */ |
| 101 | private static final int SYSTEM_ACTION_ID_POWER_DIALOG = |
| 102 | AccessibilityService.GLOBAL_ACTION_POWER_DIALOG; // = 6 |
| 103 | |
| 104 | /** |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 105 | * Action ID to lock the screen |
| 106 | */ |
| 107 | private static final int SYSTEM_ACTION_ID_LOCK_SCREEN = |
| 108 | AccessibilityService.GLOBAL_ACTION_LOCK_SCREEN; // = 8 |
| 109 | |
| 110 | /** |
| 111 | * Action ID to take a screenshot |
| 112 | */ |
| 113 | private static final int SYSTEM_ACTION_ID_TAKE_SCREENSHOT = |
| 114 | AccessibilityService.GLOBAL_ACTION_TAKE_SCREENSHOT; // = 9 |
| 115 | |
| 116 | /** |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 117 | * Action ID to trigger the accessibility button |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 118 | */ |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 119 | public static final int SYSTEM_ACTION_ID_ACCESSIBILITY_BUTTON = |
| 120 | AccessibilityService.GLOBAL_ACTION_ACCESSIBILITY_BUTTON; // 11 |
| 121 | |
| 122 | /** |
| 123 | * Action ID to show accessibility button's menu of services |
| 124 | */ |
| 125 | public static final int SYSTEM_ACTION_ID_ACCESSIBILITY_BUTTON_CHOOSER = |
| 126 | AccessibilityService.GLOBAL_ACTION_ACCESSIBILITY_BUTTON_CHOOSER; // 12 |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 127 | |
sallyyuen | 40dd559 | 2020-05-01 10:02:53 -0700 | [diff] [blame] | 128 | public static final int SYSTEM_ACTION_ID_ACCESSIBILITY_SHORTCUT = |
| 129 | AccessibilityService.GLOBAL_ACTION_ACCESSIBILITY_SHORTCUT; // 13 |
| 130 | |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 131 | private Recents mRecents; |
| 132 | private StatusBar mStatusBar; |
| 133 | private SystemActionsBroadcastReceiver mReceiver; |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 134 | private Locale mLocale; |
| 135 | private AccessibilityManager mA11yManager; |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 136 | |
| 137 | @Inject |
| 138 | public SystemActions(Context context) { |
| 139 | super(context); |
| 140 | mRecents = Dependency.get(Recents.class); |
| 141 | mStatusBar = Dependency.get(StatusBar.class); |
| 142 | mReceiver = new SystemActionsBroadcastReceiver(); |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 143 | mLocale = mContext.getResources().getConfiguration().getLocales().get(0); |
| 144 | mA11yManager = (AccessibilityManager) mContext.getSystemService( |
| 145 | Context.ACCESSIBILITY_SERVICE); |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | @Override |
| 149 | public void start() { |
| 150 | mContext.registerReceiverForAllUsers(mReceiver, mReceiver.createIntentFilter(), null, null); |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 151 | registerActions(); |
| 152 | } |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 153 | |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 154 | @Override |
| 155 | public void onConfigurationChanged(Configuration newConfig) { |
| 156 | super.onConfigurationChanged(newConfig); |
| 157 | final Locale locale = mContext.getResources().getConfiguration().getLocales().get(0); |
| 158 | if (!locale.equals(mLocale)) { |
| 159 | mLocale = locale; |
| 160 | registerActions(); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | private void registerActions() { |
| 165 | RemoteAction actionBack = createRemoteAction( |
| 166 | R.string.accessibility_system_action_back_label, |
| 167 | SystemActionsBroadcastReceiver.INTENT_ACTION_BACK); |
| 168 | |
| 169 | RemoteAction actionHome = createRemoteAction( |
| 170 | R.string.accessibility_system_action_home_label, |
| 171 | SystemActionsBroadcastReceiver.INTENT_ACTION_HOME); |
| 172 | |
| 173 | RemoteAction actionRecents = createRemoteAction( |
| 174 | R.string.accessibility_system_action_recents_label, |
| 175 | SystemActionsBroadcastReceiver.INTENT_ACTION_RECENTS); |
| 176 | |
| 177 | RemoteAction actionNotifications = createRemoteAction( |
| 178 | R.string.accessibility_system_action_notifications_label, |
| 179 | SystemActionsBroadcastReceiver.INTENT_ACTION_NOTIFICATIONS); |
| 180 | |
| 181 | RemoteAction actionQuickSettings = createRemoteAction( |
| 182 | R.string.accessibility_system_action_quick_settings_label, |
| 183 | SystemActionsBroadcastReceiver.INTENT_ACTION_QUICK_SETTINGS); |
| 184 | |
| 185 | RemoteAction actionPowerDialog = createRemoteAction( |
| 186 | R.string.accessibility_system_action_power_dialog_label, |
| 187 | SystemActionsBroadcastReceiver.INTENT_ACTION_POWER_DIALOG); |
| 188 | |
| 189 | RemoteAction actionLockScreen = createRemoteAction( |
| 190 | R.string.accessibility_system_action_lock_screen_label, |
| 191 | SystemActionsBroadcastReceiver.INTENT_ACTION_LOCK_SCREEN); |
| 192 | |
| 193 | RemoteAction actionTakeScreenshot = createRemoteAction( |
| 194 | R.string.accessibility_system_action_screenshot_label, |
| 195 | SystemActionsBroadcastReceiver.INTENT_ACTION_TAKE_SCREENSHOT); |
| 196 | |
sallyyuen | 40dd559 | 2020-05-01 10:02:53 -0700 | [diff] [blame] | 197 | RemoteAction actionAccessibilityShortcut = createRemoteAction( |
| 198 | R.string.accessibility_system_action_hardware_a11y_shortcut_label, |
| 199 | SystemActionsBroadcastReceiver.INTENT_ACTION_ACCESSIBILITY_SHORTCUT); |
| 200 | |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 201 | mA11yManager.registerSystemAction(actionBack, SYSTEM_ACTION_ID_BACK); |
| 202 | mA11yManager.registerSystemAction(actionHome, SYSTEM_ACTION_ID_HOME); |
| 203 | mA11yManager.registerSystemAction(actionRecents, SYSTEM_ACTION_ID_RECENTS); |
| 204 | mA11yManager.registerSystemAction(actionNotifications, SYSTEM_ACTION_ID_NOTIFICATIONS); |
| 205 | mA11yManager.registerSystemAction(actionQuickSettings, SYSTEM_ACTION_ID_QUICK_SETTINGS); |
| 206 | mA11yManager.registerSystemAction(actionPowerDialog, SYSTEM_ACTION_ID_POWER_DIALOG); |
| 207 | mA11yManager.registerSystemAction(actionLockScreen, SYSTEM_ACTION_ID_LOCK_SCREEN); |
| 208 | mA11yManager.registerSystemAction(actionTakeScreenshot, SYSTEM_ACTION_ID_TAKE_SCREENSHOT); |
sallyyuen | 40dd559 | 2020-05-01 10:02:53 -0700 | [diff] [blame] | 209 | mA11yManager.registerSystemAction( |
| 210 | actionAccessibilityShortcut, SYSTEM_ACTION_ID_ACCESSIBILITY_SHORTCUT); |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | /** |
| 214 | * Register a system action. |
| 215 | * @param actionId the action ID to register. |
| 216 | */ |
| 217 | public void register(int actionId) { |
| 218 | int labelId; |
| 219 | String intent; |
| 220 | switch (actionId) { |
| 221 | case SYSTEM_ACTION_ID_BACK: |
| 222 | labelId = R.string.accessibility_system_action_back_label; |
| 223 | intent = SystemActionsBroadcastReceiver.INTENT_ACTION_BACK; |
| 224 | break; |
| 225 | case SYSTEM_ACTION_ID_HOME: |
| 226 | labelId = R.string.accessibility_system_action_home_label; |
| 227 | intent = SystemActionsBroadcastReceiver.INTENT_ACTION_HOME; |
| 228 | break; |
| 229 | case SYSTEM_ACTION_ID_RECENTS: |
| 230 | labelId = R.string.accessibility_system_action_recents_label; |
| 231 | intent = SystemActionsBroadcastReceiver.INTENT_ACTION_RECENTS; |
| 232 | break; |
| 233 | case SYSTEM_ACTION_ID_NOTIFICATIONS: |
| 234 | labelId = R.string.accessibility_system_action_notifications_label; |
| 235 | intent = SystemActionsBroadcastReceiver.INTENT_ACTION_NOTIFICATIONS; |
| 236 | break; |
| 237 | case SYSTEM_ACTION_ID_QUICK_SETTINGS: |
| 238 | labelId = R.string.accessibility_system_action_quick_settings_label; |
| 239 | intent = SystemActionsBroadcastReceiver.INTENT_ACTION_QUICK_SETTINGS; |
| 240 | break; |
| 241 | case SYSTEM_ACTION_ID_POWER_DIALOG: |
| 242 | labelId = R.string.accessibility_system_action_power_dialog_label; |
| 243 | intent = SystemActionsBroadcastReceiver.INTENT_ACTION_POWER_DIALOG; |
| 244 | break; |
| 245 | case SYSTEM_ACTION_ID_LOCK_SCREEN: |
| 246 | labelId = R.string.accessibility_system_action_lock_screen_label; |
| 247 | intent = SystemActionsBroadcastReceiver.INTENT_ACTION_LOCK_SCREEN; |
| 248 | break; |
| 249 | case SYSTEM_ACTION_ID_TAKE_SCREENSHOT: |
| 250 | labelId = R.string.accessibility_system_action_screenshot_label; |
| 251 | intent = SystemActionsBroadcastReceiver.INTENT_ACTION_TAKE_SCREENSHOT; |
| 252 | break; |
| 253 | case SYSTEM_ACTION_ID_ACCESSIBILITY_BUTTON: |
sallyyuen | 40dd559 | 2020-05-01 10:02:53 -0700 | [diff] [blame] | 254 | labelId = R.string.accessibility_system_action_on_screen_a11y_shortcut_label; |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 255 | intent = SystemActionsBroadcastReceiver.INTENT_ACTION_ACCESSIBILITY_BUTTON; |
| 256 | break; |
| 257 | case SYSTEM_ACTION_ID_ACCESSIBILITY_BUTTON_CHOOSER: |
sallyyuen | 40dd559 | 2020-05-01 10:02:53 -0700 | [diff] [blame] | 258 | labelId = |
| 259 | R.string.accessibility_system_action_on_screen_a11y_shortcut_chooser_label; |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 260 | intent = SystemActionsBroadcastReceiver.INTENT_ACTION_ACCESSIBILITY_BUTTON_CHOOSER; |
| 261 | break; |
sallyyuen | 40dd559 | 2020-05-01 10:02:53 -0700 | [diff] [blame] | 262 | case SYSTEM_ACTION_ID_ACCESSIBILITY_SHORTCUT: |
| 263 | labelId = R.string.accessibility_system_action_hardware_a11y_shortcut_label; |
| 264 | intent = SystemActionsBroadcastReceiver.INTENT_ACTION_ACCESSIBILITY_SHORTCUT; |
| 265 | break; |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 266 | default: |
| 267 | return; |
| 268 | } |
| 269 | mA11yManager.registerSystemAction(createRemoteAction(labelId, intent), actionId); |
| 270 | } |
| 271 | |
| 272 | private RemoteAction createRemoteAction(int labelId, String intent) { |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 273 | // TODO(b/148087487): update the icon used below to a valid one |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 274 | return new RemoteAction( |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 275 | Icon.createWithResource(mContext, R.drawable.ic_info), |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 276 | mContext.getString(labelId), |
| 277 | mContext.getString(labelId), |
| 278 | mReceiver.createPendingIntent(mContext, intent)); |
| 279 | } |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 280 | |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 281 | /** |
| 282 | * Unregister a system action. |
| 283 | * @param actionId the action ID to unregister. |
| 284 | */ |
| 285 | public void unregister(int actionId) { |
| 286 | mA11yManager.unregisterSystemAction(actionId); |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | private void handleBack() { |
| 290 | sendDownAndUpKeyEvents(KeyEvent.KEYCODE_BACK); |
| 291 | } |
| 292 | |
| 293 | private void handleHome() { |
| 294 | sendDownAndUpKeyEvents(KeyEvent.KEYCODE_HOME); |
| 295 | } |
| 296 | |
| 297 | private void sendDownAndUpKeyEvents(int keyCode) { |
| 298 | final long downTime = SystemClock.uptimeMillis(); |
| 299 | sendKeyEventIdentityCleared(keyCode, KeyEvent.ACTION_DOWN, downTime, downTime); |
| 300 | sendKeyEventIdentityCleared( |
| 301 | keyCode, KeyEvent.ACTION_UP, downTime, SystemClock.uptimeMillis()); |
| 302 | } |
| 303 | |
| 304 | private void sendKeyEventIdentityCleared(int keyCode, int action, long downTime, long time) { |
| 305 | KeyEvent event = KeyEvent.obtain(downTime, time, action, keyCode, 0, 0, |
| 306 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FROM_SYSTEM, |
| 307 | InputDevice.SOURCE_KEYBOARD, null); |
| 308 | InputManager.getInstance() |
| 309 | .injectInputEvent(event, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC); |
| 310 | event.recycle(); |
| 311 | } |
| 312 | |
| 313 | private void handleRecents() { |
| 314 | mRecents.toggleRecentApps(); |
| 315 | } |
| 316 | |
| 317 | private void handleNotifications() { |
| 318 | mStatusBar.animateExpandNotificationsPanel(); |
| 319 | } |
| 320 | |
| 321 | private void handleQuickSettings() { |
| 322 | mStatusBar.animateExpandSettingsPanel(null); |
| 323 | } |
| 324 | |
| 325 | private void handlePowerDialog() { |
| 326 | IWindowManager windowManager = WindowManagerGlobal.getWindowManagerService(); |
| 327 | |
| 328 | try { |
| 329 | windowManager.showGlobalActions(); |
| 330 | } catch (RemoteException e) { |
| 331 | Log.e(TAG, "failed to display power dialog."); |
| 332 | } |
| 333 | } |
| 334 | |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 335 | private void handleLockScreen() { |
| 336 | IWindowManager windowManager = WindowManagerGlobal.getWindowManagerService(); |
| 337 | |
| 338 | mContext.getSystemService(PowerManager.class).goToSleep(SystemClock.uptimeMillis(), |
| 339 | PowerManager.GO_TO_SLEEP_REASON_ACCESSIBILITY, 0); |
| 340 | try { |
| 341 | windowManager.lockNow(null); |
| 342 | } catch (RemoteException e) { |
| 343 | Log.e(TAG, "failed to lock screen."); |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | private void handleTakeScreenshot() { |
| 348 | ScreenshotHelper screenshotHelper = new ScreenshotHelper(mContext); |
Miranda Kephart | 7b2c313 | 2020-03-27 09:54:14 -0400 | [diff] [blame] | 349 | screenshotHelper.takeScreenshot(WindowManager.TAKE_SCREENSHOT_FULLSCREEN, true, true, |
| 350 | SCREENSHOT_GLOBAL_ACTIONS, new Handler(Looper.getMainLooper()), null); |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 351 | } |
| 352 | |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 353 | private void handleAccessibilityButton() { |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 354 | AccessibilityManager.getInstance(mContext).notifyAccessibilityButtonClicked( |
| 355 | Display.DEFAULT_DISPLAY); |
| 356 | } |
| 357 | |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 358 | private void handleAccessibilityButtonChooser() { |
| 359 | final Intent intent = new Intent(AccessibilityManager.ACTION_CHOOSE_ACCESSIBILITY_BUTTON); |
| 360 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); |
| 361 | final String chooserClassName = AccessibilityButtonChooserActivity.class.getName(); |
| 362 | intent.setClassName(CHOOSER_PACKAGE_NAME, chooserClassName); |
| 363 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
| 364 | } |
| 365 | |
sallyyuen | 40dd559 | 2020-05-01 10:02:53 -0700 | [diff] [blame] | 366 | private void handleAccessibilityShortcut() { |
| 367 | mA11yManager.performAccessibilityShortcut(); |
| 368 | } |
| 369 | |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 370 | private class SystemActionsBroadcastReceiver extends BroadcastReceiver { |
| 371 | private static final String INTENT_ACTION_BACK = "SYSTEM_ACTION_BACK"; |
| 372 | private static final String INTENT_ACTION_HOME = "SYSTEM_ACTION_HOME"; |
| 373 | private static final String INTENT_ACTION_RECENTS = "SYSTEM_ACTION_RECENTS"; |
| 374 | private static final String INTENT_ACTION_NOTIFICATIONS = "SYSTEM_ACTION_NOTIFICATIONS"; |
| 375 | private static final String INTENT_ACTION_QUICK_SETTINGS = "SYSTEM_ACTION_QUICK_SETTINGS"; |
| 376 | private static final String INTENT_ACTION_POWER_DIALOG = "SYSTEM_ACTION_POWER_DIALOG"; |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 377 | private static final String INTENT_ACTION_LOCK_SCREEN = "SYSTEM_ACTION_LOCK_SCREEN"; |
| 378 | private static final String INTENT_ACTION_TAKE_SCREENSHOT = "SYSTEM_ACTION_TAKE_SCREENSHOT"; |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 379 | private static final String INTENT_ACTION_ACCESSIBILITY_BUTTON = |
| 380 | "SYSTEM_ACTION_ACCESSIBILITY_BUTTON"; |
| 381 | private static final String INTENT_ACTION_ACCESSIBILITY_BUTTON_CHOOSER = |
| 382 | "SYSTEM_ACTION_ACCESSIBILITY_BUTTON_MENU"; |
sallyyuen | 40dd559 | 2020-05-01 10:02:53 -0700 | [diff] [blame] | 383 | private static final String INTENT_ACTION_ACCESSIBILITY_SHORTCUT = |
| 384 | "SYSTEM_ACTION_ACCESSIBILITY_SHORTCUT"; |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 385 | |
| 386 | private PendingIntent createPendingIntent(Context context, String intentAction) { |
| 387 | switch (intentAction) { |
| 388 | case INTENT_ACTION_BACK: |
| 389 | case INTENT_ACTION_HOME: |
| 390 | case INTENT_ACTION_RECENTS: |
| 391 | case INTENT_ACTION_NOTIFICATIONS: |
| 392 | case INTENT_ACTION_QUICK_SETTINGS: |
| 393 | case INTENT_ACTION_POWER_DIALOG: |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 394 | case INTENT_ACTION_LOCK_SCREEN: |
| 395 | case INTENT_ACTION_TAKE_SCREENSHOT: |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 396 | case INTENT_ACTION_ACCESSIBILITY_BUTTON: |
sallyyuen | 40dd559 | 2020-05-01 10:02:53 -0700 | [diff] [blame] | 397 | case INTENT_ACTION_ACCESSIBILITY_BUTTON_CHOOSER: |
| 398 | case INTENT_ACTION_ACCESSIBILITY_SHORTCUT: { |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 399 | Intent intent = new Intent(intentAction); |
| 400 | return PendingIntent.getBroadcast(context, 0, intent, 0); |
| 401 | } |
| 402 | default: |
| 403 | break; |
| 404 | } |
| 405 | return null; |
| 406 | } |
| 407 | |
| 408 | private IntentFilter createIntentFilter() { |
| 409 | IntentFilter intentFilter = new IntentFilter(); |
| 410 | intentFilter.addAction(INTENT_ACTION_BACK); |
| 411 | intentFilter.addAction(INTENT_ACTION_HOME); |
| 412 | intentFilter.addAction(INTENT_ACTION_RECENTS); |
| 413 | intentFilter.addAction(INTENT_ACTION_NOTIFICATIONS); |
| 414 | intentFilter.addAction(INTENT_ACTION_QUICK_SETTINGS); |
| 415 | intentFilter.addAction(INTENT_ACTION_POWER_DIALOG); |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 416 | intentFilter.addAction(INTENT_ACTION_LOCK_SCREEN); |
| 417 | intentFilter.addAction(INTENT_ACTION_TAKE_SCREENSHOT); |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 418 | intentFilter.addAction(INTENT_ACTION_ACCESSIBILITY_BUTTON); |
| 419 | intentFilter.addAction(INTENT_ACTION_ACCESSIBILITY_BUTTON_CHOOSER); |
sallyyuen | 40dd559 | 2020-05-01 10:02:53 -0700 | [diff] [blame] | 420 | intentFilter.addAction(INTENT_ACTION_ACCESSIBILITY_SHORTCUT); |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 421 | return intentFilter; |
| 422 | } |
| 423 | |
| 424 | @Override |
| 425 | public void onReceive(Context context, Intent intent) { |
| 426 | String intentAction = intent.getAction(); |
| 427 | switch (intentAction) { |
| 428 | case INTENT_ACTION_BACK: { |
| 429 | handleBack(); |
| 430 | break; |
| 431 | } |
| 432 | case INTENT_ACTION_HOME: { |
| 433 | handleHome(); |
| 434 | break; |
| 435 | } |
| 436 | case INTENT_ACTION_RECENTS: { |
| 437 | handleRecents(); |
| 438 | break; |
| 439 | } |
| 440 | case INTENT_ACTION_NOTIFICATIONS: { |
| 441 | handleNotifications(); |
| 442 | break; |
| 443 | } |
| 444 | case INTENT_ACTION_QUICK_SETTINGS: { |
| 445 | handleQuickSettings(); |
| 446 | break; |
| 447 | } |
| 448 | case INTENT_ACTION_POWER_DIALOG: { |
| 449 | handlePowerDialog(); |
| 450 | break; |
| 451 | } |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 452 | case INTENT_ACTION_LOCK_SCREEN: { |
| 453 | handleLockScreen(); |
| 454 | break; |
| 455 | } |
| 456 | case INTENT_ACTION_TAKE_SCREENSHOT: { |
| 457 | handleTakeScreenshot(); |
| 458 | break; |
| 459 | } |
sallyyuen | 93edd11 | 2020-04-01 11:09:45 -0700 | [diff] [blame] | 460 | case INTENT_ACTION_ACCESSIBILITY_BUTTON: { |
| 461 | handleAccessibilityButton(); |
| 462 | break; |
| 463 | } |
| 464 | case INTENT_ACTION_ACCESSIBILITY_BUTTON_CHOOSER: { |
| 465 | handleAccessibilityButtonChooser(); |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 466 | break; |
| 467 | } |
sallyyuen | 40dd559 | 2020-05-01 10:02:53 -0700 | [diff] [blame] | 468 | case INTENT_ACTION_ACCESSIBILITY_SHORTCUT: { |
| 469 | handleAccessibilityShortcut(); |
| 470 | break; |
| 471 | } |
Hongming Jin | e0ab6b1 | 2020-01-16 14:52:19 -0800 | [diff] [blame] | 472 | default: |
| 473 | break; |
| 474 | } |
| 475 | } |
| 476 | } |
| 477 | } |