Try to recycle prefs in battery summary

Bug: 27404159
Change-Id: I5a71413f22e14b8300b6821da661a613392a06e0
This commit is contained in:
Jason Monk
2016-03-16 15:52:35 -04:00
parent 30ab199536
commit 0d6a574100

View File

@@ -28,6 +28,7 @@ import android.os.Process;
import android.os.UserHandle; import android.os.UserHandle;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceGroup; import android.support.v7.preference.PreferenceGroup;
import android.text.TextUtils;
import android.util.SparseArray; import android.util.SparseArray;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.Menu; import android.view.Menu;
@@ -167,10 +168,15 @@ public class PowerUsageSummary extends PowerUsageBase {
} }
private void addNotAvailableMessage() { private void addNotAvailableMessage() {
Preference notAvailable = new Preference(getPrefContext()); final String NOT_AVAILABLE = "not_available";
Preference notAvailable = getCachedPreference(NOT_AVAILABLE);
if (notAvailable == null) {
notAvailable = new Preference(getPrefContext());
notAvailable.setKey(NOT_AVAILABLE);
notAvailable.setTitle(R.string.power_usage_not_available); notAvailable.setTitle(R.string.power_usage_not_available);
mAppListGroup.addPreference(notAvailable); mAppListGroup.addPreference(notAvailable);
} }
}
private static boolean isSharedGid(int uid) { private static boolean isSharedGid(int uid) {
return UserHandle.getAppIdFromSharedAppGid(uid) > 0; return UserHandle.getAppIdFromSharedAppGid(uid) > 0;
@@ -274,7 +280,7 @@ public class PowerUsageSummary extends PowerUsageBase {
super.refreshStats(); super.refreshStats();
PowerWhitelistBackend powerWhiteist = PowerWhitelistBackend.getInstance(); PowerWhitelistBackend powerWhiteist = PowerWhitelistBackend.getInstance();
updatePreference(mHistPref); updatePreference(mHistPref);
mAppListGroup.removeAll(); cacheRemoveAllPrefs(mAppListGroup);
mAppListGroup.setOrderingAsAdded(false); mAppListGroup.setOrderingAsAdded(false);
boolean addedSome = false; boolean addedSome = false;
@@ -336,8 +342,16 @@ public class PowerUsageSummary extends PowerUsageBase {
userHandle); userHandle);
final CharSequence contentDescription = mUm.getBadgedLabelForUser(entry.getLabel(), final CharSequence contentDescription = mUm.getBadgedLabelForUser(entry.getLabel(),
userHandle); userHandle);
final PowerGaugePreference pref = new PowerGaugePreference(getPrefContext(), final String key = sipper.drainType == DrainType.APP ? sipper.getPackages() != null
badgedIcon, contentDescription, entry); ? TextUtils.concat(sipper.getPackages()).toString()
: String.valueOf(sipper.getUid())
: sipper.drainType.toString();
PowerGaugePreference pref = (PowerGaugePreference) getCachedPreference(key);
if (pref == null) {
pref = new PowerGaugePreference(getPrefContext(), badgedIcon,
contentDescription, entry);
pref.setKey(key);
}
final double percentOfMax = (sipper.totalPowerMah * 100) final double percentOfMax = (sipper.totalPowerMah * 100)
/ mStatsHelper.getMaxPower(); / mStatsHelper.getMaxPower();
@@ -368,6 +382,7 @@ public class PowerUsageSummary extends PowerUsageBase {
if (!addedSome) { if (!addedSome) {
addNotAvailableMessage(); addNotAvailableMessage();
} }
removeCachedPrefs(mAppListGroup);
BatteryEntry.startRequestQueue(); BatteryEntry.startRequestQueue();
} }