Loading core/java/android/app/WallpaperColors.java +17 −6 Original line number Diff line number Diff line Loading @@ -111,12 +111,15 @@ public final class WallpaperColors implements Parcelable { public WallpaperColors(Parcel parcel) { mMainColors = new ArrayList<>(); mAllColors = new HashMap<>(); final int count = parcel.readInt(); int count = parcel.readInt(); for (int i = 0; i < count; i++) { final int colorInt = parcel.readInt(); Color color = Color.valueOf(colorInt); mMainColors.add(color); } count = parcel.readInt(); for (int i = 0; i < count; i++) { final int colorInt = parcel.readInt(); final int population = parcel.readInt(); mAllColors.put(colorInt, population); } Loading Loading @@ -411,10 +414,17 @@ public final class WallpaperColors implements Parcelable { for (int i = 0; i < count; i++) { Color color = mainColors.get(i); dest.writeInt(color.toArgb()); Integer population = mAllColors.get(color.toArgb()); } count = mAllColors.size(); dest.writeInt(count); for (Map.Entry<Integer, Integer> colorEntry : mAllColors.entrySet()) { if (colorEntry.getKey() != null) { dest.writeInt(colorEntry.getKey()); Integer population = mAllColors.get(colorEntry.getValue()); int populationInt = (population != null) ? population : 0; dest.writeInt(populationInt); } } dest.writeInt(mColorHints); } Loading Loading @@ -476,12 +486,13 @@ public final class WallpaperColors implements Parcelable { WallpaperColors other = (WallpaperColors) o; return mMainColors.equals(other.mMainColors) && mAllColors.equals(other.mAllColors) && mColorHints == other.mColorHints; } @Override public int hashCode() { return 31 * mMainColors.hashCode() + mColorHints; return (31 * mMainColors.hashCode() * mAllColors.hashCode()) + mColorHints; } /** Loading tests/Internal/src/android/app/WallpaperColorsTest.java +23 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.os.Parcel; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; Loading Loading @@ -106,4 +107,26 @@ public class WallpaperColorsTest { // This would crash: canvas.drawBitmap(image, 0, 0, new Paint()); } /** * Parcelled WallpaperColors object should equal the original. */ @Test public void testParcelUnparcel() { Bitmap image = Bitmap.createBitmap(300, 300, Bitmap.Config.ARGB_8888); WallpaperColors colors = WallpaperColors.fromBitmap(image); Parcel parcel = Parcel.obtain(); colors.writeToParcel(parcel, 0); parcel.setDataPosition(0); WallpaperColors reconstructed = new WallpaperColors(parcel); parcel.recycle(); Assert.assertEquals("WallpaperColors recreated from Parcel should equal original", colors, reconstructed); Assert.assertEquals("getAllColors() on WallpaperColors recreated from Parcel should" + "return the same as the original", colors.getAllColors(), reconstructed.getAllColors()); Assert.assertEquals("getMainColors() on WallpaperColors recreated from Parcel should" + "return the same as the original", colors.getMainColors(), reconstructed.getMainColors()); } } Loading
core/java/android/app/WallpaperColors.java +17 −6 Original line number Diff line number Diff line Loading @@ -111,12 +111,15 @@ public final class WallpaperColors implements Parcelable { public WallpaperColors(Parcel parcel) { mMainColors = new ArrayList<>(); mAllColors = new HashMap<>(); final int count = parcel.readInt(); int count = parcel.readInt(); for (int i = 0; i < count; i++) { final int colorInt = parcel.readInt(); Color color = Color.valueOf(colorInt); mMainColors.add(color); } count = parcel.readInt(); for (int i = 0; i < count; i++) { final int colorInt = parcel.readInt(); final int population = parcel.readInt(); mAllColors.put(colorInt, population); } Loading Loading @@ -411,10 +414,17 @@ public final class WallpaperColors implements Parcelable { for (int i = 0; i < count; i++) { Color color = mainColors.get(i); dest.writeInt(color.toArgb()); Integer population = mAllColors.get(color.toArgb()); } count = mAllColors.size(); dest.writeInt(count); for (Map.Entry<Integer, Integer> colorEntry : mAllColors.entrySet()) { if (colorEntry.getKey() != null) { dest.writeInt(colorEntry.getKey()); Integer population = mAllColors.get(colorEntry.getValue()); int populationInt = (population != null) ? population : 0; dest.writeInt(populationInt); } } dest.writeInt(mColorHints); } Loading Loading @@ -476,12 +486,13 @@ public final class WallpaperColors implements Parcelable { WallpaperColors other = (WallpaperColors) o; return mMainColors.equals(other.mMainColors) && mAllColors.equals(other.mAllColors) && mColorHints == other.mColorHints; } @Override public int hashCode() { return 31 * mMainColors.hashCode() + mColorHints; return (31 * mMainColors.hashCode() * mAllColors.hashCode()) + mColorHints; } /** Loading
tests/Internal/src/android/app/WallpaperColorsTest.java +23 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.os.Parcel; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; Loading Loading @@ -106,4 +107,26 @@ public class WallpaperColorsTest { // This would crash: canvas.drawBitmap(image, 0, 0, new Paint()); } /** * Parcelled WallpaperColors object should equal the original. */ @Test public void testParcelUnparcel() { Bitmap image = Bitmap.createBitmap(300, 300, Bitmap.Config.ARGB_8888); WallpaperColors colors = WallpaperColors.fromBitmap(image); Parcel parcel = Parcel.obtain(); colors.writeToParcel(parcel, 0); parcel.setDataPosition(0); WallpaperColors reconstructed = new WallpaperColors(parcel); parcel.recycle(); Assert.assertEquals("WallpaperColors recreated from Parcel should equal original", colors, reconstructed); Assert.assertEquals("getAllColors() on WallpaperColors recreated from Parcel should" + "return the same as the original", colors.getAllColors(), reconstructed.getAllColors()); Assert.assertEquals("getMainColors() on WallpaperColors recreated from Parcel should" + "return the same as the original", colors.getMainColors(), reconstructed.getMainColors()); } }