Merge "Fix errors in WallpaperManagerService" into udc-dev

This commit is contained in:
Aurélien Pomini
2023-02-21 12:37:13 +00:00
committed by Android (Google) Code Review
2 changed files with 64 additions and 41 deletions

View File

@@ -29,6 +29,7 @@ import static com.android.server.wallpaper.WallpaperUtils.makeWallpaperIdLocked;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.app.WallpaperColors; import android.app.WallpaperColors;
import android.app.WallpaperManager.SetWallpaperFlags;
import android.app.backup.WallpaperBackupHelper; import android.app.backup.WallpaperBackupHelper;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; 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 * 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 userId the id of the user for which the wallpaper should be loaded
* @param keepDimensionHints if false, parse and set the * @param keepDimensionHints if false, parse and set the
@@ -132,17 +135,21 @@ class WallpaperDataParser {
* If null, a new object will be created. * If null, a new object will be created.
* @param lockWallpaper the lock wallpaper object to reuse to do the modifications. * @param lockWallpaper the lock wallpaper object to reuse to do the modifications.
* If null, a new object will be created. * 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. * @return a {@link WallpaperLoadingResult} object containing the wallpaper data.
* This object will contain the {@code wallpaper} and * This object will contain the {@code wallpaper} and
* {@code lockWallpaper} provided as parameters, if they are not null. * {@code lockWallpaper} provided as parameters, if they are not null.
*/ */
public WallpaperLoadingResult loadSettingsLocked(int userId, boolean keepDimensionHints, public WallpaperLoadingResult loadSettingsLocked(int userId, boolean keepDimensionHints,
WallpaperData wallpaper, WallpaperData lockWallpaper) { WallpaperData wallpaper, WallpaperData lockWallpaper, @SetWallpaperFlags int which) {
JournaledFile journal = makeJournaledFile(userId); JournaledFile journal = makeJournaledFile(userId);
FileInputStream stream = null; FileInputStream stream = null;
File file = journal.chooseForRead(); File file = journal.chooseForRead();
boolean migrateFromOld = wallpaper == null; 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 // don't reuse the wallpaper objects in the new version
if (mEnableSeparateLockScreenEngine) { if (mEnableSeparateLockScreenEngine) {
@@ -150,7 +157,7 @@ class WallpaperDataParser {
lockWallpaper = null; lockWallpaper = null;
} }
if (wallpaper == null) { if (wallpaper == null && loadSystem) {
// Do this once per boot // Do this once per boot
if (migrateFromOld) migrateFromOld(); if (migrateFromOld) migrateFromOld();
wallpaper = new WallpaperData(userId, FLAG_SYSTEM); wallpaper = new WallpaperData(userId, FLAG_SYSTEM);
@@ -176,8 +183,8 @@ class WallpaperDataParser {
type = parser.next(); type = parser.next();
if (type == XmlPullParser.START_TAG) { if (type == XmlPullParser.START_TAG) {
String tag = parser.getName(); String tag = parser.getName();
if ("wp".equals(tag) if (("wp".equals(tag) && loadSystem)
|| ("kwp".equals(tag) && mEnableSeparateLockScreenEngine)) { || ("kwp".equals(tag) && mEnableSeparateLockScreenEngine && loadLock)) {
if ("kwp".equals(tag) && lockWallpaper == null) { if ("kwp".equals(tag) && lockWallpaper == null) {
lockWallpaper = new WallpaperData(userId, FLAG_LOCK); lockWallpaper = new WallpaperData(userId, FLAG_LOCK);
@@ -206,9 +213,8 @@ class WallpaperDataParser {
Slog.v(TAG, "mNextWallpaperComponent:" Slog.v(TAG, "mNextWallpaperComponent:"
+ wallpaper.nextWallpaperComponent); + wallpaper.nextWallpaperComponent);
} }
} else if ("kwp".equals(tag)) { } else if ("kwp".equals(tag) && !mEnableSeparateLockScreenEngine) {
// keyguard-specific wallpaper for this user // keyguard-specific wallpaper for this user (legacy code)
if (lockWallpaper == null) { if (lockWallpaper == null) {
lockWallpaper = new WallpaperData(userId, FLAG_LOCK); lockWallpaper = new WallpaperData(userId, FLAG_LOCK);
} }
@@ -232,29 +238,32 @@ class WallpaperDataParser {
} }
IoUtils.closeQuietly(stream); IoUtils.closeQuietly(stream);
if (!success) { mWallpaperDisplayHelper.ensureSaneWallpaperDisplaySize(wpdData, DEFAULT_DISPLAY);
wallpaper.cropHint.set(0, 0, 0, 0);
wpdData.mPadding.set(0, 0, 0, 0); if (loadSystem) {
wallpaper.name = ""; if (!success) {
lockWallpaper = null; wallpaper.cropHint.set(0, 0, 0, 0);
} else { wpdData.mPadding.set(0, 0, 0, 0);
if (wallpaper.wallpaperId <= 0) { wallpaper.name = "";
wallpaper.wallpaperId = makeWallpaperIdLocked(); } else {
if (DEBUG) { if (wallpaper.wallpaperId <= 0) {
Slog.w(TAG, "Didn't set wallpaper id in loadSettingsLocked(" + userId wallpaper.wallpaperId = makeWallpaperIdLocked();
+ "); now " + wallpaper.wallpaperId); if (DEBUG) {
Slog.w(TAG, "Didn't set wallpaper id in loadSettingsLocked(" + userId
+ "); now " + wallpaper.wallpaperId);
}
} }
} }
ensureSaneWallpaperData(wallpaper);
wallpaper.mWhich = lockWallpaper != null ? FLAG_SYSTEM : FLAG_SYSTEM | FLAG_LOCK;
} }
mWallpaperDisplayHelper.ensureSaneWallpaperDisplaySize(wpdData, DEFAULT_DISPLAY); if (loadLock) {
ensureSaneWallpaperData(wallpaper); if (!success) lockWallpaper = null;
if (lockWallpaper != null) { if (lockWallpaper != null) {
ensureSaneWallpaperData(lockWallpaper); ensureSaneWallpaperData(lockWallpaper);
lockWallpaper.mWhich = FLAG_LOCK; lockWallpaper.mWhich = FLAG_LOCK;
wallpaper.mWhich = FLAG_SYSTEM; }
} else {
wallpaper.mWhich = FLAG_SYSTEM | FLAG_LOCK;
} }
return new WallpaperLoadingResult(wallpaper, lockWallpaper, success); return new WallpaperLoadingResult(wallpaper, lockWallpaper, success);

View File

@@ -297,7 +297,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
if (DEBUG) { if (DEBUG) {
Slog.v(TAG, "Wallpaper restore; reloading metadata"); Slog.v(TAG, "Wallpaper restore; reloading metadata");
} }
loadSettingsLocked(wallpaper.userId, true); loadSettingsLocked(wallpaper.userId, true, FLAG_SYSTEM | FLAG_LOCK);
} }
if (DEBUG) { if (DEBUG) {
Slog.v(TAG, "Wallpaper written; generating crop"); Slog.v(TAG, "Wallpaper written; generating crop");
@@ -440,7 +440,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
if (DEBUG) { if (DEBUG) {
Slog.v(TAG, "moved-to, therefore restore; reloading metadata"); Slog.v(TAG, "moved-to, therefore restore; reloading metadata");
} }
loadSettingsLocked(wallpaper.userId, true); loadSettingsLocked(wallpaper.userId, true, FLAG_SYSTEM | FLAG_LOCK);
} }
mWallpaperCropper.generateCrop(wallpaper); mWallpaperCropper.generateCrop(wallpaper);
if (DEBUG) { if (DEBUG) {
@@ -1621,7 +1621,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
// Initialize state from the persistent store, then guarantee that the // Initialize state from the persistent store, then guarantee that the
// WallpaperData for the system imagery is instantiated & active, creating // WallpaperData for the system imagery is instantiated & active, creating
// it from defaults if necessary. // 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); getWallpaperSafeLocked(UserHandle.USER_SYSTEM, FLAG_SYSTEM);
} }
@@ -1936,7 +1936,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
wallpaper = mWallpaperMap.get(userId); wallpaper = mWallpaperMap.get(userId);
if (wallpaper == null) { if (wallpaper == null) {
// Might need to bring it in the first time to establish our rewrite // 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); wallpaper = mWallpaperMap.get(userId);
} }
} }
@@ -2034,7 +2034,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
WallpaperData wd = mWallpaperMap.get(user.id); WallpaperData wd = mWallpaperMap.get(user.id);
if (wd == null) { if (wd == null) {
// User hasn't started yet, so load their settings to peek at the wallpaper // 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); wd = mWallpaperMap.get(user.id);
} }
if (wd != null && name.equals(wd.name)) { if (wd != null && name.equals(wd.name)) {
@@ -2910,8 +2910,16 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
liveSync.complete(); 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 */ boolean bindSuccess = bindWallpaperComponentLocked(name, /* force */
false, /* fromUser */ true, newWallpaper, callback); forceRebind, /* fromUser */ true, newWallpaper, callback);
if (bindSuccess) { if (bindSuccess) {
if (!same) { if (!same) {
newWallpaper.primaryColors = null; newWallpaper.primaryColors = null;
@@ -3434,7 +3442,8 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
if (wallpaper == null) { if (wallpaper == null) {
// common case, this is the first lookup post-boot of the system or // 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. // 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); wallpaper = whichSet.get(userId);
if (wallpaper == null) { if (wallpaper == null) {
// if it's still null here, this is likely a lock-only operation and there is not // if it's still null here, this is likely a lock-only operation and there is not
@@ -3455,18 +3464,23 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
return wallpaper; return wallpaper;
} }
private void loadSettingsLocked(int userId, boolean keepDimensionHints) { private void loadSettingsLocked(int userId, boolean keepDimensionHints, int which) {
initializeFallbackWallpaper(); initializeFallbackWallpaper();
WallpaperData wallpaperData = mWallpaperMap.get(userId); WallpaperData wallpaperData = mWallpaperMap.get(userId);
WallpaperData lockWallpaperData = mLockWallpaperMap.get(userId); WallpaperData lockWallpaperData = mLockWallpaperMap.get(userId);
WallpaperDataParser.WallpaperLoadingResult result = mWallpaperDataParser.loadSettingsLocked( WallpaperDataParser.WallpaperLoadingResult result = mWallpaperDataParser.loadSettingsLocked(
userId, keepDimensionHints, wallpaperData, lockWallpaperData); userId, keepDimensionHints, wallpaperData, lockWallpaperData, which);
mWallpaperMap.put(userId, result.getSystemWallpaperData()); boolean updateSystem = !mEnableSeparateLockScreenEngine || (which & FLAG_SYSTEM) != 0;
if (result.success()) { boolean updateLock = !mEnableSeparateLockScreenEngine || (which & FLAG_LOCK) != 0;
mLockWallpaperMap.put(userId, result.getLockWallpaperData());
} else { if (updateSystem) mWallpaperMap.put(userId, result.getSystemWallpaperData());
mLockWallpaperMap.remove(userId); if (updateLock) {
if (result.success()) {
mLockWallpaperMap.put(userId, result.getLockWallpaperData());
} else {
mLockWallpaperMap.remove(userId);
}
} }
} }
@@ -3493,7 +3507,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
WallpaperData wallpaper = null; WallpaperData wallpaper = null;
boolean success = false; boolean success = false;
synchronized (mLock) { synchronized (mLock) {
loadSettingsLocked(UserHandle.USER_SYSTEM, false); loadSettingsLocked(UserHandle.USER_SYSTEM, false, FLAG_SYSTEM | FLAG_LOCK);
wallpaper = mWallpaperMap.get(UserHandle.USER_SYSTEM); wallpaper = mWallpaperMap.get(UserHandle.USER_SYSTEM);
wallpaper.wallpaperId = makeWallpaperIdLocked(); // always bump id at restore wallpaper.wallpaperId = makeWallpaperIdLocked(); // always bump id at restore
wallpaper.allowBackup = true; // by definition if it was restored wallpaper.allowBackup = true; // by definition if it was restored