use of com.android.settings.fuelgauge.anomaly.Anomaly in project android_packages_apps_Settings by omnirom.
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);
}
use of com.android.settings.fuelgauge.anomaly.Anomaly in project android_packages_apps_Settings by omnirom.
the class WakeLockAnomalyDetector method detectAnomalies.
@Override
public List<Anomaly> detectAnomalies(BatteryStatsHelper batteryStatsHelper, String targetPackageName) {
final List<BatterySipper> batterySippers = batteryStatsHelper.getUsageList();
final List<Anomaly> anomalies = new ArrayList<>();
final long rawRealtime = SystemClock.elapsedRealtime();
final int targetUid = mBatteryUtils.getPackageUid(targetPackageName);
// Check the app one by one
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 currentDurationMs = getCurrentDurationMs(uid, rawRealtime);
final long backgroundDurationMs = getBackgroundTotalDurationMs(uid, rawRealtime);
if (backgroundDurationMs > mWakeLockThresholdMs && currentDurationMs != 0) {
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.WAKE_LOCK).setDisplayName(displayName).setPackageName(packageName).setWakeLockTimeMs(backgroundDurationMs).build();
if (mAnomalyUtils.getAnomalyAction(anomaly).isActionActive(anomaly)) {
anomalies.add(anomaly);
}
}
}
return anomalies;
}
use of com.android.settings.fuelgauge.anomaly.Anomaly in project android_packages_apps_Settings by omnirom.
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.settings.fuelgauge.anomaly.Anomaly in project android_packages_apps_Settings by omnirom.
the class PowerUsageSummaryTest method testUpdateAnomalySparseArray.
@Test
public void testUpdateAnomalySparseArray() {
mFragment.mAnomalySparseArray = new SparseArray<>();
final List<Anomaly> anomalies = new ArrayList<>();
final Anomaly anomaly1 = new Anomaly.Builder().setUid(UID).build();
final Anomaly anomaly2 = new Anomaly.Builder().setUid(UID).build();
final Anomaly anomaly3 = new Anomaly.Builder().setUid(UID_2).build();
anomalies.add(anomaly1);
anomalies.add(anomaly2);
anomalies.add(anomaly3);
mFragment.updateAnomalySparseArray(anomalies);
assertThat(mFragment.mAnomalySparseArray.get(UID)).containsExactly(anomaly1, anomaly2);
assertThat(mFragment.mAnomalySparseArray.get(UID_2)).containsExactly(anomaly3);
}
use of com.android.settings.fuelgauge.anomaly.Anomaly in project android_packages_apps_Settings by omnirom.
the class BluetoothScanAnomalyDetectorTest method testDetectAnomalies_containsAnomaly_detectIt.
@Test
public void testDetectAnomalies_containsAnomaly_detectIt() {
doReturn(-1).when(mBatteryUtils).getPackageUid(nullable(String.class));
final Anomaly anomaly = createBluetoothAnomaly(ANOMALY_UID);
final Anomaly targetAnomaly = createBluetoothAnomaly(TARGET_UID);
List<Anomaly> mAnomalies = mBluetoothScanAnomalyDetector.detectAnomalies(mBatteryStatsHelper);
assertThat(mAnomalies).containsExactly(anomaly, targetAnomaly);
}
Aggregations