summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalInteractorTest.kt4
-rw-r--r--packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt3
-rw-r--r--packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalEditModeViewModel.kt2
-rw-r--r--packages/SystemUI/src/com/android/systemui/communal/widgets/EditWidgetsActivity.kt24
4 files changed, 25 insertions, 8 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalInteractorTest.kt
index 766798c2c2c3..83227e1fc597 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalInteractorTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalInteractorTest.kt
@@ -204,14 +204,14 @@ class CommunalInteractorTest : SysuiTestCase() {
}
@Test
- fun isCommunalAvailable_whenDreaming_true() =
+ fun isCommunalAvailable_whenKeyguardShowing_true() =
testScope.runTest {
val isAvailable by collectLastValue(underTest.isCommunalAvailable)
assertThat(isAvailable).isFalse()
keyguardRepository.setIsEncryptedOrLockdown(false)
userRepository.setSelectedUserInfo(mainUser)
- keyguardRepository.setDreaming(true)
+ keyguardRepository.setKeyguardShowing(true)
assertThat(isAvailable).isTrue()
}
diff --git a/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt b/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt
index 06c83962df6b..9599a8864bcc 100644
--- a/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt
@@ -61,7 +61,6 @@ import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.settings.UserTracker
import com.android.systemui.smartspace.data.repository.SmartspaceRepository
import com.android.systemui.util.kotlin.BooleanFlowOperators.allOf
-import com.android.systemui.util.kotlin.BooleanFlowOperators.anyOf
import com.android.systemui.util.kotlin.BooleanFlowOperators.not
import com.android.systemui.util.kotlin.emitOnStart
import javax.inject.Inject
@@ -130,7 +129,7 @@ constructor(
allOf(
communalSettingsInteractor.isCommunalEnabled,
not(keyguardInteractor.isEncryptedOrLockdown),
- anyOf(keyguardInteractor.isKeyguardShowing, keyguardInteractor.isDreaming)
+ keyguardInteractor.isKeyguardShowing
)
.distinctUntilChanged()
.onEach { available ->
diff --git a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalEditModeViewModel.kt b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalEditModeViewModel.kt
index f6122ad48300..c0dc313e14f7 100644
--- a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalEditModeViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalEditModeViewModel.kt
@@ -96,6 +96,8 @@ constructor(
uiEventLogger.log(CommunalUiEvent.COMMUNAL_HUB_REORDER_WIDGET_CANCEL)
}
+ val isIdleOnCommunal: StateFlow<Boolean> = communalInteractor.isIdleOnCommunal
+
/** Launch the widget picker activity using the given {@link ActivityResultLauncher}. */
suspend fun onOpenWidgetPicker(
resources: Resources,
diff --git a/packages/SystemUI/src/com/android/systemui/communal/widgets/EditWidgetsActivity.kt b/packages/SystemUI/src/com/android/systemui/communal/widgets/EditWidgetsActivity.kt
index f20fafccfd19..426f484e4d02 100644
--- a/packages/SystemUI/src/com/android/systemui/communal/widgets/EditWidgetsActivity.kt
+++ b/packages/SystemUI/src/com/android/systemui/communal/widgets/EditWidgetsActivity.kt
@@ -44,6 +44,7 @@ import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.Logger
import com.android.systemui.log.dagger.CommunalLog
import javax.inject.Inject
+import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
/** An Activity for editing the widgets that appear in hub mode. */
@@ -69,6 +70,8 @@ constructor(
private var shouldOpenWidgetPickerOnStart = false
+ private var lockOnDestroy = false
+
private val addWidgetActivityLauncher: ActivityResultLauncher<Intent> =
registerForActivityResult(StartActivityForResult()) { result ->
when (result.resultCode) {
@@ -149,15 +152,18 @@ constructor(
}
private fun onEditDone() {
- try {
+ lifecycleScope.launch {
communalViewModel.changeScene(
CommunalScenes.Communal,
CommunalTransitionKeys.SimpleFade
)
- checkNotNull(windowManagerService).lockNow(/* options */ null)
+
+ // Wait for the current scene to be idle on communal.
+ communalViewModel.isIdleOnCommunal.first { it }
+ // Then finish the activity (this helps to avoid a flash of lockscreen when locking
+ // in onDestroy()).
+ lockOnDestroy = true
finish()
- } catch (e: RemoteException) {
- Log.e(TAG, "Couldn't lock the device as WindowManager is dead.")
}
}
@@ -190,5 +196,15 @@ constructor(
override fun onDestroy() {
super.onDestroy()
communalViewModel.setEditModeOpen(false)
+
+ if (lockOnDestroy) lockNow()
+ }
+
+ private fun lockNow() {
+ try {
+ checkNotNull(windowManagerService).lockNow(/* options */ null)
+ } catch (e: RemoteException) {
+ Log.e(TAG, "Couldn't lock the device as WindowManager is dead.")
+ }
}
}