Loading src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java +6 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.content.Intent; import android.database.Cursor; import android.net.Uri; import com.android.internal.os.BatterySipper; import com.android.settings.fuelgauge.anomaly.Anomaly; /** * Feature Provider used in power usage Loading Loading @@ -85,4 +86,9 @@ public interface PowerUsageFeatureProvider { * Returns the the estimate in the cursor as a long or -1 if the cursor is null */ long getTimeRemainingEstimate(Cursor cursor); /** * Check whether a specific anomaly detector is enabled */ boolean isAnomalyDetectorEnabled(@Anomaly.AnomalyType int type); } src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java +6 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.net.Uri; import android.os.Process; import com.android.internal.os.BatterySipper; import com.android.internal.util.ArrayUtils; import com.android.settings.fuelgauge.anomaly.Anomaly; public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider { Loading Loading @@ -111,4 +112,9 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider public long getTimeRemainingEstimate(Cursor cursor) { return 0; } @Override public boolean isAnomalyDetectorEnabled(@Anomaly.AnomalyType int type) { return false; } } src/com/android/settings/fuelgauge/anomaly/Anomaly.java +3 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,9 @@ public class Anomaly implements Parcelable { int FORCE_STOP = 0; } @AnomalyType public static final int[] ANOMALY_TYPE_LIST = {AnomalyType.WAKE_LOCK}; /** * Type of this this anomaly */ Loading src/com/android/settings/fuelgauge/anomaly/AnomalyLoader.java +15 −4 Original line number Diff line number Diff line Loading @@ -17,9 +17,11 @@ package com.android.settings.fuelgauge.anomaly; import android.content.Context; import android.support.annotation.VisibleForTesting; import com.android.internal.os.BatteryStatsHelper; import com.android.settings.fuelgauge.anomaly.checker.WakeLockAnomalyDetector; import com.android.settings.fuelgauge.PowerUsageFeatureProvider; import com.android.settings.overlay.FeatureFactory; import com.android.settings.utils.AsyncLoader; import java.util.ArrayList; Loading @@ -29,13 +31,18 @@ import java.util.List; * Loader to compute which apps are anomaly and return a anomaly list. It will return * an empty list if there is no anomaly. */ //TODO(b/36924669): add test for this file, for now it seems there is nothing to test public class AnomalyLoader extends AsyncLoader<List<Anomaly>> { private BatteryStatsHelper mBatteryStatsHelper; private PowerUsageFeatureProvider mPowerUsageFeatureProvider; @VisibleForTesting AnomalyUtils mAnomalyUtils; public AnomalyLoader(Context context, BatteryStatsHelper batteryStatsHelper) { super(context); mBatteryStatsHelper = batteryStatsHelper; mPowerUsageFeatureProvider = FeatureFactory.getFactory( context).getPowerUsageFeatureProvider(context); mAnomalyUtils = AnomalyUtils.getInstance(context); } @Override Loading @@ -45,8 +52,12 @@ public class AnomalyLoader extends AsyncLoader<List<Anomaly>> { @Override public List<Anomaly> loadInBackground() { final List<Anomaly> anomalies = new ArrayList<>(); anomalies.addAll(new WakeLockAnomalyDetector(getContext()) .detectAnomalies(mBatteryStatsHelper)); for (@Anomaly.AnomalyType int type : Anomaly.ANOMALY_TYPE_LIST) { if (mPowerUsageFeatureProvider.isAnomalyDetectorEnabled(type)) { anomalies.addAll(mAnomalyUtils.getAnomalyDetector(type).detectAnomalies( mBatteryStatsHelper)); } } return anomalies; } Loading src/com/android/settings/fuelgauge/anomaly/AnomalyUtils.java +18 −1 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ import android.support.annotation.VisibleForTesting; import com.android.settings.fuelgauge.anomaly.action.AnomalyAction; import com.android.settings.fuelgauge.anomaly.action.ForceStopAction; import com.android.settings.fuelgauge.anomaly.checker.AnomalyDetector; import com.android.settings.fuelgauge.anomaly.checker.WakeLockAnomalyDetector; /** * Utility class for anomaly detection Loading @@ -47,7 +49,7 @@ public class AnomalyUtils { * * @return corresponding {@link AnomalyAction}, or null if cannot find it. */ public final AnomalyAction getAnomalyAction(@Anomaly.AnomalyType int anomalyType) { public AnomalyAction getAnomalyAction(@Anomaly.AnomalyType int anomalyType) { switch (anomalyType) { case Anomaly.AnomalyType.WAKE_LOCK: return new ForceStopAction(mContext); Loading @@ -55,4 +57,19 @@ public class AnomalyUtils { return null; } } /** * Return the corresponding {@link AnomalyDetector} according to * {@link com.android.settings.fuelgauge.anomaly.Anomaly.AnomalyType} * * @return corresponding {@link AnomalyDetector}, or null if cannot find it. */ public AnomalyDetector getAnomalyDetector(@Anomaly.AnomalyType int anomalyType) { switch (anomalyType) { case Anomaly.AnomalyType.WAKE_LOCK: return new WakeLockAnomalyDetector(mContext); default: return null; } } } Loading
src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java +6 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.content.Intent; import android.database.Cursor; import android.net.Uri; import com.android.internal.os.BatterySipper; import com.android.settings.fuelgauge.anomaly.Anomaly; /** * Feature Provider used in power usage Loading Loading @@ -85,4 +86,9 @@ public interface PowerUsageFeatureProvider { * Returns the the estimate in the cursor as a long or -1 if the cursor is null */ long getTimeRemainingEstimate(Cursor cursor); /** * Check whether a specific anomaly detector is enabled */ boolean isAnomalyDetectorEnabled(@Anomaly.AnomalyType int type); }
src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java +6 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.net.Uri; import android.os.Process; import com.android.internal.os.BatterySipper; import com.android.internal.util.ArrayUtils; import com.android.settings.fuelgauge.anomaly.Anomaly; public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider { Loading Loading @@ -111,4 +112,9 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider public long getTimeRemainingEstimate(Cursor cursor) { return 0; } @Override public boolean isAnomalyDetectorEnabled(@Anomaly.AnomalyType int type) { return false; } }
src/com/android/settings/fuelgauge/anomaly/Anomaly.java +3 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,9 @@ public class Anomaly implements Parcelable { int FORCE_STOP = 0; } @AnomalyType public static final int[] ANOMALY_TYPE_LIST = {AnomalyType.WAKE_LOCK}; /** * Type of this this anomaly */ Loading
src/com/android/settings/fuelgauge/anomaly/AnomalyLoader.java +15 −4 Original line number Diff line number Diff line Loading @@ -17,9 +17,11 @@ package com.android.settings.fuelgauge.anomaly; import android.content.Context; import android.support.annotation.VisibleForTesting; import com.android.internal.os.BatteryStatsHelper; import com.android.settings.fuelgauge.anomaly.checker.WakeLockAnomalyDetector; import com.android.settings.fuelgauge.PowerUsageFeatureProvider; import com.android.settings.overlay.FeatureFactory; import com.android.settings.utils.AsyncLoader; import java.util.ArrayList; Loading @@ -29,13 +31,18 @@ import java.util.List; * Loader to compute which apps are anomaly and return a anomaly list. It will return * an empty list if there is no anomaly. */ //TODO(b/36924669): add test for this file, for now it seems there is nothing to test public class AnomalyLoader extends AsyncLoader<List<Anomaly>> { private BatteryStatsHelper mBatteryStatsHelper; private PowerUsageFeatureProvider mPowerUsageFeatureProvider; @VisibleForTesting AnomalyUtils mAnomalyUtils; public AnomalyLoader(Context context, BatteryStatsHelper batteryStatsHelper) { super(context); mBatteryStatsHelper = batteryStatsHelper; mPowerUsageFeatureProvider = FeatureFactory.getFactory( context).getPowerUsageFeatureProvider(context); mAnomalyUtils = AnomalyUtils.getInstance(context); } @Override Loading @@ -45,8 +52,12 @@ public class AnomalyLoader extends AsyncLoader<List<Anomaly>> { @Override public List<Anomaly> loadInBackground() { final List<Anomaly> anomalies = new ArrayList<>(); anomalies.addAll(new WakeLockAnomalyDetector(getContext()) .detectAnomalies(mBatteryStatsHelper)); for (@Anomaly.AnomalyType int type : Anomaly.ANOMALY_TYPE_LIST) { if (mPowerUsageFeatureProvider.isAnomalyDetectorEnabled(type)) { anomalies.addAll(mAnomalyUtils.getAnomalyDetector(type).detectAnomalies( mBatteryStatsHelper)); } } return anomalies; } Loading
src/com/android/settings/fuelgauge/anomaly/AnomalyUtils.java +18 −1 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ import android.support.annotation.VisibleForTesting; import com.android.settings.fuelgauge.anomaly.action.AnomalyAction; import com.android.settings.fuelgauge.anomaly.action.ForceStopAction; import com.android.settings.fuelgauge.anomaly.checker.AnomalyDetector; import com.android.settings.fuelgauge.anomaly.checker.WakeLockAnomalyDetector; /** * Utility class for anomaly detection Loading @@ -47,7 +49,7 @@ public class AnomalyUtils { * * @return corresponding {@link AnomalyAction}, or null if cannot find it. */ public final AnomalyAction getAnomalyAction(@Anomaly.AnomalyType int anomalyType) { public AnomalyAction getAnomalyAction(@Anomaly.AnomalyType int anomalyType) { switch (anomalyType) { case Anomaly.AnomalyType.WAKE_LOCK: return new ForceStopAction(mContext); Loading @@ -55,4 +57,19 @@ public class AnomalyUtils { return null; } } /** * Return the corresponding {@link AnomalyDetector} according to * {@link com.android.settings.fuelgauge.anomaly.Anomaly.AnomalyType} * * @return corresponding {@link AnomalyDetector}, or null if cannot find it. */ public AnomalyDetector getAnomalyDetector(@Anomaly.AnomalyType int anomalyType) { switch (anomalyType) { case Anomaly.AnomalyType.WAKE_LOCK: return new WakeLockAnomalyDetector(mContext); default: return null; } } }