Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit edfebbaa authored by jackqdyulei's avatar jackqdyulei
Browse files

Add log for anomaly.

This cl adds all the info that need to be logged to Anomaly and add a
dump method for log.

Bug: 63776178
Test: RunSettingsRoboTests
Change-Id: If762bfca725fee07944ffa23998332c81335a37f
parent e4c9b716
Loading
Loading
Loading
Loading
+45 −2
Original line number Diff line number Diff line
@@ -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
     *
@@ -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) {
@@ -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
@@ -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
@@ -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() {
@@ -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;
@@ -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);
        }
+3 −0
Original line number Diff line number Diff line
@@ -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;

+1 −0
Original line number Diff line number Diff line
@@ -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)) {
+1 −0
Original line number Diff line number Diff line
@@ -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)) {
+4 −2
Original line number Diff line number Diff line
@@ -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);
@@ -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