Remove PowerUsageFeatureProvider.isAnomalyDetectionEnabled
Instead, this decision is being handled via AnomalyDetectionPolicy. Change-Id: I5b1831c78e31e3be984dda07bcea9f0b0a25d52f Fixes: 62871629 Test: robotests
This commit is contained in:
@@ -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
|
||||||
|
@@ -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;
|
||||||
|
@@ -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++) {
|
||||||
|
@@ -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:
|
||||||
|
@@ -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();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user