[Action Corner] Handle overview action in launcher

Add a new command type "TOGGLE_OVERVIEW_PREVIOUS" to toggle between overview and the previous task or homepage.
Renamed the existing command types to make them more precise

Bug: 409036363
Flag: com.android.systemui.shared.cursor_hot_corner
Test: OverviewCommandHelperTest
Change-Id: I7bab39adb0c933e16ac222fafc8be3f60fe36cc1
This commit is contained in:
helencheuk
2025-04-11 15:13:09 +01:00
parent bb2b582e7f
commit f4d8a9d3a2
4 changed files with 163 additions and 32 deletions

View File

@@ -21,12 +21,18 @@ import android.view.Display.DEFAULT_DISPLAY
import androidx.test.filters.SmallTest
import com.android.app.displaylib.DisplayRepository
import com.android.launcher3.Flags
import com.android.launcher3.LauncherState
import com.android.launcher3.statemanager.StateManager
import com.android.launcher3.statemanager.StatefulActivity
import com.android.launcher3.uioverrides.QuickstepLauncher
import com.android.launcher3.util.LauncherMultivalentJUnit
import com.android.launcher3.util.TestDispatcherProvider
import com.android.launcher3.util.rule.setFlags
import com.android.quickstep.OverviewCommandHelper.CommandInfo
import com.android.quickstep.OverviewCommandHelper.CommandInfo.CommandStatus
import com.android.quickstep.OverviewCommandHelper.CommandType
import com.android.quickstep.views.RecentsView
import com.android.quickstep.views.TaskView
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
@@ -46,6 +52,7 @@ import org.mockito.Mockito.doAnswer
import org.mockito.Mockito.spy
import org.mockito.kotlin.any
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
@SmallTest
@@ -63,6 +70,10 @@ class OverviewCommandHelperTest {
private val displayRepository: DisplayRepository = mock()
private val executeCommandDisplayIds = mutableListOf<Int>()
private val recentView: RecentsView<*, *> = mock()
private val stateManager: StateManager<LauncherState, StatefulActivity<LauncherState>> = mock()
private val containerInterface: BaseActivityInterface<LauncherState, QuickstepLauncher> = mock()
private fun setupDefaultDisplay() {
whenever(displayRepository.displayIds).thenReturn(MutableStateFlow(setOf(DEFAULT_DISPLAY)))
}
@@ -79,18 +90,30 @@ class OverviewCommandHelperTest {
setupDefaultDisplay()
val overviewComponentObserver = mock<OverviewComponentObserver>()
whenever(overviewComponentObserver.getContainerInterface(any()))
.thenReturn(containerInterface)
whenever(recentView.getStateManager()).thenReturn(stateManager)
whenever(containerInterface.switchToRecentsIfVisible(any())).thenReturn(true)
sut =
spy(
OverviewCommandHelper(
touchInteractionService = mock(),
overviewComponentObserver = mock(),
overviewComponentObserver = overviewComponentObserver,
dispatcherProvider = TestDispatcherProvider(dispatcher),
displayRepository = displayRepository,
taskbarManager = mock(),
taskAnimationManagerRepository = mock(),
)
)
}
private fun addCallbackDelay(delayInMillis: Long = 0) {
pendingCallbacksWithDelays.add(delayInMillis)
}
private fun mockExecuteCommand() {
doAnswer { invocation ->
val pendingCallback = invocation.arguments[1] as () -> Unit
@@ -111,13 +134,10 @@ class OverviewCommandHelperTest {
.executeCommand(any<CommandInfo>(), any())
}
private fun addCallbackDelay(delayInMillis: Long = 0) {
pendingCallbacksWithDelays.add(delayInMillis)
}
@Test
fun whenFirstCommandIsAdded_executeCommandImmediately() =
testScope.runTest {
mockExecuteCommand()
// Add command to queue
val commandInfo: CommandInfo = sut.addCommand(CommandType.HOME)!!
assertThat(commandInfo.status).isEqualTo(CommandStatus.IDLE)
@@ -128,6 +148,7 @@ class OverviewCommandHelperTest {
@Test
fun whenFirstCommandIsAdded_executeCommandImmediately_WithCallbackDelay() =
testScope.runTest {
mockExecuteCommand()
addCallbackDelay(100)
// Add command to queue
@@ -145,6 +166,7 @@ class OverviewCommandHelperTest {
@Test
fun whenFirstCommandIsPendingCallback_NextCommandWillWait() =
testScope.runTest {
mockExecuteCommand()
// Add command to queue
addCallbackDelay(100)
val commandType1 = CommandType.HOME
@@ -152,7 +174,7 @@ class OverviewCommandHelperTest {
assertThat(commandInfo1.status).isEqualTo(CommandStatus.IDLE)
addCallbackDelay(100)
val commandType2 = CommandType.SHOW
val commandType2 = CommandType.SHOW_ALT_TAB
val commandInfo2: CommandInfo = sut.addCommand(commandType2)!!
assertThat(commandInfo2.status).isEqualTo(CommandStatus.IDLE)
@@ -171,6 +193,7 @@ class OverviewCommandHelperTest {
@Test
fun whenCommandTakesTooLong_TriggerTimeout_AndExecuteNextCommand() =
testScope.runTest {
mockExecuteCommand()
// Add command to queue
addCallbackDelay(QUEUE_TIMEOUT)
val commandType1 = CommandType.HOME
@@ -178,7 +201,7 @@ class OverviewCommandHelperTest {
assertThat(commandInfo1.status).isEqualTo(CommandStatus.IDLE)
addCallbackDelay(100)
val commandType2 = CommandType.SHOW
val commandType2 = CommandType.SHOW_ALT_TAB
val commandInfo2: CommandInfo = sut.addCommand(commandType2)!!
assertThat(commandInfo2.status).isEqualTo(CommandStatus.IDLE)
@@ -197,6 +220,7 @@ class OverviewCommandHelperTest {
@Test
fun whenAllDisplaysCommandIsAdded_singleCommandProcessedForDefaultDisplay() =
testScope.runTest {
mockExecuteCommand()
executeCommandDisplayIds.clear()
// Add command to queue
val commandInfo: CommandInfo = sut.addCommandsForAllDisplays(CommandType.HOME)!!
@@ -209,6 +233,7 @@ class OverviewCommandHelperTest {
@Test
fun whenAllDisplaysCommandIsAdded_multipleCommandsProcessedForMultipleDisplays() =
testScope.runTest {
mockExecuteCommand()
setupMultipleDisplays()
executeCommandDisplayIds.clear()
// Add command to queue
@@ -223,6 +248,7 @@ class OverviewCommandHelperTest {
@Test
fun whenAllExceptDisplayCommandIsAdded_otherDisplayProcessed() =
testScope.runTest {
mockExecuteCommand()
setupMultipleDisplays()
executeCommandDisplayIds.clear()
// Add command to queue
@@ -237,6 +263,7 @@ class OverviewCommandHelperTest {
@Test
fun whenSingleDisplayCommandIsAdded_thatDisplayIsProcessed() =
testScope.runTest {
mockExecuteCommand()
executeCommandDisplayIds.clear()
val displayId = 5
// Add command to queue
@@ -247,6 +274,39 @@ class OverviewCommandHelperTest {
assertThat(executeCommandDisplayIds).containsExactly(displayId)
}
@Test
fun recentViewNotVisible_toggleOverviewPrev_goToOverview() =
testScope.runTest {
whenever(containerInterface.getVisibleRecentsView<RecentsView<*, *>>()).thenReturn(null)
sut.addCommand(CommandType.TOGGLE_OVERVIEW_PREVIOUS)!!
runCurrent()
verify(containerInterface).switchToRecentsIfVisible(any())
}
@Test
fun recentViewVisible_toggleOverviewPrev_goToHome() =
testScope.runTest {
whenever(containerInterface.getVisibleRecentsView<RecentsView<*, *>>())
.thenReturn(recentView)
sut.addCommand(CommandType.TOGGLE_OVERVIEW_PREVIOUS)!!
runCurrent()
verify(recentView).startHome()
}
@Test
fun recentViewVisible_hasRunningTask_toggleOverviewPrev_goToPrevTask() =
testScope.runTest {
whenever(containerInterface.getVisibleRecentsView<RecentsView<*, *>>())
.thenReturn(recentView)
val mockTask = mock<TaskView>()
whenever(recentView.runningTaskView).thenReturn(mockTask)
sut.addCommand(CommandType.TOGGLE_OVERVIEW_PREVIOUS)!!
runCurrent()
verify(mockTask).launchWithAnimation()
}
private companion object {
const val QUEUE_TIMEOUT = 5001L
const val EXTERNAL_DISPLAY_ID = 1