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

Commit 0733ebd3 authored by Alex Chau's avatar Alex Chau
Browse files

Run setCurrentPage in applyLoadPlan after scroll initialized

- Also combined the 2 setCurrentPage call in applyLoadPlan into 1
- Otherwise setCurrentTask may set to page 1 unexpectedly due to page 0's scroll being invalid and out of range

Bug: 246283207
Bug: 238461210
Test: Split screen with 2 apps, click back, go to overview again, should snap to focsued task
Change-Id: I3b57655c810668fe244659437fbd4a745ca02d21
parent 82469ea2
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -90,9 +90,9 @@ public final class RecentsViewStateController extends
            // While animating into recents, update the visible task data as needed
            builder.addOnFrameCallback(() -> mRecentsView.loadVisibleTaskData(FLAG_UPDATE_ALL));
            mRecentsView.updateEmptyMessage();
            // TODO(b/238461210): Remove logging once root cause of flake detected.
            // TODO(b/246283207): Remove logging once root cause of flake detected.
            if (Utilities.IS_RUNNING_IN_TEST_HARNESS) {
                Log.d("b/238461210", "RecentsView#setStateWithAnimationInternal getCurrentPage(): "
                Log.d("b/246283207", "RecentsView#setStateWithAnimationInternal getCurrentPage(): "
                                + mRecentsView.getCurrentPage()
                                + ", getScrollForPage(getCurrentPage())): "
                                + mRecentsView.getScrollForPage(mRecentsView.getCurrentPage()));
+22 −22
Original line number Diff line number Diff line
@@ -1500,21 +1500,6 @@ public abstract class RecentsView<ACTIVITY_TYPE extends StatefulActivity<STATE_T
            addView(mClearAllButton);
        }

        boolean settlingOnNewTask = mNextPage != INVALID_PAGE;
        if (settlingOnNewTask) {
            // Restore mCurrentPage but don't call setCurrentPage() as that clobbers the scroll.
            mCurrentPage = previousCurrentPage;
        } else {
            // TODO(b/238461210): Remove logging once root cause of flake detected.
            if (Utilities.IS_RUNNING_IN_TEST_HARNESS) {
                Log.d("b/238461210", "RecentsView#applyLoadPlan() -> !settlingOnNewTask -> "
                                + "previousCurrentPage: " + previousCurrentPage
                                + ", getScrollForPage(previousCurrentPage): "
                                + getScrollForPage(previousCurrentPage));
            }
            setCurrentPage(previousCurrentPage);
        }

        // Keep same previous focused task
        TaskView newFocusedTaskView = getTaskViewByTaskId(focusedTaskId);
        // If the list changed, maybe the focused task doesn't exist anymore
@@ -1539,21 +1524,36 @@ public abstract class RecentsView<ACTIVITY_TYPE extends StatefulActivity<STATE_T
        }

        int targetPage = -1;
        if (!settlingOnNewTask) {
        if (mNextPage != INVALID_PAGE) {
            // Restore mCurrentPage but don't call setCurrentPage() as that clobbers the scroll.
            mCurrentPage = previousCurrentPage;
            if (currentTaskId != -1) {
                currentTaskView = getTaskViewByTaskId(currentTaskId);
                if (currentTaskView != null) {
                    targetPage = indexOfChild(currentTaskView);
                }
            }
        } else {
            // Set the current page to the running task, but not if settling on new task.
            if (runningTaskId != -1) {
                targetPage = indexOfChild(newRunningTaskView);
            } else if (getTaskViewCount() > 0) {
                targetPage = indexOfChild(requireTaskViewAt(0));
            }
        } else if (currentTaskId != -1) {
            currentTaskView = getTaskViewByTaskId(currentTaskId);
            if (currentTaskView != null) {
                targetPage = indexOfChild(currentTaskView);
            }
        }
        if (targetPage != -1 && mCurrentPage != targetPage) {
            setCurrentPage(targetPage);
            int finalTargetPage = targetPage;
            runOnPageScrollsInitialized(() -> {
                // TODO(b/246283207): Remove logging once root cause of flake detected.
                if (Utilities.IS_RUNNING_IN_TEST_HARNESS) {
                    Log.d("b/246283207", "RecentsView#applyLoadPlan() -> "
                            + "previousCurrentPage: " + previousCurrentPage
                            + ", targetPage: " + finalTargetPage
                            + ", getScrollForPage(targetPage): "
                            + getScrollForPage(finalTargetPage));
                }
                setCurrentPage(finalTargetPage);
            });
        }

        if (mIgnoreResetTaskId != -1 &&
+2 −2
Original line number Diff line number Diff line
@@ -772,9 +772,9 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
        }

        if (mScroller.isFinished() && pageScrollChanged) {
            // TODO(b/238461210): Remove logging once root cause of flake detected.
            // TODO(b/246283207): Remove logging once root cause of flake detected.
            if (Utilities.IS_RUNNING_IN_TEST_HARNESS && !(this instanceof Workspace)) {
                Log.d("b/238461210", this.getClass().getSimpleName() + "#onLayout() -> "
                Log.d("b/246283207", this.getClass().getSimpleName() + "#onLayout() -> "
                        + "if(mScroller.isFinished() && pageScrollChanged) -> getNextPage(): "
                        + getNextPage() + ", getScrollForPage(getNextPage()): "
                        + getScrollForPage(getNextPage()));