Merge "Add null-check to findLastActiveTaskAndRunCallback" into udc-dev am: bfa0fae851

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/23590296

Change-Id: Ie46aaae7828fad968ef00bac8d3069da651b0f91
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Schneider Victor-tulias
2023-06-07 17:35:14 +00:00
committed by Automerger Merge Worker
5 changed files with 19 additions and 19 deletions
@@ -98,7 +98,6 @@ import com.android.launcher3.testing.shared.TestProtocol;
import com.android.launcher3.touch.ItemClickHandler; import com.android.launcher3.touch.ItemClickHandler;
import com.android.launcher3.touch.ItemClickHandler.ItemClickProxy; import com.android.launcher3.touch.ItemClickHandler.ItemClickProxy;
import com.android.launcher3.util.ActivityOptionsWrapper; import com.android.launcher3.util.ActivityOptionsWrapper;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.DisplayController; import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.Executors; import com.android.launcher3.util.Executors;
import com.android.launcher3.util.NavigationMode; import com.android.launcher3.util.NavigationMode;
@@ -939,9 +938,8 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
if (recents == null) { if (recents == null) {
return; return;
} }
ComponentKey componentToBeLaunched = new ComponentKey(info.getTargetComponent(), info.user);
recents.getSplitSelectController().findLastActiveTaskAndRunCallback( recents.getSplitSelectController().findLastActiveTaskAndRunCallback(
componentToBeLaunched, info.getComponentKey(),
foundTask -> { foundTask -> {
if (foundTask != null) { if (foundTask != null) {
TaskView foundTaskView = TaskView foundTaskView =
@@ -34,7 +34,6 @@ import com.android.launcher3.Utilities;
import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.ItemInfoWithIcon; import com.android.launcher3.model.data.ItemInfoWithIcon;
import com.android.launcher3.popup.SystemShortcut; import com.android.launcher3.popup.SystemShortcut;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.DisplayController; import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.SplitConfigurationOptions; import com.android.launcher3.util.SplitConfigurationOptions;
import com.android.quickstep.util.GroupTask; import com.android.quickstep.util.GroupTask;
@@ -205,11 +204,8 @@ public class TaskbarUIController {
return; return;
} }
ComponentKey componentToBeStaged = new ComponentKey(
splitSelectSource.itemInfo.getTargetComponent(),
splitSelectSource.itemInfo.user);
recentsView.getSplitSelectController().findLastActiveTaskAndRunCallback( recentsView.getSplitSelectController().findLastActiveTaskAndRunCallback(
componentToBeStaged, splitSelectSource.itemInfo.getComponentKey(),
foundTask -> { foundTask -> {
splitSelectSource.alreadyRunningTaskId = foundTask == null splitSelectSource.alreadyRunningTaskId = foundTask == null
? INVALID_TASK_ID ? INVALID_TASK_ID
@@ -225,9 +221,8 @@ public class TaskbarUIController {
*/ */
public void triggerSecondAppForSplit(ItemInfoWithIcon info, Intent intent, View startingView) { public void triggerSecondAppForSplit(ItemInfoWithIcon info, Intent intent, View startingView) {
RecentsView recents = getRecentsView(); RecentsView recents = getRecentsView();
ComponentKey secondAppComponent = new ComponentKey(info.getTargetComponent(), info.user);
recents.getSplitSelectController().findLastActiveTaskAndRunCallback( recents.getSplitSelectController().findLastActiveTaskAndRunCallback(
secondAppComponent, info.getComponentKey(),
foundTask -> { foundTask -> {
if (foundTask != null) { if (foundTask != null) {
TaskView foundTaskView = recents.getTaskViewByTaskId(foundTask.key.id); TaskView foundTaskView = recents.getTaskViewByTaskId(foundTask.key.id);
@@ -142,7 +142,6 @@ import com.android.launcher3.uioverrides.touchcontrollers.TaskViewTouchControlle
import com.android.launcher3.uioverrides.touchcontrollers.TransposedQuickSwitchTouchController; import com.android.launcher3.uioverrides.touchcontrollers.TransposedQuickSwitchTouchController;
import com.android.launcher3.uioverrides.touchcontrollers.TwoButtonNavbarTouchController; import com.android.launcher3.uioverrides.touchcontrollers.TwoButtonNavbarTouchController;
import com.android.launcher3.util.ActivityOptionsWrapper; import com.android.launcher3.util.ActivityOptionsWrapper;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.DisplayController; import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.Executors; import com.android.launcher3.util.Executors;
import com.android.launcher3.util.IntSet; import com.android.launcher3.util.IntSet;
@@ -601,13 +600,10 @@ public class QuickstepLauncher extends Launcher {
@Override @Override
public void startSplitSelection(SplitSelectSource splitSelectSource) { public void startSplitSelection(SplitSelectSource splitSelectSource) {
RecentsView recentsView = getOverviewPanel(); RecentsView recentsView = getOverviewPanel();
ComponentKey componentToBeStaged = new ComponentKey(
splitSelectSource.itemInfo.getTargetComponent(),
splitSelectSource.itemInfo.user);
// Check if there is already an instance of this app running, if so, initiate the split // Check if there is already an instance of this app running, if so, initiate the split
// using that. // using that.
mSplitSelectStateController.findLastActiveTaskAndRunCallback( mSplitSelectStateController.findLastActiveTaskAndRunCallback(
componentToBeStaged, splitSelectSource.itemInfo.getComponentKey(),
foundTask -> { foundTask -> {
splitSelectSource.alreadyRunningTaskId = foundTask == null splitSelectSource.alreadyRunningTaskId = foundTask == null
? INVALID_TASK_ID ? INVALID_TASK_ID
@@ -202,13 +202,17 @@ public class SplitSelectStateController {
* Pulls the list of active Tasks from RecentsModel, and finds the most recently active Task * Pulls the list of active Tasks from RecentsModel, and finds the most recently active Task
* matching a given ComponentName. Then uses that Task (which could be null) with the given * matching a given ComponentName. Then uses that Task (which could be null) with the given
* callback. * callback.
* * <p>
* Used in various task-switching or splitscreen operations when we need to check if there is a * Used in various task-switching or splitscreen operations when we need to check if there is a
* currently running Task of a certain type and use the most recent one. * currently running Task of a certain type and use the most recent one.
*/ */
public void findLastActiveTaskAndRunCallback(ComponentKey componentKey, public void findLastActiveTaskAndRunCallback(
Consumer<Task> callback) { @Nullable ComponentKey componentKey, Consumer<Task> callback) {
mRecentTasksModel.getTasks(taskGroups -> { mRecentTasksModel.getTasks(taskGroups -> {
if (componentKey == null) {
callback.accept(null);
return;
}
Task lastActiveTask = null; Task lastActiveTask = null;
// Loop through tasks in reverse, since they are ordered with most-recent tasks last. // Loop through tasks in reverse, since they are ordered with most-recent tasks last.
for (int i = taskGroups.size() - 1; i >= 0; i--) { for (int i = taskGroups.size() - 1; i >= 0; i--) {
@@ -233,7 +237,7 @@ public class SplitSelectStateController {
* Checks if a given Task is the most recently-active Task of type componentName. Used for * Checks if a given Task is the most recently-active Task of type componentName. Used for
* selecting already-running Tasks for splitscreen. * selecting already-running Tasks for splitscreen.
*/ */
public boolean isInstanceOfComponent(@Nullable Task task, ComponentKey componentKey) { public boolean isInstanceOfComponent(@Nullable Task task, @NonNull ComponentKey componentKey) {
// Exclude the task that is already staged // Exclude the task that is already staged
if (task == null || task.key.id == mInitialTaskId) { if (task == null || task.key.id == mInitialTaskId) {
return false; return false;
@@ -62,6 +62,7 @@ import com.android.launcher3.logger.LauncherAtom.TaskSwitcherContainer;
import com.android.launcher3.logger.LauncherAtom.WallpapersContainer; import com.android.launcher3.logger.LauncherAtom.WallpapersContainer;
import com.android.launcher3.logger.LauncherAtomExtensions.ExtendedContainers; import com.android.launcher3.logger.LauncherAtomExtensions.ExtendedContainers;
import com.android.launcher3.model.ModelWriter; import com.android.launcher3.model.ModelWriter;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.ContentWriter; import com.android.launcher3.util.ContentWriter;
import com.android.launcher3.util.SettingsCache; import com.android.launcher3.util.SettingsCache;
@@ -211,6 +212,12 @@ public class ItemInfo {
return Optional.ofNullable(getIntent()).map(Intent::getComponent).orElse(mComponentName); return Optional.ofNullable(getIntent()).map(Intent::getComponent).orElse(mComponentName);
} }
@Nullable
public final ComponentKey getComponentKey() {
ComponentName targetComponent = getTargetComponent();
return targetComponent == null ? null : new ComponentKey(targetComponent, user);
}
/** /**
* Returns this item's package name. * Returns this item's package name.
* *