diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java index b58ad38597..9fe0c00bac 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java @@ -335,6 +335,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 528cb309cf..c423fb3608 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; @@ -270,6 +271,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()) {