use of com.android.internal.os.BatterySipper in project platform_packages_apps_Settings by BlissRoms.
the class BatteryUtils method removeHiddenBatterySippers.
/**
* Remove the {@link BatterySipper} that we should hide and smear the screen usage based on
* foreground activity time.
*
* @param sippers sipper list that need to check and remove
* @return the total power of the hidden items of {@link BatterySipper}
* for proportional smearing
*/
public double removeHiddenBatterySippers(List<BatterySipper> sippers) {
double proportionalSmearPowerMah = 0;
BatterySipper screenSipper = null;
for (int i = sippers.size() - 1; i >= 0; i--) {
final BatterySipper sipper = sippers.get(i);
if (shouldHideSipper(sipper)) {
sippers.remove(i);
if (sipper.drainType != BatterySipper.DrainType.OVERCOUNTED && sipper.drainType != BatterySipper.DrainType.SCREEN && sipper.drainType != BatterySipper.DrainType.UNACCOUNTED && sipper.drainType != BatterySipper.DrainType.BLUETOOTH && sipper.drainType != BatterySipper.DrainType.WIFI && sipper.drainType != BatterySipper.DrainType.IDLE) {
// Don't add it if it is overcounted, unaccounted, wifi, bluetooth, or screen
proportionalSmearPowerMah += sipper.totalPowerMah;
}
}
if (sipper.drainType == BatterySipper.DrainType.SCREEN) {
screenSipper = sipper;
}
}
smearScreenBatterySipper(sippers, screenSipper);
return proportionalSmearPowerMah;
}
use of com.android.internal.os.BatterySipper in project platform_packages_apps_Settings by BlissRoms.
the class BatteryEntryTest method createSipperForApp.
private BatterySipper createSipperForApp() {
BatterySipper sipper = new BatterySipper(DrainType.APP, new FakeUid(APP_UID), 0);
sipper.packageWithHighestDrain = HIGH_DRAIN_PACKAGE;
return sipper;
}
use of com.android.internal.os.BatterySipper in project platform_packages_apps_Settings by BlissRoms.
the class BatteryUtilsTest method testSmearScreenBatterySipper.
@Test
public void testSmearScreenBatterySipper() {
final BatterySipper sipperNull = createTestSmearBatterySipper(TIME_FOREGROUND_ZERO, BATTERY_APP_USAGE, 0, /* uid */
true);
final BatterySipper sipperBg = createTestSmearBatterySipper(TIME_FOREGROUND_ZERO, BATTERY_APP_USAGE, 1, /* uid */
false);
final BatterySipper sipperFg = createTestSmearBatterySipper(TIME_FOREGROUND, BATTERY_APP_USAGE, 2, /* uid */
false);
final BatterySipper sipperFg2 = createTestSmearBatterySipper(TIME_FOREGROUND, BATTERY_APP_USAGE, 3, /* uid */
false);
final List<BatterySipper> sippers = new ArrayList<>();
sippers.add(sipperNull);
sippers.add(sipperBg);
sippers.add(sipperFg);
sippers.add(sipperFg2);
mBatteryUtils.smearScreenBatterySipper(sippers, mScreenBatterySipper);
assertThat(sipperNull.totalPowerMah).isWithin(PRECISION).of(BATTERY_APP_USAGE);
assertThat(sipperBg.totalPowerMah).isWithin(PRECISION).of(BATTERY_APP_USAGE);
assertThat(sipperFg.totalPowerMah).isWithin(PRECISION).of(BATTERY_APP_USAGE + BATTERY_SCREEN_USAGE / 2);
assertThat(sipperFg2.totalPowerMah).isWithin(PRECISION).of(BATTERY_APP_USAGE + BATTERY_SCREEN_USAGE / 2);
}
use of com.android.internal.os.BatterySipper in project platform_packages_apps_Settings by BlissRoms.
the class PowerUsageAdvancedTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mShadowContext = spy(RuntimeEnvironment.application);
mPowerUsageAdvanced = spy(new PowerUsageAdvanced());
List<BatterySipper> batterySippers = new ArrayList<>();
batterySippers.add(new BatterySipper(DrainType.APP, new FakeUid(FAKE_UID_1), TYPE_APP_USAGE));
batterySippers.add(new BatterySipper(DrainType.APP, new FakeUid(FAKE_UID_2), TYPE_APP_USAGE));
batterySippers.add(new BatterySipper(DrainType.BLUETOOTH, new FakeUid(FAKE_UID_1), TYPE_BLUETOOTH_USAGE));
batterySippers.add(new BatterySipper(DrainType.WIFI, new FakeUid(FAKE_UID_1), TYPE_WIFI_USAGE));
mDischargingBatteryIntent = BatteryTestUtils.getDischargingIntent();
doReturn(mDischargingBatteryIntent).when(mShadowContext).registerReceiver(any(), any());
when(mBatteryStatsHelper.getStats().getDischargeAmount(anyInt())).thenReturn(DISCHARGE_AMOUNT);
when(mBatteryStatsHelper.getUsageList()).thenReturn(batterySippers);
when(mBatteryStatsHelper.getTotalPower()).thenReturn(TOTAL_USAGE);
when(mPowerUsageAdvanced.getContext()).thenReturn(mShadowContext);
doReturn(STUB_STRING).when(mPowerUsageAdvanced).getString(anyInt(), any(), any());
doReturn(STUB_STRING).when(mPowerUsageAdvanced).getString(anyInt(), any());
doReturn(mShadowContext.getText(R.string.battery_used_for)).when(mPowerUsageAdvanced).getText(R.string.battery_used_for);
mPowerUsageAdvanced.setPackageManager(mPackageManager);
mPowerUsageAdvanced.setPowerUsageFeatureProvider(mPowerUsageFeatureProvider);
mPowerUsageAdvanced.setUserManager(mUserManager);
mPowerUsageAdvanced.setBatteryUtils(BatteryUtils.getInstance(mShadowContext));
when(mShadowContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(mConnectivityManager);
mPowerUsageData = new PowerUsageData(UsageType.USER);
mMaxBatterySipper.totalPowerMah = TYPE_BLUETOOTH_USAGE;
mMaxBatterySipper.drainType = DrainType.BLUETOOTH;
mNormalBatterySipper.drainType = DrainType.SCREEN;
}
use of com.android.internal.os.BatterySipper in project android_packages_apps_Settings by omnirom.
the class BatteryEntryTest method createSipperForSystem.
private BatterySipper createSipperForSystem() {
BatterySipper sipper = new BatterySipper(DrainType.APP, new FakeUid(SYSTEM_UID), 0);
sipper.packageWithHighestDrain = HIGH_DRAIN_PACKAGE;
sipper.mPackages = SYSTEM_PACKAGES;
return sipper;
}
Aggregations