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

Commit 51a1a500 authored by William Leshner's avatar William Leshner Committed by Android (Google) Code Review
Browse files

Merge "Fix several bugs with entering/exiting EditWidgetsActivity." into main

parents 24d8df89 45fbcb01
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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()
        }
+1 −2
Original line number Diff line number Diff line
@@ -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 ->
+2 −0
Original line number Diff line number Diff line
@@ -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,
+20 −4
Original line number Diff line number Diff line
@@ -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.")
        }
    }
}