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;
}
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;
}
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;
}
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;
}
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())));
}
Aggregations