Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2e036538 authored by Xiaohui Chen's avatar Xiaohui Chen Committed by Android Git Automerger
Browse files

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

* commit '55a30240':
  wallpaper: avoid exception when user is not initialized
parents ca0d787f 55a30240
Loading
Loading
Loading
Loading
+20 −18
Original line number Diff line number Diff line
@@ -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");