From 1780cee0fe8d3133b9a4c217b46bf238452178a0 Mon Sep 17 00:00:00 2001 From: Tracy Zhou Date: Tue, 12 Jul 2022 00:13:24 -0700 Subject: [PATCH 1/5] Add testSplitFromOverview test (for phones) Design doc: go/split_tapl Bug: 238553914 Fixes: 239082974 Test: run this test Change-Id: I6b67ede6d62a9fb48222aa4d15fe29ccd1d0fa06 --- .../android/quickstep/TaplTestsQuickstep.java | 15 ++++++ .../android/launcher3/tapl/BaseOverview.java | 6 ++- .../tapl/LauncherInstrumentation.java | 17 +++++- .../android/launcher3/tapl/OverviewTask.java | 17 ++++++ .../launcher3/tapl/OverviewTaskMenu.java | 52 +++++++++++++++++++ .../launcher3/tapl/SplitScreenSelect.java | 6 +++ 6 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 tests/tapl/com/android/launcher3/tapl/OverviewTaskMenu.java diff --git a/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java b/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java index 81df3c0f1a..b52ab9b341 100644 --- a/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java +++ b/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java @@ -179,6 +179,21 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest { actionsView.clickAndDismissScreenshot(); } + @Test + @PortraitLandscape + public void testSplitFromOverview() { + assumeTrue(!mLauncher.isTablet()); + + startTestActivity(2); + startTestActivity(3); + + mLauncher.goHome().switchToOverview().getCurrentTask() + .tapMenu() + .tapSplitMenuItem() + .getTestActivityTask(2) + .open(); + } + @Test @PortraitLandscape public void testSplitFromOverviewForTablet() { diff --git a/tests/tapl/com/android/launcher3/tapl/BaseOverview.java b/tests/tapl/com/android/launcher3/tapl/BaseOverview.java index 6a11336bb9..3321c63502 100644 --- a/tests/tapl/com/android/launcher3/tapl/BaseOverview.java +++ b/tests/tapl/com/android/launcher3/tapl/BaseOverview.java @@ -247,8 +247,12 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer { return mLauncher.hasLauncherObject(mLauncher.getOverviewObjectSelector("clear_all")); } + protected boolean isActionsViewVisible() { + return true; + } + private void verifyActionsViewVisibility() { - if (!hasTasks()) { + if (!hasTasks() || !isActionsViewVisible()) { return; } try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer( diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 5f920972ca..3de49e65a5 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -169,6 +169,7 @@ public final class LauncherInstrumentation { private static final String WIDGETS_RES_ID = "primary_widgets_list_view"; private static final String CONTEXT_MENU_RES_ID = "popup_container"; private static final String TASKBAR_RES_ID = "taskbar_view"; + private static final String SPLIT_PLACEHOLDER_RES_ID = "split_placeholder"; public static final int WAIT_TIME_MS = 30000; private static final String SYSTEMUI_PACKAGE = "com.android.systemui"; private static final String ANDROID_PACKAGE = "android"; @@ -724,6 +725,7 @@ public final class LauncherInstrumentation { waitUntilLauncherObjectGone(OVERVIEW_RES_ID); waitUntilLauncherObjectGone(WIDGETS_RES_ID); waitUntilLauncherObjectGone(TASKBAR_RES_ID); + waitUntilLauncherObjectGone(SPLIT_PLACEHOLDER_RES_ID); return waitForLauncherObject(WORKSPACE_RES_ID); } @@ -732,6 +734,7 @@ public final class LauncherInstrumentation { waitUntilLauncherObjectGone(APPS_RES_ID); waitUntilLauncherObjectGone(OVERVIEW_RES_ID); waitUntilLauncherObjectGone(TASKBAR_RES_ID); + waitUntilLauncherObjectGone(SPLIT_PLACEHOLDER_RES_ID); return waitForLauncherObject(WIDGETS_RES_ID); } @@ -741,16 +744,26 @@ public final class LauncherInstrumentation { waitUntilLauncherObjectGone(OVERVIEW_RES_ID); waitUntilLauncherObjectGone(WIDGETS_RES_ID); waitUntilLauncherObjectGone(TASKBAR_RES_ID); + waitUntilLauncherObjectGone(SPLIT_PLACEHOLDER_RES_ID); return waitForLauncherObject(APPS_RES_ID); } - case OVERVIEW: + case OVERVIEW: { + waitUntilLauncherObjectGone(APPS_RES_ID); + waitUntilLauncherObjectGone(WORKSPACE_RES_ID); + waitUntilLauncherObjectGone(WIDGETS_RES_ID); + waitUntilLauncherObjectGone(TASKBAR_RES_ID); + waitUntilLauncherObjectGone(SPLIT_PLACEHOLDER_RES_ID); + + return waitForLauncherObject(OVERVIEW_RES_ID); + } case SPLIT_SCREEN_SELECT: { waitUntilLauncherObjectGone(APPS_RES_ID); waitUntilLauncherObjectGone(WORKSPACE_RES_ID); waitUntilLauncherObjectGone(WIDGETS_RES_ID); waitUntilLauncherObjectGone(TASKBAR_RES_ID); + waitForLauncherObject(SPLIT_PLACEHOLDER_RES_ID); return waitForLauncherObject(OVERVIEW_RES_ID); } case FALLBACK_OVERVIEW: { @@ -758,6 +771,7 @@ public final class LauncherInstrumentation { waitUntilLauncherObjectGone(WORKSPACE_RES_ID); waitUntilLauncherObjectGone(WIDGETS_RES_ID); waitUntilLauncherObjectGone(TASKBAR_RES_ID); + waitUntilLauncherObjectGone(SPLIT_PLACEHOLDER_RES_ID); return waitForFallbackLauncherObject(OVERVIEW_RES_ID); } @@ -766,6 +780,7 @@ public final class LauncherInstrumentation { waitUntilLauncherObjectGone(APPS_RES_ID); waitUntilLauncherObjectGone(OVERVIEW_RES_ID); waitUntilLauncherObjectGone(WIDGETS_RES_ID); + waitUntilLauncherObjectGone(SPLIT_PLACEHOLDER_RES_ID); if (isTablet() && !isFallbackOverview()) { waitForLauncherObject(TASKBAR_RES_ID); diff --git a/tests/tapl/com/android/launcher3/tapl/OverviewTask.java b/tests/tapl/com/android/launcher3/tapl/OverviewTask.java index ac7424ef26..a90d4ea3c0 100644 --- a/tests/tapl/com/android/launcher3/tapl/OverviewTask.java +++ b/tests/tapl/com/android/launcher3/tapl/OverviewTask.java @@ -20,6 +20,7 @@ import static android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_STATE_CH import android.graphics.Rect; +import androidx.annotation.NonNull; import androidx.test.uiautomator.By; import androidx.test.uiautomator.BySelector; import androidx.test.uiautomator.UiObject2; @@ -159,4 +160,20 @@ public final class OverviewTask { } } } + + /** Taps the task menu. */ + @NonNull + public OverviewTaskMenu tapMenu() { + try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck(); + LauncherInstrumentation.Closable c = mLauncher.addContextLayer( + "want to tap the task menu")) { + mLauncher.clickLauncherObject( + mLauncher.waitForObjectInContainer(mTask.getParent(), "icon")); + + try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer( + "tapped the task menu")) { + return new OverviewTaskMenu(mLauncher); + } + } + } } diff --git a/tests/tapl/com/android/launcher3/tapl/OverviewTaskMenu.java b/tests/tapl/com/android/launcher3/tapl/OverviewTaskMenu.java new file mode 100644 index 0000000000..8cdc8a036e --- /dev/null +++ b/tests/tapl/com/android/launcher3/tapl/OverviewTaskMenu.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3.tapl; + +import androidx.annotation.NonNull; +import androidx.test.uiautomator.By; +import androidx.test.uiautomator.UiObject2; + +/** Represents the menu of an overview task. */ +public class OverviewTaskMenu { + + private final LauncherInstrumentation mLauncher; + private final UiObject2 mMenu; + + OverviewTaskMenu(LauncherInstrumentation launcher) { + mLauncher = launcher; + + mMenu = mLauncher.waitForLauncherObject("menu_option_layout"); + mLauncher.assertTrue("The overview task menus is not visible", + !mMenu.getVisibleBounds().isEmpty()); + } + + /** Taps the split menu item from the overview task menu. */ + @NonNull + public SplitScreenSelect tapSplitMenuItem() { + try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck(); + LauncherInstrumentation.Closable c = mLauncher.addContextLayer( + "tap split menu item")) { + mLauncher.clickLauncherObject( + mLauncher.findObjectInContainer(mMenu, By.textStartsWith("Split"))); + + try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer( + "tapped split menu item")) { + return new SplitScreenSelect(mLauncher); + } + } + } +} diff --git a/tests/tapl/com/android/launcher3/tapl/SplitScreenSelect.java b/tests/tapl/com/android/launcher3/tapl/SplitScreenSelect.java index 3cf3ed662f..9fa74e48c2 100644 --- a/tests/tapl/com/android/launcher3/tapl/SplitScreenSelect.java +++ b/tests/tapl/com/android/launcher3/tapl/SplitScreenSelect.java @@ -32,4 +32,10 @@ public class SplitScreenSelect extends Overview { protected ContainerType getContainerType() { return ContainerType.SPLIT_SCREEN_SELECT; } + + @Override + protected boolean isActionsViewVisible() { + // We don't show overview actions in split select state. + return false; + } } From f3636d09e7bde2e08ade4a86e1a19ea2e3f8d07d Mon Sep 17 00:00:00 2001 From: Tony Wickham Date: Wed, 27 Jul 2022 08:06:42 -0700 Subject: [PATCH 2/5] Set FLAG_RESUMED = false when expanding PiP This allows us to play the icon alignment animation immediately, rather than waiting for the expand to finish and launcher to be paused. Test: Open Maps in PiP on home screen, expand it and watch taskbar Fixes: 239506421 Change-Id: I5c04f778c4c39c2895db0a1ea1fca4d48d1f3093 --- .../launcher3/taskbar/LauncherTaskbarUIController.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java b/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java index 6df31e5670..62a11d4954 100644 --- a/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java +++ b/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java @@ -353,6 +353,13 @@ public class LauncherTaskbarUIController extends TaskbarUIController { .get(); } + @Override + public void onExpandPip() { + super.onExpandPip(); + mTaskbarLauncherStateController.updateStateForFlag(FLAG_RESUMED, false); + mTaskbarLauncherStateController.applyState(); + } + @Override public void dumpLogs(String prefix, PrintWriter pw) { super.dumpLogs(prefix, pw); From eeb66e41e5a4a42f789b61d46d17ff1992094a55 Mon Sep 17 00:00:00 2001 From: Tony Wickham Date: Wed, 27 Jul 2022 09:39:26 -0700 Subject: [PATCH 3/5] Cleanup taskbar+assistant interactions - Always move the taskbar layer when voice interaction window visibility changes, to ensure we remove the temporary taskbar background in all cases (e.g. swipe to home) - Move check to not draw taskbar background to the temporary view itself, so that it's at the proper layer when shown (e.g. during fulfillment on the home screen) - Don't add view to window if it's already added (we already have this check for the removal case) Test: Open an app, invoke Assistant, swipe home; Taskbar background is removed; invoke and fulfill assistant from home screen, in app, in 3 button mode, and in gesture mode (all permutations) Fixes: 236924161 Fixes: 240101132 Fixes: 235895444 Change-Id: I5958f1dbe14a6d190d3808014429f7f8146c9f96 --- .../taskbar/TaskbarActivityContext.java | 4 +++- .../taskbar/VoiceInteractionWindowController.kt | 17 +++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java index 439490e00c..24886dca3c 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java @@ -622,7 +622,9 @@ public class TaskbarActivityContext extends BaseTaskbarContext { /** Adds the given view to WindowManager with the provided LayoutParams (creates new window). */ public void addWindowView(View view, WindowManager.LayoutParams windowLayoutParams) { - mWindowManager.addView(view, windowLayoutParams); + if (!view.isAttachedToWindow()) { + mWindowManager.addView(view, windowLayoutParams); + } } /** Removes the given view from WindowManager. See {@link #addWindowView}. */ diff --git a/quickstep/src/com/android/launcher3/taskbar/VoiceInteractionWindowController.kt b/quickstep/src/com/android/launcher3/taskbar/VoiceInteractionWindowController.kt index 946873e7ab..81acda3d75 100644 --- a/quickstep/src/com/android/launcher3/taskbar/VoiceInteractionWindowController.kt +++ b/quickstep/src/com/android/launcher3/taskbar/VoiceInteractionWindowController.kt @@ -36,7 +36,10 @@ class VoiceInteractionWindowController(val context: TaskbarActivityContext) override fun draw(canvas: Canvas) { super.draw(canvas) - taskbarBackgroundRenderer.draw(canvas) + if (this@VoiceInteractionWindowController.context.isGestureNav + && controllers.taskbarStashController.isInAppAndNotStashed) { + taskbarBackgroundRenderer.draw(canvas) + } } } separateWindowForTaskbarBackground.recreateControllers() @@ -74,18 +77,20 @@ class VoiceInteractionWindowController(val context: TaskbarActivityContext) fadeStashedHandle.end() } - if (context.isGestureNav && controllers.taskbarStashController.isInAppAndNotStashed) { - moveTaskbarBackgroundToLowerLayer() - } + moveTaskbarBackgroundToAppropriateLayer() } /** + * Either: * Hides the TaskbarDragLayer background and creates a new window to draw just that background. + * OR + * Removes the temporary window and show the TaskbarDragLayer background again. */ - private fun moveTaskbarBackgroundToLowerLayer() { + private fun moveTaskbarBackgroundToAppropriateLayer() { val taskbarBackgroundOverride = controllers.taskbarDragLayerController .overrideBackgroundAlpha - if (isVoiceInteractionWindowVisible) { + val moveToLowerLayer = isVoiceInteractionWindowVisible + if (moveToLowerLayer) { // First add the temporary window, then hide the overlapping taskbar background. context.addWindowView(separateWindowForTaskbarBackground, separateWindowLayoutParams) ViewRootSync.synchronizeNextDraw(separateWindowForTaskbarBackground, context.dragLayer From 87a9bf7c15ad33b4288db1f20fbaeec571c9bf95 Mon Sep 17 00:00:00 2001 From: Andy Wickham Date: Fri, 8 Jul 2022 20:31:22 -0700 Subject: [PATCH 4/5] Only bind fast scrollbar when attached if not already bound. This was overriding the previously bound RecyclerView if multiple were attached simultaneously. Instead, the appropriate container (All Apps / Widgets) should bind the active RecyclerView whenever it changes, with the onAttach serving as a fallback to ensure the scrollbar has an initial RV to avoid NPEs. Fix: 234591523 Bug: 235476489 Test: Manually checked All Apps from Launcher and Taskbar, as well as Widget bottom sheet. Also ran relevant Tapl tests. Change-Id: I06e27d2f66f9778087711a566817b6806ec7218b --- src/com/android/launcher3/FastScrollRecyclerView.java | 4 +++- .../android/launcher3/views/RecyclerViewFastScroller.java | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/com/android/launcher3/FastScrollRecyclerView.java b/src/com/android/launcher3/FastScrollRecyclerView.java index 94903f278e..747b755263 100644 --- a/src/com/android/launcher3/FastScrollRecyclerView.java +++ b/src/com/android/launcher3/FastScrollRecyclerView.java @@ -57,7 +57,9 @@ public abstract class FastScrollRecyclerView extends RecyclerView { @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); - bindFastScrollbar(); + if (mScrollbar == null || !mScrollbar.hasRecyclerView()) { + bindFastScrollbar(); + } } public void bindFastScrollbar() { diff --git a/src/com/android/launcher3/views/RecyclerViewFastScroller.java b/src/com/android/launcher3/views/RecyclerViewFastScroller.java index 11ca130179..6e6512d294 100644 --- a/src/com/android/launcher3/views/RecyclerViewFastScroller.java +++ b/src/com/android/launcher3/views/RecyclerViewFastScroller.java @@ -174,6 +174,11 @@ public class RecyclerViewFastScroller extends View { ta.recycle(); } + /** @return whether there is a RecyclerView bound to this scroller. */ + public boolean hasRecyclerView() { + return mRv != null; + } + public void setRecyclerView(FastScrollRecyclerView rv, TextView popupView) { if (mRv != null && mOnScrollListener != null) { mRv.removeOnScrollListener(mOnScrollListener); From 5dbd289f188bac055c80c09450061607639c769e Mon Sep 17 00:00:00 2001 From: Merissa Tan Date: Tue, 25 Jan 2022 19:46:55 -0800 Subject: [PATCH 5/5] Add running apps icons to taskbar for desktop environment. This CL adds app icons for launched/running apps to the Launcher taskbar hotseat. When the activity is closed, the app icon is removed. The apps that are added to the taskbar on boot are never removed. Recall: http://recall/clips/ad6d3cfc-7358-4b37-846e-de843ad3000d Bug: 183906774 Test: Launch an app and verify the app icon is added on the taskbar. Close the app and verify the icon is removed from the taskbar. Test: Switch navigation modes on the emulator and ensure that running app icons are added to the taskbar after it is reinitialized. Test: atest NexusLauncherTests:com.android.quickstep.RecentTasksListTest RecentTasksControllerTest Change-Id: Ieaaf001530b5778871fb7a8d18cdcaa1ccbf0e31 Merged-In: Ieaaf001530b5778871fb7a8d18cdcaa1ccbf0e31 --- .../DesktopTaskbarRecentAppsController.java | 153 ++++++++++++++++++ .../taskbar/DesktopTaskbarUIController.java | 3 + .../taskbar/TaskbarActivityContext.java | 13 +- .../launcher3/taskbar/TaskbarControllers.java | 7 +- .../taskbar/TaskbarModelCallbacks.java | 31 +++- .../taskbar/TaskbarRecentAppsController.java | 63 ++++++++ .../taskbar/TaskbarViewController.java | 11 ++ .../android/quickstep/RecentTasksList.java | 76 +++++++++ .../com/android/quickstep/RecentsModel.java | 31 ++++ .../com/android/quickstep/SystemUiProxy.java | 20 +++ 10 files changed, 402 insertions(+), 6 deletions(-) create mode 100644 quickstep/src/com/android/launcher3/taskbar/DesktopTaskbarRecentAppsController.java create mode 100644 quickstep/src/com/android/launcher3/taskbar/TaskbarRecentAppsController.java diff --git a/quickstep/src/com/android/launcher3/taskbar/DesktopTaskbarRecentAppsController.java b/quickstep/src/com/android/launcher3/taskbar/DesktopTaskbarRecentAppsController.java new file mode 100644 index 0000000000..acfbea38b7 --- /dev/null +++ b/quickstep/src/com/android/launcher3/taskbar/DesktopTaskbarRecentAppsController.java @@ -0,0 +1,153 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.launcher3.taskbar; + +import android.app.ActivityManager; +import android.content.ComponentName; +import android.util.SparseArray; + +import com.android.launcher3.model.data.AppInfo; +import com.android.launcher3.model.data.ItemInfo; +import com.android.launcher3.model.data.WorkspaceItemInfo; +import com.android.quickstep.RecentsModel; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +/** + * Provides recent apps functionality specifically in a desktop environment. + */ +public class DesktopTaskbarRecentAppsController extends TaskbarRecentAppsController { + + private final TaskbarActivityContext mContext; + private ArrayList mRunningApps = new ArrayList<>(); + private AppInfo[] mApps; + + public DesktopTaskbarRecentAppsController(TaskbarActivityContext context) { + mContext = context; + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mApps = null; + } + + @Override + protected void setApps(AppInfo[] apps) { + mApps = apps; + } + + @Override + protected boolean isEnabled() { + return true; + } + + /** + * Set mRunningApps to hold currently running applications using the list of currently running + * tasks. Filtering is also done to ignore applications that are already on the taskbar in the + * original hotseat. + */ + @Override + protected void updateRunningApps(SparseArray hotseatItems) { + ArrayList runningApps = getRunningAppsFromTasks(); + ArrayList filteredRunningApps = new ArrayList<>(); + for (AppInfo runningApp : runningApps) { + boolean shouldAddOnTaskbar = true; + for (int i = 0; i < hotseatItems.size(); i++) { + if (hotseatItems.keyAt(i) >= mControllers.taskbarActivityContext.getDeviceProfile() + .numShownHotseatIcons) { + break; + } + if (hotseatItems.valueAt(i).getTargetPackage() + .equals(runningApp.getTargetPackage())) { + shouldAddOnTaskbar = false; + break; + } + } + if (shouldAddOnTaskbar) { + filteredRunningApps.add(new WorkspaceItemInfo(runningApp)); + } + } + mRunningApps = filteredRunningApps; + mControllers.taskbarViewController.commitRunningAppsToUI(); + } + + /** + * Returns a copy of hotseatItems with the addition of currently running applications. + */ + @Override + protected ItemInfo[] updateHotseatItemInfos(ItemInfo[] hotseatItemInfos) { + // hotseatItemInfos.length would be 0 if deviceProfile.numShownHotseatIcons is 0, so we + // don't want to show anything in the hotseat + if (hotseatItemInfos.length == 0) return hotseatItemInfos; + + int runningAppsIndex = 0; + ItemInfo[] newHotseatItemsInfo = Arrays.copyOf( + hotseatItemInfos, hotseatItemInfos.length + mRunningApps.size()); + for (int i = hotseatItemInfos.length; i < newHotseatItemsInfo.length; i++) { + newHotseatItemsInfo[i] = mRunningApps.get(runningAppsIndex); + runningAppsIndex++; + } + return newHotseatItemsInfo; + } + + + /** + * Returns a list of running applications from the list of currently running tasks. + */ + private ArrayList getRunningAppsFromTasks() { + ArrayList tasks = + RecentsModel.INSTANCE.get(mContext).getRunningTasks(); + ArrayList runningApps = new ArrayList<>(); + // early return if apps is empty, since we would have no AppInfo to compare + if (mApps == null) { + return runningApps; + } + + Set seenPackages = new HashSet<>(); + for (ActivityManager.RunningTaskInfo taskInfo : tasks) { + if (taskInfo.realActivity == null) continue; + + // If a different task for the same package has already been handled, skip this one + String taskPackage = taskInfo.realActivity.getPackageName(); + if (seenPackages.contains(taskPackage)) continue; + + // Otherwise, get the corresponding AppInfo and add it to the list + seenPackages.add(taskPackage); + AppInfo app = getAppInfo(taskInfo.realActivity); + if (app == null) continue; + runningApps.add(app); + } + return runningApps; + } + + /** + * Retrieves the corresponding AppInfo for the activity. + */ + private AppInfo getAppInfo(ComponentName activity) { + String packageName = activity.getPackageName(); + for (AppInfo app : mApps) { + if (!packageName.equals(app.getTargetPackage())) { + continue; + } + return app; + } + return null; + } +} diff --git a/quickstep/src/com/android/launcher3/taskbar/DesktopTaskbarUIController.java b/quickstep/src/com/android/launcher3/taskbar/DesktopTaskbarUIController.java index e2359c0d5e..3c76e8ec2d 100644 --- a/quickstep/src/com/android/launcher3/taskbar/DesktopTaskbarUIController.java +++ b/quickstep/src/com/android/launcher3/taskbar/DesktopTaskbarUIController.java @@ -32,11 +32,14 @@ public class DesktopTaskbarUIController extends TaskbarUIController { @Override protected void init(TaskbarControllers taskbarControllers) { + super.init(taskbarControllers); mLauncher.getHotseat().setIconsAlpha(0f); + mControllers.taskbarViewController.updateRunningApps(); } @Override protected void onDestroy() { + super.onDestroy(); mLauncher.getHotseat().setIconsAlpha(1f); } diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java index 36806bcf2d..2f6c2c074f 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java @@ -173,13 +173,15 @@ public class TaskbarActivityContext extends BaseTaskbarContext { mAccessibilityDelegate = new TaskbarShortcutMenuAccessibilityDelegate(this); + final boolean isDesktopMode = getPackageManager().hasSystemFeature(FEATURE_PC); + // Construct controllers. mControllers = new TaskbarControllers(this, new TaskbarDragController(this), buttonController, - getPackageManager().hasSystemFeature(FEATURE_PC) - ? new DesktopNavbarButtonsViewController(this, navButtonsView) : - new NavbarButtonsViewController(this, navButtonsView), + isDesktopMode + ? new DesktopNavbarButtonsViewController(this, navButtonsView) + : new NavbarButtonsViewController(this, navButtonsView), new RotationButtonController(this, c.getColor(R.color.taskbar_nav_icon_light_color), c.getColor(R.color.taskbar_nav_icon_dark_color), @@ -202,7 +204,10 @@ public class TaskbarActivityContext extends BaseTaskbarContext { new TaskbarForceVisibleImmersiveController(this), new TaskbarAllAppsController(this, dp), new TaskbarInsetsController(this), - new VoiceInteractionWindowController(this)); + new VoiceInteractionWindowController(this), + isDesktopMode + ? new DesktopTaskbarRecentAppsController(this) + : TaskbarRecentAppsController.DEFAULT); } public void init(@NonNull TaskbarSharedState sharedState) { diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java index d7b50b0994..2b80b753fb 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java @@ -53,6 +53,7 @@ public class TaskbarControllers { public final TaskbarAllAppsController taskbarAllAppsController; public final TaskbarInsetsController taskbarInsetsController; public final VoiceInteractionWindowController voiceInteractionWindowController; + public final TaskbarRecentAppsController taskbarRecentAppsController; @Nullable private LoggableTaskbarController[] mControllersToLog = null; @@ -82,7 +83,8 @@ public class TaskbarControllers { TaskbarForceVisibleImmersiveController taskbarForceVisibleImmersiveController, TaskbarAllAppsController taskbarAllAppsController, TaskbarInsetsController taskbarInsetsController, - VoiceInteractionWindowController voiceInteractionWindowController) { + VoiceInteractionWindowController voiceInteractionWindowController, + TaskbarRecentAppsController taskbarRecentAppsController) { this.taskbarActivityContext = taskbarActivityContext; this.taskbarDragController = taskbarDragController; this.navButtonController = navButtonController; @@ -102,6 +104,7 @@ public class TaskbarControllers { this.taskbarAllAppsController = taskbarAllAppsController; this.taskbarInsetsController = taskbarInsetsController; this.voiceInteractionWindowController = voiceInteractionWindowController; + this.taskbarRecentAppsController = taskbarRecentAppsController; } /** @@ -130,6 +133,7 @@ public class TaskbarControllers { navButtonController.init(this); taskbarInsetsController.init(this); voiceInteractionWindowController.init(this); + taskbarRecentAppsController.init(this); mControllersToLog = new LoggableTaskbarController[] { taskbarDragController, navButtonController, navbarButtonsViewController, @@ -178,6 +182,7 @@ public class TaskbarControllers { navButtonController.onDestroy(); taskbarInsetsController.onDestroy(); voiceInteractionWindowController.onDestroy(); + taskbarRecentAppsController.onDestroy(); mControllersToLog = null; } diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarModelCallbacks.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarModelCallbacks.java index 75881a31f2..5e670d2946 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarModelCallbacks.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarModelCallbacks.java @@ -29,6 +29,7 @@ import com.android.launcher3.util.IntArray; import com.android.launcher3.util.IntSet; import com.android.launcher3.util.ItemInfoMatcher; import com.android.launcher3.util.LauncherBindableItemsContainer; +import com.android.quickstep.RecentsModel; import java.io.PrintWriter; import java.util.ArrayList; @@ -42,7 +43,7 @@ import java.util.function.Predicate; * Launcher model Callbacks for rendering taskbar. */ public class TaskbarModelCallbacks implements - BgDataModel.Callbacks, LauncherBindableItemsContainer { + BgDataModel.Callbacks, LauncherBindableItemsContainer, RecentsModel.RunningTasksListener { private final SparseArray mHotseatItems = new SparseArray<>(); private List mPredictedItems = Collections.emptyList(); @@ -61,6 +62,16 @@ public class TaskbarModelCallbacks implements public void init(TaskbarControllers controllers) { mControllers = controllers; + if (mControllers.taskbarRecentAppsController.isEnabled()) { + RecentsModel.INSTANCE.get(mContext).registerRunningTasksListener(this); + } + } + + /** + * Unregisters listeners in this class. + */ + public void unregisterListeners() { + RecentsModel.INSTANCE.get(mContext).unregisterRunningTasksListener(); } @Override @@ -185,6 +196,8 @@ public class TaskbarModelCallbacks implements isHotseatEmpty = false; } } + hotseatItemInfos = mControllers.taskbarRecentAppsController + .updateHotseatItemInfos(hotseatItemInfos); mContainer.updateHotseatItems(hotseatItemInfos); final boolean finalIsHotseatEmpty = isHotseatEmpty; @@ -195,6 +208,21 @@ public class TaskbarModelCallbacks implements }); } + @Override + public void onRunningTasksChanged() { + updateRunningApps(); + } + + /** Called when there's a change in running apps to update the UI. */ + public void commitRunningAppsToUI() { + commitItemsToUI(); + } + + /** Call TaskbarRecentAppsController to update running apps with mHotseatItems. */ + public void updateRunningApps() { + mControllers.taskbarRecentAppsController.updateRunningApps(mHotseatItems); + } + @Override public void bindDeepShortcutMap(HashMap deepShortcutMapCopy) { mControllers.taskbarPopupController.setDeepShortcutMap(deepShortcutMapCopy); @@ -203,6 +231,7 @@ public class TaskbarModelCallbacks implements @Override public void bindAllApplications(AppInfo[] apps, int flags) { mControllers.taskbarAllAppsController.setApps(apps, flags); + mControllers.taskbarRecentAppsController.setApps(apps); } protected void dumpLogs(String prefix, PrintWriter pw) { diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarRecentAppsController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarRecentAppsController.java new file mode 100644 index 0000000000..8445cff0ee --- /dev/null +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarRecentAppsController.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.launcher3.taskbar; + +import android.util.SparseArray; + +import androidx.annotation.CallSuper; + +import com.android.launcher3.model.data.AppInfo; +import com.android.launcher3.model.data.ItemInfo; + +/** + * Base class for providing recent apps functionality + */ +public class TaskbarRecentAppsController { + + public static final TaskbarRecentAppsController DEFAULT = new TaskbarRecentAppsController(); + + // Initialized in init. + protected TaskbarControllers mControllers; + + @CallSuper + protected void init(TaskbarControllers taskbarControllers) { + mControllers = taskbarControllers; + } + + @CallSuper + protected void onDestroy() { + mControllers = null; + } + + /** Stores the current {@link AppInfo} instances, no-op except in desktop environment. */ + protected void setApps(AppInfo[] apps) { } + + /** + * Indicates whether recent apps functionality is enabled, should return false except in + * desktop environment. + */ + protected boolean isEnabled() { + return false; + } + + /** Called to update hotseatItems, no-op except in desktop environment. */ + protected ItemInfo[] updateHotseatItemInfos(ItemInfo[] hotseatItems) { + return hotseatItems; + } + + /** Called to update the list of currently running apps, no-op except in desktop environment. */ + protected void updateRunningApps(SparseArray hotseatItems) { } +} diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarViewController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarViewController.java index 6d45fd2d5c..077172da18 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarViewController.java @@ -126,6 +126,7 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar public void onDestroy() { LauncherAppState.getInstance(mActivity).getModel().removeCallbacks(mModelCallbacks); + mModelCallbacks.unregisterListeners(); } public boolean areIconsVisible() { @@ -389,6 +390,16 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar mModelCallbacks.dumpLogs(prefix + "\t", pw); } + /** Called when there's a change in running apps to update the UI. */ + public void commitRunningAppsToUI() { + mModelCallbacks.commitRunningAppsToUI(); + } + + /** Call TaskbarModelCallbacks to update running apps. */ + public void updateRunningApps() { + mModelCallbacks.updateRunningApps(); + } + /** * Callbacks for {@link TaskbarView} to interact with its controller. */ diff --git a/quickstep/src/com/android/quickstep/RecentTasksList.java b/quickstep/src/com/android/quickstep/RecentTasksList.java index cd93dbe509..813e687f34 100644 --- a/quickstep/src/com/android/quickstep/RecentTasksList.java +++ b/quickstep/src/com/android/quickstep/RecentTasksList.java @@ -62,6 +62,10 @@ public class RecentTasksList { private TaskLoadResult mResultsBg = INVALID_RESULT; private TaskLoadResult mResultsUi = INVALID_RESULT; + private RecentsModel.RunningTasksListener mRunningTasksListener; + // Tasks are stored in order of least recently launched to most recently launched. + private ArrayList mRunningTasks; + public RecentTasksList(LooperExecutor mainThreadExecutor, KeyguardManagerCompat keyguardManager, SystemUiProxy sysUiProxy) { mMainThreadExecutor = mainThreadExecutor; @@ -73,7 +77,26 @@ public class RecentTasksList { public void onRecentTasksChanged() throws RemoteException { mMainThreadExecutor.execute(RecentTasksList.this::onRecentTasksChanged); } + + @Override + public void onRunningTaskAppeared(ActivityManager.RunningTaskInfo taskInfo) { + mMainThreadExecutor.execute(() -> { + RecentTasksList.this.onRunningTaskAppeared(taskInfo); + }); + } + + @Override + public void onRunningTaskVanished(ActivityManager.RunningTaskInfo taskInfo) { + mMainThreadExecutor.execute(() -> { + RecentTasksList.this.onRunningTaskVanished(taskInfo); + }); + } }); + // We may receive onRunningTaskAppeared events later for tasks which have already been + // included in the list returned by mSysUiProxy.getRunningTasks(), or may receive + // onRunningTaskVanished for tasks not included in the returned list. These cases will be + // addressed when the tasks are added to/removed from mRunningTasks. + initRunningTasks(mSysUiProxy.getRunningTasks(Integer.MAX_VALUE)); } @VisibleForTesting @@ -154,6 +177,59 @@ public class RecentTasksList { mChangeId++; } + /** + * Registers a listener for running tasks + */ + public void registerRunningTasksListener(RecentsModel.RunningTasksListener listener) { + mRunningTasksListener = listener; + } + + /** + * Removes the previously registered running tasks listener + */ + public void unregisterRunningTasksListener() { + mRunningTasksListener = null; + } + + private void initRunningTasks(ArrayList runningTasks) { + // Tasks are retrieved in order of most recently launched/used to least recently launched. + mRunningTasks = new ArrayList<>(runningTasks); + Collections.reverse(mRunningTasks); + } + + /** + * Gets the set of running tasks. + */ + public ArrayList getRunningTasks() { + return mRunningTasks; + } + + private void onRunningTaskAppeared(ActivityManager.RunningTaskInfo taskInfo) { + // Make sure this task is not already in the list + for (ActivityManager.RunningTaskInfo existingTask : mRunningTasks) { + if (taskInfo.taskId == existingTask.taskId) { + return; + } + } + mRunningTasks.add(taskInfo); + if (mRunningTasksListener != null) { + mRunningTasksListener.onRunningTasksChanged(); + } + } + + private void onRunningTaskVanished(ActivityManager.RunningTaskInfo taskInfo) { + // Find the task from the list of running tasks, if it exists + for (ActivityManager.RunningTaskInfo existingTask : mRunningTasks) { + if (existingTask.taskId != taskInfo.taskId) continue; + + mRunningTasks.remove(existingTask); + if (mRunningTasksListener != null) { + mRunningTasksListener.onRunningTasksChanged(); + } + return; + } + } + /** * Loads and creates a list of all the recent tasks. */ diff --git a/quickstep/src/com/android/quickstep/RecentsModel.java b/quickstep/src/com/android/quickstep/RecentsModel.java index 442578eb80..3074dbb0b2 100644 --- a/quickstep/src/com/android/quickstep/RecentsModel.java +++ b/quickstep/src/com/android/quickstep/RecentsModel.java @@ -236,4 +236,35 @@ public class RecentsModel implements IconChangeListener, TaskStackChangeListener writer.println(prefix + "RecentsModel:"); mTaskList.dump(" ", writer); } + + /** + * Registers a listener for running tasks + */ + public void registerRunningTasksListener(RunningTasksListener listener) { + mTaskList.registerRunningTasksListener(listener); + } + + /** + * Removes the previously registered running tasks listener + */ + public void unregisterRunningTasksListener() { + mTaskList.unregisterRunningTasksListener(); + } + + /** + * Gets the set of running tasks. + */ + public ArrayList getRunningTasks() { + return mTaskList.getRunningTasks(); + } + + /** + * Listener for receiving running tasks changes + */ + public interface RunningTasksListener { + /** + * Called when there's a change to running tasks + */ + void onRunningTasksChanged(); + } } diff --git a/quickstep/src/com/android/quickstep/SystemUiProxy.java b/quickstep/src/com/android/quickstep/SystemUiProxy.java index cb80b4d979..0ec7e628b5 100644 --- a/quickstep/src/com/android/quickstep/SystemUiProxy.java +++ b/quickstep/src/com/android/quickstep/SystemUiProxy.java @@ -20,12 +20,14 @@ import static android.app.ActivityManager.RECENT_IGNORE_UNAVAILABLE; import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE; import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; +import android.app.ActivityManager; import android.app.PendingIntent; import android.app.PictureInPictureParams; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.pm.ActivityInfo; +import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.graphics.Insets; import android.graphics.Rect; @@ -108,12 +110,14 @@ public class SystemUiProxy implements ISystemUiProxy, DisplayController.DisplayI private boolean mLastNavButtonAnimate; private boolean mHasNavButtonAlphaBeenSet = false; private Runnable mPendingSetNavButtonAlpha = null; + private Context mContext; // TODO(141886704): Find a way to remove this private int mLastSystemUiStateFlags; public SystemUiProxy(Context context) { DisplayController.INSTANCE.get(context).addChangeListener(this); + mContext = context; } @Override @@ -868,4 +872,20 @@ public class SystemUiProxy implements ISystemUiProxy, DisplayController.DisplayI } return new ArrayList<>(); } + + /** + * Gets the set of running tasks. + */ + public ArrayList getRunningTasks(int numTasks) { + if (mRecentTasks != null + && mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_PC)) { + try { + return new ArrayList( + Arrays.asList(mRecentTasks.getRunningTasks(numTasks))); + } catch (RemoteException e) { + Log.w(TAG, "Failed call getRunningTasks", e); + } + } + return new ArrayList<>(); + } }