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

Commit 95c204fd authored by Chris Li's avatar Chris Li
Browse files

Add forAllTaskDisplayAreas

(6/n DisplayArea Sibling Roots)

After sibling roots, we may have TaskDisplayAreas below different roots.
We don't want to cache a list of it, so add forAllTaskDisplayAreas and
update all current usages to reduce the chance for things to be out of
sync.

Bug: 157683117
Test: atest WmTests:DisplayAreaTest
Test: atest WmTests:DisplayContentTests
Test: atest WmTests:RootActivityContainerTests
Change-Id: I10767293f7efebde957a4ead4eff32361269a3ea
parent aa388d2c
Loading
Loading
Loading
Loading
+4 −10
Original line number Diff line number Diff line
@@ -7516,22 +7516,16 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
    }

    /**
     * @return {@code true} if this is the resumed activity on its current display, {@code false}
     * @return {@code true} if this is the focused activity on its current display, {@code false}
     * otherwise.
     */
    boolean isResumedActivityOnDisplay() {
    boolean isFocusedActivityOnDisplay() {
        final DisplayContent display = getDisplay();
        if (display == null) {
            return false;
        }
        for (int tdaNdx = display.getTaskDisplayAreaCount() - 1; tdaNdx >= 0; --tdaNdx) {
            final TaskDisplayArea taskDisplayArea = display.getTaskDisplayAreaAt(tdaNdx);
            final ActivityRecord resumedActivity = taskDisplayArea.getFocusedActivity();
            if (resumedActivity != null) {
                return resumedActivity == this;
            }
        }
        return false;
        return display.forAllTaskDisplayAreas(taskDisplayArea ->
                taskDisplayArea.getFocusedActivity() == this);
    }


+2 −3
Original line number Diff line number Diff line
@@ -218,7 +218,6 @@ import android.service.voice.IVoiceInteractionSession;
import android.service.voice.VoiceInteractionManagerInternal;
import android.sysprop.DisplayProperties;
import android.telecom.TelecomManager;
import android.text.TextUtils;
import android.text.format.TimeMigrationUtils;
import android.util.ArrayMap;
import android.util.ArraySet;
@@ -1956,7 +1955,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
            r.immersive = immersive;

            // update associated state if we're frontmost
            if (r.isResumedActivityOnDisplay()) {
            if (r.isFocusedActivityOnDisplay()) {
                if (DEBUG_IMMERSIVE) Slog.d(TAG_IMMERSIVE, "Frontmost changed immersion: "+ r);
                applyUpdateLockStateLocked(r);
            }
@@ -4322,7 +4321,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                r.requestedVrComponent = (enabled) ? packageName : null;

                // Update associated state if this activity is currently focused
                if (r.isResumedActivityOnDisplay()) {
                if (r.isFocusedActivityOnDisplay()) {
                    applyUpdateVrModeLocked(r);
                }
                return 0;
+100 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import static com.android.server.wm.DisplayAreaProto.WINDOW_CONTAINER;
import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_ORIENTATION;
import static com.android.server.wm.WindowContainerChildProto.DISPLAY_AREA;

import android.annotation.Nullable;
import android.content.res.Configuration;
import android.graphics.Rect;
import android.util.proto.ProtoOutputStream;
@@ -40,7 +41,9 @@ import com.android.server.policy.WindowManagerPolicy;
import com.android.server.protolog.common.ProtoLog;

import java.util.Comparator;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;

/**
@@ -139,11 +142,108 @@ public class DisplayArea<T extends WindowContainer> extends WindowContainer<T> {
        return DISPLAY_AREA;
    }

    @Override
    final DisplayArea asDisplayArea() {
        return this;
    }

    @Override
    void forAllDisplayAreas(Consumer<DisplayArea> callback) {
        super.forAllDisplayAreas(callback);
        callback.accept(this);
    }

    @Override
    boolean forAllTaskDisplayAreas(Function<TaskDisplayArea, Boolean> callback,
            boolean traverseTopToBottom) {
        // Only DisplayArea of Type.ANY may contain TaskDisplayArea as children.
        if (mType != DisplayArea.Type.ANY) {
            return false;
        }

        int childCount = mChildren.size();
        int i = traverseTopToBottom ? childCount - 1 : 0;
        while (i >= 0 && i < childCount) {
            T child = mChildren.get(i);
            // Only traverse if the child is a DisplayArea.
            if (child.asDisplayArea() != null && child.asDisplayArea()
                    .forAllTaskDisplayAreas(callback, traverseTopToBottom)) {
                return true;
            }
            i += traverseTopToBottom ? -1 : 1;
        }
        return false;
    }

    @Override
    void forAllTaskDisplayAreas(Consumer<TaskDisplayArea> callback, boolean traverseTopToBottom) {
        // Only DisplayArea of Type.ANY may contain TaskDisplayArea as children.
        if (mType != DisplayArea.Type.ANY) {
            return;
        }

        int childCount = mChildren.size();
        int i = traverseTopToBottom ? childCount - 1 : 0;
        while (i >= 0 && i < childCount) {
            T child = mChildren.get(i);
            // Only traverse if the child is a DisplayArea.
            if (child.asDisplayArea() != null) {
                child.asDisplayArea().forAllTaskDisplayAreas(callback, traverseTopToBottom);
            }
            i += traverseTopToBottom ? -1 : 1;
        }
    }

    @Nullable
    @Override
    <R> R reduceOnAllTaskDisplayAreas(BiFunction<TaskDisplayArea, R, R> accumulator,
            @Nullable R initValue, boolean traverseTopToBottom) {
        // Only DisplayArea of Type.ANY may contain TaskDisplayArea as children.
        if (mType != DisplayArea.Type.ANY) {
            return initValue;
        }

        int childCount = mChildren.size();
        int i = traverseTopToBottom ? childCount - 1 : 0;
        R result = initValue;
        while (i >= 0 && i < childCount) {
            T child = mChildren.get(i);
            // Only traverse if the child is a DisplayArea.
            if (child.asDisplayArea() != null) {
                result = (R) child.asDisplayArea()
                        .reduceOnAllTaskDisplayAreas(accumulator, result, traverseTopToBottom);
            }
            i += traverseTopToBottom ? -1 : 1;
        }
        return result;
    }

    @Nullable
    @Override
    <R> R getItemFromTaskDisplayAreas(Function<TaskDisplayArea, R> callback,
            boolean traverseTopToBottom) {
        // Only DisplayArea of Type.ANY may contain TaskDisplayArea as children.
        if (mType != DisplayArea.Type.ANY) {
            return null;
        }

        int childCount = mChildren.size();
        int i = traverseTopToBottom ? childCount - 1 : 0;
        while (i >= 0 && i < childCount) {
            T child = mChildren.get(i);
            // Only traverse if the child is a DisplayArea.
            if (child.asDisplayArea() != null) {
                R result = (R) child.asDisplayArea()
                        .getItemFromTaskDisplayAreas(callback, traverseTopToBottom);
                if (result != null) {
                    return result;
                }
            }
            i += traverseTopToBottom ? -1 : 1;
        }
        return null;
    }

    void setOrganizer(IDisplayAreaOrganizer organizer) {
        if (mOrganizer == organizer) return;
        IDisplayAreaOrganizer lastOrganizer = mOrganizer;
+0 −10
Original line number Diff line number Diff line
@@ -63,16 +63,6 @@ public abstract class DisplayAreaPolicy {
     */
    public abstract List<DisplayArea<? extends WindowContainer>> getDisplayAreas(int featureId);

    /**
     * @return the number of task display areas on the display.
     */
    public abstract int getTaskDisplayAreaCount();

    /**
     * @return the task display area at index.
     */
    public abstract TaskDisplayArea getTaskDisplayAreaAt(int index);

    /** Provider for platform-default display area policy. */
    static final class DefaultProvider implements DisplayAreaPolicy.Provider {
        @Override
+0 −12
Original line number Diff line number Diff line
@@ -436,18 +436,6 @@ class DisplayAreaPolicyBuilder {
            }
            return new ArrayList<>();
        }

        @Override
        public int getTaskDisplayAreaCount() {
            // TODO(b/157683117): Also add TDA from sub root.
            return mRoot.mTaskDisplayAreas.size();
        }

        @Override
        public TaskDisplayArea getTaskDisplayAreaAt(int index) {
            // TODO(b/157683117): Get TDA from root/sub root based on their z-order.
            return mRoot.mTaskDisplayAreas.get(index);
        }
    }

    static class PendingArea {
Loading