summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2015-08-05 20:22:21 (GMT)
committerSunny Goyal <sunnygoyal@google.com>2015-08-05 20:23:25 (GMT)
commita2a039b66f05a1164f954387b1c12a8fb4063e92 (patch)
tree75a6e1ae8d6e83c08ec57f4d9ff52bb6d82b57f6
parentd1ea63f24a751521e6c35cc06be0e548e0b04f23 (diff)
downloadandroid_packages_apps_Trebuchet-a2a039b66f05a1164f954387b1c12a8fb4063e92.zip
android_packages_apps_Trebuchet-a2a039b66f05a1164f954387b1c12a8fb4063e92.tar.gz
android_packages_apps_Trebuchet-a2a039b66f05a1164f954387b1c12a8fb4063e92.tar.bz2
Using a reverse hashmap instead of indexOfValue in userManager
Bug: 22980139 Change-Id: I87b633d194ff4e1529dd679dc02da573ed374207
-rw-r--r--src/com/android/launcher3/WidgetPreviewLoader.java11
-rw-r--r--src/com/android/launcher3/compat/UserManagerCompatV17.java19
-rw-r--r--src/com/android/launcher3/compat/UserManagerCompatVL.java14
3 files changed, 23 insertions, 21 deletions
diff --git a/src/com/android/launcher3/WidgetPreviewLoader.java b/src/com/android/launcher3/WidgetPreviewLoader.java
index 1fb795a..3d50587 100644
--- a/src/com/android/launcher3/WidgetPreviewLoader.java
+++ b/src/com/android/launcher3/WidgetPreviewLoader.java
@@ -212,7 +212,6 @@ public class WidgetPreviewLoader {
public void removeObsoletePreviews(ArrayList<Object> list) {
Utilities.assertWorkerThread();
- LongSparseArray<UserHandleCompat> userIdCache = new LongSparseArray<>();
LongSparseArray<HashSet<String>> validPackages = new LongSparseArray<>();
for (Object obj : list) {
@@ -227,15 +226,7 @@ public class WidgetPreviewLoader {
pkg = info.provider.getPackageName();
}
- int userIdIndex = userIdCache.indexOfValue(user);
- final long userId;
- if (userIdIndex < 0) {
- userId = mUserManager.getSerialNumberForUser(user);
- userIdCache.put(userId, user);
- } else {
- userId = userIdCache.keyAt(userIdIndex);
- }
-
+ final long userId = mUserManager.getSerialNumberForUser(user);
HashSet<String> packages = validPackages.get(userId);
if (packages == null) {
packages = new HashSet<>();
diff --git a/src/com/android/launcher3/compat/UserManagerCompatV17.java b/src/com/android/launcher3/compat/UserManagerCompatV17.java
index 1687569..75203b7 100644
--- a/src/com/android/launcher3/compat/UserManagerCompatV17.java
+++ b/src/com/android/launcher3/compat/UserManagerCompatV17.java
@@ -23,10 +23,16 @@ import android.os.UserManager;
import com.android.launcher3.util.LongArrayMap;
+import java.util.HashMap;
+
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public class UserManagerCompatV17 extends UserManagerCompatV16 {
protected LongArrayMap<UserHandleCompat> mUsers;
+ // Create a separate reverse map as LongArrayMap.indexOfValue checks if objects are same
+ // and not {@link Object#equals}
+ protected HashMap<UserHandleCompat, Long> mUserToSerialMap;
+
protected UserManager mUserManager;
UserManagerCompatV17(Context context) {
@@ -35,9 +41,9 @@ public class UserManagerCompatV17 extends UserManagerCompatV16 {
public long getSerialNumberForUser(UserHandleCompat user) {
synchronized (this) {
- if (mUsers != null) {
- int index = mUsers.indexOfValue(user);
- return (index >= 0) ? mUsers.keyAt(index) : 0;
+ if (mUserToSerialMap != null) {
+ Long serial = mUserToSerialMap.get(user);
+ return serial == null ? 0 : serial;
}
}
return mUserManager.getSerialNumberForUser(user.getUser());
@@ -55,9 +61,12 @@ public class UserManagerCompatV17 extends UserManagerCompatV16 {
@Override
public void enableAndResetCache() {
synchronized (this) {
- mUsers = new LongArrayMap<UserHandleCompat>();
+ mUsers = new LongArrayMap<>();
+ mUserToSerialMap = new HashMap<>();
UserHandleCompat myUser = UserHandleCompat.myUserHandle();
- mUsers.put(mUserManager.getSerialNumberForUser(myUser.getUser()), myUser);
+ long serial = mUserManager.getSerialNumberForUser(myUser.getUser());
+ mUsers.put(serial, myUser);
+ mUserToSerialMap.put(myUser, serial);
}
}
}
diff --git a/src/com/android/launcher3/compat/UserManagerCompatVL.java b/src/com/android/launcher3/compat/UserManagerCompatVL.java
index 04cd0fd..4d404db 100644
--- a/src/com/android/launcher3/compat/UserManagerCompatVL.java
+++ b/src/com/android/launcher3/compat/UserManagerCompatVL.java
@@ -30,6 +30,7 @@ import com.android.launcher3.util.LongArrayMap;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@@ -48,12 +49,15 @@ public class UserManagerCompatVL extends UserManagerCompatV17 {
@Override
public void enableAndResetCache() {
synchronized (this) {
- mUsers = new LongArrayMap<UserHandleCompat>();
+ mUsers = new LongArrayMap<>();
+ mUserToSerialMap = new HashMap<>();
List<UserHandle> users = mUserManager.getUserProfiles();
if (users != null) {
for (UserHandle user : users) {
- mUsers.put(mUserManager.getSerialNumberForUser(user),
- UserHandleCompat.fromUser(user));
+ long serial = mUserManager.getSerialNumberForUser(user);
+ UserHandleCompat userCompat = UserHandleCompat.fromUser(user);
+ mUsers.put(serial, userCompat);
+ mUserToSerialMap.put(userCompat, serial);
}
}
}
@@ -64,9 +68,7 @@ public class UserManagerCompatVL extends UserManagerCompatV17 {
synchronized (this) {
if (mUsers != null) {
List<UserHandleCompat> users = new ArrayList<>();
- for (UserHandleCompat user : mUsers) {
- users.add(user);
- }
+ users.addAll(mUserToSerialMap.keySet());
return users;
}
}