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

Commit 0db6b846 authored by Andreas Miko's avatar Andreas Miko Committed by Android (Google) Code Review
Browse files

Merge "Add logging for LightRevealScrim" into main

parents 03fe9c4e fa10570f
Loading
Loading
Loading
Loading
+63 −0
Original line number Original line 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 Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.Context
import android.graphics.Point
import android.graphics.Point
import androidx.core.animation.Animator
import androidx.core.animation.Animator
import androidx.core.animation.ValueAnimator
import androidx.core.animation.ValueAnimator
import com.android.keyguard.logging.ScrimLogger
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.keyguard.shared.model.BiometricUnlockModel
import com.android.systemui.keyguard.shared.model.BiometricUnlockModel
import com.android.systemui.keyguard.shared.model.BiometricUnlockSource
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.LiftReveal
import com.android.systemui.statusbar.LightRevealEffect
import com.android.systemui.statusbar.LightRevealEffect
import com.android.systemui.statusbar.PowerButtonReveal
import com.android.systemui.statusbar.PowerButtonReveal
import javax.inject.Inject
import kotlin.math.max
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.Flow
@@ -42,8 +45,6 @@ import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.map
import javax.inject.Inject
import kotlin.math.max


val DEFAULT_REVEAL_EFFECT = LiftReveal
val DEFAULT_REVEAL_EFFECT = LiftReveal


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


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

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


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


@@ -138,7 +140,11 @@ constructor(
    override val revealAmount: Flow<Float> = callbackFlow {
    override val revealAmount: Flow<Float> = callbackFlow {
        val updateListener =
        val updateListener =
            Animator.AnimatorUpdateListener {
            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)
        revealAmountAnimator.addUpdateListener(updateListener)
        awaitClose { revealAmountAnimator.removeUpdateListener(updateListener) }
        awaitClose { revealAmountAnimator.removeUpdateListener(updateListener) }
@@ -146,6 +152,7 @@ constructor(


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


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


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

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


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


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


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


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

        val TAG = LightRevealScrimInteractor::class.simpleName!!
    }
    }
}
}
+10 −0
Original line number Original line Diff line number Diff line
@@ -516,6 +516,16 @@ public class LogModule {
        return factory.create("KeyguardLog", 250);
        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.
     * Provides a {@link LogBuffer} for dream-related logs.
     */
     */
+22 −0
Original line number Original line 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