Preserve shared {system+lock} wallpaper when setting system only

We migrate the existing (shared) system wallpaper to be the lock-only
wallpaper when setting a new system-only wallpaper.  The end result
is that if you say "set the system wallpaper only" the lock wallpaper
won't change.

(The migration is via a rename of the underlying imagery files, not
via copying, because copying all that data would be silly.)

Bug 27599080

Change-Id: I03ecf23c943fe88af58d5ac26f05587a15e2d0a9
This commit is contained in:
Christopher Tate
2016-04-29 18:59:18 -07:00
committed by Chris Tate
parent 8ebedfd0d9
commit 8347b63188

View File

@@ -73,6 +73,8 @@ import android.service.wallpaper.IWallpaperConnection;
import android.service.wallpaper.IWallpaperEngine; import android.service.wallpaper.IWallpaperEngine;
import android.service.wallpaper.IWallpaperService; import android.service.wallpaper.IWallpaperService;
import android.service.wallpaper.WallpaperService; import android.service.wallpaper.WallpaperService;
import android.system.ErrnoException;
import android.system.Os;
import android.util.EventLog; import android.util.EventLog;
import android.util.Slog; import android.util.Slog;
import android.util.SparseArray; import android.util.SparseArray;
@@ -224,6 +226,17 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {
+ " whichPending=0x" + Integer.toHexString(wallpaper.whichPending) + " whichPending=0x" + Integer.toHexString(wallpaper.whichPending)
+ " written=" + written); + " written=" + written);
} }
if (moved && lockWallpaperChanged) {
// We just migrated sys -> lock to preserve imagery for an impending
// new system-only wallpaper. Tell keyguard about it but that's it.
if (DEBUG) {
Slog.i(TAG, "Sys -> lock MOVED_TO");
}
notifyLockWallpaperChanged();
return;
}
synchronized (mLock) { synchronized (mLock) {
if (sysWallpaperChanged || lockWallpaperChanged) { if (sysWallpaperChanged || lockWallpaperChanged) {
notifyCallbacksLocked(wallpaper); notifyCallbacksLocked(wallpaper);
@@ -276,14 +289,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {
mLockWallpaperMap.remove(wallpaper.userId); mLockWallpaperMap.remove(wallpaper.userId);
} }
// and in any case, tell keyguard about it // and in any case, tell keyguard about it
final IWallpaperManagerCallback cb = mKeyguardListener; notifyLockWallpaperChanged();
if (cb != null) {
try {
cb.onWallpaperChanged();
} catch (RemoteException e) {
// Oh well it went away; no big deal
}
}
} }
saveSettingsLocked(wallpaper.userId); saveSettingsLocked(wallpaper.userId);
} }
@@ -293,6 +299,17 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {
} }
} }
void notifyLockWallpaperChanged() {
final IWallpaperManagerCallback cb = mKeyguardListener;
if (cb != null) {
try {
cb.onWallpaperChanged();
} catch (RemoteException e) {
// Oh well it went away; no big deal
}
}
}
/** /**
* Once a new wallpaper has been written via setWallpaper(...), it needs to be cropped * Once a new wallpaper has been written via setWallpaper(...), it needs to be cropped
* for display. * for display.
@@ -1334,6 +1351,17 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {
if (DEBUG) Slog.v(TAG, "setWallpaper which=0x" + Integer.toHexString(which)); if (DEBUG) Slog.v(TAG, "setWallpaper which=0x" + Integer.toHexString(which));
WallpaperData wallpaper; WallpaperData wallpaper;
/* If we're setting system but not lock, and lock is currently sharing the system
* wallpaper, we need to migrate that image over to being lock-only before
* the caller here writes new bitmap data.
*/
if (which == FLAG_SYSTEM && mLockWallpaperMap.get(userId) == null) {
if (DEBUG) {
Slog.i(TAG, "Migrating system->lock to preserve");
}
migrateSystemToLockWallpaperLocked(userId);
}
wallpaper = getWallpaperSafeLocked(userId, which); wallpaper = getWallpaperSafeLocked(userId, which);
final long ident = Binder.clearCallingIdentity(); final long ident = Binder.clearCallingIdentity();
try { try {
@@ -1354,6 +1382,38 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {
} }
} }
private void migrateSystemToLockWallpaperLocked(int userId) {
WallpaperData sysWP = mWallpaperMap.get(userId);
if (sysWP == null) {
if (DEBUG) {
Slog.i(TAG, "No system wallpaper? Not tracking for lock-only");
}
return;
}
// We know a-priori that there is no lock-only wallpaper currently
WallpaperData lockWP = new WallpaperData(userId,
WALLPAPER_LOCK_ORIG, WALLPAPER_LOCK_CROP);
lockWP.wallpaperId = sysWP.wallpaperId;
lockWP.cropHint.set(sysWP.cropHint);
lockWP.width = sysWP.width;
lockWP.height = sysWP.height;
lockWP.allowBackup = false;
// Migrate the bitmap files outright; no need to copy
try {
Os.rename(sysWP.wallpaperFile.getAbsolutePath(), lockWP.wallpaperFile.getAbsolutePath());
Os.rename(sysWP.cropFile.getAbsolutePath(), lockWP.cropFile.getAbsolutePath());
} catch (ErrnoException e) {
Slog.e(TAG, "Can't migrate system wallpaper: " + e.getMessage());
lockWP.wallpaperFile.delete();
lockWP.cropFile.delete();
return;
}
mLockWallpaperMap.put(userId, lockWP);
}
ParcelFileDescriptor updateWallpaperBitmapLocked(String name, WallpaperData wallpaper, ParcelFileDescriptor updateWallpaperBitmapLocked(String name, WallpaperData wallpaper,
Bundle extras) { Bundle extras) {
if (name == null) name = ""; if (name == null) name = "";