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

Commit dfe2bc46 authored by András Kurucz's avatar András Kurucz
Browse files

Fix Notification dozing for Flexiglass

 - Wire in the NotificationWakeUpCoordinator, because it was turned off
   with NPVC.
 - Set NSSL#dozing from the KeyguardInteractor, because it was turned
   off with NPVC.
 - Use SceneInteractor to determine if we can move to dozing from the
   DozeServiceHost, because the previous signal from StatusBarController is broken.

Fixes: 332556393
Test: check how notifications are displayed while dozing or pulsing.
Flag: ACONFIG com.android.systemui.scene_container DEVELOPMENT
Change-Id: Ia365ee715acd671e89e94761602fe4300bcab6cd
parent 1e804e54
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.spy
import org.mockito.Mockito.verify

@OptIn(ExperimentalCoroutinesApi::class)
@@ -69,6 +70,7 @@ class SideFpsProgressBarViewModelTest : SysuiTestCase() {
    private val kosmos = testKosmos()
    private lateinit var underTest: SideFpsProgressBarViewModel
    private val testScope = kosmos.testScope
    private val dozeServiceHost = spy(kosmos.dozeServiceHost)
    private lateinit var mTestableLooper: TestableLooper

    @Before
@@ -175,7 +177,7 @@ class SideFpsProgressBarViewModelTest : SysuiTestCase() {

            runCurrent()

            verify(kosmos.dozeServiceHost).fireSideFpsAcquisitionStarted()
            verify(dozeServiceHost).fireSideFpsAcquisitionStarted()
        }

    private fun createViewModel() =
@@ -184,7 +186,7 @@ class SideFpsProgressBarViewModelTest : SysuiTestCase() {
            kosmos.biometricStatusInteractor,
            kosmos.deviceEntryFingerprintAuthInteractor,
            kosmos.sideFpsSensorInteractor,
            kosmos.dozeServiceHost,
            dozeServiceHost,
            kosmos.keyguardInteractor,
            kosmos.displayStateInteractor,
            kosmos.testDispatcher,
+94 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.
 */

@file:OptIn(ExperimentalCoroutinesApi::class)

package com.android.systemui.statusbar.phone

import android.testing.TestableLooper.RunWithLooper
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.doze.DozeHost
import com.android.systemui.flags.EnableSceneContainer
import com.android.systemui.keyguard.domain.interactor.keyguardInteractor
import com.android.systemui.kosmos.testScope
import com.android.systemui.scene.data.repository.sceneContainerRepository
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.testKosmos
import com.android.systemui.util.mockito.mock
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.verify

@SmallTest
@RunWithLooper(setAsMainLooper = true)
@RunWith(AndroidJUnit4::class)
class DozeServiceHostCoroutinesTest : SysuiTestCase() {
    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope

    private val sceneContainerRepository = kosmos.sceneContainerRepository
    private val keyguardInteractor = kosmos.keyguardInteractor

    val underTest =
        kosmos.dozeServiceHost.apply {
            initialize(
                /* centralSurfaces = */ mock(),
                /* statusBarKeyguardViewManager = */ mock(),
                /* notificationShadeWindowViewController = */ mock(),
                /* ambientIndicationContainer = */ mock(),
            )
        }

    @Test
    @EnableSceneContainer
    fun startStopDozing() =
        testScope.runTest {
            val isDozing by collectLastValue(keyguardInteractor.isDozing)

            // GIVEN a callback is set
            val callback: DozeHost.Callback = mock()
            underTest.addCallback(callback)
            // AND we are on the lock screen
            sceneContainerRepository.changeScene(Scenes.Lockscreen)
            // AND dozing is not requested yet
            assertThat(underTest.dozingRequested).isFalse()

            // WHEN dozing started
            underTest.startDozing()
            runCurrent()

            // THEN isDozing is set to true
            assertThat(isDozing).isTrue()
            assertThat(underTest.dozingRequested).isTrue()
            verify(callback).onDozingChanged(true)

            // WHEN dozing stopped
            underTest.stopDozing()
            runCurrent()

            // THEN isDozing is set to false
            assertThat(isDozing).isFalse()
            assertThat(underTest.dozingRequested).isFalse()
            verify(callback).onDozingChanged(false)
        }
}
+3 −4
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ import com.android.systemui.assist.AssistManager;
import com.android.systemui.biometrics.AuthController;
import com.android.systemui.doze.DozeHost;
import com.android.systemui.doze.DozeLog;
import com.android.systemui.flags.FakeFeatureFlagsClassic;
import com.android.systemui.flags.DisableSceneContainer;
import com.android.systemui.keyguard.WakefulnessLifecycle;
import com.android.systemui.keyguard.domain.interactor.DozeInteractor;
import com.android.systemui.shade.NotificationShadeWindowViewController;
@@ -98,13 +98,11 @@ public class DozeServiceHostTest extends SysuiTestCase {
    @Mock private DozeHost.Callback mCallback;
    @Mock private DozeInteractor mDozeInteractor;

    private final FakeFeatureFlagsClassic mFeatureFlags = new FakeFeatureFlagsClassic();

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        mDozeServiceHost = new DozeServiceHost(mDozeLog, mPowerManager, mWakefullnessLifecycle,
                mStatusBarStateController, mDeviceProvisionedController, mFeatureFlags,
                mStatusBarStateController, mDeviceProvisionedController,
                mHeadsUpManager, mBatteryController, mScrimController,
                () -> mBiometricUnlockController, () -> mAssistManager, mDozeScrimController,
                mKeyguardUpdateMonitor, mPulseExpansionHandler, mNotificationShadeWindowController,
@@ -119,6 +117,7 @@ public class DozeServiceHostTest extends SysuiTestCase {
    }

    @Test
    @DisableSceneContainer
    public void testStartStopDozing() {
        mDozeServiceHost.addCallback(mCallback);
        when(mStatusBarStateController.getState()).thenReturn(StatusBarState.KEYGUARD);
+13 −0
Original line number Diff line number Diff line
@@ -19,6 +19,10 @@ 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 com.android.systemui.scene.domain.interactor.SceneInteractor
import com.android.systemui.scene.shared.flag.SceneContainerFlag
import com.android.systemui.scene.shared.model.Scenes
import dagger.Lazy
import javax.inject.Inject

@SysUISingleton
@@ -26,7 +30,16 @@ class DozeInteractor
@Inject
constructor(
    private val keyguardRepository: KeyguardRepository,
    // TODO(b/336364825) Remove Lazy when SceneContainerFlag is released -
    // while the flag is off, creating this object too early results in a crash
    private val sceneInteractor: Lazy<SceneInteractor>,
) {
    fun canDozeFromCurrentScene(): Boolean {
        if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) {
            return false
        }
        return sceneInteractor.get().currentScene.value == Scenes.Lockscreen
    }

    fun setAodAvailable(value: Boolean) {
        keyguardRepository.setAodAvailable(value)
+2 −1
Original line number Diff line number Diff line
@@ -4385,7 +4385,8 @@ public class NotificationStackScrollLayout
    /**
     * See {@link AmbientState#setDozing}.
     */
    public void setDozing(boolean dozing, boolean animate) {
    @Override
    public void setDozing(boolean dozing) {
        if (mAmbientState.isDozing() == dozing) {
            return;
        }
Loading