From a8ad7e448c9e66b75fd7018bafdd8380c1b37adc Mon Sep 17 00:00:00 2001 From: Brian Isganitis Date: Tue, 8 Aug 2023 19:22:48 +0000 Subject: [PATCH] Launch Taskbar All Apps with Meta key when it's available. Taskbar All Apps will be chosen over Launcher's when we are in an app or in overview. Otherwise, we fallback to toggling Launcher All Apps. Test: Manual, adb shell input keyevent 117 Fix: 282111244 Flag: ENABLE_ALL_APPS_SEARCH_IN_TASKBAR Change-Id: I68e4cb3a80d42e233f7d9ad33fc3791b5c75d219 --- .../taskbar/TaskbarActivityContext.java | 5 +++ .../launcher3/taskbar/TaskbarManager.java | 20 +++++++++ .../quickstep/TouchInteractionService.java | 41 +++++++++++++++---- 3 files changed, 57 insertions(+), 9 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java index f7f3bfde47..987d91c488 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java @@ -334,6 +334,11 @@ public class TaskbarActivityContext extends BaseTaskbarContext { mControllers.taskbarStashController.showTaskbarFromBroadcast(); } + /** Toggles Taskbar All Apps overlay. */ + public void toggleAllApps() { + mControllers.taskbarAllAppsController.toggle(); + } + @Override public DeviceProfile getDeviceProfile() { return mDeviceProfile; diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java index 1809d403d7..ac90bcdae1 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java @@ -22,6 +22,7 @@ import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL; import static com.android.launcher3.LauncherPrefs.TASKBAR_PINNING; import static com.android.launcher3.LauncherPrefs.TASKBAR_PINNING_KEY; +import static com.android.launcher3.LauncherState.OVERVIEW; import static com.android.launcher3.util.DisplayController.TASKBAR_NOT_DESTROYED_TAG; import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR; import static com.android.launcher3.util.FlagDebugUtils.formatFlagChange; @@ -267,6 +268,25 @@ public class TaskbarManager { } } + /** + * Toggles All Apps for Taskbar or Launcher depending on the current state. + * + * @param homeAllAppsIntent Intent used if Taskbar is not enabled or Launcher is resumed. + */ + public void toggleAllApps(Intent homeAllAppsIntent) { + if (mTaskbarActivityContext == null) { + mContext.startActivity(homeAllAppsIntent); + return; + } + + if (mActivity != null && mActivity.isResumed() && !mActivity.isInState(OVERVIEW)) { + mContext.startActivity(homeAllAppsIntent); + return; + } + + mTaskbarActivityContext.toggleAllApps(); + } + /** * Displays a frame of the first Launcher reveal animation. * diff --git a/quickstep/src/com/android/quickstep/TouchInteractionService.java b/quickstep/src/com/android/quickstep/TouchInteractionService.java index f1244ff5db..7a9f88adb8 100644 --- a/quickstep/src/com/android/quickstep/TouchInteractionService.java +++ b/quickstep/src/com/android/quickstep/TouchInteractionService.java @@ -56,6 +56,8 @@ import android.annotation.TargetApi; import android.app.PendingIntent; import android.app.RemoteAction; import android.app.Service; +import android.content.IIntentReceiver; +import android.content.IIntentSender; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Configuration; @@ -571,15 +573,7 @@ public class TouchInteractionService extends Service { AccessibilityManager am = getSystemService(AccessibilityManager.class); if (isHomeAndOverviewSame) { - Intent intent = new Intent(mOverviewComponentObserver.getHomeIntent()) - .setAction(INTENT_ACTION_ALL_APPS_TOGGLE); - RemoteAction allAppsAction = new RemoteAction( - Icon.createWithResource(this, R.drawable.ic_apps), - getString(R.string.all_apps_label), - getString(R.string.all_apps_label), - PendingIntent.getActivity(this, GLOBAL_ACTION_ACCESSIBILITY_ALL_APPS, intent, - PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE)); - am.registerSystemAction(allAppsAction, GLOBAL_ACTION_ACCESSIBILITY_ALL_APPS); + am.registerSystemAction(createAllAppsAction(), GLOBAL_ACTION_ACCESSIBILITY_ALL_APPS); } else { am.unregisterSystemAction(GLOBAL_ACTION_ACCESSIBILITY_ALL_APPS); } @@ -592,6 +586,35 @@ public class TouchInteractionService extends Service { mTISBinder.onOverviewTargetChange(); } + private RemoteAction createAllAppsAction() { + final Intent homeIntent = new Intent(mOverviewComponentObserver.getHomeIntent()) + .setAction(INTENT_ACTION_ALL_APPS_TOGGLE); + final PendingIntent actionPendingIntent; + + if (FeatureFlags.ENABLE_ALL_APPS_SEARCH_IN_TASKBAR.get()) { + actionPendingIntent = new PendingIntent(new IIntentSender.Stub() { + @Override + public void send(int code, Intent intent, String resolvedType, + IBinder allowlistToken, IIntentReceiver finishedReceiver, + String requiredPermission, Bundle options) { + MAIN_EXECUTOR.execute(() -> mTaskbarManager.toggleAllApps(homeIntent)); + } + }); + } else { + actionPendingIntent = PendingIntent.getActivity( + this, + GLOBAL_ACTION_ACCESSIBILITY_ALL_APPS, + homeIntent, + PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE); + } + + return new RemoteAction( + Icon.createWithResource(this, R.drawable.ic_apps), + getString(R.string.all_apps_label), + getString(R.string.all_apps_label), + actionPendingIntent); + } + @UiThread private void onSystemUiFlagsChanged(int lastSysUIFlags) { if (LockedUserState.get(this).isUserUnlocked()) {