Preserve shared {system+lock} wallpaper when setting system only
am: 8347b63188
* commit '8347b631883d073a2919517179c1e1378a8671e6':
Preserve shared {system+lock} wallpaper when setting system only
Change-Id: Ibd6043f1a27b5ad402cab8c03a090b0a3c227748
This commit is contained in:
@@ -73,6 +73,8 @@ import android.service.wallpaper.IWallpaperConnection;
|
||||
import android.service.wallpaper.IWallpaperEngine;
|
||||
import android.service.wallpaper.IWallpaperService;
|
||||
import android.service.wallpaper.WallpaperService;
|
||||
import android.system.ErrnoException;
|
||||
import android.system.Os;
|
||||
import android.util.EventLog;
|
||||
import android.util.Slog;
|
||||
import android.util.SparseArray;
|
||||
@@ -224,6 +226,17 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {
|
||||
+ " whichPending=0x" + Integer.toHexString(wallpaper.whichPending)
|
||||
+ " 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) {
|
||||
if (sysWallpaperChanged || lockWallpaperChanged) {
|
||||
notifyCallbacksLocked(wallpaper);
|
||||
@@ -276,14 +289,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {
|
||||
mLockWallpaperMap.remove(wallpaper.userId);
|
||||
}
|
||||
// and in any case, tell keyguard about it
|
||||
final IWallpaperManagerCallback cb = mKeyguardListener;
|
||||
if (cb != null) {
|
||||
try {
|
||||
cb.onWallpaperChanged();
|
||||
} catch (RemoteException e) {
|
||||
// Oh well it went away; no big deal
|
||||
}
|
||||
}
|
||||
notifyLockWallpaperChanged();
|
||||
}
|
||||
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
|
||||
* for display.
|
||||
@@ -1334,6 +1351,17 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {
|
||||
if (DEBUG) Slog.v(TAG, "setWallpaper which=0x" + Integer.toHexString(which));
|
||||
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);
|
||||
final long ident = Binder.clearCallingIdentity();
|
||||
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,
|
||||
Bundle extras) {
|
||||
if (name == null) name = "";
|
||||
|
||||
Reference in New Issue
Block a user