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

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

Made WindowState.mChildWindow private scoped

This involved:
- Moving method that operated on mChildWindows and mostly touched
WindowState fields into WindowState class.
- Creating new methods for getting information about child windows
outside WindowState class instead of accessing the child list directly.
- And, tests ;)

Bug: 30060889
Change-Id: I339cecb926b44b5db7ead1970e356304d5429c8f
parent 9d14790d
Loading
Loading
Loading
Loading
+3 −26
Original line number Original line Diff line number Diff line
@@ -1206,33 +1206,10 @@ final class AccessibilityController {
                    (int) windowFrame.right, (int) windowFrame.bottom);
                    (int) windowFrame.right, (int) windowFrame.bottom);
        }
        }


        private static WindowInfo obtainPopulatedWindowInfo(WindowState windowState,
        private static WindowInfo obtainPopulatedWindowInfo(
                Rect boundsInScreen) {
                WindowState windowState, Rect boundsInScreen) {
            WindowInfo window = WindowInfo.obtain();
            final WindowInfo window = windowState.getWindowInfo();
            window.type = windowState.mAttrs.type;
            window.layer = windowState.mLayer;
            window.token = windowState.mClient.asBinder();
            window.title = windowState.mAttrs.accessibilityTitle;
            window.accessibilityIdOfAnchor = windowState.mAttrs.accessibilityIdOfAnchor;

            if (windowState.isChildWindow()) {
                window.parentToken = windowState.mParentWindow.mClient.asBinder();
            }

            window.focused = windowState.isFocused();
            window.boundsInScreen.set(boundsInScreen);
            window.boundsInScreen.set(boundsInScreen);

            final int childCount = windowState.mChildWindows.size();
            if (childCount > 0) {
                if (window.childTokens == null) {
                    window.childTokens = new ArrayList<IBinder>();
                }
                for (int j = 0; j < childCount; j++) {
                    WindowState child = windowState.mChildWindows.get(j);
                    window.childTokens.add(child.mClient.asBinder());
                }
            }

            return window;
            return window;
        }
        }


+1 −1
Original line number Original line Diff line number Diff line
@@ -424,7 +424,7 @@ public class AppWindowAnimator {


        final int numAllAppWinAnimators = mAllAppWinAnimators.size();
        final int numAllAppWinAnimators = mAllAppWinAnimators.size();
        for (int i = 0; i < numAllAppWinAnimators; i++) {
        for (int i = 0; i < numAllAppWinAnimators; i++) {
            mAllAppWinAnimators.get(i).finishExit();
            mAllAppWinAnimators.get(i).mWin.onExitAnimationDone();
        }
        }
        mService.mAppTransition.notifyAppTransitionFinishedLocked(mAppToken.token);
        mService.mAppTransition.notifyAppTransitionFinishedLocked(mAppToken.token);
        return false;
        return false;
+3 −3
Original line number Original line Diff line number Diff line
@@ -362,7 +362,7 @@ class AppWindowToken extends WindowToken {


            win.destroyOrSaveSurface();
            win.destroyOrSaveSurface();
            if (win.mRemoveOnExit) {
            if (win.mRemoveOnExit) {
                service.removeWindowInnerLocked(win);
                win.removeLocked();
            }
            }
            final DisplayContent displayContent = win.getDisplayContent();
            final DisplayContent displayContent = win.getDisplayContent();
            if (displayContent != null && !displayList.contains(displayContent)) {
            if (displayContent != null && !displayList.contains(displayContent)) {
@@ -680,10 +680,10 @@ class AppWindowToken extends WindowToken {
                candidate.mReplacingWindow.mSkipEnterAnimationForSeamlessReplacement = false;
                candidate.mReplacingWindow.mSkipEnterAnimationForSeamlessReplacement = false;
            }
            }
            // Since the window already timed out, remove it immediately now.
            // Since the window already timed out, remove it immediately now.
            // Use removeWindowInnerLocked() instead of removeWindowLocked(), as the latter
            // Use WindowState#removeLocked() instead of removeWindowLocked(), as the latter
            // delays removal on certain conditions, which will leave the stale window in the
            // delays removal on certain conditions, which will leave the stale window in the
            // stack and marked mWillReplaceWindow=false, so the window will never be removed.
            // stack and marked mWillReplaceWindow=false, so the window will never be removed.
            service.removeWindowInnerLocked(candidate);
            candidate.removeLocked();
        }
        }
    }
    }


+4 −9
Original line number Original line Diff line number Diff line
@@ -119,18 +119,13 @@ public class WindowLayersController {
        mInputMethodAnimLayerAdjustment = adj;
        mInputMethodAnimLayerAdjustment = adj;
        final WindowState imw = mService.mInputMethodWindow;
        final WindowState imw = mService.mInputMethodWindow;
        if (imw != null) {
        if (imw != null) {
            imw.mWinAnimator.mAnimLayer = imw.mLayer + adj;
            imw.adjustAnimLayer(adj);
            if (DEBUG_LAYERS) Slog.v(TAG_WM, "IM win " + imw
                    + " anim layer: " + imw.mWinAnimator.mAnimLayer);
            for (int i = imw.mChildWindows.size() - 1; i >= 0; i--) {
                final WindowState childWindow = imw.mChildWindows.get(i);
                childWindow.mWinAnimator.mAnimLayer = childWindow.mLayer + adj;
                if (DEBUG_LAYERS) Slog.v(TAG_WM, "IM win " + childWindow
                        + " anim layer: " + childWindow.mWinAnimator.mAnimLayer);
            }
        }
        }
        for (int i = mService.mInputMethodDialogs.size() - 1; i >= 0; i--) {
        for (int i = mService.mInputMethodDialogs.size() - 1; i >= 0; i--) {
            final WindowState dialog = mService.mInputMethodDialogs.get(i);
            final WindowState dialog = mService.mInputMethodDialogs.get(i);
            // TODO: This and other places setting mAnimLayer can probably use WS.adjustAnimLayer,
            // but need to make sure we are not setting things twice for child windows that are
            // already in the list.
            dialog.mWinAnimator.mAnimLayer = dialog.mLayer + adj;
            dialog.mWinAnimator.mAnimLayer = dialog.mLayer + adj;
            if (DEBUG_LAYERS) Slog.v(TAG_WM, "IM win " + imw
            if (DEBUG_LAYERS) Slog.v(TAG_WM, "IM win " + imw
                    + " anim layer: " + dialog.mWinAnimator.mAnimLayer);
                    + " anim layer: " + dialog.mWinAnimator.mAnimLayer);
+23 −115
Original line number Original line Diff line number Diff line
@@ -1146,14 +1146,9 @@ public class WindowManagerService extends IWindowManager.Stub
    private int indexOfWinInWindowList(WindowState targetWin, WindowList windows) {
    private int indexOfWinInWindowList(WindowState targetWin, WindowList windows) {
        for (int i = windows.size() - 1; i >= 0; i--) {
        for (int i = windows.size() - 1; i >= 0; i--) {
            final WindowState w = windows.get(i);
            final WindowState w = windows.get(i);
            if (w == targetWin) {
            if (w == targetWin || w.hasChild(targetWin)) {
                return i;
                return i;
            }
            }
            if (!w.mChildWindows.isEmpty()) {
                if (indexOfWinInWindowList(targetWin, w.mChildWindows) >= 0) {
                    return i;
                }
            }
        }
        }
        return -1;
        return -1;
    }
    }
@@ -1646,30 +1641,6 @@ public class WindowManagerService extends IWindowManager.Stub
        moveInputMethodDialogsLocked(pos);
        moveInputMethodDialogsLocked(pos);
    }
    }


    private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
        WindowList windows = win.getWindowList();
        int wpos = windows.indexOf(win);
        if (wpos >= 0) {
            if (wpos < interestingPos) interestingPos--;
            if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Temp removing at " + wpos + ": " + win);
            windows.remove(wpos);
            mWindowsChanged = true;
            int NC = win.mChildWindows.size();
            while (NC > 0) {
                NC--;
                WindowState cw = win.mChildWindows.get(NC);
                int cpos = windows.indexOf(cw);
                if (cpos >= 0) {
                    if (cpos < interestingPos) interestingPos--;
                    if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Temp removing child at "
                            + cpos + ": " + cw);
                    windows.remove(cpos);
                }
            }
        }
        return interestingPos;
    }

    private void reAddWindowToListInOrderLocked(WindowState win) {
    private void reAddWindowToListInOrderLocked(WindowState win) {
        addWindowToListInOrderLocked(win, false);
        addWindowToListInOrderLocked(win, false);
        // This is a hack to get all of the child windows added as well
        // This is a hack to get all of the child windows added as well
@@ -1681,7 +1652,7 @@ public class WindowManagerService extends IWindowManager.Stub
            if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "ReAdd removing from " + wpos + ": " + win);
            if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "ReAdd removing from " + wpos + ": " + win);
            windows.remove(wpos);
            windows.remove(wpos);
            mWindowsChanged = true;
            mWindowsChanged = true;
            reAddWindowLocked(wpos, win);
            win.reAddWindowLocked(wpos);
        }
        }
    }
    }


@@ -1701,7 +1672,7 @@ public class WindowManagerService extends IWindowManager.Stub
        final int N = dialogs.size();
        final int N = dialogs.size();
        if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Removing " + N + " dialogs w/pos=" + pos);
        if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Removing " + N + " dialogs w/pos=" + pos);
        for (int i=0; i<N; i++) {
        for (int i=0; i<N; i++) {
            pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
            pos = dialogs.get(i).removeFromWindowList(pos);
        }
        }
        if (DEBUG_INPUT_METHOD) {
        if (DEBUG_INPUT_METHOD) {
            Slog.v(TAG_WM, "Window list w/pos=" + pos);
            Slog.v(TAG_WM, "Window list w/pos=" + pos);
@@ -1725,7 +1696,7 @@ public class WindowManagerService extends IWindowManager.Stub
            for (int i=0; i<N; i++) {
            for (int i=0; i<N; i++) {
                WindowState win = dialogs.get(i);
                WindowState win = dialogs.get(i);
                win.mTargetAppToken = targetAppToken;
                win.mTargetAppToken = targetAppToken;
                pos = reAddWindowLocked(pos, win);
                pos = win.reAddWindowLocked(pos);
            }
            }
            if (DEBUG_INPUT_METHOD) {
            if (DEBUG_INPUT_METHOD) {
                Slog.v(TAG_WM, "Final window list:");
                Slog.v(TAG_WM, "Final window list:");
@@ -1762,16 +1733,14 @@ public class WindowManagerService extends IWindowManager.Stub
            // First check to see if the input method windows are already
            // First check to see if the input method windows are already
            // located here, and contiguous.
            // located here, and contiguous.
            final int N = windows.size();
            final int N = windows.size();
            WindowState firstImWin = imPos < N
            final WindowState firstImWin = imPos < N ? windows.get(imPos) : null;
                    ? windows.get(imPos) : null;


            // Figure out the actual input method window that should be
            // Figure out the actual input method window that should be
            // at the bottom of their stack.
            // at the bottom of their stack.
            WindowState baseImWin = imWin != null
            WindowState baseImWin = imWin != null ? imWin : mInputMethodDialogs.get(0);
                    ? imWin : mInputMethodDialogs.get(0);
            final WindowState cw = baseImWin.getBottomChild();
            if (baseImWin.mChildWindows.size() > 0) {
            if (cw != null && cw.mSubLayer < 0) {
                WindowState cw = baseImWin.mChildWindows.get(0);
                baseImWin = cw;
                if (cw.mSubLayer < 0) baseImWin = cw;
            }
            }


            if (firstImWin == baseImWin) {
            if (firstImWin == baseImWin) {
@@ -1807,13 +1776,13 @@ public class WindowManagerService extends IWindowManager.Stub
                    Slog.v(TAG_WM, "Moving IM from " + imPos);
                    Slog.v(TAG_WM, "Moving IM from " + imPos);
                    logWindowList(windows, "  ");
                    logWindowList(windows, "  ");
                }
                }
                imPos = tmpRemoveWindowLocked(imPos, imWin);
                imPos = imWin.removeFromWindowList(imPos);
                if (DEBUG_INPUT_METHOD) {
                if (DEBUG_INPUT_METHOD) {
                    Slog.v(TAG_WM, "List after removing with new pos " + imPos + ":");
                    Slog.v(TAG_WM, "List after removing with new pos " + imPos + ":");
                    logWindowList(windows, "  ");
                    logWindowList(windows, "  ");
                }
                }
                imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
                imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
                reAddWindowLocked(imPos, imWin);
                imWin.reAddWindowLocked(imPos);
                if (DEBUG_INPUT_METHOD) {
                if (DEBUG_INPUT_METHOD) {
                    Slog.v(TAG_WM, "List after moving IM to " + imPos + ":");
                    Slog.v(TAG_WM, "List after moving IM to " + imPos + ":");
                    logWindowList(windows, "  ");
                    logWindowList(windows, "  ");
@@ -1829,7 +1798,7 @@ public class WindowManagerService extends IWindowManager.Stub


            if (imWin != null) {
            if (imWin != null) {
                if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Moving IM from " + imPos);
                if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Moving IM from " + imPos);
                tmpRemoveWindowLocked(0, imWin);
                imWin.removeFromWindowList(0);
                imWin.mTargetAppToken = null;
                imWin.mTargetAppToken = null;
                reAddWindowToListInOrderLocked(imWin);
                reAddWindowToListInOrderLocked(imWin);
                if (DEBUG_INPUT_METHOD) {
                if (DEBUG_INPUT_METHOD) {
@@ -1850,7 +1819,7 @@ public class WindowManagerService extends IWindowManager.Stub
        return true;
        return true;
    }
    }


    private static boolean excludeWindowTypeFromTapOutTask(int windowType) {
    static boolean excludeWindowTypeFromTapOutTask(int windowType) {
        switch (windowType) {
        switch (windowType) {
            case TYPE_STATUS_BAR:
            case TYPE_STATUS_BAR:
            case TYPE_NAVIGATION_BAR:
            case TYPE_NAVIGATION_BAR:
@@ -2454,7 +2423,7 @@ public class WindowManagerService extends IWindowManager.Stub
            }
            }
        }
        }


        removeWindowInnerLocked(win);
        win.removeLocked();
        // Removing a visible window will effect the computed orientation
        // Removing a visible window will effect the computed orientation
        // So just update orientation if needed.
        // So just update orientation if needed.
        if (wasVisible && updateOrientationFromAppTokensLocked(false)) {
        if (wasVisible && updateOrientationFromAppTokensLocked(false)) {
@@ -2464,41 +2433,12 @@ public class WindowManagerService extends IWindowManager.Stub
        Binder.restoreCallingIdentity(origId);
        Binder.restoreCallingIdentity(origId);
    }
    }


    void removeWindowInnerLocked(WindowState win) {
    /**
        if (win.mRemoved) {
     * Performs some centralized bookkeeping clean-up on the window that is being removed.
            // Nothing to do.
     * NOTE: Should only be called from {@link WindowState#removeLocked()}
            if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
     */
                    "removeWindowInnerLocked: " + win + " Already removed...");
    void postWindowRemoveCleanupLocked(WindowState win) {
            return;
        if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM, "postWindowRemoveCleanupLocked: " + win);
        }

        for (int i = win.mChildWindows.size() - 1; i >= 0; i--) {
            WindowState cwin = win.mChildWindows.get(i);
            Slog.w(TAG_WM, "Force-removing child win " + cwin + " from container " + win);
            removeWindowInnerLocked(cwin);
        }

        win.mRemoved = true;

        if (mInputMethodTarget == win) {
            moveInputMethodWindowsIfNeededLocked(false);
        }

        if (false) {
            RuntimeException e = new RuntimeException("here");
            e.fillInStackTrace();
            Slog.w(TAG_WM, "Removing window " + win, e);
        }

        final int type = win.mAttrs.type;
        if (excludeWindowTypeFromTapOutTask(type)) {
            final DisplayContent displaycontent = win.getDisplayContent();
            displaycontent.mTapExcludedWindows.remove(win);
        }
        mPolicy.removeWindowLw(win);
        win.removeLocked();

        if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM, "removeWindowInnerLocked: " + win);
        mWindowMap.remove(win.mClient.asBinder());
        mWindowMap.remove(win.mClient.asBinder());
        if (win.mAppOp != AppOpsManager.OP_NONE) {
        if (win.mAppOp != AppOpsManager.OP_NONE) {
            mAppOps.finishOp(win.mAppOp, win.getOwningUid(), win.getOwningPackage());
            mAppOps.finishOp(win.mAppOp, win.getOwningUid(), win.getOwningPackage());
@@ -2551,7 +2491,7 @@ public class WindowManagerService extends IWindowManager.Stub
            }
            }
        }
        }


        if (type == TYPE_WALLPAPER) {
        if (win.mAttrs.type == TYPE_WALLPAPER) {
            mWallpaperControllerLocked.clearLastWallpaperTimeoutTime();
            mWallpaperControllerLocked.clearLastWallpaperTimeoutTime();
            getDefaultDisplayContentLocked().pendingLayoutChanges |=
            getDefaultDisplayContentLocked().pendingLayoutChanges |=
                    WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
                    WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
@@ -4377,7 +4317,7 @@ public class WindowManagerService extends IWindowManager.Stub
                WindowState win = wtoken.allAppWindows.get(i);
                WindowState win = wtoken.allAppWindows.get(i);
                if (win == wtoken.startingWindow) {
                if (win == wtoken.startingWindow) {
                    // Starting window that's exiting will be removed when the animation
                    // Starting window that's exiting will be removed when the animation
                    // finishes. Mark all relevant flags for that finishExit will proceed
                    // finishes. Mark all relevant flags for that onExitAnimationDone will proceed
                    // all the way to actually remove it.
                    // all the way to actually remove it.
                    if (!visible && win.isVisibleNow() && wtoken.mAppAnimator.isAnimating()) {
                    if (!visible && win.isVisibleNow() && wtoken.mAppAnimator.isAnimating()) {
                        win.mAnimatingExit = true;
                        win.mAnimatingExit = true;
@@ -4865,38 +4805,6 @@ public class WindowManagerService extends IWindowManager.Stub
        }
        }
    }
    }


    private final int reAddWindowLocked(int index, WindowState win) {
        final WindowList windows = win.getWindowList();
        // Adding child windows relies on mChildWindows being ordered by mSubLayer.
        final int NCW = win.mChildWindows.size();
        boolean winAdded = false;
        for (int j=0; j<NCW; j++) {
            WindowState cwin = win.mChildWindows.get(j);
            if (!winAdded && cwin.mSubLayer >= 0) {
                if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Re-adding child window at "
                        + index + ": " + cwin);
                win.mRebuilding = false;
                windows.add(index, win);
                index++;
                winAdded = true;
            }
            if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Re-adding window at "
                    + index + ": " + cwin);
            cwin.mRebuilding = false;
            windows.add(index, cwin);
            index++;
        }
        if (!winAdded) {
            if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Re-adding window at "
                    + index + ": " + win);
            win.mRebuilding = false;
            windows.add(index, win);
            index++;
        }
        mWindowsChanged = true;
        return index;
    }

    private final int reAddAppWindowsLocked(final DisplayContent displayContent, int index,
    private final int reAddAppWindowsLocked(final DisplayContent displayContent, int index,
                                            WindowToken token) {
                                            WindowToken token) {
        final int NW = token.windows.size();
        final int NW = token.windows.size();
@@ -4905,7 +4813,7 @@ public class WindowManagerService extends IWindowManager.Stub
            final DisplayContent winDisplayContent = win.getDisplayContent();
            final DisplayContent winDisplayContent = win.getDisplayContent();
            if (winDisplayContent == displayContent || winDisplayContent == null) {
            if (winDisplayContent == displayContent || winDisplayContent == null) {
                win.mDisplayContent = displayContent;
                win.mDisplayContent = displayContent;
                index = reAddWindowLocked(index, win);
                index = win.reAddWindowLocked(index);
            }
            }
        }
        }
        return index;
        return index;
Loading