From 46c361b28b665878afa4d5e29c58f62d7802e573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Pomini?= Date: Tue, 11 Apr 2023 12:08:56 +0000 Subject: [PATCH] Adapt the boot logic for lockscreen live wallpapers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit First, if there are two live wallpapers, it is necessary to call bindWallpaperComponentLocked twice get the proper lockscreen live wallpaper after boot or after a user change switch. We only call bindWallpaper, we do not create a second WallpaperObserver: the observer from the system WallpaperData takes care of listening to everything. Also, we only use one callback, not two. Second, we need to handle lockscreen live wallpapers that are not direct-boot aware. If that is, we need to show the default wallpaper until the device is unlocked. In order to do that, we need to delete the LOCK_ORIG and LOCK_CROP files, to avoid showing an outdated wallpaper. Bug: 253507223 Test: Manually with the LWP feature flag enabled, -set a NOT direct-boot aware wallpaper on home + lock screen, -set another live wallpaper on home screen to trigger the migration, -set a pin code on the device -reboot -do the same for different scenarios (two NOT direct-boot aware, or a not direct-boot aware wallpaper on home screen only) Test: atest CtsWallpaperTestCases Change-Id: I353359a90e4bddc6dcdde88c9a7ab5a616a68bd3 --- .../wallpaper/WallpaperManagerService.java | 93 ++++++++++++++++++- 1 file changed, 90 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java index 51872b339c401..98d2d3d4b997d 100644 --- a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java +++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java @@ -803,6 +803,20 @@ public class WallpaperManagerService extends IWallpaperManager.Stub protected WallpaperData mLastLockWallpaper; private IWallpaperManagerCallback mKeyguardListener; private boolean mWaitingForUnlock; + + /** + * Flag set to true after reboot if the home wallpaper is waiting for the device to be unlocked. + * This happens for wallpapers that are not direct-boot aware; they can only be rendered after + * the user unlocks the device for the first time after a reboot. In the meantime, the default + * wallpaper is shown instead. + */ + private boolean mHomeWallpaperWaitingForUnlock; + + /** + * Flag set to true after reboot if the lock wallpaper is waiting for the device to be unlocked. + */ + private boolean mLockWallpaperWaitingForUnlock; + private boolean mShuttingDown; /** @@ -1790,7 +1804,23 @@ public class WallpaperManagerService extends IWallpaperManager.Stub public void onUnlockUser(final int userId) { synchronized (mLock) { if (mCurrentUserId == userId) { - if (mWaitingForUnlock) { + if (mIsLockscreenLiveWallpaperEnabled) { + if (mHomeWallpaperWaitingForUnlock) { + final WallpaperData systemWallpaper = + getWallpaperSafeLocked(userId, FLAG_SYSTEM); + switchWallpaper(systemWallpaper, null); + // TODO(b/278261563): call notifyCallbacksLocked inside switchWallpaper + notifyCallbacksLocked(systemWallpaper); + } + if (mLockWallpaperWaitingForUnlock) { + final WallpaperData lockWallpaper = + getWallpaperSafeLocked(userId, FLAG_LOCK); + switchWallpaper(lockWallpaper, null); + notifyCallbacksLocked(lockWallpaper); + } + } + + if (mWaitingForUnlock && !mIsLockscreenLiveWallpaperEnabled) { // the desired wallpaper is not direct-boot aware, load it now final WallpaperData systemWallpaper = getWallpaperSafeLocked(userId, FLAG_SYSTEM); @@ -1845,13 +1875,23 @@ public class WallpaperManagerService extends IWallpaperManager.Stub } mCurrentUserId = userId; systemWallpaper = getWallpaperSafeLocked(userId, FLAG_SYSTEM); - final WallpaperData tmpLockWallpaper = mLockWallpaperMap.get(userId); - lockWallpaper = tmpLockWallpaper == null ? systemWallpaper : tmpLockWallpaper; + + if (mIsLockscreenLiveWallpaperEnabled) { + lockWallpaper = systemWallpaper.mWhich == (FLAG_LOCK | FLAG_SYSTEM) + ? systemWallpaper : getWallpaperSafeLocked(userId, FLAG_LOCK); + } else { + final WallpaperData tmpLockWallpaper = mLockWallpaperMap.get(userId); + lockWallpaper = tmpLockWallpaper == null ? systemWallpaper : tmpLockWallpaper; + } + // Not started watching yet, in case wallpaper data was loaded for other reasons. if (systemWallpaper.wallpaperObserver == null) { systemWallpaper.wallpaperObserver = new WallpaperObserver(systemWallpaper); systemWallpaper.wallpaperObserver.startWatching(); } + if (mIsLockscreenLiveWallpaperEnabled && lockWallpaper != systemWallpaper) { + switchWallpaper(lockWallpaper, null); + } switchWallpaper(systemWallpaper, reply); } @@ -1870,6 +1910,11 @@ public class WallpaperManagerService extends IWallpaperManager.Stub void switchWallpaper(WallpaperData wallpaper, IRemoteCallback reply) { synchronized (mLock) { mWaitingForUnlock = false; + if (mIsLockscreenLiveWallpaperEnabled) { + if ((wallpaper.mWhich & FLAG_SYSTEM) != 0) mHomeWallpaperWaitingForUnlock = false; + if ((wallpaper.mWhich & FLAG_LOCK) != 0) mLockWallpaperWaitingForUnlock = false; + } + final ComponentName cname = wallpaper.wallpaperComponent != null ? wallpaper.wallpaperComponent : wallpaper.nextWallpaperComponent; if (!bindWallpaperComponentLocked(cname, true, false, wallpaper, reply)) { @@ -1882,6 +1927,11 @@ public class WallpaperManagerService extends IWallpaperManager.Stub } catch (RemoteException ignored) { } + if (mIsLockscreenLiveWallpaperEnabled) { + onSwitchWallpaperFailLocked(wallpaper, reply, si); + return; + } + if (si == null) { Slog.w(TAG, "Failure starting previous wallpaper; clearing"); clearWallpaperLocked(false, FLAG_SYSTEM, wallpaper.userId, reply); @@ -1899,6 +1949,43 @@ public class WallpaperManagerService extends IWallpaperManager.Stub } } + /** + * Fallback method if a wallpaper fails to load on boot or after a user switch. + * Only called if mIsLockscreenLiveWallpaperEnabled is true. + */ + private void onSwitchWallpaperFailLocked( + WallpaperData wallpaper, IRemoteCallback reply, ServiceInfo serviceInfo) { + + if (serviceInfo == null) { + Slog.w(TAG, "Failure starting previous wallpaper; clearing"); + + if (wallpaper.mWhich == (FLAG_LOCK | FLAG_SYSTEM)) { + clearWallpaperLocked(false, FLAG_SYSTEM, wallpaper.userId, null); + clearWallpaperLocked(false, FLAG_LOCK, wallpaper.userId, reply); + } else { + clearWallpaperLocked(false, wallpaper.mWhich, wallpaper.userId, reply); + } + return; + } + Slog.w(TAG, "Wallpaper isn't direct boot aware; using fallback until unlocked"); + // We might end up persisting the current wallpaper data + // while locked, so pretend like the component was actually + // bound into place + wallpaper.wallpaperComponent = wallpaper.nextWallpaperComponent; + final WallpaperData fallback = new WallpaperData(wallpaper.userId, wallpaper.mWhich); + + // files from the previous static wallpaper may still be stored in memory. + // delete them in order to show the default wallpaper. + if (wallpaper.wallpaperFile.exists()) { + wallpaper.wallpaperFile.delete(); + wallpaper.cropFile.delete(); + } + + bindWallpaperComponentLocked(mImageWallpaper, true, false, fallback, reply); + if ((wallpaper.mWhich & FLAG_SYSTEM) != 0) mHomeWallpaperWaitingForUnlock = true; + if ((wallpaper.mWhich & FLAG_LOCK) != 0) mLockWallpaperWaitingForUnlock = true; + } + @Override public void clearWallpaper(String callingPackage, int which, int userId) { if (DEBUG) Slog.v(TAG, "clearWallpaper");