From 32adcac8e102550714b82d5063b0b13387f0a7d4 Mon Sep 17 00:00:00 2001 From: Alejandro Nijamkin Date: Wed, 2 Aug 2023 09:42:49 -0700 Subject: [PATCH] [flexiglass] Adds logging for scene and visibility changes. This should prove useful in debugging. Fix: 294228910 Test: manually ran, changed scenes, and verified scene and visibility logging works as intended. Change-Id: I9efc88fddc30544d7629a76aa73aa3ee1c91caae --- .../domain/interactor/BouncerInteractor.kt | 3 + .../systemui/log/dagger/LogModule.java | 8 ++ .../systemui/log/dagger/SceneFrameworkLog.kt | 25 ++++++ .../recents/OverviewProxyService.java | 2 +- .../domain/interactor/SceneInteractor.kt | 25 +++++- .../startable/SceneContainerStartable.kt | 44 ++++++++-- .../scene/shared/logger/SceneLogger.kt | 81 +++++++++++++++++++ .../ui/viewmodel/SceneContainerViewModel.kt | 9 ++- .../phone/PhoneStatusBarViewController.kt | 50 ++++++------ ...KeyguardSecurityContainerControllerTest.kt | 12 +-- .../viewmodel/PasswordBouncerViewModelTest.kt | 10 +-- .../viewmodel/PatternBouncerViewModelTest.kt | 10 +-- .../ui/viewmodel/PinBouncerViewModelTest.kt | 20 ++--- .../LockscreenSceneInteractorTest.kt | 10 +-- .../domain/interactor/SceneInteractorTest.kt | 10 +-- .../startable/SceneContainerStartableTest.kt | 11 +-- .../viewmodel/SceneContainerViewModelTest.kt | 4 +- .../android/systemui/scene/SceneTestUtils.kt | 2 + 18 files changed, 257 insertions(+), 79 deletions(-) create mode 100644 packages/SystemUI/src/com/android/systemui/log/dagger/SceneFrameworkLog.kt create mode 100644 packages/SystemUI/src/com/android/systemui/scene/shared/logger/SceneLogger.kt diff --git a/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/BouncerInteractor.kt b/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/BouncerInteractor.kt index d8cf398b696b2..8ed964d4af221 100644 --- a/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/BouncerInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/BouncerInteractor.kt @@ -127,10 +127,12 @@ constructor( repository.setMessage(message ?: promptMessage(getAuthenticationMethod())) sceneInteractor.setCurrentScene( scene = SceneModel(SceneKey.Bouncer), + loggingReason = "request to unlock device while authentication required", ) } else { sceneInteractor.setCurrentScene( scene = SceneModel(SceneKey.Gone), + loggingReason = "request to unlock device while authentication isn't required", ) } } @@ -176,6 +178,7 @@ constructor( if (isAuthenticated) { sceneInteractor.setCurrentScene( scene = SceneModel(SceneKey.Gone), + loggingReason = "successful authentication", ) } else { repository.setMessage(errorMessage(getAuthenticationMethod())) 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 b5759e3a31405..cc1504a1df977 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java @@ -496,4 +496,12 @@ public class LogModule { public static LogBuffer provideDisplayMetricsRepoLogBuffer(LogBufferFactory factory) { return factory.create("DisplayMetricsRepo", 50); } + + /** Provides a {@link LogBuffer} for the scene framework. */ + @Provides + @SysUISingleton + @SceneFrameworkLog + public static LogBuffer provideSceneFrameworkLogBuffer(LogBufferFactory factory) { + return factory.create("SceneFramework", 50); + } } diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/SceneFrameworkLog.kt b/packages/SystemUI/src/com/android/systemui/log/dagger/SceneFrameworkLog.kt new file mode 100644 index 0000000000000..ef5f4e3272ca1 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/SceneFrameworkLog.kt @@ -0,0 +1,25 @@ +/* + * 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 the Scene Framework. */ +@Qualifier +@MustBeDocumented +@Retention(AnnotationRetention.RUNTIME) +annotation class SceneFrameworkLog diff --git a/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java b/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java index 03bd11bb433ef..9f45f66d9971f 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java +++ b/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java @@ -220,7 +220,7 @@ public class OverviewProxyService implements CallbackController = repository.currentScene /** Sets the visibility of the container with the given name. */ - fun setVisible(isVisible: Boolean) { + fun setVisible(isVisible: Boolean, loggingReason: String) { + val wasVisible = repository.isVisible.value + if (wasVisible == isVisible) { + return + } + + logger.logVisibilityChange( + from = wasVisible, + to = isVisible, + reason = loggingReason, + ) return repository.setVisible(isVisible) } diff --git a/packages/SystemUI/src/com/android/systemui/scene/domain/startable/SceneContainerStartable.kt b/packages/SystemUI/src/com/android/systemui/scene/domain/startable/SceneContainerStartable.kt index 1c87eb25004e6..20ee393e8dacb 100644 --- a/packages/SystemUI/src/com/android/systemui/scene/domain/startable/SceneContainerStartable.kt +++ b/packages/SystemUI/src/com/android/systemui/scene/domain/startable/SceneContainerStartable.kt @@ -28,6 +28,7 @@ import com.android.systemui.keyguard.shared.model.WakefulnessState import com.android.systemui.model.SysUiState import com.android.systemui.model.updateFlags import com.android.systemui.scene.domain.interactor.SceneInteractor +import com.android.systemui.scene.shared.logger.SceneLogger import com.android.systemui.scene.shared.model.SceneKey import com.android.systemui.scene.shared.model.SceneModel import com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_BOUNCER_SHOWING @@ -57,13 +58,17 @@ constructor( private val featureFlags: FeatureFlags, private val sysUiState: SysUiState, @DisplayId private val displayId: Int, + private val sceneLogger: SceneLogger, ) : CoreStartable { override fun start() { if (featureFlags.isEnabled(Flags.SCENE_CONTAINER)) { + sceneLogger.logFrameworkEnabled(isEnabled = true) hydrateVisibility() automaticallySwitchScenes() hydrateSystemUiState() + } else { + sceneLogger.logFrameworkEnabled(isEnabled = false) } } @@ -73,7 +78,9 @@ constructor( sceneInteractor.currentScene .map { it.key } .distinctUntilChanged() - .collect { sceneKey -> sceneInteractor.setVisible(sceneKey != SceneKey.Gone) } + .collect { sceneKey -> + sceneInteractor.setVisible(sceneKey != SceneKey.Gone, "scene is $sceneKey") + } } } @@ -88,10 +95,17 @@ constructor( isUnlocked -> when (currentSceneKey) { // When the device becomes unlocked in Bouncer, go to Gone. - is SceneKey.Bouncer -> SceneKey.Gone + is SceneKey.Bouncer -> + SceneKey.Gone to "device unlocked in Bouncer scene" // When the device becomes unlocked in Lockscreen, go to Gone if // bypass is enabled. - is SceneKey.Lockscreen -> SceneKey.Gone.takeIf { isBypassEnabled } + is SceneKey.Lockscreen -> + if (isBypassEnabled) { + SceneKey.Gone to + "device unlocked in Lockscreen scene with bypass" + } else { + null + } // We got unlocked while on a scene that's not Lockscreen or // Bouncer, no need to change scenes. else -> null @@ -104,13 +118,19 @@ constructor( is SceneKey.Bouncer -> null // We got locked while on a scene that's not Lockscreen or Bouncer, // go to Lockscreen. - else -> SceneKey.Lockscreen + else -> + SceneKey.Lockscreen to "device locked in $currentSceneKey scene" } else -> null } } .filterNotNull() - .collect { targetSceneKey -> switchToScene(targetSceneKey) } + .collect { (targetSceneKey, loggingReason) -> + switchToScene( + targetSceneKey = targetSceneKey, + loggingReason = loggingReason, + ) + } } applicationScope.launch { @@ -121,7 +141,16 @@ constructor( if (isAsleep) { // When the device goes to sleep, reset the current scene. val isUnlocked = authenticationInteractor.isUnlocked.value - switchToScene(if (isUnlocked) SceneKey.Gone else SceneKey.Lockscreen) + val (targetSceneKey, loggingReason) = + if (isUnlocked) { + SceneKey.Gone to "device is asleep while unlocked" + } else { + SceneKey.Lockscreen to "device is asleep while locked" + } + switchToScene( + targetSceneKey = targetSceneKey, + loggingReason = loggingReason, + ) } } } @@ -147,9 +176,10 @@ constructor( } } - private fun switchToScene(targetSceneKey: SceneKey) { + private fun switchToScene(targetSceneKey: SceneKey, loggingReason: String) { sceneInteractor.setCurrentScene( scene = SceneModel(targetSceneKey), + loggingReason = loggingReason, ) } } diff --git a/packages/SystemUI/src/com/android/systemui/scene/shared/logger/SceneLogger.kt b/packages/SystemUI/src/com/android/systemui/scene/shared/logger/SceneLogger.kt new file mode 100644 index 0000000000000..0adbd5ad19a7e --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/scene/shared/logger/SceneLogger.kt @@ -0,0 +1,81 @@ +/* + * Copyright 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.scene.shared.logger + +import com.android.systemui.log.LogBuffer +import com.android.systemui.log.core.LogLevel +import com.android.systemui.log.dagger.SceneFrameworkLog +import com.android.systemui.scene.shared.model.SceneKey +import javax.inject.Inject + +class SceneLogger @Inject constructor(@SceneFrameworkLog private val logBuffer: LogBuffer) { + + fun logFrameworkEnabled(isEnabled: Boolean) { + fun asWord(isEnabled: Boolean): String { + return if (isEnabled) "enabled" else "disabled" + } + + logBuffer.log( + tag = TAG, + level = LogLevel.INFO, + messageInitializer = { bool1 = isEnabled }, + messagePrinter = { "Scene framework is ${asWord(bool1)}" } + ) + } + + fun logSceneChange( + from: SceneKey, + to: SceneKey, + reason: String, + ) { + logBuffer.log( + tag = TAG, + level = LogLevel.INFO, + messageInitializer = { + str1 = from.toString() + str2 = to.toString() + str3 = reason + }, + messagePrinter = { "$str1 → $str2, reason: $str3" }, + ) + } + + fun logVisibilityChange( + from: Boolean, + to: Boolean, + reason: String, + ) { + fun asWord(isVisible: Boolean): String { + return if (isVisible) "visible" else "invisible" + } + + logBuffer.log( + tag = TAG, + level = LogLevel.INFO, + messageInitializer = { + str1 = asWord(from) + str2 = asWord(to) + str3 = reason + }, + messagePrinter = { "$str1 → $str2, reason: $str3" }, + ) + } + + companion object { + private const val TAG = "SceneFramework" + } +} diff --git a/packages/SystemUI/src/com/android/systemui/scene/ui/viewmodel/SceneContainerViewModel.kt b/packages/SystemUI/src/com/android/systemui/scene/ui/viewmodel/SceneContainerViewModel.kt index bd73e36262b8d..b4ebaece21f16 100644 --- a/packages/SystemUI/src/com/android/systemui/scene/ui/viewmodel/SceneContainerViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/scene/ui/viewmodel/SceneContainerViewModel.kt @@ -53,7 +53,10 @@ constructor( /** Requests a transition to the scene with the given key. */ fun setCurrentScene(scene: SceneModel) { - interactor.setCurrentScene(scene) + interactor.setCurrentScene( + scene = scene, + loggingReason = SCENE_TRANSITION_LOGGING_REASON, + ) } /** @@ -69,4 +72,8 @@ constructor( fun onRemoteUserInput(event: MotionEvent) { interactor.onRemoteUserInput(RemoteUserInput.translateMotionEvent(event)) } + + companion object { + private const val SCENE_TRANSITION_LOGGING_REASON = "user input" + } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewController.kt index 122728716eeed..2affb8173a01d 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewController.kt @@ -150,10 +150,10 @@ class PhoneStatusBarViewController private constructor( fun onTouch(event: MotionEvent) { if (centralSurfaces.statusBarWindowState == WINDOW_STATE_SHOWING) { val upOrCancel = - event.action == MotionEvent.ACTION_UP || + event.action == MotionEvent.ACTION_UP || event.action == MotionEvent.ACTION_CANCEL centralSurfaces.setInteracting(WINDOW_STATUS_BAR, - !upOrCancel || shadeController.isExpandedVisible) + !upOrCancel || shadeController.isExpandedVisible) } } @@ -171,7 +171,7 @@ class PhoneStatusBarViewController private constructor( if (!centralSurfaces.commandQueuePanelsEnabled) { if (event.action == MotionEvent.ACTION_DOWN) { Log.v(TAG, String.format("onTouchForwardedFromStatusBar: panel disabled, " + - "ignoring touch at (${event.x.toInt()},${event.y.toInt()})")) + "ignoring touch at (${event.x.toInt()},${event.y.toInt()})")) } return false } @@ -182,7 +182,7 @@ class PhoneStatusBarViewController private constructor( sceneInteractor.get() .onRemoteUserInput(RemoteUserInput.translateMotionEvent(event)) // TODO(b/291965119): remove once view is expanded to cover the status bar - sceneInteractor.get().setVisible(true) + sceneInteractor.get().setVisible(true, "swipe down from status bar") return false } @@ -191,11 +191,11 @@ class PhoneStatusBarViewController private constructor( // bar eat the gesture. if (!shadeViewController.isViewEnabled) { shadeLogger.logMotionEvent(event, - "onTouchForwardedFromStatusBar: panel view disabled") + "onTouchForwardedFromStatusBar: panel view disabled") return true } if (shadeViewController.isFullyCollapsed && - event.y < 1f) { + event.y < 1f) { // b/235889526 Eat events on the top edge of the phone when collapsed shadeLogger.logMotionEvent(event, "top edge touch ignored") return true @@ -257,27 +257,27 @@ class PhoneStatusBarViewController private constructor( view: PhoneStatusBarView ): PhoneStatusBarViewController { val statusBarMoveFromCenterAnimationController = - if (featureFlags.isEnabled(Flags.ENABLE_UNFOLD_STATUS_BAR_ANIMATIONS)) { - unfoldComponent.getOrNull()?.getStatusBarMoveFromCenterAnimationController() - } else { - null - } + if (featureFlags.isEnabled(Flags.ENABLE_UNFOLD_STATUS_BAR_ANIMATIONS)) { + unfoldComponent.getOrNull()?.getStatusBarMoveFromCenterAnimationController() + } else { + null + } return PhoneStatusBarViewController( - view, - progressProvider.getOrNull(), - centralSurfaces, - shadeController, - shadeViewController, - sceneInteractor, - shadeLogger, - statusBarMoveFromCenterAnimationController, - userChipViewModel, - viewUtil, - featureFlags, - configurationController, - statusOverlayHoverListenerFactory, + view, + progressProvider.getOrNull(), + centralSurfaces, + shadeController, + shadeViewController, + sceneInteractor, + shadeLogger, + statusBarMoveFromCenterAnimationController, + userChipViewModel, + viewUtil, + featureFlags, + configurationController, + statusOverlayHoverListenerFactory, ) } } -} +} \ No newline at end of file diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerControllerTest.kt b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerControllerTest.kt index e447c29b351f4..efb981e5cebbe 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerControllerTest.kt @@ -733,20 +733,20 @@ class KeyguardSecurityContainerControllerTest : SysuiTestCase() { // is // not enough to trigger a dismissal of the keyguard. underTest.onViewAttached() - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer, null)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer, null), "reason") runCurrent() verify(viewMediatorCallback, never()).keyguardDone(anyBoolean(), anyInt()) // While listening, going from the bouncer scene to the gone scene, does dismiss the // keyguard. - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Gone, null)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Gone, null), "reason") runCurrent() verify(viewMediatorCallback).keyguardDone(anyBoolean(), anyInt()) // While listening, moving back to the bouncer scene does not dismiss the keyguard // again. clearInvocations(viewMediatorCallback) - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer, null)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer, null), "reason") runCurrent() verify(viewMediatorCallback, never()).keyguardDone(anyBoolean(), anyInt()) @@ -754,12 +754,12 @@ class KeyguardSecurityContainerControllerTest : SysuiTestCase() { // scene // does not dismiss the keyguard while we're not listening. underTest.onViewDetached() - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Gone, null)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Gone, null), "reason") runCurrent() verify(viewMediatorCallback, never()).keyguardDone(anyBoolean(), anyInt()) // While not listening, moving back to the bouncer does not dismiss the keyguard. - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer, null)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer, null), "reason") runCurrent() verify(viewMediatorCallback, never()).keyguardDone(anyBoolean(), anyInt()) @@ -767,7 +767,7 @@ class KeyguardSecurityContainerControllerTest : SysuiTestCase() { // gone // scene now does dismiss the keyguard again. underTest.onViewAttached() - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Gone, null)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Gone, null), "reason") runCurrent() verify(viewMediatorCallback).keyguardDone(anyBoolean(), anyInt()) } diff --git a/packages/SystemUI/tests/src/com/android/systemui/bouncer/ui/viewmodel/PasswordBouncerViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/bouncer/ui/viewmodel/PasswordBouncerViewModelTest.kt index 1f089ca8b98e4..7f8d54c433870 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/bouncer/ui/viewmodel/PasswordBouncerViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/bouncer/ui/viewmodel/PasswordBouncerViewModelTest.kt @@ -79,7 +79,7 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { AuthenticationMethodModel.Password ) utils.authenticationRepository.setUnlocked(false) - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer), "reason") assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) underTest.onShown() @@ -99,7 +99,7 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { AuthenticationMethodModel.Password ) utils.authenticationRepository.setUnlocked(false) - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer), "reason") assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) underTest.onShown() runCurrent() @@ -119,7 +119,7 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { AuthenticationMethodModel.Password ) utils.authenticationRepository.setUnlocked(false) - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer), "reason") assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) underTest.onShown() underTest.onPasswordInputChanged("password") @@ -139,7 +139,7 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { AuthenticationMethodModel.Password ) utils.authenticationRepository.setUnlocked(false) - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer), "reason") assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) underTest.onShown() underTest.onPasswordInputChanged("wrong") @@ -161,7 +161,7 @@ class PasswordBouncerViewModelTest : SysuiTestCase() { AuthenticationMethodModel.Password ) utils.authenticationRepository.setUnlocked(false) - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer), "reason") assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) underTest.onShown() underTest.onPasswordInputChanged("wrong") diff --git a/packages/SystemUI/tests/src/com/android/systemui/bouncer/ui/viewmodel/PatternBouncerViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/bouncer/ui/viewmodel/PatternBouncerViewModelTest.kt index af54989002e98..57fcbe595fa6e 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/bouncer/ui/viewmodel/PatternBouncerViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/bouncer/ui/viewmodel/PatternBouncerViewModelTest.kt @@ -83,7 +83,7 @@ class PatternBouncerViewModelTest : SysuiTestCase() { AuthenticationMethodModel.Pattern ) utils.authenticationRepository.setUnlocked(false) - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer), "reason") assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) underTest.onShown() @@ -105,7 +105,7 @@ class PatternBouncerViewModelTest : SysuiTestCase() { AuthenticationMethodModel.Pattern ) utils.authenticationRepository.setUnlocked(false) - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer), "reason") assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) underTest.onShown() runCurrent() @@ -128,7 +128,7 @@ class PatternBouncerViewModelTest : SysuiTestCase() { AuthenticationMethodModel.Pattern ) utils.authenticationRepository.setUnlocked(false) - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer), "reason") assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) underTest.onShown() underTest.onDragStart() @@ -176,7 +176,7 @@ class PatternBouncerViewModelTest : SysuiTestCase() { AuthenticationMethodModel.Pattern ) utils.authenticationRepository.setUnlocked(false) - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer), "reason") assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) underTest.onShown() underTest.onDragStart() @@ -208,7 +208,7 @@ class PatternBouncerViewModelTest : SysuiTestCase() { AuthenticationMethodModel.Pattern ) utils.authenticationRepository.setUnlocked(false) - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer), "reason") assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) underTest.onShown() underTest.onDragStart() diff --git a/packages/SystemUI/tests/src/com/android/systemui/bouncer/ui/viewmodel/PinBouncerViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/bouncer/ui/viewmodel/PinBouncerViewModelTest.kt index c12ed033d7528..81c68ed2320f3 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/bouncer/ui/viewmodel/PinBouncerViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/bouncer/ui/viewmodel/PinBouncerViewModelTest.kt @@ -79,7 +79,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { val message by collectLastValue(bouncerViewModel.message) val pin by collectLastValue(underTest.pinInput.map { it.getPin() }) utils.authenticationRepository.setUnlocked(false) - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer), "reason") assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) underTest.onShown() @@ -97,7 +97,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { val pin by collectLastValue(underTest.pinInput.map { it.getPin() }) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) utils.authenticationRepository.setUnlocked(false) - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer), "reason") assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) underTest.onShown() runCurrent() @@ -117,7 +117,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { val pin by collectLastValue(underTest.pinInput.map { it.getPin() }) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) utils.authenticationRepository.setUnlocked(false) - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer), "reason") assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) underTest.onShown() runCurrent() @@ -138,7 +138,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { val pin by collectLastValue(underTest.pinInput.map { it.getPin() }) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) utils.authenticationRepository.setUnlocked(false) - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer), "reason") assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) underTest.onShown() @@ -161,7 +161,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { val pin by collectLastValue(underTest.pinInput.map { it.getPin() }) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) utils.authenticationRepository.setUnlocked(false) - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer), "reason") assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) underTest.onShown() runCurrent() @@ -183,7 +183,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { val currentScene by collectLastValue(sceneInteractor.currentScene) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) utils.authenticationRepository.setUnlocked(false) - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer), "reason") assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) underTest.onShown() FakeAuthenticationRepository.DEFAULT_PIN.forEach { digit -> @@ -203,7 +203,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { val pin by collectLastValue(underTest.pinInput.map { it.getPin() }) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) utils.authenticationRepository.setUnlocked(false) - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer), "reason") assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) underTest.onShown() underTest.onPinButtonClicked(1) @@ -227,7 +227,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { val pin by collectLastValue(underTest.pinInput.map { it.getPin() }) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) utils.authenticationRepository.setUnlocked(false) - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer), "reason") assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) underTest.onShown() underTest.onPinButtonClicked(1) @@ -258,7 +258,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) utils.authenticationRepository.setUnlocked(false) utils.authenticationRepository.setAutoConfirmEnabled(true) - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer), "reason") assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) underTest.onShown() FakeAuthenticationRepository.DEFAULT_PIN.forEach { digit -> @@ -277,7 +277,7 @@ class PinBouncerViewModelTest : SysuiTestCase() { utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) utils.authenticationRepository.setUnlocked(false) utils.authenticationRepository.setAutoConfirmEnabled(true) - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Bouncer), "reason") assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) underTest.onShown() FakeAuthenticationRepository.DEFAULT_PIN.dropLast(1).forEach { digit -> diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/LockscreenSceneInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/LockscreenSceneInteractorTest.kt index d825c2a014649..86e56bf1e131a 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/LockscreenSceneInteractorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/LockscreenSceneInteractorTest.kt @@ -130,11 +130,11 @@ class LockscreenSceneInteractorTest : SysuiTestCase() { fun switchFromLockScreenToGone_authMethodNotSwipe_doesNotUnlockDevice() = testScope.runTest { val isUnlocked by collectLastValue(authenticationInteractor.isUnlocked) - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Lockscreen)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Lockscreen), "reason") utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) assertThat(isUnlocked).isFalse() - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Gone)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Gone), "reason") assertThat(isUnlocked).isFalse() } @@ -144,13 +144,13 @@ class LockscreenSceneInteractorTest : SysuiTestCase() { testScope.runTest { val isUnlocked by collectLastValue(authenticationInteractor.isUnlocked) runCurrent() - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Shade)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Shade), "reason") runCurrent() utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Swipe) runCurrent() assertThat(isUnlocked).isFalse() - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Gone)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Gone), "reason") assertThat(isUnlocked).isFalse() } @@ -161,7 +161,7 @@ class LockscreenSceneInteractorTest : SysuiTestCase() { val currentScene by collectLastValue(sceneInteractor.currentScene) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Swipe) runCurrent() - sceneInteractor.setCurrentScene(SceneModel(SceneKey.QuickSettings)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.QuickSettings), "reason") runCurrent() assertThat(currentScene).isEqualTo(SceneModel(SceneKey.QuickSettings)) diff --git a/packages/SystemUI/tests/src/com/android/systemui/scene/domain/interactor/SceneInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/scene/domain/interactor/SceneInteractorTest.kt index c193d830bb20f..4facc7a6a36d7 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/scene/domain/interactor/SceneInteractorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/scene/domain/interactor/SceneInteractorTest.kt @@ -52,7 +52,7 @@ class SceneInteractorTest : SysuiTestCase() { val currentScene by collectLastValue(underTest.currentScene) assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Lockscreen)) - underTest.setCurrentScene(SceneModel(SceneKey.Shade)) + underTest.setCurrentScene(SceneModel(SceneKey.Shade), "reason") assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Shade)) } @@ -79,10 +79,10 @@ class SceneInteractorTest : SysuiTestCase() { val isVisible by collectLastValue(underTest.isVisible) assertThat(isVisible).isTrue() - underTest.setVisible(false) + underTest.setVisible(false, "reason") assertThat(isVisible).isFalse() - underTest.setVisible(true) + underTest.setVisible(true, "reason") assertThat(isVisible).isTrue() } @@ -92,7 +92,7 @@ class SceneInteractorTest : SysuiTestCase() { assertThat(transitions).isNull() val initialSceneKey = underTest.currentScene.value.key - underTest.setCurrentScene(SceneModel(SceneKey.Shade)) + underTest.setCurrentScene(SceneModel(SceneKey.Shade), "reason") assertThat(transitions) .isEqualTo( SceneTransitionModel( @@ -101,7 +101,7 @@ class SceneInteractorTest : SysuiTestCase() { ) ) - underTest.setCurrentScene(SceneModel(SceneKey.QuickSettings)) + underTest.setCurrentScene(SceneModel(SceneKey.QuickSettings), "reason") assertThat(transitions) .isEqualTo( SceneTransitionModel( diff --git a/packages/SystemUI/tests/src/com/android/systemui/scene/domain/startable/SceneContainerStartableTest.kt b/packages/SystemUI/tests/src/com/android/systemui/scene/domain/startable/SceneContainerStartableTest.kt index b6bd31f43d309..6be19b99dd3b8 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/scene/domain/startable/SceneContainerStartableTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/scene/domain/startable/SceneContainerStartableTest.kt @@ -73,6 +73,7 @@ class SceneContainerStartableTest : SysuiTestCase() { featureFlags = featureFlags, sysUiState = sysUiState, displayId = Display.DEFAULT_DISPLAY, + sceneLogger = mock(), ) @Before @@ -97,7 +98,7 @@ class SceneContainerStartableTest : SysuiTestCase() { assertThat(isVisible).isFalse() - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Shade)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Shade), "reason") assertThat(isVisible).isTrue() } @@ -117,10 +118,10 @@ class SceneContainerStartableTest : SysuiTestCase() { underTest.start() assertThat(isVisible).isTrue() - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Gone)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Gone), "reason") assertThat(isVisible).isTrue() - sceneInteractor.setCurrentScene(SceneModel(SceneKey.Shade)) + sceneInteractor.setCurrentScene(SceneModel(SceneKey.Shade), "reason") assertThat(isVisible).isTrue() } @@ -326,7 +327,7 @@ class SceneContainerStartableTest : SysuiTestCase() { SceneKey.QuickSettings, ) .forEachIndexed { index, sceneKey -> - sceneInteractor.setCurrentScene(SceneModel(sceneKey)) + sceneInteractor.setCurrentScene(SceneModel(sceneKey), "reason") runCurrent() verify(sysUiState, times(index + 1)).commitUpdate(Display.DEFAULT_DISPLAY) @@ -342,7 +343,7 @@ class SceneContainerStartableTest : SysuiTestCase() { featureFlags.set(Flags.SCENE_CONTAINER, isFeatureEnabled) authenticationRepository.setUnlocked(isDeviceUnlocked) keyguardRepository.setBypassEnabled(isBypassEnabled) - initialSceneKey?.let { sceneInteractor.setCurrentScene(SceneModel(it)) } + initialSceneKey?.let { sceneInteractor.setCurrentScene(SceneModel(it), "reason") } } companion object { diff --git a/packages/SystemUI/tests/src/com/android/systemui/scene/ui/viewmodel/SceneContainerViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/scene/ui/viewmodel/SceneContainerViewModelTest.kt index 0ab98ad512eae..9f3b12bd2042f 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/scene/ui/viewmodel/SceneContainerViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/scene/ui/viewmodel/SceneContainerViewModelTest.kt @@ -52,10 +52,10 @@ class SceneContainerViewModelTest : SysuiTestCase() { val isVisible by collectLastValue(underTest.isVisible) assertThat(isVisible).isTrue() - interactor.setVisible(false) + interactor.setVisible(false, "reason") assertThat(isVisible).isFalse() - interactor.setVisible(true) + interactor.setVisible(true, "reason") assertThat(isVisible).isTrue() } diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/scene/SceneTestUtils.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/scene/SceneTestUtils.kt index 70d15a0683564..6cffb669d466f 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/scene/SceneTestUtils.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/scene/SceneTestUtils.kt @@ -92,6 +92,7 @@ class SceneTestUtils( ) } } + private val context = test.context fun fakeSceneContainerRepository( @@ -124,6 +125,7 @@ class SceneTestUtils( ): SceneInteractor { return SceneInteractor( repository = repository, + logger = mock(), ) }