Loading src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java +0 −11 Original line number Diff line number Diff line Loading @@ -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. */ Loading @@ -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 Loading src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java +0 −10 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading src/com/android/settings/fuelgauge/PowerUsageSummary.java +7 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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<BatterySipper> usageList, DrainType type) { for (int i = 0, size = usageList.size(); i < size; i++) { Loading src/com/android/settings/fuelgauge/anomaly/AnomalyDetectionPolicy.java +8 −4 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 Loading @@ -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 Loading @@ -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 Loading Loading @@ -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: Loading tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java +5 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -151,6 +152,8 @@ public class PowerUsageSummaryTest { private PreferenceScreen mPreferenceScreen; @Mock private PreferenceGroup mAppListGroup; @Mock private AnomalyDetectionPolicy mAnomalyDetectionPolicy; private List<BatterySipper> mUsageList; private Context mRealContext; Loading Loading @@ -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(); Loading Loading
src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java +0 −11 Original line number Diff line number Diff line Loading @@ -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. */ Loading @@ -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 Loading
src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java +0 −10 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading
src/com/android/settings/fuelgauge/PowerUsageSummary.java +7 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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<BatterySipper> usageList, DrainType type) { for (int i = 0, size = usageList.size(); i < size; i++) { Loading
src/com/android/settings/fuelgauge/anomaly/AnomalyDetectionPolicy.java +8 −4 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 Loading @@ -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 Loading @@ -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 Loading Loading @@ -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: Loading
tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java +5 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -151,6 +152,8 @@ public class PowerUsageSummaryTest { private PreferenceScreen mPreferenceScreen; @Mock private PreferenceGroup mAppListGroup; @Mock private AnomalyDetectionPolicy mAnomalyDetectionPolicy; private List<BatterySipper> mUsageList; private Context mRealContext; Loading Loading @@ -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(); Loading