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

Commit 29d19ddd authored by Andrii Kulian's avatar Andrii Kulian Committed by Android (Google) Code Review
Browse files

Merge changes from topic "per-display_focus_am"

* changes:
  Update tests for new focus tracking
  Rename getFocusedStack methods
  Per-display focused stacks in AM
parents cc741083 6a6c4f18
Loading
Loading
Loading
Loading
+33 −1
Original line number Diff line number Diff line
@@ -339,6 +339,38 @@ class ActivityDisplay extends ConfigurationContainer<ActivityStack>
                        this, stackId, mSupervisor, windowingMode, activityType, onTop);
    }

    ActivityStack getFocusedStack() {
        for (int i = mStacks.size() - 1; i >= 0; --i) {
            final ActivityStack stack = mStacks.get(i);
            if (stack.isFocusable() && stack.shouldBeVisible(null /* starting */)) {
                return stack;
            }
        }

        return null;
    }

    ActivityRecord getResumedActivity() {
        final ActivityStack focusedStack = getFocusedStack();
        if (focusedStack == null) {
            return null;
        }
        // TODO(b/111541062): Move this into ActivityStack#getResumedActivity()
        // Check if the focused stack has the resumed activity
        ActivityRecord resumedActivity = focusedStack.getResumedActivity();
        if (resumedActivity == null || resumedActivity.app == null) {
            // If there is no registered resumed activity in the stack or it is not running -
            // try to use previously resumed one.
            resumedActivity = focusedStack.mPausingActivity;
            if (resumedActivity == null || resumedActivity.app == null) {
                // If previously resumed activity doesn't work either - find the topmost running
                // activity that can be focused.
                resumedActivity = focusedStack.topRunningActivityLocked(true /* focusableOnly */);
            }
        }
        return resumedActivity;
    }

    /**
     * Removes stacks in the input windowing modes from the system if they are of activity type
     * ACTIVITY_TYPE_STANDARD or ACTIVITY_TYPE_UNDEFINED
@@ -585,7 +617,7 @@ class ActivityDisplay extends ConfigurationContainer<ActivityStack>

    /**
     * Get the topmost stack on the display. It may be different from focused stack, because
     * focus may be on another display.
     * some stacks are not focusable (e.g. PiP).
     */
    ActivityStack getTopStack() {
        return mStacks.isEmpty() ? null : mStacks.get(mStacks.size() - 1);
+10 −7
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ import static android.provider.Settings.Global.DEBUG_APP;
import static android.provider.Settings.Global.NETWORK_ACCESS_TIMEOUT_MS;
import static android.provider.Settings.Global.WAIT_FOR_DEBUGGER;
import static android.text.format.DateUtils.DAY_IN_MILLIS;
import static android.view.Display.DEFAULT_DISPLAY;
import static com.android.internal.util.XmlUtils.readBooleanAttribute;
import static com.android.internal.util.XmlUtils.readIntAttribute;
import static com.android.internal.util.XmlUtils.readLongAttribute;
@@ -12825,8 +12826,8 @@ public class ActivityManagerService extends IActivityManager.Stub
        boolean needSep = printedAnything;
        boolean printed = ActivityStackSupervisor.printThisActivity(pw,
                mStackSupervisor.getResumedActivityLocked(),
                dumpPackage, needSep, "  ResumedActivity: ");
                mStackSupervisor.getTopResumedActivity(),  dumpPackage, needSep,
                "  ResumedActivity: ");
        if (printed) {
            printedAnything = true;
            needSep = false;
@@ -13230,7 +13231,8 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
        if (dumpAll) {
            if (dumpPackage == null) {
                pw.println("  mConfigWillChange: " + mActivityTaskManager.getFocusedStack().mConfigWillChange);
                pw.println("  mConfigWillChange: "
                        + mActivityTaskManager.getTopDisplayFocusedStack().mConfigWillChange);
            }
            if (mCompatModePackages.getPackages().size() > 0) {
                boolean printed = false;
@@ -13601,7 +13603,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        if (dumpPackage == null) {
            mUserController.writeToProto(proto, ActivityManagerServiceDumpProcessesProto.USER_CONTROLLER);
            getGlobalConfiguration().writeToProto(proto, ActivityManagerServiceDumpProcessesProto.GLOBAL_CONFIGURATION);
            proto.write(ActivityManagerServiceDumpProcessesProto.CONFIG_WILL_CHANGE, mActivityTaskManager.getFocusedStack().mConfigWillChange);
            proto.write(ActivityManagerServiceDumpProcessesProto.CONFIG_WILL_CHANGE, mActivityTaskManager.getTopDisplayFocusedStack().mConfigWillChange);
        }
        if (mActivityTaskManager.mHomeProcess != null && (dumpPackage == null
@@ -20642,9 +20644,10 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
    }
    private final ActivityRecord resumedAppLocked() {
        final ActivityRecord act =
                mStackSupervisor != null ? mStackSupervisor.getResumedActivityLocked() : null;
    // TODO(b/111541062): This method is only used for updating OOM adjustments. We need to update
    // the logic there and in mBatteryStatsService to make them aware of multiple resumed activities
    private ActivityRecord resumedAppLocked() {
        final ActivityRecord act = mStackSupervisor.getTopResumedActivity();
        String pkg;
        int uid;
        if (act != null) {
+1 −1
Original line number Diff line number Diff line
@@ -184,7 +184,7 @@ class ActivityMetricsLogger {
        mLastLogTimeSecs = now;

        mWindowState = WINDOW_STATE_INVALID;
        ActivityStack stack = mSupervisor.getFocusedStack();
        ActivityStack stack = mSupervisor.getTopDisplayFocusedStack();
        if (stack == null) {
            return;
        }
+11 −2
Original line number Diff line number Diff line
@@ -1792,7 +1792,7 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
        // considers the resumed activity, as normal means will bring the activity from STOPPED
        // to RESUMED. Adding PAUSING in this scenario will lead to double lifecycles.
        if (!isState(STOPPED, STOPPING) || getStack().mTranslucentActivityWaiting != null
                || mStackSupervisor.getResumedActivityLocked() == this) {
                || isResumedActivityOnDisplay()) {
            return false;
        }

@@ -2162,7 +2162,7 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
        // another activity to start or has stopped, then the key dispatching
        // timeout should not be caused by this.
        if (mStackSupervisor.mActivitiesWaitingForVisibleActivity.contains(this) || stopped) {
            final ActivityStack stack = mStackSupervisor.getFocusedStack();
            final ActivityStack stack = mStackSupervisor.getTopDisplayFocusedStack();
            // Try to use the one which is closest to top.
            ActivityRecord r = stack.getResumedActivity();
            if (r == null) {
@@ -3003,6 +3003,15 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
        return mStackSupervisor.topRunningActivityLocked() == this;
    }

    /**
     * @return {@code true} if this is the resumed activity on its current display, {@code false}
     * otherwise.
     */
    boolean isResumedActivityOnDisplay() {
        final ActivityDisplay display = getDisplay();
        return display != null && this == display.getResumedActivity();
    }

    void registerRemoteAnimations(RemoteAnimationDefinition definition) {
        mWindowContainerController.registerRemoteAnimations(definition);
    }
+27 −16
Original line number Diff line number Diff line
@@ -847,7 +847,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
        }
    }

    private ActivityRecord topRunningActivityLocked(boolean focusableOnly) {
    ActivityRecord topRunningActivityLocked(boolean focusableOnly) {
        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
            ActivityRecord r = mTaskHistory.get(taskNdx).topRunningActivityLocked();
            if (r != null && (!focusableOnly || r.isFocusable())) {
@@ -1052,12 +1052,14 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
        if (!isActivityTypeHome() && returnsToHomeStack()) {
            // Make sure the home stack is behind this stack since that is where we should return to
            // when this stack is no longer visible.
            // TODO(b/111541062): Move home stack on the current display
            mStackSupervisor.moveHomeStackToFront(reason + " returnToHome");
        }

        display.positionChildAtTop(this);
        mStackSupervisor.setFocusStackUnchecked(reason, this);
        if (task != null) {
            // This also moves the entire hierarchy branch to top, including parents
            insertTaskAtTop(task, null);
            return;
        }
@@ -1083,6 +1085,8 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
        getDisplay().positionChildAtBottom(this);
        mStackSupervisor.setFocusStackUnchecked(reason, getDisplay().getTopStack());
        if (task != null) {
            // TODO(b/111541062): We probably don't want to change display z-order to bottom just
            // because one of its stacks moved to bottom.
            insertTaskAtBottom(task);
            return;
        }
@@ -1611,7 +1615,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
        }

        if (resumeNext) {
            final ActivityStack topStack = mStackSupervisor.getFocusedStack();
            final ActivityStack topStack = mStackSupervisor.getTopDisplayFocusedStack();
            if (!topStack.shouldSleepOrShutDownActivities()) {
                mStackSupervisor.resumeFocusedStackTopActivityLocked(topStack, prev, null);
            } else {
@@ -1734,7 +1738,17 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
    }

    boolean isTopStackOnDisplay() {
        return getDisplay().isTopStack(this);
        final ActivityDisplay display = getDisplay();
        return display != null && display.isTopStack(this);
    }

    /**
     * @return {@code true} if this is the focused stack on its current display, {@code false}
     * otherwise.
     */
    boolean isFocusedStackOnDisplay() {
        final ActivityDisplay display = getDisplay();
        return display != null && this == display.getFocusedStack();
    }

    boolean isTopActivityVisible() {
@@ -1751,9 +1765,6 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
        if (!isAttached() || mForceHidden) {
            return false;
        }
        if (mStackSupervisor.isFocusedStack(this)) {
            return true;
        }

        final ActivityRecord top = topRunningActivityLocked();
        if (top == null && isInStackLocked(starting) == null && !isTopStackOnDisplay()) {
@@ -1883,7 +1894,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
            boolean aboveTop = top != null;
            final boolean stackShouldBeVisible = shouldBeVisible(starting);
            boolean behindFullscreenActivity = !stackShouldBeVisible;
            boolean resumeNextActivity = mStackSupervisor.isFocusedStack(this)
            boolean resumeNextActivity = mStackSupervisor.isTopDisplayFocusedStack(this)
                    && (isInStackLocked(starting) == null);
            final boolean isTopNotPinnedStack =
                    isAttached() && getDisplay().isTopNotPinnedStack(this);
@@ -2435,7 +2446,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai

        boolean lastResumedCanPip = false;
        ActivityRecord lastResumed = null;
        final ActivityStack lastFocusedStack = mStackSupervisor.getLastStack();
        final ActivityStack lastFocusedStack = mStackSupervisor.getTopDisplayLastFocusedStack();
        if (lastFocusedStack != null && lastFocusedStack != this) {
            // So, why aren't we using prev here??? See the param comment on the method. prev doesn't
            // represent the last resumed activity. However, the last focus stack does if it isn't null.
@@ -2596,7 +2607,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai

        mStackSupervisor.mNoAnimActivities.clear();

        ActivityStack lastStack = mStackSupervisor.getLastStack();
        ActivityStack lastStack = mStackSupervisor.getTopDisplayLastFocusedStack();
        if (next.attachedToProcess()) {
            if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resume running: " + next
                    + " stopped=" + next.stopped + " visible=" + next.visible);
@@ -2646,7 +2657,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
                // the screen based on the new activity order.
                boolean notUpdated = true;

                if (mStackSupervisor.isFocusedStack(this)) {
                if (mStackSupervisor.isTopDisplayFocusedStack(this)) {
                    // We have special rotation behavior when here is some active activity that
                    // requests specific orientation or Keyguard is locked. Make sure all activity
                    // visibilities are set correctly as well as the transition is updated if needed
@@ -2784,7 +2795,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
            // stack is not covering the entire screen or is on a secondary display (with no home
            // stack).
            return mStackSupervisor.resumeFocusedStackTopActivityLocked(
                    mStackSupervisor.getFocusedStack(), prev, null);
                    mStackSupervisor.getTopDisplayFocusedStack(), prev, null);
        }

        // Let's just start up the Launcher...
@@ -3397,7 +3408,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
    }

    private void adjustFocusedActivityStack(ActivityRecord r, String reason) {
        if (!mStackSupervisor.isFocusedStack(this) ||
        if (!mStackSupervisor.isTopDisplayFocusedStack(this) ||
                ((mResumedActivity != r) && (mResumedActivity != null))) {
            return;
        }
@@ -3845,7 +3856,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai

        r.setState(FINISHING, "finishCurrentActivityLocked");
        final boolean finishingActivityInNonFocusedStack
                = r.getStack() != mStackSupervisor.getFocusedStack()
                = r.getStack() != mStackSupervisor.getTopDisplayFocusedStack()
                && prevState == PAUSED && mode == FINISH_AFTER_VISIBLE;

        if (mode == FINISH_IMMEDIATELY
@@ -4954,7 +4965,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
     */
    void getRunningTasks(List<TaskRecord> tasksOut, @ActivityType int ignoreActivityType,
            @WindowingMode int ignoreWindowingMode, int callingUid, boolean allowed) {
        boolean focusedStack = mStackSupervisor.getFocusedStack() == this;
        boolean focusedStack = mStackSupervisor.getTopDisplayFocusedStack() == this;
        boolean topTask = true;
        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
            final TaskRecord task = mTaskHistory.get(taskNdx);
@@ -5161,7 +5172,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
            // We only need to adjust focused stack if this stack is in focus and we are not in the
            // process of moving the task to the top of the stack that will be focused.
            if (isOnHomeDisplay() && mode != REMOVE_TASK_MODE_MOVING_TO_TOP
                    && mStackSupervisor.isFocusedStack(this)) {
                    && mStackSupervisor.isTopDisplayFocusedStack(this)) {
                String myReason = reason + " leftTaskHistoryEmpty";
                if (!inMultiWindowMode() || !adjustFocusToNextFocusableStack(myReason)) {
                    mStackSupervisor.moveHomeStackToFront(myReason);
@@ -5365,7 +5376,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai

        // Do not sleep activities in this stack if we're marked as focused and the keyguard
        // is in the process of going away.
        if (mStackSupervisor.getFocusedStack() == this
        if (mStackSupervisor.getTopDisplayFocusedStack() == this
                && mStackSupervisor.getKeyguardController().isKeyguardGoingAway()) {
            return false;
        }
Loading