Search in sources :

Example 21 with PowerUsageData

use of com.android.settings.fuelgauge.PowerUsageAdvanced.PowerUsageData in project android_packages_apps_Settings by SudaMod.

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

Example 22 with PowerUsageData

use of com.android.settings.fuelgauge.PowerUsageAdvanced.PowerUsageData in project android_packages_apps_Settings by SudaMod.

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 23 with PowerUsageData

use of com.android.settings.fuelgauge.PowerUsageAdvanced.PowerUsageData in project platform_packages_apps_Settings by BlissRoms.

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;
        }
    }
}
Also used : PowerUsageData(com.android.settings.fuelgauge.PowerUsageAdvanced.PowerUsageData) Test(org.junit.Test)

Example 24 with PowerUsageData

use of com.android.settings.fuelgauge.PowerUsageAdvanced.PowerUsageData in project platform_packages_apps_Settings by BlissRoms.

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

Aggregations

PowerUsageData (com.android.settings.fuelgauge.PowerUsageAdvanced.PowerUsageData)24 ArrayList (java.util.ArrayList)18 Test (org.junit.Test)18 BatterySipper (com.android.internal.os.BatterySipper)6 Before (org.junit.Before)6