diff options
26 files changed, 186 insertions, 148 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeSensors.java b/packages/SystemUI/src/com/android/systemui/doze/DozeSensors.java index 0d3503e5765c..07efbfef732b 100644 --- a/packages/SystemUI/src/com/android/systemui/doze/DozeSensors.java +++ b/packages/SystemUI/src/com/android/systemui/doze/DozeSensors.java @@ -217,7 +217,7 @@ public class DozeSensors { true /* settingDef */, true /* configured */, DozeLog.REASON_SENSOR_TAP, - false /* reports touch coordinates */, + true /* reports touch coordinates */, true /* touchscreen */, false /* ignoresSetting */, dozeParameters.singleTapUsesProx(mDevicePosture) /* requiresProx */, diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java b/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java index b70960832d32..85272a609588 100644 --- a/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java +++ b/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java @@ -323,9 +323,7 @@ public class DozeTriggers implements DozeMachine.Part { return; } if (isDoubleTap || isTap) { - if (screenX != -1 && screenY != -1) { - mDozeHost.onSlpiTap(screenX, screenY); - } + mDozeHost.onSlpiTap(screenX, screenY); gentleWakeUp(pulseReason); } else if (isPickup) { if (shouldDropPickupEvent()) { diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepository.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepository.kt index 5b71a2ed1991..9621f03f63a0 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepository.kt @@ -45,7 +45,6 @@ import com.android.systemui.keyguard.shared.model.FailedAuthenticationStatus import com.android.systemui.keyguard.shared.model.HelpAuthenticationStatus import com.android.systemui.keyguard.shared.model.SuccessAuthenticationStatus import com.android.systemui.keyguard.shared.model.TransitionState -import com.android.systemui.keyguard.shared.model.WakefulnessModel import com.android.systemui.log.FaceAuthenticationLogger import com.android.systemui.log.SessionTracker import com.android.systemui.log.table.TableLogBuffer @@ -239,9 +238,7 @@ constructor( // Clear auth status when keyguard is going away or when the user is switching or device // starts going to sleep. merge( - keyguardRepository.wakefulness.map { - WakefulnessModel.isSleepingOrStartingToSleep(it) - }, + keyguardRepository.wakefulness.map { it.isStartingToSleepOrAsleep() }, keyguardRepository.isKeyguardGoingAway, userRepository.userSwitchingInProgress ) @@ -315,9 +312,7 @@ constructor( tableLogBuffer ), logAndObserve( - keyguardRepository.wakefulness - .map { WakefulnessModel.isSleepingOrStartingToSleep(it) } - .isFalse(), + keyguardRepository.wakefulness.map { it.isStartingToSleepOrAsleep() }.isFalse(), "deviceNotSleepingOrNotStartingToSleep", tableLogBuffer ), diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardBouncerRepository.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardBouncerRepository.kt index 0b506cfa4716..7c14280a7858 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardBouncerRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardBouncerRepository.kt @@ -18,7 +18,6 @@ package com.android.systemui.keyguard.data.repository import android.os.Build import android.util.Log -import com.android.keyguard.ViewMediatorCallback import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.keyguard.shared.constants.KeyguardBouncerConstants.EXPANSION_HIDDEN @@ -104,7 +103,6 @@ interface KeyguardBouncerRepository { class KeyguardBouncerRepositoryImpl @Inject constructor( - private val viewMediatorCallback: ViewMediatorCallback, private val clock: SystemClock, @Application private val applicationScope: CoroutineScope, @BouncerLog private val buffer: TableLogBuffer, diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepository.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepository.kt index 3567d814f63e..742e53515e82 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepository.kt @@ -26,7 +26,6 @@ import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCall import com.android.systemui.common.shared.model.Position import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Main -import com.android.systemui.doze.DozeHost import com.android.systemui.doze.DozeMachine import com.android.systemui.doze.DozeTransitionCallback import com.android.systemui.doze.DozeTransitionListener @@ -105,7 +104,7 @@ interface KeyguardRepository { * returns `false`. In order to account for that, observers should also use the * [linearDozeAmount] flow to check if it's greater than `0` */ - val isDozing: Flow<Boolean> + val isDozing: StateFlow<Boolean> /** * Observable for whether the device is dreaming. @@ -133,6 +132,8 @@ interface KeyguardRepository { /** Doze state information, as it transitions */ val dozeTransitionModel: Flow<DozeTransitionModel> + val lastDozeTapToWakePosition: StateFlow<Point?> + /** Observable for the [StatusBarState] */ val statusBarState: Flow<StatusBarState> @@ -181,6 +182,10 @@ interface KeyguardRepository { /** Sets whether quick settings or quick-quick settings is visible. */ fun setQuickSettingsVisible(isVisible: Boolean) + + fun setLastDozeTapToWakePosition(position: Point) + + fun setIsDozing(isDozing: Boolean) } /** Encapsulates application state for the keyguard. */ @@ -189,7 +194,6 @@ class KeyguardRepositoryImpl @Inject constructor( statusBarStateController: StatusBarStateController, - dozeHost: DozeHost, wakefulnessLifecycle: WakefulnessLifecycle, biometricUnlockController: BiometricUnlockController, private val keyguardStateController: KeyguardStateController, @@ -333,24 +337,19 @@ constructor( awaitClose { keyguardStateController.removeCallback(callback) } } - override val isDozing: Flow<Boolean> = - conflatedCallbackFlow { - val callback = - object : DozeHost.Callback { - override fun onDozingChanged(isDozing: Boolean) { - trySendWithFailureLogging(isDozing, TAG, "updated isDozing") - } - } - dozeHost.addCallback(callback) - trySendWithFailureLogging( - statusBarStateController.isDozing, - TAG, - "initial isDozing", - ) + private val _isDozing = MutableStateFlow(statusBarStateController.isDozing) + override val isDozing: StateFlow<Boolean> = _isDozing.asStateFlow() - awaitClose { dozeHost.removeCallback(callback) } - } - .distinctUntilChanged() + override fun setIsDozing(isDozing: Boolean) { + _isDozing.value = isDozing + } + + private val _lastDozeTapToWakePosition = MutableStateFlow<Point?>(null) + override val lastDozeTapToWakePosition = _lastDozeTapToWakePosition.asStateFlow() + + override fun setLastDozeTapToWakePosition(position: Point) { + _lastDozeTapToWakePosition.value = position + } override val isDreamingWithOverlay: Flow<Boolean> = conflatedCallbackFlow { 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 a17481a9978b..482e9a3d09d7 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 @@ -24,7 +24,6 @@ import com.android.systemui.R import com.android.systemui.dagger.SysUISingleton import com.android.systemui.keyguard.shared.model.BiometricUnlockModel import com.android.systemui.keyguard.shared.model.BiometricUnlockSource -import com.android.systemui.keyguard.shared.model.WakeSleepReason import com.android.systemui.statusbar.CircleReveal import com.android.systemui.statusbar.LiftReveal import com.android.systemui.statusbar.LightRevealEffect @@ -43,7 +42,7 @@ val DEFAULT_REVEAL_EFFECT = LiftReveal /** * Encapsulates state relevant to the light reveal scrim, the view used to reveal/hide screen - * contents during transitions between AOD and lockscreen/unlocked. + * contents during transitions between DOZE or AOD and lockscreen/unlocked. */ interface LightRevealScrimRepository { @@ -64,13 +63,20 @@ constructor( ) : LightRevealScrimRepository { /** The reveal effect used if the device was locked/unlocked via the power button. */ - private val powerButtonReveal = - PowerButtonReveal( - context.resources - .getDimensionPixelSize(R.dimen.physical_power_button_center_screen_location_y) - .toFloat() + private val powerButtonRevealEffect: Flow<LightRevealEffect?> = + flowOf( + PowerButtonReveal( + context.resources + .getDimensionPixelSize(R.dimen.physical_power_button_center_screen_location_y) + .toFloat() + ) ) + private val tapRevealEffect: Flow<LightRevealEffect?> = + keyguardRepository.lastDozeTapToWakePosition.map { + it?.let { constructCircleRevealFromPoint(it) } + } + /** * Reveal effect to use for a fingerprint unlock. This is reconstructed if the fingerprint * sensor location on the screen (in pixels) changes due to configuration changes. @@ -102,18 +108,11 @@ constructor( /** The reveal effect we'll use for the next non-biometric unlock (tap, power button, etc). */ private val nonBiometricRevealEffect: Flow<LightRevealEffect?> = - keyguardRepository.wakefulness.map { wakefulnessModel -> - val wakingUpFromPowerButton = - wakefulnessModel.isWakingUpOrAwake && - wakefulnessModel.lastWakeReason == WakeSleepReason.POWER_BUTTON - val sleepingFromPowerButton = - !wakefulnessModel.isWakingUpOrAwake && - wakefulnessModel.lastSleepReason == WakeSleepReason.POWER_BUTTON - - if (wakingUpFromPowerButton || sleepingFromPowerButton) { - powerButtonReveal - } else { - LiftReveal + keyguardRepository.wakefulness.flatMapLatest { wakefulnessModel -> + when { + wakefulnessModel.isTransitioningFromPowerButton() -> powerButtonRevealEffect + wakefulnessModel.isAwakeFromTap() -> tapRevealEffect + else -> flowOf(LiftReveal) } } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/DozeInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/DozeInteractor.kt new file mode 100644 index 000000000000..2efcd0c1ffe7 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/DozeInteractor.kt @@ -0,0 +1,38 @@ +/* + * 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.keyguard.domain.interactor + +import android.graphics.Point +import com.android.systemui.dagger.SysUISingleton +import com.android.systemui.keyguard.data.repository.KeyguardRepository +import javax.inject.Inject + +@SysUISingleton +class DozeInteractor +@Inject +constructor( + private val keyguardRepository: KeyguardRepository, +) { + + fun setIsDozing(isDozing: Boolean) { + keyguardRepository.setIsDozing(isDozing) + } + + fun setLastTapToWakePosition(position: Point) { + keyguardRepository.setLastDozeTapToWakePosition(position) + } +} diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromDozingTransitionInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromDozingTransitionInteractor.kt index aca40195dbcf..323fc317ebe1 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromDozingTransitionInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromDozingTransitionInteractor.kt @@ -24,13 +24,11 @@ import com.android.systemui.keyguard.data.repository.KeyguardTransitionRepositor import com.android.systemui.keyguard.shared.model.BiometricUnlockModel.Companion.isWakeAndUnlock import com.android.systemui.keyguard.shared.model.KeyguardState import com.android.systemui.keyguard.shared.model.TransitionInfo -import com.android.systemui.keyguard.shared.model.WakefulnessModel.Companion.isWakingOrStartingToWake import com.android.systemui.util.kotlin.sample import javax.inject.Inject import kotlin.time.Duration import kotlin.time.Duration.Companion.milliseconds import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch @SysUISingleton @@ -54,7 +52,7 @@ constructor( .sample(keyguardTransitionInteractor.startedKeyguardTransitionStep, ::Pair) .collect { (wakefulnessModel, lastStartedTransition) -> if ( - isWakingOrStartingToWake(wakefulnessModel) && + wakefulnessModel.isStartingToWake() && lastStartedTransition.to == KeyguardState.DOZING ) { keyguardTransitionRepository.startTransition( diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractor.kt index 1ac0c526f975..3cf9a9ec5a9c 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractor.kt @@ -33,7 +33,6 @@ import com.android.systemui.keyguard.shared.model.DozeStateModel.Companion.isDoz import com.android.systemui.keyguard.shared.model.DozeTransitionModel import com.android.systemui.keyguard.shared.model.StatusBarState import com.android.systemui.keyguard.shared.model.WakefulnessModel -import com.android.systemui.keyguard.shared.model.WakefulnessModel.Companion.isWakingOrStartingToWake import com.android.systemui.statusbar.CommandQueue import com.android.systemui.util.kotlin.sample import javax.inject.Inject @@ -108,18 +107,12 @@ constructor( */ val isAbleToDream: Flow<Boolean> = merge(isDreaming, isDreamingWithOverlay) - .combine( - dozeTransitionModel, - { isDreaming, dozeTransitionModel -> - isDreaming && isDozeOff(dozeTransitionModel.to) - } - ) - .sample( - wakefulnessModel, - { isAbleToDream, wakefulnessModel -> - isAbleToDream && isWakingOrStartingToWake(wakefulnessModel) - } - ) + .combine(dozeTransitionModel) { isDreaming, dozeTransitionModel -> + isDreaming && isDozeOff(dozeTransitionModel.to) + } + .sample(wakefulnessModel) { isAbleToDream, wakefulnessModel -> + isAbleToDream && wakefulnessModel.isStartingToWake() + } .flatMapLatest { isAbleToDream -> flow { delay(50) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/shared/model/WakeSleepReason.kt b/packages/SystemUI/src/com/android/systemui/keyguard/shared/model/WakeSleepReason.kt index b32597d5cff0..51ce7ff45182 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/shared/model/WakeSleepReason.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/shared/model/WakeSleepReason.kt @@ -23,6 +23,9 @@ enum class WakeSleepReason { /** The physical power button was pressed to wake up or sleep the device. */ POWER_BUTTON, + /** The user has taped or double tapped to wake the screen */ + TAP, + /** Something else happened to wake up or sleep the device. */ OTHER; @@ -30,6 +33,7 @@ enum class WakeSleepReason { fun fromPowerManagerWakeReason(reason: Int): WakeSleepReason { return when (reason) { PowerManager.WAKE_REASON_POWER_BUTTON -> POWER_BUTTON + PowerManager.WAKE_REASON_TAP -> TAP else -> OTHER } } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/shared/model/WakefulnessModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/shared/model/WakefulnessModel.kt index 03dee0045c10..7ca90ba63fda 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/shared/model/WakefulnessModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/shared/model/WakefulnessModel.kt @@ -20,26 +20,31 @@ import com.android.systemui.keyguard.WakefulnessLifecycle /** Model device wakefulness states. */ data class WakefulnessModel( val state: WakefulnessState, - val isWakingUpOrAwake: Boolean, val lastWakeReason: WakeSleepReason, val lastSleepReason: WakeSleepReason, ) { - companion object { - fun isSleepingOrStartingToSleep(model: WakefulnessModel): Boolean { - return model.state == WakefulnessState.ASLEEP || - model.state == WakefulnessState.STARTING_TO_SLEEP - } + fun isStartingToWake() = state == WakefulnessState.STARTING_TO_WAKE - fun isWakingOrStartingToWake(model: WakefulnessModel): Boolean { - return model.state == WakefulnessState.AWAKE || - model.state == WakefulnessState.STARTING_TO_WAKE - } + fun isStartingToSleep() = state == WakefulnessState.STARTING_TO_SLEEP + + fun isStartingToSleepOrAsleep() = isStartingToSleep() || state == WakefulnessState.ASLEEP + + fun isStartingToSleepFromPowerButton() = + isStartingToSleep() && lastWakeReason == WakeSleepReason.POWER_BUTTON + fun isWakingFromPowerButton() = + isStartingToWake() && lastWakeReason == WakeSleepReason.POWER_BUTTON + + fun isTransitioningFromPowerButton() = + isStartingToSleepFromPowerButton() || isWakingFromPowerButton() + + fun isAwakeFromTap() = + state == WakefulnessState.STARTING_TO_WAKE && lastWakeReason == WakeSleepReason.TAP + + companion object { fun fromWakefulnessLifecycle(wakefulnessLifecycle: WakefulnessLifecycle): WakefulnessModel { return WakefulnessModel( WakefulnessState.fromWakefulnessLifecycleInt(wakefulnessLifecycle.wakefulness), - wakefulnessLifecycle.wakefulness == WakefulnessLifecycle.WAKEFULNESS_WAKING || - wakefulnessLifecycle.wakefulness == WakefulnessLifecycle.WAKEFULNESS_AWAKE, WakeSleepReason.fromPowerManagerWakeReason(wakefulnessLifecycle.lastWakeReason), WakeSleepReason.fromPowerManagerSleepReason(wakefulnessLifecycle.lastSleepReason), ) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeServiceHost.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeServiceHost.java index 618120d406cb..7312db6595e5 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeServiceHost.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeServiceHost.java @@ -20,6 +20,7 @@ import static com.android.systemui.keyguard.WakefulnessLifecycle.WAKEFULNESS_AWA import static com.android.systemui.keyguard.WakefulnessLifecycle.WAKEFULNESS_WAKING; import android.annotation.NonNull; +import android.graphics.Point; import android.os.Bundle; import android.os.PowerManager; import android.os.SystemClock; @@ -38,6 +39,7 @@ import com.android.systemui.doze.DozeLog; import com.android.systemui.doze.DozeReceiver; import com.android.systemui.keyguard.WakefulnessLifecycle; import com.android.systemui.keyguard.domain.interactor.BurnInInteractor; +import com.android.systemui.keyguard.domain.interactor.DozeInteractor; import com.android.systemui.shade.NotificationShadeWindowViewController; import com.android.systemui.shade.ShadeViewController; import com.android.systemui.statusbar.NotificationShadeWindowController; @@ -99,6 +101,7 @@ public final class DozeServiceHost implements DozeHost { private CentralSurfaces mCentralSurfaces; private boolean mAlwaysOnSuppressed; private boolean mPulsePending; + private DozeInteractor mDozeInteractor; @Inject public DozeServiceHost(DozeLog dozeLog, PowerManager powerManager, @@ -115,6 +118,7 @@ public final class DozeServiceHost implements DozeHost { NotificationWakeUpCoordinator notificationWakeUpCoordinator, AuthController authController, NotificationIconAreaController notificationIconAreaController, + DozeInteractor dozeInteractor, BurnInInteractor burnInInteractor) { super(); mDozeLog = dozeLog; @@ -136,6 +140,7 @@ public final class DozeServiceHost implements DozeHost { mNotificationIconAreaController = notificationIconAreaController; mBurnInInteractor = burnInInteractor; mHeadsUpManagerPhone.addListener(mOnHeadsUpChangedListener); + mDozeInteractor = dozeInteractor; } // TODO: we should try to not pass status bar in here if we can avoid it. @@ -226,6 +231,7 @@ public final class DozeServiceHost implements DozeHost { for (Callback callback : mCallbacks) { callback.onDozingChanged(dozing); } + mDozeInteractor.setIsDozing(dozing); mStatusBarStateController.setIsDozing(dozing); } @@ -360,7 +366,14 @@ public final class DozeServiceHost implements DozeHost { @Override public void onSlpiTap(float screenX, float screenY) { - if (screenX > 0 && screenY > 0 && mAmbientIndicationContainer != null + if (screenX < 0 || screenY < 0) return; + dispatchTouchEventToAmbientIndicationContainer(screenX, screenY); + + mDozeInteractor.setLastTapToWakePosition(new Point((int) screenX, (int) screenY)); + } + + private void dispatchTouchEventToAmbientIndicationContainer(float screenX, float screenY) { + if (mAmbientIndicationContainer != null && mAmbientIndicationContainer.getVisibility() == View.VISIBLE) { int[] locationOnScreen = new int[2]; mAmbientIndicationContainer.getLocationOnScreen(locationOnScreen); diff --git a/packages/SystemUI/tests/src/com/android/keyguard/ClockEventControllerTest.kt b/packages/SystemUI/tests/src/com/android/keyguard/ClockEventControllerTest.kt index 19d5278932c2..3f1560bc5fce 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/ClockEventControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/keyguard/ClockEventControllerTest.kt @@ -136,7 +136,7 @@ class ClockEventControllerTest : SysuiTestCase() { runBlocking(IMMEDIATE) { underTest.registerListeners(parentView) - repository.setDozing(true) + repository.setIsDozing(true) repository.setDozeAmount(1f) } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsKeyguardViewLegacyControllerWithCoroutinesTest.kt b/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsKeyguardViewLegacyControllerWithCoroutinesTest.kt index 9e600f549e0f..7531cb4a91f7 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsKeyguardViewLegacyControllerWithCoroutinesTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsKeyguardViewLegacyControllerWithCoroutinesTest.kt @@ -75,7 +75,6 @@ class UdfpsKeyguardViewLegacyControllerWithCoroutinesTest : MockitoAnnotations.initMocks(this) keyguardBouncerRepository = KeyguardBouncerRepositoryImpl( - mock(com.android.keyguard.ViewMediatorCallback::class.java), FakeSystemClock(), testScope.backgroundScope, bouncerLogger, diff --git a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java index 3552399586a3..494e230947b3 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java @@ -301,6 +301,22 @@ public class DozeTriggersTest extends SysuiTestCase { } @Test + public void test_onSensor_tap() { + mTriggers.onSensor(DozeLog.REASON_SENSOR_TAP, 100, 200, null); + + verify(mHost).onSlpiTap(100, 200); + verify(mMachine).wakeUp(DozeLog.REASON_SENSOR_TAP); + } + + @Test + public void test_onSensor_double_tap() { + mTriggers.onSensor(DozeLog.REASON_SENSOR_DOUBLE_TAP, 100, 200, null); + + verify(mHost).onSlpiTap(100, 200); + verify(mMachine).wakeUp(DozeLog.REASON_SENSOR_DOUBLE_TAP); + } + + @Test public void testPickupGestureDroppedKeyguardOccluded() { // GIVEN device is in doze (screen blank, but running doze sensors) when(mMachine.getState()).thenReturn(DozeMachine.State.DOZE); diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepositoryTest.kt index d73c2c76272e..e61620beeff3 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepositoryTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepositoryTest.kt @@ -530,7 +530,6 @@ class DeviceEntryFaceAuthRepositoryTest : SysuiTestCase() { keyguardRepository.setWakefulnessModel( WakefulnessModel( state = WakefulnessState.STARTING_TO_SLEEP, - isWakingUpOrAwake = false, lastWakeReason = WakeSleepReason.OTHER, lastSleepReason = WakeSleepReason.OTHER, ) @@ -545,7 +544,6 @@ class DeviceEntryFaceAuthRepositoryTest : SysuiTestCase() { keyguardRepository.setWakefulnessModel( WakefulnessModel( state = WakefulnessState.ASLEEP, - isWakingUpOrAwake = false, lastWakeReason = WakeSleepReason.OTHER, lastSleepReason = WakeSleepReason.OTHER, ) @@ -682,7 +680,6 @@ class DeviceEntryFaceAuthRepositoryTest : SysuiTestCase() { keyguardRepository.setWakefulnessModel( WakefulnessModel( WakefulnessState.STARTING_TO_SLEEP, - isWakingUpOrAwake = false, lastWakeReason = WakeSleepReason.POWER_BUTTON, lastSleepReason = WakeSleepReason.POWER_BUTTON ) @@ -708,7 +705,6 @@ class DeviceEntryFaceAuthRepositoryTest : SysuiTestCase() { keyguardRepository.setWakefulnessModel( WakefulnessModel( WakefulnessState.ASLEEP, - isWakingUpOrAwake = false, lastWakeReason = WakeSleepReason.POWER_BUTTON, lastSleepReason = WakeSleepReason.POWER_BUTTON ) @@ -765,7 +761,6 @@ class DeviceEntryFaceAuthRepositoryTest : SysuiTestCase() { keyguardRepository.setWakefulnessModel( WakefulnessModel( state = WakefulnessState.STARTING_TO_SLEEP, - isWakingUpOrAwake = false, lastWakeReason = WakeSleepReason.OTHER, lastSleepReason = WakeSleepReason.OTHER, ) @@ -1006,7 +1001,6 @@ class DeviceEntryFaceAuthRepositoryTest : SysuiTestCase() { keyguardRepository.setWakefulnessModel( WakefulnessModel( WakefulnessState.STARTING_TO_WAKE, - true, WakeSleepReason.OTHER, WakeSleepReason.OTHER ) diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardBouncerRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardBouncerRepositoryTest.kt index 657ee20475d8..b3104b7de4b9 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardBouncerRepositoryTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardBouncerRepositoryTest.kt @@ -50,7 +50,6 @@ class KeyguardBouncerRepositoryTest : SysuiTestCase() { val testCoroutineScope = TestCoroutineScope() underTest = KeyguardBouncerRepositoryImpl( - viewMediatorCallback, systemClock, testCoroutineScope, bouncerLogger, diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardRepositoryImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardRepositoryImplTest.kt index 4b4c7e9d39f3..4b797cb1ba46 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardRepositoryImplTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardRepositoryImplTest.kt @@ -27,7 +27,6 @@ import com.android.systemui.SysuiTestCase import com.android.systemui.biometrics.AuthController import com.android.systemui.common.shared.model.Position import com.android.systemui.coroutines.collectLastValue -import com.android.systemui.doze.DozeHost import com.android.systemui.doze.DozeMachine import com.android.systemui.doze.DozeTransitionCallback import com.android.systemui.doze.DozeTransitionListener @@ -69,7 +68,6 @@ import org.mockito.MockitoAnnotations class KeyguardRepositoryImplTest : SysuiTestCase() { @Mock private lateinit var statusBarStateController: StatusBarStateController - @Mock private lateinit var dozeHost: DozeHost @Mock private lateinit var keyguardStateController: KeyguardStateController @Mock private lateinit var wakefulnessLifecycle: WakefulnessLifecycle @Mock private lateinit var biometricUnlockController: BiometricUnlockController @@ -91,7 +89,6 @@ class KeyguardRepositoryImplTest : SysuiTestCase() { underTest = KeyguardRepositoryImpl( statusBarStateController, - dozeHost, wakefulnessLifecycle, biometricUnlockController, keyguardStateController, @@ -262,42 +259,21 @@ class KeyguardRepositoryImplTest : SysuiTestCase() { @Test fun isDozing() = testScope.runTest { - var latest: Boolean? = null - val job = underTest.isDozing.onEach { latest = it }.launchIn(this) - - runCurrent() - val captor = argumentCaptor<DozeHost.Callback>() - verify(dozeHost).addCallback(captor.capture()) - - captor.value.onDozingChanged(true) - runCurrent() - assertThat(latest).isTrue() + underTest.setIsDozing(true) + assertThat(underTest.isDozing.value).isEqualTo(true) - captor.value.onDozingChanged(false) - runCurrent() - assertThat(latest).isFalse() - - job.cancel() - runCurrent() - verify(dozeHost).removeCallback(captor.value) + underTest.setIsDozing(false) + assertThat(underTest.isDozing.value).isEqualTo(false) } @Test fun isDozing_startsWithCorrectInitialValueForIsDozing() = testScope.runTest { - var latest: Boolean? = null + assertThat(underTest.lastDozeTapToWakePosition.value).isEqualTo(null) - whenever(statusBarStateController.isDozing).thenReturn(true) - var job = underTest.isDozing.onEach { latest = it }.launchIn(this) - runCurrent() - assertThat(latest).isTrue() - job.cancel() - - whenever(statusBarStateController.isDozing).thenReturn(false) - job = underTest.isDozing.onEach { latest = it }.launchIn(this) - runCurrent() - assertThat(latest).isFalse() - job.cancel() + val expectedPoint = Point(100, 200) + underTest.setLastDozeTapToWakePosition(expectedPoint) + assertThat(underTest.lastDozeTapToWakePosition.value).isEqualTo(expectedPoint) } @Test diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/AlternateBouncerInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/AlternateBouncerInteractorTest.kt index 2180a8f19636..ca6b8d51e9e6 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/AlternateBouncerInteractorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/AlternateBouncerInteractorTest.kt @@ -18,7 +18,6 @@ package com.android.systemui.keyguard.domain.interactor import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest -import com.android.keyguard.ViewMediatorCallback import com.android.systemui.RoboPilotTest import com.android.systemui.SysuiTestCase import com.android.systemui.keyguard.data.repository.FakeBiometricSettingsRepository @@ -39,7 +38,6 @@ import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mock -import org.mockito.Mockito.mock import org.mockito.MockitoAnnotations @OptIn(ExperimentalCoroutinesApi::class) @@ -62,7 +60,6 @@ class AlternateBouncerInteractorTest : SysuiTestCase() { MockitoAnnotations.initMocks(this) bouncerRepository = KeyguardBouncerRepositoryImpl( - mock(ViewMediatorCallback::class.java), FakeSystemClock(), TestCoroutineScope(), bouncerLogger, diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardQuickAffordanceInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardQuickAffordanceInteractorTest.kt index 4b7c641abf1e..3336e3b21180 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardQuickAffordanceInteractorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardQuickAffordanceInteractorTest.kt @@ -313,7 +313,7 @@ class KeyguardQuickAffordanceInteractorTest : SysuiTestCase() { @Test fun quickAffordance_bottomStartAffordanceHiddenWhileDozing() = testScope.runTest { - repository.setDozing(true) + repository.setIsDozing(true) homeControls.setState( KeyguardQuickAffordanceConfig.LockScreenState.Visible( icon = ICON, @@ -348,7 +348,7 @@ class KeyguardQuickAffordanceInteractorTest : SysuiTestCase() { fun quickAffordanceAlwaysVisible_evenWhenLockScreenNotShowingAndDozing() = testScope.runTest { repository.setKeyguardShowing(false) - repository.setDozing(true) + repository.setIsDozing(true) val configKey = BuiltInKeyguardQuickAffordanceKeys.HOME_CONTROLS homeControls.setState( KeyguardQuickAffordanceConfig.LockScreenState.Visible( @@ -623,7 +623,7 @@ class KeyguardQuickAffordanceInteractorTest : SysuiTestCase() { testScope.runTest { featureFlags.set(Flags.CUSTOMIZABLE_LOCK_SCREEN_QUICK_AFFORDANCES, true) dockManager.setIsDocked(false) - val firstUseLongPress by collectLastValue (underTest.useLongPress()) + val firstUseLongPress by collectLastValue(underTest.useLongPress()) runCurrent() assertThat(firstUseLongPress).isTrue() diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionScenariosTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionScenariosTest.kt index 344df0acc409..603f199b468b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionScenariosTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionScenariosTest.kt @@ -871,7 +871,6 @@ class KeyguardTransitionScenariosTest : SysuiTestCase() { private fun startingToWake() = WakefulnessModel( WakefulnessState.STARTING_TO_WAKE, - true, WakeSleepReason.OTHER, WakeSleepReason.OTHER ) @@ -879,7 +878,6 @@ class KeyguardTransitionScenariosTest : SysuiTestCase() { private fun startingToSleep() = WakefulnessModel( WakefulnessState.STARTING_TO_SLEEP, - true, WakeSleepReason.OTHER, WakeSleepReason.OTHER ) diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBottomAreaViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBottomAreaViewModelTest.kt index 5eec8a88dd14..69d43af60321 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBottomAreaViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBottomAreaViewModelTest.kt @@ -505,9 +505,9 @@ class KeyguardBottomAreaViewModelTest : SysuiTestCase() { val value = collectLastValue(underTest.isOverlayContainerVisible) assertThat(value()).isTrue() - repository.setDozing(true) + repository.setIsDozing(true) assertThat(value()).isFalse() - repository.setDozing(false) + repository.setIsDozing(false) assertThat(value()).isTrue() } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/KeyguardCoordinatorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/KeyguardCoordinatorTest.kt index c3f51233f59a..2fbe87158eba 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/KeyguardCoordinatorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/KeyguardCoordinatorTest.kt @@ -327,7 +327,7 @@ class KeyguardCoordinatorTest : SysuiTestCase() { fun unseenNotificationIsMarkedAsSeenWhenKeyguardGoesAway() { // GIVEN: Keyguard is showing, not dozing, unseen notification is present keyguardRepository.setKeyguardShowing(true) - keyguardRepository.setDozing(false) + keyguardRepository.setIsDozing(false) runKeyguardCoordinatorTest { val fakeEntry = NotificationEntryBuilder().build() collectionListener.onEntryAdded(fakeEntry) diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/DozeServiceHostTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/DozeServiceHostTest.java index 163369f0412f..57037e0c9c63 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/DozeServiceHostTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/DozeServiceHostTest.java @@ -25,8 +25,10 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; +import android.graphics.Point; import android.os.PowerManager; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper.RunWithLooper; @@ -42,6 +44,7 @@ import com.android.systemui.doze.DozeHost; import com.android.systemui.doze.DozeLog; import com.android.systemui.keyguard.WakefulnessLifecycle; import com.android.systemui.keyguard.domain.interactor.BurnInInteractor; +import com.android.systemui.keyguard.domain.interactor.DozeInteractor; import com.android.systemui.shade.NotificationShadeWindowViewController; import com.android.systemui.shade.ShadeViewController; import com.android.systemui.statusbar.NotificationShadeWindowController; @@ -95,6 +98,7 @@ public class DozeServiceHostTest extends SysuiTestCase { @Mock private DozeHost.Callback mCallback; @Mock private BurnInInteractor mBurnInInteractor; + @Mock private DozeInteractor mDozeInteractor; @Before public void setup() { MockitoAnnotations.initMocks(this); @@ -104,7 +108,7 @@ public class DozeServiceHostTest extends SysuiTestCase { () -> mAssistManager, mDozeScrimController, mKeyguardUpdateMonitor, mPulseExpansionHandler, mNotificationShadeWindowController, mNotificationWakeUpCoordinator, - mAuthController, mNotificationIconAreaController, + mAuthController, mNotificationIconAreaController, mDozeInteractor, mBurnInInteractor); mDozeServiceHost.initialize( @@ -216,6 +220,19 @@ public class DozeServiceHostTest extends SysuiTestCase { assertFalse(mDozeServiceHost.isPulsePending()); verify(mDozeScrimController).pulseOutNow(); } + + @Test + public void onSlpiTap_calls_DozeInteractor() { + mDozeServiceHost.onSlpiTap(100, 200); + verify(mDozeInteractor).setLastTapToWakePosition(new Point(100, 200)); + } + + @Test + public void onSlpiTap_doesnt_pass_negative_values() { + mDozeServiceHost.onSlpiTap(-1, 200); + mDozeServiceHost.onSlpiTap(100, -2); + verifyZeroInteractions(mDozeInteractor); + } @Test public void dozeTimeTickSentTBurnInInteractor() { // WHEN dozeTimeTick diff --git a/packages/SystemUI/tests/src/com/android/systemui/unfold/FoldAodAnimationControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/unfold/FoldAodAnimationControllerTest.kt index 62985060e7d4..d9ee08157c84 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/unfold/FoldAodAnimationControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/unfold/FoldAodAnimationControllerTest.kt @@ -146,7 +146,7 @@ class FoldAodAnimationControllerTest : SysuiTestCase() { fun onFolded_aodDisabled_doesNotLogLatency() = runBlocking(IMMEDIATE) { val job = underTest.listenForDozing(this) - keyguardRepository.setDozing(true) + keyguardRepository.setIsDozing(true) setAodEnabled(enabled = false) yield() @@ -163,7 +163,7 @@ class FoldAodAnimationControllerTest : SysuiTestCase() { fun onFolded_aodEnabled_logsLatency() = runBlocking(IMMEDIATE) { val job = underTest.listenForDozing(this) - keyguardRepository.setDozing(true) + keyguardRepository.setIsDozing(true) setAodEnabled(enabled = true) yield() @@ -181,7 +181,7 @@ class FoldAodAnimationControllerTest : SysuiTestCase() { fun onFolded_onScreenTurningOnInvokedTwice_doesNotLogLatency() = runBlocking(IMMEDIATE) { val job = underTest.listenForDozing(this) - keyguardRepository.setDozing(true) + keyguardRepository.setIsDozing(true) setAodEnabled(enabled = true) yield() @@ -203,7 +203,7 @@ class FoldAodAnimationControllerTest : SysuiTestCase() { fun onFolded_onScreenTurningOnWithoutDozingThenWithDozing_doesNotLogLatency() = runBlocking(IMMEDIATE) { val job = underTest.listenForDozing(this) - keyguardRepository.setDozing(false) + keyguardRepository.setIsDozing(false) setAodEnabled(enabled = true) yield() @@ -214,7 +214,7 @@ class FoldAodAnimationControllerTest : SysuiTestCase() { // Now enable dozing and trigger a second run through the aod animation code. It should // not rerun the animation - keyguardRepository.setDozing(true) + keyguardRepository.setIsDozing(true) yield() simulateScreenTurningOn() @@ -228,7 +228,7 @@ class FoldAodAnimationControllerTest : SysuiTestCase() { fun onFolded_animationCancelled_doesNotLogLatency() = runBlocking(IMMEDIATE) { val job = underTest.listenForDozing(this) - keyguardRepository.setDozing(true) + keyguardRepository.setIsDozing(true) setAodEnabled(enabled = true) yield() diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/FakeKeyguardRepository.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/FakeKeyguardRepository.kt index d4115900850f..fd8c4b81063d 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/FakeKeyguardRepository.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/FakeKeyguardRepository.kt @@ -54,7 +54,10 @@ class FakeKeyguardRepository : KeyguardRepository { override val isKeyguardOccluded: Flow<Boolean> = _isKeyguardOccluded private val _isDozing = MutableStateFlow(false) - override val isDozing: Flow<Boolean> = _isDozing + override val isDozing: StateFlow<Boolean> = _isDozing + + private val _lastDozeTapToWakePosition = MutableStateFlow<Point?>(null) + override val lastDozeTapToWakePosition = _lastDozeTapToWakePosition.asStateFlow() private val _isAodAvailable = MutableStateFlow(false) override val isAodAvailable: Flow<Boolean> = _isAodAvailable @@ -76,12 +79,7 @@ class FakeKeyguardRepository : KeyguardRepository { private val _wakefulnessModel = MutableStateFlow( - WakefulnessModel( - WakefulnessState.ASLEEP, - false, - WakeSleepReason.OTHER, - WakeSleepReason.OTHER - ) + WakefulnessModel(WakefulnessState.ASLEEP, WakeSleepReason.OTHER, WakeSleepReason.OTHER) ) override val wakefulness: Flow<WakefulnessModel> = _wakefulnessModel @@ -137,10 +135,14 @@ class FakeKeyguardRepository : KeyguardRepository { _isKeyguardOccluded.value = isOccluded } - fun setDozing(isDozing: Boolean) { + override fun setIsDozing(isDozing: Boolean) { _isDozing.value = isDozing } + override fun setLastDozeTapToWakePosition(position: Point) { + _lastDozeTapToWakePosition.value = position + } + fun setAodAvailable(isAodAvailable: Boolean) { _isAodAvailable.value = isAodAvailable } |