Search in sources :

Example 1 with UsageType

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

the class PowerUsageAdvanced method extractUsageType.

@VisibleForTesting
@UsageType
int extractUsageType(BatterySipper sipper) {
    final DrainType drainType = sipper.drainType;
    final int uid = sipper.getUid();
    if (drainType == DrainType.WIFI) {
        return UsageType.WIFI;
    } else if (drainType == DrainType.BLUETOOTH) {
        return UsageType.BLUETOOTH;
    } else if (drainType == DrainType.IDLE) {
        return UsageType.IDLE;
    } else if (drainType == DrainType.USER) {
        return UsageType.USER;
    } else if (drainType == DrainType.CELL) {
        return UsageType.CELL;
    } else if (drainType == DrainType.UNACCOUNTED) {
        return UsageType.UNACCOUNTED;
    } else if (drainType == DrainType.OVERCOUNTED) {
        return UsageType.OVERCOUNTED;
    } else if (mPowerUsageFeatureProvider.isTypeSystem(sipper) || mPowerUsageFeatureProvider.isTypeService(sipper)) {
        return UsageType.SYSTEM;
    } else {
        return UsageType.APP;
    }
}
Also used : DrainType(com.android.internal.os.BatterySipper.DrainType) VisibleForTesting(android.support.annotation.VisibleForTesting) UsageType(com.android.settings.fuelgauge.PowerUsageAdvanced.PowerUsageData.UsageType)

Example 2 with UsageType

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

the class PowerUsageAdvanced method parsePowerUsageData.

@VisibleForTesting
List<PowerUsageData> parsePowerUsageData(BatteryStatsHelper statusHelper) {
    final List<BatterySipper> batterySippers = statusHelper.getUsageList();
    final Map<Integer, PowerUsageData> batteryDataMap = new HashMap<>();
    for (@UsageType final Integer type : mUsageTypes) {
        batteryDataMap.put(type, new PowerUsageData(type));
    }
    // Accumulate power usage based on usage type
    for (final BatterySipper sipper : batterySippers) {
        sipper.mPackages = mPackageManager.getPackagesForUid(sipper.getUid());
        final PowerUsageData usageData = batteryDataMap.get(extractUsageType(sipper));
        usageData.totalPowerMah += sipper.totalPowerMah;
        if (sipper.drainType == DrainType.APP && sipper.usageTimeMs != 0) {
            sipper.usageTimeMs = mBatteryUtils.getProcessTimeMs(BatteryUtils.StatusType.FOREGROUND, sipper.uidObj, STATUS_TYPE);
        }
        usageData.totalUsageTimeMs += sipper.usageTimeMs;
        if (shouldShowBatterySipper(sipper)) {
            usageData.usageList.add(sipper);
        }
    }
    final List<PowerUsageData> batteryDataList = new ArrayList<>(batteryDataMap.values());
    final int dischargeAmount = statusHelper.getStats().getDischargeAmount(STATUS_TYPE);
    final double totalPower = statusHelper.getTotalPower();
    final double hiddenPower = calculateHiddenPower(batteryDataList);
    for (final PowerUsageData usageData : batteryDataList) {
        usageData.percentage = mBatteryUtils.calculateBatteryPercent(usageData.totalPowerMah, totalPower, hiddenPower, dischargeAmount);
        updateUsageDataSummary(usageData, totalPower, dischargeAmount);
    }
    Collections.sort(batteryDataList);
    mBatteryDataMap = batteryDataMap;
    return batteryDataList;
}
Also used : BatterySipper(com.android.internal.os.BatterySipper) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UsageType(com.android.settings.fuelgauge.PowerUsageAdvanced.PowerUsageData.UsageType) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 3 with UsageType

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

the class PowerUsageAdvanced method extractUsageType.

@VisibleForTesting
@UsageType
int extractUsageType(BatterySipper sipper) {
    final DrainType drainType = sipper.drainType;
    final int uid = sipper.getUid();
    if (drainType == DrainType.WIFI) {
        return UsageType.WIFI;
    } else if (drainType == DrainType.BLUETOOTH) {
        return UsageType.BLUETOOTH;
    } else if (drainType == DrainType.IDLE) {
        return UsageType.IDLE;
    } else if (drainType == DrainType.USER) {
        return UsageType.USER;
    } else if (drainType == DrainType.CELL) {
        return UsageType.CELL;
    } else if (drainType == DrainType.UNACCOUNTED) {
        return UsageType.UNACCOUNTED;
    } else if (drainType == DrainType.OVERCOUNTED) {
        return UsageType.OVERCOUNTED;
    } else if (mPowerUsageFeatureProvider.isTypeSystem(sipper) || mPowerUsageFeatureProvider.isTypeService(sipper)) {
        return UsageType.SYSTEM;
    } else {
        return UsageType.APP;
    }
}
Also used : DrainType(com.android.internal.os.BatterySipper.DrainType) VisibleForTesting(android.support.annotation.VisibleForTesting) UsageType(com.android.settings.fuelgauge.PowerUsageAdvanced.PowerUsageData.UsageType)

Example 4 with UsageType

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

the class PowerUsageAdvanced method extractUsageType.

@VisibleForTesting
@UsageType
int extractUsageType(BatterySipper sipper) {
    final DrainType drainType = sipper.drainType;
    final int uid = sipper.getUid();
    if (drainType == DrainType.WIFI) {
        return UsageType.WIFI;
    } else if (drainType == DrainType.BLUETOOTH) {
        return UsageType.BLUETOOTH;
    } else if (drainType == DrainType.IDLE) {
        return UsageType.IDLE;
    } else if (drainType == DrainType.USER) {
        return UsageType.USER;
    } else if (drainType == DrainType.CELL) {
        return UsageType.CELL;
    } else if (drainType == DrainType.UNACCOUNTED) {
        return UsageType.UNACCOUNTED;
    } else if (drainType == DrainType.OVERCOUNTED) {
        return UsageType.OVERCOUNTED;
    } else if (mPowerUsageFeatureProvider.isTypeSystem(sipper) || mPowerUsageFeatureProvider.isTypeService(sipper)) {
        return UsageType.SYSTEM;
    } else {
        return UsageType.APP;
    }
}
Also used : DrainType(com.android.internal.os.BatterySipper.DrainType) VisibleForTesting(android.support.annotation.VisibleForTesting) UsageType(com.android.settings.fuelgauge.PowerUsageAdvanced.PowerUsageData.UsageType)

Example 5 with UsageType

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

the class PowerUsageAdvanced method parsePowerUsageData.

@VisibleForTesting
List<PowerUsageData> parsePowerUsageData(BatteryStatsHelper statusHelper) {
    final List<BatterySipper> batterySippers = statusHelper.getUsageList();
    final Map<Integer, PowerUsageData> batteryDataMap = new HashMap<>();
    for (@UsageType final Integer type : mUsageTypes) {
        batteryDataMap.put(type, new PowerUsageData(type));
    }
    // Accumulate power usage based on usage type
    for (final BatterySipper sipper : batterySippers) {
        sipper.mPackages = mPackageManager.getPackagesForUid(sipper.getUid());
        final PowerUsageData usageData = batteryDataMap.get(extractUsageType(sipper));
        usageData.totalPowerMah += sipper.totalPowerMah;
        if (sipper.drainType == DrainType.APP && sipper.usageTimeMs != 0) {
            sipper.usageTimeMs = mBatteryUtils.getProcessTimeMs(BatteryUtils.StatusType.FOREGROUND, sipper.uidObj, STATUS_TYPE);
        }
        usageData.totalUsageTimeMs += sipper.usageTimeMs;
        if (shouldShowBatterySipper(sipper)) {
            usageData.usageList.add(sipper);
        }
    }
    final List<PowerUsageData> batteryDataList = new ArrayList<>(batteryDataMap.values());
    final int dischargeAmount = statusHelper.getStats().getDischargeAmount(STATUS_TYPE);
    final double totalPower = statusHelper.getTotalPower();
    final double hiddenPower = calculateHiddenPower(batteryDataList);
    for (final PowerUsageData usageData : batteryDataList) {
        usageData.percentage = mBatteryUtils.calculateBatteryPercent(usageData.totalPowerMah, totalPower, hiddenPower, dischargeAmount);
        updateUsageDataSummary(usageData, totalPower, dischargeAmount);
    }
    Collections.sort(batteryDataList);
    mBatteryDataMap = batteryDataMap;
    return batteryDataList;
}
Also used : BatterySipper(com.android.internal.os.BatterySipper) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UsageType(com.android.settings.fuelgauge.PowerUsageAdvanced.PowerUsageData.UsageType) VisibleForTesting(android.support.annotation.VisibleForTesting)

Aggregations

VisibleForTesting (android.support.annotation.VisibleForTesting)12 UsageType (com.android.settings.fuelgauge.PowerUsageAdvanced.PowerUsageData.UsageType)12 BatterySipper (com.android.internal.os.BatterySipper)6 DrainType (com.android.internal.os.BatterySipper.DrainType)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6