Loading src/com/android/settings/fuelgauge/anomaly/AnomalyLoader.java +1 −9 Original line number Diff line number Diff line Loading @@ -98,15 +98,7 @@ public class AnomalyLoader extends AsyncLoader<List<Anomaly>> { mUserManager.getUserProfiles()); } final List<Anomaly> anomalies = new ArrayList<>(); for (@Anomaly.AnomalyType int type : Anomaly.ANOMALY_TYPE_LIST) { if (mPolicy.isAnomalyDetectorEnabled(type)) { anomalies.addAll(mAnomalyUtils.getAnomalyDetector(type).detectAnomalies( mBatteryStatsHelper, mPackageName)); } } return anomalies; return mAnomalyUtils.detectAnomalies(mBatteryStatsHelper, mPolicy, mPackageName); } @VisibleForTesting Loading src/com/android/settings/fuelgauge/anomaly/AnomalyUtils.java +27 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.content.Context; import android.os.Build; import android.support.annotation.VisibleForTesting; import com.android.internal.os.BatteryStatsHelper; import com.android.settings.fuelgauge.anomaly.action.AnomalyAction; import com.android.settings.fuelgauge.anomaly.action.ForceStopAction; import com.android.settings.fuelgauge.anomaly.action.LocationCheckAction; Loading @@ -29,6 +30,9 @@ import com.android.settings.fuelgauge.anomaly.checker.BluetoothScanAnomalyDetect import com.android.settings.fuelgauge.anomaly.checker.WakeLockAnomalyDetector; import com.android.settings.fuelgauge.anomaly.checker.WakeupAlarmAnomalyDetector; import java.util.ArrayList; import java.util.List; /** * Utility class for anomaly detection */ Loading Loading @@ -91,4 +95,27 @@ public class AnomalyUtils { return null; } } /** * Detect whether application with {@code targetPackageName} has anomaly. When * {@code targetPackageName} is null, start detection among all the applications. * * @param batteryStatsHelper contains battery stats, used to detect anomaly * @param policy contains configuration about anomaly check * @param targetPackageName represents the app need to be detected * @return the list of anomalies */ public List<Anomaly> detectAnomalies(BatteryStatsHelper batteryStatsHelper, AnomalyDetectionPolicy policy, String targetPackageName) { final List<Anomaly> anomalies = new ArrayList<>(); for (@Anomaly.AnomalyType int type : Anomaly.ANOMALY_TYPE_LIST) { if (policy.isAnomalyDetectorEnabled(type)) { anomalies.addAll(getAnomalyDetector(type).detectAnomalies( batteryStatsHelper, targetPackageName)); } } return anomalies; } } Loading
src/com/android/settings/fuelgauge/anomaly/AnomalyLoader.java +1 −9 Original line number Diff line number Diff line Loading @@ -98,15 +98,7 @@ public class AnomalyLoader extends AsyncLoader<List<Anomaly>> { mUserManager.getUserProfiles()); } final List<Anomaly> anomalies = new ArrayList<>(); for (@Anomaly.AnomalyType int type : Anomaly.ANOMALY_TYPE_LIST) { if (mPolicy.isAnomalyDetectorEnabled(type)) { anomalies.addAll(mAnomalyUtils.getAnomalyDetector(type).detectAnomalies( mBatteryStatsHelper, mPackageName)); } } return anomalies; return mAnomalyUtils.detectAnomalies(mBatteryStatsHelper, mPolicy, mPackageName); } @VisibleForTesting Loading
src/com/android/settings/fuelgauge/anomaly/AnomalyUtils.java +27 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.content.Context; import android.os.Build; import android.support.annotation.VisibleForTesting; import com.android.internal.os.BatteryStatsHelper; import com.android.settings.fuelgauge.anomaly.action.AnomalyAction; import com.android.settings.fuelgauge.anomaly.action.ForceStopAction; import com.android.settings.fuelgauge.anomaly.action.LocationCheckAction; Loading @@ -29,6 +30,9 @@ import com.android.settings.fuelgauge.anomaly.checker.BluetoothScanAnomalyDetect import com.android.settings.fuelgauge.anomaly.checker.WakeLockAnomalyDetector; import com.android.settings.fuelgauge.anomaly.checker.WakeupAlarmAnomalyDetector; import java.util.ArrayList; import java.util.List; /** * Utility class for anomaly detection */ Loading Loading @@ -91,4 +95,27 @@ public class AnomalyUtils { return null; } } /** * Detect whether application with {@code targetPackageName} has anomaly. When * {@code targetPackageName} is null, start detection among all the applications. * * @param batteryStatsHelper contains battery stats, used to detect anomaly * @param policy contains configuration about anomaly check * @param targetPackageName represents the app need to be detected * @return the list of anomalies */ public List<Anomaly> detectAnomalies(BatteryStatsHelper batteryStatsHelper, AnomalyDetectionPolicy policy, String targetPackageName) { final List<Anomaly> anomalies = new ArrayList<>(); for (@Anomaly.AnomalyType int type : Anomaly.ANOMALY_TYPE_LIST) { if (policy.isAnomalyDetectorEnabled(type)) { anomalies.addAll(getAnomalyDetector(type).detectAnomalies( batteryStatsHelper, targetPackageName)); } } return anomalies; } }