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

Commit 04a05ac3 authored by Wale Ogunwale's avatar Wale Ogunwale
Browse files

Ability to getOrCreateStack by windowingMode/activityType in AM.

Another step away from using static stack ids for things.

Test: Existing tests pass.
Test: go/wm-smoke
Bug: 64146578
Change-Id: Iac05046c96d10e5b26d444172341f2ecf9efe3ee
parent 6070e803
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -675,7 +675,7 @@ public class ActivityManager {


        /** First static stack ID.
        /** First static stack ID.
         * @hide */
         * @hide */
        public static final int FIRST_STATIC_STACK_ID = 0;
        private  static final int FIRST_STATIC_STACK_ID = 0;


        /** Home activity stack ID. */
        /** Home activity stack ID. */
        public static final int HOME_STACK_ID = FIRST_STATIC_STACK_ID;
        public static final int HOME_STACK_ID = FIRST_STATIC_STACK_ID;
@@ -700,7 +700,7 @@ public class ActivityManager {


        /** Last static stack stack ID.
        /** Last static stack stack ID.
         * @hide */
         * @hide */
        public static final int LAST_STATIC_STACK_ID = ASSISTANT_STACK_ID;
        private static final int LAST_STATIC_STACK_ID = ASSISTANT_STACK_ID;


        /** Start of ID range used by stacks that are created dynamically.
        /** Start of ID range used by stacks that are created dynamically.
         * @hide */
         * @hide */
+7 −2
Original line number Original line Diff line number Diff line
@@ -500,10 +500,15 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
     * @hide
     * @hide
     */
     */
    public boolean supportSplitScreenWindowingMode() {
    public boolean supportSplitScreenWindowingMode() {
        if (mActivityType == ACTIVITY_TYPE_ASSISTANT) {
        return supportSplitScreenWindowingMode(mWindowingMode, mActivityType);
    }

    /** @hide */
    public static boolean supportSplitScreenWindowingMode(int windowingMode, int activityType) {
        if (activityType == ACTIVITY_TYPE_ASSISTANT) {
            return false;
            return false;
        }
        }
        return mWindowingMode != WINDOWING_MODE_FREEFORM && mWindowingMode != WINDOWING_MODE_PINNED;
        return windowingMode != WINDOWING_MODE_FREEFORM && windowingMode != WINDOWING_MODE_PINNED;
    }
    }


    private static String windowingModeToString(@WindowingMode int windowingMode) {
    private static String windowingModeToString(@WindowingMode int windowingMode) {
+0 −6
Original line number Original line Diff line number Diff line
@@ -16,11 +16,6 @@


package com.android.systemui.recents.views;
package com.android.systemui.recents.views;


import static android.app.ActivityManager.StackId.ASSISTANT_STACK_ID;
import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS;
@@ -32,7 +27,6 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECOND
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;


import android.annotation.Nullable;
import android.annotation.Nullable;
import android.app.ActivityManager.StackId;
import android.app.ActivityOptions;
import android.app.ActivityOptions;
import android.app.ActivityOptions.OnAnimationStartedListener;
import android.app.ActivityOptions.OnAnimationStartedListener;
import android.content.Context;
import android.content.Context;
+170 −0
Original line number Original line Diff line number Diff line
@@ -16,6 +16,20 @@


package com.android.server.am;
package com.android.server.am;


import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
import static android.app.ActivityManager.StackId.getStackIdForActivityType;
import static android.app.ActivityManager.StackId.getStackIdForWindowingMode;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY;
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.FLAG_PRIVATE;
import static android.view.Display.FLAG_PRIVATE;
import static android.view.Display.REMOVE_MODE_DESTROY_CONTENT;
import static android.view.Display.REMOVE_MODE_DESTROY_CONTENT;
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STACK;
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STACK;
@@ -27,10 +41,12 @@ import static com.android.server.am.proto.ActivityDisplayProto.STACKS;
import static com.android.server.am.proto.ActivityDisplayProto.ID;
import static com.android.server.am.proto.ActivityDisplayProto.ID;


import android.app.ActivityManagerInternal;
import android.app.ActivityManagerInternal;
import android.app.WindowConfiguration;
import android.util.IntArray;
import android.util.IntArray;
import android.util.Slog;
import android.util.Slog;
import android.util.proto.ProtoOutputStream;
import android.util.proto.ProtoOutputStream;
import android.view.Display;
import android.view.Display;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.wm.ConfigurationContainer;
import com.android.server.wm.ConfigurationContainer;


import java.util.ArrayList;
import java.util.ArrayList;
@@ -129,6 +145,160 @@ class ActivityDisplay extends ConfigurationContainer {
        return null;
        return null;
    }
    }


    /**
     * @return the topmost stack on the display that is compatible with the input windowing mode and
     * activity type. {@code null} means no compatible stack on the display.
     * @see ConfigurationContainer#isCompatible(int, int)
     */
    <T extends ActivityStack> T getStack(int windowingMode, int activityType) {
        for (int i = mStacks.size() - 1; i >= 0; --i) {
            final ActivityStack stack = mStacks.get(i);
            // TODO: Should undefined windowing and activity type be compatible with standard type?
            if (stack.isCompatible(windowingMode, activityType)) {
                return (T) stack;
            }
        }
        return null;
    }

    /**
     * @see #getStack(int, int)
     * @see #createStack(int, int, boolean)
     */
    <T extends ActivityStack> T getOrCreateStack(int windowingMode, int activityType,
            boolean onTop) {
        T stack = getStack(windowingMode, activityType);
        if (stack != null) {
            return stack;
        }
        return createStack(windowingMode, activityType, onTop);
    }

    /** Creates a stack matching the input windowing mode and activity type on this display. */
    <T extends ActivityStack> T createStack(int windowingMode, int activityType, boolean onTop) {

        if (activityType != ACTIVITY_TYPE_STANDARD && activityType != ACTIVITY_TYPE_UNDEFINED) {
            // For now there can be only one stack of a particular non-standard activity type on a
            // display. So, get that ignoring whatever windowing mode it is currently in.
            T stack = getStack(WINDOWING_MODE_UNDEFINED, activityType);
            if (stack != null) {
                throw new IllegalArgumentException("Stack=" + stack + " of activityType="
                        + activityType + " already on display=" + this + ". Can't have multiple.");
            }
        }

        final ActivityManagerService service = mSupervisor.mService;
        if (!mSupervisor.isWindowingModeSupported(windowingMode, service.mSupportsMultiWindow,
                service.mSupportsSplitScreenMultiWindow, service.mSupportsFreeformWindowManagement,
                service.mSupportsPictureInPicture, activityType)) {
            throw new IllegalArgumentException("Can't create stack for unsupported windowingMode="
                    + windowingMode);
        }

        if (windowingMode == WINDOWING_MODE_UNDEFINED) {
            // TODO: Should be okay to have stacks with with undefined windowing mode long term, but
            // have to set them to something for now due to logic that depending on them.
            windowingMode = WINDOWING_MODE_FULLSCREEN;
        }

        final boolean inSplitScreenMode = hasSplitScreenStack();
        if (!inSplitScreenMode
                && windowingMode == WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY) {
            // Switch to fullscreen windowing mode if we are not in split-screen mode and we are
            // trying to launch in split-screen secondary.
            windowingMode = WINDOWING_MODE_FULLSCREEN;
        } else if (inSplitScreenMode && windowingMode == WINDOWING_MODE_FULLSCREEN
                && WindowConfiguration.supportSplitScreenWindowingMode(
                        windowingMode, activityType)) {
            windowingMode = WINDOWING_MODE_SPLIT_SCREEN_SECONDARY;
        }

        int stackId = INVALID_STACK_ID;
        if (mDisplayId == DEFAULT_DISPLAY) {
            // TODO: Will be removed once we are no longer using static stack ids.
            stackId = getStackIdForActivityType(activityType);
            if (stackId == INVALID_STACK_ID) {
                stackId = getStackIdForWindowingMode(windowingMode);
            }
            if (stackId == INVALID_STACK_ID) {
                // Whatever...put in fullscreen stack for now.
                stackId = FULLSCREEN_WORKSPACE_STACK_ID;
            }
            final T stack = getStack(stackId);
            if (stack != null) {
                return stack;
            }
        }

        if (stackId == INVALID_STACK_ID) {
            stackId = mSupervisor.getNextStackId();
        }

        final T stack = createStackUnchecked(windowingMode, activityType, stackId, onTop);

        if (mDisplayId == DEFAULT_DISPLAY && windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
            // Make sure recents stack exist when creating a dock stack as it normally need to be on
            // the other side of the docked stack and we make visibility decisions based on that.
            // TODO: Not sure if this is needed after we change to calculate visibility based on
            // stack z-order vs. id.
            getOrCreateStack(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_RECENTS, onTop);
        }

        return stack;
    }

    @VisibleForTesting
    <T extends ActivityStack> T createStackUnchecked(int windowingMode, int activityType,
            int stackId, boolean onTop) {
        switch (windowingMode) {
            case WINDOWING_MODE_PINNED:
                return (T) new PinnedActivityStack(this, stackId, mSupervisor, onTop);
            default:
                return (T) new ActivityStack(
                        this, stackId, mSupervisor, windowingMode, activityType, onTop);
        }
    }

    /** Removes all stacks in the input windowing mode from the system */
    void removeStacksInWindowingMode(int windowingMode) {
        for (int i = mStacks.size() - 1; i >= 0; --i) {
            final ActivityStack stack = mStacks.get(i);
            if (stack.getWindowingMode() == windowingMode) {
                mSupervisor.removeStackLocked(stack.mStackId);
            }
        }
    }

    /** Returns the top visible stack activity type that isn't in the exclude windowing mode. */
    int getTopVisibleStackActivityType(int excludeWindowingMode) {
        for (int i = mStacks.size() - 1; i >= 0; --i) {
            final ActivityStack stack = mStacks.get(i);
            if (stack.getWindowingMode() == excludeWindowingMode) {
                continue;
            }
            if (stack.shouldBeVisible(null /* starting */)) {
                return stack.getActivityType();
            }
        }
        return ACTIVITY_TYPE_UNDEFINED;
    }

    ActivityStack getSplitScreenStack() {
        return getStack(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_UNDEFINED);
    }

    boolean hasSplitScreenStack() {
        return getSplitScreenStack() != null;
    }

    PinnedActivityStack getPinnedStack() {
        return getStack(WINDOWING_MODE_PINNED, ACTIVITY_TYPE_UNDEFINED);
    }

    boolean hasPinnedStack() {
        return getPinnedStack() != null;
    }

    @Override
    @Override
    public String toString() {
    public String toString() {
        return "ActivityDisplay={" + mDisplayId + " numStacks=" + mStacks.size() + "}";
        return "ActivityDisplay={" + mDisplayId + " numStacks=" + mStacks.size() + "}";
+69 −43
Original line number Original line Diff line number Diff line
@@ -33,6 +33,14 @@ import static android.app.ActivityManager.StackId.FIRST_DYNAMIC_STACK_ID;
import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
import static android.app.ActivityManager.StackId.getActivityTypeForStackId;
import static android.app.ActivityManager.StackId.getWindowingModeForStackId;
import static android.app.ActivityManager.StackId.isStaticStack;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
import static android.content.pm.PackageManager.FEATURE_ACTIVITIES_ON_SECONDARY_DISPLAYS;
import static android.content.pm.PackageManager.FEATURE_ACTIVITIES_ON_SECONDARY_DISPLAYS;
import static android.content.pm.PackageManager.FEATURE_FREEFORM_WINDOW_MANAGEMENT;
import static android.content.pm.PackageManager.FEATURE_FREEFORM_WINDOW_MANAGEMENT;
import static android.content.pm.PackageManager.FEATURE_LEANBACK_ONLY;
import static android.content.pm.PackageManager.FEATURE_LEANBACK_ONLY;
@@ -164,7 +172,6 @@ import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_URI_PERMI
import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_VISIBILITY;
import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_VISIBILITY;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.am.ActivityStackSupervisor.CREATE_IF_NEEDED;
import static com.android.server.am.ActivityStackSupervisor.DEFER_RESUME;
import static com.android.server.am.ActivityStackSupervisor.DEFER_RESUME;
import static com.android.server.am.ActivityStackSupervisor.MATCH_TASK_IN_STACKS_ONLY;
import static com.android.server.am.ActivityStackSupervisor.MATCH_TASK_IN_STACKS_ONLY;
import static com.android.server.am.ActivityStackSupervisor.MATCH_TASK_IN_STACKS_OR_RECENT_TASKS;
import static com.android.server.am.ActivityStackSupervisor.MATCH_TASK_IN_STACKS_OR_RECENT_TASKS;
@@ -177,7 +184,6 @@ import static com.android.server.am.TaskRecord.REPARENT_KEEP_STACK_AT_FRONT;
import static com.android.server.am.TaskRecord.REPARENT_LEAVE_STACK_IN_PLACE;
import static com.android.server.am.TaskRecord.REPARENT_LEAVE_STACK_IN_PLACE;
import static com.android.server.am.proto.ActivityManagerServiceProto.ACTIVITIES;
import static com.android.server.am.proto.ActivityManagerServiceProto.ACTIVITIES;
import static com.android.server.wm.AppTransition.TRANSIT_ACTIVITY_OPEN;
import static com.android.server.wm.AppTransition.TRANSIT_ACTIVITY_OPEN;
import static com.android.server.wm.AppTransition.TRANSIT_ACTIVITY_RELAUNCH;
import static com.android.server.wm.AppTransition.TRANSIT_NONE;
import static com.android.server.wm.AppTransition.TRANSIT_NONE;
import static com.android.server.wm.AppTransition.TRANSIT_TASK_IN_PLACE;
import static com.android.server.wm.AppTransition.TRANSIT_TASK_IN_PLACE;
import static com.android.server.wm.AppTransition.TRANSIT_TASK_OPEN;
import static com.android.server.wm.AppTransition.TRANSIT_TASK_OPEN;
@@ -2372,11 +2378,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                    if (disableNonVrUi) {
                    if (disableNonVrUi) {
                        // If we are in a VR mode where Picture-in-Picture mode is unsupported,
                        // If we are in a VR mode where Picture-in-Picture mode is unsupported,
                        // then remove the pinned stack.
                        // then remove the pinned stack.
                        final PinnedActivityStack pinnedStack = mStackSupervisor.getStack(
                        mStackSupervisor.removeStacksInWindowingMode(WINDOWING_MODE_PINNED);
                                PINNED_STACK_ID);
                        if (pinnedStack != null) {
                            mStackSupervisor.removeStackLocked(PINNED_STACK_ID);
                        }
                    }
                    }
                }
                }
            } break;
            } break;
@@ -8105,7 +8107,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                    final Rect sourceBounds = new Rect(r.pictureInPictureArgs.getSourceRectHint());
                    final Rect sourceBounds = new Rect(r.pictureInPictureArgs.getSourceRectHint());
                    mStackSupervisor.moveActivityToPinnedStackLocked(r, sourceBounds, aspectRatio,
                    mStackSupervisor.moveActivityToPinnedStackLocked(r, sourceBounds, aspectRatio,
                            true /* moveHomeStackToFront */, "enterPictureInPictureMode");
                            true /* moveHomeStackToFront */, "enterPictureInPictureMode");
                    final PinnedActivityStack stack = mStackSupervisor.getStack(PINNED_STACK_ID);
                    final PinnedActivityStack stack = r.getStack();
                    stack.setPictureInPictureAspectRatio(aspectRatio);
                    stack.setPictureInPictureAspectRatio(aspectRatio);
                    stack.setPictureInPictureActions(actions);
                    stack.setPictureInPictureActions(actions);
@@ -9862,7 +9864,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        if (tr.mBounds != null) {
        if (tr.mBounds != null) {
            rti.bounds = new Rect(tr.mBounds);
            rti.bounds = new Rect(tr.mBounds);
        }
        }
        rti.supportsSplitScreenMultiWindow = tr.supportsSplitScreen();
        rti.supportsSplitScreenMultiWindow = tr.supportsSplitScreenWindowingMode();
        rti.resizeMode = tr.mResizeMode;
        rti.resizeMode = tr.mResizeMode;
        ActivityRecord base = null;
        ActivityRecord base = null;
@@ -10181,21 +10183,23 @@ public class ActivityManagerService extends IActivityManager.Stub
                // - a non-null bounds on a non-freeform (fullscreen OR docked) task moves
                // - a non-null bounds on a non-freeform (fullscreen OR docked) task moves
                //   that task to freeform
                //   that task to freeform
                // - otherwise the task is not moved
                // - otherwise the task is not moved
                int stackId = task.getStackId();
                ActivityStack stack = task.getStack();
                if (!task.getWindowConfiguration().canResizeTask()) {
                if (!task.getWindowConfiguration().canResizeTask()) {
                    throw new IllegalArgumentException("resizeTask not allowed on task=" + task);
                    throw new IllegalArgumentException("resizeTask not allowed on task=" + task);
                }
                }
                if (bounds == null && stackId == FREEFORM_WORKSPACE_STACK_ID) {
                if (bounds == null && stack.getWindowingMode() == WINDOWING_MODE_FREEFORM) {
                    stackId = FULLSCREEN_WORKSPACE_STACK_ID;
                    stack = stack.getDisplay().getOrCreateStack(
                } else if (bounds != null && stackId != FREEFORM_WORKSPACE_STACK_ID ) {
                            WINDOWING_MODE_FULLSCREEN, stack.getActivityType(), ON_TOP);
                    stackId = FREEFORM_WORKSPACE_STACK_ID;
                } else if (bounds != null && stack.getWindowingMode() != WINDOWING_MODE_FREEFORM) {
                    stack = stack.getDisplay().getOrCreateStack(
                            WINDOWING_MODE_FREEFORM, stack.getActivityType(), ON_TOP);
                }
                }
                // Reparent the task to the right stack if necessary
                // Reparent the task to the right stack if necessary
                boolean preserveWindow = (resizeMode & RESIZE_MODE_PRESERVE_WINDOW) != 0;
                boolean preserveWindow = (resizeMode & RESIZE_MODE_PRESERVE_WINDOW) != 0;
                if (stackId != task.getStackId()) {
                if (stack != task.getStack()) {
                    // Defer resume until the task is resized below
                    // Defer resume until the task is resized below
                    task.reparent(stackId, ON_TOP, REPARENT_KEEP_STACK_AT_FRONT, ANIMATE,
                    task.reparent(stack, ON_TOP, REPARENT_KEEP_STACK_AT_FRONT, ANIMATE,
                            DEFER_RESUME, "resizeTask");
                            DEFER_RESUME, "resizeTask");
                    preserveWindow = false;
                    preserveWindow = false;
                }
                }
@@ -10525,13 +10529,15 @@ public class ActivityManagerService extends IActivityManager.Stub
    public int createStackOnDisplay(int displayId) throws RemoteException {
    public int createStackOnDisplay(int displayId) throws RemoteException {
        enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "createStackOnDisplay()");
        enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "createStackOnDisplay()");
        synchronized (this) {
        synchronized (this) {
            final int stackId = mStackSupervisor.getNextStackId();
            final ActivityDisplay display =
            final ActivityStack stack =
                    mStackSupervisor.getActivityDisplayOrCreateLocked(displayId);
                    mStackSupervisor.createStackOnDisplay(stackId, displayId, true /*onTop*/);
            if (display == null) {
            if (stack == null) {
                return INVALID_STACK_ID;
                return INVALID_STACK_ID;
            }
            }
            return stack.mStackId;
            // TODO(multi-display): Have the caller pass in the windowing mode and activity type.
            final ActivityStack stack = display.createStack(
                    WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /*onTop*/);
            return (stack != null) ? stack.mStackId : INVALID_STACK_ID;
        }
        }
    }
    }
@@ -10563,8 +10569,12 @@ public class ActivityManagerService extends IActivityManager.Stub
                            "exitFreeformMode: You can only go fullscreen from freeform.");
                            "exitFreeformMode: You can only go fullscreen from freeform.");
                }
                }
                final ActivityStack fullscreenStack = stack.getDisplay().getOrCreateStack(
                        WINDOWING_MODE_FULLSCREEN, stack.getActivityType(), ON_TOP);
                if (DEBUG_STACK) Slog.d(TAG_STACK, "exitFreeformMode: " + r);
                if (DEBUG_STACK) Slog.d(TAG_STACK, "exitFreeformMode: " + r);
                r.getTask().reparent(FULLSCREEN_WORKSPACE_STACK_ID, ON_TOP,
                // TODO: Should just change windowing mode vs. re-parenting...
                r.getTask().reparent(fullscreenStack, ON_TOP,
                        REPARENT_KEEP_STACK_AT_FRONT, ANIMATE, !DEFER_RESUME, "exitFreeformMode");
                        REPARENT_KEEP_STACK_AT_FRONT, ANIMATE, !DEFER_RESUME, "exitFreeformMode");
            } finally {
            } finally {
                Binder.restoreCallingIdentity(ident);
                Binder.restoreCallingIdentity(ident);
@@ -10594,8 +10604,20 @@ public class ActivityManagerService extends IActivityManager.Stub
                    mWindowManager.setDockedStackCreateState(DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT,
                    mWindowManager.setDockedStackCreateState(DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT,
                            null /* initialBounds */);
                            null /* initialBounds */);
                }
                }
                task.reparent(stackId, toTop,
                        REPARENT_KEEP_STACK_AT_FRONT, ANIMATE, !DEFER_RESUME, "moveTaskToStack");
                ActivityStack stack = mStackSupervisor.getStack(stackId);
                if (stack == null) {
                    if (!isStaticStack(stackId)) {
                        throw new IllegalStateException(
                                "moveTaskToStack: No stack for stackId=" + stackId);
                    }
                    stack = mStackSupervisor.getDefaultDisplay().createStack(
                            getWindowingModeForStackId(stackId,
                                    mStackSupervisor.getDefaultDisplay().hasSplitScreenStack()),
                            getActivityTypeForStackId(stackId), toTop);
                }
                task.reparent(stack, toTop, REPARENT_KEEP_STACK_AT_FRONT, ANIMATE, !DEFER_RESUME,
                        "moveTaskToStack");
            } finally {
            } finally {
                Binder.restoreCallingIdentity(ident);
                Binder.restoreCallingIdentity(ident);
            }
            }
@@ -10628,13 +10650,18 @@ public class ActivityManagerService extends IActivityManager.Stub
                    Slog.w(TAG, "moveTaskToDockedStack: No task for id=" + taskId);
                    Slog.w(TAG, "moveTaskToDockedStack: No task for id=" + taskId);
                    return false;
                    return false;
                }
                }
                if (DEBUG_STACK) Slog.d(TAG_STACK, "moveTaskToDockedStack: moving task=" + taskId
                if (DEBUG_STACK) Slog.d(TAG_STACK, "moveTaskToDockedStack: moving task=" + taskId
                        + " to createMode=" + createMode + " toTop=" + toTop);
                        + " to createMode=" + createMode + " toTop=" + toTop);
                mWindowManager.setDockedStackCreateState(createMode, initialBounds);
                mWindowManager.setDockedStackCreateState(createMode, initialBounds);
                final ActivityDisplay display = task.getStack().getDisplay();
                final ActivityStack stack = display.getOrCreateStack(
                        WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, task.getStack().getActivityType(),
                        toTop);
                // Defer resuming until we move the home stack to the front below
                // Defer resuming until we move the home stack to the front below
                final boolean moved = task.reparent(DOCKED_STACK_ID, toTop,
                // TODO: Should just change windowing mode vs. re-parenting...
                final boolean moved = task.reparent(stack, toTop,
                        REPARENT_KEEP_STACK_AT_FRONT, animate, !DEFER_RESUME,
                        REPARENT_KEEP_STACK_AT_FRONT, animate, !DEFER_RESUME,
                        "moveTaskToDockedStack");
                        "moveTaskToDockedStack");
                if (moved) {
                if (moved) {
@@ -10682,17 +10709,16 @@ public class ActivityManagerService extends IActivityManager.Stub
        try {
        try {
            synchronized (this) {
            synchronized (this) {
                if (animate) {
                if (animate) {
                    if (stackId == PINNED_STACK_ID) {
                    final PinnedActivityStack stack = mStackSupervisor.getStack(stackId);
                        final PinnedActivityStack pinnedStack =
                    if (stack == null) {
                                mStackSupervisor.getStack(PINNED_STACK_ID);
                        return;
                        if (pinnedStack != null) {
                            pinnedStack.animateResizePinnedStack(null /* sourceHintBounds */,
                                    destBounds, animationDuration, false /* fromFullscreen */);
                    }
                    }
                    } else {
                    if (stack.getWindowingMode() != WINDOWING_MODE_PINNED) {
                        throw new IllegalArgumentException("Stack: " + stackId
                        throw new IllegalArgumentException("Stack: " + stackId
                                + " doesn't support animated resize.");
                                + " doesn't support animated resize.");
                    }
                    }
                    stack.animateResizePinnedStack(null /* sourceHintBounds */, destBounds,
                            animationDuration, false /* fromFullscreen */);
                } else {
                } else {
                    mStackSupervisor.resizeStackLocked(stackId, destBounds, null /* tempTaskBounds */,
                    mStackSupervisor.resizeStackLocked(stackId, destBounds, null /* tempTaskBounds */,
                            null /* tempTaskInsetBounds */, preserveWindows,
                            null /* tempTaskInsetBounds */, preserveWindows,
@@ -10760,8 +10786,12 @@ public class ActivityManagerService extends IActivityManager.Stub
                            + taskId);
                            + taskId);
                }
                }
                final ActivityStack stack = mStackSupervisor.getStack(stackId, CREATE_IF_NEEDED,
                final ActivityStack stack = mStackSupervisor.getStack(stackId);
                        !ON_TOP);
                if (stack == null) {
                    throw new IllegalArgumentException("positionTaskInStack: no stack for id="
                            + stackId);
                }
                // TODO: Have the callers of this API call a separate reparent method if that is
                // TODO: Have the callers of this API call a separate reparent method if that is
                // what they intended to do vs. having this method also do reparenting.
                // what they intended to do vs. having this method also do reparenting.
@@ -10770,8 +10800,8 @@ public class ActivityManagerService extends IActivityManager.Stub
                    stack.positionChildAt(task, position);
                    stack.positionChildAt(task, position);
                } else {
                } else {
                    // Reparent to new stack.
                    // Reparent to new stack.
                    task.reparent(stackId, position, REPARENT_LEAVE_STACK_IN_PLACE,
                    task.reparent(stack, position, REPARENT_LEAVE_STACK_IN_PLACE, !ANIMATE,
                            !ANIMATE, !DEFER_RESUME, "positionTaskInStack");
                            !DEFER_RESUME, "positionTaskInStack");
                }
                }
            } finally {
            } finally {
                Binder.restoreCallingIdentity(ident);
                Binder.restoreCallingIdentity(ident);
@@ -10849,11 +10879,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
        }
        // When a task is locked, dismiss the pinned stack if it exists
        // When a task is locked, dismiss the pinned stack if it exists
        final PinnedActivityStack pinnedStack = mStackSupervisor.getStack(
        mStackSupervisor.removeStacksInWindowingMode(WINDOWING_MODE_PINNED);
                PINNED_STACK_ID);
        if (pinnedStack != null) {
            mStackSupervisor.removeStackLocked(PINNED_STACK_ID);
        }
        // isAppPinning is used to distinguish between locked and pinned mode, as pinned mode
        // isAppPinning is used to distinguish between locked and pinned mode, as pinned mode
        // is initiated by system after the pinning request was shown and locked mode is initiated
        // is initiated by system after the pinning request was shown and locked mode is initiated
Loading