Reorder loading wallpapers during a user switch.
If the target user's home and lock screen wallpapers are different,
both of them are loaded during the user switch and this lengthens
the user switch duration unnecessarily. We can load the necessary one
during the user switch and postpone loading the other after the switch
depending on whether the target user has credentials or not.
Bug: 324911115
Test: atest WallpaperManagerTest
Flag: ACONFIG android.multiuser.reorder_wallpaper_during_user_switch DEVELOPMENT
Change-Id: I3b073f3315d9f69d18d45d7292cb734eaffe3458
diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
index 118985a..18afafd 100644
--- a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
+++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
@@ -52,6 +52,7 @@
import android.app.ILocalWallpaperColorConsumer;
import android.app.IWallpaperManager;
import android.app.IWallpaperManagerCallback;
+import android.app.KeyguardManager;
import android.app.PendingIntent;
import android.app.UidObserver;
import android.app.UserSwitchObserver;
@@ -1792,10 +1793,27 @@
systemWallpaper.wallpaperObserver = new WallpaperObserver(systemWallpaper);
systemWallpaper.wallpaperObserver.startWatching();
}
- if (lockWallpaper != systemWallpaper) {
- switchWallpaper(lockWallpaper, null);
+ if (Flags.reorderWallpaperDuringUserSwitch()) {
+ if (mLastLockWallpaper != null) {
+ detachWallpaperLocked(mLastLockWallpaper);
+ }
+ if (mLastWallpaper != null) {
+ detachWallpaperLocked(mLastWallpaper);
+ }
+ if (lockWallpaper == systemWallpaper) {
+ switchWallpaper(systemWallpaper, reply);
+ } else {
+ KeyguardManager km = mContext.getSystemService(KeyguardManager.class);
+ boolean isDeviceSecure = km != null && km.isDeviceSecure(userId);
+ switchWallpaper(isDeviceSecure ? lockWallpaper : systemWallpaper, reply);
+ switchWallpaper(isDeviceSecure ? systemWallpaper : lockWallpaper, null);
+ }
+ } else {
+ if (lockWallpaper != systemWallpaper) {
+ switchWallpaper(lockWallpaper, null);
+ }
+ switchWallpaper(systemWallpaper, reply);
}
- switchWallpaper(systemWallpaper, reply);
mInitialUserSwitch = false;
}