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;
sendDownAndUpKeyEvents(KeyEvent.KEYCODE_HOME);
} return true;
case AccessibilityService.GLOBAL_ACTION_RECENTS: {
- openRecents();
- } return true;
+ return openRecents();
+ }
case AccessibilityService.GLOBAL_ACTION_NOTIFICATIONS: {
expandNotifications();
} return true;
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() {