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

Commit 8f93b64d authored by Wale Ogunwale's avatar Wale Ogunwale Committed by Louis Chang
Browse files

Unify ActivityStack extend Task (84/n)

Step towards merging stacks into tasks.

Test: Existing tests pass.
Bug: 80414790
Change-Id: Ifb167129c89a3aba11796daa21a9dee7200913ca
parent aa8974f8
Loading
Loading
Loading
Loading
+9 −15
Original line number Diff line number Diff line
@@ -745,7 +745,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            synchronized (mAtmService.mGlobalLock) {
                Slog.w(TAG, "Activity stop timeout for " + ActivityRecord.this);
                if (isInHistory()) {
                    activityStopped(null /*icicle*/, null /*persistentState*/, null /*description*/);
                    activityStopped(
                            null /*icicle*/, null /*persistentState*/, null /*description*/);
                }
            }
        }
@@ -1286,17 +1287,11 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A

        updateColorTransform();

        final ActivityStack oldStack = (oldTask != null) ? oldTask.getStack() : null;
        final ActivityStack newStack = (newTask != null) ? newTask.getStack() : null;
        // Inform old stack (if present) of activity removal and new stack (if set) of activity
        // addition.
        if (oldStack != newStack) {
            if (oldStack !=  null) {
                oldStack.onActivityRemovedFromStack(this);
            }
            if (newStack !=  null) {
                newStack.onActivityAddedToStack(this);
        if (oldTask != null) {
            oldTask.cleanUpActivityReferences(this);
        }
        if (newTask != null && isState(RESUMED)) {
            newTask.setResumedActivity(this, "onParentChanged");
        }
    }

@@ -2904,8 +2899,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
     * Note: Call before {@link #removeFromHistory(String)}.
     */
    void cleanUp(boolean cleanServices, boolean setState) {
        final ActivityStack stack = getActivityStack();
        stack.onActivityRemovedFromStack(this);
        task.cleanUpActivityReferences(this);

        deferRelaunchUntilPaused = false;
        frozenBeforeDestroy = false;
@@ -5832,7 +5826,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
    @Override
    boolean isWaitingForTransitionStart() {
        final DisplayContent dc = getDisplayContent();
        return dc.mAppTransition.isTransitionSet()
        return dc != null && dc.mAppTransition.isTransitionSet()
                && (dc.mOpeningApps.contains(this)
                || dc.mClosingApps.contains(this)
                || dc.mChangingApps.contains(this));
+149 −497

File changed.

Preview size limit exceeded, changes collapsed.

+5 −5
Original line number Diff line number Diff line
@@ -419,7 +419,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {

            final PooledConsumer c = PooledLambda.obtainConsumer(
                    MoveTaskToFullscreenHelper::processTask, this, PooledLambda.__(Task.class));
            fromStack.forAllTasks(c, false);
            fromStack.forAllTasks(c, false /* traverseTopToBottom */, fromStack);
            c.recycle();
            mToDisplay = null;
            mTopTask = null;
@@ -1724,7 +1724,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
        } else {
            final PooledConsumer c = PooledLambda.obtainConsumer(
                    ActivityStackSupervisor::processRemoveTask, this, PooledLambda.__(Task.class));
            stack.forAllTasks(c);
            stack.forAllTasks(c, true /* traverseTopToBottom */, stack);
            c.recycle();
        }
    }
@@ -1849,14 +1849,14 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
    boolean restoreRecentTaskLocked(Task task, ActivityOptions aOptions, boolean onTop) {
        final ActivityStack stack =
                mRootWindowContainer.getLaunchStack(null, aOptions, task, onTop);
        final ActivityStack currentStack = task.getStack();
        final WindowContainer parent = task.getParent();

        if (currentStack == stack) {
        if (parent == stack) {
            // Nothing else to do since it is already restored in the right stack.
            return true;
        }

        if (currentStack != null) {
        if (parent != null) {
            // Task has already been restored once. Just re-parent it to the new stack.
            task.reparent(stack, POSITION_TOP, true /*moveParents*/, "restoreRecentTaskLocked");
            return true;
+6 −6
Original line number Diff line number Diff line
@@ -306,7 +306,7 @@ import java.util.Set;
 */
public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
    private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityTaskManagerService" : TAG_ATM;
    private static final String TAG_STACK = TAG + POSTFIX_STACK;
    static final String TAG_STACK = TAG + POSTFIX_STACK;
    static final String TAG_SWITCH = TAG + POSTFIX_SWITCH;
    private static final String TAG_IMMERSIVE = TAG + POSTFIX_IMMERSIVE;
    private static final String TAG_FOCUS = TAG + POSTFIX_FOCUS;
@@ -2057,8 +2057,9 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
    public int getDisplayId(IBinder activityToken) throws RemoteException {
        synchronized (mGlobalLock) {
            final ActivityStack stack = ActivityRecord.getStackLocked(activityToken);
            if (stack != null && stack.getDisplayId() != INVALID_DISPLAY) {
                return stack.getDisplayId();
            if (stack != null) {
                final int displayId = stack.getDisplayId();
                return displayId != INVALID_DISPLAY ? displayId : DEFAULT_DISPLAY;
            }
            return DEFAULT_DISPLAY;
        }
@@ -3216,8 +3217,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {

                final ActivityStack stack = r.getActivityStack();
                final Task task = stack.createTask(
                        mStackSupervisor.getNextTaskIdForUser(r.mUserId), ainfo, intent,
                        null /* voiceSession */, null /* voiceInteractor */, !ON_TOP);
                        mStackSupervisor.getNextTaskIdForUser(r.mUserId), ainfo, intent, !ON_TOP);
                if (!mRecentTasks.addToBottom(task)) {
                    // The app has too many tasks already and we can't add any more
                    stack.removeChild(task, "addAppTask");
@@ -4385,7 +4385,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {

        if (params.hasSetAspectRatio()
                && !mWindowManager.isValidPictureInPictureAspectRatio(
                        r.getDisplayId(), params.getAspectRatio())) {
                        r.getDisplay(), params.getAspectRatio())) {
            final float minAspectRatio = mContext.getResources().getFloat(
                    com.android.internal.R.dimen.config_pictureInPictureMinAspectRatio);
            final float maxAspectRatio = mContext.getResources().getFloat(
+48 −24
Original line number Diff line number Diff line
@@ -168,8 +168,10 @@ import android.app.ActivityManagerInternal;
import android.app.ActivityOptions;
import android.app.WindowConfiguration;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ActivityInfo.ScreenOrientation;
import android.content.pm.ApplicationInfo;
import android.content.res.CompatibilityInfo;
import android.content.res.Configuration;
import android.graphics.Bitmap;
@@ -4241,7 +4243,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        ArrayList<Task> getVisibleTasks() {
            final ArrayList<Task> visibleTasks = new ArrayList<>();
            forAllTasks(task -> {
                if (task.isVisible()) {
                if (!task.isRootTask() && task.isVisible()) {
                    visibleTasks.add(task);
                }
            });
@@ -4260,38 +4262,50 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        private void addStackReferenceIfNeeded(ActivityStack stack) {
            if (stack.isActivityTypeHome()) {
                if (mHomeStack != null) {
                    if (!stack.isDescendantOf(mHomeStack)) {
                        throw new IllegalArgumentException("addStackReferenceIfNeeded: home stack="
                            + mHomeStack + " already exist on display=" + this + " stack=" + stack);

                                + mHomeStack + " already exist on display=" + this
                                + " stack=" + stack);
                    }
                } else {
                    mHomeStack = stack;
                }
            } else if (stack.isActivityTypeRecents()) {
                if (mRecentsStack != null && mRecentsStack != stack) {
                    if (!stack.isDescendantOf(mRecentsStack)) {
                        throw new IllegalArgumentException(
                                "addStackReferenceIfNeeded: recents stack=" + mRecentsStack
                                        + " already exist on display=" + this + " stack=" + stack);
                    }
                } else {
                    mRecentsStack = stack;
                }
            }
            final int windowingMode = stack.getWindowingMode();
            if (windowingMode == WINDOWING_MODE_PINNED) {
                if (mPinnedStack != null) {
                    throw new IllegalArgumentException("addStackReferenceIfNeeded: pinned stack="
                            + mPinnedStack + " already exist on display=" + this
                            + " stack=" + stack);
                    if (!stack.isDescendantOf(mPinnedStack)) {
                        throw new IllegalArgumentException(
                                "addStackReferenceIfNeeded: pinned stack=" + mPinnedStack
                                        + " already exist on display=" + this + " stack=" + stack);
                    }
                } else {
                    mPinnedStack = stack;
                }
            } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
                if (mSplitScreenPrimaryStack != null) {
                    if (!stack.isDescendantOf(mSplitScreenPrimaryStack)) {
                        throw new IllegalArgumentException("addStackReferenceIfNeeded:"
                                + " split-screen-primary" + " stack=" + mSplitScreenPrimaryStack
                                + " already exist on display=" + this + " stack=" + stack);
                    }
                } else {
                    mSplitScreenPrimaryStack = stack;
                    mDisplayContent.onSplitScreenModeActivated();
                    mDividerControllerLocked.notifyDockedStackExistsChanged(true);
                }
            }
        }

        void removeStackReferenceIfNeeded(ActivityStack stack) {
            if (stack == mHomeStack) {
@@ -5738,6 +5752,10 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        return mAtmService.mStackSupervisor.getNextTaskIdForUser();
    }

    ActivityStack createStack(int windowingMode, int activityType, boolean onTop) {
        return createStack(windowingMode, activityType, onTop, null /*info*/, null /*intent*/);
    }

    /**
     * Creates a stack matching the input windowing mode and activity type on this display.
     * @param windowingMode The windowing mode the stack should be created in. If
@@ -5749,13 +5767,14 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
     * @param onTop If true the stack will be created at the top of the display, else at the bottom.
     * @return The newly created stack.
     */
    ActivityStack createStack(int windowingMode, int activityType, boolean onTop) {
    ActivityStack createStack(int windowingMode, int activityType, boolean onTop, ActivityInfo info,
            Intent intent) {
        if (mSingleTaskInstance && getStackCount() > 0) {
            // Create stack on default display instead since this display can only contain 1 stack.
            // TODO: Kinda a hack, but better that having the decision at each call point. Hoping
            // this goes away once ActivityView is no longer using virtual displays.
            return mRootWindowContainer.getDefaultDisplay().createStack(
                    windowingMode, activityType, onTop);
                    windowingMode, activityType, onTop, info, intent);
        }

        if (activityType == ACTIVITY_TYPE_UNDEFINED) {
@@ -5783,18 +5802,23 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        }

        final int stackId = getNextStackId();
        return createStackUnchecked(windowingMode, activityType, stackId, onTop);
        return createStackUnchecked(windowingMode, activityType, stackId, onTop, info, intent);
    }

    @VisibleForTesting
    ActivityStack createStackUnchecked(int windowingMode, int activityType,
            int stackId, boolean onTop) {
            int stackId, boolean onTop, ActivityInfo info, Intent intent) {
        if (windowingMode == WINDOWING_MODE_PINNED && activityType != ACTIVITY_TYPE_STANDARD) {
            throw new IllegalArgumentException("Stack with windowing mode cannot with non standard "
                    + "activity type.");
        }
        if (info == null) {
            info = new ActivityInfo();
            info.applicationInfo = new ApplicationInfo();
        }

        final ActivityStack stack = new ActivityStack(this, stackId,
                mRootWindowContainer.mStackSupervisor, activityType);
                mRootWindowContainer.mStackSupervisor, activityType, info, intent);
        addStack(stack, onTop ? POSITION_TOP : POSITION_BOTTOM);
        stack.setWindowingMode(windowingMode, false /* animate */, false /* showRecents */,
                false /* enteringSplitScreenMode */, false /* deferEnsuringVisibility */,
Loading