summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJing Ji <jji@google.com>2021-08-24 11:42:58 -0700
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-09-01 02:13:58 +0000
commit1a2e96c6f2c3a8a1ea3575a08a57450aae2f6132 (patch)
tree4744424267d85d9a7e7e26e3a0194c1c07b2fb37
parentabefb3fc7f453b15e04a0d09d6b0ef5e3e78f5e0 (diff)
downloadbase-1a2e96c6f2c3a8a1ea3575a08a57450aae2f6132.tar.gz
Use ArrayMap instead of SparseArray to manage the ProviderKey
As the ArrayMap handles the hash code collision properly. Bug: 197647956 Test: atest CtsContentTestCases:android.content.cts Change-Id: Ibb57a22c08b0fa5462505d586d5fb0aaf908c80f (cherry picked from commit 119dd01b497b5e6e25009785ec36c9877675deef)
-rw-r--r--core/java/android/app/ActivityThread.java12
1 files changed, 4 insertions, 8 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index 12b1df44b6f5..fc4bb1a00da5 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -464,11 +464,7 @@ public final class ActivityThread extends ClientTransactionHandler
@Override
public int hashCode() {
- return hashCode(authority, userId);
- }
-
- public static int hashCode(final String auth, final int userIdent) {
- return ((auth != null) ? auth.hashCode() : 0) ^ userIdent;
+ return ((authority != null) ? authority.hashCode() : 0) ^ userId;
}
}
@@ -490,7 +486,7 @@ public final class ActivityThread extends ClientTransactionHandler
// Note we never removes items from this map but that's okay because there are only so many
// users and so many authorities.
@GuardedBy("mGetProviderKeys")
- final SparseArray<ProviderKey> mGetProviderKeys = new SparseArray<>();
+ final ArrayMap<ProviderKey, ProviderKey> mGetProviderKeys = new ArrayMap<>();
final ArrayMap<Activity, ArrayList<OnActivityPausedListener>> mOnPauseListeners
= new ArrayMap<Activity, ArrayList<OnActivityPausedListener>>();
@@ -7016,11 +7012,11 @@ public final class ActivityThread extends ClientTransactionHandler
}
private ProviderKey getGetProviderKey(String auth, int userId) {
- final int key = ProviderKey.hashCode(auth, userId);
+ final ProviderKey key = new ProviderKey(auth, userId);
synchronized (mGetProviderKeys) {
ProviderKey lock = mGetProviderKeys.get(key);
if (lock == null) {
- lock = new ProviderKey(auth, userId);
+ lock = key;
mGetProviderKeys.put(key, lock);
}
return lock;