Search in sources :

Example 36 with BatterySipper

use of com.android.internal.os.BatterySipper in project android_packages_apps_Settings by SudaMod.

the class PowerUsageSummary method updateScreenPreference.

@VisibleForTesting
void updateScreenPreference() {
    final BatterySipper sipper = findBatterySipperByType(mStatsHelper.getUsageList(), DrainType.SCREEN);
    final long usageTimeMs = sipper != null ? sipper.usageTimeMs : 0;
    mScreenUsagePref.setSubtitle(Utils.formatElapsedTime(getContext(), usageTimeMs, false));
}
Also used : BatterySipper(com.android.internal.os.BatterySipper) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 37 with BatterySipper

use of com.android.internal.os.BatterySipper in project android_packages_apps_Settings by SudaMod.

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;
}
Also used : BatterySipper(com.android.internal.os.BatterySipper)

Example 38 with BatterySipper

use of com.android.internal.os.BatterySipper in project android_packages_apps_Settings by SudaMod.

the class PowerUsageAdvanced method updateUsageDataSummary.

@VisibleForTesting
void updateUsageDataSummary(PowerUsageData usageData, double totalPower, int dischargeAmount) {
    if (shouldHideSummary(usageData)) {
        return;
    }
    if (usageData.usageList.size() <= 1) {
        CharSequence timeSequence = Utils.formatElapsedTime(getContext(), usageData.totalUsageTimeMs, false);
        usageData.summary = usageData.usageType == UsageType.IDLE ? timeSequence : TextUtils.expandTemplate(getText(R.string.battery_used_for), timeSequence);
    } else {
        BatterySipper sipper = findBatterySipperWithMaxBatteryUsage(usageData.usageList);
        BatteryEntry batteryEntry = new BatteryEntry(getContext(), mHandler, mUserManager, sipper);
        final double percentage = (sipper.totalPowerMah / totalPower) * dischargeAmount;
        usageData.summary = getString(R.string.battery_used_by, Utils.formatPercentage(percentage, true), batteryEntry.name);
    }
}
Also used : BatterySipper(com.android.internal.os.BatterySipper) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 39 with BatterySipper

use of com.android.internal.os.BatterySipper 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)

Example 40 with BatterySipper

use of com.android.internal.os.BatterySipper in project android_packages_apps_Settings by SudaMod.

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;
}
Also used : BatterySipper(com.android.internal.os.BatterySipper) ArrayList(java.util.ArrayList) Anomaly(com.android.settings.fuelgauge.anomaly.Anomaly) BatteryStats(android.os.BatteryStats)

Aggregations

BatterySipper (com.android.internal.os.BatterySipper)148 ArrayList (java.util.ArrayList)60 BatteryStats (android.os.BatteryStats)48 VisibleForTesting (android.support.annotation.VisibleForTesting)30 Test (org.junit.Test)29 Anomaly (com.android.settings.fuelgauge.anomaly.Anomaly)18 HashMap (java.util.HashMap)16 UserHandle (android.os.UserHandle)15 ArrayMap (android.util.ArrayMap)10 BatteryStatsHelper (com.android.internal.os.BatteryStatsHelper)10 Map (java.util.Map)10 Drawable (android.graphics.drawable.Drawable)8 SparseArray (android.util.SparseArray)8 DrainType (com.android.internal.os.BatterySipper.DrainType)8 PowerProfile (com.android.internal.os.PowerProfile)8 Bundle (android.os.Bundle)7 SparseLongArray (android.util.SparseLongArray)7 Context (android.content.Context)6 TypedArray (android.content.res.TypedArray)6 PowerUsageData (com.android.settings.fuelgauge.PowerUsageAdvanced.PowerUsageData)6