Merge "Add flag for wakeup alarm"
This commit is contained in:
@@ -35,7 +35,11 @@ public class AnomalyDetectionPolicy {
|
||||
@VisibleForTesting
|
||||
static final String KEY_WAKELOCK_DETECTION_ENABLED = "wakelock_enabled";
|
||||
@VisibleForTesting
|
||||
static final String KEY_WAKEUP_ALARM_DETECTION_ENABLED = "wakeup_alarm_enabled";
|
||||
@VisibleForTesting
|
||||
static final String KEY_WAKELOCK_THRESHOLD = "wakelock_threshold";
|
||||
@VisibleForTesting
|
||||
static final String KEY_WAKEUP_ALARM_THRESHOLD = "wakeup_alarm_threshold";
|
||||
|
||||
/**
|
||||
* {@code true} if general anomaly detection is enabled
|
||||
@@ -53,6 +57,14 @@ public class AnomalyDetectionPolicy {
|
||||
*/
|
||||
public final boolean wakeLockDetectionEnabled;
|
||||
|
||||
/**
|
||||
* {@code true} if wakeup alarm detection is enabled
|
||||
*
|
||||
* @see Settings.Global#ANOMALY_DETECTION_CONSTANTS
|
||||
* @see #KEY_WAKEUP_ALARM_DETECTION_ENABLED
|
||||
*/
|
||||
public final boolean wakeupAlarmDetectionEnabled;
|
||||
|
||||
/**
|
||||
* Threshold for wakelock time in milli seconds
|
||||
*
|
||||
@@ -61,6 +73,14 @@ public class AnomalyDetectionPolicy {
|
||||
*/
|
||||
public final long wakeLockThreshold;
|
||||
|
||||
/**
|
||||
* Threshold for wakeup alarm count per hour
|
||||
*
|
||||
* @see Settings.Global#ANOMALY_DETECTION_CONSTANTS
|
||||
* @see #KEY_WAKEUP_ALARM_THRESHOLD
|
||||
*/
|
||||
public final long wakeupAlarmThreshold;
|
||||
|
||||
private final KeyValueListParserWrapper mParserWrapper;
|
||||
|
||||
public AnomalyDetectionPolicy(Context context) {
|
||||
@@ -81,8 +101,11 @@ public class AnomalyDetectionPolicy {
|
||||
|
||||
anomalyDetectionEnabled = mParserWrapper.getBoolean(KEY_ANOMALY_DETECTION_ENABLED, true);
|
||||
wakeLockDetectionEnabled = mParserWrapper.getBoolean(KEY_WAKELOCK_DETECTION_ENABLED, true);
|
||||
wakeupAlarmDetectionEnabled = mParserWrapper.getBoolean(KEY_WAKEUP_ALARM_DETECTION_ENABLED,
|
||||
true);
|
||||
wakeLockThreshold = mParserWrapper.getLong(KEY_WAKELOCK_THRESHOLD,
|
||||
DateUtils.HOUR_IN_MILLIS);
|
||||
wakeupAlarmThreshold = mParserWrapper.getLong(KEY_WAKEUP_ALARM_THRESHOLD, 60);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -39,15 +39,20 @@ import java.util.List;
|
||||
*/
|
||||
public class WakeupAlarmAnomalyDetector implements AnomalyDetector {
|
||||
private static final String TAG = "WakeupAlarmAnomalyDetector";
|
||||
//TODO: add this threshold into AnomalyDetectionPolicy
|
||||
private static final int WAKEUP_ALARM_THRESHOLD = 60;
|
||||
private Context mContext;
|
||||
@VisibleForTesting
|
||||
BatteryUtils mBatteryUtils;
|
||||
private long mWakeupAlarmThreshold;
|
||||
private Context mContext;
|
||||
|
||||
public WakeupAlarmAnomalyDetector(Context context) {
|
||||
this(context, new AnomalyDetectionPolicy(context));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
WakeupAlarmAnomalyDetector(Context context, AnomalyDetectionPolicy policy) {
|
||||
mContext = context;
|
||||
mBatteryUtils = BatteryUtils.getInstance(context);
|
||||
mWakeupAlarmThreshold = policy.wakeupAlarmThreshold;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,7 +71,7 @@ public class WakeupAlarmAnomalyDetector implements AnomalyDetector {
|
||||
}
|
||||
|
||||
final int wakeups = getWakeupAlarmCountFromUid(uid);
|
||||
if ((wakeups / totalRunningHours) > WAKEUP_ALARM_THRESHOLD) {
|
||||
if ((wakeups / totalRunningHours) > mWakeupAlarmThreshold) {
|
||||
final String packageName = mBatteryUtils.getPackageName(uid.getUid());
|
||||
final CharSequence displayName = Utils.getApplicationLabel(mContext,
|
||||
packageName);
|
||||
|
Reference in New Issue
Block a user