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