use of com.android.settings.fuelgauge.anomaly.Anomaly in project android_packages_apps_Settings by DirtyUnicorns.
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);
}
}
use of com.android.settings.fuelgauge.anomaly.Anomaly in project android_packages_apps_Settings by DirtyUnicorns.
the class BluetoothScanAnomalyDetectorTest method testDetectAnomalies_detectTargetAnomaly_detectIt.
@Test
public void testDetectAnomalies_detectTargetAnomaly_detectIt() {
doReturn(TARGET_UID).when(mBatteryUtils).getPackageUid(TARGET_PACKAGE_NAME);
final Anomaly targetAnomaly = createBluetoothAnomaly(TARGET_UID);
List<Anomaly> mAnomalies = mBluetoothScanAnomalyDetector.detectAnomalies(mBatteryStatsHelper, TARGET_PACKAGE_NAME);
assertThat(mAnomalies).containsExactly(targetAnomaly);
}
use of com.android.settings.fuelgauge.anomaly.Anomaly 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.settings.fuelgauge.anomaly.Anomaly in project android_packages_apps_Settings by DirtyUnicorns.
the class PowerUsageAnomalyDetailsTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mAbnormalListGroup = spy(new PreferenceCategory(mContext));
mAnomalyList = new ArrayList<>();
Anomaly anomaly1 = new Anomaly.Builder().setType(Anomaly.AnomalyType.WAKE_LOCK).setPackageName(PACKAGE_NAME_1).setDisplayName(NAME_APP_1).build();
mAnomalyList.add(anomaly1);
Anomaly anomaly2 = new Anomaly.Builder().setType(Anomaly.AnomalyType.WAKEUP_ALARM).setPackageName(PACKAGE_NAME_2).setDisplayName(NAME_APP_2).build();
mAnomalyList.add(anomaly2);
Anomaly anomaly3 = new Anomaly.Builder().setType(Anomaly.AnomalyType.BLUETOOTH_SCAN).setPackageName(PACKAGE_NAME_3).setDisplayName(NAME_APP_3).build();
mAnomalyList.add(anomaly3);
mFragment = spy(new PowerUsageAnomalyDetails());
mFragment.mAbnormalListGroup = mAbnormalListGroup;
mFragment.mAnomalies = mAnomalyList;
mFragment.mBatteryUtils = new BatteryUtils(mContext);
mFragment.mPackageManager = mPackageManager;
mFragment.mIconDrawableFactory = mIconDrawableFactory;
doReturn(mPreferenceManager).when(mFragment).getPreferenceManager();
doReturn(mContext).when(mPreferenceManager).getContext();
}
use of com.android.settings.fuelgauge.anomaly.Anomaly in project android_packages_apps_Settings by DirtyUnicorns.
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);
}
Aggregations