Loading src/com/android/settings/fuelgauge/PowerUsageSummary.java +12 −2 Original line number Diff line number Diff line Loading @@ -319,7 +319,7 @@ public class PowerUsageSummary extends PowerUsageBase { final int numSippers = usageList.size(); for (int i = 0; i < numSippers; i++) { final BatterySipper sipper = usageList.get(i); if ((sipper.totalPowerMah * SECONDS_IN_HOUR) < MIN_POWER_THRESHOLD_MILLI_AMP) { if (shouldHideSipper(sipper)) { continue; } double totalPower = USE_FAKE_DATA ? 4000 : mStatsHelper.getTotalPower(); Loading Loading @@ -375,7 +375,7 @@ public class PowerUsageSummary extends PowerUsageBase { pref.setTitle(entry.getLabel()); pref.setOrder(i + 1); pref.setPercent(percentOfMax, percentOfTotal); if ((sipper.drainType != DrainType.APP || sipper.uidObj.getUid() == 0) if ((sipper.drainType != DrainType.APP || sipper.uidObj.getUid() == Process.ROOT_UID) && sipper.drainType != DrainType.USER) { pref.setTint(colorControl); } Loading @@ -395,6 +395,16 @@ public class PowerUsageSummary extends PowerUsageBase { BatteryEntry.startRequestQueue(); } @VisibleForTesting boolean shouldHideSipper(BatterySipper sipper) { final DrainType drainType = sipper.drainType; final int uid = sipper.getUid(); return drainType == DrainType.IDLE || drainType == DrainType.CELL || uid == Process.ROOT_UID || uid == Process.SYSTEM_UID || (sipper.totalPowerMah * SECONDS_IN_HOUR) < MIN_POWER_THRESHOLD_MILLI_AMP; } @VisibleForTesting String extractKeyFromSipper(BatterySipper sipper) { if (sipper.uidObj != null) { Loading tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java +36 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.settings.fuelgauge; import android.content.Context; import android.content.Intent; import android.os.Process; import android.text.TextUtils; import android.view.Menu; import android.view.MenuInflater; Loading @@ -28,7 +29,6 @@ import com.android.settings.TestConfig; import com.android.settings.testutils.FakeFeatureFactory; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; import org.mockito.Mock; Loading @@ -52,6 +52,7 @@ import static org.mockito.Mockito.when; public class PowerUsageSummaryTest { private static final String[] PACKAGE_NAMES = {"com.app1", "com.app2"}; private static final int UID = 123; private static final int POWER_MAH = 100; private static final Intent ADDITIONAL_BATTERY_INFO_INTENT = new Intent("com.example.app.ADDITIONAL_BATTERY_INFO"); Loading Loading @@ -96,6 +97,7 @@ public class PowerUsageSummaryTest { when(mBatterySipper.getPackages()).thenReturn(PACKAGE_NAMES); when(mBatterySipper.getUid()).thenReturn(UID); mBatterySipper.totalPowerMah = POWER_MAH; } @Test Loading Loading @@ -152,6 +154,39 @@ public class PowerUsageSummaryTest { assertThat(key).isEqualTo(Integer.toString(mBatterySipper.getUid())); } @Test public void testShouldHideSipper_TypeIdle_ReturnTrue() { mBatterySipper.drainType = BatterySipper.DrainType.IDLE; assertThat(mPowerUsageSummary.shouldHideSipper(mBatterySipper)).isTrue(); } @Test public void testShouldHideSipper_TypeCell_ReturnTrue() { mBatterySipper.drainType = BatterySipper.DrainType.CELL; assertThat(mPowerUsageSummary.shouldHideSipper(mBatterySipper)).isTrue(); } @Test public void testShouldHideSipper_UidRoot_ReturnTrue() { mBatterySipper.drainType = BatterySipper.DrainType.APP; when(mBatterySipper.getUid()).thenReturn(Process.ROOT_UID); assertThat(mPowerUsageSummary.shouldHideSipper(mBatterySipper)).isTrue(); } @Test public void testShouldHideSipper_UidSystem_ReturnTrue() { mBatterySipper.drainType = BatterySipper.DrainType.APP; when(mBatterySipper.getUid()).thenReturn(Process.SYSTEM_UID); assertThat(mPowerUsageSummary.shouldHideSipper(mBatterySipper)).isTrue(); } @Test public void testShouldHideSipper_UidNormal_ReturnFalse() { mBatterySipper.drainType = BatterySipper.DrainType.APP; when(mBatterySipper.getUid()).thenReturn(UID); assertThat(mPowerUsageSummary.shouldHideSipper(mBatterySipper)).isFalse(); } public static class TestFragment extends PowerUsageSummary { private Context mContext; Loading Loading
src/com/android/settings/fuelgauge/PowerUsageSummary.java +12 −2 Original line number Diff line number Diff line Loading @@ -319,7 +319,7 @@ public class PowerUsageSummary extends PowerUsageBase { final int numSippers = usageList.size(); for (int i = 0; i < numSippers; i++) { final BatterySipper sipper = usageList.get(i); if ((sipper.totalPowerMah * SECONDS_IN_HOUR) < MIN_POWER_THRESHOLD_MILLI_AMP) { if (shouldHideSipper(sipper)) { continue; } double totalPower = USE_FAKE_DATA ? 4000 : mStatsHelper.getTotalPower(); Loading Loading @@ -375,7 +375,7 @@ public class PowerUsageSummary extends PowerUsageBase { pref.setTitle(entry.getLabel()); pref.setOrder(i + 1); pref.setPercent(percentOfMax, percentOfTotal); if ((sipper.drainType != DrainType.APP || sipper.uidObj.getUid() == 0) if ((sipper.drainType != DrainType.APP || sipper.uidObj.getUid() == Process.ROOT_UID) && sipper.drainType != DrainType.USER) { pref.setTint(colorControl); } Loading @@ -395,6 +395,16 @@ public class PowerUsageSummary extends PowerUsageBase { BatteryEntry.startRequestQueue(); } @VisibleForTesting boolean shouldHideSipper(BatterySipper sipper) { final DrainType drainType = sipper.drainType; final int uid = sipper.getUid(); return drainType == DrainType.IDLE || drainType == DrainType.CELL || uid == Process.ROOT_UID || uid == Process.SYSTEM_UID || (sipper.totalPowerMah * SECONDS_IN_HOUR) < MIN_POWER_THRESHOLD_MILLI_AMP; } @VisibleForTesting String extractKeyFromSipper(BatterySipper sipper) { if (sipper.uidObj != null) { Loading
tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java +36 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.settings.fuelgauge; import android.content.Context; import android.content.Intent; import android.os.Process; import android.text.TextUtils; import android.view.Menu; import android.view.MenuInflater; Loading @@ -28,7 +29,6 @@ import com.android.settings.TestConfig; import com.android.settings.testutils.FakeFeatureFactory; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; import org.mockito.Mock; Loading @@ -52,6 +52,7 @@ import static org.mockito.Mockito.when; public class PowerUsageSummaryTest { private static final String[] PACKAGE_NAMES = {"com.app1", "com.app2"}; private static final int UID = 123; private static final int POWER_MAH = 100; private static final Intent ADDITIONAL_BATTERY_INFO_INTENT = new Intent("com.example.app.ADDITIONAL_BATTERY_INFO"); Loading Loading @@ -96,6 +97,7 @@ public class PowerUsageSummaryTest { when(mBatterySipper.getPackages()).thenReturn(PACKAGE_NAMES); when(mBatterySipper.getUid()).thenReturn(UID); mBatterySipper.totalPowerMah = POWER_MAH; } @Test Loading Loading @@ -152,6 +154,39 @@ public class PowerUsageSummaryTest { assertThat(key).isEqualTo(Integer.toString(mBatterySipper.getUid())); } @Test public void testShouldHideSipper_TypeIdle_ReturnTrue() { mBatterySipper.drainType = BatterySipper.DrainType.IDLE; assertThat(mPowerUsageSummary.shouldHideSipper(mBatterySipper)).isTrue(); } @Test public void testShouldHideSipper_TypeCell_ReturnTrue() { mBatterySipper.drainType = BatterySipper.DrainType.CELL; assertThat(mPowerUsageSummary.shouldHideSipper(mBatterySipper)).isTrue(); } @Test public void testShouldHideSipper_UidRoot_ReturnTrue() { mBatterySipper.drainType = BatterySipper.DrainType.APP; when(mBatterySipper.getUid()).thenReturn(Process.ROOT_UID); assertThat(mPowerUsageSummary.shouldHideSipper(mBatterySipper)).isTrue(); } @Test public void testShouldHideSipper_UidSystem_ReturnTrue() { mBatterySipper.drainType = BatterySipper.DrainType.APP; when(mBatterySipper.getUid()).thenReturn(Process.SYSTEM_UID); assertThat(mPowerUsageSummary.shouldHideSipper(mBatterySipper)).isTrue(); } @Test public void testShouldHideSipper_UidNormal_ReturnFalse() { mBatterySipper.drainType = BatterySipper.DrainType.APP; when(mBatterySipper.getUid()).thenReturn(UID); assertThat(mPowerUsageSummary.shouldHideSipper(mBatterySipper)).isFalse(); } public static class TestFragment extends PowerUsageSummary { private Context mContext; Loading