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

Commit 6a87e8e6 authored by Beverly Tai's avatar Beverly Tai Committed by Android (Google) Code Review
Browse files

Merge changes I0377cce2,I423f22c2 into main

* changes:
  Synchronize calls to updateDoze
  Update DozeScreenState and DozeBrightnessChange logs
parents 922a6fdb a7b30e3c
Loading
Loading
Loading
Loading
+30 −18
Original line number Diff line number Diff line
@@ -267,10 +267,10 @@ public class DreamService extends Service implements Window.Callback {
    private boolean mDozing;
    private boolean mWindowless;
    private boolean mPreviewMode;
    private volatile int mDozeScreenState = Display.STATE_UNKNOWN;
    private volatile @Display.StateReason int mDozeScreenStateReason = Display.STATE_REASON_UNKNOWN;
    private volatile int mDozeScreenBrightness = PowerManager.BRIGHTNESS_DEFAULT;
    private volatile float mDozeScreenBrightnessFloat = PowerManager.BRIGHTNESS_INVALID_FLOAT;
    private int mDozeScreenState = Display.STATE_UNKNOWN;
    private @Display.StateReason int mDozeScreenStateReason = Display.STATE_REASON_UNKNOWN;
    private int mDozeScreenBrightness = PowerManager.BRIGHTNESS_DEFAULT;
    private float mDozeScreenBrightnessFloat = PowerManager.BRIGHTNESS_INVALID_FLOAT;

    private boolean mDebug = false;

@@ -913,13 +913,15 @@ public class DreamService extends Service implements Window.Callback {
     */
    @UnsupportedAppUsage
    public void startDozing() {
        synchronized (this) {
            if (mCanDoze && !mDozing) {
                mDozing = true;
                updateDoze();
            }
        }
    }

    private void updateDoze() {
    private synchronized void updateDoze() {
        if (mDreamToken == null) {
            Slog.w(mTag, "Updating doze without a dream token.");
            return;
@@ -927,6 +929,9 @@ public class DreamService extends Service implements Window.Callback {

        if (mDozing) {
            try {
                Slog.v(mTag, "UpdateDoze mDozeScreenState=" + mDozeScreenState
                        + " mDozeScreenBrightness=" + mDozeScreenBrightness
                        + " mDozeScreenBrightnessFloat=" + mDozeScreenBrightnessFloat);
                if (startAndStopDozingInBackground()) {
                    mDreamManager.startDozingOneway(
                            mDreamToken, mDozeScreenState, mDozeScreenStateReason,
@@ -1048,12 +1053,14 @@ public class DreamService extends Service implements Window.Callback {
     */
    @UnsupportedAppUsage
    public void setDozeScreenState(int state, @Display.StateReason int reason) {
        synchronized (this) {
            if (mDozeScreenState != state) {
                mDozeScreenState = state;
                mDozeScreenStateReason = reason;
                updateDoze();
            }
        }
    }

    /**
     * Gets the screen brightness to use while dozing.
@@ -1103,11 +1110,13 @@ public class DreamService extends Service implements Window.Callback {
        if (brightness != PowerManager.BRIGHTNESS_DEFAULT) {
            brightness = clampAbsoluteBrightness(brightness);
        }
        synchronized (this) {
            if (mDozeScreenBrightness != brightness) {
                mDozeScreenBrightness = brightness;
                updateDoze();
            }
        }
    }

    /**
     * Sets the screen brightness to use while dozing.
@@ -1141,11 +1150,14 @@ public class DreamService extends Service implements Window.Callback {
        if (!Float.isNaN(brightness)) {
            brightness = clampAbsoluteBrightnessFloat(brightness);
        }

        synchronized (this) {
            if (!BrightnessSynchronizer.floatEquals(mDozeScreenBrightnessFloat, brightness)) {
                mDozeScreenBrightnessFloat = brightness;
                updateDoze();
            }
        }
    }

    /**
     * Called when this Dream is constructed.
+2 −5
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package com.android.systemui.doze;

import java.util.concurrent.Executor;

/**
 * Forwards the currently used brightness to {@link DozeHost}.
 */
@@ -25,9 +23,8 @@ public class DozeBrightnessHostForwarder extends DozeMachine.Service.Delegate {

    private final DozeHost mHost;

    public DozeBrightnessHostForwarder(DozeMachine.Service wrappedService, DozeHost host,
            Executor bgExecutor) {
        super(wrappedService, bgExecutor);
    public DozeBrightnessHostForwarder(DozeMachine.Service wrappedService, DozeHost host) {
        super(wrappedService);
        mHost = host;
    }

+12 −6
Original line number Diff line number Diff line
@@ -253,9 +253,11 @@ public class DozeLog implements Dumpable {
    /**
     * Appends display state changed event to the logs
     * @param displayState new DozeMachine state
     * @param afterRequest whether the request has successfully been sent else false for it's
     *                        about to be requested
     */
    public void traceDisplayState(int displayState) {
        mLogger.logDisplayStateChanged(displayState);
    public void traceDisplayState(int displayState, boolean afterRequest) {
        mLogger.logDisplayStateChanged(displayState, afterRequest);
    }

    /**
@@ -402,18 +404,22 @@ public class DozeLog implements Dumpable {
    /**
     * Appends new AOD screen brightness to logs
     * @param brightness display brightness setting between 1 and 255
     * @param afterRequest whether the request has successfully been sent else false for it's
     *                        about to be requested
     */
    public void traceDozeScreenBrightness(int brightness) {
        mLogger.logDozeScreenBrightness(brightness);
    public void traceDozeScreenBrightness(int brightness, boolean afterRequest) {
        mLogger.logDozeScreenBrightness(brightness, afterRequest);
    }

    /**
     * Appends new AOD screen brightness to logs
     * @param brightness display brightness setting between {@link PowerManager#BRIGHTNESS_MIN} and
     *                   {@link PowerManager#BRIGHTNESS_MAX}
     * @param afterRequest whether the request has successfully been sent else false for it's
     *                        about to be requested
     */
    public void traceDozeScreenBrightnessFloat(float brightness) {
        mLogger.logDozeScreenBrightnessFloat(brightness);
    public void traceDozeScreenBrightnessFloat(float brightness, boolean afterRequest) {
        mLogger.logDozeScreenBrightnessFloat(brightness, afterRequest);
    }

    /**
+265 −237
Original line number Diff line number Diff line
@@ -32,23 +32,18 @@ import java.util.Locale
import javax.inject.Inject

/** Interface for logging messages to the [DozeLog]. */
class DozeLogger @Inject constructor(
    @DozeLog private val buffer: LogBuffer
) {
class DozeLogger @Inject constructor(@DozeLog private val buffer: LogBuffer) {
    fun logPickupWakeup(isWithinVibrationThreshold: Boolean) {
        buffer.log(TAG, DEBUG, {
            bool1 = isWithinVibrationThreshold
        }, {
            "PickupWakeup withinVibrationThreshold=$bool1"
        })
        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)}"
        })
        buffer.log(TAG, INFO, { int1 = reason }, { "Pulse start, reason=${reasonToString(int1)}" })
    }

    fun logPulseFinish() {
@@ -60,52 +55,51 @@ class DozeLogger @Inject constructor(
    }

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

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

    fun logPowerSaveChanged(powerSaveActive: Boolean, nextState: DozeMachine.State) {
        buffer.log(TAG, INFO, {
        buffer.log(
            TAG,
            INFO,
            {
                bool1 = powerSaveActive
                str1 = nextState.name
        }, {
            "Power save active=$bool1 nextState=$str1"
        })
            },
            { "Power save active=$bool1 nextState=$str1" }
        )
    }

    fun logAlwaysOnSuppressedChange(isAodSuppressed: Boolean, nextState: DozeMachine.State) {
        buffer.log(TAG, INFO, {
        buffer.log(
            TAG,
            INFO,
            {
                bool1 = isAodSuppressed
                str1 = nextState.name
        }, {
            "Always on (AOD) suppressed changed, suppressed=$bool1 nextState=$str1"
        })
            },
            { "Always on (AOD) suppressed changed, suppressed=$bool1 nextState=$str1" }
        )
    }

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

    fun logEmergencyCall() {
@@ -113,250 +107,279 @@ class DozeLogger @Inject constructor(
    }

    fun logKeyguardBouncerChanged(isShowing: Boolean) {
        buffer.log(TAG, INFO, {
            bool1 = isShowing
        }, {
            "Keyguard bouncer changed, showing=$bool1"
        })
        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"
        })
        buffer.log(TAG, INFO, { bool1 = isPulsing }, { "Screen on, pulsing=$bool1" })
    }

    fun logScreenOff(why: Int) {
        buffer.log(TAG, INFO, {
            int1 = why
        }, {
            "Screen off, why=$int1"
        })
        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"
        })
        buffer.log(TAG, ERROR, { str1 = delay }, { "Missed AOD time tick by $str1" })
    }

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

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

    fun logPendingUnscheduleTimeTick(isPending: Boolean, isTimeTickScheduled: Boolean) {
        buffer.log(TAG, INFO, {
        buffer.log(
            TAG,
            INFO,
            {
                bool1 = isPending
                bool2 = isTimeTickScheduled
        }, {
            "Pending unschedule time tick, isPending=$bool1, isTimeTickScheduled:$bool2"
        })
            },
            { "Pending unschedule time tick, isPending=$bool1, isTimeTickScheduled:$bool2" }
        )
    }

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

    fun logStateChangedSent(state: DozeMachine.State) {
        buffer.log(TAG, INFO, {
            str1 = state.name
        }, {
            "Doze state sent to all DozeMachineParts stateSent=$str1"
        })
        buffer.log(
            TAG,
            INFO,
            { str1 = state.name },
            { "Doze state sent to all DozeMachineParts stateSent=$str1" }
        )
    }

    fun logDisplayStateDelayedByUdfps(delayedDisplayState: Int) {
        buffer.log(TAG, INFO, {
            str1 = Display.stateToString(delayedDisplayState)
        }, {
            "Delaying display state change to: $str1 due to UDFPS activity"
        })
    }

    fun logDisplayStateChanged(displayState: Int) {
        buffer.log(TAG, INFO, {
        buffer.log(
            TAG,
            INFO,
            { str1 = Display.stateToString(delayedDisplayState) },
            { "Delaying display state change to: $str1 due to UDFPS activity" }
        )
    }

    fun logDisplayStateChanged(displayState: Int, afterRequest: Boolean) {
        buffer.log(
            TAG,
            INFO,
            {
                str1 = Display.stateToString(displayState)
        }, {
            "Display state changed to $str1"
        })
                bool1 = afterRequest
            },
            { "Display state ${if (bool1) "changed" else "requested"} to $str1" }
        )
    }

    fun logWakeDisplay(isAwake: Boolean, @Reason reason: Int) {
        buffer.log(TAG, DEBUG, {
        buffer.log(
            TAG,
            DEBUG,
            {
                bool1 = isAwake
                int1 = reason
        }, {
            "Display wakefulness changed, isAwake=$bool1, reason=${reasonToString(int1)}"
        })
            },
            { "Display wakefulness changed, isAwake=$bool1, reason=${reasonToString(int1)}" }
        )
    }

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

    fun logPostureChanged(posture: Int, partUpdated: String) {
        buffer.log(TAG, INFO, {
        buffer.log(
            TAG,
            INFO,
            {
                int1 = posture
                str1 = partUpdated
        }, {
            },
            {
                "Posture changed, posture=${DevicePostureController.devicePostureToString(int1)}" +
                    " partUpdated=$str1"
        })
            }
        )
    }

    /**
     * Log why a pulse was dropped and the current doze machine state. The state can be null
     * if the DozeMachine is the middle of transitioning between states.
     * Log why a pulse was dropped and the current doze machine state. The state can be null if the
     * DozeMachine is the middle of transitioning between states.
     */
    fun logPulseDropped(from: String, state: DozeMachine.State?) {
        buffer.log(TAG, INFO, {
        buffer.log(
            TAG,
            INFO,
            {
                str1 = from
                str2 = state?.name
        }, {
            "Pulse dropped, cannot pulse from=$str1 state=$str2"
        })
            },
            { "Pulse dropped, cannot pulse from=$str1 state=$str2" }
        )
    }

    fun logSensorEventDropped(sensorEvent: Int, reason: String) {
        buffer.log(TAG, INFO, {
        buffer.log(
            TAG,
            INFO,
            {
                int1 = sensorEvent
                str1 = reason
        }, {
            "SensorEvent [$int1] dropped, reason=$str1"
        })
            },
            { "SensorEvent [$int1] dropped, reason=$str1" }
        )
    }

    fun logPulseEvent(pulseEvent: String, dozing: Boolean, pulseReason: String) {
        buffer.log(TAG, DEBUG, {
        buffer.log(
            TAG,
            DEBUG,
            {
                str1 = pulseEvent
                bool1 = dozing
                str2 = pulseReason
        }, {
            "Pulse-$str1 dozing=$bool1 pulseReason=$str2"
        })
            },
            { "Pulse-$str1 dozing=$bool1 pulseReason=$str2" }
        )
    }

    fun logPulseDropped(reason: String) {
        buffer.log(TAG, INFO, {
            str1 = reason
        }, {
            "Pulse dropped, why=$str1"
        })
        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"
        })
        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)}"
        })
        buffer.log(
            TAG,
            DEBUG,
            { int1 = reason },
            { "Sensor triggered, type=${reasonToString(int1)}" }
        )
    }

    fun logAlwaysOnSuppressed(state: DozeMachine.State, reason: String) {
        buffer.log(TAG, INFO, {
        buffer.log(
            TAG,
            INFO,
            {
                str1 = state.name
                str2 = reason
        }, {
            "Always-on state suppressed, suppressed state=$str1 reason=$str2"
        })
            },
            { "Always-on state suppressed, suppressed state=$str1 reason=$str2" }
        )
    }

    fun logImmediatelyEndDoze(reason: String) {
        buffer.log(TAG, INFO, {
            str1 = reason
        }, {
            "Doze immediately ended due to $str1"
        })
        buffer.log(TAG, INFO, { str1 = reason }, { "Doze immediately ended due to $str1" })
    }

    fun logDozeScreenBrightness(brightness: Int) {
        buffer.log(TAG, INFO, {
    fun logDozeScreenBrightness(brightness: Int, afterRequest: Boolean) {
        buffer.log(
            TAG,
            INFO,
            {
                int1 = brightness
        }, {
            "Doze screen brightness set (int), brightness=$int1"
        })
                bool1 = afterRequest
            },
            {
                "Doze screen brightness ${if (bool1) "set" else "requested"}" +
                    " (int), brightness=$int1"
            }
        )
    }

    fun logDozeScreenBrightnessFloat(brightness: Float) {
        buffer.log(TAG, INFO, {
    fun logDozeScreenBrightnessFloat(brightness: Float, afterRequest: Boolean) {
        buffer.log(
            TAG,
            INFO,
            {
                double1 = brightness.toDouble()
        }, {
            "Doze screen brightness set (float), brightness=$double1"
        })
                bool1 = afterRequest
            },
            {
                "Doze screen brightness ${if (bool1) "set" else "requested"}" +
                    " (float), brightness=$double1"
            }
        )
    }

    fun logSetAodDimmingScrim(scrimOpacity: Long) {
        buffer.log(TAG, INFO, {
            long1 = scrimOpacity
        }, {
            "Doze aod dimming scrim opacity set, opacity=$long1"
        })
        buffer.log(
            TAG,
            INFO,
            { long1 = scrimOpacity },
            { "Doze aod dimming scrim opacity set, opacity=$long1" }
        )
    }

    fun logCarModeEnded() {
        buffer.log(TAG, INFO, {}, {
            "Doze car mode ended"
        })
        buffer.log(TAG, INFO, {}, { "Doze car mode ended" })
    }

    fun logCarModeStarted() {
        buffer.log(TAG, INFO, {}, {
            "Doze car mode started"
        })
        buffer.log(TAG, INFO, {}, { "Doze car mode started" })
    }

    fun logSensorRegisterAttempt(sensorInfo: String, successfulRegistration: Boolean) {
        buffer.log(TAG, INFO, {
        buffer.log(
            TAG,
            INFO,
            {
                str1 = sensorInfo
                bool1 = successfulRegistration
        }, {
            "Register sensor. Success=$bool1 sensor=$str1"
        })
            },
            { "Register sensor. Success=$bool1 sensor=$str1" }
        )
    }

    fun logSensorUnregisterAttempt(sensorInfo: String, successfulUnregister: Boolean) {
        buffer.log(TAG, INFO, {
        buffer.log(
            TAG,
            INFO,
            {
                str1 = sensorInfo
                bool1 = successfulUnregister
        }, {
            "Unregister sensor. Success=$bool1 sensor=$str1"
        })
            },
            { "Unregister sensor. Success=$bool1 sensor=$str1" }
        )
    }

    fun logSensorUnregisterAttempt(
@@ -364,29 +387,34 @@ class DozeLogger @Inject constructor(
        successfulUnregister: Boolean,
        reason: String
    ) {
        buffer.log(TAG, INFO, {
        buffer.log(
            TAG,
            INFO,
            {
                str1 = sensorInfo
                bool1 = successfulUnregister
                str2 = reason
        }, {
            "Unregister sensor. reason=$str2. Success=$bool1 sensor=$str1"
        })
            },
            { "Unregister sensor. reason=$str2. Success=$bool1 sensor=$str1" }
        )
    }

    fun logSkipSensorRegistration(sensor: String) {
        buffer.log(TAG, DEBUG, {
            str1 = sensor
        }, {
            "Skipping sensor registration because its already registered. sensor=$str1"
        })
        buffer.log(
            TAG,
            DEBUG,
            { str1 = sensor },
            { "Skipping sensor registration because its already registered. sensor=$str1" }
        )
    }

    fun logSetIgnoreTouchWhilePulsing(ignoreTouchWhilePulsing: Boolean) {
        buffer.log(TAG, DEBUG, {
            bool1 = ignoreTouchWhilePulsing
        }, {
            "Prox changed while pulsing. setIgnoreTouchWhilePulsing=$bool1"
        })
        buffer.log(
            TAG,
            DEBUG,
            { bool1 = ignoreTouchWhilePulsing },
            { "Prox changed while pulsing. setIgnoreTouchWhilePulsing=$bool1" }
        )
    }

    fun log(@CompileTimeConstant msg: String) {
+3 −11
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ import com.android.systemui.util.wakelock.WakeLock;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.concurrent.Executor;

import javax.inject.Inject;

@@ -232,7 +231,6 @@ public class DozeMachine {
    }

    void onScreenState(int state) {
        mDozeLog.traceDisplayState(state);
        for (Part part : mParts) {
            part.onScreenState(state);
        }
@@ -516,11 +514,9 @@ public class DozeMachine {

        class Delegate implements Service {
            private final Service mDelegate;
            private final Executor mBgExecutor;

            public Delegate(Service delegate, Executor bgExecutor) {
            public Delegate(Service delegate) {
                mDelegate = delegate;
                mBgExecutor = bgExecutor;
            }

            @Override
@@ -540,16 +536,12 @@ public class DozeMachine {

            @Override
            public void setDozeScreenBrightness(int brightness) {
                mBgExecutor.execute(() -> {
                mDelegate.setDozeScreenBrightness(brightness);
                });
            }

            @Override
            public void setDozeScreenBrightnessFloat(float brightness) {
                mBgExecutor.execute(() -> {
                mDelegate.setDozeScreenBrightnessFloat(brightness);
                });
            }
        }
    }
Loading