Merge "wallpaper: avoid exception when user is not initialized" into mnc-dev

This commit is contained in:
Xiaohui Chen
2015-05-14 21:05:35 +00:00
committed by Android (Google) Code Review

View File

@@ -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");