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

View File

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

View File

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