Loading packages/SystemUI/src/com/android/systemui/doze/DozeEvent.java +19 −7 Original line number Diff line number Diff line Loading @@ -28,12 +28,10 @@ import java.lang.annotation.RetentionPolicy; * and triaging purposes. */ public class DozeEvent extends RichEvent { /** * Initializes a doze event */ public DozeEvent init(@EventType int type, String reason) { super.init(DEBUG, type, reason); return this; public static final int TOTAL_EVENT_TYPES = 19; public DozeEvent(int logLevel, int type, String reason) { super(logLevel, type, reason); } /** Loading Loading @@ -91,6 +89,21 @@ 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 @@ -119,7 +132,6 @@ 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 +35 −31 Original line number Diff line number Diff line Loading @@ -35,11 +35,9 @@ import javax.inject.Singleton; * dependency DumpController DozeLog */ @Singleton public class DozeLog extends SysuiLog<DozeEvent> { public class DozeLog extends SysuiLog { private static final String TAG = "DozeLog"; private DozeEvent mRecycledEvent; private boolean mPulsing; private long mSince; private SummaryStats mPickupPulseNearVibrationStats; Loading Loading @@ -75,8 +73,8 @@ public class DozeLog extends SysuiLog<DozeEvent> { * Appends pickup wakeup event to the logs */ public void tracePickupWakeUp(boolean withinVibrationThreshold) { log(DozeEvent.PICKUP_WAKEUP, "withinVibrationThreshold=" + withinVibrationThreshold); if (mEnabled) { if (log(DozeEvent.PICKUP_WAKEUP, "withinVibrationThreshold=" + withinVibrationThreshold)) { (withinVibrationThreshold ? mPickupPulseNearVibrationStats : mPickupPulseNotNearVibrationStats).append(); } Loading @@ -87,24 +85,27 @@ public class DozeLog extends SysuiLog<DozeEvent> { * @param reason why the pulse started */ public void tracePulseStart(@DozeEvent.Reason int reason) { log(DozeEvent.PULSE_START, DozeEvent.reasonToString(reason)); if (mEnabled) mPulsing = true; if (log(DozeEvent.PULSE_START, DozeEvent.reasonToString(reason))) { mPulsing = true; } } /** * Appends pulse finished event to the logs */ public void tracePulseFinish() { log(DozeEvent.PULSE_FINISH); if (mEnabled) mPulsing = false; if (log(DozeEvent.PULSE_FINISH)) { mPulsing = false; } } /** * Appends pulse event to the logs */ public void traceNotificationPulse() { log(DozeEvent.NOTIFICATION_PULSE); if (mEnabled) mNotificationPulseStats.append(); if (log(DozeEvent.NOTIFICATION_PULSE)) { mNotificationPulseStats.append(); } } /** Loading @@ -112,8 +113,9 @@ public class DozeLog extends SysuiLog<DozeEvent> { * @param dozing true if dozing, else false */ public void traceDozing(boolean dozing) { log(DozeEvent.DOZING, "dozing=" + dozing); if (mEnabled) mPulsing = false; if (log(DozeEvent.DOZING, "dozing=" + dozing)) { mPulsing = false; } } /** Loading @@ -131,8 +133,9 @@ public class DozeLog extends SysuiLog<DozeEvent> { * Appends emergency call event to the logs */ public void traceEmergencyCall() { log(DozeEvent.EMERGENCY_CALL); if (mEnabled) mEmergencyCallStats.append(); if (log(DozeEvent.EMERGENCY_CALL)) { mEmergencyCallStats.append(); } } /** Loading @@ -147,8 +150,7 @@ public class DozeLog extends SysuiLog<DozeEvent> { * Appends screen-on event to the logs */ public void traceScreenOn() { log(DozeEvent.SCREEN_ON, "pulsing=" + mPulsing); if (mEnabled) { if (log(DozeEvent.SCREEN_ON, "pulsing=" + mPulsing)) { (mPulsing ? mScreenOnPulsingStats : mScreenOnNotPulsingStats).append(); mPulsing = false; } Loading Loading @@ -186,8 +188,10 @@ public class DozeLog extends SysuiLog<DozeEvent> { * @param showing whether the keyguard is now showing */ public void traceKeyguard(boolean showing) { log(DozeEvent.KEYGUARD_VISIBILITY_CHANGE, "showing=" + showing); if (mEnabled && !showing) mPulsing = false; if (log(DozeEvent.KEYGUARD_VISIBILITY_CHANGE, "showing=" + showing) && !showing) { mPulsing = false; } } /** Loading @@ -213,11 +217,12 @@ public class DozeLog extends SysuiLog<DozeEvent> { * @param reason why proximity result was triggered */ public void traceProximityResult(boolean near, long millis, @DozeEvent.Reason int reason) { log(DozeEvent.PROXIMITY_RESULT, if (log(DozeEvent.PROXIMITY_RESULT, " reason=" + DozeEvent.reasonToString(reason) + " near=" + near + " millis=" + millis); if (mEnabled) mProxStats[reason][near ? 0 : 1].append(); + " millis=" + millis)) { mProxStats[reason][near ? 0 : 1].append(); } } /** Loading Loading @@ -245,16 +250,15 @@ public class DozeLog extends SysuiLog<DozeEvent> { } } private void log(@DozeEvent.EventType int eventType) { log(eventType, ""); private boolean log(@DozeEvent.EventType int eventType) { return log(eventType, ""); } 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)); } private boolean log(@DozeEvent.EventType int eventType, String msg) { return super.log(new DozeEvent.DozeEventBuilder() .setType(eventType) .setReason(msg) .build()); } /** Loading packages/SystemUI/src/com/android/systemui/log/Event.java +6 −23 Original line number Diff line number Diff line Loading @@ -37,28 +37,20 @@ 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 = DEFAULT_LOG_LEVEL; private String mMessage = ""; private @Level int mLogLevel = DEBUG; protected String mMessage; /** * initialize an event with a message */ public Event init(String message) { init(DEFAULT_LOG_LEVEL, message); return this; public Event(String message) { mTimestamp = System.currentTimeMillis(); mMessage = message; } /** * initialize an event with a logLevel and message */ public Event init(@Level int logLevel, String message) { public Event(@Level int logLevel, String message) { mTimestamp = System.currentTimeMillis(); mLogLevel = logLevel; mMessage = message; return this; } public String getMessage() { Loading @@ -72,13 +64,4 @@ 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 +16 −32 Original line number Diff line number Diff line Loading @@ -23,21 +23,23 @@ 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 int mType; private final int mType; private final String mReason; /** * Initializes a rich event that includes an event type that matches with an index in the array * Create a rich event that includes an event type that matches with an index in the array * getEventLabels(). */ public RichEvent init(@Event.Level int logLevel, int type, String reason) { public RichEvent(@Event.Level int logLevel, int type, String reason) { super(logLevel, null); 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; super.init(logLevel, getEventLabels()[mType] + " " + reason); return this; mReason = reason; mMessage = getEventLabels()[mType] + " " + mReason; } /** Loading @@ -47,43 +49,25 @@ public abstract class RichEvent extends Event { */ public abstract String[] getEventLabels(); @Override public void recycle() { super.recycle(); mType = -1; } public int getType() { return mType; } public String getReason() { return mReason; } /** * 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, E>, E extends RichEvent> { public abstract static class Builder<B extends Builder<B>> { public static final int UNINITIALIZED = -1; public final SysuiLog mLog; private B mBuilder = getBuilder(); protected int mType; protected int mType = UNINITIALIZED; protected String mReason; 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; } protected @Level int mLogLevel = VERBOSE; /** * Get the log-specific builder. Loading @@ -91,9 +75,9 @@ public abstract class RichEvent extends Event { public abstract B getBuilder(); /** * Build the log-specific event given an event to populate. * Build the log-specific event. */ public abstract E build(E e); public abstract RichEvent build(); /** * Optional - set the log level. Defaults to DEBUG. Loading packages/SystemUI/src/com/android/systemui/log/SysuiLog.java +20 −24 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ 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 @@ -40,25 +39,22 @@ 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<E extends Event> implements Dumpable { public class SysuiLog implements Dumpable { public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("MM-dd HH:mm:ss", Locale.US); protected final Object mDataLock = new Object(); private final Object mDataLock = new Object(); private final String mId; private final int mMaxLogs; protected boolean mEnabled; private boolean mEnabled; @VisibleForTesting protected ArrayDeque<E> mTimeline; @VisibleForTesting protected ArrayDeque<Event> 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 @@ -78,20 +74,23 @@ public class SysuiLog<E extends Event> 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 the last event that was discarded from the Timeline (can be recycled) * @return true if event was logged, else false */ public E log(E event) { public boolean log(Event event) { if (!mEnabled) { return null; return false; } E recycledEvent = null; synchronized (mDataLock) { if (mTimeline.size() >= mMaxLogs) { recycledEvent = mTimeline.removeFirst(); mTimeline.removeFirst(); } mTimeline.add(event); Loading @@ -117,18 +116,13 @@ public class SysuiLog<E extends Event> implements Dumpable { break; } } if (recycledEvent != null) { recycledEvent.recycle(); } return recycledEvent; return true; } /** * @return user-readable string of the given event with timestamp */ private String eventToTimestampedString(Event event) { public String eventToTimestampedString(Event event) { StringBuilder sb = new StringBuilder(); sb.append(SysuiLog.DATE_FORMAT.format(event.getTimestamp())); sb.append(" "); Loading @@ -143,7 +137,9 @@ public class SysuiLog<E extends Event> implements Dumpable { return event.getMessage(); } @GuardedBy("mDataLock") /** * only call on this method if you have the mDataLock */ private void dumpTimelineLocked(PrintWriter pw) { pw.println("\tTimeline:"); Loading @@ -166,7 +162,7 @@ public class SysuiLog<E extends Event> implements Dumpable { } private static boolean sDebuggable = Build.IS_DEBUGGABLE; private static final String SYSPROP_ENABLED_PREFIX = "persist.sysui.log.enabled."; private static final String SYSPROP_ENABLED_PREFIX = "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 +19 −7 Original line number Diff line number Diff line Loading @@ -28,12 +28,10 @@ import java.lang.annotation.RetentionPolicy; * and triaging purposes. */ public class DozeEvent extends RichEvent { /** * Initializes a doze event */ public DozeEvent init(@EventType int type, String reason) { super.init(DEBUG, type, reason); return this; public static final int TOTAL_EVENT_TYPES = 19; public DozeEvent(int logLevel, int type, String reason) { super(logLevel, type, reason); } /** Loading Loading @@ -91,6 +89,21 @@ 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 @@ -119,7 +132,6 @@ 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 +35 −31 Original line number Diff line number Diff line Loading @@ -35,11 +35,9 @@ import javax.inject.Singleton; * dependency DumpController DozeLog */ @Singleton public class DozeLog extends SysuiLog<DozeEvent> { public class DozeLog extends SysuiLog { private static final String TAG = "DozeLog"; private DozeEvent mRecycledEvent; private boolean mPulsing; private long mSince; private SummaryStats mPickupPulseNearVibrationStats; Loading Loading @@ -75,8 +73,8 @@ public class DozeLog extends SysuiLog<DozeEvent> { * Appends pickup wakeup event to the logs */ public void tracePickupWakeUp(boolean withinVibrationThreshold) { log(DozeEvent.PICKUP_WAKEUP, "withinVibrationThreshold=" + withinVibrationThreshold); if (mEnabled) { if (log(DozeEvent.PICKUP_WAKEUP, "withinVibrationThreshold=" + withinVibrationThreshold)) { (withinVibrationThreshold ? mPickupPulseNearVibrationStats : mPickupPulseNotNearVibrationStats).append(); } Loading @@ -87,24 +85,27 @@ public class DozeLog extends SysuiLog<DozeEvent> { * @param reason why the pulse started */ public void tracePulseStart(@DozeEvent.Reason int reason) { log(DozeEvent.PULSE_START, DozeEvent.reasonToString(reason)); if (mEnabled) mPulsing = true; if (log(DozeEvent.PULSE_START, DozeEvent.reasonToString(reason))) { mPulsing = true; } } /** * Appends pulse finished event to the logs */ public void tracePulseFinish() { log(DozeEvent.PULSE_FINISH); if (mEnabled) mPulsing = false; if (log(DozeEvent.PULSE_FINISH)) { mPulsing = false; } } /** * Appends pulse event to the logs */ public void traceNotificationPulse() { log(DozeEvent.NOTIFICATION_PULSE); if (mEnabled) mNotificationPulseStats.append(); if (log(DozeEvent.NOTIFICATION_PULSE)) { mNotificationPulseStats.append(); } } /** Loading @@ -112,8 +113,9 @@ public class DozeLog extends SysuiLog<DozeEvent> { * @param dozing true if dozing, else false */ public void traceDozing(boolean dozing) { log(DozeEvent.DOZING, "dozing=" + dozing); if (mEnabled) mPulsing = false; if (log(DozeEvent.DOZING, "dozing=" + dozing)) { mPulsing = false; } } /** Loading @@ -131,8 +133,9 @@ public class DozeLog extends SysuiLog<DozeEvent> { * Appends emergency call event to the logs */ public void traceEmergencyCall() { log(DozeEvent.EMERGENCY_CALL); if (mEnabled) mEmergencyCallStats.append(); if (log(DozeEvent.EMERGENCY_CALL)) { mEmergencyCallStats.append(); } } /** Loading @@ -147,8 +150,7 @@ public class DozeLog extends SysuiLog<DozeEvent> { * Appends screen-on event to the logs */ public void traceScreenOn() { log(DozeEvent.SCREEN_ON, "pulsing=" + mPulsing); if (mEnabled) { if (log(DozeEvent.SCREEN_ON, "pulsing=" + mPulsing)) { (mPulsing ? mScreenOnPulsingStats : mScreenOnNotPulsingStats).append(); mPulsing = false; } Loading Loading @@ -186,8 +188,10 @@ public class DozeLog extends SysuiLog<DozeEvent> { * @param showing whether the keyguard is now showing */ public void traceKeyguard(boolean showing) { log(DozeEvent.KEYGUARD_VISIBILITY_CHANGE, "showing=" + showing); if (mEnabled && !showing) mPulsing = false; if (log(DozeEvent.KEYGUARD_VISIBILITY_CHANGE, "showing=" + showing) && !showing) { mPulsing = false; } } /** Loading @@ -213,11 +217,12 @@ public class DozeLog extends SysuiLog<DozeEvent> { * @param reason why proximity result was triggered */ public void traceProximityResult(boolean near, long millis, @DozeEvent.Reason int reason) { log(DozeEvent.PROXIMITY_RESULT, if (log(DozeEvent.PROXIMITY_RESULT, " reason=" + DozeEvent.reasonToString(reason) + " near=" + near + " millis=" + millis); if (mEnabled) mProxStats[reason][near ? 0 : 1].append(); + " millis=" + millis)) { mProxStats[reason][near ? 0 : 1].append(); } } /** Loading Loading @@ -245,16 +250,15 @@ public class DozeLog extends SysuiLog<DozeEvent> { } } private void log(@DozeEvent.EventType int eventType) { log(eventType, ""); private boolean log(@DozeEvent.EventType int eventType) { return log(eventType, ""); } 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)); } private boolean log(@DozeEvent.EventType int eventType, String msg) { return super.log(new DozeEvent.DozeEventBuilder() .setType(eventType) .setReason(msg) .build()); } /** Loading
packages/SystemUI/src/com/android/systemui/log/Event.java +6 −23 Original line number Diff line number Diff line Loading @@ -37,28 +37,20 @@ 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 = DEFAULT_LOG_LEVEL; private String mMessage = ""; private @Level int mLogLevel = DEBUG; protected String mMessage; /** * initialize an event with a message */ public Event init(String message) { init(DEFAULT_LOG_LEVEL, message); return this; public Event(String message) { mTimestamp = System.currentTimeMillis(); mMessage = message; } /** * initialize an event with a logLevel and message */ public Event init(@Level int logLevel, String message) { public Event(@Level int logLevel, String message) { mTimestamp = System.currentTimeMillis(); mLogLevel = logLevel; mMessage = message; return this; } public String getMessage() { Loading @@ -72,13 +64,4 @@ 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 +16 −32 Original line number Diff line number Diff line Loading @@ -23,21 +23,23 @@ 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 int mType; private final int mType; private final String mReason; /** * Initializes a rich event that includes an event type that matches with an index in the array * Create a rich event that includes an event type that matches with an index in the array * getEventLabels(). */ public RichEvent init(@Event.Level int logLevel, int type, String reason) { public RichEvent(@Event.Level int logLevel, int type, String reason) { super(logLevel, null); 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; super.init(logLevel, getEventLabels()[mType] + " " + reason); return this; mReason = reason; mMessage = getEventLabels()[mType] + " " + mReason; } /** Loading @@ -47,43 +49,25 @@ public abstract class RichEvent extends Event { */ public abstract String[] getEventLabels(); @Override public void recycle() { super.recycle(); mType = -1; } public int getType() { return mType; } public String getReason() { return mReason; } /** * 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, E>, E extends RichEvent> { public abstract static class Builder<B extends Builder<B>> { public static final int UNINITIALIZED = -1; public final SysuiLog mLog; private B mBuilder = getBuilder(); protected int mType; protected int mType = UNINITIALIZED; protected String mReason; 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; } protected @Level int mLogLevel = VERBOSE; /** * Get the log-specific builder. Loading @@ -91,9 +75,9 @@ public abstract class RichEvent extends Event { public abstract B getBuilder(); /** * Build the log-specific event given an event to populate. * Build the log-specific event. */ public abstract E build(E e); public abstract RichEvent build(); /** * Optional - set the log level. Defaults to DEBUG. Loading
packages/SystemUI/src/com/android/systemui/log/SysuiLog.java +20 −24 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ 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 @@ -40,25 +39,22 @@ 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<E extends Event> implements Dumpable { public class SysuiLog implements Dumpable { public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("MM-dd HH:mm:ss", Locale.US); protected final Object mDataLock = new Object(); private final Object mDataLock = new Object(); private final String mId; private final int mMaxLogs; protected boolean mEnabled; private boolean mEnabled; @VisibleForTesting protected ArrayDeque<E> mTimeline; @VisibleForTesting protected ArrayDeque<Event> 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 @@ -78,20 +74,23 @@ public class SysuiLog<E extends Event> 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 the last event that was discarded from the Timeline (can be recycled) * @return true if event was logged, else false */ public E log(E event) { public boolean log(Event event) { if (!mEnabled) { return null; return false; } E recycledEvent = null; synchronized (mDataLock) { if (mTimeline.size() >= mMaxLogs) { recycledEvent = mTimeline.removeFirst(); mTimeline.removeFirst(); } mTimeline.add(event); Loading @@ -117,18 +116,13 @@ public class SysuiLog<E extends Event> implements Dumpable { break; } } if (recycledEvent != null) { recycledEvent.recycle(); } return recycledEvent; return true; } /** * @return user-readable string of the given event with timestamp */ private String eventToTimestampedString(Event event) { public String eventToTimestampedString(Event event) { StringBuilder sb = new StringBuilder(); sb.append(SysuiLog.DATE_FORMAT.format(event.getTimestamp())); sb.append(" "); Loading @@ -143,7 +137,9 @@ public class SysuiLog<E extends Event> implements Dumpable { return event.getMessage(); } @GuardedBy("mDataLock") /** * only call on this method if you have the mDataLock */ private void dumpTimelineLocked(PrintWriter pw) { pw.println("\tTimeline:"); Loading @@ -166,7 +162,7 @@ public class SysuiLog<E extends Event> implements Dumpable { } private static boolean sDebuggable = Build.IS_DEBUGGABLE; private static final String SYSPROP_ENABLED_PREFIX = "persist.sysui.log.enabled."; private static final String SYSPROP_ENABLED_PREFIX = "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