Loading packages/SystemUI/src/com/android/systemui/doze/DozeEvent.java +7 −19 Original line number Diff line number Diff line Loading @@ -28,10 +28,12 @@ import java.lang.annotation.RetentionPolicy; * and triaging purposes. */ public class DozeEvent extends RichEvent { public static final int TOTAL_EVENT_TYPES = 19; public DozeEvent(int logLevel, int type, String reason) { super(logLevel, type, reason); /** * Initializes a doze event */ public DozeEvent init(@EventType int type, String reason) { super.init(DEBUG, type, reason); return this; } /** Loading Loading @@ -89,21 +91,6 @@ public class DozeEvent extends RichEvent { } } /** * Builds a DozeEvent. */ public static class DozeEventBuilder extends RichEvent.Builder<DozeEventBuilder> { @Override public DozeEventBuilder getBuilder() { return this; } @Override public RichEvent build() { return new DozeEvent(mLogLevel, mType, mReason); } } @IntDef({PICKUP_WAKEUP, PULSE_START, PULSE_FINISH, NOTIFICATION_PULSE, DOZING, FLING, EMERGENCY_CALL, KEYGUARD_BOUNCER_CHANGED, SCREEN_ON, SCREEN_OFF, MISSED_TICK, TIME_TICK_SCHEDULED, KEYGUARD_VISIBILITY_CHANGE, DOZE_STATE_CHANGED, WAKE_DISPLAY, Loading Loading @@ -132,6 +119,7 @@ public class DozeEvent extends RichEvent { public static final int PULSE_DROPPED = 16; public static final int PULSE_DISABLED_BY_PROX = 17; public static final int SENSOR_TRIGGERED = 18; public static final int TOTAL_EVENT_TYPES = 19; public static final int TOTAL_REASONS = 10; @IntDef({PULSE_REASON_NONE, PULSE_REASON_INTENT, PULSE_REASON_NOTIFICATION, Loading packages/SystemUI/src/com/android/systemui/doze/DozeLog.java +31 −35 Original line number Diff line number Diff line Loading @@ -35,9 +35,11 @@ import javax.inject.Singleton; * dependency DumpController DozeLog */ @Singleton public class DozeLog extends SysuiLog { public class DozeLog extends SysuiLog<DozeEvent> { private static final String TAG = "DozeLog"; private DozeEvent mRecycledEvent; private boolean mPulsing; private long mSince; private SummaryStats mPickupPulseNearVibrationStats; Loading Loading @@ -73,8 +75,8 @@ public class DozeLog extends SysuiLog { * Appends pickup wakeup event to the logs */ public void tracePickupWakeUp(boolean withinVibrationThreshold) { if (log(DozeEvent.PICKUP_WAKEUP, "withinVibrationThreshold=" + withinVibrationThreshold)) { log(DozeEvent.PICKUP_WAKEUP, "withinVibrationThreshold=" + withinVibrationThreshold); if (mEnabled) { (withinVibrationThreshold ? mPickupPulseNearVibrationStats : mPickupPulseNotNearVibrationStats).append(); } Loading @@ -85,27 +87,24 @@ public class DozeLog extends SysuiLog { * @param reason why the pulse started */ public void tracePulseStart(@DozeEvent.Reason int reason) { if (log(DozeEvent.PULSE_START, DozeEvent.reasonToString(reason))) { mPulsing = true; } log(DozeEvent.PULSE_START, DozeEvent.reasonToString(reason)); if (mEnabled) mPulsing = true; } /** * Appends pulse finished event to the logs */ public void tracePulseFinish() { if (log(DozeEvent.PULSE_FINISH)) { mPulsing = false; } log(DozeEvent.PULSE_FINISH); if (mEnabled) mPulsing = false; } /** * Appends pulse event to the logs */ public void traceNotificationPulse() { if (log(DozeEvent.NOTIFICATION_PULSE)) { mNotificationPulseStats.append(); } log(DozeEvent.NOTIFICATION_PULSE); if (mEnabled) mNotificationPulseStats.append(); } /** Loading @@ -113,9 +112,8 @@ public class DozeLog extends SysuiLog { * @param dozing true if dozing, else false */ public void traceDozing(boolean dozing) { if (log(DozeEvent.DOZING, "dozing=" + dozing)) { mPulsing = false; } log(DozeEvent.DOZING, "dozing=" + dozing); if (mEnabled) mPulsing = false; } /** Loading @@ -133,9 +131,8 @@ public class DozeLog extends SysuiLog { * Appends emergency call event to the logs */ public void traceEmergencyCall() { if (log(DozeEvent.EMERGENCY_CALL)) { mEmergencyCallStats.append(); } log(DozeEvent.EMERGENCY_CALL); if (mEnabled) mEmergencyCallStats.append(); } /** Loading @@ -150,7 +147,8 @@ public class DozeLog extends SysuiLog { * Appends screen-on event to the logs */ public void traceScreenOn() { if (log(DozeEvent.SCREEN_ON, "pulsing=" + mPulsing)) { log(DozeEvent.SCREEN_ON, "pulsing=" + mPulsing); if (mEnabled) { (mPulsing ? mScreenOnPulsingStats : mScreenOnNotPulsingStats).append(); mPulsing = false; } Loading Loading @@ -188,10 +186,8 @@ public class DozeLog extends SysuiLog { * @param showing whether the keyguard is now showing */ public void traceKeyguard(boolean showing) { if (log(DozeEvent.KEYGUARD_VISIBILITY_CHANGE, "showing=" + showing) && !showing) { mPulsing = false; } log(DozeEvent.KEYGUARD_VISIBILITY_CHANGE, "showing=" + showing); if (mEnabled && !showing) mPulsing = false; } /** Loading @@ -217,12 +213,11 @@ public class DozeLog extends SysuiLog { * @param reason why proximity result was triggered */ public void traceProximityResult(boolean near, long millis, @DozeEvent.Reason int reason) { if (log(DozeEvent.PROXIMITY_RESULT, log(DozeEvent.PROXIMITY_RESULT, " reason=" + DozeEvent.reasonToString(reason) + " near=" + near + " millis=" + millis)) { mProxStats[reason][near ? 0 : 1].append(); } + " millis=" + millis); if (mEnabled) mProxStats[reason][near ? 0 : 1].append(); } /** Loading Loading @@ -250,15 +245,16 @@ public class DozeLog extends SysuiLog { } } private boolean log(@DozeEvent.EventType int eventType) { return log(eventType, ""); private void log(@DozeEvent.EventType int eventType) { log(eventType, ""); } private boolean log(@DozeEvent.EventType int eventType, String msg) { return super.log(new DozeEvent.DozeEventBuilder() .setType(eventType) .setReason(msg) .build()); private void log(@DozeEvent.EventType int eventType, String msg) { if (mRecycledEvent != null) { mRecycledEvent = log(mRecycledEvent.init(eventType, msg)); } else { mRecycledEvent = log(new DozeEvent().init(eventType, msg)); } } /** Loading packages/SystemUI/src/com/android/systemui/log/Event.java +23 −6 Original line number Diff line number Diff line Loading @@ -37,20 +37,28 @@ public class Event { public static final int INFO = 4; public static final int WARN = 5; public static final int ERROR = 6; public static final @Level int DEFAULT_LOG_LEVEL = DEBUG; private long mTimestamp; private @Level int mLogLevel = DEBUG; protected String mMessage; private @Level int mLogLevel = DEFAULT_LOG_LEVEL; private String mMessage = ""; public Event(String message) { mTimestamp = System.currentTimeMillis(); mMessage = message; /** * initialize an event with a message */ public Event init(String message) { init(DEFAULT_LOG_LEVEL, message); return this; } public Event(@Level int logLevel, String message) { /** * initialize an event with a logLevel and message */ public Event init(@Level int logLevel, String message) { mTimestamp = System.currentTimeMillis(); mLogLevel = logLevel; mMessage = message; return this; } public String getMessage() { Loading @@ -64,4 +72,13 @@ public class Event { public @Level int getLogLevel() { return mLogLevel; } /** * Recycle this event */ void recycle() { mTimestamp = -1; mLogLevel = DEFAULT_LOG_LEVEL; mMessage = ""; } } packages/SystemUI/src/com/android/systemui/log/RichEvent.java +32 −16 Original line number Diff line number Diff line Loading @@ -23,23 +23,21 @@ package com.android.systemui.log; * Events are stored in {@link SysuiLog} and can be printed in a dumpsys. */ public abstract class RichEvent extends Event { private final int mType; private final String mReason; private int mType; /** * Create a rich event that includes an event type that matches with an index in the array * Initializes a rich event that includes an event type that matches with an index in the array * getEventLabels(). */ public RichEvent(@Event.Level int logLevel, int type, String reason) { super(logLevel, null); public RichEvent init(@Event.Level int logLevel, int type, String reason) { final int numEvents = getEventLabels().length; if (type < 0 || type >= numEvents) { throw new IllegalArgumentException("Unsupported event type. Events only supported" + " from 0 to " + (numEvents - 1) + ", but given type=" + type); } mType = type; mReason = reason; mMessage = getEventLabels()[mType] + " " + mReason; super.init(logLevel, getEventLabels()[mType] + " " + reason); return this; } /** Loading @@ -49,25 +47,43 @@ public abstract class RichEvent extends Event { */ public abstract String[] getEventLabels(); public int getType() { return mType; @Override public void recycle() { super.recycle(); mType = -1; } public String getReason() { return mReason; public int getType() { return mType; } /** * Builder to build a RichEvent. * @param <B> Log specific builder that is extending this builder * @param <E> Type of event we'll be building */ public abstract static class Builder<B extends Builder<B>> { public abstract static class Builder<B extends Builder<B, E>, E extends RichEvent> { public static final int UNINITIALIZED = -1; public final SysuiLog mLog; private B mBuilder = getBuilder(); protected int mType = UNINITIALIZED; protected int mType; protected String mReason; protected @Level int mLogLevel = VERBOSE; protected @Level int mLogLevel; public Builder(SysuiLog sysuiLog) { mLog = sysuiLog; reset(); } /** * Reset this builder's parameters so it can be reused to build another RichEvent. */ public void reset() { mType = UNINITIALIZED; mReason = null; mLogLevel = VERBOSE; } /** * Get the log-specific builder. Loading @@ -75,9 +91,9 @@ public abstract class RichEvent extends Event { public abstract B getBuilder(); /** * Build the log-specific event. * Build the log-specific event given an event to populate. */ public abstract RichEvent build(); public abstract E build(E e); /** * Optional - set the log level. Defaults to DEBUG. Loading packages/SystemUI/src/com/android/systemui/log/SysuiLog.java +24 −20 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.os.Build; import android.os.SystemProperties; import android.util.Log; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; import com.android.systemui.DumpController; import com.android.systemui.Dumpable; Loading @@ -39,22 +40,25 @@ import java.util.Locale; * To manually view the logs via adb: * adb shell dumpsys activity service com.android.systemui/.SystemUIService \ * dependency DumpController <SysuiLogId> * * Logs can be disabled by setting the following SystemProperty and then restarting the device: * adb shell setprop persist.sysui.log.enabled.<id> true/false && adb reboot * * @param <E> Type of event we'll be logging */ public class SysuiLog implements Dumpable { public class SysuiLog<E extends Event> implements Dumpable { public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("MM-dd HH:mm:ss", Locale.US); private final Object mDataLock = new Object(); protected final Object mDataLock = new Object(); private final String mId; private final int mMaxLogs; private boolean mEnabled; protected boolean mEnabled; @VisibleForTesting protected ArrayDeque<Event> mTimeline; @VisibleForTesting protected ArrayDeque<E> mTimeline; /** * Creates a SysuiLog * To enable or disable logs, set the system property and then restart the device: * adb shell setprop sysui.log.enabled.<id> true/false && adb reboot * @param dumpController where to register this logger's dumpsys * @param id user-readable tag for this logger * @param maxDebugLogs maximum number of logs to retain when {@link sDebuggable} is true Loading @@ -74,23 +78,20 @@ public class SysuiLog implements Dumpable { dumpController.registerDumpable(mId, this); } public SysuiLog(DumpController dumpController, String id) { this(dumpController, id, DEFAULT_MAX_DEBUG_LOGS, DEFAULT_MAX_LOGS); } /** * Logs an event to the timeline which can be printed by the dumpsys. * May also log to logcat if enabled. * @return true if event was logged, else false * @return the last event that was discarded from the Timeline (can be recycled) */ public boolean log(Event event) { public E log(E event) { if (!mEnabled) { return false; return null; } E recycledEvent = null; synchronized (mDataLock) { if (mTimeline.size() >= mMaxLogs) { mTimeline.removeFirst(); recycledEvent = mTimeline.removeFirst(); } mTimeline.add(event); Loading @@ -116,13 +117,18 @@ public class SysuiLog implements Dumpable { break; } } return true; if (recycledEvent != null) { recycledEvent.recycle(); } return recycledEvent; } /** * @return user-readable string of the given event with timestamp */ public String eventToTimestampedString(Event event) { private String eventToTimestampedString(Event event) { StringBuilder sb = new StringBuilder(); sb.append(SysuiLog.DATE_FORMAT.format(event.getTimestamp())); sb.append(" "); Loading @@ -137,9 +143,7 @@ public class SysuiLog implements Dumpable { return event.getMessage(); } /** * only call on this method if you have the mDataLock */ @GuardedBy("mDataLock") private void dumpTimelineLocked(PrintWriter pw) { pw.println("\tTimeline:"); Loading @@ -162,7 +166,7 @@ public class SysuiLog implements Dumpable { } private static boolean sDebuggable = Build.IS_DEBUGGABLE; private static final String SYSPROP_ENABLED_PREFIX = "sysui.log.enabled."; private static final String SYSPROP_ENABLED_PREFIX = "persist.sysui.log.enabled."; private static final boolean LOG_TO_LOGCAT_ENABLED = sDebuggable; private static final boolean DEFAULT_ENABLED = sDebuggable; private static final int DEFAULT_MAX_DEBUG_LOGS = 100; Loading Loading
packages/SystemUI/src/com/android/systemui/doze/DozeEvent.java +7 −19 Original line number Diff line number Diff line Loading @@ -28,10 +28,12 @@ import java.lang.annotation.RetentionPolicy; * and triaging purposes. */ public class DozeEvent extends RichEvent { public static final int TOTAL_EVENT_TYPES = 19; public DozeEvent(int logLevel, int type, String reason) { super(logLevel, type, reason); /** * Initializes a doze event */ public DozeEvent init(@EventType int type, String reason) { super.init(DEBUG, type, reason); return this; } /** Loading Loading @@ -89,21 +91,6 @@ public class DozeEvent extends RichEvent { } } /** * Builds a DozeEvent. */ public static class DozeEventBuilder extends RichEvent.Builder<DozeEventBuilder> { @Override public DozeEventBuilder getBuilder() { return this; } @Override public RichEvent build() { return new DozeEvent(mLogLevel, mType, mReason); } } @IntDef({PICKUP_WAKEUP, PULSE_START, PULSE_FINISH, NOTIFICATION_PULSE, DOZING, FLING, EMERGENCY_CALL, KEYGUARD_BOUNCER_CHANGED, SCREEN_ON, SCREEN_OFF, MISSED_TICK, TIME_TICK_SCHEDULED, KEYGUARD_VISIBILITY_CHANGE, DOZE_STATE_CHANGED, WAKE_DISPLAY, Loading Loading @@ -132,6 +119,7 @@ public class DozeEvent extends RichEvent { public static final int PULSE_DROPPED = 16; public static final int PULSE_DISABLED_BY_PROX = 17; public static final int SENSOR_TRIGGERED = 18; public static final int TOTAL_EVENT_TYPES = 19; public static final int TOTAL_REASONS = 10; @IntDef({PULSE_REASON_NONE, PULSE_REASON_INTENT, PULSE_REASON_NOTIFICATION, Loading
packages/SystemUI/src/com/android/systemui/doze/DozeLog.java +31 −35 Original line number Diff line number Diff line Loading @@ -35,9 +35,11 @@ import javax.inject.Singleton; * dependency DumpController DozeLog */ @Singleton public class DozeLog extends SysuiLog { public class DozeLog extends SysuiLog<DozeEvent> { private static final String TAG = "DozeLog"; private DozeEvent mRecycledEvent; private boolean mPulsing; private long mSince; private SummaryStats mPickupPulseNearVibrationStats; Loading Loading @@ -73,8 +75,8 @@ public class DozeLog extends SysuiLog { * Appends pickup wakeup event to the logs */ public void tracePickupWakeUp(boolean withinVibrationThreshold) { if (log(DozeEvent.PICKUP_WAKEUP, "withinVibrationThreshold=" + withinVibrationThreshold)) { log(DozeEvent.PICKUP_WAKEUP, "withinVibrationThreshold=" + withinVibrationThreshold); if (mEnabled) { (withinVibrationThreshold ? mPickupPulseNearVibrationStats : mPickupPulseNotNearVibrationStats).append(); } Loading @@ -85,27 +87,24 @@ public class DozeLog extends SysuiLog { * @param reason why the pulse started */ public void tracePulseStart(@DozeEvent.Reason int reason) { if (log(DozeEvent.PULSE_START, DozeEvent.reasonToString(reason))) { mPulsing = true; } log(DozeEvent.PULSE_START, DozeEvent.reasonToString(reason)); if (mEnabled) mPulsing = true; } /** * Appends pulse finished event to the logs */ public void tracePulseFinish() { if (log(DozeEvent.PULSE_FINISH)) { mPulsing = false; } log(DozeEvent.PULSE_FINISH); if (mEnabled) mPulsing = false; } /** * Appends pulse event to the logs */ public void traceNotificationPulse() { if (log(DozeEvent.NOTIFICATION_PULSE)) { mNotificationPulseStats.append(); } log(DozeEvent.NOTIFICATION_PULSE); if (mEnabled) mNotificationPulseStats.append(); } /** Loading @@ -113,9 +112,8 @@ public class DozeLog extends SysuiLog { * @param dozing true if dozing, else false */ public void traceDozing(boolean dozing) { if (log(DozeEvent.DOZING, "dozing=" + dozing)) { mPulsing = false; } log(DozeEvent.DOZING, "dozing=" + dozing); if (mEnabled) mPulsing = false; } /** Loading @@ -133,9 +131,8 @@ public class DozeLog extends SysuiLog { * Appends emergency call event to the logs */ public void traceEmergencyCall() { if (log(DozeEvent.EMERGENCY_CALL)) { mEmergencyCallStats.append(); } log(DozeEvent.EMERGENCY_CALL); if (mEnabled) mEmergencyCallStats.append(); } /** Loading @@ -150,7 +147,8 @@ public class DozeLog extends SysuiLog { * Appends screen-on event to the logs */ public void traceScreenOn() { if (log(DozeEvent.SCREEN_ON, "pulsing=" + mPulsing)) { log(DozeEvent.SCREEN_ON, "pulsing=" + mPulsing); if (mEnabled) { (mPulsing ? mScreenOnPulsingStats : mScreenOnNotPulsingStats).append(); mPulsing = false; } Loading Loading @@ -188,10 +186,8 @@ public class DozeLog extends SysuiLog { * @param showing whether the keyguard is now showing */ public void traceKeyguard(boolean showing) { if (log(DozeEvent.KEYGUARD_VISIBILITY_CHANGE, "showing=" + showing) && !showing) { mPulsing = false; } log(DozeEvent.KEYGUARD_VISIBILITY_CHANGE, "showing=" + showing); if (mEnabled && !showing) mPulsing = false; } /** Loading @@ -217,12 +213,11 @@ public class DozeLog extends SysuiLog { * @param reason why proximity result was triggered */ public void traceProximityResult(boolean near, long millis, @DozeEvent.Reason int reason) { if (log(DozeEvent.PROXIMITY_RESULT, log(DozeEvent.PROXIMITY_RESULT, " reason=" + DozeEvent.reasonToString(reason) + " near=" + near + " millis=" + millis)) { mProxStats[reason][near ? 0 : 1].append(); } + " millis=" + millis); if (mEnabled) mProxStats[reason][near ? 0 : 1].append(); } /** Loading Loading @@ -250,15 +245,16 @@ public class DozeLog extends SysuiLog { } } private boolean log(@DozeEvent.EventType int eventType) { return log(eventType, ""); private void log(@DozeEvent.EventType int eventType) { log(eventType, ""); } private boolean log(@DozeEvent.EventType int eventType, String msg) { return super.log(new DozeEvent.DozeEventBuilder() .setType(eventType) .setReason(msg) .build()); private void log(@DozeEvent.EventType int eventType, String msg) { if (mRecycledEvent != null) { mRecycledEvent = log(mRecycledEvent.init(eventType, msg)); } else { mRecycledEvent = log(new DozeEvent().init(eventType, msg)); } } /** Loading
packages/SystemUI/src/com/android/systemui/log/Event.java +23 −6 Original line number Diff line number Diff line Loading @@ -37,20 +37,28 @@ public class Event { public static final int INFO = 4; public static final int WARN = 5; public static final int ERROR = 6; public static final @Level int DEFAULT_LOG_LEVEL = DEBUG; private long mTimestamp; private @Level int mLogLevel = DEBUG; protected String mMessage; private @Level int mLogLevel = DEFAULT_LOG_LEVEL; private String mMessage = ""; public Event(String message) { mTimestamp = System.currentTimeMillis(); mMessage = message; /** * initialize an event with a message */ public Event init(String message) { init(DEFAULT_LOG_LEVEL, message); return this; } public Event(@Level int logLevel, String message) { /** * initialize an event with a logLevel and message */ public Event init(@Level int logLevel, String message) { mTimestamp = System.currentTimeMillis(); mLogLevel = logLevel; mMessage = message; return this; } public String getMessage() { Loading @@ -64,4 +72,13 @@ public class Event { public @Level int getLogLevel() { return mLogLevel; } /** * Recycle this event */ void recycle() { mTimestamp = -1; mLogLevel = DEFAULT_LOG_LEVEL; mMessage = ""; } }
packages/SystemUI/src/com/android/systemui/log/RichEvent.java +32 −16 Original line number Diff line number Diff line Loading @@ -23,23 +23,21 @@ package com.android.systemui.log; * Events are stored in {@link SysuiLog} and can be printed in a dumpsys. */ public abstract class RichEvent extends Event { private final int mType; private final String mReason; private int mType; /** * Create a rich event that includes an event type that matches with an index in the array * Initializes a rich event that includes an event type that matches with an index in the array * getEventLabels(). */ public RichEvent(@Event.Level int logLevel, int type, String reason) { super(logLevel, null); public RichEvent init(@Event.Level int logLevel, int type, String reason) { final int numEvents = getEventLabels().length; if (type < 0 || type >= numEvents) { throw new IllegalArgumentException("Unsupported event type. Events only supported" + " from 0 to " + (numEvents - 1) + ", but given type=" + type); } mType = type; mReason = reason; mMessage = getEventLabels()[mType] + " " + mReason; super.init(logLevel, getEventLabels()[mType] + " " + reason); return this; } /** Loading @@ -49,25 +47,43 @@ public abstract class RichEvent extends Event { */ public abstract String[] getEventLabels(); public int getType() { return mType; @Override public void recycle() { super.recycle(); mType = -1; } public String getReason() { return mReason; public int getType() { return mType; } /** * Builder to build a RichEvent. * @param <B> Log specific builder that is extending this builder * @param <E> Type of event we'll be building */ public abstract static class Builder<B extends Builder<B>> { public abstract static class Builder<B extends Builder<B, E>, E extends RichEvent> { public static final int UNINITIALIZED = -1; public final SysuiLog mLog; private B mBuilder = getBuilder(); protected int mType = UNINITIALIZED; protected int mType; protected String mReason; protected @Level int mLogLevel = VERBOSE; protected @Level int mLogLevel; public Builder(SysuiLog sysuiLog) { mLog = sysuiLog; reset(); } /** * Reset this builder's parameters so it can be reused to build another RichEvent. */ public void reset() { mType = UNINITIALIZED; mReason = null; mLogLevel = VERBOSE; } /** * Get the log-specific builder. Loading @@ -75,9 +91,9 @@ public abstract class RichEvent extends Event { public abstract B getBuilder(); /** * Build the log-specific event. * Build the log-specific event given an event to populate. */ public abstract RichEvent build(); public abstract E build(E e); /** * Optional - set the log level. Defaults to DEBUG. Loading
packages/SystemUI/src/com/android/systemui/log/SysuiLog.java +24 −20 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.os.Build; import android.os.SystemProperties; import android.util.Log; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; import com.android.systemui.DumpController; import com.android.systemui.Dumpable; Loading @@ -39,22 +40,25 @@ import java.util.Locale; * To manually view the logs via adb: * adb shell dumpsys activity service com.android.systemui/.SystemUIService \ * dependency DumpController <SysuiLogId> * * Logs can be disabled by setting the following SystemProperty and then restarting the device: * adb shell setprop persist.sysui.log.enabled.<id> true/false && adb reboot * * @param <E> Type of event we'll be logging */ public class SysuiLog implements Dumpable { public class SysuiLog<E extends Event> implements Dumpable { public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("MM-dd HH:mm:ss", Locale.US); private final Object mDataLock = new Object(); protected final Object mDataLock = new Object(); private final String mId; private final int mMaxLogs; private boolean mEnabled; protected boolean mEnabled; @VisibleForTesting protected ArrayDeque<Event> mTimeline; @VisibleForTesting protected ArrayDeque<E> mTimeline; /** * Creates a SysuiLog * To enable or disable logs, set the system property and then restart the device: * adb shell setprop sysui.log.enabled.<id> true/false && adb reboot * @param dumpController where to register this logger's dumpsys * @param id user-readable tag for this logger * @param maxDebugLogs maximum number of logs to retain when {@link sDebuggable} is true Loading @@ -74,23 +78,20 @@ public class SysuiLog implements Dumpable { dumpController.registerDumpable(mId, this); } public SysuiLog(DumpController dumpController, String id) { this(dumpController, id, DEFAULT_MAX_DEBUG_LOGS, DEFAULT_MAX_LOGS); } /** * Logs an event to the timeline which can be printed by the dumpsys. * May also log to logcat if enabled. * @return true if event was logged, else false * @return the last event that was discarded from the Timeline (can be recycled) */ public boolean log(Event event) { public E log(E event) { if (!mEnabled) { return false; return null; } E recycledEvent = null; synchronized (mDataLock) { if (mTimeline.size() >= mMaxLogs) { mTimeline.removeFirst(); recycledEvent = mTimeline.removeFirst(); } mTimeline.add(event); Loading @@ -116,13 +117,18 @@ public class SysuiLog implements Dumpable { break; } } return true; if (recycledEvent != null) { recycledEvent.recycle(); } return recycledEvent; } /** * @return user-readable string of the given event with timestamp */ public String eventToTimestampedString(Event event) { private String eventToTimestampedString(Event event) { StringBuilder sb = new StringBuilder(); sb.append(SysuiLog.DATE_FORMAT.format(event.getTimestamp())); sb.append(" "); Loading @@ -137,9 +143,7 @@ public class SysuiLog implements Dumpable { return event.getMessage(); } /** * only call on this method if you have the mDataLock */ @GuardedBy("mDataLock") private void dumpTimelineLocked(PrintWriter pw) { pw.println("\tTimeline:"); Loading @@ -162,7 +166,7 @@ public class SysuiLog implements Dumpable { } private static boolean sDebuggable = Build.IS_DEBUGGABLE; private static final String SYSPROP_ENABLED_PREFIX = "sysui.log.enabled."; private static final String SYSPROP_ENABLED_PREFIX = "persist.sysui.log.enabled."; private static final boolean LOG_TO_LOGCAT_ENABLED = sDebuggable; private static final boolean DEFAULT_ENABLED = sDebuggable; private static final int DEFAULT_MAX_DEBUG_LOGS = 100; Loading