summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/app/WallpaperManager.java14
-rw-r--r--services/core/java/com/android/server/wallpaper/WallpaperManagerService.java6
2 files changed, 18 insertions, 2 deletions
diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java
index 02d694436bfe..257aff04a09f 100644
--- a/core/java/android/app/WallpaperManager.java
+++ b/core/java/android/app/WallpaperManager.java
@@ -1603,8 +1603,18 @@ public class WallpaperManager {
@SetWallpaperFlags int which, boolean originalBitmap) {
checkExactlyOneWallpaperFlagSet(which);
try {
- return sGlobals.mService.getBitmapCrops(displaySizes, which, originalBitmap,
- mContext.getUserId());
+ List<Rect> result = sGlobals.mService.getBitmapCrops(
+ displaySizes, which, originalBitmap, mContext.getUserId());
+ if (result != null) return result;
+ // mService.getBitmapCrops returns null if the requested wallpaper is an ImageWallpaper,
+ // but there are no crop hints and the bitmap size is unknown to the service (this
+ // mostly happens for the default wallpaper). In that case, fetch the bitmap dimensions
+ // and use the other getBitmapCrops API with no cropHints to figure out the crops.
+ Rect bitmapDimensions = peekBitmapDimensions(which, true);
+ if (bitmapDimensions == null) return List.of();
+ Point bitmapSize = new Point(bitmapDimensions.width(), bitmapDimensions.height());
+ return getBitmapCrops(bitmapSize, displaySizes, null);
+
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
index 9a5961af6083..f1ba755836b2 100644
--- a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
+++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
@@ -2269,6 +2269,12 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
Point croppedBitmapSize = new Point(
(int) (0.5f + wallpaper.cropHint.width() / wallpaper.mSampleSize),
(int) (0.5f + wallpaper.cropHint.height() / wallpaper.mSampleSize));
+ if (croppedBitmapSize.equals(0, 0)) {
+ // There is an ImageWallpaper, but there are no crop hints and the bitmap size is
+ // unknown (e.g. the default wallpaper). Return a special "null" value that will be
+ // handled by WallpaperManager, which will fetch the dimensions of the wallpaper.
+ return null;
+ }
SparseArray<Rect> relativeDefaultCrops =
mWallpaperCropper.getDefaultCrops(relativeSuggestedCrops, croppedBitmapSize);
SparseArray<Rect> adjustedRelativeSuggestedCrops = new SparseArray<>();