Loading packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/homecontrols/HomeControlsComponentInteractorKosmos.kt +2 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ package com.android.systemui.dreams.homecontrols import android.os.powerManager import android.service.dream.dreamManager import com.android.systemui.common.domain.interactor.packageChangeInteractor import com.android.systemui.controls.dagger.ControlsComponent Loading @@ -37,6 +38,7 @@ val Kosmos.homeControlsComponentInteractor by userRepository = fakeUserRepository, bgScope = applicationCoroutineScope, systemClock = fakeSystemClock, powerManager = powerManager, dreamManager = dreamManager, packageChangeInteractor = packageChangeInteractor, ) Loading packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/homecontrols/HomeControlsComponentInteractorTest.kt +25 −2 Original line number Diff line number Diff line Loading @@ -20,7 +20,9 @@ import android.content.Context import android.content.pm.ApplicationInfo import android.content.pm.ServiceInfo import android.content.pm.UserInfo import android.os.PowerManager import android.os.UserHandle import android.os.powerManager import android.service.dream.dreamManager import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest Loading Loading @@ -50,6 +52,8 @@ import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.ArgumentMatchers.anyInt import org.mockito.Mockito.anyLong import org.mockito.Mockito.never import org.mockito.Mockito.verify Loading Loading @@ -196,7 +200,7 @@ class HomeControlsComponentInteractorTest : SysuiTestCase() { ) fakeSystemClock.advanceTime(MAX_UPDATE_CORRELATION_DELAY.inWholeMilliseconds) // Task fragment becomes empty as a result of the update. underTest.onTaskFragmentEmpty() underTest.onDreamEndUnexpectedly() runCurrent() verify(dreamManager, never()).startDream() Loading Loading @@ -240,7 +244,7 @@ class HomeControlsComponentInteractorTest : SysuiTestCase() { ) fakeSystemClock.advanceTime(MAX_UPDATE_CORRELATION_DELAY.inWholeMilliseconds + 100) // Task fragment becomes empty as a result of the update. underTest.onTaskFragmentEmpty() underTest.onDreamEndUnexpectedly() runCurrent() verify(dreamManager, never()).startDream() Loading @@ -258,6 +262,25 @@ class HomeControlsComponentInteractorTest : SysuiTestCase() { } } @Test fun testDreamUnexpectedlyEnds_triggersUserActivity() = with(kosmos) { testScope.runTest { fakeSystemClock.setUptimeMillis(100000L) verify(powerManager, never()).userActivity(anyLong(), anyInt(), anyInt()) // Dream ends unexpectedly underTest.onDreamEndUnexpectedly() verify(powerManager) .userActivity( 100000L, PowerManager.USER_ACTIVITY_EVENT_OTHER, PowerManager.USER_ACTIVITY_FLAG_NO_CHANGE_LIGHTS ) } } private fun runServicesUpdate(hasPanelBoolean: Boolean = true) { val listings = listOf(ControlsServiceInfo(TEST_COMPONENT, "panel", hasPanel = hasPanelBoolean)) Loading packages/SystemUI/src/com/android/systemui/dreams/homecontrols/HomeControlsDreamService.kt +7 −3 Original line number Diff line number Diff line Loading @@ -81,7 +81,7 @@ constructor( activity = activity, onCreateCallback = this::onTaskFragmentCreated, onInfoChangedCallback = this::onTaskFragmentInfoChanged, hide = { finish() } hide = { endDream() } ) .apply { createTaskFragment() } Loading @@ -91,9 +91,13 @@ constructor( private fun onTaskFragmentInfoChanged(taskFragmentInfo: TaskFragmentInfo) { if (taskFragmentInfo.isEmpty) { logger.d("Finishing dream due to TaskFragment being empty") finish() homeControlsComponentInteractor.onTaskFragmentEmpty() endDream() } } private fun endDream() { homeControlsComponentInteractor.onDreamEndUnexpectedly() wakeUp() } private fun onTaskFragmentCreated(taskFragmentInfo: TaskFragmentInfo) { Loading packages/SystemUI/src/com/android/systemui/dreams/homecontrols/domain/interactor/HomeControlsComponentInteractor.kt +8 −1 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.systemui.dreams.homecontrols.domain.interactor import android.annotation.SuppressLint import android.app.DreamManager import android.content.ComponentName import android.os.PowerManager import android.os.UserHandle import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow import com.android.systemui.common.domain.interactor.PackageChangeInteractor Loading Loading @@ -66,6 +67,7 @@ constructor( userRepository: UserRepository, private val packageChangeInteractor: PackageChangeInteractor, private val systemClock: SystemClock, private val powerManager: PowerManager, private val dreamManager: DreamManager, @Background private val bgScope: CoroutineScope ) { Loading Loading @@ -135,7 +137,12 @@ constructor( private val taskFragmentFinished = MutableSharedFlow<Long>(replay = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST) fun onTaskFragmentEmpty() { fun onDreamEndUnexpectedly() { powerManager.userActivity( systemClock.uptimeMillis(), PowerManager.USER_ACTIVITY_EVENT_OTHER, PowerManager.USER_ACTIVITY_FLAG_NO_CHANGE_LIGHTS, ) taskFragmentFinished.tryEmit(systemClock.currentTimeMillis()) } Loading packages/SystemUI/tests/utils/src/android/os/PowerManagerKosmos.kt 0 → 100644 +22 −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. */ package android.os import com.android.systemui.kosmos.Kosmos import com.android.systemui.util.mockito.mock var Kosmos.powerManager by Kosmos.Fixture { mock<PowerManager>() } Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/homecontrols/HomeControlsComponentInteractorKosmos.kt +2 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ package com.android.systemui.dreams.homecontrols import android.os.powerManager import android.service.dream.dreamManager import com.android.systemui.common.domain.interactor.packageChangeInteractor import com.android.systemui.controls.dagger.ControlsComponent Loading @@ -37,6 +38,7 @@ val Kosmos.homeControlsComponentInteractor by userRepository = fakeUserRepository, bgScope = applicationCoroutineScope, systemClock = fakeSystemClock, powerManager = powerManager, dreamManager = dreamManager, packageChangeInteractor = packageChangeInteractor, ) Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/homecontrols/HomeControlsComponentInteractorTest.kt +25 −2 Original line number Diff line number Diff line Loading @@ -20,7 +20,9 @@ import android.content.Context import android.content.pm.ApplicationInfo import android.content.pm.ServiceInfo import android.content.pm.UserInfo import android.os.PowerManager import android.os.UserHandle import android.os.powerManager import android.service.dream.dreamManager import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest Loading Loading @@ -50,6 +52,8 @@ import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.ArgumentMatchers.anyInt import org.mockito.Mockito.anyLong import org.mockito.Mockito.never import org.mockito.Mockito.verify Loading Loading @@ -196,7 +200,7 @@ class HomeControlsComponentInteractorTest : SysuiTestCase() { ) fakeSystemClock.advanceTime(MAX_UPDATE_CORRELATION_DELAY.inWholeMilliseconds) // Task fragment becomes empty as a result of the update. underTest.onTaskFragmentEmpty() underTest.onDreamEndUnexpectedly() runCurrent() verify(dreamManager, never()).startDream() Loading Loading @@ -240,7 +244,7 @@ class HomeControlsComponentInteractorTest : SysuiTestCase() { ) fakeSystemClock.advanceTime(MAX_UPDATE_CORRELATION_DELAY.inWholeMilliseconds + 100) // Task fragment becomes empty as a result of the update. underTest.onTaskFragmentEmpty() underTest.onDreamEndUnexpectedly() runCurrent() verify(dreamManager, never()).startDream() Loading @@ -258,6 +262,25 @@ class HomeControlsComponentInteractorTest : SysuiTestCase() { } } @Test fun testDreamUnexpectedlyEnds_triggersUserActivity() = with(kosmos) { testScope.runTest { fakeSystemClock.setUptimeMillis(100000L) verify(powerManager, never()).userActivity(anyLong(), anyInt(), anyInt()) // Dream ends unexpectedly underTest.onDreamEndUnexpectedly() verify(powerManager) .userActivity( 100000L, PowerManager.USER_ACTIVITY_EVENT_OTHER, PowerManager.USER_ACTIVITY_FLAG_NO_CHANGE_LIGHTS ) } } private fun runServicesUpdate(hasPanelBoolean: Boolean = true) { val listings = listOf(ControlsServiceInfo(TEST_COMPONENT, "panel", hasPanel = hasPanelBoolean)) Loading
packages/SystemUI/src/com/android/systemui/dreams/homecontrols/HomeControlsDreamService.kt +7 −3 Original line number Diff line number Diff line Loading @@ -81,7 +81,7 @@ constructor( activity = activity, onCreateCallback = this::onTaskFragmentCreated, onInfoChangedCallback = this::onTaskFragmentInfoChanged, hide = { finish() } hide = { endDream() } ) .apply { createTaskFragment() } Loading @@ -91,9 +91,13 @@ constructor( private fun onTaskFragmentInfoChanged(taskFragmentInfo: TaskFragmentInfo) { if (taskFragmentInfo.isEmpty) { logger.d("Finishing dream due to TaskFragment being empty") finish() homeControlsComponentInteractor.onTaskFragmentEmpty() endDream() } } private fun endDream() { homeControlsComponentInteractor.onDreamEndUnexpectedly() wakeUp() } private fun onTaskFragmentCreated(taskFragmentInfo: TaskFragmentInfo) { Loading
packages/SystemUI/src/com/android/systemui/dreams/homecontrols/domain/interactor/HomeControlsComponentInteractor.kt +8 −1 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.systemui.dreams.homecontrols.domain.interactor import android.annotation.SuppressLint import android.app.DreamManager import android.content.ComponentName import android.os.PowerManager import android.os.UserHandle import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow import com.android.systemui.common.domain.interactor.PackageChangeInteractor Loading Loading @@ -66,6 +67,7 @@ constructor( userRepository: UserRepository, private val packageChangeInteractor: PackageChangeInteractor, private val systemClock: SystemClock, private val powerManager: PowerManager, private val dreamManager: DreamManager, @Background private val bgScope: CoroutineScope ) { Loading Loading @@ -135,7 +137,12 @@ constructor( private val taskFragmentFinished = MutableSharedFlow<Long>(replay = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST) fun onTaskFragmentEmpty() { fun onDreamEndUnexpectedly() { powerManager.userActivity( systemClock.uptimeMillis(), PowerManager.USER_ACTIVITY_EVENT_OTHER, PowerManager.USER_ACTIVITY_FLAG_NO_CHANGE_LIGHTS, ) taskFragmentFinished.tryEmit(systemClock.currentTimeMillis()) } Loading
packages/SystemUI/tests/utils/src/android/os/PowerManagerKosmos.kt 0 → 100644 +22 −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. */ package android.os import com.android.systemui.kosmos.Kosmos import com.android.systemui.util.mockito.mock var Kosmos.powerManager by Kosmos.Fixture { mock<PowerManager>() }