Actually use the cache for names and icons.
Fixes the flashes in name and icon in Battery usage screen when refreshing. Bug: 8219466 Some earlier refactoring must have messed up the cache's scope. It will now avoid reloading name and icon if already present in the cache. Change-Id: I99c1f14dd53828dcb74cf12c02c47628e2e64d30
This commit is contained in:
@@ -32,7 +32,8 @@ import java.util.HashMap;
|
||||
|
||||
class BatterySipper implements Comparable<BatterySipper> {
|
||||
final Context mContext;
|
||||
final HashMap<String,UidToDetail> mUidCache = new HashMap<String,UidToDetail>();
|
||||
/* Cache cleared when PowerUsageSummary is destroyed */
|
||||
static final HashMap<String,UidToDetail> sUidCache = new HashMap<String,UidToDetail>();
|
||||
final ArrayList<BatterySipper> mRequestQueue;
|
||||
final Handler mHandler;
|
||||
String name;
|
||||
@@ -99,8 +100,8 @@ class BatterySipper implements Comparable<BatterySipper> {
|
||||
void getQuickNameIconForUid(Uid uidObj) {
|
||||
final int uid = uidObj.getUid();
|
||||
final String uidString = Integer.toString(uid);
|
||||
if (mUidCache.containsKey(uidString)) {
|
||||
UidToDetail utd = mUidCache.get(uidString);
|
||||
if (sUidCache.containsKey(uidString)) {
|
||||
UidToDetail utd = sUidCache.get(uidString);
|
||||
defaultPackageName = utd.packageName;
|
||||
name = utd.name;
|
||||
icon = utd.icon;
|
||||
@@ -193,7 +194,7 @@ class BatterySipper implements Comparable<BatterySipper> {
|
||||
utd.name = name;
|
||||
utd.icon = icon;
|
||||
utd.packageName = defaultPackageName;
|
||||
mUidCache.put(uidString, utd);
|
||||
sUidCache.put(uidString, utd);
|
||||
mHandler.sendMessage(mHandler.obtainMessage(PowerUsageSummary.MSG_UPDATE_NAME_ICON, this));
|
||||
}
|
||||
}
|
@@ -178,6 +178,8 @@ public class PowerUsageSummary extends PreferenceFragment implements Runnable {
|
||||
super.onDestroy();
|
||||
if (getActivity().isChangingConfigurations()) {
|
||||
sStatsXfer = mStats;
|
||||
} else {
|
||||
BatterySipper.sUidCache.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user