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

Commit fa10570f authored by Andreas Miko's avatar Andreas Miko
Browse files

Add logging for LightRevealScrim

There has been issues where LightRevealScrim would get out of sync with
Lockscreen state. To better diagnose these kind of issues new logs are
added.

Test: NONE
Bug: b/305680502
Flag: NONE
Change-Id: I929ceca5b1f62d3b708b0b1cb24e660255396bf9
parent 845d3abc
Loading
Loading
Loading
Loading
+63 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.keyguard.logging

import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.LogLevel
import com.android.systemui.log.dagger.ScrimLog
import com.google.errorprone.annotations.CompileTimeConstant
import javax.inject.Inject

/**
 * A logger to log scrim state.
 *
 * To enable logcat echoing for this buffer use this command:
 * ```
 * $ adb shell cmd statusbar echo -b ScrimLog:VERBOSE
 * ```
 */
class ScrimLogger
@Inject
constructor(
    @ScrimLog val buffer: LogBuffer,
) {
    companion object {
        val TAG = ScrimLogger::class.simpleName!!
    }

    fun d(
        tag: String,
        @CompileTimeConstant msg: String,
        arg: Any,
    ) = log("$tag::$TAG", LogLevel.DEBUG, msg, arg)

    fun log(
        tag: String,
        level: LogLevel,
        @CompileTimeConstant msg: String,
        arg: Any,
    ) =
        buffer.log(
            tag,
            level,
            {
                str1 = msg
                str2 = arg.toString()
            },
            { "$str1: $str2" }
        )
}
+38 −24
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.Context
import android.graphics.Point
import androidx.core.animation.Animator
import androidx.core.animation.ValueAnimator
import com.android.keyguard.logging.ScrimLogger
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.keyguard.shared.model.BiometricUnlockModel
import com.android.systemui.keyguard.shared.model.BiometricUnlockSource
@@ -33,6 +34,8 @@ import com.android.systemui.statusbar.CircleReveal
import com.android.systemui.statusbar.LiftReveal
import com.android.systemui.statusbar.LightRevealEffect
import com.android.systemui.statusbar.PowerButtonReveal
import javax.inject.Inject
import kotlin.math.max
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
@@ -42,8 +45,6 @@ import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import javax.inject.Inject
import kotlin.math.max

val DEFAULT_REVEAL_EFFECT = LiftReveal

@@ -72,8 +73,13 @@ constructor(
    keyguardRepository: KeyguardRepository,
    val context: Context,
    powerInteractor: PowerInteractor,
    private val scrimLogger: ScrimLogger,
) : LightRevealScrimRepository {

    companion object {
        val TAG = LightRevealScrimRepository::class.simpleName!!
    }

    /** The reveal effect used if the device was locked/unlocked via the power button. */
    private val powerButtonRevealEffect: Flow<LightRevealEffect?> =
        flowOf(
@@ -120,16 +126,12 @@ constructor(

    /** The reveal effect we'll use for the next non-biometric unlock (tap, power button, etc). */
    private val nonBiometricRevealEffect: Flow<LightRevealEffect?> =
        powerInteractor
                .detailedWakefulness
                .flatMapLatest { wakefulnessModel ->
        powerInteractor.detailedWakefulness.flatMapLatest { wakefulnessModel ->
            when {
                wakefulnessModel.isAwakeOrAsleepFrom(WakeSleepReason.POWER_BUTTON) ->
                    powerButtonRevealEffect
                        wakefulnessModel.isAwakeFrom(TAP) ->
                            tapRevealEffect
                        else ->
                            flowOf(LiftReveal)
                wakefulnessModel.isAwakeFrom(TAP) -> tapRevealEffect
                else -> flowOf(LiftReveal)
            }
        }

@@ -138,7 +140,11 @@ constructor(
    override val revealAmount: Flow<Float> = callbackFlow {
        val updateListener =
            Animator.AnimatorUpdateListener {
                trySend((it as ValueAnimator).animatedValue as Float)
                val value = (it as ValueAnimator).animatedValue
                trySend(value as Float)
                if (value <= 0.0f || value >= 1.0f) {
                    scrimLogger.d(TAG, "revealAmount", value)
                }
            }
        revealAmountAnimator.addUpdateListener(updateListener)
        awaitClose { revealAmountAnimator.removeUpdateListener(updateListener) }
@@ -146,6 +152,7 @@ constructor(

    override fun startRevealAmountAnimator(reveal: Boolean) {
        if (reveal) revealAmountAnimator.start() else revealAmountAnimator.reverse()
        scrimLogger.d(TAG, "startRevealAmountAnimator, reveal", reveal)
    }

    override val revealEffect =
@@ -156,6 +163,7 @@ constructor(
            ) { biometricUnlockState, biometricReveal, nonBiometricReveal ->

                // Use the biometric reveal for any flavor of wake and unlocking.
                val revealEffect =
                    when (biometricUnlockState) {
                        BiometricUnlockModel.WAKE_AND_UNLOCK,
                        BiometricUnlockModel.WAKE_AND_UNLOCK_PULSING,
@@ -163,6 +171,13 @@ constructor(
                        else -> nonBiometricReveal
                    }
                        ?: DEFAULT_REVEAL_EFFECT

                scrimLogger.d(
                    TAG,
                    "revealEffect",
                    "$revealEffect, biometricUnlockState: ${biometricUnlockState.name}"
                )
                return@combine revealEffect
            }
            .distinctUntilChanged()

@@ -173,8 +188,7 @@ constructor(
                x,
                y,
                startRadius = 0,
                endRadius =
                    max(max(x, display.width - x), max(y, display.height - y)),
                endRadius = max(max(x, display.width - x), max(y, display.height - y)),
            )
        }
    }
+5 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.keyguard.domain.interactor

import com.android.keyguard.logging.ScrimLogger
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.keyguard.data.repository.LightRevealScrimRepository
@@ -37,6 +38,7 @@ constructor(
    private val transitionInteractor: KeyguardTransitionInteractor,
    private val lightRevealScrimRepository: LightRevealScrimRepository,
    @Application private val scope: CoroutineScope,
    private val scrimLogger: ScrimLogger,
) {

    init {
@@ -46,6 +48,7 @@ constructor(
    private fun listenForStartedKeyguardTransitionStep() {
        scope.launch {
            transitionInteractor.startedKeyguardTransitionStep.collect {
                scrimLogger.d(TAG, "listenForStartedKeyguardTransitionStep", it)
                if (willTransitionChangeEndState(it)) {
                    lightRevealScrimRepository.startRevealAmountAnimator(
                        willBeRevealedInState(it.to)
@@ -100,5 +103,7 @@ constructor(
                KeyguardState.OCCLUDED -> true
            }
        }

        val TAG = LightRevealScrimInteractor::class.simpleName!!
    }
}
+10 −0
Original line number Diff line number Diff line
@@ -516,6 +516,16 @@ public class LogModule {
        return factory.create("KeyguardLog", 250);
    }

    /**
     * Provides a {@link LogBuffer} for Scrims like LightRevealScrim.
     */
    @Provides
    @SysUISingleton
    @ScrimLog
    public static LogBuffer provideScrimLogBuffer(LogBufferFactory factory) {
        return factory.create("ScrimLog", 100);
    }

    /**
     * Provides a {@link LogBuffer} for dream-related logs.
     */
+22 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.log.dagger

import javax.inject.Qualifier

/** A [com.android.systemui.log.LogBuffer] for Scrims like LightRevealScrim */
@Qualifier @MustBeDocumented @Retention(AnnotationRetention.RUNTIME) annotation class ScrimLog
Loading