Merge "Fix errors in WallpaperManagerService" into udc-dev am: d106e33178
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21466552 Change-Id: Iee15348d5cddc0f7b4766f395e06df277157f3a2 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -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,29 +238,32 @@ class WallpaperDataParser {
|
||||
}
|
||||
IoUtils.closeQuietly(stream);
|
||||
|
||||
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();
|
||||
if (DEBUG) {
|
||||
Slog.w(TAG, "Didn't set wallpaper id in loadSettingsLocked(" + userId
|
||||
+ "); now " + wallpaper.wallpaperId);
|
||||
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 = "";
|
||||
} else {
|
||||
if (wallpaper.wallpaperId <= 0) {
|
||||
wallpaper.wallpaperId = makeWallpaperIdLocked();
|
||||
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);
|
||||
ensureSaneWallpaperData(wallpaper);
|
||||
if (lockWallpaper != null) {
|
||||
ensureSaneWallpaperData(lockWallpaper);
|
||||
lockWallpaper.mWhich = FLAG_LOCK;
|
||||
wallpaper.mWhich = FLAG_SYSTEM;
|
||||
} else {
|
||||
wallpaper.mWhich = FLAG_SYSTEM | FLAG_LOCK;
|
||||
if (loadLock) {
|
||||
if (!success) lockWallpaper = null;
|
||||
if (lockWallpaper != null) {
|
||||
ensureSaneWallpaperData(lockWallpaper);
|
||||
lockWallpaper.mWhich = FLAG_LOCK;
|
||||
}
|
||||
}
|
||||
|
||||
return new WallpaperLoadingResult(wallpaper, lockWallpaper, success);
|
||||
|
||||
@@ -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,18 +3464,23 @@ 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);
|
||||
|
||||
mWallpaperMap.put(userId, result.getSystemWallpaperData());
|
||||
if (result.success()) {
|
||||
mLockWallpaperMap.put(userId, result.getLockWallpaperData());
|
||||
} else {
|
||||
mLockWallpaperMap.remove(userId);
|
||||
boolean updateSystem = !mEnableSeparateLockScreenEngine || (which & FLAG_SYSTEM) != 0;
|
||||
boolean updateLock = !mEnableSeparateLockScreenEngine || (which & FLAG_LOCK) != 0;
|
||||
|
||||
if (updateSystem) mWallpaperMap.put(userId, result.getSystemWallpaperData());
|
||||
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;
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user