diff options
| author | 2024-05-09 14:53:16 -0700 | |
|---|---|---|
| committer | 2024-05-16 12:23:30 -0700 | |
| commit | 45fbcb019d76d8ceec4ed48344fc3fa6f1f463c7 (patch) | |
| tree | d1b84b34a2df4e8a6bc685ea6aa75988436a3e1e | |
| parent | d13062605eca2d2672390648e123a8b801837be5 (diff) | |
Fix several bugs with entering/exiting EditWidgetsActivity.
In particular:
1. Fixes an issue with lockscreen flashing when leaving
EditWidgetsActivity.
2. Fixes an issue with the notification shade appearing with a
transparent background when shown over communal hub.
Bug: 325108777, 339421165
Test: atest CommunalRepositoryImplTest
Test: atest CommunalInteractorTest
Test: atest CommunalEditModeViewModelTest
Flag: com.android.systemui.communal_hub
Change-Id: I6d5a6c82ff9ec34907b8ff4a76deb5c2baf857fd
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.") + } } } |