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

Commit 660d573e authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Let wallpaper know when to animate AoD transition

Sometimes the screen will blank, and sometime the
wallpaper has the opportunity to animate the
transition.

Bug: 64155983
Test: atest tests/Internal/src/android/service/wallpaper/WallpaperServiceTest.java
Test: atest packages/SystemUI/tests/src/com/android/systemui/doze/DozeWallpaperStateTest.java
Change-Id: Ia92c00edb98eeeba42da33bdc7bec3feb961a658
parent 84a41d66
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -159,5 +159,5 @@ interface IWallpaperManager {
    /**
     * Called from SystemUI when it shows the AoD UI.
     */
    void setInAmbientMode(boolean inAmbienMode);
    void setInAmbientMode(boolean inAmbientMode, boolean animated);
}
+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ oneway interface IWallpaperEngine {
    void setDesiredSize(int width, int height);
    void setDisplayPadding(in Rect padding);
    void setVisibility(boolean visible);
    void setInAmbientMode(boolean inAmbientDisplay);
    void setInAmbientMode(boolean inAmbientDisplay, boolean animated);
    void dispatchPointer(in MotionEvent event);
    void dispatchWallpaperCommand(String action, int x, int y,
            int z, in Bundle extras);
+15 −8
Original line number Diff line number Diff line
@@ -563,9 +563,12 @@ public abstract class WallpaperService extends Service {
         * Called when the device enters or exits ambient mode.
         *
         * @param inAmbientMode {@code true} if in ambient mode.
         * @param animated {@code true} if you'll have te opportunity of animating your transition
         *                 {@code false} when the screen will blank and the wallpaper should be
         *                 set to ambient mode immediately.
         * @hide
         */
        public void onAmbientModeChanged(boolean inAmbientMode) {
        public void onAmbientModeChanged(boolean inAmbientMode, boolean animated) {
        }

        /**
@@ -1021,18 +1024,20 @@ public abstract class WallpaperService extends Service {
         * Executes life cycle event and updates internal ambient mode state based on
         * message sent from handler.
         *
         * @param inAmbientMode True if in ambient mode.
         * @param inAmbientMode {@code true} if in ambient mode.
         * @param animated {@code true} if the transition will be animated.
         * @hide
         */
        @VisibleForTesting
        public void doAmbientModeChanged(boolean inAmbientMode) {
        public void doAmbientModeChanged(boolean inAmbientMode, boolean animated) {
            if (!mDestroyed) {
                if (DEBUG) {
                    Log.v(TAG, "onAmbientModeChanged(" + inAmbientMode + "): " + this);
                    Log.v(TAG, "onAmbientModeChanged(" + inAmbientMode + ", "
                            + animated + "): " + this);
                }
                mIsInAmbientMode = inAmbientMode;
                if (mCreated) {
                    onAmbientModeChanged(inAmbientMode);
                    onAmbientModeChanged(inAmbientMode, animated);
                }
            }
        }
@@ -1278,8 +1283,10 @@ public abstract class WallpaperService extends Service {
        }

        @Override
        public void setInAmbientMode(boolean inAmbientDisplay) throws RemoteException {
            Message msg = mCaller.obtainMessageI(DO_IN_AMBIENT_MODE, inAmbientDisplay ? 1 : 0);
        public void setInAmbientMode(boolean inAmbientDisplay, boolean animated)
                throws RemoteException {
            Message msg = mCaller.obtainMessageII(DO_IN_AMBIENT_MODE, inAmbientDisplay ? 1 : 0,
                    animated ? 1 : 0);
            mCaller.sendMessage(msg);
        }

@@ -1350,7 +1357,7 @@ public abstract class WallpaperService extends Service {
                    return;
                }
                case DO_IN_AMBIENT_MODE: {
                    mEngine.doAmbientModeChanged(message.arg1 != 0);
                    mEngine.doAmbientModeChanged(message.arg1 != 0, message.arg2 != 0);
                    return;
                }
                case MSG_UPDATE_SURFACE:
+1 −1
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ public class DozeFactory {
                createDozeUi(context, host, wakeLock, machine, handler, alarmManager, params),
                new DozeScreenState(wrappedService, handler),
                createDozeScreenBrightness(context, wrappedService, sensorManager, host, handler),
                new DozeWallpaperState()
                new DozeWallpaperState(context)
        });

        return machine;
+30 −8
Original line number Diff line number Diff line
@@ -23,6 +23,10 @@ import android.os.ServiceManager;
import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardUpdateMonitorCallback;
import com.android.systemui.statusbar.phone.DozeParameters;
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;

import java.io.PrintWriter;

@@ -34,18 +38,28 @@ public class DozeWallpaperState implements DozeMachine.Part {
    private static final String TAG = "DozeWallpaperState";
    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);

    @VisibleForTesting
    final IWallpaperManager mWallpaperManagerService;
    private final IWallpaperManager mWallpaperManagerService;
    private boolean mKeyguardVisible;
    private boolean mIsAmbientMode;
    private final DozeParameters mDozeParameters;

    public DozeWallpaperState() {
    public DozeWallpaperState(Context context) {
        this(IWallpaperManager.Stub.asInterface(
                ServiceManager.getService(Context.WALLPAPER_SERVICE)));
                ServiceManager.getService(Context.WALLPAPER_SERVICE)),
                new DozeParameters(context), KeyguardUpdateMonitor.getInstance(context));
    }

    @VisibleForTesting
    DozeWallpaperState(IWallpaperManager wallpaperManagerService) {
    DozeWallpaperState(IWallpaperManager wallpaperManagerService, DozeParameters parameters,
            KeyguardUpdateMonitor keyguardUpdateMonitor) {
        mWallpaperManagerService = wallpaperManagerService;
        mDozeParameters = parameters;
        keyguardUpdateMonitor.registerCallback(new KeyguardUpdateMonitorCallback() {
            @Override
            public void onKeyguardVisibilityChanged(boolean showing) {
                mKeyguardVisible = showing;
            }
        });
    }

    @Override
@@ -56,17 +70,25 @@ public class DozeWallpaperState implements DozeMachine.Part {
            case DOZE_REQUEST_PULSE:
            case DOZE_PULSING:
            case DOZE_PULSE_DONE:
                isAmbientMode = true;
                isAmbientMode = mDozeParameters.getAlwaysOn();
                break;
            default:
                isAmbientMode = false;
        }

        final boolean animated;
        if (isAmbientMode) {
            animated = mDozeParameters.getCanControlScreenOffAnimation() && !mKeyguardVisible;
        } else {
            animated = !mDozeParameters.getDisplayNeedsBlanking();
        }

        if (isAmbientMode != mIsAmbientMode) {
            mIsAmbientMode = isAmbientMode;
            try {
                Log.i(TAG, "AoD wallpaper state changed to: " + mIsAmbientMode);
                mWallpaperManagerService.setInAmbientMode(mIsAmbientMode);
                Log.i(TAG, "AoD wallpaper state changed to: " + mIsAmbientMode
                        + ", animated: " + animated);
                mWallpaperManagerService.setInAmbientMode(mIsAmbientMode, animated);
            } catch (RemoteException e) {
                // Cannot notify wallpaper manager service, but it's fine, let's just skip it.
                Log.w(TAG, "Cannot notify state to WallpaperManagerService: " + mIsAmbientMode);
Loading