Merge "Remove PowerUsageFeatureProvider.isAnomalyDetectionEnabled" into oc-dr1-dev

am: 74a350f9c9

Change-Id: I5f90f5dc56765ab16e9bc6879fe84d3fe31ce0df
This commit is contained in:
Andrew Sapperstein
2017-06-24 04:54:51 +00:00
committed by android-build-merger
5 changed files with 20 additions and 28 deletions

View File

@@ -62,11 +62,6 @@ public interface PowerUsageFeatureProvider {
*/ */
boolean isPowerAccountingToggleEnabled(); boolean isPowerAccountingToggleEnabled();
/**
* Check whether the anomaly detection is enabled
*/
boolean isAnomalyDetectionEnabled();
/** /**
* Returns an improved prediction for battery time remaining. * Returns an improved prediction for battery time remaining.
*/ */
@@ -87,12 +82,6 @@ public interface PowerUsageFeatureProvider {
*/ */
long getTimeRemainingEstimate(Cursor cursor); 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. * Checks whether debugging should be enabled for battery estimates.
* @return * @return

View File

@@ -88,11 +88,6 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
return true; return true;
} }
@Override
public boolean isAnomalyDetectionEnabled() {
return false;
}
@Override @Override
public long getEnhancedBatteryPrediction(Context context) { public long getEnhancedBatteryPrediction(Context context) {
return -1; return -1;
@@ -113,11 +108,6 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
return 0; return 0;
} }
@Override
public boolean isAnomalyDetectorEnabled(@Anomaly.AnomalyType int type) {
return false;
}
@Override @Override
public String getEnhancedEstimateDebugString(String timeRemaining) { public String getEnhancedEstimateDebugString(String timeRemaining) {
return null; return null;

View File

@@ -63,6 +63,7 @@ import com.android.settings.display.AutoBrightnessPreferenceController;
import com.android.settings.display.BatteryPercentagePreferenceController; import com.android.settings.display.BatteryPercentagePreferenceController;
import com.android.settings.display.TimeoutPreferenceController; import com.android.settings.display.TimeoutPreferenceController;
import com.android.settings.fuelgauge.anomaly.Anomaly; 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.AnomalyDialogFragment.AnomalyDialogListener;
import com.android.settings.fuelgauge.anomaly.AnomalyLoader; import com.android.settings.fuelgauge.anomaly.AnomalyLoader;
import com.android.settings.fuelgauge.anomaly.AnomalySummaryPreferenceController; import com.android.settings.fuelgauge.anomaly.AnomalySummaryPreferenceController;
@@ -661,11 +662,16 @@ public class PowerUsageSummary extends PowerUsageBase implements
@VisibleForTesting @VisibleForTesting
void initAnomalyDetectionIfPossible() { void initAnomalyDetectionIfPossible() {
if (mPowerFeatureProvider.isAnomalyDetectionEnabled()) { if (getAnomalyDetectionPolicy().isAnomalyDetectionEnabled()) {
getLoaderManager().initLoader(ANOMALY_LOADER, Bundle.EMPTY, mAnomalyLoaderCallbacks); getLoaderManager().initLoader(ANOMALY_LOADER, Bundle.EMPTY, mAnomalyLoaderCallbacks);
} }
} }
@VisibleForTesting
AnomalyDetectionPolicy getAnomalyDetectionPolicy() {
return new AnomalyDetectionPolicy(getContext());
}
@VisibleForTesting @VisibleForTesting
BatterySipper findBatterySipperByType(List<BatterySipper> usageList, DrainType type) { BatterySipper findBatterySipperByType(List<BatterySipper> usageList, DrainType type) {
for (int i = 0, size = usageList.size(); i < size; i++) { for (int i = 0, size = usageList.size(); i < size; i++) {

View File

@@ -51,7 +51,7 @@ public class AnomalyDetectionPolicy {
* @see Settings.Global#ANOMALY_DETECTION_CONSTANTS * @see Settings.Global#ANOMALY_DETECTION_CONSTANTS
* @see #KEY_ANOMALY_DETECTION_ENABLED * @see #KEY_ANOMALY_DETECTION_ENABLED
*/ */
public final boolean anomalyDetectionEnabled; final boolean anomalyDetectionEnabled;
/** /**
* {@code true} if wakelock anomaly detection is enabled * {@code true} if wakelock anomaly detection is enabled
@@ -59,7 +59,7 @@ public class AnomalyDetectionPolicy {
* @see Settings.Global#ANOMALY_DETECTION_CONSTANTS * @see Settings.Global#ANOMALY_DETECTION_CONSTANTS
* @see #KEY_WAKELOCK_DETECTION_ENABLED * @see #KEY_WAKELOCK_DETECTION_ENABLED
*/ */
public final boolean wakeLockDetectionEnabled; final boolean wakeLockDetectionEnabled;
/** /**
* {@code true} if wakeup alarm detection is enabled * {@code true} if wakeup alarm detection is enabled
@@ -67,7 +67,7 @@ public class AnomalyDetectionPolicy {
* @see Settings.Global#ANOMALY_DETECTION_CONSTANTS * @see Settings.Global#ANOMALY_DETECTION_CONSTANTS
* @see #KEY_WAKEUP_ALARM_DETECTION_ENABLED * @see #KEY_WAKEUP_ALARM_DETECTION_ENABLED
*/ */
public final boolean wakeupAlarmDetectionEnabled; final boolean wakeupAlarmDetectionEnabled;
/** /**
* {@code true} if bluetooth scanning detection is enabled * {@code true} if bluetooth scanning detection is enabled
@@ -75,7 +75,7 @@ public class AnomalyDetectionPolicy {
* @see Settings.Global#ANOMALY_DETECTION_CONSTANTS * @see Settings.Global#ANOMALY_DETECTION_CONSTANTS
* @see #KEY_BLUETOOTH_SCAN_THRESHOLD * @see #KEY_BLUETOOTH_SCAN_THRESHOLD
*/ */
public final boolean bluetoothScanDetectionEnabled; final boolean bluetoothScanDetectionEnabled;
/** /**
* Threshold for wakelock time in milli seconds * Threshold for wakelock time in milli seconds
@@ -132,6 +132,10 @@ public class AnomalyDetectionPolicy {
30 * DateUtils.MINUTE_IN_MILLIS); 30 * DateUtils.MINUTE_IN_MILLIS);
} }
public boolean isAnomalyDetectionEnabled() {
return anomalyDetectionEnabled;
}
public boolean isAnomalyDetectorEnabled(@Anomaly.AnomalyType int type) { public boolean isAnomalyDetectorEnabled(@Anomaly.AnomalyType int type) {
switch (type) { switch (type) {
case Anomaly.AnomalyType.WAKE_LOCK: case Anomaly.AnomalyType.WAKE_LOCK:

View File

@@ -39,6 +39,7 @@ import com.android.internal.os.BatteryStatsHelper;
import com.android.internal.os.BatteryStatsImpl; import com.android.internal.os.BatteryStatsImpl;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SettingsActivity; import com.android.settings.SettingsActivity;
import com.android.settings.fuelgauge.anomaly.AnomalyDetectionPolicy;
import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig; import com.android.settings.TestConfig;
import com.android.settings.Utils; import com.android.settings.Utils;
@@ -151,6 +152,8 @@ public class PowerUsageSummaryTest {
private PreferenceScreen mPreferenceScreen; private PreferenceScreen mPreferenceScreen;
@Mock @Mock
private PreferenceGroup mAppListGroup; private PreferenceGroup mAppListGroup;
@Mock
private AnomalyDetectionPolicy mAnomalyDetectionPolicy;
private List<BatterySipper> mUsageList; private List<BatterySipper> mUsageList;
private Context mRealContext; private Context mRealContext;
@@ -463,9 +466,9 @@ public class PowerUsageSummaryTest {
@Test @Test
public void testInitAnomalyDetectionIfPossible_detectionEnabled_init() { public void testInitAnomalyDetectionIfPossible_detectionEnabled_init() {
when(mFeatureFactory.powerUsageFeatureProvider.isAnomalyDetectionEnabled()).thenReturn(
true);
doReturn(mLoaderManager).when(mFragment).getLoaderManager(); doReturn(mLoaderManager).when(mFragment).getLoaderManager();
doReturn(mAnomalyDetectionPolicy).when(mFragment).getAnomalyDetectionPolicy();
when(mAnomalyDetectionPolicy.isAnomalyDetectionEnabled()).thenReturn(true);
mFragment.initAnomalyDetectionIfPossible(); mFragment.initAnomalyDetectionIfPossible();