Search in sources :

Example 31 with BatterySipper

use of com.android.internal.os.BatterySipper in project android_packages_apps_Settings by SudaMod.

the class PowerUsageSummaryTest method testFindBatterySipperByType_findTypeApp.

@Test
public void testFindBatterySipperByType_findTypeApp() {
    BatterySipper sipper = mFragment.findBatterySipperByType(mUsageList, BatterySipper.DrainType.APP);
    assertThat(sipper).isSameAs(mNormalBatterySipper);
}
Also used : BatterySipper(com.android.internal.os.BatterySipper) Test(org.junit.Test)

Example 32 with BatterySipper

use of com.android.internal.os.BatterySipper in project android_packages_apps_Settings by SudaMod.

the class PowerUsageSummaryTest method testFindBatterySipperByType_findTypeScreen.

@Test
public void testFindBatterySipperByType_findTypeScreen() {
    BatterySipper sipper = mFragment.findBatterySipperByType(mUsageList, BatterySipper.DrainType.SCREEN);
    assertThat(sipper).isSameAs(mScreenBatterySipper);
}
Also used : BatterySipper(com.android.internal.os.BatterySipper) Test(org.junit.Test)

Example 33 with BatterySipper

use of com.android.internal.os.BatterySipper in project android_packages_apps_Settings by SudaMod.

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);
}
Also used : BatterySipper(com.android.internal.os.BatterySipper) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 34 with BatterySipper

use of com.android.internal.os.BatterySipper in project android_packages_apps_Settings by SudaMod.

the class BatteryUtilsTest method createTestSmearBatterySipper.

private BatterySipper createTestSmearBatterySipper(long topTime, double totalPowerMah, int uidCode, boolean isUidNull) {
    final BatterySipper sipper = mock(BatterySipper.class);
    sipper.drainType = BatterySipper.DrainType.APP;
    sipper.totalPowerMah = totalPowerMah;
    doReturn(uidCode).when(sipper).getUid();
    if (!isUidNull) {
        final BatteryStats.Uid uid = mock(BatteryStats.Uid.class, RETURNS_DEEP_STUBS);
        doReturn(topTime).when(mBatteryUtils).getProcessTimeMs(eq(BatteryUtils.StatusType.SCREEN_USAGE), eq(uid), anyInt());
        doReturn(uidCode).when(uid).getUid();
        sipper.uidObj = uid;
    }
    return sipper;
}
Also used : BatterySipper(com.android.internal.os.BatterySipper) BatteryStats(android.os.BatteryStats)

Example 35 with BatterySipper

use of com.android.internal.os.BatterySipper in project android_packages_apps_Settings by SudaMod.

the class PowerUsageSummary method getFakeStats.

private static List<BatterySipper> getFakeStats() {
    ArrayList<BatterySipper> stats = new ArrayList<>();
    float use = 5;
    for (DrainType type : DrainType.values()) {
        if (type == DrainType.APP) {
            continue;
        }
        stats.add(new BatterySipper(type, null, use));
        use += 5;
    }
    for (int i = 0; i < 100; i++) {
        stats.add(new BatterySipper(DrainType.APP, new FakeUid(Process.FIRST_APPLICATION_UID + i), use));
    }
    stats.add(new BatterySipper(DrainType.APP, new FakeUid(0), use));
    // Simulate dex2oat process.
    BatterySipper sipper = new BatterySipper(DrainType.APP, new FakeUid(UserHandle.getSharedAppGid(Process.FIRST_APPLICATION_UID)), 10.0f);
    sipper.packageWithHighestDrain = "dex2oat";
    stats.add(sipper);
    sipper = new BatterySipper(DrainType.APP, new FakeUid(UserHandle.getSharedAppGid(Process.FIRST_APPLICATION_UID + 1)), 10.0f);
    sipper.packageWithHighestDrain = "dex2oat";
    stats.add(sipper);
    sipper = new BatterySipper(DrainType.APP, new FakeUid(UserHandle.getSharedAppGid(Process.LOG_UID)), 9.0f);
    stats.add(sipper);
    return stats;
}
Also used : DrainType(com.android.internal.os.BatterySipper.DrainType) BatterySipper(com.android.internal.os.BatterySipper) ArrayList(java.util.ArrayList)

Aggregations

BatterySipper (com.android.internal.os.BatterySipper)148 ArrayList (java.util.ArrayList)60 BatteryStats (android.os.BatteryStats)48 VisibleForTesting (android.support.annotation.VisibleForTesting)30 Test (org.junit.Test)29 Anomaly (com.android.settings.fuelgauge.anomaly.Anomaly)18 HashMap (java.util.HashMap)16 UserHandle (android.os.UserHandle)15 ArrayMap (android.util.ArrayMap)10 BatteryStatsHelper (com.android.internal.os.BatteryStatsHelper)10 Map (java.util.Map)10 Drawable (android.graphics.drawable.Drawable)8 SparseArray (android.util.SparseArray)8 DrainType (com.android.internal.os.BatterySipper.DrainType)8 PowerProfile (com.android.internal.os.PowerProfile)8 Bundle (android.os.Bundle)7 SparseLongArray (android.util.SparseLongArray)7 Context (android.content.Context)6 TypedArray (android.content.res.TypedArray)6 PowerUsageData (com.android.settings.fuelgauge.PowerUsageAdvanced.PowerUsageData)6