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

Commit f540a2e2 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Fixed Task#getVisibility to take into account task hierarchy" into rvc-dev am: 872afaea

Change-Id: I2fe4a98074d6de52657530fc6112c169e25a8791
parents b850ad1f 872afaea
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -2791,7 +2791,9 @@ public class ActivityManager {
        @UnsupportedAppUsage
        @UnsupportedAppUsage
        public boolean visible;
        public boolean visible;
        // Index of the stack in the display's stack list, can be used for comparison of stack order
        // Index of the stack in the display's stack list, can be used for comparison of stack order
        // TODO: Can be removed since no one is using it.
        @UnsupportedAppUsage
        @UnsupportedAppUsage
        @Deprecated
        public int position;
        public int position;
        public WindowContainerToken stackToken;
        public WindowContainerToken stackToken;
        /**
        /**
+2 −2
Original line number Original line Diff line number Diff line
@@ -2183,7 +2183,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A


    boolean isInStackLocked() {
    boolean isInStackLocked() {
        final ActivityStack stack = getRootTask();
        final ActivityStack stack = getRootTask();
        return stack != null && stack.isInStackLocked(this) != null;
        return stack != null && stack.isInTask(this) != null;
    }
    }


    boolean isPersistable() {
    boolean isPersistable() {
@@ -5588,7 +5588,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A


    static ActivityRecord isInStackLocked(IBinder token) {
    static ActivityRecord isInStackLocked(IBinder token) {
        final ActivityRecord r = ActivityRecord.forTokenLocked(token);
        final ActivityRecord r = ActivityRecord.forTokenLocked(token);
        return (r != null) ? r.getRootTask().isInStackLocked(r) : null;
        return (r != null) ? r.getRootTask().isInTask(r) : null;
    }
    }


    static ActivityStack getStackLocked(IBinder token) {
    static ActivityStack getStackLocked(IBinder token) {
+1 −214
Original line number Original line Diff line number Diff line
@@ -259,11 +259,9 @@ class ActivityStack extends Task {
    private Rect mTmpRect = new Rect();
    private Rect mTmpRect = new Rect();
    private Rect mTmpRect2 = new Rect();
    private Rect mTmpRect2 = new Rect();


    /** For Pinned stack controlling. */
    private Rect mTmpToBounds = new Rect();

    /** Detach this stack from its display when animation completes. */
    /** Detach this stack from its display when animation completes. */
    // TODO: maybe tie this to WindowContainer#removeChild some how...
    // TODO: maybe tie this to WindowContainer#removeChild some how...
    // TODO: This is no longer set. Okay to remove or was the set removed by accident?
    private boolean mDeferRemoval;
    private boolean mDeferRemoval;


    // If this is true, we are in the bounds animating mode. The task will be down or upscaled to
    // If this is true, we are in the bounds animating mode. The task will be down or upscaled to
@@ -281,7 +279,6 @@ class ActivityStack extends Task {
    /**
    /**
     * For {@link #prepareSurfaces}.
     * For {@link #prepareSurfaces}.
     */
     */
    private final Rect mTmpDimBoundsRect = new Rect();
    private final Point mLastSurfaceSize = new Point();
    private final Point mLastSurfaceSize = new Point();


    private final AnimatingActivityRegistry mAnimatingActivityRegistry =
    private final AnimatingActivityRegistry mAnimatingActivityRegistry =
@@ -290,9 +287,6 @@ class ActivityStack extends Task {
    /** Stores the override windowing-mode from before a transient mode change (eg. split) */
    /** Stores the override windowing-mode from before a transient mode change (eg. split) */
    private int mRestoreOverrideWindowingMode = WINDOWING_MODE_UNDEFINED;
    private int mRestoreOverrideWindowingMode = WINDOWING_MODE_UNDEFINED;


    /** List for processing through a set of activities */
    private final ArrayList<ActivityRecord> mTmpActivities = new ArrayList<>();

    private boolean mTopActivityOccludesKeyguard;
    private boolean mTopActivityOccludesKeyguard;
    private ActivityRecord mTopDismissingKeyguardActivity;
    private ActivityRecord mTopDismissingKeyguardActivity;


@@ -605,9 +599,6 @@ class ActivityStack extends Task {
        final int prevWindowingMode = getWindowingMode();
        final int prevWindowingMode = getWindowingMode();
        final boolean prevIsAlwaysOnTop = isAlwaysOnTop();
        final boolean prevIsAlwaysOnTop = isAlwaysOnTop();
        final int prevRotation = getWindowConfiguration().getRotation();
        final int prevRotation = getWindowConfiguration().getRotation();
        final int prevDensity = getConfiguration().densityDpi;
        final int prevScreenW = getConfiguration().screenWidthDp;
        final int prevScreenH = getConfiguration().screenHeightDp;
        final Rect newBounds = mTmpRect;
        final Rect newBounds = mTmpRect;
        // Initialize the new bounds by previous bounds as the input and output for calculating
        // Initialize the new bounds by previous bounds as the input and output for calculating
        // override bounds in pinned (pip) or split-screen mode.
        // override bounds in pinned (pip) or split-screen mode.
@@ -920,70 +911,6 @@ class ActivityStack extends Task {
        return false;
        return false;
    }
    }


    ActivityRecord topRunningActivity() {
        return topRunningActivity(false /* focusableOnly */);
    }

    ActivityRecord topRunningActivity(boolean focusableOnly) {
        // Split into 2 to avoid object creation due to variable capture.
        if (focusableOnly) {
            return getActivity((r) -> r.canBeTopRunning() && r.isFocusable());
        } else {
            return getActivity(ActivityRecord::canBeTopRunning);
        }
    }

    private ActivityRecord topRunningNonOverlayTaskActivity() {
        return getActivity((r) -> (r.canBeTopRunning() && !r.isTaskOverlay()));
    }

    ActivityRecord topRunningNonDelayedActivityLocked(ActivityRecord notTop) {
        final PooledPredicate p = PooledLambda.obtainPredicate(ActivityStack::isTopRunningNonDelayed
                , PooledLambda.__(ActivityRecord.class), notTop);
        final ActivityRecord r = getActivity(p);
        p.recycle();
        return r;
    }

    private static boolean isTopRunningNonDelayed(ActivityRecord r, ActivityRecord notTop) {
        return !r.delayedResume && r != notTop && r.canBeTopRunning();
    }

    /**
     * This is a simplified version of topRunningActivity that provides a number of
     * optional skip-over modes.  It is intended for use with the ActivityController hook only.
     *
     * @param token If non-null, any history records matching this token will be skipped.
     * @param taskId If non-zero, we'll attempt to skip over records with the same task ID.
     *
     * @return Returns the HistoryRecord of the next activity on the stack.
     */
    ActivityRecord topRunningActivity(IBinder token, int taskId) {
        final PooledPredicate p = PooledLambda.obtainPredicate(ActivityStack::isTopRunning,
                PooledLambda.__(ActivityRecord.class), taskId, token);
        final ActivityRecord r = getActivity(p);
        p.recycle();
        return r;
    }

    private static boolean isTopRunning(ActivityRecord r, int taskId, IBinder notTop) {
        return r.getTask().mTaskId != taskId && r.appToken != notTop && r.canBeTopRunning();
    }

    ActivityRecord isInStackLocked(ActivityRecord r) {
        if (r == null) {
            return null;
        }
        final Task task = r.getRootTask();
        if (task != null && r.isDescendantOf(task)) {
            if (task != this) Slog.w(TAG, "Illegal state! task does not point to stack it is in. "
                    + "stack=" + this + " task=" + task + " r=" + r
                    + " callers=" + Debug.getCallers(15, "\n"));
            return r;
        }
        return null;
    }

    /** @return true if the stack can only contain one task */
    /** @return true if the stack can only contain one task */
    boolean isSingleTaskInstance() {
    boolean isSingleTaskInstance() {
        final DisplayContent display = getDisplay();
        final DisplayContent display = getDisplay();
@@ -1106,12 +1033,6 @@ class ActivityStack extends Task {
        return isTopActivityFocusable() && shouldBeVisible(null /* starting */);
        return isTopActivityFocusable() && shouldBeVisible(null /* starting */);
    }
    }


    @Override
    public boolean isAttached() {
        final TaskDisplayArea taskDisplayArea = getDisplayArea();
        return taskDisplayArea != null && !taskDisplayArea.isRemoved();
    }

    // TODO: Should each user have there own stacks?
    // TODO: Should each user have there own stacks?
    @Override
    @Override
    void switchUser(int userId) {
    void switchUser(int userId) {
@@ -1462,140 +1383,6 @@ class ActivityStack extends Task {
        return display != null && this == display.getFocusedStack();
        return display != null && this == display.getFocusedStack();
    }
    }


    /**
     * Returns true if the stack should be visible.
     *
     * @param starting The currently starting activity or null if there is none.
     */
    @Override
    boolean shouldBeVisible(ActivityRecord starting) {
        return getVisibility(starting) != STACK_VISIBILITY_INVISIBLE;
    }

    /**
     * Returns true if the stack should be visible.
     *
     * @param starting The currently starting activity or null if there is none.
     */
    @StackVisibility
    int getVisibility(ActivityRecord starting) {
        if (!isAttached() || isForceHidden()) {
            return STACK_VISIBILITY_INVISIBLE;
        }

        final TaskDisplayArea taskDisplayArea = getDisplayArea();
        boolean gotSplitScreenStack = false;
        boolean gotOpaqueSplitScreenPrimary = false;
        boolean gotOpaqueSplitScreenSecondary = false;
        boolean gotTranslucentFullscreen = false;
        boolean gotTranslucentSplitScreenPrimary = false;
        boolean gotTranslucentSplitScreenSecondary = false;
        boolean shouldBeVisible = true;
        final int windowingMode = getWindowingMode();
        final boolean isAssistantType = isActivityTypeAssistant();
        for (int i = taskDisplayArea.getStackCount() - 1; i >= 0; --i) {
            final ActivityStack other = taskDisplayArea.getStackAt(i);
            final boolean hasRunningActivities = other.topRunningActivity() != null;
            if (other == this) {
                // Should be visible if there is no other stack occluding it, unless it doesn't
                // have any running activities, not starting one and not home stack.
                shouldBeVisible = hasRunningActivities || isInStackLocked(starting) != null
                        || isActivityTypeHome();
                break;
            }

            if (!hasRunningActivities) {
                continue;
            }

            final int otherWindowingMode = other.getWindowingMode();

            if (otherWindowingMode == WINDOWING_MODE_FULLSCREEN) {
                // In this case the home stack isn't resizeable even though we are in split-screen
                // mode. We still want the primary splitscreen stack to be visible as there will be
                // a slight hint of it in the status bar area above the non-resizeable home
                // activity. In addition, if the fullscreen assistant is over primary splitscreen
                // stack, the stack should still be visible in the background as long as the recents
                // animation is running.
                final int activityType = other.getActivityType();
                if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
                    if (activityType == ACTIVITY_TYPE_HOME
                            || (activityType == ACTIVITY_TYPE_ASSISTANT
                                && mWmService.getRecentsAnimationController() != null)) {
                        break;
                    }
                }
                if (other.isTranslucent(starting)) {
                    // Can be visible behind a translucent fullscreen stack.
                    gotTranslucentFullscreen = true;
                    continue;
                }
                return STACK_VISIBILITY_INVISIBLE;
            } else if (otherWindowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY
                    && !gotOpaqueSplitScreenPrimary) {
                gotSplitScreenStack = true;
                gotTranslucentSplitScreenPrimary = other.isTranslucent(starting);
                gotOpaqueSplitScreenPrimary = !gotTranslucentSplitScreenPrimary;
                if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY
                        && gotOpaqueSplitScreenPrimary) {
                    // Can not be visible behind another opaque stack in split-screen-primary mode.
                    return STACK_VISIBILITY_INVISIBLE;
                }
            } else if (otherWindowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY
                    && !gotOpaqueSplitScreenSecondary) {
                gotSplitScreenStack = true;
                gotTranslucentSplitScreenSecondary = other.isTranslucent(starting);
                gotOpaqueSplitScreenSecondary = !gotTranslucentSplitScreenSecondary;
                if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY
                        && gotOpaqueSplitScreenSecondary) {
                    // Can not be visible behind another opaque stack in split-screen-secondary mode.
                    return STACK_VISIBILITY_INVISIBLE;
                }
            }
            if (gotOpaqueSplitScreenPrimary && gotOpaqueSplitScreenSecondary) {
                // Can not be visible if we are in split-screen windowing mode and both halves of
                // the screen are opaque.
                return STACK_VISIBILITY_INVISIBLE;
            }
            if (isAssistantType && gotSplitScreenStack) {
                // Assistant stack can't be visible behind split-screen. In addition to this not
                // making sense, it also works around an issue here we boost the z-order of the
                // assistant window surfaces in window manager whenever it is visible.
                return STACK_VISIBILITY_INVISIBLE;
            }
        }

        if (!shouldBeVisible) {
            return STACK_VISIBILITY_INVISIBLE;
        }

        // Handle cases when there can be a translucent split-screen stack on top.
        switch (windowingMode) {
            case WINDOWING_MODE_FULLSCREEN:
                if (gotTranslucentSplitScreenPrimary || gotTranslucentSplitScreenSecondary) {
                    // At least one of the split-screen stacks that covers this one is translucent.
                    return STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT;
                }
                break;
            case WINDOWING_MODE_SPLIT_SCREEN_PRIMARY:
                if (gotTranslucentSplitScreenPrimary) {
                    // Covered by translucent primary split-screen on top.
                    return STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT;
                }
                break;
            case WINDOWING_MODE_SPLIT_SCREEN_SECONDARY:
                if (gotTranslucentSplitScreenSecondary) {
                    // Covered by translucent secondary split-screen on top.
                    return STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT;
                }
                break;
        }

        // Lastly - check if there is a translucent fullscreen stack on top.
        return gotTranslucentFullscreen ? STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT
                : STACK_VISIBILITY_VISIBLE;
    }

    /**
    /**
     * Make sure that all activities that need to be visible in the stack (that is, they
     * Make sure that all activities that need to be visible in the stack (that is, they
     * currently can be seen by the user) actually are and update their configuration.
     * currently can be seen by the user) actually are and update their configuration.
+1 −1
Original line number Original line Diff line number Diff line
@@ -4065,7 +4065,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        return r != null
        return r != null
                && r.getRootTask() != null
                && r.getRootTask() != null
                && r.inPinnedWindowingMode()
                && r.inPinnedWindowingMode()
                && r.getRootTask().isInStackLocked(r) != null;
                && r.getRootTask().isInTask(r) != null;
    }
    }


    @Override
    @Override
+2 −3
Original line number Original line Diff line number Diff line
@@ -1398,10 +1398,9 @@ class RecentTasks {
            return false;
            return false;
        }
        }


        // Trim tasks that are in stacks that are behind the home stack
        // Trim tasks that are behind the home task.
        final TaskDisplayArea taskDisplayArea = stack.getDisplayArea();
        final TaskDisplayArea taskDisplayArea = stack.getDisplayArea();
        return taskDisplayArea.getIndexOf(stack) < taskDisplayArea.getIndexOf(
        return task.compareTo(taskDisplayArea.getRootHomeTask()) < 0;
                taskDisplayArea.getRootHomeTask());
    }
    }


    /** Remove the tasks that user may not be able to return. */
    /** Remove the tasks that user may not be able to return. */
Loading