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;
}
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);
}
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);
}
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);
}
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;
}
Aggregations