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

Commit c32538e6 authored by wilsonshih's avatar wilsonshih
Browse files

Support wallpaper on secondary displays.(2/N)

Modify wm struct to let DisplayContent has its own WallpaperController.
The wallpaper target would be decided for each display.
Remove SET_WALLPAPER_MAY_CHANGE flag from WindowSurfacePlacer, its not
used anymore.

Bug: 115486823
Bug: 118645630
Bug: 118662630
Test: Manual test with Chromecast.
Test: atest WallpaperControllerTests
Test: atest WmTests
Test: atest ActivityManagerMultiDisplayTests

Change-Id: I5ec1320ff0500ce3f7b9429a594bc44b7267cc5f
parent de93f49a
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -51,7 +51,6 @@ import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
import static com.android.server.wm.WindowManagerService.H.NOTIFY_APP_TRANSITION_STARTING;

import android.app.WindowConfiguration;
import android.os.Trace;
import android.util.ArraySet;
import android.util.Slog;
@@ -83,7 +82,7 @@ public class AppTransitionController {
    AppTransitionController(WindowManagerService service, DisplayContent displayContent) {
        mService = service;
        mDisplayContent = displayContent;
        mWallpaperControllerLocked = new WallpaperController(mService);
        mWallpaperControllerLocked = mDisplayContent.mWallpaperController;
    }

    /**
@@ -106,7 +105,7 @@ public class AppTransitionController {

        mDisplayContent.mAppTransition.removeAppTransitionTimeoutCallbacks();

        mService.mRoot.mWallpaperMayChange = false;
        mDisplayContent.mWallpaperMayChange = false;

        int i;
        for (i = 0; i < appsCount; i++) {
@@ -121,7 +120,7 @@ public class AppTransitionController {
        // Adjust wallpaper before we pull the lower/upper target, since pending changes
        // (like the clearAnimatingFlags() above) might affect wallpaper target result.
        // Or, the opening app window should be a wallpaper target.
        mWallpaperControllerLocked.adjustWallpaperWindowsForAppTransitionIfNeeded(mDisplayContent,
        mWallpaperControllerLocked.adjustWallpaperWindowsForAppTransitionIfNeeded(
                mDisplayContent.mOpeningApps);

        // Determine if closing and opening app token sets are wallpaper targets, in which case
+13 −14
Original line number Diff line number Diff line
@@ -414,6 +414,8 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo

    WallpaperController mWallpaperController;

    boolean mWallpaperMayChange = false;

    private final SurfaceSession mSession = new SurfaceSession();

    /**
@@ -751,8 +753,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
            }
        }

        if (isDefaultDisplay && obscuredChanged && w.isVisibleLw()
                && mWallpaperController.isWallpaperTarget(w)) {
        if (obscuredChanged && w.isVisibleLw() && mWallpaperController.isWallpaperTarget(w)) {
            // This is the wallpaper target and its obscured state changed... make sure the
            // current wallpaper's visibility has been updated accordingly.
            mWallpaperController.updateWallpaperVisibility();
@@ -784,7 +785,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
                if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
                    if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
                            "First draw done in potential wallpaper target " + w);
                    root.mWallpaperMayChange = true;
                    mWallpaperMayChange = true;
                    pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
                    if (DEBUG_LAYOUT_REPEATS) {
                        surfacePlacer.debugLayoutRepeats(
@@ -816,11 +817,10 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
     * initialize direct children.
     * @param display May not be null.
     * @param service You know.
     * @param wallpaperController wallpaper windows controller used to adjust the positioning of the
     *                            wallpaper windows in the window list.
     * @param controller The controller for the display container.
     */
    DisplayContent(Display display, WindowManagerService service,
            WallpaperController wallpaperController, DisplayWindowController controller) {
            DisplayWindowController controller) {
        super(service);
        setController(controller);
        if (service.mRoot.getDisplayContent(display.getDisplayId()) != null) {
@@ -831,7 +831,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo

        mDisplay = display;
        mDisplayId = display.getDisplayId();
        mWallpaperController = wallpaperController;
        mWallpaperController = new WallpaperController(mService, this);
        display.getDisplayInfo(mDisplayInfo);
        display.getMetrics(mDisplayMetrics);
        isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
@@ -2660,6 +2660,9 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        }
        pw.print("  mFocusedApp="); pw.println(mFocusedApp);

        pw.println();
        mWallpaperController.dump(pw, "  ");

        pw.println();
        pw.println(prefix + "Application tokens in top down Z order:");
        for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
@@ -3388,12 +3391,8 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
            if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner",
                    pendingLayoutChanges);

            // TODO(multi-display): For now adjusting wallpaper only on primary display to avoid
            // the wallpaper window jumping across displays.
            // Remove check for default display when there will be support for multiple wallpaper
            // targets (on different displays).
            if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
                mWallpaperController.adjustWallpaperWindows(this);
            if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
                mWallpaperController.adjustWallpaperWindows();
            }

            if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
@@ -4673,7 +4672,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
            Slog.v(TAG_WM, "Wallpaper layer changed: assigning layers + relayout");
        }
        computeImeTarget(true /* updateImeTarget */);
        mService.mRoot.mWallpaperMayChange = true;
        mWallpaperMayChange = true;
        // Since the window list has been rebuilt, focus might have to be recomputed since the
        // actual order of windows might have changed again.
        mService.mFocusMayChange = true;
+4 −7
Original line number Diff line number Diff line
@@ -40,14 +40,11 @@ import android.os.UserHandle;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Slog;
import android.view.InputApplicationHandle;
import android.view.InputChannel;
import android.view.InputEventReceiver;
import android.view.KeyEvent;
import android.view.WindowManager;
import android.view.InputApplicationHandle;
import android.view.InputWindowHandle;

import com.android.server.input.InputManagerService;
import com.android.server.policy.WindowManagerPolicy;

import java.io.PrintWriter;
@@ -401,10 +398,10 @@ final class InputMonitor {
            mTmpRect.setEmpty();
            mDisableWallpaperTouchEvents = false;
            this.inDrag = inDrag;
            wallpaperController = mService.mRoot.mWallpaperController;
            final DisplayContent dc = mService.mRoot.getDisplayContent(mDisplayId);
            wallpaperController = dc.mWallpaperController;

            mService.mRoot.getDisplayContent(mDisplayId).forAllWindows(this,
                    true /* traverseTopToBottom */);
            dc.forAllWindows(this, true /* traverseTopToBottom */);
            if (mAddWallpaperInputConsumerHandle) {
                // No visible wallpaper found, add the wallpaper input consumer at the end.
                addInputWindowHandle(wallpaperInputConsumer.mWindowHandle);
+13 −24
Original line number Diff line number Diff line
@@ -51,7 +51,6 @@ import static com.android.server.wm.WindowManagerService.logSurface;
import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE;
import static com.android.server.wm.WindowSurfacePlacer.SET_UPDATE_ROTATION;
import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_ACTION_PENDING;
import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE;

import android.annotation.CallSuper;
import android.annotation.NonNull;
@@ -106,7 +105,6 @@ class RootWindowContainer extends WindowContainer<DisplayContent> {
    private boolean mSustainedPerformanceModeEnabled = false;
    private boolean mSustainedPerformanceModeCurrent = false;

    boolean mWallpaperMayChange = false;
    // During an orientation change, we track whether all windows have rendered
    // at the new orientation, and this will be false from changing orientation until that occurs.
    // For seamless rotation cases this always stays true, as the windows complete their orientation
@@ -114,8 +112,6 @@ class RootWindowContainer extends WindowContainer<DisplayContent> {
    boolean mOrientationChangeComplete = true;
    boolean mWallpaperActionPending = false;

    final WallpaperController mWallpaperController;

    private final Handler mHandler;

    private String mCloseSystemDialogsReason;
@@ -150,7 +146,6 @@ class RootWindowContainer extends WindowContainer<DisplayContent> {
    RootWindowContainer(WindowManagerService service) {
        super(service);
        mHandler = new MyHandler(service.mH.getLooper());
        mWallpaperController = new WallpaperController(mService);
    }

    boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) {
@@ -236,8 +231,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> {
            return existing;
        }

        final DisplayContent dc =
                new DisplayContent(display, mService, mWallpaperController, controller);
        final DisplayContent dc = new DisplayContent(display, mService, controller);

        if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Adding display=" + display);

@@ -579,14 +573,19 @@ class RootWindowContainer extends WindowContainer<DisplayContent> {
        final RecentsAnimationController recentsAnimationController =
                mService.getRecentsAnimationController();
        if (recentsAnimationController != null) {
            recentsAnimationController.checkAnimationReady(mWallpaperController);
            recentsAnimationController.checkAnimationReady(defaultDisplay.mWallpaperController);
        }

        if (mWallpaperMayChange) {
        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
            final DisplayContent displayContent = mChildren.get(displayNdx);
            if (displayContent.mWallpaperMayChange) {
                if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "Wallpaper may change!  Adjusting");
            defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
            if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("WallpaperMayChange",
                    defaultDisplay.pendingLayoutChanges);
                displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
                if (DEBUG_LAYOUT_REPEATS) {
                    surfacePlacer.debugLayoutRepeats("WallpaperMayChange",
                            displayContent.pendingLayoutChanges);
                }
            }
        }

        if (mService.mFocusMayChange) {
@@ -617,7 +616,6 @@ class RootWindowContainer extends WindowContainer<DisplayContent> {
        }

        // Destroy the surface of any windows that are no longer visible.
        boolean wallpaperDestroyed = false;
        i = mService.mDestroySurface.size();
        if (i > 0) {
            do {
@@ -629,7 +627,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> {
                    displayContent.setInputMethodWindowLocked(null);
                }
                if (displayContent.mWallpaperController.isWallpaperTarget(win)) {
                    wallpaperDestroyed = true;
                    displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
                }
                win.destroySurfaceUnchecked();
                win.mWinAnimator.destroyPreservedSurfaceLocked();
@@ -643,11 +641,6 @@ class RootWindowContainer extends WindowContainer<DisplayContent> {
            displayContent.removeExistingTokensIfPossible();
        }

        if (wallpaperDestroyed) {
            defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
            defaultDisplay.setLayoutNeeded();
        }

        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
            final DisplayContent displayContent = mChildren.get(displayNdx);
            if (displayContent.pendingLayoutChanges != 0) {
@@ -905,10 +898,6 @@ class RootWindowContainer extends WindowContainer<DisplayContent> {
            mUpdateRotation = true;
            doRequest = true;
        }
        if ((bulkUpdateParams & SET_WALLPAPER_MAY_CHANGE) != 0) {
            mWallpaperMayChange = true;
            doRequest = true;
        }
        if ((bulkUpdateParams & SET_ORIENTATION_CHANGE_COMPLETE) == 0) {
            mOrientationChangeComplete = false;
        } else {
+18 −12
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;

import android.content.ClipData;
import android.content.Context;
import android.graphics.Rect;
import android.graphics.Region;
import android.os.Binder;
@@ -42,7 +41,6 @@ import android.os.Trace;
import android.os.UserHandle;
import android.util.MergedConfiguration;
import android.util.Slog;
import android.view.Display;
import android.view.DisplayCutout;
import android.view.IWindow;
import android.view.IWindowId;
@@ -60,6 +58,7 @@ import com.android.server.wm.WindowManagerService.H;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Set;
import java.util.function.BiConsumer;

/**
 * This class represents an active client session.  There is generally one
@@ -315,14 +314,19 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
        }
    }

    private void actionOnWallpaper(IBinder window,
            BiConsumer<WallpaperController, WindowState> action) {
        final WindowState windowState = mService.windowForClientLocked(this, window, true);
        action.accept(windowState.getDisplayContent().mWallpaperController, windowState);
    }

    @Override
    public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
        synchronized (mService.mGlobalLock) {
            long ident = Binder.clearCallingIdentity();
            try {
                mService.mRoot.mWallpaperController.setWindowWallpaperPosition(
                        mService.windowForClientLocked(this, window, true),
                        x, y, xStep, yStep);
                actionOnWallpaper(window, (wpController, windowState) ->
                        wpController.setWindowWallpaperPosition(windowState, x, y, xStep, yStep));
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
@@ -332,7 +336,8 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
    @Override
    public void wallpaperOffsetsComplete(IBinder window) {
        synchronized (mService.mGlobalLock) {
            mService.mRoot.mWallpaperController.wallpaperOffsetsComplete(window);
            actionOnWallpaper(window, (wpController, windowState) ->
                    wpController.wallpaperOffsetsComplete(window));
        }
    }

@@ -341,8 +346,8 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
        synchronized (mService.mGlobalLock) {
            long ident = Binder.clearCallingIdentity();
            try {
                mService.mRoot.mWallpaperController.setWindowWallpaperDisplayOffset(
                        mService.windowForClientLocked(this, window, true), x, y);
                actionOnWallpaper(window, (wpController, windowState) ->
                        wpController.setWindowWallpaperDisplayOffset(windowState, x, y));
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
@@ -355,9 +360,9 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
        synchronized (mService.mGlobalLock) {
            long ident = Binder.clearCallingIdentity();
            try {
                return mService.mRoot.mWallpaperController.sendWindowWallpaperCommand(
                        mService.windowForClientLocked(this, window, true),
                        action, x, y, z, extras, sync);
                final WindowState windowState = mService.windowForClientLocked(this, window, true);
                return windowState.getDisplayContent().mWallpaperController
                        .sendWindowWallpaperCommand(windowState, action, x, y, z, extras, sync);
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
@@ -367,7 +372,8 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
    @Override
    public void wallpaperCommandComplete(IBinder window, Bundle result) {
        synchronized (mService.mGlobalLock) {
            mService.mRoot.mWallpaperController.wallpaperCommandComplete(window);
            actionOnWallpaper(window, (wpController, windowState) ->
                    wpController.wallpaperCommandComplete(window));
        }
    }

Loading