diff --git a/core/java/android/app/IWallpaperManager.aidl b/core/java/android/app/IWallpaperManager.aidl index e83557c18f8f7..4f7c6841d6bb8 100644 --- a/core/java/android/app/IWallpaperManager.aidl +++ b/core/java/android/app/IWallpaperManager.aidl @@ -190,4 +190,18 @@ interface IWallpaperManager { * Called from SystemUI when it shows the AoD UI. */ oneway void setInAmbientMode(boolean inAmbientMode, long animationDuration); + + /** + * Called from SystemUI when the device is waking up. + * + * @hide + */ + oneway void notifyWakingUp(int x, int y, in Bundle extras); + + /** + * Called from SystemUI when the device is going to sleep. + * + * @hide + */ + void notifyGoingToSleep(int x, int y, in Bundle extras); } diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java index 6a71c92fbc37d..8d332ab1d58b5 100644 --- a/core/java/android/app/WallpaperManager.java +++ b/core/java/android/app/WallpaperManager.java @@ -189,6 +189,30 @@ public class WallpaperManager { */ public static final String COMMAND_DROP = "android.home.drop"; + /** + * Command for {@link #sendWallpaperCommand}: reported by System UI when the device is waking + * up. The x and y arguments are a location (possibly very roughly) corresponding to the action + * that caused the device to wake up. For example, if the power button was pressed, this will be + * the location on the screen nearest the power button. + * + * If the location is unknown or not applicable, x and y will be -1. + * + * @hide + */ + public static final String COMMAND_WAKING_UP = "android.wallpaper.wakingup"; + + /** + * Command for {@link #sendWallpaperCommand}: reported by System UI when the device is going to + * sleep. The x and y arguments are a location (possibly very roughly) corresponding to the + * action that caused the device to go to sleep. For example, if the power button was pressed, + * this will be the location on the screen nearest the power button. + * + * If the location is unknown or not applicable, x and y will be -1. + * + * @hide + */ + public static final String COMMAND_GOING_TO_SLEEP = "android.wallpaper.goingtosleep"; + /** * Command for {@link #sendWallpaperCommand}: reported when the wallpaper that was already * set is re-applied by the user. diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/WakefulnessLifecycle.java b/packages/SystemUI/src/com/android/systemui/keyguard/WakefulnessLifecycle.java index de00d50b6e361..2e03d9a90f49f 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/WakefulnessLifecycle.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/WakefulnessLifecycle.java @@ -17,10 +17,20 @@ package com.android.systemui.keyguard; import android.annotation.IntDef; +import android.app.IWallpaperManager; +import android.content.Context; +import android.content.res.Configuration; +import android.graphics.Point; +import android.os.Bundle; import android.os.PowerManager; +import android.os.RemoteException; import android.os.Trace; +import android.util.DisplayMetrics; + +import androidx.annotation.Nullable; import com.android.systemui.Dumpable; +import com.android.systemui.R; import com.android.systemui.dagger.SysUISingleton; import java.io.FileDescriptor; @@ -31,7 +41,7 @@ import java.lang.annotation.RetentionPolicy; import javax.inject.Inject; /** - * Tracks the wakefulness lifecycle. + * Tracks the wakefulness lifecycle, including why we're waking or sleeping. */ @SysUISingleton public class WakefulnessLifecycle extends Lifecycle implements @@ -51,13 +61,32 @@ public class WakefulnessLifecycle extends Lifecycle { + if (displayConnector.mEngine != null) { + try { + displayConnector.mEngine.dispatchWallpaperCommand( + WallpaperManager.COMMAND_WAKING_UP, x, y, -1, extras); + } catch (RemoteException e) { + e.printStackTrace(); + } + } + }); + } + } + + /** + * Propagate a sleep event to the wallpaper engine. + */ + public void notifyGoingToSleep(int x, int y, @NonNull Bundle extras) { + synchronized (mLock) { + final WallpaperData data = mWallpaperMap.get(mCurrentUserId); + data.connection.forEachDisplayConnector( + displayConnector -> { + if (displayConnector.mEngine != null) { + try { + displayConnector.mEngine.dispatchWallpaperCommand( + WallpaperManager.COMMAND_GOING_TO_SLEEP, x, y, -1, extras); + } catch (RemoteException e) { + e.printStackTrace(); + } + } + }); + } + } + @Override public boolean setLockWallpaperCallback(IWallpaperManagerCallback cb) { checkPermission(android.Manifest.permission.INTERNAL_SYSTEM_WINDOW);