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

Commit 4723c4e1 authored by Luca Zuccarini's avatar Luca Zuccarini Committed by Android (Google) Code Review
Browse files

Merge "Remove Dream/background flicker from Communal->Edit transition." into main

parents 4334b1af 7aac24df
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import com.android.systemui.communal.domain.interactor.communalSceneInteractor
import com.android.systemui.communal.domain.interactor.communalSettingsInteractor
import com.android.systemui.communal.domain.interactor.setCommunalAvailable
import com.android.systemui.communal.shared.model.CommunalScenes
import com.android.systemui.communal.shared.model.EditModeState
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.dock.dockManager
import com.android.systemui.dock.fakeDockManager
@@ -104,6 +105,27 @@ class CommunalSceneStartableTest : SysuiTestCase() {
        }
    }

    @Test
    @DisableFlags(FLAG_COMMUNAL_SCENE_KTF_REFACTOR)
    fun keyguardGoesAway_whenLaunchingEditMode_doNotForceBlankScene() =
        with(kosmos) {
            testScope.runTest {
                val scene by collectLastValue(communalSceneInteractor.currentScene)

                communalSceneInteractor.changeScene(CommunalScenes.Communal)
                assertThat(scene).isEqualTo(CommunalScenes.Communal)

                communalSceneInteractor.setEditModeState(EditModeState.STARTING)
                fakeKeyguardTransitionRepository.sendTransitionSteps(
                    from = KeyguardState.PRIMARY_BOUNCER,
                    to = KeyguardState.GONE,
                    testScope = this
                )

                assertThat(scene).isEqualTo(CommunalScenes.Communal)
            }
        }

    @Test
    @DisableFlags(FLAG_COMMUNAL_SCENE_KTF_REFACTOR)
    fun keyguardGoesAway_whenLaunchingWidget_doNotForceBlankScene() =
+106 −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 com.android.systemui.communal.widgets

import android.content.ComponentName
import android.content.Intent
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.communal.widgets.EditWidgetsActivity.Companion.EXTRA_PRESELECTED_KEY
import com.android.systemui.kosmos.testScope
import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.any
import org.mockito.kotlin.argumentCaptor
import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import org.mockito.kotlin.times
import org.mockito.kotlin.verify

@ExperimentalCoroutinesApi
@SmallTest
@RunWith(AndroidJUnit4::class)
class EditWidgetsActivityStarterTest : SysuiTestCase() {
    private val activityStarter = mock<ActivityStarter>()
    private val kosmos = testKosmos()

    private lateinit var component: ComponentName
    private lateinit var underTest: EditWidgetsActivityStarter

    @Before
    fun setUp() {
        component = ComponentName(context, EditWidgetsActivity::class.java)
        underTest =
            EditWidgetsActivityStarterImpl(
                context.applicationContext,
                activityStarter,
            )
    }

    @Test
    fun activityLaunch_intentIsWellFormed() {
        with(kosmos) {
            testScope.runTest {
                underTest.startActivity(TEST_PRESELECTED_KEY, shouldOpenWidgetPickerOnStart = true)

                val captor = argumentCaptor<Intent>()
                verify(activityStarter)
                    .startActivityDismissingKeyguard(captor.capture(), eq(true), eq(true), any())
                assertThat(captor.lastValue.component).isEqualTo(component)
                assertThat(captor.lastValue.flags and Intent.FLAG_ACTIVITY_NEW_TASK).isNotEqualTo(0)
                assertThat(captor.lastValue.flags and Intent.FLAG_ACTIVITY_CLEAR_TASK)
                    .isNotEqualTo(0)
                assertThat(captor.lastValue.extras?.getString(EXTRA_PRESELECTED_KEY))
                    .isEqualTo(TEST_PRESELECTED_KEY)
                assertThat(
                        captor.lastValue.extras?.getBoolean(
                            EditWidgetsActivity.EXTRA_OPEN_WIDGET_PICKER_ON_START
                        )
                    )
                    .isEqualTo(true)

                underTest.startActivity(TEST_PRESELECTED_KEY, shouldOpenWidgetPickerOnStart = false)

                verify(activityStarter, times(2))
                    .startActivityDismissingKeyguard(captor.capture(), eq(true), eq(true), any())
                assertThat(captor.lastValue.component).isEqualTo(component)
                assertThat(captor.lastValue.flags and Intent.FLAG_ACTIVITY_NEW_TASK).isNotEqualTo(0)
                assertThat(captor.lastValue.flags and Intent.FLAG_ACTIVITY_CLEAR_TASK)
                    .isNotEqualTo(0)
                assertThat(captor.lastValue.extras?.getString(EXTRA_PRESELECTED_KEY))
                    .isEqualTo(TEST_PRESELECTED_KEY)
                assertThat(
                        captor.lastValue.extras?.getBoolean(
                            EditWidgetsActivity.EXTRA_OPEN_WIDGET_PICKER_ON_START
                        )
                    )
                    .isEqualTo(false)
            }
        }
    }

    companion object {
        const val TEST_PRESELECTED_KEY = "test-key"
    }
}
+9 −5
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import com.android.systemui.communal.domain.interactor.CommunalSceneInteractor
import com.android.systemui.communal.domain.interactor.CommunalSettingsInteractor
import com.android.systemui.communal.shared.model.CommunalScenes
import com.android.systemui.communal.shared.model.CommunalTransitionKeys
import com.android.systemui.communal.shared.model.EditModeState
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
@@ -103,11 +104,14 @@ constructor(
                .mapLatest(::determineSceneAfterTransition)
                .filterNotNull()
                .onEach { (nextScene, nextTransition) ->
                    if (!communalSceneInteractor.isLaunchingWidget.value) {
                    // When launching a widget, we don't want to animate the scene change or the
                        // Communal Hub will reveal the wallpaper even though it shouldn't. Instead
                        // we snap to the new scene as part of the launch animation, once the
                        // activity launch is done, so we don't change scene here.
                    // Communal Hub will reveal the wallpaper even though it shouldn't. Instead we
                    // snap to the new scene as part of the launch animation, once the activity
                    // launch is done, so we don't change scene here.
                    val delaySceneTransition =
                        communalSceneInteractor.editModeState.value == EditModeState.STARTING ||
                            communalSceneInteractor.isLaunchingWidget.value
                    if (!delaySceneTransition) {
                        communalSceneInteractor.changeScene(nextScene, nextTransition)
                    }
                }