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

Commit 4551c8bb authored by Wale Ogunwale's avatar Wale Ogunwale
Browse files

WindowList be gone!

The use of DisplayContent.mWindow list to track all windows is
no longer needed as we can now get windows through the window
container hierarchy with methods like forAllWindows. The window
list was also a very complicated logic to understand and maintain,
so it won't be missed :)

Bug: 30060889
Test: Existing tests pass
Change-Id: I590cb33aa0f42bcd4a26ddce102f05e657f54144
parent 6b18e8f5
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -411,7 +411,7 @@ public class AppWindowAnimator {
        }
        }
        if (mService.mInputMethodTarget != null
        if (mService.mInputMethodTarget != null
                && mService.mInputMethodTarget.mAppToken == mAppToken) {
                && mService.mInputMethodTarget.mAppToken == mAppToken) {
            mAppToken.getDisplayContent().moveInputMethodWindowsIfNeeded(true);
            mAppToken.getDisplayContent().computeImeTarget(true /* updateImeTarget */);
        }
        }


        if (DEBUG_ANIM) Slog.v(TAG, "Animation done in " + mAppToken
        if (DEBUG_ANIM) Slog.v(TAG, "Animation done in " + mAppToken
+27 −16
Original line number Original line Diff line number Diff line
@@ -1006,10 +1006,7 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
            tStartingWindow.mToken = this;
            tStartingWindow.mToken = this;
            tStartingWindow.mAppToken = this;
            tStartingWindow.mAppToken = this;


            if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
            if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
                    "Removing starting window: " + tStartingWindow);
            getDisplayContent().removeFromWindowList(tStartingWindow);
            if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
                    "Removing starting " + tStartingWindow + " from " + fromToken);
                    "Removing starting " + tStartingWindow + " from " + fromToken);
            fromToken.removeChild(tStartingWindow);
            fromToken.removeChild(tStartingWindow);
            fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
            fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
@@ -1259,18 +1256,6 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
        }
        }
    }
    }


    int rebuildWindowListUnchecked(int addIndex) {
        return super.rebuildWindowList(addIndex);
    }

    @Override
    int rebuildWindowList(int addIndex) {
        if (mIsExiting && !waitingForReplacement()) {
            return addIndex;
        }
        return rebuildWindowListUnchecked(addIndex);
    }

    @Override
    @Override
    boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
    boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
        // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
        // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
@@ -1332,6 +1317,32 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
        mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
        mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
    }
    }


    WindowState getImeTargetBelowWindow(WindowState w) {
        final int index = mChildren.indexOf(w);
        if (index > 0) {
            final WindowState target = mChildren.get(index - 1);
            if (target.canBeImeTarget()) {
                return target;
            }
        }
        return null;
    }

    WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
        WindowState candidate = null;
        for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
            final WindowState w = mChildren.get(i);
            if (w.mRemoved) {
                continue;
            }
            if (candidate == null || w.mWinAnimator.mAnimLayer >
                    candidate.mWinAnimator.mAnimLayer) {
                candidate = w;
            }
        }
        return candidate;
    }

    @Override
    @Override
    void dump(PrintWriter pw, String prefix) {
    void dump(PrintWriter pw, String prefix) {
        super.dump(pw, prefix);
        super.dump(pw, prefix);
+492 −1256

File changed.

Preview size limit exceeded, changes collapsed.

+93 −7
Original line number Original line Diff line number Diff line
@@ -16,10 +16,15 @@


package com.android.server.wm;
package com.android.server.wm;


import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.WindowManager.INPUT_CONSUMER_NAVIGATION;
import static android.view.WindowManager.INPUT_CONSUMER_PIP;
import static android.view.WindowManager.INPUT_CONSUMER_PIP;
import static android.view.WindowManager.INPUT_CONSUMER_WALLPAPER;
import static android.view.WindowManager.INPUT_CONSUMER_WALLPAPER;
import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DRAG;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DRAG;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT;
@@ -70,6 +75,10 @@ final class InputMonitor implements InputManagerService.WindowManagerCallbacks {
    // Array of window handles to provide to the input dispatcher.
    // Array of window handles to provide to the input dispatcher.
    private InputWindowHandle[] mInputWindowHandles;
    private InputWindowHandle[] mInputWindowHandles;
    private int mInputWindowHandleCount;
    private int mInputWindowHandleCount;
    private boolean mAddInputConsumerHandle;
    private boolean mAddPipInputConsumerHandle;
    private boolean mAddWallpaperInputConsumerHandle;
    private boolean mDisableWallpaperTouchEvents;


    // Set to true when the first input device configuration change notification
    // Set to true when the first input device configuration change notification
    // is received to indicate that the input devices are ready.
    // is received to indicate that the input devices are ready.
@@ -323,12 +332,12 @@ final class InputMonitor implements InputManagerService.WindowManagerCallbacks {
        }
        }
    }
    }


    public void setUpdateInputWindowsNeededLw() {
    void setUpdateInputWindowsNeededLw() {
        mUpdateInputWindowsNeeded = true;
        mUpdateInputWindowsNeeded = true;
    }
    }


    /* Updates the cached window information provided to the input dispatcher. */
    /* Updates the cached window information provided to the input dispatcher. */
    public void updateInputWindowsLw(boolean force) {
    void updateInputWindowsLw(boolean force) {
        if (!force && !mUpdateInputWindowsNeeded) {
        if (!force && !mUpdateInputWindowsNeeded) {
            return;
            return;
        }
        }
@@ -372,15 +381,92 @@ final class InputMonitor implements InputManagerService.WindowManagerCallbacks {
        }
        }


        // Add all windows on the default display.
        // Add all windows on the default display.
        mService.mRoot.updateInputWindows(this, mInputFocus, inDrag);
        updateInputWindows(inDrag);


        // Send windows to native code.
        if (false) Slog.d(TAG_WM, "<<<<<<< EXITED updateInputWindowsLw");
        mService.mInputManager.setInputWindows(mInputWindowHandles);
    }

    private void updateInputWindows(boolean inDrag) {


        // Clear the list in preparation for the next round.
        clearInputWindowHandlesLw();
        clearInputWindowHandlesLw();


        if (false) Slog.d(TAG_WM, "<<<<<<< EXITED updateInputWindowsLw");
        // TODO: multi-display
        final InputConsumerImpl navInputConsumer =
                getInputConsumer(INPUT_CONSUMER_NAVIGATION, DEFAULT_DISPLAY);
        final InputConsumerImpl pipInputConsumer =
                getInputConsumer(INPUT_CONSUMER_PIP, DEFAULT_DISPLAY);
        final InputConsumerImpl wallpaperInputConsumer =
                getInputConsumer(INPUT_CONSUMER_WALLPAPER, DEFAULT_DISPLAY);
        mAddInputConsumerHandle = navInputConsumer != null;
        mAddPipInputConsumerHandle = pipInputConsumer != null;
        mAddWallpaperInputConsumerHandle = wallpaperInputConsumer != null;
        final Rect pipTouchableBounds = mAddPipInputConsumerHandle ? new Rect() : null;
        mDisableWallpaperTouchEvents = false;

        final WallpaperController wallpaperController = mService.mRoot.mWallpaperController;
        mService.mRoot.forAllWindows(w -> {
            final InputChannel inputChannel = w.mInputChannel;
            final InputWindowHandle inputWindowHandle = w.mInputWindowHandle;
            if (inputChannel == null || inputWindowHandle == null || w.mRemoved
                    || w.isAdjustedForMinimizedDock()) {
                // Skip this window because it cannot possibly receive input.
                return;
            }

            if (mAddPipInputConsumerHandle
                    && w.getStackId() == PINNED_STACK_ID
                    && inputWindowHandle.layer <= pipInputConsumer.mWindowHandle.layer) {
                // Update the bounds of the Pip input consumer to match the Pinned stack
                w.getStack().getBounds(pipTouchableBounds);
                pipInputConsumer.mWindowHandle.touchableRegion.set(pipTouchableBounds);
                addInputWindowHandle(pipInputConsumer.mWindowHandle);
                mAddPipInputConsumerHandle = false;
            }

            if (mAddInputConsumerHandle
                    && inputWindowHandle.layer <= navInputConsumer.mWindowHandle.layer) {
                addInputWindowHandle(navInputConsumer.mWindowHandle);
                mAddInputConsumerHandle = false;
            }

            if (mAddWallpaperInputConsumerHandle) {
                if (w.mAttrs.type == TYPE_WALLPAPER && w.isVisibleLw()) {
                    // Add the wallpaper input consumer above the first visible wallpaper.
                    addInputWindowHandle(wallpaperInputConsumer.mWindowHandle);
                    mAddWallpaperInputConsumerHandle = false;
                }
            }

            final int flags = w.mAttrs.flags;
            final int privateFlags = w.mAttrs.privateFlags;
            final int type = w.mAttrs.type;

            final boolean hasFocus = w == mInputFocus;
            final boolean isVisible = w.isVisibleLw();
            if ((privateFlags & PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS) != 0) {
                mDisableWallpaperTouchEvents = true;
            }
            final boolean hasWallpaper = wallpaperController.isWallpaperTarget(w)
                    && (privateFlags & PRIVATE_FLAG_KEYGUARD) == 0
                    && !mDisableWallpaperTouchEvents;

            // If there's a drag in progress and 'child' is a potential drop target,
            // make sure it's been told about the drag
            if (inDrag && isVisible && w.getDisplayContent().isDefaultDisplay) {
                mService.mDragState.sendDragStartedIfNeededLw(w);
            }

            addInputWindowHandle(
                    inputWindowHandle, w, flags, type, isVisible, hasFocus, hasWallpaper);
        }, true /* traverseTopToBottom */);

        if (mAddWallpaperInputConsumerHandle) {
            // No visible wallpaper found, add the wallpaper input consumer at the end.
            addInputWindowHandle(wallpaperInputConsumer.mWindowHandle);
        }

        // Send windows to native code.
        mService.mInputManager.setInputWindows(mInputWindowHandles);
    }
    }


    /* Notifies that the input device configuration has changed. */
    /* Notifies that the input device configuration has changed. */
+2 −19
Original line number Original line Diff line number Diff line
@@ -219,7 +219,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> {
        return false;
        return false;
    }
    }


    void getWindowsByName(WindowList output, String name) {
    void getWindowsByName(ArrayList<WindowState> output, String name) {
        int objectId = 0;
        int objectId = 0;
        // See if this is an object ID.
        // See if this is an object ID.
        try {
        try {
@@ -231,7 +231,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> {
        getWindowsByName(output, name, objectId);
        getWindowsByName(output, name, objectId);
    }
    }


    private void getWindowsByName(WindowList output, String name, int objectId) {
    private void getWindowsByName(ArrayList<WindowState> output, String name, int objectId) {
        forAllWindows((w) -> {
        forAllWindows((w) -> {
            if (name != null) {
            if (name != null) {
                if (w.mAttrs.getTitle().toString().contains(name)) {
                if (w.mAttrs.getTitle().toString().contains(name)) {
@@ -276,15 +276,6 @@ class RootWindowContainer extends WindowContainer<DisplayContent> {
        return null;
        return null;
    }
    }


    // TODO: Users would have their own window containers under the display container?
    void switchUser() {
        final int count = mChildren.size();
        for (int i = 0; i < count; ++i) {
            final DisplayContent dc = mChildren.get(i);
            dc.switchUser();
        }
    }

    /**
    /**
     * Set new display override config and return array of ids of stacks that were changed during
     * Set new display override config and return array of ids of stacks that were changed during
     * update. If called for the default display, global configuration will also be updated.
     * update. If called for the default display, global configuration will also be updated.
@@ -429,14 +420,6 @@ class RootWindowContainer extends WindowContainer<DisplayContent> {
        return hasChanges;
        return hasChanges;
    }
    }


    void updateInputWindows(InputMonitor inputMonitor, WindowState inputFocus, boolean inDrag) {
        final int count = mChildren.size();
        for (int i = 0; i < count; ++i) {
            final DisplayContent dc = mChildren.get(i);
            dc.updateInputWindows(inputMonitor, inputFocus, inDrag);
        }
    }

    boolean reclaimSomeSurfaceMemory(WindowStateAnimator winAnimator, String operation,
    boolean reclaimSomeSurfaceMemory(WindowStateAnimator winAnimator, String operation,
            boolean secure) {
            boolean secure) {
        final WindowSurfaceController surfaceController = winAnimator.mSurfaceController;
        final WindowSurfaceController surfaceController = winAnimator.mSurfaceController;
Loading