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

Commit 30d67702 authored by Ned Burns's avatar Ned Burns
Browse files

Switch DozeLog over to new buffer

DozeLog should really be renamed DozeTracer or similar (to avoid clashes
with the new DozeLogger) but I didn't want to nuke the change history.

Test: atest
Change-Id: Id74d04f3b073b0680b3b39707d2fa38a1706e418
parent bbc9afbc
Loading
Loading
Loading
Loading
+0 −142
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.doze;

import android.annotation.IntDef;

import com.android.systemui.log.RichEvent;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * An event related to dozing. {@link DozeLog} stores and prints these events for debugging
 * 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;
    }

    /**
     * Event labels for each doze event
     * Index corresponds to the integer associated with each {@link EventType}
     */
    @Override
    public String[] getEventLabels() {
        final String[] events = new String[]{
                "PickupWakeup",
                "PulseStart",
                "PulseFinish",
                "NotificationPulse",
                "Dozing",
                "Fling",
                "EmergencyCall",
                "KeyguardBouncerChanged",
                "ScreenOn",
                "ScreenOff",
                "MissedTick",
                "TimeTickScheduled",
                "KeyguardVisibilityChanged",
                "DozeStateChanged",
                "WakeDisplay",
                "ProximityResult",
                "PulseDropped",
                "PulseDisabledByProx",
                "SensorTriggered"
        };

        if (events.length != TOTAL_EVENT_TYPES) {
            throw new IllegalStateException("DozeEvent events.length should match TOTAL_EVENT_TYPES"
                    + " events.length=" + events.length
                    + " TOTAL_EVENT_LENGTH=" + TOTAL_EVENT_TYPES);
        }
        return events;
    }

    /**
     * Converts the reason (integer) to a user-readable string
     */
    public static String reasonToString(@Reason int pulseReason) {
        switch (pulseReason) {
            case PULSE_REASON_INTENT: return "intent";
            case PULSE_REASON_NOTIFICATION: return "notification";
            case PULSE_REASON_SENSOR_SIGMOTION: return "sigmotion";
            case REASON_SENSOR_PICKUP: return "pickup";
            case REASON_SENSOR_DOUBLE_TAP: return "doubletap";
            case PULSE_REASON_SENSOR_LONG_PRESS: return "longpress";
            case PULSE_REASON_DOCKING: return "docking";
            case PULSE_REASON_SENSOR_WAKE_LOCK_SCREEN: return "wakelockscreen";
            case REASON_SENSOR_WAKE_UP: return "wakeup";
            case REASON_SENSOR_TAP: return "tap";
            default: throw new IllegalArgumentException("invalid reason: " + pulseReason);
        }
    }

    @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,
            PROXIMITY_RESULT, PULSE_DROPPED, PULSE_DISABLED_BY_PROX, SENSOR_TRIGGERED})
    /**
     * Types of DozeEvents
     */
    @Retention(RetentionPolicy.SOURCE)
    public @interface EventType {}
    public static final int PICKUP_WAKEUP = 0;
    public static final int PULSE_START = 1;
    public static final int PULSE_FINISH = 2;
    public static final int NOTIFICATION_PULSE = 3;
    public static final int DOZING = 4;
    public static final int FLING = 5;
    public static final int EMERGENCY_CALL = 6;
    public static final int KEYGUARD_BOUNCER_CHANGED = 7;
    public static final int SCREEN_ON = 8;
    public static final int SCREEN_OFF = 9;
    public static final int MISSED_TICK = 10;
    public static final int TIME_TICK_SCHEDULED = 11;
    public static final int KEYGUARD_VISIBILITY_CHANGE = 12;
    public static final int DOZE_STATE_CHANGED = 13;
    public static final int WAKE_DISPLAY = 14;
    public static final int PROXIMITY_RESULT = 15;
    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,
            PULSE_REASON_SENSOR_SIGMOTION, REASON_SENSOR_PICKUP, REASON_SENSOR_DOUBLE_TAP,
            PULSE_REASON_SENSOR_LONG_PRESS, PULSE_REASON_DOCKING, REASON_SENSOR_WAKE_UP,
            PULSE_REASON_SENSOR_WAKE_LOCK_SCREEN, REASON_SENSOR_TAP})
    @Retention(RetentionPolicy.SOURCE)
    public @interface Reason {}
    public static final int PULSE_REASON_NONE = -1;
    public static final int PULSE_REASON_INTENT = 0;
    public static final int PULSE_REASON_NOTIFICATION = 1;
    public static final int PULSE_REASON_SENSOR_SIGMOTION = 2;
    public static final int REASON_SENSOR_PICKUP = 3;
    public static final int REASON_SENSOR_DOUBLE_TAP = 4;
    public static final int PULSE_REASON_SENSOR_LONG_PRESS = 5;
    public static final int PULSE_REASON_DOCKING = 6;
    public static final int REASON_SENSOR_WAKE_UP = 7;
    public static final int PULSE_REASON_SENSOR_WAKE_LOCK_SCREEN = 8;
    public static final int REASON_SENSOR_TAP = 9;
}
+95 −82
Original line number Diff line number Diff line
@@ -16,15 +16,20 @@

package com.android.systemui.doze;

import android.annotation.IntDef;
import android.util.TimeUtils;

import androidx.annotation.NonNull;

import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardUpdateMonitorCallback;
import com.android.systemui.DumpController;
import com.android.systemui.log.SysuiLog;
import com.android.systemui.Dumpable;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.Date;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

import javax.inject.Inject;
import javax.inject.Singleton;
@@ -32,13 +37,11 @@ import javax.inject.Singleton;
/**
 * Logs doze events for debugging and triaging purposes. Logs are dumped in bugreports or on demand:
 *      adb shell dumpsys activity service com.android.systemui/.SystemUIService \
 *      dependency DumpController DozeLog
 *      dependency DumpController DozeLog,DozeStats
 */
@Singleton
public class DozeLog extends SysuiLog<DozeEvent> {
    private static final String TAG = "DozeLog";

    private DozeEvent mRecycledEvent;
public class DozeLog implements Dumpable {
    private final DozeLogger mLogger;

    private boolean mPulsing;
    private long mSince;
@@ -51,8 +54,11 @@ public class DozeLog extends SysuiLog<DozeEvent> {
    private SummaryStats[][] mProxStats; // [reason][near/far]

    @Inject
    public DozeLog(KeyguardUpdateMonitor keyguardUpdateMonitor, DumpController dumpController) {
        super(dumpController, TAG, MAX_DOZE_DEBUG_LOGS, MAX_DOZE_LOGS);
    public DozeLog(
            KeyguardUpdateMonitor keyguardUpdateMonitor,
            DumpController dumpController,
            DozeLogger logger) {
        mLogger = logger;
        mSince = System.currentTimeMillis();
        mPickupPulseNearVibrationStats = new SummaryStats();
        mPickupPulseNotNearVibrationStats = new SummaryStats();
@@ -60,8 +66,8 @@ public class DozeLog extends SysuiLog<DozeEvent> {
        mScreenOnPulsingStats = new SummaryStats();
        mScreenOnNotPulsingStats = new SummaryStats();
        mEmergencyCallStats = new SummaryStats();
        mProxStats = new SummaryStats[DozeEvent.TOTAL_REASONS][2];
        for (int i = 0; i < DozeEvent.TOTAL_REASONS; i++) {
        mProxStats = new SummaryStats[TOTAL_REASONS][2];
        for (int i = 0; i < TOTAL_REASONS; i++) {
            mProxStats[i][0] = new SummaryStats();
            mProxStats[i][1] = new SummaryStats();
        }
@@ -69,42 +75,42 @@ public class DozeLog extends SysuiLog<DozeEvent> {
        if (keyguardUpdateMonitor != null) {
            keyguardUpdateMonitor.registerCallback(mKeyguardCallback);
        }

        dumpController.registerDumpable("DumpStats", this);
    }

    /**
     * Appends pickup wakeup event to the logs
     */
    public void tracePickupWakeUp(boolean withinVibrationThreshold) {
        log(DozeEvent.PICKUP_WAKEUP, "withinVibrationThreshold=" + withinVibrationThreshold);
        if (mEnabled) {
        mLogger.logPickupWakeup(withinVibrationThreshold);
        (withinVibrationThreshold ? mPickupPulseNearVibrationStats
                : mPickupPulseNotNearVibrationStats).append();
    }
    }

    /**
     * Appends pulse started event to the logs.
     * @param reason why the pulse started
     */
    public void tracePulseStart(@DozeEvent.Reason int reason) {
        log(DozeEvent.PULSE_START, DozeEvent.reasonToString(reason));
        if (mEnabled) mPulsing = true;
    public void tracePulseStart(@Reason int reason) {
        mLogger.logPulseStart(reason);
        mPulsing = true;
    }

    /**
     * Appends pulse finished event to the logs
     */
    public void tracePulseFinish() {
        log(DozeEvent.PULSE_FINISH);
        if (mEnabled) mPulsing = false;
        mLogger.logPulseFinish();
        mPulsing = false;
    }

    /**
     * Appends pulse event to the logs
     */
    public void traceNotificationPulse() {
        log(DozeEvent.NOTIFICATION_PULSE);
        if (mEnabled) mNotificationPulseStats.append();
        mLogger.logNotificationPulse();
        mNotificationPulseStats.append();
    }

    /**
@@ -112,8 +118,8 @@ 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;
        mLogger.logDozing(dozing);
        mPulsing = false;
    }

    /**
@@ -121,18 +127,15 @@ public class DozeLog extends SysuiLog<DozeEvent> {
     */
    public void traceFling(boolean expand, boolean aboveThreshold, boolean thresholdNeeded,
            boolean screenOnFromTouch) {
        log(DozeEvent.FLING, "expand=" + expand
                + " aboveThreshold=" + aboveThreshold
                + " thresholdNeeded=" + thresholdNeeded
                + " screenOnFromTouch=" + screenOnFromTouch);
        mLogger.logFling(expand, aboveThreshold, thresholdNeeded, screenOnFromTouch);
    }

    /**
     * Appends emergency call event to the logs
     */
    public void traceEmergencyCall() {
        log(DozeEvent.EMERGENCY_CALL);
        if (mEnabled) mEmergencyCallStats.append();
        mLogger.logEmergencyCall();
        mEmergencyCallStats.append();
    }

    /**
@@ -140,26 +143,24 @@ public class DozeLog extends SysuiLog<DozeEvent> {
     * @param showing true if the keyguard bouncer is showing, else false
     */
    public void traceKeyguardBouncerChanged(boolean showing) {
        log(DozeEvent.KEYGUARD_BOUNCER_CHANGED, "showing=" + showing);
        mLogger.logKeyguardBouncerChanged(showing);
    }

    /**
     * Appends screen-on event to the logs
     */
    public void traceScreenOn() {
        log(DozeEvent.SCREEN_ON, "pulsing=" + mPulsing);
        if (mEnabled) {
        mLogger.logScreenOn(mPulsing);
        (mPulsing ? mScreenOnPulsingStats : mScreenOnNotPulsingStats).append();
        mPulsing = false;
    }
    }

    /**
     * Appends screen-off event to the logs
     * @param why reason the screen is off
     */
    public void traceScreenOff(int why) {
        log(DozeEvent.SCREEN_OFF, "why=" + why);
        mLogger.logScreenOff(why);
    }

    /**
@@ -167,7 +168,7 @@ public class DozeLog extends SysuiLog<DozeEvent> {
     * @param delay of the missed tick
     */
    public void traceMissedTick(String delay) {
        log(DozeEvent.MISSED_TICK, "delay=" + delay);
        mLogger.logMissedTick(delay);
    }

    /**
@@ -176,9 +177,7 @@ public class DozeLog extends SysuiLog<DozeEvent> {
     * @param triggerAt time tick trigger at
     */
    public void traceTimeTickScheduled(long when, long triggerAt) {
        log(DozeEvent.TIME_TICK_SCHEDULED,
                "scheduledAt=" + DATE_FORMAT.format(new Date(when))
                + " triggerAt=" + DATE_FORMAT.format(new Date(triggerAt)));
        mLogger.logTimeTickScheduled(when, triggerAt);
    }

    /**
@@ -186,8 +185,8 @@ 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;
        mLogger.logKeyguardVisibilityChange(showing);
        if (!showing) mPulsing = false;
    }

    /**
@@ -195,7 +194,7 @@ public class DozeLog extends SysuiLog<DozeEvent> {
     * @param state new DozeMachine state
     */
    public void traceState(DozeMachine.State state) {
        log(DozeEvent.DOZE_STATE_CHANGED, state.name());
        mLogger.logDozeStateChanged(state);
    }

    /**
@@ -203,31 +202,22 @@ public class DozeLog extends SysuiLog<DozeEvent> {
     * @param wake if we're waking up or sleeping.
     */
    public void traceWakeDisplay(boolean wake) {
        log(DozeEvent.WAKE_DISPLAY, "wake=" + wake);
        mLogger.logWakeDisplay(wake);
    }

    /**
     * Appends proximity result event to the logs
     * @param near true if near, else false
     * @param millis
     * @param reason why proximity result was triggered
     */
    public void traceProximityResult(boolean near, long millis, @DozeEvent.Reason int reason) {
        log(DozeEvent.PROXIMITY_RESULT,
                " reason=" + DozeEvent.reasonToString(reason)
                        + " near=" + near
                        + " millis=" + millis);
        if (mEnabled) mProxStats[reason][near ? 0 : 1].append();
    public void traceProximityResult(boolean near, long millis, @Reason int reason) {
        mLogger.logProximityResult(near, millis, reason);
        mProxStats[reason][near ? 0 : 1].append();
    }

    /**
     * Prints doze log timeline and consolidated stats
     * @param pw
     */
    public void dump(PrintWriter pw) {
    @Override
    public void dump(@NonNull FileDescriptor fd, @NonNull PrintWriter pw, @NonNull String[] args) {
        synchronized (DozeLog.class) {
            super.dump(null, pw, null); // prints timeline

            pw.print("  Doze summary stats (for ");
            TimeUtils.formatDuration(System.currentTimeMillis() - mSince, pw);
            pw.println("):");
@@ -237,32 +227,19 @@ public class DozeLog extends SysuiLog<DozeEvent> {
            mScreenOnPulsingStats.dump(pw, "Screen on (pulsing)");
            mScreenOnNotPulsingStats.dump(pw, "Screen on (not pulsing)");
            mEmergencyCallStats.dump(pw, "Emergency call");
            for (int i = 0; i < DozeEvent.TOTAL_REASONS; i++) {
                final String reason = DozeEvent.reasonToString(i);
            for (int i = 0; i < TOTAL_REASONS; i++) {
                final String reason = reasonToString(i);
                mProxStats[i][0].dump(pw, "Proximity near (" + reason + ")");
                mProxStats[i][1].dump(pw, "Proximity far (" + reason + ")");
            }
        }
    }

    private void log(@DozeEvent.EventType int eventType) {
        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));
        }
    }

    /**
     * Appends pulse dropped event to logs
     */
    public void tracePulseDropped(boolean pulsePending, DozeMachine.State state, boolean blocked) {
        log(DozeEvent.PULSE_DROPPED, "pulsePending=" + pulsePending + " state="
                + state.name() + " blocked=" + blocked);
        mLogger.logPulseDropped(pulsePending, state, blocked);
    }

    /**
@@ -270,7 +247,7 @@ public class DozeLog extends SysuiLog<DozeEvent> {
     * @param reason why the pulse was dropped
     */
    public void tracePulseDropped(String reason) {
        log(DozeEvent.PULSE_DROPPED, "why=" + reason);
        mLogger.logPulseDropped(reason);
    }

    /**
@@ -278,15 +255,15 @@ public class DozeLog extends SysuiLog<DozeEvent> {
     * @param disabled
     */
    public void tracePulseTouchDisabledByProx(boolean disabled) {
        log(DozeEvent.PULSE_DISABLED_BY_PROX, "disabled=" + disabled);
        mLogger.logPulseTouchDisabledByProx(disabled);
    }

    /**
     * Appends sensor triggered event to logs
     * @param reason why the sensor was triggered
     */
    public void traceSensor(@DozeEvent.Reason int reason) {
        log(DozeEvent.SENSOR_TRIGGERED, "type=" + DozeEvent.reasonToString(reason));
    public void traceSensor(@Reason int reason) {
        mLogger.logSensorTriggered(reason);
    }

    private class SummaryStats {
@@ -339,6 +316,42 @@ public class DozeLog extends SysuiLog<DozeEvent> {
        }
    };

    private static final int MAX_DOZE_DEBUG_LOGS = 400;
    private static final int MAX_DOZE_LOGS = 50;
    /**
     * Converts the reason (integer) to a user-readable string
     */
    public static String reasonToString(@Reason int pulseReason) {
        switch (pulseReason) {
            case PULSE_REASON_INTENT: return "intent";
            case PULSE_REASON_NOTIFICATION: return "notification";
            case PULSE_REASON_SENSOR_SIGMOTION: return "sigmotion";
            case REASON_SENSOR_PICKUP: return "pickup";
            case REASON_SENSOR_DOUBLE_TAP: return "doubletap";
            case PULSE_REASON_SENSOR_LONG_PRESS: return "longpress";
            case PULSE_REASON_DOCKING: return "docking";
            case PULSE_REASON_SENSOR_WAKE_LOCK_SCREEN: return "wakelockscreen";
            case REASON_SENSOR_WAKE_UP: return "wakeup";
            case REASON_SENSOR_TAP: return "tap";
            default: throw new IllegalArgumentException("invalid reason: " + pulseReason);
        }
    }

    @Retention(RetentionPolicy.SOURCE)
    @IntDef({PULSE_REASON_NONE, PULSE_REASON_INTENT, PULSE_REASON_NOTIFICATION,
            PULSE_REASON_SENSOR_SIGMOTION, REASON_SENSOR_PICKUP, REASON_SENSOR_DOUBLE_TAP,
            PULSE_REASON_SENSOR_LONG_PRESS, PULSE_REASON_DOCKING, REASON_SENSOR_WAKE_UP,
            PULSE_REASON_SENSOR_WAKE_LOCK_SCREEN, REASON_SENSOR_TAP})
    public @interface Reason {}
    public static final int PULSE_REASON_NONE = -1;
    public static final int PULSE_REASON_INTENT = 0;
    public static final int PULSE_REASON_NOTIFICATION = 1;
    public static final int PULSE_REASON_SENSOR_SIGMOTION = 2;
    public static final int REASON_SENSOR_PICKUP = 3;
    public static final int REASON_SENSOR_DOUBLE_TAP = 4;
    public static final int PULSE_REASON_SENSOR_LONG_PRESS = 5;
    public static final int PULSE_REASON_DOCKING = 6;
    public static final int REASON_SENSOR_WAKE_UP = 7;
    public static final int PULSE_REASON_SENSOR_WAKE_LOCK_SCREEN = 8;
    public static final int REASON_SENSOR_TAP = 9;

    public static final int TOTAL_REASONS = 10;
}
+201 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.doze

import com.android.systemui.doze.DozeLog.Reason
import com.android.systemui.doze.DozeLog.reasonToString
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LogLevel.DEBUG
import com.android.systemui.log.LogLevel.ERROR
import com.android.systemui.log.LogLevel.INFO
import com.android.systemui.log.dagger.DozeLog
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
import javax.inject.Inject

/** Interface for logging messages to the [DozeLog]. */
class DozeLogger @Inject constructor(
    @DozeLog private val buffer: LogBuffer
) {
    fun logPickupWakeup(isWithinVibrationThreshold: Boolean) {
        buffer.log(TAG, DEBUG, {
            bool1 = isWithinVibrationThreshold
        }, {
            "PickupWakeup withinVibrationThreshold=$bool1"
        })
    }

    fun logPulseStart(@Reason reason: Int) {
        buffer.log(TAG, INFO, {
            int1 = reason
        }, {
            "Pulse start, reason=${reasonToString(int1)}"
        })
    }

    fun logPulseFinish() {
        buffer.log(TAG, INFO, {}, { "Pulse finish" })
    }

    fun logNotificationPulse() {
        buffer.log(TAG, INFO, {}, { "Notification pulse" })
    }

    fun logDozing(isDozing: Boolean) {
        buffer.log(TAG, INFO, {
            bool1 = isDozing
        }, {
            "Dozing=$bool1"
        })
    }

    fun logFling(
        expand: Boolean,
        aboveThreshold: Boolean,
        thresholdNeeded: Boolean,
        screenOnFromTouch: Boolean
    ) {
        buffer.log(TAG, DEBUG, {
            bool1 = expand
            bool2 = aboveThreshold
            bool3 = thresholdNeeded
            bool4 = screenOnFromTouch
        }, {
            "Fling expand=$bool1 aboveThreshold=$bool2 thresholdNeeded=$bool3 " +
                    "screenOnFromTouch=$bool4"
        })
    }

    fun logEmergencyCall() {
        buffer.log(TAG, INFO, {}, { "Emergency call" })
    }

    fun logKeyguardBouncerChanged(isShowing: Boolean) {
        buffer.log(TAG, INFO, {
            bool1 = isShowing
        }, {
            "Keyguard bouncer changed, showing=$bool1"
        })
    }

    fun logScreenOn(isPulsing: Boolean) {
        buffer.log(TAG, INFO, {
            bool1 = isPulsing
        }, {
            "Screen on, pulsing=$bool1"
        })
    }

    fun logScreenOff(why: Int) {
        buffer.log(TAG, INFO, {
            int1 = why
        }, {
            "Screen off, why=$int1"
        })
    }

    fun logMissedTick(delay: String) {
        buffer.log(TAG, ERROR, {
            str1 = delay
        }, {
            "Missed AOD time tick by $str1"
        })
    }

    fun logTimeTickScheduled(whenAt: Long, triggerAt: Long) {
        buffer.log(TAG, DEBUG, {
            long1 = whenAt
            long2 = triggerAt
        }, {
            "Time tick scheduledAt=${DATE_FORMAT.format(Date(long1))} " +
                    "triggerAt=${DATE_FORMAT.format(Date(long2))}"
        })
    }

    fun logKeyguardVisibilityChange(isShowing: Boolean) {
        buffer.log(TAG, INFO, {
            bool1 = isShowing
        }, {
            "Keyguard visibility change, isShowing=$bool1"
        })
    }

    fun logDozeStateChanged(state: DozeMachine.State) {
        buffer.log(TAG, INFO, {
            str1 = state.name
        }, {
            "Doze state changed to $str1"
        })
    }

    fun logWakeDisplay(isAwake: Boolean) {
        buffer.log(TAG, DEBUG, {
            bool1 = isAwake
        }, {
            "Display wakefulness changed, isAwake=$bool1"
        })
    }

    fun logProximityResult(isNear: Boolean, millis: Long, @Reason reason: Int) {
        buffer.log(TAG, DEBUG, {
            bool1 = isNear
            long1 = millis
            int1 = reason
        }, {
            "Proximity result reason=${reasonToString(int1)} near=$bool1 millis=$long1"
        })
    }

    fun logPulseDropped(pulsePending: Boolean, state: DozeMachine.State, blocked: Boolean) {
        buffer.log(TAG, INFO, {
            bool1 = pulsePending
            str1 = state.name
            bool2 = blocked
        }, {
            "Pulse dropped, pulsePending=$bool1 state=$str1 blocked=$bool2"
        })
    }

    fun logPulseDropped(reason: String) {
        buffer.log(TAG, INFO, {
            str1 = reason
        }, {
            "Pulse dropped, why=$str1"
        })
    }

    fun logPulseTouchDisabledByProx(disabled: Boolean) {
        buffer.log(TAG, DEBUG, {
            bool1 = disabled
        }, {
            "Pulse touch modified by prox, disabled=$bool1"
        })
    }

    fun logSensorTriggered(@Reason reason: Int) {
        buffer.log(TAG, DEBUG, {
            int1 = reason
        }, {
            "Sensor triggered, type=${reasonToString(int1)}"
        })
    }
}

private const val TAG = "DozeLog"

val DATE_FORMAT = SimpleDateFormat("MM-dd HH:mm:ss.S", Locale.US)
+3 −3
Original line number Diff line number Diff line
@@ -169,7 +169,7 @@ public class DozeMachine {
    @MainThread
    public void requestState(State requestedState) {
        Preconditions.checkArgument(requestedState != State.DOZE_REQUEST_PULSE);
        requestState(requestedState, DozeEvent.PULSE_REASON_NONE);
        requestState(requestedState, DozeLog.PULSE_REASON_NONE);
    }

    @MainThread
@@ -271,7 +271,7 @@ public class DozeMachine {
        if (newState == State.DOZE_REQUEST_PULSE) {
            mPulseReason = pulseReason;
        } else if (oldState == State.DOZE_PULSE_DONE) {
            mPulseReason = DozeEvent.PULSE_REASON_NONE;
            mPulseReason = DozeLog.PULSE_REASON_NONE;
        }
    }

@@ -368,7 +368,7 @@ public class DozeMachine {
                    nextState = State.DOZE;
                }

                transitionTo(nextState, DozeEvent.PULSE_REASON_NONE);
                transitionTo(nextState, DozeLog.PULSE_REASON_NONE);
                break;
            default:
                break;
+8 −8

File changed.

Preview size limit exceeded, changes collapsed.

Loading