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

Commit 3bf23372 authored by Calvin Huang's avatar Calvin Huang
Browse files

Skip moving home to front when starting task from recents in multi-window mode

In multi-window mode, home should not move to front when starts task
from resents since it might covers other tasks.

Bug: 400759425
Test: atest com.android.server.wm.ActivityTaskSupervisorTests
Flag: EXEMPT bug fix
Change-Id: If408b0faadf82d2294ed82b560446f0cdab78579
parent ddcbebad
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -55,9 +55,7 @@ import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Icon;
import android.hardware.HardwareBuffer;
import android.os.BatteryStats;
import android.os.Binder;
import android.os.Build;
@@ -86,7 +84,6 @@ import android.util.Log;
import android.util.Singleton;
import android.util.Size;
import android.view.WindowInsetsController.Appearance;
import android.window.TaskSnapshot;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.app.LocalePicker;
@@ -3102,7 +3099,8 @@ public class ActivityManager {
    /**
     * Flag for {@link #moveTaskToFront(int, int)}: also move the "home"
     * activity along with the task, so it is positioned immediately behind
     * the task.
     * the task. This flag is ignored if the task's windowing mode is
     * {@link WindowConfiguration#WINDOWING_MODE_MULTI_WINDOW}.
     */
    public static final int MOVE_TASK_WITH_HOME = 0x00000001;

+14 −3
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
import static android.content.Intent.ACTION_VIEW;
@@ -1627,16 +1628,19 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
        }
    }

    private void moveHomeRootTaskToFrontIfNeeded(int flags, TaskDisplayArea taskDisplayArea,
    @VisibleForTesting
    void moveHomeRootTaskToFrontIfNeeded(int flags, TaskDisplayArea taskDisplayArea,
            String reason) {
        final Task focusedRootTask = taskDisplayArea.getFocusedRootTask();

        if ((taskDisplayArea.getWindowingMode() == WINDOWING_MODE_FULLSCREEN
                && (flags & ActivityManager.MOVE_TASK_WITH_HOME) != 0)
                || (focusedRootTask != null && focusedRootTask.isActivityTypeRecents())) {
                || (focusedRootTask != null && focusedRootTask.isActivityTypeRecents()
                && focusedRootTask.getWindowingMode() != WINDOWING_MODE_MULTI_WINDOW)) {
            // We move root home task to front when we are on a fullscreen display area and
            // caller has requested the home activity to move with it. Or the previous root task
            // is recents.
            // is recents and we are not on multi-window mode.

            taskDisplayArea.moveHomeRootTaskToFront(reason);
        }
    }
@@ -2823,6 +2827,13 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
                            "startActivityFromRecents: Task " + taskId + " not found.");
                }


                if (task.getRootTask() != null
                        && task.getRootTask().getWindowingMode() == WINDOWING_MODE_MULTI_WINDOW) {
                    // Don't move home forward if task is in multi window mode
                    moveHomeTaskForward = false;
                }

                if (moveHomeTaskForward) {
                    // We always want to return to the home activity instead of the recents
                    // activity from whatever is started from the recents activity, so move
+58 −4
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.app.ActivityManager.START_DELIVERED_TO_TOP;
import static android.app.ActivityManager.START_TASK_TO_FRONT;
import static android.app.ITaskStackListener.FORCED_RESIZEABLE_REASON_SECONDARY_DISPLAY;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;

import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer;
@@ -82,6 +83,8 @@ import java.util.concurrent.TimeUnit;
@RunWith(WindowTestRunner.class)
public class ActivityTaskSupervisorTests extends WindowTestsBase {
    private static final long TIMEOUT_MS = TimeUnit.SECONDS.toMillis(10);
    private static final int DEFAULT_CALLING_PID = -1;
    private static final int DEFAULT_CALLING_UID = -1;

    /**
     * Ensures that an activity is removed from the stopping activities list once it is resumed.
@@ -408,7 +411,8 @@ public class ActivityTaskSupervisorTests extends WindowTestsBase {
        doNothing().when(mSupervisor.mService).moveTaskToFrontLocked(eq(null), eq(null), anyInt(),
                anyInt(), any());

        mSupervisor.startActivityFromRecents(-1, -1, activity.getRootTaskId(), safeOptions);
        mSupervisor.startActivityFromRecents(DEFAULT_CALLING_PID, DEFAULT_CALLING_UID,
                activity.getRootTaskId(), safeOptions);

        assertThat(activity.mLaunchCookie).isEqualTo(launchCookie);
        verify(mAtm).moveTaskToFrontLocked(any(), eq(null), anyInt(), anyInt(), eq(safeOptions));
@@ -426,12 +430,62 @@ public class ActivityTaskSupervisorTests extends WindowTestsBase {
        doNothing().when(mSupervisor.mService).moveTaskToFrontLocked(eq(null), eq(null), anyInt(),
                anyInt(), any());

        mSupervisor.startActivityFromRecents(-1, -1, activity.getRootTaskId(), safeOptions);
        mSupervisor.startActivityFromRecents(DEFAULT_CALLING_PID, DEFAULT_CALLING_UID,
                activity.getRootTaskId(), safeOptions);

        assertThat(activity.mLaunchCookie).isNull();
        verify(mAtm).moveTaskToFrontLocked(any(), eq(null), anyInt(), anyInt(), eq(safeOptions));
    }

    /** Verifies that launch from recents doesn't set the launch cookie on the activity. */
    @Test
    public void testStartActivityFromRecents_inMultiWindowRootTask_homeNotMoved() {
        final Task multiWindowRootTask = new TaskBuilder(mSupervisor).setWindowingMode(
                WINDOWING_MODE_MULTI_WINDOW).setOnTop(true).build();

        final ActivityRecord activity = new ActivityBuilder(mAtm).setParentTask(
                multiWindowRootTask).setCreateTask(true).build();

        SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(
                ActivityOptions.makeBasic().toBundle(),
                Binder.getCallingPid(), Binder.getCallingUid());

        doNothing().when(mSupervisor.mService).moveTaskToFrontLocked(eq(null), eq(null), anyInt(),
                anyInt(), any());

        mSupervisor.startActivityFromRecents(DEFAULT_CALLING_PID, DEFAULT_CALLING_UID,
                activity.getRootTaskId(), safeOptions);

        verify(mAtm).moveTaskToFrontLocked(any(), eq(null), anyInt(), anyInt(), eq(safeOptions));
        verify(mRootWindowContainer.getDefaultTaskDisplayArea(), never()).moveHomeRootTaskToFront(
                any());
        verify(multiWindowRootTask.getDisplayArea(), never()).moveHomeRootTaskToFront(any());
    }

    /** Verifies that launch from recents doesn't set the launch cookie on the activity. */
    @Test
    public void testStartActivityFromRecents_inFullScreenRootTask_homeMovedToFront() {
        final Task fullscreenRootTask = new TaskBuilder(mSupervisor).setWindowingMode(
                WINDOWING_MODE_FULLSCREEN).setOnTop(true).build();

        final ActivityRecord activity = new ActivityBuilder(mAtm).setParentTask(
                fullscreenRootTask).setCreateTask(true).build();

        SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(
                ActivityOptions.makeBasic().toBundle(),
                Binder.getCallingPid(), Binder.getCallingUid());

        doNothing().when(mSupervisor.mService).moveTaskToFrontLocked(eq(null), eq(null), anyInt(),
                anyInt(), any());

        mSupervisor.startActivityFromRecents(DEFAULT_CALLING_PID, DEFAULT_CALLING_UID,
                activity.getRootTaskId(), safeOptions);

        verify(mAtm).moveTaskToFrontLocked(any(), eq(null), anyInt(), anyInt(), eq(safeOptions));
        verify(mRootWindowContainer.getDefaultTaskDisplayArea()).moveHomeRootTaskToFront(any());
        verify(fullscreenRootTask.getDisplayArea()).moveHomeRootTaskToFront(any());
    }

    @Test
    public void testOpaque_leafTask_occludingActivity_isOpaque() {
        final ActivityRecord activity = new ActivityBuilder(mAtm).setCreateTask(true).build();