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

Commit efab3398 authored by Riddle Hsu's avatar Riddle Hsu Committed by Android (Google) Code Review
Browse files

Merge "Remove wallpaper visibility preservation for display switch" into main

parents 796e806b 0a5f2ad5
Loading
Loading
Loading
Loading
+0 −7
Original line number Original line Diff line number Diff line
@@ -261,13 +261,6 @@ public class WallpaperManager {
     */
     */
    public static final String COMMAND_GOING_TO_SLEEP = "android.wallpaper.goingtosleep";
    public static final String COMMAND_GOING_TO_SLEEP = "android.wallpaper.goingtosleep";


    /**
     * Command for {@link #sendWallpaperCommand}: reported when a physical display switch event
     * happens, e.g. fold and unfold.
     * @hide
     */
    public static final String COMMAND_DISPLAY_SWITCH = "android.wallpaper.displayswitch";

    /**
    /**
     * Command for {@link #sendWallpaperCommand}: reported when the wallpaper that was already
     * Command for {@link #sendWallpaperCommand}: reported when the wallpaper that was already
     * set is re-applied by the user.
     * set is re-applied by the user.
+1 −37
Original line number Original line Diff line number Diff line
@@ -16,7 +16,6 @@


package android.service.wallpaper;
package android.service.wallpaper;


import static android.app.WallpaperManager.COMMAND_DISPLAY_SWITCH;
import static android.app.WallpaperManager.COMMAND_FREEZE;
import static android.app.WallpaperManager.COMMAND_FREEZE;
import static android.app.WallpaperManager.COMMAND_UNFREEZE;
import static android.app.WallpaperManager.COMMAND_UNFREEZE;
import static android.app.WallpaperManager.SetWallpaperFlags;
import static android.app.WallpaperManager.SetWallpaperFlags;
@@ -161,7 +160,6 @@ public abstract class WallpaperService extends Service {
    static final boolean DEBUG = false;
    static final boolean DEBUG = false;
    static final float MIN_PAGE_ALLOWED_MARGIN = .05f;
    static final float MIN_PAGE_ALLOWED_MARGIN = .05f;
    private static final int MIN_BITMAP_SCREENSHOT_WIDTH = 64;
    private static final int MIN_BITMAP_SCREENSHOT_WIDTH = 64;
    private static final long PRESERVE_VISIBLE_TIMEOUT_MS = 1000;
    private static final long DEFAULT_UPDATE_SCREENSHOT_DURATION = 60 * 1000; //Once per minute
    private static final long DEFAULT_UPDATE_SCREENSHOT_DURATION = 60 * 1000; //Once per minute
    private static final @NonNull RectF LOCAL_COLOR_BOUNDS =
    private static final @NonNull RectF LOCAL_COLOR_BOUNDS =
            new RectF(0, 0, 1, 1);
            new RectF(0, 0, 1, 1);
@@ -174,7 +172,6 @@ public abstract class WallpaperService extends Service {


    private static final int MSG_UPDATE_SURFACE = 10000;
    private static final int MSG_UPDATE_SURFACE = 10000;
    private static final int MSG_VISIBILITY_CHANGED = 10010;
    private static final int MSG_VISIBILITY_CHANGED = 10010;
    private static final int MSG_REFRESH_VISIBILITY = 10011;
    private static final int MSG_WALLPAPER_OFFSETS = 10020;
    private static final int MSG_WALLPAPER_OFFSETS = 10020;
    private static final int MSG_WALLPAPER_COMMAND = 10025;
    private static final int MSG_WALLPAPER_COMMAND = 10025;
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
@@ -258,11 +255,6 @@ public abstract class WallpaperService extends Service {
         */
         */
        private boolean mIsScreenTurningOn;
        private boolean mIsScreenTurningOn;
        boolean mReportedVisible;
        boolean mReportedVisible;
        /**
         * This is used with {@link #PRESERVE_VISIBLE_TIMEOUT_MS} to avoid intermediate visibility
         * changes if the display may be toggled in a short time, e.g. display switch.
         */
        boolean mPreserveVisible;
        boolean mDestroyed;
        boolean mDestroyed;
        // Set to true after receiving WallpaperManager#COMMAND_FREEZE. It's reset back to false
        // Set to true after receiving WallpaperManager#COMMAND_FREEZE. It's reset back to false
        // after receiving WallpaperManager#COMMAND_UNFREEZE. COMMAND_FREEZE is fully applied once
        // after receiving WallpaperManager#COMMAND_UNFREEZE. COMMAND_FREEZE is fully applied once
@@ -1107,9 +1099,6 @@ public abstract class WallpaperService extends Service {
            if (pendingCount != 0) {
            if (pendingCount != 0) {
                out.print(prefix); out.print("mPendingResizeCount="); out.println(pendingCount);
                out.print(prefix); out.print("mPendingResizeCount="); out.println(pendingCount);
            }
            }
            if (mPreserveVisible) {
                out.print(prefix); out.print("mPreserveVisible=true");
            }
            synchronized (mLock) {
            synchronized (mLock) {
                out.print(prefix); out.print("mPendingXOffset="); out.print(mPendingXOffset);
                out.print(prefix); out.print("mPendingXOffset="); out.print(mPendingXOffset);
                        out.print(" mPendingXOffset="); out.println(mPendingXOffset);
                        out.print(" mPendingXOffset="); out.println(mPendingXOffset);
@@ -1672,8 +1661,7 @@ public abstract class WallpaperService extends Service {
                                ? false
                                ? false
                                : mIWallpaperEngine.mInfo.supportsAmbientMode();
                                : mIWallpaperEngine.mInfo.supportsAmbientMode();
                // Report visibility only if display is fully on or wallpaper supports ambient mode.
                // Report visibility only if display is fully on or wallpaper supports ambient mode.
                final boolean visible = (mVisible && (displayFullyOn || supportsAmbientMode))
                final boolean visible = mVisible && (displayFullyOn || supportsAmbientMode);
                        || mPreserveVisible;
                if (DEBUG) {
                if (DEBUG) {
                    Log.v(
                    Log.v(
                            TAG,
                            TAG,
@@ -2110,9 +2098,6 @@ public abstract class WallpaperService extends Service {
            if (!mDestroyed) {
            if (!mDestroyed) {
                if (COMMAND_FREEZE.equals(cmd.action) || COMMAND_UNFREEZE.equals(cmd.action)) {
                if (COMMAND_FREEZE.equals(cmd.action) || COMMAND_UNFREEZE.equals(cmd.action)) {
                    updateFrozenState(/* frozenRequested= */ !COMMAND_UNFREEZE.equals(cmd.action));
                    updateFrozenState(/* frozenRequested= */ !COMMAND_UNFREEZE.equals(cmd.action));
                } else if (COMMAND_DISPLAY_SWITCH.equals(cmd.action)) {
                    handleDisplaySwitch(cmd.z == 1 /* startToSwitch */);
                    return;
                }
                }
                result = onCommand(cmd.action, cmd.x, cmd.y, cmd.z,
                result = onCommand(cmd.action, cmd.x, cmd.y, cmd.z,
                        cmd.extras, cmd.sync);
                        cmd.extras, cmd.sync);
@@ -2128,23 +2113,6 @@ public abstract class WallpaperService extends Service {
            }
            }
        }
        }


        private void handleDisplaySwitch(boolean startToSwitch) {
            if (startToSwitch && mReportedVisible) {
                // The display may be off/on in a short time when the display is switching.
                // Keep the visible state until onScreenTurnedOn or !startToSwitch is received, so
                // the rendering thread can be active to redraw in time when receiving size change.
                mPreserveVisible = true;
                mCaller.removeMessages(MSG_REFRESH_VISIBILITY);
                mCaller.sendMessageDelayed(mCaller.obtainMessage(MSG_REFRESH_VISIBILITY),
                        PRESERVE_VISIBLE_TIMEOUT_MS);
            } else if (!startToSwitch && mPreserveVisible) {
                // The switch is finished, so restore to actual visibility.
                mPreserveVisible = false;
                mCaller.removeMessages(MSG_REFRESH_VISIBILITY);
                reportVisibility(false /* forceReport */);
            }
        }

        private void updateFrozenState(boolean frozenRequested) {
        private void updateFrozenState(boolean frozenRequested) {
            if (mIWallpaperEngine.mInfo == null
            if (mIWallpaperEngine.mInfo == null
                    // Procees the unfreeze command in case the wallaper became static while
                    // Procees the unfreeze command in case the wallaper became static while
@@ -2691,10 +2659,6 @@ public abstract class WallpaperService extends Service {
                            + ": " + message.arg1);
                            + ": " + message.arg1);
                    mEngine.doVisibilityChanged(message.arg1 != 0);
                    mEngine.doVisibilityChanged(message.arg1 != 0);
                    break;
                    break;
                case MSG_REFRESH_VISIBILITY:
                    mEngine.mPreserveVisible = false;
                    mEngine.reportVisibility(false /* forceReport */);
                    break;
                case MSG_UPDATE_SCREEN_TURNING_ON:
                case MSG_UPDATE_SCREEN_TURNING_ON:
                    if (DEBUG) {
                    if (DEBUG) {
                        Log.v(TAG,
                        Log.v(TAG,
+0 −1
Original line number Original line Diff line number Diff line
@@ -782,7 +782,6 @@ public class DisplayPolicy {
    }
    }


    private void onDisplaySwitchFinished() {
    private void onDisplaySwitchFinished() {
        mDisplayContent.mWallpaperController.onDisplaySwitchFinished();
        mDisplayContent.mDisplayUpdater.onDisplaySwitching(false);
        mDisplayContent.mDisplayUpdater.onDisplaySwitching(false);
    }
    }


+0 −3
Original line number Original line Diff line number Diff line
@@ -2866,9 +2866,6 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
        } else {
        } else {
            throw new RuntimeException("Create the same sleep token twice: " + token);
            throw new RuntimeException("Create the same sleep token twice: " + token);
        }
        }
        if (isSwappingDisplay) {
            display.mWallpaperController.onDisplaySwitchStarted();
        }
        return token;
        return token;
    }
    }


+0 −52
Original line number Original line Diff line number Diff line
@@ -16,7 +16,6 @@


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


import static android.app.WallpaperManager.COMMAND_DISPLAY_SWITCH;
import static android.app.WallpaperManager.COMMAND_FREEZE;
import static android.app.WallpaperManager.COMMAND_FREEZE;
import static android.app.WallpaperManager.COMMAND_UNFREEZE;
import static android.app.WallpaperManager.COMMAND_UNFREEZE;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
@@ -119,11 +118,6 @@ class WallpaperController {


    private boolean mShouldOffsetWallpaperCenter;
    private boolean mShouldOffsetWallpaperCenter;


    /**
     * Whether the wallpaper has been notified about a physical display switch event is started.
     */
    private volatile boolean mIsWallpaperNotifiedOnDisplaySwitch;

    private final ToBooleanFunction<WindowState> mFindWallpaperTargetFunction = w -> {
    private final ToBooleanFunction<WindowState> mFindWallpaperTargetFunction = w -> {
        final boolean useShellTransition = w.mTransitionController.isShellTransitionsEnabled();
        final boolean useShellTransition = w.mTransitionController.isShellTransitionsEnabled();
        if (!useShellTransition) {
        if (!useShellTransition) {
@@ -1093,52 +1087,6 @@ class WallpaperController {
        return null;
        return null;
    }
    }


    /**
     * Notifies the wallpaper that the display turns off when switching physical device. If the
     * wallpaper is currently visible, its client visibility will be preserved until the display is
     * confirmed to be off or on.
     */
    void onDisplaySwitchStarted() {
        mIsWallpaperNotifiedOnDisplaySwitch = notifyDisplaySwitch(true /* start */);
    }

    /**
     * Called when the screen has finished turning on or the device goes to sleep. This is no-op if
     * the operation is not part of a display switch.
     */
    void onDisplaySwitchFinished() {
        // The method can be called outside WM lock (turned on), so only acquire lock if needed.
        // This is to optimize the common cases that regular devices don't have display switch.
        if (mIsWallpaperNotifiedOnDisplaySwitch) {
            synchronized (mService.mGlobalLock) {
                mIsWallpaperNotifiedOnDisplaySwitch = false;
                notifyDisplaySwitch(false /* start */);
            }
        }
    }

    private boolean notifyDisplaySwitch(boolean start) {
        boolean notified = false;
        for (int curTokenNdx = mWallpaperTokens.size() - 1; curTokenNdx >= 0; curTokenNdx--) {
            final WallpaperWindowToken token = mWallpaperTokens.get(curTokenNdx);
            for (int i = token.getChildCount() - 1; i >= 0; i--) {
                final WindowState w = token.getChildAt(i);
                if (start && !w.mWinAnimator.getShown()) {
                    continue;
                }
                try {
                    w.mClient.dispatchWallpaperCommand(COMMAND_DISPLAY_SWITCH, 0 /* x */, 0 /* y */,
                            start ? 1 : 0 /* use z as start or finish */,
                            null /* bundle */, false /* sync */);
                } catch (RemoteException e) {
                    Slog.w(TAG, "Failed to dispatch COMMAND_DISPLAY_SWITCH " + e);
                }
                notified = true;
            }
        }
        return notified;
    }

    /**
    /**
     * Each window can request a zoom, example:
     * Each window can request a zoom, example:
     * - User is in overview, zoomed out.
     * - User is in overview, zoomed out.