From 594497e44fe1d0b9625dcfbb3cbbda8286d6462c Mon Sep 17 00:00:00 2001 From: wilsonshih Date: Tue, 31 Mar 2020 10:49:37 +0800 Subject: [PATCH] Prevent cropHint been overwrite by display size. Follow the issue discussion, the cropHint should be preserved as what is backuped, so it shouldn't be overwrite by any reason. Validate the cropHint is enough. Bug: 152293002 Test: atest WallpaperManagerServiceTests Test: run bmgr to do backup/restore and see the cropHint doesn't been overwrite after reboot. Change-Id: I7b35ef17601418d730c3bcfc4c7e24978e55c721 --- .../wallpaper/WallpaperManagerService.java | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java index ddf166eb0bd57..63952b086c1c8 100644 --- a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java +++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java @@ -1904,7 +1904,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub final WallpaperData fallback = new WallpaperData(wallpaper.userId, getWallpaperDir(wallpaper.userId), WALLPAPER_LOCK_ORIG, WALLPAPER_LOCK_CROP); - ensureSaneWallpaperData(fallback, DEFAULT_DISPLAY); + ensureSaneWallpaperData(fallback); bindWallpaperComponentLocked(mImageWallpaper, true, false, fallback, reply); mWaitingForUnlock = true; } @@ -2425,7 +2425,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub if (cropHint == null) { cropHint = new Rect(0, 0, 0, 0); } else { - if (cropHint.isEmpty() + if (cropHint.width() < 0 || cropHint.height() < 0 || cropHint.left < 0 || cropHint.top < 0) { throw new IllegalArgumentException("Invalid crop rect supplied: " + cropHint); @@ -3077,7 +3077,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub wallpaper = new WallpaperData(userId, getWallpaperDir(userId), WALLPAPER_LOCK_ORIG, WALLPAPER_LOCK_CROP); mLockWallpaperMap.put(userId, wallpaper); - ensureSaneWallpaperData(wallpaper, DEFAULT_DISPLAY); + ensureSaneWallpaperData(wallpaper); } else { // sanity fallback: we're in bad shape, but establishing a known // valid system+lock WallpaperData will keep us from dying. @@ -3085,7 +3085,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub wallpaper = new WallpaperData(userId, getWallpaperDir(userId), WALLPAPER, WALLPAPER_CROP); mWallpaperMap.put(userId, wallpaper); - ensureSaneWallpaperData(wallpaper, DEFAULT_DISPLAY); + ensureSaneWallpaperData(wallpaper); } } } @@ -3196,10 +3196,10 @@ public class WallpaperManagerService extends IWallpaperManager.Stub } ensureSaneWallpaperDisplaySize(wpdData, DEFAULT_DISPLAY); - ensureSaneWallpaperData(wallpaper, DEFAULT_DISPLAY); + ensureSaneWallpaperData(wallpaper); WallpaperData lockWallpaper = mLockWallpaperMap.get(userId); if (lockWallpaper != null) { - ensureSaneWallpaperData(lockWallpaper, DEFAULT_DISPLAY); + ensureSaneWallpaperData(lockWallpaper); } } @@ -3215,15 +3215,11 @@ public class WallpaperManagerService extends IWallpaperManager.Stub } } - private void ensureSaneWallpaperData(WallpaperData wallpaper, int displayId) { - final DisplayData size = getDisplayDataOrCreate(displayId); - - if (displayId == DEFAULT_DISPLAY) { - // crop, if not previously specified - if (wallpaper.cropHint.width() <= 0 - || wallpaper.cropHint.height() <= 0) { - wallpaper.cropHint.set(0, 0, size.mWidth, size.mHeight); - } + private void ensureSaneWallpaperData(WallpaperData wallpaper) { + // Only overwrite cropHint if the rectangle is invalid. + if (wallpaper.cropHint.width() < 0 + || wallpaper.cropHint.height() < 0) { + wallpaper.cropHint.set(0, 0, 0, 0); } }