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

Commit 5d6c5577 authored by Aurélien Pomini's avatar Aurélien Pomini Committed by Automerger Merge Worker
Browse files

Merge "Fix errors in WallpaperManagerService" into udc-dev am: d106e331

parents 2b5096e9 d106e331
Loading
Loading
Loading
Loading
+35 −26
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import static com.android.server.wallpaper.WallpaperUtils.makeWallpaperIdLocked;

import android.annotation.Nullable;
import android.app.WallpaperColors;
import android.app.WallpaperManager.SetWallpaperFlags;
import android.app.backup.WallpaperBackupHelper;
import android.content.ComponentName;
import android.content.Context;
@@ -124,6 +125,8 @@ class WallpaperDataParser {
    }

    /**
     * TODO(b/197814683) adapt comment once flag is removed
     *
     * Load the system wallpaper (and the lock wallpaper, if it exists) from disk
     * @param userId the id of the user for which the wallpaper should be loaded
     * @param keepDimensionHints if false, parse and set the
@@ -132,17 +135,21 @@ class WallpaperDataParser {
     *                      If null, a new object will be created.
     * @param lockWallpaper the lock wallpaper object to reuse to do the modifications.
     *                      If null, a new object will be created.
     * @param which The wallpaper(s) to load. If {@link #mEnableSeparateLockScreenEngine} is false,
     *                      this flag has no effect and both wallpapers will always be loaded.
     * @return a {@link WallpaperLoadingResult} object containing the wallpaper data.
     *                      This object will contain the {@code wallpaper} and
     *                      {@code lockWallpaper} provided as parameters, if they are not null.
     */
    public WallpaperLoadingResult loadSettingsLocked(int userId, boolean keepDimensionHints,
            WallpaperData wallpaper, WallpaperData lockWallpaper) {
            WallpaperData wallpaper, WallpaperData lockWallpaper, @SetWallpaperFlags int which) {
        JournaledFile journal = makeJournaledFile(userId);
        FileInputStream stream = null;
        File file = journal.chooseForRead();

        boolean migrateFromOld = wallpaper == null;
        boolean loadSystem = !mEnableSeparateLockScreenEngine || (which & FLAG_SYSTEM) != 0;
        boolean loadLock = !mEnableSeparateLockScreenEngine || (which & FLAG_LOCK) != 0;

        // don't reuse the wallpaper objects in the new version
        if (mEnableSeparateLockScreenEngine) {
@@ -150,7 +157,7 @@ class WallpaperDataParser {
            lockWallpaper = null;
        }

        if (wallpaper == null) {
        if (wallpaper == null && loadSystem) {
            // Do this once per boot
            if (migrateFromOld) migrateFromOld();
            wallpaper = new WallpaperData(userId, FLAG_SYSTEM);
@@ -176,8 +183,8 @@ class WallpaperDataParser {
                type = parser.next();
                if (type == XmlPullParser.START_TAG) {
                    String tag = parser.getName();
                    if ("wp".equals(tag)
                            || ("kwp".equals(tag) && mEnableSeparateLockScreenEngine)) {
                    if (("wp".equals(tag) && loadSystem)
                            || ("kwp".equals(tag) && mEnableSeparateLockScreenEngine && loadLock)) {

                        if ("kwp".equals(tag) && lockWallpaper == null) {
                            lockWallpaper = new WallpaperData(userId, FLAG_LOCK);
@@ -206,9 +213,8 @@ class WallpaperDataParser {
                            Slog.v(TAG, "mNextWallpaperComponent:"
                                    + wallpaper.nextWallpaperComponent);
                        }
                    } else if ("kwp".equals(tag)) {
                        // keyguard-specific wallpaper for this user

                    } else if ("kwp".equals(tag) && !mEnableSeparateLockScreenEngine) {
                        // keyguard-specific wallpaper for this user (legacy code)
                        if (lockWallpaper == null) {
                            lockWallpaper = new WallpaperData(userId, FLAG_LOCK);
                        }
@@ -232,11 +238,13 @@ class WallpaperDataParser {
        }
        IoUtils.closeQuietly(stream);

        mWallpaperDisplayHelper.ensureSaneWallpaperDisplaySize(wpdData, DEFAULT_DISPLAY);

        if (loadSystem) {
            if (!success) {
                wallpaper.cropHint.set(0, 0, 0, 0);
                wpdData.mPadding.set(0, 0, 0, 0);
                wallpaper.name = "";
            lockWallpaper = null;
            } else {
                if (wallpaper.wallpaperId <= 0) {
                    wallpaper.wallpaperId = makeWallpaperIdLocked();
@@ -246,15 +254,16 @@ class WallpaperDataParser {
                    }
                }
            }

        mWallpaperDisplayHelper.ensureSaneWallpaperDisplaySize(wpdData, DEFAULT_DISPLAY);
            ensureSaneWallpaperData(wallpaper);
            wallpaper.mWhich = lockWallpaper != null ? FLAG_SYSTEM : FLAG_SYSTEM | FLAG_LOCK;
        }

        if (loadLock) {
            if (!success) lockWallpaper = null;
            if (lockWallpaper != null) {
                ensureSaneWallpaperData(lockWallpaper);
                lockWallpaper.mWhich = FLAG_LOCK;
            wallpaper.mWhich = FLAG_SYSTEM;
        } else {
            wallpaper.mWhich = FLAG_SYSTEM | FLAG_LOCK;
            }
        }

        return new WallpaperLoadingResult(wallpaper, lockWallpaper, success);
+29 −15
Original line number Diff line number Diff line
@@ -297,7 +297,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
                    if (DEBUG) {
                        Slog.v(TAG, "Wallpaper restore; reloading metadata");
                    }
                    loadSettingsLocked(wallpaper.userId, true);
                    loadSettingsLocked(wallpaper.userId, true, FLAG_SYSTEM | FLAG_LOCK);
                }
                if (DEBUG) {
                    Slog.v(TAG, "Wallpaper written; generating crop");
@@ -440,7 +440,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
                                if (DEBUG) {
                                    Slog.v(TAG, "moved-to, therefore restore; reloading metadata");
                                }
                                loadSettingsLocked(wallpaper.userId, true);
                                loadSettingsLocked(wallpaper.userId, true, FLAG_SYSTEM | FLAG_LOCK);
                            }
                            mWallpaperCropper.generateCrop(wallpaper);
                            if (DEBUG) {
@@ -1621,7 +1621,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
        // Initialize state from the persistent store, then guarantee that the
        // WallpaperData for the system imagery is instantiated & active, creating
        // it from defaults if necessary.
        loadSettingsLocked(UserHandle.USER_SYSTEM, false);
        loadSettingsLocked(UserHandle.USER_SYSTEM, false, FLAG_SYSTEM | FLAG_LOCK);
        getWallpaperSafeLocked(UserHandle.USER_SYSTEM, FLAG_SYSTEM);
    }

@@ -1936,7 +1936,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
            wallpaper = mWallpaperMap.get(userId);
            if (wallpaper == null) {
                // Might need to bring it in the first time to establish our rewrite
                loadSettingsLocked(userId, false);
                loadSettingsLocked(userId, false, FLAG_SYSTEM);
                wallpaper = mWallpaperMap.get(userId);
            }
        }
@@ -2034,7 +2034,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
                WallpaperData wd = mWallpaperMap.get(user.id);
                if (wd == null) {
                    // User hasn't started yet, so load their settings to peek at the wallpaper
                    loadSettingsLocked(user.id, false);
                    loadSettingsLocked(user.id, false, FLAG_SYSTEM | FLAG_LOCK);
                    wd = mWallpaperMap.get(user.id);
                }
                if (wd != null && name.equals(wd.name)) {
@@ -2910,8 +2910,16 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
                        liveSync.complete();
                    }
                };

                /*
                 * If we have a shared system+lock wallpaper, and we reapply the same wallpaper
                 * to system only, force rebind: the current wallpaper will be migrated to lock
                 * and a new engine with the same wallpaper will be applied to system.
                 */
                boolean forceRebind = same && systemIsBoth && which == FLAG_SYSTEM;

                boolean bindSuccess = bindWallpaperComponentLocked(name, /* force */
                        false, /* fromUser */ true, newWallpaper, callback);
                        forceRebind, /* fromUser */ true, newWallpaper, callback);
                if (bindSuccess) {
                    if (!same) {
                        newWallpaper.primaryColors = null;
@@ -3434,7 +3442,8 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
        if (wallpaper == null) {
            // common case, this is the first lookup post-boot of the system or
            // unified lock, so we bring up the saved state lazily now and recheck.
            loadSettingsLocked(userId, false);
            int whichLoad = (which == FLAG_LOCK) ? FLAG_LOCK : FLAG_SYSTEM;
            loadSettingsLocked(userId, false, whichLoad);
            wallpaper = whichSet.get(userId);
            if (wallpaper == null) {
                // if it's still null here, this is likely a lock-only operation and there is not
@@ -3455,20 +3464,25 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
        return wallpaper;
    }

    private void loadSettingsLocked(int userId, boolean keepDimensionHints) {
    private void loadSettingsLocked(int userId, boolean keepDimensionHints, int which) {
        initializeFallbackWallpaper();
        WallpaperData wallpaperData = mWallpaperMap.get(userId);
        WallpaperData lockWallpaperData = mLockWallpaperMap.get(userId);
        WallpaperDataParser.WallpaperLoadingResult result = mWallpaperDataParser.loadSettingsLocked(
                userId, keepDimensionHints, wallpaperData, lockWallpaperData);
                userId, keepDimensionHints, wallpaperData, lockWallpaperData, which);

        boolean updateSystem = !mEnableSeparateLockScreenEngine || (which & FLAG_SYSTEM) != 0;
        boolean updateLock = !mEnableSeparateLockScreenEngine || (which & FLAG_LOCK) != 0;

        mWallpaperMap.put(userId, result.getSystemWallpaperData());
        if (updateSystem) mWallpaperMap.put(userId, result.getSystemWallpaperData());
        if (updateLock) {
            if (result.success()) {
                mLockWallpaperMap.put(userId, result.getLockWallpaperData());
            } else {
                mLockWallpaperMap.remove(userId);
            }
        }
    }

    private void initializeFallbackWallpaper() {
        if (mFallbackWallpaper == null) {
@@ -3493,7 +3507,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
        WallpaperData wallpaper = null;
        boolean success = false;
        synchronized (mLock) {
            loadSettingsLocked(UserHandle.USER_SYSTEM, false);
            loadSettingsLocked(UserHandle.USER_SYSTEM, false, FLAG_SYSTEM | FLAG_LOCK);
            wallpaper = mWallpaperMap.get(UserHandle.USER_SYSTEM);
            wallpaper.wallpaperId = makeWallpaperIdLocked();    // always bump id at restore
            wallpaper.allowBackup = true;   // by definition if it was restored