From a01f48681cdaf34e0943609683d0bbb26e761a58 Mon Sep 17 00:00:00 2001 From: Filip Gruszczynski Date: Tue, 4 Aug 2015 14:46:33 -0700 Subject: [PATCH] Make ResourceKey always use non-null configuration override. We don't differentiate between null conifguration and Configuration.EMPTY, but if ResourceKey uses both, it will produce different hashes and won't be equal. This CL makes ResourceKey always hold a non null reference to the Configuration object. We started delivering the configuration overrides in Ib2c7be0b427f5ce05e7a362bcdd496ddbc9164f0, which changed behavior from using always null, to using both null and Conifguration.EMPTY for empty confgiuration. Now we will switch to using only one value, which is Configuration.EMPTY. Bug: 22620824 Change-Id: I090fd90ac21a6b3ebc7f2974a91dd7c861af10d7 --- .../android/content/res/ResourcesKey.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/core/java/android/content/res/ResourcesKey.java b/core/java/android/content/res/ResourcesKey.java index 9548d49af418c..26205718c44d9 100644 --- a/core/java/android/content/res/ResourcesKey.java +++ b/core/java/android/content/res/ResourcesKey.java @@ -16,6 +16,8 @@ package android.content.res; +import android.annotation.NonNull; + import java.util.Objects; /** @hide */ @@ -25,27 +27,27 @@ public final class ResourcesKey { private final int mHash; public final int mDisplayId; + @NonNull public final Configuration mOverrideConfiguration; public ResourcesKey(String resDir, int displayId, Configuration overrideConfiguration, float scale) { mResDir = resDir; mDisplayId = displayId; - mOverrideConfiguration = overrideConfiguration; + mOverrideConfiguration = overrideConfiguration != null + ? overrideConfiguration : Configuration.EMPTY; mScale = scale; int hash = 17; hash = 31 * hash + (mResDir == null ? 0 : mResDir.hashCode()); hash = 31 * hash + mDisplayId; - hash = 31 * hash + (mOverrideConfiguration != null - ? mOverrideConfiguration.hashCode() : 0); + hash = 31 * hash + mOverrideConfiguration.hashCode(); hash = 31 * hash + Float.floatToIntBits(mScale); mHash = hash; } public boolean hasOverrideConfiguration() { - return mOverrideConfiguration != null - && !Configuration.EMPTY.equals(mOverrideConfiguration); + return !Configuration.EMPTY.equals(mOverrideConfiguration); } @Override @@ -66,13 +68,8 @@ public final class ResourcesKey { if (mDisplayId != peer.mDisplayId) { return false; } - if (mOverrideConfiguration != peer.mOverrideConfiguration) { - if (mOverrideConfiguration == null || peer.mOverrideConfiguration == null) { - return false; - } - if (!mOverrideConfiguration.equals(peer.mOverrideConfiguration)) { - return false; - } + if (!mOverrideConfiguration.equals(peer.mOverrideConfiguration)) { + return false; } if (mScale != peer.mScale) { return false;