summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/homecontrols/HomeControlsComponentInteractorKosmos.kt2
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/homecontrols/HomeControlsComponentInteractorTest.kt27
-rw-r--r--packages/SystemUI/src/com/android/systemui/dreams/homecontrols/HomeControlsDreamService.kt10
-rw-r--r--packages/SystemUI/src/com/android/systemui/dreams/homecontrols/domain/interactor/HomeControlsComponentInteractor.kt9
-rw-r--r--packages/SystemUI/tests/utils/src/android/os/PowerManagerKosmos.kt22
5 files changed, 64 insertions, 6 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/homecontrols/HomeControlsComponentInteractorKosmos.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/homecontrols/HomeControlsComponentInteractorKosmos.kt
index 2c890f4e6c42..7d7841f0da5b 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/homecontrols/HomeControlsComponentInteractorKosmos.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/homecontrols/HomeControlsComponentInteractorKosmos.kt
@@ -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
@@ -37,6 +38,7 @@ val Kosmos.homeControlsComponentInteractor by
userRepository = fakeUserRepository,
bgScope = applicationCoroutineScope,
systemClock = fakeSystemClock,
+ powerManager = powerManager,
dreamManager = dreamManager,
packageChangeInteractor = packageChangeInteractor,
)
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/homecontrols/HomeControlsComponentInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/homecontrols/HomeControlsComponentInteractorTest.kt
index 298ce7029f0a..feb72989980c 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/homecontrols/HomeControlsComponentInteractorTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/homecontrols/HomeControlsComponentInteractorTest.kt
@@ -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
@@ -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
@@ -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()
@@ -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()
@@ -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))
diff --git a/packages/SystemUI/src/com/android/systemui/dreams/homecontrols/HomeControlsDreamService.kt b/packages/SystemUI/src/com/android/systemui/dreams/homecontrols/HomeControlsDreamService.kt
index 376d3129d8c3..ee8e2059e177 100644
--- a/packages/SystemUI/src/com/android/systemui/dreams/homecontrols/HomeControlsDreamService.kt
+++ b/packages/SystemUI/src/com/android/systemui/dreams/homecontrols/HomeControlsDreamService.kt
@@ -81,7 +81,7 @@ constructor(
activity = activity,
onCreateCallback = this::onTaskFragmentCreated,
onInfoChangedCallback = this::onTaskFragmentInfoChanged,
- hide = { finish() }
+ hide = { endDream() }
)
.apply { createTaskFragment() }
@@ -91,11 +91,15 @@ 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) {
val setting = controlsSettingsRepository.allowActionOnTrivialControlsInLockscreen.value
val componentName = homeControlsComponentInteractor.panelComponent.value
diff --git a/packages/SystemUI/src/com/android/systemui/dreams/homecontrols/domain/interactor/HomeControlsComponentInteractor.kt b/packages/SystemUI/src/com/android/systemui/dreams/homecontrols/domain/interactor/HomeControlsComponentInteractor.kt
index f0067dcb7fe2..74452d1980be 100644
--- a/packages/SystemUI/src/com/android/systemui/dreams/homecontrols/domain/interactor/HomeControlsComponentInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/dreams/homecontrols/domain/interactor/HomeControlsComponentInteractor.kt
@@ -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
@@ -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
) {
@@ -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())
}
diff --git a/packages/SystemUI/tests/utils/src/android/os/PowerManagerKosmos.kt b/packages/SystemUI/tests/utils/src/android/os/PowerManagerKosmos.kt
new file mode 100644
index 000000000000..4ddbb457fd6b
--- /dev/null
+++ b/packages/SystemUI/tests/utils/src/android/os/PowerManagerKosmos.kt
@@ -0,0 +1,22 @@
+/*
+ * 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>() }