Search in sources :

Example 96 with BatterySipper

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

the class BluetoothScanAnomalyDetector method detectAnomalies.

@Override
public List<Anomaly> detectAnomalies(BatteryStatsHelper batteryStatsHelper, String targetPackageName) {
    final List<BatterySipper> batterySippers = batteryStatsHelper.getUsageList();
    final List<Anomaly> anomalies = new ArrayList<>();
    final int targetUid = mBatteryUtils.getPackageUid(targetPackageName);
    final long elapsedRealtimeMs = SystemClock.elapsedRealtime();
    for (int i = 0, size = batterySippers.size(); i < size; i++) {
        final BatterySipper sipper = batterySippers.get(i);
        final BatteryStats.Uid uid = sipper.uidObj;
        if (uid == null || mBatteryUtils.shouldHideSipper(sipper) || (targetUid != BatteryUtils.UID_NULL && targetUid != uid.getUid())) {
            continue;
        }
        final long bluetoothTimeMs = getBluetoothUnoptimizedBgTimeMs(uid, elapsedRealtimeMs);
        if (bluetoothTimeMs > mBluetoothScanningThreshold) {
            final String packageName = mBatteryUtils.getPackageName(uid.getUid());
            final CharSequence displayName = Utils.getApplicationLabel(mContext, packageName);
            Anomaly anomaly = new Anomaly.Builder().setUid(uid.getUid()).setType(Anomaly.AnomalyType.BLUETOOTH_SCAN).setDisplayName(displayName).setPackageName(packageName).setBluetoothScanningTimeMs(bluetoothTimeMs).build();
            if (mAnomalyUtils.getAnomalyAction(anomaly).isActionActive(anomaly)) {
                anomalies.add(anomaly);
            }
        }
    }
    return anomalies;
}
Also used : BatterySipper(com.android.internal.os.BatterySipper) ArrayList(java.util.ArrayList) Anomaly(com.android.settings.fuelgauge.anomaly.Anomaly) BatteryStats(android.os.BatteryStats)

Example 97 with BatterySipper

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

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

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

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

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

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

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

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)

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