Search in sources :

Example 51 with BatterySipper

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

the class WakeupAlarmAnomalyDetector method detectAnomalies.

@Override
public List<Anomaly> detectAnomalies(BatteryStatsHelper batteryStatsHelper, String targetPackageName) {
    final List<BatterySipper> batterySippers = batteryStatsHelper.getUsageList();
    final List<Anomaly> anomalies = new ArrayList<>();
    final double totalRunningHours = mBatteryUtils.calculateRunningTimeBasedOnStatsType(batteryStatsHelper, BatteryStats.STATS_SINCE_CHARGED) / (double) DateUtils.HOUR_IN_MILLIS;
    final int targetUid = mBatteryUtils.getPackageUid(targetPackageName);
    if (totalRunningHours >= 1) {
        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 int wakeupAlarmCount = (int) (getWakeupAlarmCountFromUid(uid) / totalRunningHours);
            if (wakeupAlarmCount > mWakeupAlarmThreshold) {
                final String packageName = mBatteryUtils.getPackageName(uid.getUid());
                final CharSequence displayName = Utils.getApplicationLabel(mContext, packageName);
                final int targetSdkVersion = mBatteryUtils.getTargetSdkVersion(packageName);
                Anomaly anomaly = new Anomaly.Builder().setUid(uid.getUid()).setType(Anomaly.AnomalyType.WAKEUP_ALARM).setDisplayName(displayName).setPackageName(packageName).setTargetSdkVersion(targetSdkVersion).setBackgroundRestrictionEnabled(mBatteryUtils.isBackgroundRestrictionEnabled(targetSdkVersion, uid.getUid(), packageName)).setWakeupAlarmCount(wakeupAlarmCount).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)

Example 52 with BatterySipper

use of com.android.internal.os.BatterySipper in project platform_packages_apps_Settings by BlissRoms.

the class PowerUsageSummary method getFakeStats.

private static List<BatterySipper> getFakeStats() {
    ArrayList<BatterySipper> stats = new ArrayList<>();
    float use = 5;
    for (DrainType type : DrainType.values()) {
        if (type == DrainType.APP) {
            continue;
        }
        stats.add(new BatterySipper(type, null, use));
        use += 5;
    }
    for (int i = 0; i < 100; i++) {
        stats.add(new BatterySipper(DrainType.APP, new FakeUid(Process.FIRST_APPLICATION_UID + i), use));
    }
    stats.add(new BatterySipper(DrainType.APP, new FakeUid(0), use));
    // Simulate dex2oat process.
    BatterySipper sipper = new BatterySipper(DrainType.APP, new FakeUid(UserHandle.getSharedAppGid(Process.FIRST_APPLICATION_UID)), 10.0f);
    sipper.packageWithHighestDrain = "dex2oat";
    stats.add(sipper);
    sipper = new BatterySipper(DrainType.APP, new FakeUid(UserHandle.getSharedAppGid(Process.FIRST_APPLICATION_UID + 1)), 10.0f);
    sipper.packageWithHighestDrain = "dex2oat";
    stats.add(sipper);
    sipper = new BatterySipper(DrainType.APP, new FakeUid(UserHandle.getSharedAppGid(Process.LOG_UID)), 9.0f);
    stats.add(sipper);
    return stats;
}
Also used : DrainType(com.android.internal.os.BatterySipper.DrainType) BatterySipper(com.android.internal.os.BatterySipper) ArrayList(java.util.ArrayList)

Example 53 with BatterySipper

use of com.android.internal.os.BatterySipper in project platform_packages_apps_Settings by BlissRoms.

the class WakeupAlarmAnomalyDetector method detectAnomalies.

@Override
public List<Anomaly> detectAnomalies(BatteryStatsHelper batteryStatsHelper, String targetPackageName) {
    final List<BatterySipper> batterySippers = batteryStatsHelper.getUsageList();
    final List<Anomaly> anomalies = new ArrayList<>();
    final double totalRunningHours = mBatteryUtils.calculateRunningTimeBasedOnStatsType(batteryStatsHelper, BatteryStats.STATS_SINCE_CHARGED) / (double) DateUtils.HOUR_IN_MILLIS;
    final int targetUid = mBatteryUtils.getPackageUid(targetPackageName);
    if (totalRunningHours >= 1) {
        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 int wakeupAlarmCount = (int) (getWakeupAlarmCountFromUid(uid) / totalRunningHours);
            if (wakeupAlarmCount > mWakeupAlarmThreshold) {
                final String packageName = mBatteryUtils.getPackageName(uid.getUid());
                final CharSequence displayName = Utils.getApplicationLabel(mContext, packageName);
                final int targetSdkVersion = mBatteryUtils.getTargetSdkVersion(packageName);
                Anomaly anomaly = new Anomaly.Builder().setUid(uid.getUid()).setType(Anomaly.AnomalyType.WAKEUP_ALARM).setDisplayName(displayName).setPackageName(packageName).setTargetSdkVersion(targetSdkVersion).setBackgroundRestrictionEnabled(mBatteryUtils.isBackgroundRestrictionEnabled(targetSdkVersion, uid.getUid(), packageName)).setWakeupAlarmCount(wakeupAlarmCount).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)

Example 54 with BatterySipper

use of com.android.internal.os.BatterySipper in project platform_packages_apps_Settings by BlissRoms.

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)

Example 55 with BatterySipper

use of com.android.internal.os.BatterySipper in project platform_packages_apps_Settings by BlissRoms.

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())));
}
Also used : BatterySipper(com.android.internal.os.BatterySipper) Bundle(android.os.Bundle) UserHandle(android.os.UserHandle) BatteryStats(android.os.BatteryStats) VisibleForTesting(android.support.annotation.VisibleForTesting)

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