Loading src/com/android/settings/fuelgauge/anomaly/Anomaly.java +45 −2 Original line number Diff line number Diff line Loading @@ -68,6 +68,8 @@ public class Anomaly implements Parcelable { public final int uid; public final int targetSdkVersion; public final long wakelockTimeMs; public final long bluetoothScanningTimeMs; public final int wakeupAlarmCount; /** * {@code true} if background restriction is enabled * Loading @@ -88,6 +90,8 @@ public class Anomaly implements Parcelable { wakelockTimeMs = builder.mWakeLockTimeMs; targetSdkVersion = builder.mTargetSdkVersion; backgroundRestrictionEnabled = builder.mBgRestrictionEnabled; bluetoothScanningTimeMs = builder.mBluetoothScanningTimeMs; wakeupAlarmCount = builder.mWakeupAlarmCount; } private Anomaly(Parcel in) { Loading @@ -98,6 +102,8 @@ public class Anomaly implements Parcelable { wakelockTimeMs = in.readLong(); targetSdkVersion = in.readInt(); backgroundRestrictionEnabled = in.readBoolean(); wakeupAlarmCount = in.readInt(); bluetoothScanningTimeMs = in.readLong(); } @Override Loading @@ -114,6 +120,8 @@ public class Anomaly implements Parcelable { dest.writeLong(wakelockTimeMs); dest.writeInt(targetSdkVersion); dest.writeBoolean(backgroundRestrictionEnabled); dest.writeInt(wakeupAlarmCount); dest.writeLong(bluetoothScanningTimeMs); } @Override Loading @@ -132,13 +140,36 @@ public class Anomaly implements Parcelable { && TextUtils.equals(displayName, other.displayName) && TextUtils.equals(packageName, other.packageName) && targetSdkVersion == other.targetSdkVersion && backgroundRestrictionEnabled == other.backgroundRestrictionEnabled; && backgroundRestrictionEnabled == other.backgroundRestrictionEnabled && wakeupAlarmCount == other.wakeupAlarmCount && bluetoothScanningTimeMs == other.bluetoothScanningTimeMs; } @Override public int hashCode() { return Objects.hash(type, uid, displayName, packageName, wakelockTimeMs, targetSdkVersion, backgroundRestrictionEnabled); backgroundRestrictionEnabled, wakeupAlarmCount, bluetoothScanningTimeMs); } @Override public String toString() { return "type=" + toAnomalyTypeText(type) + " uid=" + uid + " package=" + packageName + " displayName=" + displayName + " wakelockTimeMs=" + wakelockTimeMs + " wakeupAlarmCount=" + wakeupAlarmCount + " bluetoothTimeMs=" + bluetoothScanningTimeMs; } private String toAnomalyTypeText(@AnomalyType int type) { switch (type) { case AnomalyType.WAKEUP_ALARM: return "wakeupAlarm"; case AnomalyType.WAKE_LOCK: return "wakelock"; case AnomalyType.BLUETOOTH_SCAN: return "unoptimizedBluetoothScan"; } return ""; } public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { Loading @@ -160,6 +191,8 @@ public class Anomaly implements Parcelable { private String mPackageName; private long mWakeLockTimeMs; private boolean mBgRestrictionEnabled; private int mWakeupAlarmCount; private long mBluetoothScanningTimeMs; public Builder setType(@AnomalyType int type) { mType = type; Loading Loading @@ -196,6 +229,16 @@ public class Anomaly implements Parcelable { return this; } public Builder setWakeupAlarmCount(int wakeupAlarmCount) { mWakeupAlarmCount = wakeupAlarmCount; return this; } public Builder setBluetoothScanningTimeMs(long bluetoothScanningTimeMs) { mBluetoothScanningTimeMs = bluetoothScanningTimeMs; return this; } public Anomaly build() { return new Anomaly(this); } Loading src/com/android/settings/fuelgauge/anomaly/AnomalyLoader.java +3 −0 Original line number Diff line number Diff line Loading @@ -25,8 +25,11 @@ import android.support.annotation.VisibleForTesting; import android.util.Log; import com.android.internal.os.BatteryStatsHelper; import com.android.internal.util.ArrayUtils; import com.android.settings.utils.AsyncLoader; import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; Loading src/com/android/settings/fuelgauge/anomaly/checker/BluetoothScanAnomalyDetector.java +1 −0 Original line number Diff line number Diff line Loading @@ -93,6 +93,7 @@ public class BluetoothScanAnomalyDetector implements AnomalyDetector { .setType(Anomaly.AnomalyType.BLUETOOTH_SCAN) .setDisplayName(displayName) .setPackageName(packageName) .setBluetoothScanningTimeMs(bluetoothTimeMs) .build(); if (mAnomalyUtils.getAnomalyAction(anomaly).isActionActive(anomaly)) { Loading src/com/android/settings/fuelgauge/anomaly/checker/WakeLockAnomalyDetector.java +1 −0 Original line number Diff line number Diff line Loading @@ -97,6 +97,7 @@ public class WakeLockAnomalyDetector implements AnomalyDetector { .setType(Anomaly.AnomalyType.WAKE_LOCK) .setDisplayName(displayName) .setPackageName(packageName) .setWakeLockTimeMs(backgroundDurationMs) .build(); if (mAnomalyUtils.getAnomalyAction(anomaly).isActionActive(anomaly)) { Loading src/com/android/settings/fuelgauge/anomaly/checker/WakeupAlarmAnomalyDetector.java +4 −2 Original line number Diff line number Diff line Loading @@ -84,8 +84,9 @@ public class WakeupAlarmAnomalyDetector implements AnomalyDetector { continue; } final int wakeups = getWakeupAlarmCountFromUid(uid); if ((wakeups / totalRunningHours) > mWakeupAlarmThreshold) { final int wakeupAlarmCount = (int) (getWakeupAlarmCountFromUid(uid) / totalRunningHours); if (wakeupAlarmCount > mWakeupAlarmThreshold) { final String packageName = mBatteryUtils.getPackageName(uid.getUid()); final CharSequence displayName = Utils.getApplicationLabel(mContext, packageName); Loading @@ -100,6 +101,7 @@ public class WakeupAlarmAnomalyDetector implements AnomalyDetector { .setBackgroundRestrictionEnabled( mBatteryUtils.isBackgroundRestrictionEnabled(targetSdkVersion, uid.getUid(), packageName)) .setWakeupAlarmCount(wakeupAlarmCount) .build(); if (mAnomalyUtils.getAnomalyAction(anomaly).isActionActive(anomaly)) { Loading Loading
src/com/android/settings/fuelgauge/anomaly/Anomaly.java +45 −2 Original line number Diff line number Diff line Loading @@ -68,6 +68,8 @@ public class Anomaly implements Parcelable { public final int uid; public final int targetSdkVersion; public final long wakelockTimeMs; public final long bluetoothScanningTimeMs; public final int wakeupAlarmCount; /** * {@code true} if background restriction is enabled * Loading @@ -88,6 +90,8 @@ public class Anomaly implements Parcelable { wakelockTimeMs = builder.mWakeLockTimeMs; targetSdkVersion = builder.mTargetSdkVersion; backgroundRestrictionEnabled = builder.mBgRestrictionEnabled; bluetoothScanningTimeMs = builder.mBluetoothScanningTimeMs; wakeupAlarmCount = builder.mWakeupAlarmCount; } private Anomaly(Parcel in) { Loading @@ -98,6 +102,8 @@ public class Anomaly implements Parcelable { wakelockTimeMs = in.readLong(); targetSdkVersion = in.readInt(); backgroundRestrictionEnabled = in.readBoolean(); wakeupAlarmCount = in.readInt(); bluetoothScanningTimeMs = in.readLong(); } @Override Loading @@ -114,6 +120,8 @@ public class Anomaly implements Parcelable { dest.writeLong(wakelockTimeMs); dest.writeInt(targetSdkVersion); dest.writeBoolean(backgroundRestrictionEnabled); dest.writeInt(wakeupAlarmCount); dest.writeLong(bluetoothScanningTimeMs); } @Override Loading @@ -132,13 +140,36 @@ public class Anomaly implements Parcelable { && TextUtils.equals(displayName, other.displayName) && TextUtils.equals(packageName, other.packageName) && targetSdkVersion == other.targetSdkVersion && backgroundRestrictionEnabled == other.backgroundRestrictionEnabled; && backgroundRestrictionEnabled == other.backgroundRestrictionEnabled && wakeupAlarmCount == other.wakeupAlarmCount && bluetoothScanningTimeMs == other.bluetoothScanningTimeMs; } @Override public int hashCode() { return Objects.hash(type, uid, displayName, packageName, wakelockTimeMs, targetSdkVersion, backgroundRestrictionEnabled); backgroundRestrictionEnabled, wakeupAlarmCount, bluetoothScanningTimeMs); } @Override public String toString() { return "type=" + toAnomalyTypeText(type) + " uid=" + uid + " package=" + packageName + " displayName=" + displayName + " wakelockTimeMs=" + wakelockTimeMs + " wakeupAlarmCount=" + wakeupAlarmCount + " bluetoothTimeMs=" + bluetoothScanningTimeMs; } private String toAnomalyTypeText(@AnomalyType int type) { switch (type) { case AnomalyType.WAKEUP_ALARM: return "wakeupAlarm"; case AnomalyType.WAKE_LOCK: return "wakelock"; case AnomalyType.BLUETOOTH_SCAN: return "unoptimizedBluetoothScan"; } return ""; } public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { Loading @@ -160,6 +191,8 @@ public class Anomaly implements Parcelable { private String mPackageName; private long mWakeLockTimeMs; private boolean mBgRestrictionEnabled; private int mWakeupAlarmCount; private long mBluetoothScanningTimeMs; public Builder setType(@AnomalyType int type) { mType = type; Loading Loading @@ -196,6 +229,16 @@ public class Anomaly implements Parcelable { return this; } public Builder setWakeupAlarmCount(int wakeupAlarmCount) { mWakeupAlarmCount = wakeupAlarmCount; return this; } public Builder setBluetoothScanningTimeMs(long bluetoothScanningTimeMs) { mBluetoothScanningTimeMs = bluetoothScanningTimeMs; return this; } public Anomaly build() { return new Anomaly(this); } Loading
src/com/android/settings/fuelgauge/anomaly/AnomalyLoader.java +3 −0 Original line number Diff line number Diff line Loading @@ -25,8 +25,11 @@ import android.support.annotation.VisibleForTesting; import android.util.Log; import com.android.internal.os.BatteryStatsHelper; import com.android.internal.util.ArrayUtils; import com.android.settings.utils.AsyncLoader; import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; Loading
src/com/android/settings/fuelgauge/anomaly/checker/BluetoothScanAnomalyDetector.java +1 −0 Original line number Diff line number Diff line Loading @@ -93,6 +93,7 @@ public class BluetoothScanAnomalyDetector implements AnomalyDetector { .setType(Anomaly.AnomalyType.BLUETOOTH_SCAN) .setDisplayName(displayName) .setPackageName(packageName) .setBluetoothScanningTimeMs(bluetoothTimeMs) .build(); if (mAnomalyUtils.getAnomalyAction(anomaly).isActionActive(anomaly)) { Loading
src/com/android/settings/fuelgauge/anomaly/checker/WakeLockAnomalyDetector.java +1 −0 Original line number Diff line number Diff line Loading @@ -97,6 +97,7 @@ public class WakeLockAnomalyDetector implements AnomalyDetector { .setType(Anomaly.AnomalyType.WAKE_LOCK) .setDisplayName(displayName) .setPackageName(packageName) .setWakeLockTimeMs(backgroundDurationMs) .build(); if (mAnomalyUtils.getAnomalyAction(anomaly).isActionActive(anomaly)) { Loading
src/com/android/settings/fuelgauge/anomaly/checker/WakeupAlarmAnomalyDetector.java +4 −2 Original line number Diff line number Diff line Loading @@ -84,8 +84,9 @@ public class WakeupAlarmAnomalyDetector implements AnomalyDetector { continue; } final int wakeups = getWakeupAlarmCountFromUid(uid); if ((wakeups / totalRunningHours) > mWakeupAlarmThreshold) { final int wakeupAlarmCount = (int) (getWakeupAlarmCountFromUid(uid) / totalRunningHours); if (wakeupAlarmCount > mWakeupAlarmThreshold) { final String packageName = mBatteryUtils.getPackageName(uid.getUid()); final CharSequence displayName = Utils.getApplicationLabel(mContext, packageName); Loading @@ -100,6 +101,7 @@ public class WakeupAlarmAnomalyDetector implements AnomalyDetector { .setBackgroundRestrictionEnabled( mBatteryUtils.isBackgroundRestrictionEnabled(targetSdkVersion, uid.getUid(), packageName)) .setWakeupAlarmCount(wakeupAlarmCount) .build(); if (mAnomalyUtils.getAnomalyAction(anomaly).isActionActive(anomaly)) { Loading