Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2daa3eba authored by Alex Chau's avatar Alex Chau Committed by Android (Google) Code Review
Browse files

Merge "Refactor TaskView.getTaskIds and its attribute container to support any...

Merge "Refactor TaskView.getTaskIds and its attribute container to support any number of tasks" into main
parents 19f8002e 15e2c773
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import com.android.quickstep.views.TaskView;
import com.android.systemui.shared.recents.model.Task;

import java.util.ArrayList;
import java.util.Arrays;

public class FallbackRecentsView extends RecentsView<RecentsActivity, RecentsState>
        implements StateListener<RecentsState> {
@@ -144,8 +145,9 @@ public class FallbackRecentsView extends RecentsView<RecentsActivity, RecentsSta
    @Override
    public void setCurrentTask(int runningTaskViewId) {
        super.setCurrentTask(runningTaskViewId);
        int runningTaskId = getTaskIdsForRunningTaskView()[0];
        if (mHomeTask != null && mHomeTask.key.id != runningTaskId) {
        int[] runningTaskIds = getTaskIdsForRunningTaskView();
        if (mHomeTask != null
                && Arrays.stream(runningTaskIds).noneMatch(taskId -> taskId == mHomeTask.key.id)) {
            mHomeTask = null;
            setRunningTaskHidden(false);
        }
@@ -182,13 +184,14 @@ public class FallbackRecentsView extends RecentsView<RecentsActivity, RecentsSta
        // as well. This tile is never shown as we have setCurrentTaskHidden, but allows use to
        // track the index of the next task appropriately, as if we are switching on any other app.
        // TODO(b/195607777) Confirm home task info is front-most task and not mixed in with others
        int runningTaskId = getTaskIdsForRunningTaskView()[0];
        if (mHomeTask != null && mHomeTask.key.id == runningTaskId
        int[] runningTaskIds = getTaskIdsForRunningTaskView();
        if (mHomeTask != null
                && Arrays.stream(runningTaskIds).allMatch(taskId -> taskId == mHomeTask.key.id)
                && !taskGroups.isEmpty()) {
            // Check if the task list has running task
            boolean found = false;
            for (GroupTask group : taskGroups) {
                if (group.containsTask(runningTaskId)) {
                if (Arrays.stream(runningTaskIds).allMatch(group::containsTask)) {
                    found = true;
                    break;
                }
+2 −12
Original line number Diff line number Diff line
@@ -204,18 +204,14 @@ public class DesktopTaskView extends TaskView {
    }

    private void updateTaskIdContainer() {
        // TODO(b/249371338): TaskView expects the array to have at least 2 elements.
        // At least 2 elements in the array
        mTaskIdContainer = new int[Math.max(mTasks.size(), 2)];
        mTaskIdContainer = new int[mTasks.size()];
        for (int i = 0; i < mTasks.size(); i++) {
            mTaskIdContainer[i] = mTasks.get(i).key.id;
        }
    }

    private void updateTaskIdAttributeContainer() {
        // TODO(b/249371338): TaskView expects the array to have at least 2 elements.
        // At least 2 elements in the array
        mTaskIdAttributeContainer = new TaskIdAttributeContainer[Math.max(mTasks.size(), 2)];
        mTaskIdAttributeContainer = new TaskIdAttributeContainer[mTasks.size()];
        for (int i = 0; i < mTasks.size(); i++) {
            Task task = mTasks.get(i);
            TaskThumbnailViewDeprecated thumbnailView = mSnapshotViewMap.get(task.key.id);
@@ -247,12 +243,6 @@ public class DesktopTaskView extends TaskView {
        return mTaskThumbnailViewDeprecated;
    }

    @Override
    public boolean containsTaskId(int taskId) {
        // Thumbnail map contains taskId -> thumbnail map. Use the keys for contains
        return mSnapshotViewMap.contains(taskId);
    }

    @Override
    public void onTaskListVisibilityChanged(boolean visible, int changes) {
        cancelPendingLoadTasks();
+30 −17
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ import static com.android.launcher3.Flags.enableOverviewIconMenu;
import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_POSITION_BOTTOM_OR_RIGHT;
import static com.android.quickstep.util.SplitScreenUtils.convertLauncherSplitBoundsToShell;

import android.app.ActivityTaskManager;
import android.content.Context;
import android.graphics.Point;
import android.graphics.PointF;
@@ -46,6 +47,7 @@ import kotlin.Unit;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Optional;
import java.util.function.Consumer;

/**
@@ -129,9 +131,11 @@ public class GroupedTaskView extends TaskView {
            @Nullable SplitBounds splitBoundsConfig) {
        super.bind(primary, orientedState);
        mSecondaryTask = secondary;
        mTaskIdContainer[1] = secondary.key.id;
        mTaskIdAttributeContainer[1] = new TaskIdAttributeContainer(secondary, mSnapshotView2,
                mIconView2, STAGE_POSITION_BOTTOM_OR_RIGHT);
        mTaskIdContainer = new int[]{mTaskIdContainer[0], secondary.key.id};
        mTaskIdAttributeContainer = new TaskIdAttributeContainer[]{
                mTaskIdAttributeContainer[0],
                new TaskIdAttributeContainer(secondary, mSnapshotView2,
                        mIconView2, STAGE_POSITION_BOTTOM_OR_RIGHT)};
        mTaskIdAttributeContainer[0].setStagePosition(
                SplitConfigurationOptions.STAGE_POSITION_TOP_OR_LEFT);
        mSnapshotView2.bind(secondary);
@@ -154,6 +158,9 @@ public class GroupedTaskView extends TaskView {
    public void setUpShowAllInstancesListener() {
        // sets up the listener for the left/top task
        super.setUpShowAllInstancesListener();
        if (mTaskIdAttributeContainer.length < 2) {
            return;
        }

        // right/bottom task's base package name
        String taskPackageName = mTaskIdAttributeContainer[1].getTask().key.getPackageName();
@@ -307,17 +314,21 @@ public class GroupedTaskView extends TaskView {
        mSnapshotView2.refresh();
    }

    @Override
    public boolean containsTaskId(int taskId) {
        return (mTask != null && mTask.key.id == taskId)
                || (mSecondaryTask != null && mSecondaryTask.key.id == taskId);
    }

    @Override
    public TaskThumbnailViewDeprecated[] getThumbnails() {
        return new TaskThumbnailViewDeprecated[]{mTaskThumbnailViewDeprecated, mSnapshotView2};
    }

    /**
     * Returns taskId that split selection was initiated with,
     * {@link ActivityTaskManager#INVALID_TASK_ID} if no tasks in this TaskView are part of
     * split selection
     */
    protected int getThisTaskCurrentlyInSplitSelection() {
        int initialTaskId = getRecentsView().getSplitSelectController().getInitialTaskId();
        return containsTaskId(initialTaskId) ? initialTaskId : INVALID_TASK_ID;
    }

    @Override
    protected int getLastSelectedChildTaskIndex() {
        SplitSelectStateController splitSelectController =
@@ -382,13 +393,15 @@ public class GroupedTaskView extends TaskView {
        } else {
            // Currently being split with this taskView, let the non-split selected thumbnail
            // take up full thumbnail area
            TaskIdAttributeContainer container =
                    mTaskIdAttributeContainer[initSplitTaskId == mTask.key.id ? 1 : 0];
            container.getThumbnailView().measure(widthMeasureSpec,
                    View.MeasureSpec.makeMeasureSpec(
                            heightSize -
                                    mContainer.getDeviceProfile().overviewTaskThumbnailTopMarginPx,
                            MeasureSpec.EXACTLY));
            Optional<TaskIdAttributeContainer> nonSplitContainer = Arrays.stream(
                    mTaskIdAttributeContainer).filter(
                            container -> container.getTask().key.id != initSplitTaskId).findAny();
            nonSplitContainer.ifPresent(
                    taskIdAttributeContainer -> taskIdAttributeContainer.getThumbnailView().measure(
                            widthMeasureSpec, MeasureSpec.makeMeasureSpec(
                                    heightSize - mContainer.getDeviceProfile()
                                            .overviewTaskThumbnailTopMarginPx,
                                    MeasureSpec.EXACTLY)));
        }
        if (!enableOverviewIconMenu()) {
            updateIconPlacement();
@@ -529,7 +542,7 @@ public class GroupedTaskView extends TaskView {
            mDigitalWellBeingToast.setBannerVisibility(visibility);
            mSnapshotView2.setVisibility(visibility);
            mDigitalWellBeingToast2.setBannerVisibility(visibility);
        } else if (taskId == getTaskIds()[0]) {
        } else if (mTaskIdContainer.length > 0 && mTaskIdContainer[0] == taskId) {
            mTaskThumbnailViewDeprecated.setVisibility(visibility);
            mDigitalWellBeingToast.setBannerVisibility(visibility);
        } else {
+43 −45
Original line number Diff line number Diff line
@@ -626,7 +626,6 @@ public abstract class RecentsView<CONTAINER_TYPE extends Context & RecentsViewCo
     */
    protected int mRunningTaskViewId = -1;
    private int mTaskViewIdCount;
    private final int[] INVALID_TASK_IDS = new int[]{-1, -1};
    protected boolean mRunningTaskTileHidden;
    @Nullable
    private Task[] mTmpRunningTasks;
@@ -1413,7 +1412,7 @@ public abstract class RecentsView<CONTAINER_TYPE extends Context & RecentsViewCo
     */
    @Nullable
    public TaskView getTaskViewByTaskIds(int[] taskIds) {
        if (!hasAnyValidTaskIds(taskIds)) {
        if (!hasAllValidTaskIds(taskIds)) {
            return null;
        }

@@ -1432,9 +1431,11 @@ public abstract class RecentsView<CONTAINER_TYPE extends Context & RecentsViewCo
        return null;
    }

    /** Returns false if {@code taskIds} is null or contains invalid values, true otherwise */
    private boolean hasAnyValidTaskIds(int[] taskIds) {
        return taskIds != null && !Arrays.equals(taskIds, INVALID_TASK_IDS);
    /** Returns false if {@code taskIds} is null or contains any invalid values, true otherwise */
    private boolean hasAllValidTaskIds(int[] taskIds) {
        return taskIds != null
                && taskIds.length > 0
                && Arrays.stream(taskIds).noneMatch(taskId -> taskId == INVALID_TASK_ID);
    }

    public void setOverviewStateEnabled(boolean enabled) {
@@ -1720,10 +1721,12 @@ public abstract class RecentsView<CONTAINER_TYPE extends Context & RecentsViewCo
            return;
        }

        int[] currentTaskId = INVALID_TASK_IDS;
        int[] currentTaskIds;
        TaskView currentTaskView = getTaskViewAt(mCurrentPage);
        if (currentTaskView != null && currentTaskView.getTask() != null) {
            currentTaskId = currentTaskView.getTaskIds();
            currentTaskIds = currentTaskView.getTaskIds();
        } else {
            currentTaskIds = new int[0];
        }

        // Unload existing visible task data
@@ -1735,8 +1738,8 @@ public abstract class RecentsView<CONTAINER_TYPE extends Context & RecentsViewCo

        // Save running task ID if it exists before rebinding all taskViews, otherwise the task from
        // the runningTaskView currently bound could get assigned to another TaskView
        int[] runningTaskId = getTaskIdsForTaskViewId(mRunningTaskViewId);
        int[] focusedTaskId = getTaskIdsForTaskViewId(mFocusedTaskViewId);
        int[] runningTaskIds = getTaskIdsForTaskViewId(mRunningTaskViewId);
        int[] focusedTaskIds = getTaskIdsForTaskViewId(mFocusedTaskViewId);

        // Reset the focused task to avoiding initializing TaskViews layout as focused task during
        // binding. The focused task view will be updated after all the TaskViews are bound.
@@ -1819,7 +1822,7 @@ public abstract class RecentsView<CONTAINER_TYPE extends Context & RecentsViewCo
        }

        // Keep same previous focused task
        TaskView newFocusedTaskView = getTaskViewByTaskIds(focusedTaskId);
        TaskView newFocusedTaskView = getTaskViewByTaskIds(focusedTaskIds);
        // If the list changed, maybe the focused task doesn't exist anymore
        if (newFocusedTaskView == null && getTaskViewCount() > 0) {
            newFocusedTaskView = getTaskViewAt(0);
@@ -1830,10 +1833,10 @@ public abstract class RecentsView<CONTAINER_TYPE extends Context & RecentsViewCo
        updateChildTaskOrientations();

        TaskView newRunningTaskView = null;
        if (hasAnyValidTaskIds(runningTaskId)) {
        if (hasAllValidTaskIds(runningTaskIds)) {
            // Update mRunningTaskViewId to be the new TaskView that was assigned by binding
            // the full list of tasks to taskViews
            newRunningTaskView = getTaskViewByTaskIds(runningTaskId);
            newRunningTaskView = getTaskViewByTaskIds(runningTaskIds);
            if (newRunningTaskView != null) {
                setRunningTaskViewId(newRunningTaskView.getTaskViewId());
            } else {
@@ -1853,8 +1856,8 @@ public abstract class RecentsView<CONTAINER_TYPE extends Context & RecentsViewCo
        if (mNextPage != INVALID_PAGE) {
            // Restore mCurrentPage but don't call setCurrentPage() as that clobbers the scroll.
            mCurrentPage = previousCurrentPage;
            if (hasAnyValidTaskIds(currentTaskId)) {
                currentTaskView = getTaskViewByTaskIds(currentTaskId);
            if (hasAllValidTaskIds(currentTaskIds)) {
                currentTaskView = getTaskViewByTaskIds(currentTaskIds);
                if (currentTaskView != null) {
                    targetPage = indexOfChild(currentTaskView);
                }
@@ -1863,7 +1866,7 @@ public abstract class RecentsView<CONTAINER_TYPE extends Context & RecentsViewCo
            targetPage = previousFocusedPage;
        } else {
            // Set the current page to the running task, but not if settling on new task.
            if (hasAnyValidTaskIds(runningTaskId)) {
            if (hasAllValidTaskIds(runningTaskIds)) {
                targetPage = indexOfChild(newRunningTaskView);
            } else if (getTaskViewCount() > 0) {
                targetPage = indexOfChild(requireTaskViewAt(0));
@@ -1963,7 +1966,8 @@ public abstract class RecentsView<CONTAINER_TYPE extends Context & RecentsViewCo
    public void resetTaskVisuals() {
        for (int i = getTaskViewCount() - 1; i >= 0; i--) {
            TaskView taskView = requireTaskViewAt(i);
            if (mIgnoreResetTaskId != taskView.getTaskIds()[0]) {
            if (Arrays.stream(taskView.getTaskIds()).noneMatch(
                    taskId -> taskId == mIgnoreResetTaskId)) {
                taskView.resetViewTransforms();
                taskView.setIconScaleAndDim(mTaskIconScaledDown ? 0 : 1);
                taskView.setStableAlpha(mContentAlpha);
@@ -2343,7 +2347,7 @@ public abstract class RecentsView<CONTAINER_TYPE extends Context & RecentsViewCo
        for (int i = 0; i < getTaskViewCount(); i++) {
            TaskView taskView = requireTaskViewAt(i);
            TaskIdAttributeContainer[] containers = taskView.getTaskIdAttributeContainers();
            if (containers[0] == null && containers[1] == null) {
            if (containers.length == 0) {
                continue;
            }
            int index = indexOfChild(taskView);
@@ -2498,7 +2502,7 @@ public abstract class RecentsView<CONTAINER_TYPE extends Context & RecentsViewCo
        // For now 2 distinct task IDs is max for split screen
        TaskView runningTaskView = getTaskViewFromTaskViewId(taskViewId);
        if (runningTaskView == null) {
            return INVALID_TASK_IDS;
            return new int[0];
        }

        return runningTaskView.getTaskIds();
@@ -2736,22 +2740,19 @@ public abstract class RecentsView<CONTAINER_TYPE extends Context & RecentsViewCo
     * Returns true if we should add a stub taskView for the running task id
     */
    protected boolean shouldAddStubTaskView(Task[] runningTasks) {
        TaskView taskView = getTaskViewByTaskId(runningTasks[0].key.id);
        if (taskView == null) {
            // No TaskView found, add a stub task.
            return true;
        int[] runningTaskIds = Arrays.stream(runningTasks).mapToInt(task -> task.key.id).toArray();
        TaskView matchingTaskView = null;
        if (hasDesktopTask(runningTasks) && runningTaskIds.length == 1) {
            // TODO(b/249371338): Unsure if it's expected, desktop runningTasks only have a single
            // taskId, therefore we match any DesktopTaskView that contains the runningTaskId.
            TaskView taskview = getTaskViewByTaskId(runningTaskIds[0]);
            if (taskview instanceof DesktopTaskView) {
                matchingTaskView = taskview;
            }

        if (runningTasks.length > 1) {
            // Ensure all taskIds matches the TaskView, otherwise add a stub task.
            return Arrays.stream(runningTasks).anyMatch(
                    runningTask -> !taskView.containsTaskId(runningTask.key.id));
        } else {
            // Ensure the TaskView only contains a single taskId, or is a DesktopTask,
            // otherwise add a stub task.
            // TODO(b/249371338): Figure out why DesktopTask only have a single runningTask.
            return taskView.containsMultipleTasks() && !taskView.isDesktopTask();
            matchingTaskView = getTaskViewByTaskIds(runningTaskIds);
        }
        return matchingTaskView == null;
    }

    /**
@@ -4273,13 +4274,10 @@ public abstract class RecentsView<CONTAINER_TYPE extends Context & RecentsViewCo
        alpha = Utilities.boundToRange(alpha, 0, 1);
        mContentAlpha = alpha;

        int runningTaskId = getTaskIdsForRunningTaskView()[0];
        TaskView runningTaskView = getRunningTaskView();
        for (int i = getTaskViewCount() - 1; i >= 0; i--) {
            TaskView child = requireTaskViewAt(i);
            int[] childTaskIds = child.getTaskIds();
            if (runningTaskId != INVALID_TASK_ID
                    && mRunningTaskTileHidden
                    && (childTaskIds[0] == runningTaskId || childTaskIds[1] == runningTaskId)) {
            if (runningTaskView != null && mRunningTaskTileHidden && child == runningTaskView) {
                continue;
            }
            child.setStableAlpha(alpha);
@@ -4753,7 +4751,7 @@ public abstract class RecentsView<CONTAINER_TYPE extends Context & RecentsViewCo

        // Prevent dismissing whole task if we're only initiating from one of 2 tasks in split pair
        mSplitSelectStateController.setDismissingFromSplitPair(mSplitHiddenTaskView != null
                && mSplitHiddenTaskView.containsMultipleTasks());
                && mSplitHiddenTaskView instanceof GroupedTaskView);
        mSplitSelectStateController.setInitialTaskSelect(splitSelectSource.intent,
                splitSelectSource.position.stagePosition, splitSelectSource.itemInfo,
                splitSelectSource.splitEvent, splitSelectSource.alreadyRunningTaskId);
@@ -4774,14 +4772,14 @@ public abstract class RecentsView<CONTAINER_TYPE extends Context & RecentsViewCo
                mSplitSelectStateController.isAnimateCurrentTaskDismissal();
        boolean isInitiatingTaskViewSplitPair =
                mSplitSelectStateController.isDismissingFromSplitPair();
        if (isInitiatingSplitFromTaskView && isInitiatingTaskViewSplitPair) {
        if (isInitiatingSplitFromTaskView && isInitiatingTaskViewSplitPair
                && mSplitHiddenTaskView instanceof GroupedTaskView) {
            // Splitting from Overview for split pair task
            createInitialSplitSelectAnimation(builder);

            // Animate pair thumbnail into full thumbnail
            boolean primaryTaskSelected =
                    mSplitHiddenTaskView.getTaskIdAttributeContainers()[0].getTask().key.id ==
                            mSplitSelectStateController.getInitialTaskId();
            boolean primaryTaskSelected = mSplitHiddenTaskView.getTaskIds()[0]
                    == mSplitSelectStateController.getInitialTaskId();
            TaskIdAttributeContainer taskIdAttributeContainer = mSplitHiddenTaskView
                    .getTaskIdAttributeContainers()[primaryTaskSelected ? 1 : 0];
            TaskThumbnailViewDeprecated thumbnail = taskIdAttributeContainer.getThumbnailView();
@@ -5232,7 +5230,8 @@ public abstract class RecentsView<CONTAINER_TYPE extends Context & RecentsViewCo
        mPendingAnimation.addOnFrameCallback(this::redrawLiveTile);
        mPendingAnimation.addEndListener(isSuccess -> {
            if (isSuccess) {
                if (tv.getTaskIds()[1] != -1 && mRemoteTargetHandles != null) {
                if (tv instanceof GroupedTaskView && hasAllValidTaskIds(tv.getTaskIds())
                        && mRemoteTargetHandles != null) {
                    // TODO(b/194414938): make this part of the animations instead.
                    TaskViewUtils.createSplitAuxiliarySurfacesAnimator(
                            mRemoteTargetHandles[0].getTransformParams().getTargetSet().nonApps,
@@ -5879,8 +5878,7 @@ public abstract class RecentsView<CONTAINER_TYPE extends Context & RecentsViewCo
        }

        taskView.setShowScreenshot(true);
        for (TaskIdAttributeContainer container :
                taskView.getTaskIdAttributeContainers()) {
        for (TaskIdAttributeContainer container : taskView.getTaskIdAttributeContainers()) {
            if (container == null) {
                continue;
            }
+44 −56

File changed.

Preview size limit exceeded, changes collapsed.