Add wakelock anomaly detector

This cl detects whether apps hold wakelock for long time.
For now we use the following attribute:
1. Longest total duration time among all the wakelocks
for one app.

Following cl will:
1. Get threshold from server side.
2. Add more attributes to make the detection more robust.

Bug: 36925184
Test: RunSettingsRoboTests

Change-Id: I1946faf69c363f6aa823d0005d6e03bc9082c085
This commit is contained in:
jackqdyulei
2017-04-25 18:22:45 -07:00
parent f223383936
commit 4aa3358c4c
5 changed files with 263 additions and 10 deletions

View File

@@ -19,9 +19,11 @@ package com.android.settings.fuelgauge.anomaly;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.IntDef;
import android.text.TextUtils;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Objects;
/**
* Data that represents an app has been detected as anomaly. It contains
@@ -53,7 +55,7 @@ public class Anomaly implements Parcelable {
/**
* Display name of this anomaly, usually it is the app name
*/
public final String displayName;
public final CharSequence displayName;
public final String packageName;
private Anomaly(Builder builder) {
@@ -67,7 +69,7 @@ public class Anomaly implements Parcelable {
private Anomaly(Parcel in) {
type = in.readInt();
uid = in.readInt();
displayName = in.readString();
displayName = in.readCharSequence();
packageName = in.readString();
wakelockTimeMs = in.readLong();
}
@@ -81,11 +83,34 @@ public class Anomaly implements Parcelable {
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(type);
dest.writeInt(uid);
dest.writeString(displayName);
dest.writeCharSequence(displayName);
dest.writeString(packageName);
dest.writeLong(wakelockTimeMs);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof Anomaly)) {
return false;
}
Anomaly other = (Anomaly) obj;
return type == other.type
&& uid == other.uid
&& wakelockTimeMs == other.wakelockTimeMs
&& TextUtils.equals(displayName, other.displayName)
&& TextUtils.equals(packageName, other.packageName);
}
@Override
public int hashCode() {
return Objects.hash(type, uid, displayName, packageName, wakelockTimeMs);
}
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public Anomaly createFromParcel(Parcel in) {
return new Anomaly(in);
@@ -100,7 +125,7 @@ public class Anomaly implements Parcelable {
@AnomalyType
private int mType;
private int mUid;
private String mDisplayName;
private CharSequence mDisplayName;
private String mPackageName;
private long mWakeLockTimeMs;
@@ -114,7 +139,7 @@ public class Anomaly implements Parcelable {
return this;
}
public Builder setDisplayName(String displayName) {
public Builder setDisplayName(CharSequence displayName) {
mDisplayName = displayName;
return this;
}