use of com.android.settings.fuelgauge.PowerUsageAdvanced.PowerUsageData in project android_packages_apps_Settings by DirtyUnicorns.
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.settings.fuelgauge.PowerUsageAdvanced.PowerUsageData in project android_packages_apps_Settings by DirtyUnicorns.
the class PowerUsageAdvancedTest method testCalculateHiddenPower_returnCorrectPower.
@Test
public void testCalculateHiddenPower_returnCorrectPower() {
List<PowerUsageData> powerUsageDataList = new ArrayList<>();
final double unaccountedPower = 100;
final double normalPower = 150;
powerUsageDataList.add(new PowerUsageData(UsageType.UNACCOUNTED, unaccountedPower));
powerUsageDataList.add(new PowerUsageData(UsageType.APP, normalPower));
powerUsageDataList.add(new PowerUsageData(UsageType.CELL, normalPower));
assertThat(mPowerUsageAdvanced.calculateHiddenPower(powerUsageDataList)).isWithin(PRECISION).of(unaccountedPower);
}
use of com.android.settings.fuelgauge.PowerUsageAdvanced.PowerUsageData in project android_packages_apps_Settings by DirtyUnicorns.
the class PowerUsageAdvancedTest method testPowerUsageData_SortedByUsage.
@Test
public void testPowerUsageData_SortedByUsage() {
List<PowerUsageData> dataList = new ArrayList<>();
dataList.add(new PowerUsageData(UsageType.WIFI, TYPE_WIFI_USAGE));
dataList.add(new PowerUsageData(UsageType.BLUETOOTH, TYPE_BLUETOOTH_USAGE));
dataList.add(new PowerUsageData(UsageType.APP, TYPE_APP_USAGE));
Collections.sort(dataList);
for (int i = 1, size = dataList.size(); i < size; i++) {
assertThat(dataList.get(i - 1).totalPowerMah).isAtLeast(dataList.get(i).totalPowerMah);
}
}
use of com.android.settings.fuelgauge.PowerUsageAdvanced.PowerUsageData in project android_packages_apps_Settings by DirtyUnicorns.
the class PowerUsageAdvancedTest method testParsePowerUsageData_PercentageCalculatedCorrectly.
@Test
public void testParsePowerUsageData_PercentageCalculatedCorrectly() {
final double percentApp = TYPE_APP_USAGE * 2 / TOTAL_USAGE * DISCHARGE_AMOUNT;
final double percentWifi = TYPE_WIFI_USAGE / TOTAL_USAGE * DISCHARGE_AMOUNT;
final double percentBluetooth = TYPE_BLUETOOTH_USAGE / TOTAL_USAGE * DISCHARGE_AMOUNT;
List<PowerUsageData> batteryData = mPowerUsageAdvanced.parsePowerUsageData(mBatteryStatsHelper);
for (PowerUsageData data : batteryData) {
switch(data.usageType) {
case UsageType.WIFI:
assertThat(data.percentage).isWithin(PRECISION).of(percentWifi);
break;
case UsageType.APP:
assertThat(data.percentage).isWithin(PRECISION).of(percentApp);
break;
case UsageType.BLUETOOTH:
assertThat(data.percentage).isWithin(PRECISION).of(percentBluetooth);
break;
default:
break;
}
}
}
use of com.android.settings.fuelgauge.PowerUsageAdvanced.PowerUsageData in project android_packages_apps_Settings by crdroidandroid.
the class PowerUsageAdvancedTest method testPowerUsageData_SortedByUsage.
@Test
public void testPowerUsageData_SortedByUsage() {
List<PowerUsageData> dataList = new ArrayList<>();
dataList.add(new PowerUsageData(UsageType.WIFI, TYPE_WIFI_USAGE));
dataList.add(new PowerUsageData(UsageType.BLUETOOTH, TYPE_BLUETOOTH_USAGE));
dataList.add(new PowerUsageData(UsageType.APP, TYPE_APP_USAGE));
Collections.sort(dataList);
for (int i = 1, size = dataList.size(); i < size; i++) {
assertThat(dataList.get(i - 1).totalPowerMah).isAtLeast(dataList.get(i).totalPowerMah);
}
}
Aggregations