Merge "Multicrop: adds crop hints to recents" into main
diff --git a/src/com/android/wallpaper/module/DefaultWallpaperPersister.java b/src/com/android/wallpaper/module/DefaultWallpaperPersister.java
index 6a43253..9683857 100755
--- a/src/com/android/wallpaper/module/DefaultWallpaperPersister.java
+++ b/src/com/android/wallpaper/module/DefaultWallpaperPersister.java
@@ -59,6 +59,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.List;
+import java.util.Map;
 
 /**
  * Concrete implementation of WallpaperPersister which actually sets wallpapers to the system via
@@ -395,7 +396,7 @@
     }
 
     @Override
-    public int setStreamToWallpaperManager(InputStream inputStream, Rect cropHint,
+    public int setStreamToWallpaperManager(InputStream inputStream, @Nullable Rect cropHint,
             boolean allowBackup, int whichWallpaper) {
         try {
             return mWallpaperManager.setStream(inputStream, cropHint, allowBackup,
@@ -406,6 +407,17 @@
     }
 
     @Override
+    public int setStreamWithCropsToWallpaperManager(InputStream inputStream,
+            @NonNull Map<Point, Rect> cropHints, boolean allowBackup, int whichWallpaper) {
+        try {
+            return mWallpaperManager.setStreamWithCrops(inputStream, cropHints, allowBackup,
+                whichWallpaper);
+        } catch (IOException e) {
+            return 0;
+        }
+    }
+
+    @Override
     public void setWallpaperInfoInPreview(WallpaperInfo wallpaper) {
         mWallpaperInfoInPreview = wallpaper;
     }
diff --git a/src/com/android/wallpaper/module/DefaultWallpaperPreferences.kt b/src/com/android/wallpaper/module/DefaultWallpaperPreferences.kt
index f6c55f9..a59b0a3 100755
--- a/src/com/android/wallpaper/module/DefaultWallpaperPreferences.kt
+++ b/src/com/android/wallpaper/module/DefaultWallpaperPreferences.kt
@@ -897,7 +897,7 @@
         destination: WallpaperDestination,
         wallpaperModel: StaticWallpaperModel,
         bitmap: Bitmap,
-        cropHints: Map<Point, Rect?>,
+        cropHints: Map<Point, Rect>?,
     ) {}
 
     override suspend fun addLiveWallpaperToRecentWallpapers(
diff --git a/src/com/android/wallpaper/module/WallpaperPersister.java b/src/com/android/wallpaper/module/WallpaperPersister.java
index 0940d81..585aa13 100755
--- a/src/com/android/wallpaper/module/WallpaperPersister.java
+++ b/src/com/android/wallpaper/module/WallpaperPersister.java
@@ -20,9 +20,11 @@
 import static android.app.WallpaperManager.SetWallpaperFlags;
 
 import android.graphics.Bitmap;
+import android.graphics.Point;
 import android.graphics.Rect;
 
 import androidx.annotation.IntDef;
+import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 
 import com.android.wallpaper.asset.Asset;
@@ -31,6 +33,7 @@
 
 import java.io.InputStream;
 import java.util.List;
+import java.util.Map;
 
 /**
  * Interface for classes which persist wallpapers to the system.
@@ -159,7 +162,18 @@
      * Android, otherwise on pre-N versions of Android will return a positive integer when the
      * operation was successful and zero if the operation encountered an error.
      */
-    int setStreamToWallpaperManager(InputStream inputStream, Rect cropHint,
+    int setStreamToWallpaperManager(InputStream inputStream, @Nullable Rect cropHint,
+            boolean allowBackup, int whichWallpaper);
+
+    /**
+     * Sets a wallpaper stream to the {@link android.app.WallpaperManager}.
+     *
+     * @return an integer wallpaper ID. This is an actual wallpaper ID on N and later versions of
+     * Android, otherwise on pre-N versions of Android will return a positive integer when the
+     * operation was successful and zero if the operation encountered an error.
+     */
+    int setStreamWithCropsToWallpaperManager(InputStream inputStream,
+            @NonNull Map<Point, Rect> cropModel,
             boolean allowBackup, int whichWallpaper);
 
     /**
diff --git a/src/com/android/wallpaper/module/WallpaperPreferences.kt b/src/com/android/wallpaper/module/WallpaperPreferences.kt
index e45cbf3..6fbb34a 100755
--- a/src/com/android/wallpaper/module/WallpaperPreferences.kt
+++ b/src/com/android/wallpaper/module/WallpaperPreferences.kt
@@ -392,7 +392,7 @@
         destination: WallpaperDestination,
         wallpaperModel: StaticWallpaperModel,
         bitmap: Bitmap,
-        cropHints: Map<Point, Rect?>,
+        cropHints: Map<Point, Rect>?,
     )
 
     /**
diff --git a/src/com/android/wallpaper/picker/customization/data/content/WallpaperClientImpl.kt b/src/com/android/wallpaper/picker/customization/data/content/WallpaperClientImpl.kt
index e9f97b0..7edc234 100644
--- a/src/com/android/wallpaper/picker/customization/data/content/WallpaperClientImpl.kt
+++ b/src/com/android/wallpaper/picker/customization/data/content/WallpaperClientImpl.kt
@@ -167,8 +167,7 @@
             destination,
             wallpaperModel,
             bitmap,
-            // TODO (b/309139122): Introduce crop hints to recent wallpapers
-            emptyMap(),
+            cropHintsWithParallax,
         )
     }
 
diff --git a/tests/common/src/com/android/wallpaper/testing/TestWallpaperPersister.java b/tests/common/src/com/android/wallpaper/testing/TestWallpaperPersister.java
index e1be186..7d36852 100644
--- a/tests/common/src/com/android/wallpaper/testing/TestWallpaperPersister.java
+++ b/tests/common/src/com/android/wallpaper/testing/TestWallpaperPersister.java
@@ -17,8 +17,10 @@
 
 import android.content.Context;
 import android.graphics.Bitmap;
+import android.graphics.Point;
 import android.graphics.Rect;
 
+import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 
 import com.android.wallpaper.asset.Asset;
@@ -31,6 +33,7 @@
 
 import java.io.InputStream;
 import java.util.List;
+import java.util.Map;
 
 /**
  * Test double for {@link WallpaperPersister}.
@@ -43,6 +46,7 @@
     private Bitmap mCurrentHomeWallpaper;
     private Bitmap mCurrentLockWallpaper;
     private Bitmap mPendingHomeWallpaper;
+
     private Bitmap mPendingLockWallpaper;
     private List<String> mHomeAttributions;
     private String mHomeActionUrl;
@@ -239,4 +243,10 @@
             boolean allowBackup, int whichWallpaper) {
         return 1;
     }
+
+    @Override
+    public int setStreamWithCropsToWallpaperManager(InputStream inputStream,
+            @NonNull Map<Point, Rect> cropHints, boolean allowBackup, int whichWallpaper) {
+        return 1;
+    }
 }
diff --git a/tests/common/src/com/android/wallpaper/testing/TestWallpaperPreferences.kt b/tests/common/src/com/android/wallpaper/testing/TestWallpaperPreferences.kt
index 8d4f91b..e7480cf 100644
--- a/tests/common/src/com/android/wallpaper/testing/TestWallpaperPreferences.kt
+++ b/tests/common/src/com/android/wallpaper/testing/TestWallpaperPreferences.kt
@@ -477,7 +477,7 @@
         destination: WallpaperDestination,
         wallpaperModel: WallpaperModel.StaticWallpaperModel,
         bitmap: Bitmap,
-        cropHints: Map<Point, Rect?>
+        cropHints: Map<Point, Rect>?,
     ) {}
 
     override suspend fun addLiveWallpaperToRecentWallpapers(