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

Commit 83ed170c authored by Presubmit Automerger Backend's avatar Presubmit Automerger Backend
Browse files

[automerge] Report visibility only when display is fully on in WallpaperService 2p: 66266df5

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22475042

Bug: 275057152
Change-Id: I7357ae90e31590e67b8e66ee48069215d6633a1e
Merged-In: I8c8c59ad0e3f19880ec543686285a89b0b864739
parents 7e633df3 66266df5
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -205,6 +205,20 @@ interface IWallpaperManager {
     */
    void notifyGoingToSleep(int x, int y, in Bundle extras);

    /**
     * Called when the screen has been fully turned on and is visible.
     *
     * @hide
     */
    void notifyScreenTurnedOn(int displayId);

    /**
     * Called when the screen starts turning on.
     *
     * @hide
     */
    void notifyScreenTurningOn(int displayId);

    /**
     * Sets the wallpaper dim amount between [0f, 1f] which would be blended with the system default
     * dimming. 0f doesn't add any additional dimming and 1f makes the wallpaper fully black.
+2 −0
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ interface IWallpaperEngine {
    oneway void setDisplayPadding(in Rect padding);
    @UnsupportedAppUsage
    oneway void setVisibility(boolean visible);
    oneway void onScreenTurningOn();
    oneway void onScreenTurnedOn();
    oneway void setInAmbientMode(boolean inAmbientDisplay, long animationDuration);
    @UnsupportedAppUsage
    oneway void dispatchPointer(in MotionEvent event);
+44 −3
Original line number Diff line number Diff line
@@ -168,6 +168,7 @@ public abstract class WallpaperService extends Service {
    private static final int MSG_ZOOM = 10100;
    private static final int MSG_RESIZE_PREVIEW = 10110;
    private static final int MSG_REPORT_SHOWN = 10150;
    private static final int MSG_UPDATE_SCREEN_TURNING_ON = 10170;
    private static final int MSG_UPDATE_DIMMING = 10200;

    /** limit calls to {@link Engine#onComputeColors} to at most once per second */
@@ -213,6 +214,16 @@ public abstract class WallpaperService extends Service {

        boolean mInitializing = true;
        boolean mVisible;
        /**
         * Whether the screen is turning on.
         * After the display is powered on, brightness is initially off. It is turned on only after
         * all windows have been drawn, and sysui notifies that it's ready (See
         * {@link com.android.internal.policy.IKeyguardDrawnCallback}).
         * As some wallpapers use visibility as a signal to start animations, this makes sure
         * {@link Engine#onVisibilityChanged} is invoked only when the display is both on and
         * visible (with brightness on).
         */
        private boolean mIsScreenTurningOn;
        boolean mReportedVisible;
        boolean mDestroyed;
        // Set to true after receiving WallpaperManager#COMMAND_FREEZE. It's reset back to false
@@ -988,6 +999,7 @@ public abstract class WallpaperService extends Service {
                    out.print(" mDestroyed="); out.println(mDestroyed);
            out.print(prefix); out.print("mVisible="); out.print(mVisible);
                    out.print(" mReportedVisible="); out.println(mReportedVisible);
                    out.print(" mIsScreenTurningOn="); out.println(mIsScreenTurningOn);
            out.print(prefix); out.print("mDisplay="); out.println(mDisplay);
            out.print(prefix); out.print("mCreated="); out.print(mCreated);
                    out.print(" mSurfaceCreated="); out.print(mSurfaceCreated);
@@ -1522,6 +1534,13 @@ public abstract class WallpaperService extends Service {
            }
        }

        void onScreenTurningOnChanged(boolean isScreenTurningOn) {
            if (!mDestroyed) {
                mIsScreenTurningOn = isScreenTurningOn;
                reportVisibility();
            }
        }

        void doVisibilityChanged(boolean visible) {
            if (!mDestroyed) {
                mVisible = visible;
@@ -1538,9 +1557,10 @@ public abstract class WallpaperService extends Service {
                return;
            }
            if (!mDestroyed) {
                mDisplayState = mDisplay == null ? Display.STATE_UNKNOWN :
                        mDisplay.getCommittedState();
                boolean visible = mVisible && mDisplayState != Display.STATE_OFF;
                mDisplayState =
                        mDisplay == null ? Display.STATE_UNKNOWN : mDisplay.getCommittedState();
                boolean displayVisible = Display.isOnState(mDisplayState) && !mIsScreenTurningOn;
                boolean visible = mVisible && displayVisible;
                if (mReportedVisible != visible) {
                    mReportedVisible = visible;
                    if (DEBUG) Log.v(TAG, "onVisibilityChanged(" + visible
@@ -2414,6 +2434,20 @@ public abstract class WallpaperService extends Service {
            }
        }

        public void updateScreenTurningOn(boolean isScreenTurningOn) {
            Message msg = mCaller.obtainMessageBO(MSG_UPDATE_SCREEN_TURNING_ON, isScreenTurningOn,
                    null);
            mCaller.sendMessage(msg);
        }

        public void onScreenTurningOn() throws RemoteException {
            updateScreenTurningOn(true);
        }

        public void onScreenTurnedOn() throws RemoteException {
            updateScreenTurningOn(false);
        }

        @Override
        public void executeMessage(Message message) {
            if (mDetached.get()) {
@@ -2464,6 +2498,13 @@ public abstract class WallpaperService extends Service {
                            + ": " + message.arg1);
                    mEngine.doVisibilityChanged(message.arg1 != 0);
                    break;
                case MSG_UPDATE_SCREEN_TURNING_ON:
                    if (DEBUG) {
                        Log.v(TAG,
                                message.arg1 != 0 ? "Screen turning on" : "Screen turned on");
                    }
                    mEngine.onScreenTurningOnChanged(/* isScreenTurningOn= */ message.arg1 != 0);
                    break;
                case MSG_WALLPAPER_OFFSETS: {
                    mEngine.doOffsetsChanged(true);
                } break;
+29 −0
Original line number Diff line number Diff line
@@ -213,6 +213,7 @@ import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener;
import com.android.server.policy.keyguard.KeyguardStateMonitor.StateCallback;
import com.android.server.statusbar.StatusBarManagerInternal;
import com.android.server.vr.VrManagerInternal;
import com.android.server.wallpaper.WallpaperManagerInternal;
import com.android.server.wm.ActivityTaskManagerInternal;
import com.android.server.wm.DisplayPolicy;
import com.android.server.wm.DisplayRotation;
@@ -404,6 +405,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    SensorPrivacyManager mSensorPrivacyManager;
    DisplayManager mDisplayManager;
    DisplayManagerInternal mDisplayManagerInternal;

    private WallpaperManagerInternal mWallpaperManagerInternal;

    boolean mPreloadedRecentApps;
    final Object mServiceAcquireLock = new Object();
    Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
@@ -4823,11 +4827,34 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        return bootCompleted ? mKeyguardDrawnTimeout : 5000;
    }

    @Nullable
    private WallpaperManagerInternal getWallpaperManagerInternal() {
        if (mWallpaperManagerInternal == null) {
            mWallpaperManagerInternal = LocalServices.getService(WallpaperManagerInternal.class);
        }
        return mWallpaperManagerInternal;
    }

    private void reportScreenTurningOnToWallpaper(int displayId) {
        WallpaperManagerInternal wallpaperManagerInternal = getWallpaperManagerInternal();
        if (wallpaperManagerInternal != null) {
            wallpaperManagerInternal.onScreenTurningOn(displayId);
        }
    }

    private void reportScreenTurnedOnToWallpaper(int displayId) {
        WallpaperManagerInternal wallpaperManagerInternal = getWallpaperManagerInternal();
        if (wallpaperManagerInternal != null) {
            wallpaperManagerInternal.onScreenTurnedOn(displayId);
        }
    }

    // Called on the DisplayManager's DisplayPowerController thread.
    @Override
    public void screenTurningOn(int displayId, final ScreenOnListener screenOnListener) {
        if (DEBUG_WAKEUP) Slog.i(TAG, "Display " + displayId + " turning on...");

        reportScreenTurningOnToWallpaper(displayId);
        if (displayId == DEFAULT_DISPLAY) {
            Trace.asyncTraceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "screenTurningOn",
                    0 /* cookie */);
@@ -4868,6 +4895,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    public void screenTurnedOn(int displayId) {
        if (DEBUG_WAKEUP) Slog.i(TAG, "Display " + displayId + " turned on...");

        reportScreenTurnedOnToWallpaper(displayId);

        if (displayId != DEFAULT_DISPLAY) {
            return;
        }
+6 −0
Original line number Diff line number Diff line
@@ -27,4 +27,10 @@ public abstract class WallpaperManagerInternal {
     * Notifies the display is ready for adding wallpaper on it.
     */
    public abstract void onDisplayReady(int displayId);

    /** Notifies when the screen finished turning on and is visible to the user. */
    public abstract void onScreenTurnedOn(int displayId);

    /** Notifies when the screen starts turning on and is not yet visible to the user. */
    public abstract void onScreenTurningOn(int displayId);
}
Loading