WallpaperColors.fromDrawable Drawable mutation

WallpaperColors.fromDrawable should never mutate Drawable bounds

Test: tests/app/src/android/app/cts/WallpaperColorsTest.java
Change-Id: I7467033c6a4e587b04e60423ceec3404b980cdf2
Fixes: 73506557
diff --git a/core/java/android/app/WallpaperColors.java b/core/java/android/app/WallpaperColors.java
index a2864b9..60e8a12 100644
--- a/core/java/android/app/WallpaperColors.java
+++ b/core/java/android/app/WallpaperColors.java
@@ -21,6 +21,7 @@
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.Color;
+import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
 import android.os.Parcel;
 import android.os.Parcelable;
@@ -107,6 +108,11 @@
      * @param drawable Source where to extract from.
      */
     public static WallpaperColors fromDrawable(Drawable drawable) {
+        if (drawable == null) {
+            throw new IllegalArgumentException("Drawable cannot be null");
+        }
+
+        Rect initialBounds = drawable.copyBounds();
         int width = drawable.getIntrinsicWidth();
         int height = drawable.getIntrinsicHeight();
 
@@ -126,6 +132,7 @@
         final WallpaperColors colors = WallpaperColors.fromBitmap(bitmap);
         bitmap.recycle();
 
+        drawable.setBounds(initialBounds);
         return colors;
     }