diff options
| author | Xiaohui Chen <xiaohuic@google.com> | 2015-05-13 13:20:52 -0700 |
|---|---|---|
| committer | Xiaohui Chen <xiaohuic@google.com> | 2015-05-13 13:34:40 -0700 |
| commit | ac531941fb9259057b86c08fb95b82cd67f6d8c0 (patch) | |
| tree | 9f6b666c7d657215265c1dfab39e23b380a9619e | |
| parent | 0ca0f5800034f5fbd041d31617efa75f9d727885 (diff) | |
| download | frameworks_base-ac531941fb9259057b86c08fb95b82cd67f6d8c0.zip frameworks_base-ac531941fb9259057b86c08fb95b82cd67f6d8c0.tar.gz frameworks_base-ac531941fb9259057b86c08fb95b82cd67f6d8c0.tar.bz2 | |
wallpaper: avoid exception when user is not initialized
Bug: 21087887
Change-Id: I56b9bf08c6e7100589f0df116e9d20f2f77d50e8
| -rw-r--r-- | services/core/java/com/android/server/wallpaper/WallpaperManagerService.java | 38 |
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 755c414..ff7f96c 100644 --- a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java +++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java @@ -589,12 +589,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); @@ -717,10 +712,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"); } @@ -782,10 +774,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); } @@ -866,10 +855,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); @@ -1229,6 +1215,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"); |
