diff --git a/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java b/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java index 732db23b780..969afb98681 100644 --- a/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java +++ b/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java @@ -62,11 +62,6 @@ public interface PowerUsageFeatureProvider { */ boolean isPowerAccountingToggleEnabled(); - /** - * Check whether the anomaly detection is enabled - */ - boolean isAnomalyDetectionEnabled(); - /** * Returns an improved prediction for battery time remaining. */ @@ -87,12 +82,6 @@ public interface PowerUsageFeatureProvider { */ long getTimeRemainingEstimate(Cursor cursor); - /** - * Check whether a specific anomaly detector is enabled - */ - //TODO(b/62096650): remove this method and use AnomalyDetectionPolicy instead - boolean isAnomalyDetectorEnabled(@Anomaly.AnomalyType int type); - /** * Checks whether debugging should be enabled for battery estimates. * @return diff --git a/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java b/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java index 1d8e03ac7b5..df7e7e1e790 100644 --- a/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java +++ b/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java @@ -88,11 +88,6 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider return true; } - @Override - public boolean isAnomalyDetectionEnabled() { - return false; - } - @Override public long getEnhancedBatteryPrediction(Context context) { return -1; @@ -113,11 +108,6 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider return 0; } - @Override - public boolean isAnomalyDetectorEnabled(@Anomaly.AnomalyType int type) { - return false; - } - @Override public String getEnhancedEstimateDebugString(String timeRemaining) { return null; diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java index 26dac41197e..e4ae053ce5b 100644 --- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java +++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java @@ -63,6 +63,7 @@ import com.android.settings.display.AutoBrightnessPreferenceController; import com.android.settings.display.BatteryPercentagePreferenceController; import com.android.settings.display.TimeoutPreferenceController; import com.android.settings.fuelgauge.anomaly.Anomaly; +import com.android.settings.fuelgauge.anomaly.AnomalyDetectionPolicy; import com.android.settings.fuelgauge.anomaly.AnomalyDialogFragment.AnomalyDialogListener; import com.android.settings.fuelgauge.anomaly.AnomalyLoader; import com.android.settings.fuelgauge.anomaly.AnomalySummaryPreferenceController; @@ -661,11 +662,16 @@ public class PowerUsageSummary extends PowerUsageBase implements @VisibleForTesting void initAnomalyDetectionIfPossible() { - if (mPowerFeatureProvider.isAnomalyDetectionEnabled()) { + if (getAnomalyDetectionPolicy().isAnomalyDetectionEnabled()) { getLoaderManager().initLoader(ANOMALY_LOADER, Bundle.EMPTY, mAnomalyLoaderCallbacks); } } + @VisibleForTesting + AnomalyDetectionPolicy getAnomalyDetectionPolicy() { + return new AnomalyDetectionPolicy(getContext()); + } + @VisibleForTesting BatterySipper findBatterySipperByType(List usageList, DrainType type) { for (int i = 0, size = usageList.size(); i < size; i++) { diff --git a/src/com/android/settings/fuelgauge/anomaly/AnomalyDetectionPolicy.java b/src/com/android/settings/fuelgauge/anomaly/AnomalyDetectionPolicy.java index 647737c6939..4829ca01d31 100644 --- a/src/com/android/settings/fuelgauge/anomaly/AnomalyDetectionPolicy.java +++ b/src/com/android/settings/fuelgauge/anomaly/AnomalyDetectionPolicy.java @@ -51,7 +51,7 @@ public class AnomalyDetectionPolicy { * @see Settings.Global#ANOMALY_DETECTION_CONSTANTS * @see #KEY_ANOMALY_DETECTION_ENABLED */ - public final boolean anomalyDetectionEnabled; + final boolean anomalyDetectionEnabled; /** * {@code true} if wakelock anomaly detection is enabled @@ -59,7 +59,7 @@ public class AnomalyDetectionPolicy { * @see Settings.Global#ANOMALY_DETECTION_CONSTANTS * @see #KEY_WAKELOCK_DETECTION_ENABLED */ - public final boolean wakeLockDetectionEnabled; + final boolean wakeLockDetectionEnabled; /** * {@code true} if wakeup alarm detection is enabled @@ -67,7 +67,7 @@ public class AnomalyDetectionPolicy { * @see Settings.Global#ANOMALY_DETECTION_CONSTANTS * @see #KEY_WAKEUP_ALARM_DETECTION_ENABLED */ - public final boolean wakeupAlarmDetectionEnabled; + final boolean wakeupAlarmDetectionEnabled; /** * {@code true} if bluetooth scanning detection is enabled @@ -75,7 +75,7 @@ public class AnomalyDetectionPolicy { * @see Settings.Global#ANOMALY_DETECTION_CONSTANTS * @see #KEY_BLUETOOTH_SCAN_THRESHOLD */ - public final boolean bluetoothScanDetectionEnabled; + final boolean bluetoothScanDetectionEnabled; /** * Threshold for wakelock time in milli seconds @@ -132,6 +132,10 @@ public class AnomalyDetectionPolicy { 30 * DateUtils.MINUTE_IN_MILLIS); } + public boolean isAnomalyDetectionEnabled() { + return anomalyDetectionEnabled; + } + public boolean isAnomalyDetectorEnabled(@Anomaly.AnomalyType int type) { switch (type) { case Anomaly.AnomalyType.WAKE_LOCK: diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java index 659b07948dd..5225a74c9dd 100644 --- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java +++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java @@ -39,6 +39,7 @@ import com.android.internal.os.BatteryStatsHelper; import com.android.internal.os.BatteryStatsImpl; import com.android.settings.R; import com.android.settings.SettingsActivity; +import com.android.settings.fuelgauge.anomaly.AnomalyDetectionPolicy; import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.TestConfig; import com.android.settings.Utils; @@ -151,6 +152,8 @@ public class PowerUsageSummaryTest { private PreferenceScreen mPreferenceScreen; @Mock private PreferenceGroup mAppListGroup; + @Mock + private AnomalyDetectionPolicy mAnomalyDetectionPolicy; private List mUsageList; private Context mRealContext; @@ -463,9 +466,9 @@ public class PowerUsageSummaryTest { @Test public void testInitAnomalyDetectionIfPossible_detectionEnabled_init() { - when(mFeatureFactory.powerUsageFeatureProvider.isAnomalyDetectionEnabled()).thenReturn( - true); doReturn(mLoaderManager).when(mFragment).getLoaderManager(); + doReturn(mAnomalyDetectionPolicy).when(mFragment).getAnomalyDetectionPolicy(); + when(mAnomalyDetectionPolicy.isAnomalyDetectionEnabled()).thenReturn(true); mFragment.initAnomalyDetectionIfPossible();