summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorSantiago Etchebehere <santie@google.com>2021-06-18 15:58:14 -0700
committerSantiago Etchebehere <santie@google.com>2021-06-18 16:56:30 -0700
commit3af6019b81980edce9eb00be657f6a3aade8dc82 (patch)
treec86d65c27f5ff8646eef25778bdb1fdcf5c36a71 /core/java/android
parent5001447b8634dc3a00c02677db300e40c93aceaf (diff)
Update serialization of WallpaperColors
Do not assume mMainColors and mAllColors contain the same color since recent changes modified that. Update equals and hashCode as well to account for this. Bug: 191391779 Bug: 191374703 Test: atest WallpaperColorsTest Change-Id: I8c7775055a2360ec3a91cee76a42d14a143ec7fb
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/app/WallpaperColors.java23
1 files changed, 17 insertions, 6 deletions
diff --git a/core/java/android/app/WallpaperColors.java b/core/java/android/app/WallpaperColors.java
index cd82deb13e9b..2777a7aae517 100644
--- a/core/java/android/app/WallpaperColors.java
+++ b/core/java/android/app/WallpaperColors.java
@@ -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);
}
@@ -411,9 +414,16 @@ 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());
- int populationInt = (population != null) ? population : 0;
- dest.writeInt(populationInt);
+ }
+ 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);
}
@@ -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;
}
/**