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

Commit b783fd8a authored by Wale Ogunwale's avatar Wale Ogunwale
Browse files

Traverse window hierarchy without window list

Added support for to get all windows in the hierarchy without needing
to use WindowList concept which is a very complicated implementation
in the code base.
This implementation walks the hierarchy node by node returns windows
in order to the caller using a callback.

Test: bit FrameworksServicesTests:com.android.server.wm.DisplayContentTests
Change-Id: I2719f7c96f26dad23f91c1c589be88712bd224b8
parent 67387af7
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import android.view.animation.Animation;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.function.Consumer;

class AppTokenList extends ArrayList<AppWindowToken> {
}
@@ -1268,6 +1269,22 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
        return rebuildWindowListUnchecked(addIndex);
    }

    @Override
    void forAllWindows(Consumer<WindowState> callback, boolean traverseTopToBottom) {
        // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
        // before the non-exiting app tokens. So, we skip the exiting app tokens here.
        // TODO: Investigate if we need to continue to do this or if we can just process them
        // in-order.
        if (mIsExiting && !waitingForReplacement()) {
            return;
        }
        forAllWindowsUnchecked(callback, traverseTopToBottom);
    }

    void forAllWindowsUnchecked(Consumer<WindowState> callback, boolean traverseTopToBottom) {
        super.forAllWindows(callback, traverseTopToBottom);
    }

    @Override
    AppWindowToken asAppWindowToken() {
        // I am an app window token!
+37 −0
Original line number Diff line number Diff line
@@ -140,6 +140,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Consumer;

/**
 * Utility class for keeping track of the WindowStates and other pertinent contents of a
@@ -3242,6 +3243,42 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
            setLayoutNeeded();
        }

        @Override
        void forAllWindows(Consumer<WindowState> callback, boolean traverseTopToBottom) {
            if (traverseTopToBottom) {
                super.forAllWindows(callback, traverseTopToBottom);
                forAllExitingAppTokenWindows(callback, traverseTopToBottom);
            } else {
                forAllExitingAppTokenWindows(callback, traverseTopToBottom);
                super.forAllWindows(callback, traverseTopToBottom);
            }
        }

        private void forAllExitingAppTokenWindows(Consumer<WindowState> callback,
                boolean traverseTopToBottom) {
            // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the
            // app tokens.
            // TODO: Investigate if we need to continue to do this or if we can just process them
            // in-order.
            if (traverseTopToBottom) {
                for (int i = mChildren.size() - 1; i >= 0; --i) {
                    final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
                    for (int j = appTokens.size() - 1; j >= 0; --j) {
                        appTokens.get(j).forAllWindowsUnchecked(callback, traverseTopToBottom);
                    }
                }
            } else {
                final int count = mChildren.size();
                for (int i = 0; i < count; ++i) {
                    final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
                    final int appTokensCount = appTokens.size();
                    for (int j = 0; j < appTokensCount; j++) {
                        appTokens.get(j).forAllWindowsUnchecked(callback, traverseTopToBottom);
                    }
                }
            }
        }

        @Override
        int getOrientation() {
            if (mService.isStackVisibleLocked(DOCKED_STACK_ID)
+2 −1
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.view.IPinnedStackListener;
import com.android.internal.os.BackgroundThread;
import com.android.internal.policy.PipMotionHelper;
import com.android.internal.policy.PipSnapAlgorithm;
import com.android.server.UiThread;

import java.io.PrintWriter;

@@ -55,7 +56,7 @@ class PinnedStackController {

    private final WindowManagerService mService;
    private final DisplayContent mDisplayContent;
    private final Handler mHandler = new Handler();
    private final Handler mHandler = UiThread.getHandler();

    private IPinnedStackListener mPinnedStackListener;
    private final PinnedStackListenerDeathHandler mPinnedStackListenerDeathHandler =
+15 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.view.animation.Animation;

import java.util.Comparator;
import java.util.LinkedList;
import java.util.function.Consumer;

import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
@@ -494,6 +495,19 @@ class WindowContainer<E extends WindowContainer> implements Comparable<WindowCon
        return addIndex;
    }

    void forAllWindows(Consumer<WindowState> callback, boolean traverseTopToBottom) {
        if (traverseTopToBottom) {
            for (int i = mChildren.size() - 1; i >= 0; --i) {
                mChildren.get(i).forAllWindows(callback, traverseTopToBottom);
            }
        } else {
            final int count = mChildren.size();
            for (int i = 0; i < count; i++) {
                mChildren.get(i).forAllWindows(callback, traverseTopToBottom);
            }
        }
    }

    /**
     * Returns 1, 0, or -1 depending on if this container is greater than, equal to, or lesser than
     * the input container in terms of z-order.
@@ -562,8 +576,7 @@ class WindowContainer<E extends WindowContainer> implements Comparable<WindowCon
    void dumpChildrenNames(StringBuilder out, String prefix) {
        final String childPrefix = prefix + " ";
        out.append(getName() + "\n");
        final int count = mChildren.size();
        for (int i = 0; i < count; i++) {
        for (int i = mChildren.size() - 1; i >= 0; --i) {
            final WindowContainer wc = mChildren.get(i);
            out.append(childPrefix + "#" + i + " ");
            wc.dumpChildrenNames(out, childPrefix);
+2 −0
Original line number Diff line number Diff line
@@ -8201,6 +8201,8 @@ public class WindowManagerService extends IWindowManager.Stub
                    StringBuilder output = new StringBuilder();
                    mRoot.dumpChildrenNames(output, " ");
                    pw.println(output.toString());
                    pw.println(" ");
                    mRoot.forAllWindows(pw::println, true /* traverseTopToBottom */);
                }
                return;
            } else {
Loading