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

Commit 51969ae4 authored by Louis Chang's avatar Louis Chang
Browse files

Notify ITaskStackListener#onTaskMovedToFront when root task moves

The callback was used to be called only when the leaf task
moved to front. However, it should also be called if the top
leaf task is not moved, but the parent root task is moved to
front.

Bug: 338612247
Test: TaskDisplayAreaTests
Flag: EXEMPT bugfix
Change-Id: I09463b0cefa013238e49e06c7d2b9f3a5d74189c
parent bb5e28e7
Loading
Loading
Loading
Loading
+3 −5
Original line number Original line Diff line number Diff line
@@ -1278,8 +1278,8 @@ class Task extends TaskFragment {
        EventLogTags.writeWmTaskMoved(mTaskId, getRootTaskId(), getDisplayId(), toTop ? 1 : 0,
        EventLogTags.writeWmTaskMoved(mTaskId, getRootTaskId(), getDisplayId(), toTop ? 1 : 0,
                position);
                position);
        final TaskDisplayArea taskDisplayArea = getDisplayArea();
        final TaskDisplayArea taskDisplayArea = getDisplayArea();
        if (taskDisplayArea != null && isLeafTask()) {
        if (taskDisplayArea != null) {
            taskDisplayArea.onLeafTaskMoved(this, toTop, toBottom);
            taskDisplayArea.onTaskMoved(this, toTop, toBottom);
        }
        }
        if (isPersistable) {
        if (isPersistable) {
            mLastTimeMoved = System.currentTimeMillis();
            mLastTimeMoved = System.currentTimeMillis();
@@ -6129,9 +6129,7 @@ class Task extends TaskFragment {


        if (canBeLaunchedOnDisplay(newParent.getDisplayId())) {
        if (canBeLaunchedOnDisplay(newParent.getDisplayId())) {
            reparent(newParent, onTop ? POSITION_TOP : POSITION_BOTTOM);
            reparent(newParent, onTop ? POSITION_TOP : POSITION_BOTTOM);
            if (isLeafTask()) {
            newParent.onTaskMoved(this, onTop, !onTop);
                newParent.onLeafTaskMoved(this, onTop, !onTop);
            }
        } else {
        } else {
            Slog.w(TAG, "Task=" + this + " can't reparent to " + newParent);
            Slog.w(TAG, "Task=" + this + " can't reparent to " + newParent);
        }
        }
+14 −1
Original line number Original line Diff line number Diff line
@@ -37,6 +37,7 @@ import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ROOT_TASK;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;


import android.annotation.ColorInt;
import android.annotation.ColorInt;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.app.ActivityOptions;
import android.app.ActivityOptions;
import android.app.WindowConfiguration;
import android.app.WindowConfiguration;
@@ -435,7 +436,19 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
        }
        }
    }
    }


    void onLeafTaskMoved(Task t, boolean toTop, boolean toBottom) {
    void onTaskMoved(@NonNull Task t, boolean toTop, boolean toBottom) {
        if (toBottom && !t.isLeafTask()) {
            // Return early when a non-leaf task moved to bottom, to prevent sending duplicated
            // leaf task movement callback if the leaf task is moved along with its parent tasks.
            // Unless, we also track the task id, like `mLastLeafTaskToFrontId`.
            return;
        }

        final Task topLeafTask = t.getTopLeafTask();
        onLeafTaskMoved(topLeafTask, toTop, toBottom);
    }

    void onLeafTaskMoved(@NonNull Task t, boolean toTop, boolean toBottom) {
        if (toBottom) {
        if (toBottom) {
            mAtmService.getTaskChangeNotificationController().notifyTaskMovedToBack(
            mAtmService.getTaskChangeNotificationController().notifyTaskMovedToBack(
                    t.getTaskInfo());
                    t.getTaskInfo());
+14 −0
Original line number Original line Diff line number Diff line
@@ -34,6 +34,7 @@ import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
import static android.window.DisplayAreaOrganizer.FEATURE_VENDOR_FIRST;
import static android.window.DisplayAreaOrganizer.FEATURE_VENDOR_FIRST;


import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyBoolean;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
import static com.android.server.wm.ActivityRecord.State.RESUMED;
import static com.android.server.wm.ActivityRecord.State.RESUMED;
@@ -50,6 +51,7 @@ import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verify;


@@ -839,4 +841,16 @@ public class TaskDisplayAreaTests extends WindowTestsBase {
                0 /* launchFlags */, pinnedTask /* candidateTask */);
                0 /* launchFlags */, pinnedTask /* candidateTask */);
        assertNull(actualRootTask);
        assertNull(actualRootTask);
    }
    }

    @Test
    public void testMovedRootTaskToFront() {
        final TaskDisplayArea tda = mDefaultDisplay.getDefaultTaskDisplayArea();
        final Task rootTask = createTask(tda, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD,
                true /* onTop */, true /* createActivity */, true /* twoLevelTask */);
        final Task leafTask = rootTask.getTopLeafTask();

        clearInvocations(tda);
        tda.onTaskMoved(rootTask, true /* toTop */, false /* toBottom */);
        verify(tda).onLeafTaskMoved(eq(leafTask), anyBoolean(), anyBoolean());
    }
}
}