Search in sources :

Example 86 with BatterySipper

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

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

Example 87 with BatterySipper

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

the class PowerUsageAdvancedTest method testFindBatterySipperWithMaxBatteryUsage_findCorrectOne.

@Test
public void testFindBatterySipperWithMaxBatteryUsage_findCorrectOne() {
    mPowerUsageData.usageList.add(mNormalBatterySipper);
    mPowerUsageData.usageList.add(mMaxBatterySipper);
    BatterySipper sipper = mPowerUsageAdvanced.findBatterySipperWithMaxBatteryUsage(mPowerUsageData.usageList);
    assertThat(sipper).isEqualTo(mMaxBatterySipper);
}
Also used : BatterySipper(com.android.internal.os.BatterySipper) Test(org.junit.Test)

Example 88 with BatterySipper

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

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 89 with BatterySipper

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

the class AdvancedPowerUsageDetail method startBatteryDetailPage.

@VisibleForTesting
static void startBatteryDetailPage(SettingsActivity caller, BatteryUtils batteryUtils, PreferenceFragment fragment, BatteryStatsHelper helper, int which, BatteryEntry entry, String usagePercent, List<Anomaly> anomalies) {
    // Initialize mStats if necessary.
    helper.getStats();
    final Bundle args = new Bundle();
    final BatterySipper sipper = entry.sipper;
    final BatteryStats.Uid uid = sipper.uidObj;
    final boolean isTypeApp = sipper.drainType == BatterySipper.DrainType.APP;
    final long foregroundTimeMs = isTypeApp ? batteryUtils.getProcessTimeMs(BatteryUtils.StatusType.FOREGROUND, uid, which) : sipper.usageTimeMs;
    final long backgroundTimeMs = isTypeApp ? batteryUtils.getProcessTimeMs(BatteryUtils.StatusType.BACKGROUND, uid, which) : 0;
    if (ArrayUtils.isEmpty(sipper.mPackages)) {
        // populate data for system app
        args.putString(EXTRA_LABEL, entry.getLabel());
        args.putInt(EXTRA_ICON_ID, entry.iconId);
        args.putString(EXTRA_PACKAGE_NAME, null);
    } else {
        // populate data for normal app
        args.putString(EXTRA_PACKAGE_NAME, entry.defaultPackageName != null ? entry.defaultPackageName : sipper.mPackages[0]);
    }
    args.putInt(EXTRA_UID, sipper.getUid());
    args.putLong(EXTRA_BACKGROUND_TIME, backgroundTimeMs);
    args.putLong(EXTRA_FOREGROUND_TIME, foregroundTimeMs);
    args.putString(EXTRA_POWER_USAGE_PERCENT, usagePercent);
    args.putInt(EXTRA_POWER_USAGE_AMOUNT, (int) sipper.totalPowerMah);
    args.putParcelableList(EXTRA_ANOMALY_LIST, anomalies);
    caller.startPreferencePanelAsUser(fragment, AdvancedPowerUsageDetail.class.getName(), args, R.string.battery_details_title, null, new UserHandle(UserHandle.getUserId(sipper.getUid())));
}
Also used : BatterySipper(com.android.internal.os.BatterySipper) Bundle(android.os.Bundle) UserHandle(android.os.UserHandle) BatteryStats(android.os.BatteryStats) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 90 with BatterySipper

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

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;
}
Also used : BatterySipper(com.android.internal.os.BatterySipper)

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