Search in sources :

Example 26 with Anomaly

use of com.android.settings.fuelgauge.anomaly.Anomaly in project platform_packages_apps_Settings by BlissRoms.

the class PowerUsageAnomalyDetails method refreshUi.

void refreshUi() {
    mAbnormalListGroup.removeAll();
    for (int i = 0, size = mAnomalies.size(); i < size; i++) {
        final Anomaly anomaly = mAnomalies.get(i);
        Preference pref = new AnomalyPreference(getPrefContext(), anomaly);
        pref.setSummary(mBatteryUtils.getSummaryResIdFromAnomalyType(anomaly.type));
        Drawable icon = getBadgedIcon(anomaly.packageName, UserHandle.getUserId(anomaly.uid));
        if (icon != null) {
            pref.setIcon(icon);
        }
        mAbnormalListGroup.addPreference(pref);
    }
}
Also used : AnomalyPreference(com.android.settings.fuelgauge.anomaly.AnomalyPreference) Preference(android.support.v7.preference.Preference) AnomalyPreference(com.android.settings.fuelgauge.anomaly.AnomalyPreference) Drawable(android.graphics.drawable.Drawable) Anomaly(com.android.settings.fuelgauge.anomaly.Anomaly)

Example 27 with Anomaly

use of com.android.settings.fuelgauge.anomaly.Anomaly 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 28 with Anomaly

use of com.android.settings.fuelgauge.anomaly.Anomaly 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 29 with Anomaly

use of com.android.settings.fuelgauge.anomaly.Anomaly in project android_packages_apps_Settings by LineageOS.

the class PowerUsageAnomalyDetails method onPreferenceTreeClick.

@Override
public boolean onPreferenceTreeClick(Preference preference) {
    if (preference instanceof AnomalyPreference) {
        AnomalyPreference anomalyPreference = (AnomalyPreference) preference;
        final Anomaly anomaly = anomalyPreference.getAnomaly();
        AnomalyDialogFragment dialogFragment = AnomalyDialogFragment.newInstance(anomaly, MetricsProto.MetricsEvent.FUELGAUGE_ANOMALY_DETAIL);
        dialogFragment.setTargetFragment(this, REQUEST_ANOMALY_ACTION);
        dialogFragment.show(getFragmentManager(), TAG);
        return true;
    }
    return super.onPreferenceTreeClick(preference);
}
Also used : AnomalyPreference(com.android.settings.fuelgauge.anomaly.AnomalyPreference) AnomalyDialogFragment(com.android.settings.fuelgauge.anomaly.AnomalyDialogFragment) Anomaly(com.android.settings.fuelgauge.anomaly.Anomaly)

Example 30 with Anomaly

use of com.android.settings.fuelgauge.anomaly.Anomaly in project android_packages_apps_Settings by LineageOS.

the class PowerUsageAnomalyDetails method refreshUi.

void refreshUi() {
    mAbnormalListGroup.removeAll();
    for (int i = 0, size = mAnomalies.size(); i < size; i++) {
        final Anomaly anomaly = mAnomalies.get(i);
        Preference pref = new AnomalyPreference(getPrefContext(), anomaly);
        pref.setSummary(mBatteryUtils.getSummaryResIdFromAnomalyType(anomaly.type));
        Drawable icon = getBadgedIcon(anomaly.packageName, UserHandle.getUserId(anomaly.uid));
        if (icon != null) {
            pref.setIcon(icon);
        }
        mAbnormalListGroup.addPreference(pref);
    }
}
Also used : AnomalyPreference(com.android.settings.fuelgauge.anomaly.AnomalyPreference) Preference(android.support.v7.preference.Preference) AnomalyPreference(com.android.settings.fuelgauge.anomaly.AnomalyPreference) Drawable(android.graphics.drawable.Drawable) Anomaly(com.android.settings.fuelgauge.anomaly.Anomaly)

Aggregations

Anomaly (com.android.settings.fuelgauge.anomaly.Anomaly)60 ArrayList (java.util.ArrayList)24 BatteryStats (android.os.BatteryStats)18 BatterySipper (com.android.internal.os.BatterySipper)18 Test (org.junit.Test)18 AnomalyPreference (com.android.settings.fuelgauge.anomaly.AnomalyPreference)12 Drawable (android.graphics.drawable.Drawable)6 VisibleForTesting (android.support.annotation.VisibleForTesting)6 Preference (android.support.v7.preference.Preference)6 PreferenceCategory (android.support.v7.preference.PreferenceCategory)6 AnomalyDialogFragment (com.android.settings.fuelgauge.anomaly.AnomalyDialogFragment)6 Before (org.junit.Before)6