diff options
| author | 2023-11-15 18:46:03 +0000 | |
|---|---|---|
| committer | 2023-11-15 18:46:03 +0000 | |
| commit | 0db6b846272e89972c980cec7dae70d0cd645989 (patch) | |
| tree | beb389cdbff210cc233bdf5ccb96bc4943a4fc0d | |
| parent | 03fe9c4e8e0826361800cf6ecf6c3df33fe15112 (diff) | |
| parent | fa10570fbdec9ef9e944c0602cdbc6abc047ae96 (diff) | |
Merge "Add logging for LightRevealScrim" into main
10 files changed, 180 insertions, 48 deletions
diff --git a/packages/SystemUI/src/com/android/keyguard/logging/ScrimLogger.kt b/packages/SystemUI/src/com/android/keyguard/logging/ScrimLogger.kt new file mode 100644 index 000000000000..a068769cb515 --- /dev/null +++ b/packages/SystemUI/src/com/android/keyguard/logging/ScrimLogger.kt @@ -0,0 +1,63 @@ +/* + * 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" } + ) +} diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/LightRevealScrimRepository.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/LightRevealScrimRepository.kt index 54031dcc9525..cb0f18630324 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/LightRevealScrimRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/LightRevealScrimRepository.kt @@ -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,25 +126,25 @@ 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 -> - when { - wakefulnessModel.isAwakeOrAsleepFrom(WakeSleepReason.POWER_BUTTON) -> - powerButtonRevealEffect - wakefulnessModel.isAwakeFrom(TAP) -> - tapRevealEffect - else -> - flowOf(LiftReveal) - } - } + powerInteractor.detailedWakefulness.flatMapLatest { wakefulnessModel -> + when { + wakefulnessModel.isAwakeOrAsleepFrom(WakeSleepReason.POWER_BUTTON) -> + powerButtonRevealEffect + wakefulnessModel.isAwakeFrom(TAP) -> tapRevealEffect + else -> flowOf(LiftReveal) + } + } private val revealAmountAnimator = ValueAnimator.ofFloat(0f, 1f).apply { duration = 500 } 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,13 +163,21 @@ constructor( ) { biometricUnlockState, biometricReveal, nonBiometricReveal -> // Use the biometric reveal for any flavor of wake and unlocking. - when (biometricUnlockState) { - BiometricUnlockModel.WAKE_AND_UNLOCK, - BiometricUnlockModel.WAKE_AND_UNLOCK_PULSING, - BiometricUnlockModel.WAKE_AND_UNLOCK_FROM_DREAM -> biometricReveal - else -> nonBiometricReveal - } - ?: DEFAULT_REVEAL_EFFECT + val revealEffect = + when (biometricUnlockState) { + BiometricUnlockModel.WAKE_AND_UNLOCK, + BiometricUnlockModel.WAKE_AND_UNLOCK_PULSING, + BiometricUnlockModel.WAKE_AND_UNLOCK_FROM_DREAM -> biometricReveal + 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)), ) } } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/LightRevealScrimInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/LightRevealScrimInteractor.kt index 6115d90430b3..2d43897c2565 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/LightRevealScrimInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/LightRevealScrimInteractor.kt @@ -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!! } } diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java b/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java index 17ff1b1ae888..0d81940cacbd 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java @@ -517,6 +517,16 @@ public class LogModule { } /** + * 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 diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/ScrimLog.kt b/packages/SystemUI/src/com/android/systemui/log/dagger/ScrimLog.kt new file mode 100644 index 000000000000..e78a162e723f --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/ScrimLog.kt @@ -0,0 +1,22 @@ +/* + * 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 diff --git a/packages/SystemUI/src/com/android/systemui/shade/ShadeViewProviderModule.kt b/packages/SystemUI/src/com/android/systemui/shade/ShadeViewProviderModule.kt index 37073a6b5a50..374e8717f819 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/ShadeViewProviderModule.kt +++ b/packages/SystemUI/src/com/android/systemui/shade/ShadeViewProviderModule.kt @@ -22,6 +22,7 @@ import android.os.Handler import android.view.LayoutInflater import android.view.ViewStub import androidx.constraintlayout.motion.widget.MotionLayout +import com.android.keyguard.logging.ScrimLogger import com.android.systemui.battery.BatteryMeterView import com.android.systemui.battery.BatteryMeterViewController import com.android.systemui.biometrics.AuthRippleView @@ -140,8 +141,14 @@ abstract class ShadeViewProviderModule { @SysUISingleton fun providesLightRevealScrim( notificationShadeWindowView: NotificationShadeWindowView, + scrimLogger: ScrimLogger, ): LightRevealScrim { - return notificationShadeWindowView.requireViewById(R.id.light_reveal_scrim) + val scrim = + notificationShadeWindowView.requireViewById<LightRevealScrim>( + R.id.light_reveal_scrim + ) + scrim.scrimLogger = scrimLogger + return scrim } @Provides diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/LightRevealScrim.kt b/packages/SystemUI/src/com/android/systemui/statusbar/LightRevealScrim.kt index 3120128c7967..39b7930ed386 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/LightRevealScrim.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/LightRevealScrim.kt @@ -18,6 +18,7 @@ import android.view.MotionEvent import android.view.View import android.view.animation.PathInterpolator import com.android.app.animation.Interpolators +import com.android.keyguard.logging.ScrimLogger import com.android.systemui.shade.TouchLogger import com.android.systemui.statusbar.LightRevealEffect.Companion.getPercentPastThreshold import com.android.systemui.util.getColorWithAlpha @@ -89,7 +90,7 @@ object LiftReveal : LightRevealEffect { } } -class LinearLightRevealEffect(private val isVertical: Boolean) : LightRevealEffect { +data class LinearLightRevealEffect(private val isVertical: Boolean) : LightRevealEffect { // Interpolator that reveals >80% of the content at 0.5 progress, makes revealing faster private val interpolator = @@ -155,7 +156,7 @@ class LinearLightRevealEffect(private val isVertical: Boolean) : LightRevealEffe } } -class CircleReveal( +data class CircleReveal( /** X-value of the circle center of the reveal. */ val centerX: Int, /** Y-value of the circle center of the reveal. */ @@ -181,7 +182,7 @@ class CircleReveal( } } -class PowerButtonReveal( +data class PowerButtonReveal( /** Approximate Y-value of the center of the power button on the physical device. */ val powerButtonY: Float ) : LightRevealEffect { @@ -253,7 +254,9 @@ constructor( ) : View(context, attrs) { /** Listener that is called if the scrim's opaqueness changes */ - lateinit var isScrimOpaqueChangedListener: Consumer<Boolean> + var isScrimOpaqueChangedListener: Consumer<Boolean>? = null + + var scrimLogger: ScrimLogger? = null /** * How much of the underlying views are revealed, in percent. 0 means they will be completely @@ -263,7 +266,9 @@ constructor( set(value) { if (field != value) { field = value - + if (value <= 0.0f || value >= 1.0f) { + scrimLogger?.d(TAG, "revealAmount", "$value on ${logString()}") + } revealEffect.setRevealAmountOnScrim(value, this) updateScrimOpaque() Trace.traceCounter( @@ -285,6 +290,7 @@ constructor( field = value revealEffect.setRevealAmountOnScrim(revealAmount, this) + scrimLogger?.d(TAG, "revealEffect", "$value on ${logString()}") invalidate() } } @@ -301,6 +307,7 @@ constructor( */ internal var viewWidth: Int = initialWidth ?: 0 private set + internal var viewHeight: Int = initialHeight ?: 0 private set @@ -342,7 +349,8 @@ constructor( private set(value) { if (field != value) { field = value - isScrimOpaqueChangedListener.accept(field) + isScrimOpaqueChangedListener?.accept(field) + scrimLogger?.d(TAG, "isScrimOpaque", "$value on ${logString()}") } } @@ -360,11 +368,13 @@ constructor( override fun setAlpha(alpha: Float) { super.setAlpha(alpha) + scrimLogger?.d(TAG, "alpha", "$alpha on ${logString()}") updateScrimOpaque() } override fun setVisibility(visibility: Int) { super.setVisibility(visibility) + scrimLogger?.d(TAG, "visibility", "$visibility on ${logString()}") updateScrimOpaque() } @@ -424,11 +434,7 @@ constructor( } override fun onDraw(canvas: Canvas) { - if ( - revealGradientWidth <= 0 || - revealGradientHeight <= 0 || - revealAmount == 0f - ) { + if (revealGradientWidth <= 0 || revealGradientHeight <= 0 || revealAmount == 0f) { if (revealAmount < 1f) { canvas.drawColor(revealGradientEndColor) } @@ -461,4 +467,8 @@ constructor( PorterDuff.Mode.MULTIPLY ) } + + private fun logString(): String { + return this::class.simpleName!! + "@" + hashCode() + } } diff --git a/packages/SystemUI/src/com/android/systemui/unfold/UnfoldLightRevealOverlayAnimation.kt b/packages/SystemUI/src/com/android/systemui/unfold/UnfoldLightRevealOverlayAnimation.kt index 2afb43515be7..36a1e8a072c9 100644 --- a/packages/SystemUI/src/com/android/systemui/unfold/UnfoldLightRevealOverlayAnimation.kt +++ b/packages/SystemUI/src/com/android/systemui/unfold/UnfoldLightRevealOverlayAnimation.kt @@ -49,6 +49,7 @@ import com.android.systemui.unfold.updates.RotationChangeProvider import com.android.systemui.unfold.util.ScaleAwareTransitionProgressProvider.Companion.areAnimationsEnabled import com.android.systemui.util.concurrency.ThreadFactory import com.android.app.tracing.traceSection +import com.android.keyguard.logging.ScrimLogger import com.android.wm.shell.displayareahelper.DisplayAreaHelper import java.util.Optional import java.util.concurrent.Executor @@ -69,7 +70,8 @@ constructor( @Main private val executor: Executor, private val threadFactory: ThreadFactory, private val rotationChangeProvider: RotationChangeProvider, - private val displayTracker: DisplayTracker + private val displayTracker: DisplayTracker, + private val scrimLogger: ScrimLogger, ) { private val transitionListener = TransitionListener() @@ -179,8 +181,8 @@ constructor( ) .apply { revealEffect = createLightRevealEffect() - isScrimOpaqueChangedListener = Consumer {} revealAmount = calculateRevealAmount() + scrimLogger = this@UnfoldLightRevealOverlayAnimation.scrimLogger } newRoot.setView(newView, params) diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/LightRevealScrimRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/LightRevealScrimRepositoryTest.kt index 799bd5ac5739..7242cb20dc77 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/LightRevealScrimRepositoryTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/LightRevealScrimRepositoryTest.kt @@ -31,6 +31,7 @@ import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.se import com.android.systemui.power.domain.interactor.PowerInteractorFactory import com.android.systemui.statusbar.CircleReveal import com.android.systemui.statusbar.LightRevealEffect +import com.android.systemui.util.mockito.mock import junit.framework.Assert.assertEquals import junit.framework.Assert.assertFalse import kotlinx.coroutines.ExperimentalCoroutinesApi @@ -60,15 +61,11 @@ class LightRevealScrimRepositoryTest : SysuiTestCase() { MockitoAnnotations.initMocks(this) fakeKeyguardRepository = FakeKeyguardRepository() powerRepository = FakePowerRepository() - powerInteractor = PowerInteractorFactory.create( - repository = powerRepository - ).powerInteractor - - underTest = LightRevealScrimRepositoryImpl( - fakeKeyguardRepository, - context, - powerInteractor, - ) + powerInteractor = + PowerInteractorFactory.create(repository = powerRepository).powerInteractor + + underTest = + LightRevealScrimRepositoryImpl(fakeKeyguardRepository, context, powerInteractor, mock()) } @Test diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/LightRevealScrimInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/LightRevealScrimInteractorTest.kt index 03a1f7a3d6ab..b483085cf1e5 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/LightRevealScrimInteractorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/LightRevealScrimInteractorTest.kt @@ -26,6 +26,7 @@ import com.android.systemui.keyguard.shared.model.TransitionState import com.android.systemui.keyguard.shared.model.TransitionStep import com.android.systemui.statusbar.LightRevealEffect import com.android.systemui.statusbar.LightRevealScrim +import com.android.systemui.util.mockito.mock import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach @@ -80,7 +81,8 @@ class LightRevealScrimInteractorTest : SysuiTestCase() { LightRevealScrimInteractor( keyguardTransitionInteractor, fakeLightRevealScrimRepository, - testScope.backgroundScope + testScope.backgroundScope, + mock() ) } |