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

am: 65afc6f86b

Change-Id: Ie4169d421e4c31e0e4eb780a9b1c8b3921db3fd4
This commit is contained in:
Lei Yu
2017-06-21 01:02:56 +00:00
committed by android-build-merger
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;

View File

@@ -15,16 +15,14 @@
*/
package com.android.settings.fuelgauge;
import android.view.View;
import java.util.List;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
import android.app.LoaderManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.content.ContentResolver;
import android.os.PowerManager;
import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceScreen;
import android.text.TextUtils;
import android.text.format.DateUtils;
@@ -32,6 +30,7 @@ import android.util.SparseArray;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import com.android.internal.logging.nano.MetricsProto;
@@ -58,6 +57,8 @@ import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
import java.util.ArrayList;
@@ -148,6 +149,8 @@ public class PowerUsageSummaryTest {
private ContentResolver mContentResolver;
@Mock
private PreferenceScreen mPreferenceScreen;
@Mock
private PreferenceGroup mAppListGroup;
private List<BatterySipper> mUsageList;
private Context mRealContext;
@@ -215,6 +218,7 @@ public class PowerUsageSummaryTest {
mFragment.mScreenUsagePref = mScreenUsagePref;
mFragment.mLastFullChargePref = mLastFullChargePref;
mFragment.mBatteryUtils = spy(new BatteryUtils(mRealContext));
mFragment.mAppListGroup = mAppListGroup;
}
@Test
@@ -493,6 +497,20 @@ public class PowerUsageSummaryTest {
assertThat(mFragment.mShowAllApps).isTrue();
}
@Test
public void testRefreshAnomalyIcon_containsAnomaly_showAnomalyIcon() {
PowerGaugePreference preference = new PowerGaugePreference(mRealContext);
final String key = mFragment.extractKeyFromUid(UID);
preference.setKey(key);
doReturn(preference).when(mAppListGroup).findPreference(key);
mFragment.mAnomalySparseArray = new SparseArray<>();
mFragment.mAnomalySparseArray.append(UID, null);
mFragment.refreshAnomalyIcon();
assertThat(preference.showAnomalyIcon()).isTrue();
}
public static class TestFragment extends PowerUsageSummary {
private Context mContext;