Add check for null manger for a11y recents action
Bug: 31986988
Test: Ran A11y cts
Change-Id: Ia6a1e1b921d8b0008edbcf1f1a8d1d3d0eb969c6
(cherry picked from commit 3cdd6c7654ff688b2dbd638e388bc56db7a020e2)
diff --git a/core/java/android/accessibilityservice/AccessibilityService.java b/core/java/android/accessibilityservice/AccessibilityService.java
index 163e7d2..b311c21 100644
--- a/core/java/android/accessibilityservice/AccessibilityService.java
+++ b/core/java/android/accessibilityservice/AccessibilityService.java
@@ -334,7 +334,8 @@
public static final int GLOBAL_ACTION_HOME = 2;
/**
- * Action to toggle showing the overview of recent apps
+ * Action to toggle showing the overview of recent apps. Will fail on platforms that don't
+ * show recent apps.
*/
public static final int GLOBAL_ACTION_RECENTS = 3;
diff --git a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
index e00178f..58bb5f3 100644
--- a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
+++ b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
@@ -2891,8 +2891,8 @@
sendDownAndUpKeyEvents(KeyEvent.KEYCODE_HOME);
} return true;
case AccessibilityService.GLOBAL_ACTION_RECENTS: {
- openRecents();
- } return true;
+ return openRecents();
+ }
case AccessibilityService.GLOBAL_ACTION_NOTIFICATIONS: {
expandNotifications();
} return true;
@@ -3385,14 +3385,19 @@
Binder.restoreCallingIdentity(token);
}
- private void openRecents() {
+ private boolean openRecents() {
final long token = Binder.clearCallingIdentity();
-
- StatusBarManagerInternal statusBarService = LocalServices.getService(
- StatusBarManagerInternal.class);
- statusBarService.toggleRecentApps();
-
- Binder.restoreCallingIdentity(token);
+ try {
+ StatusBarManagerInternal statusBarService = LocalServices.getService(
+ StatusBarManagerInternal.class);
+ if (statusBarService == null) {
+ return false;
+ }
+ statusBarService.toggleRecentApps();
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ return true;
}
private void showGlobalActions() {