Merge "Only update anomaly icon in AnomalyLoader" into oc-dr1-dev

This commit is contained in:
Lei Yu
2017-06-21 00:51:30 +00:00
committed by Android (Google) Code Review
3 changed files with 48 additions and 7 deletions

View File

@@ -25,6 +25,7 @@ import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.android.settings.R;
import com.android.settings.TintablePreference;
import com.android.settings.Utils;
@@ -96,6 +97,10 @@ public class PowerGaugePreference extends TintablePreference {
notifyChanged();
}
public boolean showAnomalyIcon() {
return mShowAnomalyIcon;
}
BatteryEntry getInfo() {
return mInfo;
}

View File

@@ -129,8 +129,9 @@ public class PowerUsageSummary extends PowerUsageBase implements
*/
@VisibleForTesting
SparseArray<List<Anomaly>> mAnomalySparseArray;
@VisibleForTesting
PreferenceGroup mAppListGroup;
private BatteryHeaderPreferenceController mBatteryHeaderPreferenceController;
private PreferenceGroup mAppListGroup;
private AnomalySummaryPreferenceController mAnomalySummaryPreferenceController;
private int mStatsType = BatteryStats.STATS_SINCE_CHARGED;
@@ -148,7 +149,7 @@ public class PowerUsageSummary extends PowerUsageBase implements
mAnomalySummaryPreferenceController.updateAnomalySummaryPreference(data);
updateAnomalySparseArray(data);
refreshAppListGroup();
refreshAnomalyIcon();
}
@Override
@@ -619,7 +620,7 @@ public class PowerUsageSummary extends PowerUsageBase implements
pref.setTitle(entry.getLabel());
pref.setOrder(i + 1);
pref.setPercent(percentOfTotal);
pref.shouldShowAnomalyIcon(mAnomalySparseArray.get(sipper.getUid()) != null);
pref.shouldShowAnomalyIcon(false);
if (sipper.usageTimeMs == 0 && sipper.drainType == DrainType.APP) {
sipper.usageTimeMs = mBatteryUtils.getProcessTimeMs(
BatteryUtils.StatusType.FOREGROUND, sipper.uidObj, mStatsType);
@@ -646,6 +647,18 @@ public class PowerUsageSummary extends PowerUsageBase implements
BatteryEntry.startRequestQueue();
}
@VisibleForTesting
void refreshAnomalyIcon() {
for (int i = 0, size = mAnomalySparseArray.size(); i < size; i++) {
final String key = extractKeyFromUid(mAnomalySparseArray.keyAt(i));
final PowerGaugePreference pref = (PowerGaugePreference) mAppListGroup.findPreference(
key);
if (pref != null) {
pref.shouldShowAnomalyIcon(true);
}
}
}
@VisibleForTesting
void initAnomalyDetectionIfPossible() {
if (mPowerFeatureProvider.isAnomalyDetectionEnabled()) {
@@ -714,7 +727,7 @@ public class PowerUsageSummary extends PowerUsageBase implements
@VisibleForTesting
String extractKeyFromSipper(BatterySipper sipper) {
if (sipper.uidObj != null) {
return Integer.toString(sipper.getUid());
return extractKeyFromUid(sipper.getUid());
} else if (sipper.drainType != DrainType.APP) {
return sipper.drainType.toString();
} else if (sipper.getPackages() != null) {
@@ -725,6 +738,11 @@ public class PowerUsageSummary extends PowerUsageBase implements
}
}
@VisibleForTesting
String extractKeyFromUid(int uid) {
return Integer.toString(uid);
}
@VisibleForTesting
void setBatteryLayoutPreference(LayoutPreference layoutPreference) {
mBatteryLayoutPref = layoutPreference;