summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--services/core/java/com/android/server/wallpaper/WallpaperManagerService.java38
1 files changed, 20 insertions, 18 deletions
diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
index 4098698..7784884 100644
--- a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
+++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
@@ -590,12 +590,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {
void switchUser(int userId, IRemoteCallback reply) {
synchronized (mLock) {
mCurrentUserId = userId;
- WallpaperData wallpaper = mWallpaperMap.get(userId);
- if (wallpaper == null) {
- wallpaper = new WallpaperData(userId);
- mWallpaperMap.put(userId, wallpaper);
- loadSettingsLocked(userId);
- }
+ WallpaperData wallpaper = getWallpaperSafeLocked(userId);
// Not started watching yet, in case wallpaper data was loaded for other reasons.
if (wallpaper.wallpaperObserver == null) {
wallpaper.wallpaperObserver = new WallpaperObserver(wallpaper);
@@ -718,10 +713,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {
}
synchronized (mLock) {
int userId = UserHandle.getCallingUserId();
- WallpaperData wallpaper = mWallpaperMap.get(userId);
- if (wallpaper == null) {
- throw new IllegalStateException("Wallpaper not yet initialized for user " + userId);
- }
+ WallpaperData wallpaper = getWallpaperSafeLocked(userId);
if (width <= 0 || height <= 0) {
throw new IllegalArgumentException("width and height must be > 0");
}
@@ -783,10 +775,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {
}
synchronized (mLock) {
int userId = UserHandle.getCallingUserId();
- WallpaperData wallpaper = mWallpaperMap.get(userId);
- if (wallpaper == null) {
- throw new IllegalStateException("Wallpaper not yet initialized for user " + userId);
- }
+ WallpaperData wallpaper = getWallpaperSafeLocked(userId);
if (padding.left < 0 || padding.top < 0 || padding.right < 0 || padding.bottom < 0) {
throw new IllegalArgumentException("padding must be positive: " + padding);
}
@@ -867,10 +856,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {
synchronized (mLock) {
if (DEBUG) Slog.v(TAG, "setWallpaper");
int userId = UserHandle.getCallingUserId();
- WallpaperData wallpaper = mWallpaperMap.get(userId);
- if (wallpaper == null) {
- throw new IllegalStateException("Wallpaper not yet initialized for user " + userId);
- }
+ WallpaperData wallpaper = getWallpaperSafeLocked(userId);
final long ident = Binder.clearCallingIdentity();
try {
ParcelFileDescriptor pfd = updateWallpaperBitmapLocked(name, wallpaper);
@@ -1230,6 +1216,22 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {
return Integer.parseInt(value);
}
+ /**
+ * Sometimes it is expected the wallpaper map may not have a user's data. E.g. This could
+ * happen during user switch. The async user switch observer may not have received
+ * the event yet. We use this safe method when we don't care about this ordering and just
+ * want to update the data. The data is going to be applied when the user switch observer
+ * is eventually executed.
+ */
+ private WallpaperData getWallpaperSafeLocked(int userId) {
+ WallpaperData wallpaper = mWallpaperMap.get(userId);
+ if (wallpaper == null) {
+ loadSettingsLocked(userId);
+ wallpaper = mWallpaperMap.get(userId);
+ }
+ return wallpaper;
+ }
+
private void loadSettingsLocked(int userId) {
if (DEBUG) Slog.v(TAG, "loadSettingsLocked");