Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5e0c9b41 authored by Aurélien Pomini's avatar Aurélien Pomini
Browse files

Fix getBitmapCrops

Fixe two cases where getBitmapCrops could return empty Rect if the
cropHint of the wallpaper is empty, which can happen with
 - the default wallpaper
 - a wallpaper coming from forward migration after reboot

Flag: aconfig com.android.window.flags.multi_crop TEAMFOOD
Bug: 333456932
Test: manual
Change-Id: I46806cab1735f4ab26511750907d528fc448e1c6
parent 67f87795
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -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();
        }
+6 −0
Original line number Diff line number Diff line
@@ -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<>();