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
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user