This cl adds the following knobs:
1. bluetoothScanDetectionEnabled: whether to enable this detector
2. bluetoothScanThreshold: threshold about bt unoptimized scanning
time in background
Also add the default values for these knobs, which are:
1. bluetoothScanDetectionEnabled: true
2. bluetoothScanThreshold: 30 minutes
Bug:
36921532
Test: RunSettingsRoboTests
Change-Id: I7619453ebe3cc3f5a13b3bbd4fbf3b65a1f1d45c
@VisibleForTesting
static final String KEY_WAKEUP_ALARM_DETECTION_ENABLED = "wakeup_alarm_enabled";
@VisibleForTesting
+ static final String KEY_BLUETOOTH_SCAN_DETECTION_ENABLED = "bluetooth_scan_enabled";
+ @VisibleForTesting
static final String KEY_WAKELOCK_THRESHOLD = "wakelock_threshold";
@VisibleForTesting
static final String KEY_WAKEUP_ALARM_THRESHOLD = "wakeup_alarm_threshold";
+ @VisibleForTesting
+ static final String KEY_BLUETOOTH_SCAN_THRESHOLD = "bluetooth_scan_threshold";
/**
* {@code true} if general anomaly detection is enabled
public final boolean wakeupAlarmDetectionEnabled;
/**
+ * {@code true} if bluetooth scanning detection is enabled
+ *
+ * @see Settings.Global#ANOMALY_DETECTION_CONSTANTS
+ * @see #KEY_BLUETOOTH_SCAN_THRESHOLD
+ */
+ public final boolean bluetoothScanDetectionEnabled;
+
+ /**
* Threshold for wakelock time in milli seconds
*
* @see Settings.Global#ANOMALY_DETECTION_CONSTANTS
*/
public final long wakeupAlarmThreshold;
+ /**
+ * Threshold for bluetooth unoptimized scanning time in milli seconds
+ *
+ * @see Settings.Global#ANOMALY_DETECTION_CONSTANTS
+ * @see #KEY_BLUETOOTH_SCAN_THRESHOLD
+ */
+ public final long bluetoothScanThreshold;
+
private final KeyValueListParserWrapper mParserWrapper;
public AnomalyDetectionPolicy(Context context) {
wakeLockDetectionEnabled = mParserWrapper.getBoolean(KEY_WAKELOCK_DETECTION_ENABLED, true);
wakeupAlarmDetectionEnabled = mParserWrapper.getBoolean(KEY_WAKEUP_ALARM_DETECTION_ENABLED,
true);
+ bluetoothScanDetectionEnabled = mParserWrapper.getBoolean(
+ KEY_BLUETOOTH_SCAN_DETECTION_ENABLED, true);
wakeLockThreshold = mParserWrapper.getLong(KEY_WAKELOCK_THRESHOLD,
DateUtils.HOUR_IN_MILLIS);
wakeupAlarmThreshold = mParserWrapper.getLong(KEY_WAKEUP_ALARM_THRESHOLD, 60);
+ bluetoothScanThreshold = mParserWrapper.getLong(KEY_BLUETOOTH_SCAN_THRESHOLD,
+ 30 * DateUtils.MINUTE_IN_MILLIS);
}
public boolean isAnomalyDetectorEnabled(@Anomaly.AnomalyType int type) {
return wakeLockDetectionEnabled;
case Anomaly.AnomalyType.WAKEUP_ALARM:
return wakeupAlarmDetectionEnabled;
+ case Anomaly.AnomalyType.BLUETOOTH_SCAN:
+ return bluetoothScanDetectionEnabled;
default:
return false; // Disabled when no this type
}
mBatteryUtils = BatteryUtils.getInstance(context);
mAnomalyAction = AnomalyUtils.getInstance(context).getAnomalyAction(
Anomaly.AnomalyType.BLUETOOTH_SCAN);
- //TODO(b/36921532): hook up it to AnomalyDectionPolicy
- mBluetoothScanningThreshold = 30 * DateUtils.MINUTE_IN_MILLIS;
+ mBluetoothScanningThreshold = policy.bluetoothScanThreshold;
}
@Override
+ ",wakelock_enabled=false"
+ ",wakelock_threshold=3000"
+ ",wakeup_alarm_enabled=true"
- + ",wakeup_alarm_threshold=100";
+ + ",wakeup_alarm_threshold=100"
+ + ",bluetooth_scan_enabled=true"
+ + ",bluetooth_scan_threshold=2000";
private Context mContext;
private KeyValueListParserWrapper mKeyValueListParserWrapper;
assertThat(anomalyDetectionPolicy.wakeLockThreshold).isEqualTo(3000);
assertThat(anomalyDetectionPolicy.wakeupAlarmDetectionEnabled).isTrue();
assertThat(anomalyDetectionPolicy.wakeupAlarmThreshold).isEqualTo(100);
+ assertThat(anomalyDetectionPolicy.bluetoothScanDetectionEnabled).isTrue();
+ assertThat(anomalyDetectionPolicy.bluetoothScanThreshold).isEqualTo(2000);
}
@Test
assertThat(anomalyDetectionPolicy.wakeLockThreshold).isEqualTo(DateUtils.HOUR_IN_MILLIS);
assertThat(anomalyDetectionPolicy.wakeupAlarmDetectionEnabled).isTrue();
assertThat(anomalyDetectionPolicy.wakeupAlarmThreshold).isEqualTo(60);
+ assertThat(anomalyDetectionPolicy.bluetoothScanDetectionEnabled).isTrue();
+ assertThat(anomalyDetectionPolicy.bluetoothScanThreshold).isEqualTo(
+ 30 * DateUtils.MINUTE_IN_MILLIS);
}
@Test
Anomaly.AnomalyType.WAKE_LOCK)).isFalse();
assertThat(anomalyDetectionPolicy.isAnomalyDetectorEnabled(
Anomaly.AnomalyType.WAKEUP_ALARM)).isTrue();
+ assertThat(anomalyDetectionPolicy.isAnomalyDetectorEnabled(
+ Anomaly.AnomalyType.BLUETOOTH_SCAN)).isTrue();
}
private AnomalyDetectionPolicy createAnomalyPolicyWithConfig() {
AnomalyDetectionPolicy.KEY_WAKELOCK_DETECTION_ENABLED, true);
doReturn(true).when(mKeyValueListParserWrapper).getBoolean(
AnomalyDetectionPolicy.KEY_WAKEUP_ALARM_DETECTION_ENABLED, true);
+ doReturn(true).when(mKeyValueListParserWrapper).getBoolean(
+ AnomalyDetectionPolicy.KEY_BLUETOOTH_SCAN_DETECTION_ENABLED, true);
return new AnomalyDetectionPolicy(mContext, mKeyValueListParserWrapper);
}
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
import java.util.ArrayList;
import java.util.List;
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
+ ReflectionHelpers.setField(mPolicy, "bluetoothScanThreshold",
+ 30 * DateUtils.MINUTE_IN_MILLIS);
mAnomalySipper.uidObj = mAnomalyUid;
doReturn(ANOMALY_UID).when(mAnomalyUid).getUid();