Add support for custom action button for url

Allow the wallpaper info to provide a custom label and icon for
the "explore" button if available. The default is kept as the
compas and "Explore" label, but the API now allows to provide,
store and retrieve a custom resource for label and icon.

Bug: 77695473
Change-Id: I3a0f4c8bca46fc5e9c113f1b68fa3b794b9294a4
diff --git a/src/com/android/wallpaper/module/DefaultWallpaperPersister.java b/src/com/android/wallpaper/module/DefaultWallpaperPersister.java
index 4df0e71..5d371a3 100755
--- a/src/com/android/wallpaper/module/DefaultWallpaperPersister.java
+++ b/src/com/android/wallpaper/module/DefaultWallpaperPersister.java
@@ -337,15 +337,18 @@
 
     @Override
     public boolean setWallpaperInRotation(Bitmap wallpaperBitmap, List<String> attributions,
+                                          int actionLabelRes, int actionIconRes,
                                           String actionUrl, String collectionId) {
         @RotatingWallpaperComponent int rotatingWallpaperComponent = mRotatingWallpaperComponentChecker
                 .getCurrentRotatingWallpaperComponent(mAppContext);
 
         switch (rotatingWallpaperComponent) {
             case RotatingWallpaperComponentChecker.ROTATING_WALLPAPER_COMPONENT_STATIC:
-                return setWallpaperInRotationStatic(wallpaperBitmap, attributions, actionUrl, collectionId);
+                return setWallpaperInRotationStatic(wallpaperBitmap, attributions, actionUrl,
+                        actionLabelRes, actionIconRes, collectionId);
             case RotatingWallpaperComponentChecker.ROTATING_WALLPAPER_COMPONENT_LIVE:
-                return setWallpaperInRotationLive(wallpaperBitmap, attributions, actionUrl, collectionId);
+                return setWallpaperInRotationLive(wallpaperBitmap, attributions, actionUrl,
+                        actionLabelRes, actionIconRes, collectionId);
             default:
                 Log.e(TAG, "Unknown rotating wallpaper component: " + rotatingWallpaperComponent);
                 return false;
@@ -371,11 +374,12 @@
 
     @Override
     public boolean finalizeWallpaperForNextRotation(List<String> attributions, String actionUrl,
+                                                    int actionLabelRes, int actionIconRes,
                                                     String collectionId, int wallpaperId) {
-        @RotatingWallpaperComponent int rotatingWallpaperComponent = mRotatingWallpaperComponentChecker
-                .getNextRotatingWallpaperComponent(mAppContext);
-        return finalizeWallpaperForRotatingComponent(attributions, actionUrl, collectionId,
-                wallpaperId, rotatingWallpaperComponent);
+        @RotatingWallpaperComponent int rotatingWallpaperComponent =
+                mRotatingWallpaperComponentChecker.getNextRotatingWallpaperComponent(mAppContext);
+        return finalizeWallpaperForRotatingComponent(attributions, actionUrl, actionLabelRes,
+                actionIconRes, collectionId, wallpaperId, rotatingWallpaperComponent);
     }
 
     /**
@@ -383,15 +387,17 @@
      * current "daily wallpaper".
      */
     private boolean setWallpaperInRotationStatic(Bitmap wallpaperBitmap, List<String> attributions,
-                                                 String actionUrl, String collectionId) {
+                                                 String actionUrl, int actionLabelRes,
+                                                 int actionIconRes, String collectionId) {
         final int wallpaperId = setWallpaperBitmapInRotationStatic(wallpaperBitmap);
 
         if (wallpaperId == 0) {
             return false;
         }
 
-        return finalizeWallpaperForRotatingComponent(attributions, actionUrl, collectionId,
-                wallpaperId, RotatingWallpaperComponentChecker.ROTATING_WALLPAPER_COMPONENT_STATIC);
+        return finalizeWallpaperForRotatingComponent(attributions, actionUrl, actionLabelRes,
+                actionIconRes, collectionId, wallpaperId,
+                RotatingWallpaperComponentChecker.ROTATING_WALLPAPER_COMPONENT_STATIC);
     }
 
     /**
@@ -402,8 +408,12 @@
      * @return Whether the operation was successful.
      */
     private boolean finalizeWallpaperForRotatingComponent(List<String> attributions,
-                                                          String actionUrl, String collectionId, int wallpaperId,
-                                                          @RotatingWallpaperComponent int rotatingWallpaperComponent) {
+            String actionUrl,
+            int actionLabelRes,
+            int actionIconRes,
+            String collectionId,
+            int wallpaperId,
+            @RotatingWallpaperComponent int rotatingWallpaperComponent) {
         mWallpaperPreferences.clearHomeWallpaperMetadata();
 
         boolean isLockWallpaperSet = isSeparateLockScreenWallpaperSet();
@@ -481,6 +491,8 @@
 
         mWallpaperPreferences.setHomeWallpaperAttributions(attributions);
         mWallpaperPreferences.setHomeWallpaperActionUrl(actionUrl);
+        mWallpaperPreferences.setHomeWallpaperActionLabelRes(actionLabelRes);
+        mWallpaperPreferences.setHomeWallpaperActionIconRes(actionIconRes);
         // Only set base image URL for static Backdrop images, not for rotation.
         mWallpaperPreferences.setHomeWallpaperBaseImageUrl(null);
         mWallpaperPreferences.setHomeWallpaperCollectionId(collectionId);
@@ -492,6 +504,8 @@
                 && !isLockWallpaperSet) {
             mWallpaperPreferences.setLockWallpaperAttributions(attributions);
             mWallpaperPreferences.setLockWallpaperActionUrl(actionUrl);
+            mWallpaperPreferences.setLockWallpaperActionLabelRes(actionLabelRes);
+            mWallpaperPreferences.setLockWallpaperActionIconRes(actionIconRes);
             mWallpaperPreferences.setLockWallpaperCollectionId(collectionId);
         }
 
@@ -503,15 +517,18 @@
      * current "daily wallpaper".
      */
     private boolean setWallpaperInRotationLive(Bitmap wallpaperBitmap, List<String> attributions,
-                                               String actionUrl, String collectionId) {
+                                               String actionUrl, int actionLabelRes,
+                                               int actionIconRes, String collectionId) {
 
         synchronized (RotatingWallpaperLockProvider.getInstance()) {
             if (!setWallpaperBitmapInRotationLive(wallpaperBitmap, false /* isPreview */)) {
                 return false;
             }
 
-            return finalizeWallpaperForRotatingComponent(attributions, actionUrl, collectionId,
-                    0 /* wallpaperId */, RotatingWallpaperComponentChecker.ROTATING_WALLPAPER_COMPONENT_LIVE);
+            return finalizeWallpaperForRotatingComponent(attributions, actionUrl, actionLabelRes,
+                    actionIconRes, collectionId,
+                    0 /* wallpaperId */,
+                    RotatingWallpaperComponentChecker.ROTATING_WALLPAPER_COMPONENT_LIVE);
         }
     }
 
@@ -907,6 +924,10 @@
                     mWallpaperPreferences.getHomeWallpaperAttributions());
             mWallpaperPreferences.setLockWallpaperActionUrl(
                     mWallpaperPreferences.getHomeWallpaperActionUrl());
+            mWallpaperPreferences.setLockWallpaperActionLabelRes(
+                    mWallpaperPreferences.getHomeWallpaperActionLabelRes());
+            mWallpaperPreferences.setLockWallpaperActionIconRes(
+                    mWallpaperPreferences.getHomeWallpaperActionIconRes());
             mWallpaperPreferences.setLockWallpaperCollectionId(
                     mWallpaperPreferences.getHomeWallpaperCollectionId());
 
@@ -976,18 +997,26 @@
 
             mWallpaperPreferences.setHomeWallpaperHashCode(bitmapHash);
 
-            mWallpaperPreferences.setHomeWallpaperAttributions(mWallpaper.getAttributions(mAppContext));
+            mWallpaperPreferences.setHomeWallpaperAttributions(
+                    mWallpaper.getAttributions(mAppContext));
             mWallpaperPreferences.setHomeWallpaperBaseImageUrl(mWallpaper.getBaseImageUrl());
             mWallpaperPreferences.setHomeWallpaperActionUrl(mWallpaper.getActionUrl(mAppContext));
-            mWallpaperPreferences.setHomeWallpaperCollectionId(mWallpaper.getCollectionId(mAppContext));
+            mWallpaperPreferences.setHomeWallpaperActionLabelRes(mWallpaper.getActionLabelRes());
+            mWallpaperPreferences.setHomeWallpaperActionIconRes(mWallpaper.getActionIconRes());
+            mWallpaperPreferences.setHomeWallpaperCollectionId(
+                    mWallpaper.getCollectionId(mAppContext));
             mWallpaperPreferences.setHomeWallpaperRemoteId(mWallpaper.getWallpaperId());
         }
 
         private void setImageWallpaperLockMetadata(int lockWallpaperId) {
             mWallpaperPreferences.setLockWallpaperId(lockWallpaperId);
-            mWallpaperPreferences.setLockWallpaperAttributions(mWallpaper.getAttributions(mAppContext));
+            mWallpaperPreferences.setLockWallpaperAttributions(
+                    mWallpaper.getAttributions(mAppContext));
             mWallpaperPreferences.setLockWallpaperActionUrl(mWallpaper.getActionUrl(mAppContext));
-            mWallpaperPreferences.setLockWallpaperCollectionId(mWallpaper.getCollectionId(mAppContext));
+            mWallpaperPreferences.setHomeWallpaperActionLabelRes(mWallpaper.getActionLabelRes());
+            mWallpaperPreferences.setHomeWallpaperActionIconRes(mWallpaper.getActionIconRes());
+            mWallpaperPreferences.setLockWallpaperCollectionId(
+                    mWallpaper.getCollectionId(mAppContext));
 
             // Save the lock wallpaper image's hash code as well for the sake of backup & restore because
             // WallpaperManager-generated IDs are specific to a physical device and cannot be used to