Merge "Tidy up stale lock wallpaper state in set-both operation" into nyc-dev

This commit is contained in:
Chris Tate
2016-02-26 01:11:34 +00:00
committed by Android (Google) Code Review

View File

@@ -231,11 +231,16 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {
} }
if (lockWallpaperChanged if (lockWallpaperChanged
|| (wallpaper.whichPending & FLAG_SET_LOCK) != 0) { || (wallpaper.whichPending & FLAG_SET_LOCK) != 0) {
// either a lock-only wallpaper commit or a system+lock event,
// so tell keyguard about it
if (DEBUG) { if (DEBUG) {
Slog.i(TAG, "Lock-relevant wallpaper changed; telling listener"); Slog.i(TAG, "Lock-relevant wallpaper changed");
} }
// either a lock-only wallpaper commit or a system+lock event.
// if it's system-plus-lock we need to wipe the lock bookkeeping;
// we're falling back to displaying the system wallpaper there.
if (!lockWallpaperChanged) {
mLockWallpaperMap.remove(wallpaper.userId);
}
// and in any case, tell keyguard about it
final IWallpaperManagerCallback cb = mKeyguardListener; final IWallpaperManagerCallback cb = mKeyguardListener;
if (cb != null) { if (cb != null) {
try { try {
@@ -245,7 +250,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {
} }
} }
} }
saveSettingsLocked(wallpaper); saveSettingsLocked(wallpaper.userId);
} }
} }
} }
@@ -479,7 +484,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {
// when we have an engine, but I'm not sure about // when we have an engine, but I'm not sure about
// locking there and anyway we always need to be able to // locking there and anyway we always need to be able to
// recover if there is something wrong. // recover if there is something wrong.
saveSettingsLocked(mWallpaper); saveSettingsLocked(mWallpaper.userId);
} }
} }
} }
@@ -995,7 +1000,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {
if (width != wallpaper.width || height != wallpaper.height) { if (width != wallpaper.width || height != wallpaper.height) {
wallpaper.width = width; wallpaper.width = width;
wallpaper.height = height; wallpaper.height = height;
saveSettingsLocked(wallpaper); saveSettingsLocked(userId);
if (mCurrentUserId != userId) return; // Don't change the properties now if (mCurrentUserId != userId) return; // Don't change the properties now
if (wallpaper.connection != null) { if (wallpaper.connection != null) {
if (wallpaper.connection.mEngine != null) { if (wallpaper.connection.mEngine != null) {
@@ -1052,7 +1057,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {
if (!padding.equals(wallpaper.padding)) { if (!padding.equals(wallpaper.padding)) {
wallpaper.padding.set(padding); wallpaper.padding.set(padding);
saveSettingsLocked(wallpaper); saveSettingsLocked(userId);
if (mCurrentUserId != userId) return; // Don't change the properties now if (mCurrentUserId != userId) return; // Don't change the properties now
if (wallpaper.connection != null) { if (wallpaper.connection != null) {
if (wallpaper.connection.mEngine != null) { if (wallpaper.connection.mEngine != null) {
@@ -1488,50 +1493,33 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {
return new JournaledFile(new File(base), new File(base + ".tmp")); return new JournaledFile(new File(base), new File(base + ".tmp"));
} }
private void saveSettingsLocked(WallpaperData wallpaper) { private void saveSettingsLocked(int userId) {
JournaledFile journal = makeJournaledFile(wallpaper.userId); JournaledFile journal = makeJournaledFile(userId);
FileOutputStream stream = null; FileOutputStream fstream = null;
BufferedOutputStream stream = null;
try { try {
stream = new FileOutputStream(journal.chooseForWrite(), false);
XmlSerializer out = new FastXmlSerializer(); XmlSerializer out = new FastXmlSerializer();
fstream = new FileOutputStream(journal.chooseForWrite(), false);
stream = new BufferedOutputStream(fstream);
out.setOutput(stream, StandardCharsets.UTF_8.name()); out.setOutput(stream, StandardCharsets.UTF_8.name());
out.startDocument(null, true); out.startDocument(null, true);
out.startTag(null, "wp"); WallpaperData wallpaper;
out.attribute(null, "id", Integer.toString(wallpaper.wallpaperId));
out.attribute(null, "width", Integer.toString(wallpaper.width));
out.attribute(null, "height", Integer.toString(wallpaper.height));
out.attribute(null, "cropLeft", Integer.toString(wallpaper.cropHint.left)); wallpaper = mWallpaperMap.get(userId);
out.attribute(null, "cropTop", Integer.toString(wallpaper.cropHint.top)); if (wallpaper != null) {
out.attribute(null, "cropRight", Integer.toString(wallpaper.cropHint.right)); writeWallpaperAttributes(out, "wp", wallpaper);
out.attribute(null, "cropBottom", Integer.toString(wallpaper.cropHint.bottom));
if (wallpaper.padding.left != 0) {
out.attribute(null, "paddingLeft", Integer.toString(wallpaper.padding.left));
} }
if (wallpaper.padding.top != 0) { wallpaper = mLockWallpaperMap.get(userId);
out.attribute(null, "paddingTop", Integer.toString(wallpaper.padding.top)); if (wallpaper != null) {
writeWallpaperAttributes(out, "kwp", wallpaper);
} }
if (wallpaper.padding.right != 0) {
out.attribute(null, "paddingRight", Integer.toString(wallpaper.padding.right));
}
if (wallpaper.padding.bottom != 0) {
out.attribute(null, "paddingBottom", Integer.toString(wallpaper.padding.bottom));
}
out.attribute(null, "name", wallpaper.name);
if (wallpaper.wallpaperComponent != null
&& !wallpaper.wallpaperComponent.equals(mImageWallpaper)) {
out.attribute(null, "component",
wallpaper.wallpaperComponent.flattenToShortString());
}
out.endTag(null, "wp");
out.endDocument(); out.endDocument();
stream.flush();
FileUtils.sync(stream); stream.flush(); // also flushes fstream
stream.close(); FileUtils.sync(fstream);
stream.close(); // also closes fstream
journal.commit(); journal.commit();
} catch (IOException e) { } catch (IOException e) {
IoUtils.closeQuietly(stream); IoUtils.closeQuietly(stream);
@@ -1539,6 +1527,40 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {
} }
} }
private void writeWallpaperAttributes(XmlSerializer out, String tag, WallpaperData wallpaper)
throws IllegalArgumentException, IllegalStateException, IOException {
out.startTag(null, tag);
out.attribute(null, "id", Integer.toString(wallpaper.wallpaperId));
out.attribute(null, "width", Integer.toString(wallpaper.width));
out.attribute(null, "height", Integer.toString(wallpaper.height));
out.attribute(null, "cropLeft", Integer.toString(wallpaper.cropHint.left));
out.attribute(null, "cropTop", Integer.toString(wallpaper.cropHint.top));
out.attribute(null, "cropRight", Integer.toString(wallpaper.cropHint.right));
out.attribute(null, "cropBottom", Integer.toString(wallpaper.cropHint.bottom));
if (wallpaper.padding.left != 0) {
out.attribute(null, "paddingLeft", Integer.toString(wallpaper.padding.left));
}
if (wallpaper.padding.top != 0) {
out.attribute(null, "paddingTop", Integer.toString(wallpaper.padding.top));
}
if (wallpaper.padding.right != 0) {
out.attribute(null, "paddingRight", Integer.toString(wallpaper.padding.right));
}
if (wallpaper.padding.bottom != 0) {
out.attribute(null, "paddingBottom", Integer.toString(wallpaper.padding.bottom));
}
out.attribute(null, "name", wallpaper.name);
if (wallpaper.wallpaperComponent != null
&& !wallpaper.wallpaperComponent.equals(mImageWallpaper)) {
out.attribute(null, "component",
wallpaper.wallpaperComponent.flattenToShortString());
}
out.endTag(null, tag);
}
private void migrateFromOld() { private void migrateFromOld() {
File oldWallpaper = new File(WallpaperBackupHelper.WALLPAPER_IMAGE_KEY); File oldWallpaper = new File(WallpaperBackupHelper.WALLPAPER_IMAGE_KEY);
File oldInfo = new File(WallpaperBackupHelper.WALLPAPER_INFO_KEY); File oldInfo = new File(WallpaperBackupHelper.WALLPAPER_INFO_KEY);
@@ -1753,8 +1775,8 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {
WallpaperData wallpaper = null; WallpaperData wallpaper = null;
boolean success = false; boolean success = false;
synchronized (mLock) { synchronized (mLock) {
loadSettingsLocked(0); loadSettingsLocked(UserHandle.USER_SYSTEM);
wallpaper = mWallpaperMap.get(0); wallpaper = mWallpaperMap.get(UserHandle.USER_SYSTEM);
wallpaper.wallpaperId = makeWallpaperIdLocked(); // always bump id at restore wallpaper.wallpaperId = makeWallpaperIdLocked(); // always bump id at restore
if (wallpaper.nextWallpaperComponent != null if (wallpaper.nextWallpaperComponent != null
&& !wallpaper.nextWallpaperComponent.equals(mImageWallpaper)) { && !wallpaper.nextWallpaperComponent.equals(mImageWallpaper)) {
@@ -1788,11 +1810,11 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {
if (!success) { if (!success) {
Slog.e(TAG, "Failed to restore wallpaper: '" + wallpaper.name + "'"); Slog.e(TAG, "Failed to restore wallpaper: '" + wallpaper.name + "'");
wallpaper.name = ""; wallpaper.name = "";
getWallpaperDir(0).delete(); getWallpaperDir(UserHandle.USER_SYSTEM).delete();
} }
synchronized (mLock) { synchronized (mLock) {
saveSettingsLocked(wallpaper); saveSettingsLocked(UserHandle.USER_SYSTEM);
} }
} }