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

Commit 0303c572 authored by Wale Ogunwale's avatar Wale Ogunwale
Browse files

Have DisplayContent be the call point for adjusting wallpaper windows

4th step in trying to make the WindowList private to DisplayContent
Have the rest of the system call DisplayContent when they need to
adjust the position of the wallpaper windows in the window list
instead of calling WallpaperController directly. That way the display
content can control the window list that the wallpaper controller sees.

Test: Existing tests pass and manual testing.
Change-Id: Iaa7f421d7cd24d36e5a83e091f77b4a08d0ae123
parent 824ab5c4
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -202,6 +202,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
    private boolean mRemovingDisplay = false;

    private final WindowLayersController mLayersController;
    final WallpaperController mWallpaperController;
    int mInputMethodAnimLayerAdjustment;

    /**
@@ -209,12 +210,15 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
     * @param service You know.
     * @param layersController window layer controller used to assign layer to the windows on this
     *                         display.
     * @param wallpaperController wallpaper windows controller used to adjust the positioning of the
     *                            wallpaper windows in the window list.
     */
    DisplayContent(Display display, WindowManagerService service,
            WindowLayersController layersController) {
            WindowLayersController layersController, WallpaperController wallpaperController) {
        mDisplay = display;
        mDisplayId = display.getDisplayId();
        mLayersController = layersController;
        mWallpaperController = wallpaperController;
        display.getDisplayInfo(mDisplayInfo);
        display.getMetrics(mDisplayMetrics);
        isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
@@ -1226,6 +1230,12 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        }
    }

    void adjustWallpaperWindows() {
        if (mWallpaperController.adjustWallpaperWindows(mWindows)) {
            assignWindowLayers(true /*setLayoutNeeded*/);
        }
    }

    /**
     * Z-orders the display window list so that:
     * <ul>
@@ -1888,7 +1898,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        boolean startingInUnForceHiding = false;
        ArrayList<WindowStateAnimator> unForceHiding = null;
        WindowState wallpaper = null;
        final WallpaperController wallpaperController = mService.mWallpaperControllerLocked;
        final WallpaperController wallpaperController = mWallpaperController;
        for (int i = mWindows.size() - 1; i >= 0; i--) {
            WindowState win = mWindows.get(i);
            WindowStateAnimator winAnimator = win.mWinAnimator;
+15 −15
Original line number Diff line number Diff line
@@ -166,10 +166,12 @@ class RootWindowContainer extends WindowContainer<DisplayContent> {
    RemoteEventTrace mRemoteEventTrace;

    private final WindowLayersController mLayersController;
    final WallpaperController mWallpaperController;

    RootWindowContainer(WindowManagerService service) {
        mService = service;
        mLayersController = new WindowLayersController(mService);
        mWallpaperController = new WallpaperController(mService);
    }

    WindowState computeFocusedWindow() {
@@ -214,7 +216,8 @@ class RootWindowContainer extends WindowContainer<DisplayContent> {
    }

    private DisplayContent createDisplayContent(final Display display) {
        final DisplayContent dc = new DisplayContent(display, mService, mLayersController);
        final DisplayContent dc = new DisplayContent(display, mService, mLayersController,
                mWallpaperController);
        final int displayId = display.getDisplayId();

        if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Adding display=" + display);
@@ -442,10 +445,10 @@ class RootWindowContainer extends WindowContainer<DisplayContent> {

        // TODO(multi-display): By default we add this to the default display, but maybe we
        // should provide an API for a token to be added to any display?
        final WindowToken token = new WindowToken(mService, binder, type, true,
                getDisplayContent(DEFAULT_DISPLAY));
        final DisplayContent dc = getDisplayContent(DEFAULT_DISPLAY);
        final WindowToken token = new WindowToken(mService, binder, type, true, dc);
        if (type == TYPE_WALLPAPER) {
            mService.mWallpaperControllerLocked.addWallpaperToken(token);
            dc.mWallpaperController.addWallpaperToken(token);
        }
    }

@@ -718,7 +721,6 @@ class RootWindowContainer extends WindowContainer<DisplayContent> {
        boolean addPipInputConsumerHandle = pipInputConsumer != null;
        boolean addWallpaperInputConsumerHandle = wallpaperInputConsumer != null;
        final Rect pipTouchableBounds = addPipInputConsumerHandle ? new Rect() : null;
        final WallpaperController wallpaperController = mService.mWallpaperControllerLocked;
        boolean disableWallpaperTouchEvents = false;

        final int count = mChildren.size();
@@ -769,7 +771,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> {
                if ((privateFlags & PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS) != 0) {
                    disableWallpaperTouchEvents = true;
                }
                final boolean hasWallpaper = wallpaperController.isWallpaperTarget(child)
                final boolean hasWallpaper = dc.mWallpaperController.isWallpaperTarget(child)
                        && (privateFlags & PRIVATE_FLAG_KEYGUARD) == 0
                        && !disableWallpaperTouchEvents;

@@ -951,14 +953,13 @@ class RootWindowContainer extends WindowContainer<DisplayContent> {
                    "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
        }

        final WindowList defaultWindows = defaultDisplay.getWindowList();
        final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;

        // If we are ready to perform an app transition, check through all of the app tokens to be
        // shown and see if they are ready to go.
        if (mService.mAppTransition.isReady()) {
            defaultDisplay.pendingLayoutChanges |=
                    surfacePlacer.handleAppTransitionReadyLocked(defaultWindows);
                    surfacePlacer.handleAppTransitionReadyLocked();
            if (DEBUG_LAYOUT_REPEATS)
                surfacePlacer.debugLayoutRepeats("after handleAppTransitionReadyLocked",
                        defaultDisplay.pendingLayoutChanges);
@@ -1046,7 +1047,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> {
                if (mService.mInputMethodWindow == win) {
                    mService.mInputMethodWindow = null;
                }
                if (mService.mWallpaperControllerLocked.isWallpaperTarget(win)) {
                if (win.getDisplayContent().mWallpaperController.isWallpaperTarget(win)) {
                    wallpaperDestroyed = true;
                }
                win.destroyOrSaveSurface();
@@ -1063,7 +1064,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> {
                if (!token.hasVisible) {
                    exitingTokens.remove(i);
                    if (token.windowType == TYPE_WALLPAPER) {
                        mService.mWallpaperControllerLocked.removeWallpaperToken(token);
                        displayContent.mWallpaperController.removeWallpaperToken(token);
                    }
                }
            }
@@ -1251,9 +1252,8 @@ class RootWindowContainer extends WindowContainer<DisplayContent> {
                if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
                        "On entry to LockedInner", dc.pendingLayoutChanges);

                if ((dc.pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0
                        && mService.mWallpaperControllerLocked.adjustWallpaperWindows()) {
                    dc.assignWindowLayers(true /*setLayoutNeeded*/);
                if ((dc.pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
                    dc.adjustWallpaperWindows();
                }

                if (isDefaultDisplay
@@ -1318,10 +1318,10 @@ class RootWindowContainer extends WindowContainer<DisplayContent> {
                w.applyDimLayerIfNeeded();

                if (isDefaultDisplay && obscuredChanged && w.isVisibleLw()
                        && mService.mWallpaperControllerLocked.isWallpaperTarget(w)) {
                        && dc.mWallpaperController.isWallpaperTarget(w)) {
                    // This is the wallpaper target and its obscured state changed... make sure the
                    // current wallpaper's visibility has been updated accordingly.
                    mService.mWallpaperControllerLocked.updateWallpaperVisibility();
                    dc.mWallpaperController.updateWallpaperVisibility();
                }

                w.handleWindowMovedIfNeeded();
+5 −5
Original line number Diff line number Diff line
@@ -460,7 +460,7 @@ public class Session extends IWindowSession.Stub
        synchronized(mService.mWindowMap) {
            long ident = Binder.clearCallingIdentity();
            try {
                mService.mWallpaperControllerLocked.setWindowWallpaperPosition(
                mService.mRoot.mWallpaperController.setWindowWallpaperPosition(
                        mService.windowForClientLocked(this, window, true),
                        x, y, xStep, yStep);
            } finally {
@@ -471,7 +471,7 @@ public class Session extends IWindowSession.Stub

    public void wallpaperOffsetsComplete(IBinder window) {
        synchronized (mService.mWindowMap) {
            mService.mWallpaperControllerLocked.wallpaperOffsetsComplete(window);
            mService.mRoot.mWallpaperController.wallpaperOffsetsComplete(window);
        }
    }

@@ -479,7 +479,7 @@ public class Session extends IWindowSession.Stub
        synchronized(mService.mWindowMap) {
            long ident = Binder.clearCallingIdentity();
            try {
                mService.mWallpaperControllerLocked.setWindowWallpaperDisplayOffset(
                mService.mRoot.mWallpaperController.setWindowWallpaperDisplayOffset(
                        mService.windowForClientLocked(this, window, true), x, y);
            } finally {
                Binder.restoreCallingIdentity(ident);
@@ -492,7 +492,7 @@ public class Session extends IWindowSession.Stub
        synchronized(mService.mWindowMap) {
            long ident = Binder.clearCallingIdentity();
            try {
                return mService.mWallpaperControllerLocked.sendWindowWallpaperCommand(
                return mService.mRoot.mWallpaperController.sendWindowWallpaperCommand(
                        mService.windowForClientLocked(this, window, true),
                        action, x, y, z, extras, sync);
            } finally {
@@ -503,7 +503,7 @@ public class Session extends IWindowSession.Stub

    public void wallpaperCommandComplete(IBinder window, Bundle result) {
        synchronized (mService.mWindowMap) {
            mService.mWallpaperControllerLocked.wallpaperCommandComplete(window);
            mService.mRoot.mWallpaperController.wallpaperCommandComplete(window);
        }
    }

+5 −6
Original line number Diff line number Diff line
@@ -628,10 +628,9 @@ class WallpaperController {
        return changed;
    }

    boolean adjustWallpaperWindows() {
    boolean adjustWallpaperWindows(WindowList windows) {
        mService.mRoot.mWallpaperMayChange = false;

        final WindowList windows = mService.getDefaultWindowListLocked();
        // First find top-most window that has asked to be on top of the wallpaper;
        // all wallpapers go behind it.
        findWallpaperTarget(windows, mFindResults);
@@ -726,8 +725,8 @@ class WallpaperController {
     * Adjusts the wallpaper windows if the input display has a pending wallpaper layout or one of
     * the opening apps should be a wallpaper target.
     */
    void adjustWallpaperWindowsForAppTransitionIfNeeded(
            DisplayContent dc, ArraySet<AppWindowToken> openingApps, WindowList windows) {
    void adjustWallpaperWindowsForAppTransitionIfNeeded(DisplayContent dc,
            ArraySet<AppWindowToken> openingApps) {
        boolean adjust = false;
        if ((dc.pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
            adjust = true;
@@ -741,8 +740,8 @@ class WallpaperController {
            }
        }

        if (adjust && adjustWallpaperWindows()) {
            dc.assignWindowLayers(true /*setLayoutNeeded*/);
        if (adjust) {
            dc.adjustWallpaperWindows();
        }
    }

+17 −18
Original line number Diff line number Diff line
@@ -684,8 +684,6 @@ public class WindowManagerService extends IWindowManager.Stub
        }
    }

    WallpaperController mWallpaperControllerLocked;

    boolean mAnimateWallpaperWithTarget;

    // TODO: Move to RootWindowContainer
@@ -979,7 +977,6 @@ public class WindowManagerService extends IWindowManager.Stub
        mDisplaySettings = new DisplaySettings();
        mDisplaySettings.readSettingsLocked();

        mWallpaperControllerLocked = new WallpaperController(this);
        mWindowPlacerLocked = new WindowSurfacePlacer(this);
        mPolicy = policy;

@@ -1397,11 +1394,11 @@ public class WindowManagerService extends IWindowManager.Stub
            } else {
                win.mToken.addWindow(win);
                if (type == TYPE_WALLPAPER) {
                    mWallpaperControllerLocked.clearLastWallpaperTimeoutTime();
                    displayContent.mWallpaperController.clearLastWallpaperTimeoutTime();
                    displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
                } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
                    displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
                } else if (mWallpaperControllerLocked.isBelowWallpaperTarget(win)) {
                } else if (displayContent.mWallpaperController.isBelowWallpaperTarget(win)) {
                    // If there is currently a wallpaper being shown, and
                    // the base layer of the new window is below the current
                    // layer of the target window, then adjust the wallpaper.
@@ -1675,14 +1672,14 @@ public class WindowManagerService extends IWindowManager.Stub
            atoken.postWindowRemoveStartingWindowCleanup(win);
        }

        final DisplayContent dc = win.getDisplayContent();
        if (win.mAttrs.type == TYPE_WALLPAPER) {
            mWallpaperControllerLocked.clearLastWallpaperTimeoutTime();
            getDefaultDisplayContentLocked().pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
            dc.mWallpaperController.clearLastWallpaperTimeoutTime();
            dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
        } else if ((win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
            getDefaultDisplayContentLocked().pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
            dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
        }

        final DisplayContent dc = win.getDisplayContent();
        if (dc != null && dc.removeFromWindowList(win)) {
            if (!mWindowPlacerLocked.isInLayout()) {
                dc.assignWindowLayers(true /* setLayoutNeeded */);
@@ -2079,7 +2076,7 @@ public class WindowManagerService extends IWindowManager.Stub
            mWindowPlacerLocked.performSurfacePlacement();
            if (toBeDisplayed && win.mIsWallpaper) {
                DisplayInfo displayInfo = getDefaultDisplayInfoLocked();
                mWallpaperControllerLocked.updateWallpaperOffset(
                dc.mWallpaperController.updateWallpaperOffset(
                        win, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
            }
            if (win.mAppToken != null) {
@@ -2147,7 +2144,7 @@ public class WindowManagerService extends IWindowManager.Stub
            // an exit.
            win.mAnimatingExit = true;
            win.mWinAnimator.mAnimating = true;
        } else if (mWallpaperControllerLocked.isWallpaperTarget(win)) {
        } else if (win.getDisplayContent().mWallpaperController.isWallpaperTarget(win)) {
            // If the wallpaper is currently behind this
            // window, we need to change both of them inside
            // of a transaction to avoid artifacts.
@@ -2418,7 +2415,7 @@ public class WindowManagerService extends IWindowManager.Stub
                    final WindowToken wtoken = removedTokens.get(i);
                    wtoken.setExiting();
                    if (wtoken.windowType == TYPE_WALLPAPER) {
                        mWallpaperControllerLocked.removeWallpaperToken(wtoken);
                        wtoken.getDisplayContent().mWallpaperController.removeWallpaperToken(wtoken);
                    }

                    mInputMonitor.updateInputWindowsLw(true /*force*/);
@@ -3035,7 +3032,8 @@ public class WindowManagerService extends IWindowManager.Stub
                    return false;
                }
                if (windowShowWallpaper) {
                    if (mWallpaperControllerLocked.getWallpaperTarget() == null) {
                    if (wtoken.getDisplayContent().mWallpaperController.getWallpaperTarget()
                            == null) {
                        // If this theme is requesting a wallpaper, and the wallpaper
                        // is not currently visible, then this effectively serves as
                        // an opaque window and our starting window transition animation
@@ -7004,7 +7002,7 @@ public class WindowManagerService extends IWindowManager.Stub
                break;
                case WALLPAPER_DRAW_PENDING_TIMEOUT: {
                    synchronized (mWindowMap) {
                        if (mWallpaperControllerLocked.processWallpaperDrawPendingTimeout()) {
                        if (mRoot.mWallpaperController.processWallpaperDrawPendingTimeout()) {
                            mWindowPlacerLocked.performSurfacePlacement();
                        }
                    }
@@ -7628,10 +7626,11 @@ public class WindowManagerService extends IWindowManager.Stub
        }
        mNoAnimationNotifyOnTransitionFinished.clear();

        mWallpaperControllerLocked.hideDeferredWallpapersIfNeeded();

        // TODO: multi-display.
        final DisplayContent dc = getDefaultDisplayContentLocked();

        dc.mWallpaperController.hideDeferredWallpapersIfNeeded();

        dc.onAppTransitionDone();

        changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
@@ -8229,7 +8228,7 @@ public class WindowManagerService extends IWindowManager.Stub
    private void dumpTokensLocked(PrintWriter pw, boolean dumpAll) {
        pw.println("WINDOW MANAGER TOKENS (dumpsys window tokens)");
        mRoot.dumpTokens(pw, dumpAll);
        mWallpaperControllerLocked.dumpTokens(pw, "  ", dumpAll);
        mRoot.mWallpaperController.dumpTokens(pw, "  ", dumpAll);
        if (!mFinishedStarting.isEmpty()) {
            pw.println();
            pw.println("  Finishing start of application tokens:");
@@ -8413,7 +8412,7 @@ public class WindowManagerService extends IWindowManager.Stub
                pw.print("  mInputMethodWindow="); pw.println(mInputMethodWindow);
            }
            mWindowPlacerLocked.dump(pw, "  ");
            mWallpaperControllerLocked.dump(pw, "  ");
            mRoot.mWallpaperController.dump(pw, "  ");
            pw.print("  mSystemBooted="); pw.print(mSystemBooted);
                    pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);

Loading