Fix TaskbarAutohideSuspendControllerTest with grant_manage_key_gestures_to_recents enabled

Problem:
The framework prevents a key gesture handler from being re-registered by the same process ID. In `TaskbarAutohideSuspendControllerTest`, we observed two calls to `QuickstepKeyGestureEventsManager#registerAllAppsKeyGestureEvent`. The first call originated from TouchInteractionService (as expected). The second, however, came from a new TaskbarManager instance created within `TaskbarbarUnitTestRule`. This occurs because `TaskManager#recreateTaskbarForDisplay` triggers `AllAppsActionManager#isTaskbarPresent`, which ultimately leads to the duplicate call to `QuickstepKeyGestureEventsManager#registerAllAppsKeyGestureEvent`.

Solution:
Since this problem only occurs in tests and not in practice, we can mock out `QuickstepKeyGestureEventsManager`'s [un]registration calls to do nothing within `TaskbarbarUnitTestRule` to prevent duplicated re-registration.

Flag: com.android.window.flags.grant_manage_key_gestures_to_recents
Test: atest NexusLauncherTests:TaskbarAutohideSuspendControllerTest
Test: atest NexusLauncherTests:TaskbarEduTooltipControllerTest
Fix: 421853013
Change-Id: Ic87bd8d36ce018935002b8698b1d53e30b2fca6d
This commit is contained in:
Steven Ng
2025-06-02 17:33:20 +01:00
parent d1bf60e380
commit 38ff87fca6
@@ -46,6 +46,10 @@ import org.junit.Assume.assumeTrue
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
import org.mockito.kotlin.any
import org.mockito.kotlin.doNothing
import org.mockito.kotlin.spy
import org.mockito.kotlin.whenever
/**
* Manages the Taskbar lifecycle for unit tests.
@@ -106,6 +110,20 @@ class TaskbarUnitTestRule(
context.settingsCacheSandbox[getUriFor(NAV_BAR_KIDS_MODE)] =
if (description.getAnnotation(NavBarKidsMode::class.java) != null) 1 else 0
val quickstepKeyGestureEventsManagerSpy =
spy(QuickstepKeyGestureEventsManager(context))
doNothing()
.whenever(quickstepKeyGestureEventsManagerSpy)
.registerAllAppsKeyGestureEvent(any())
doNothing()
.whenever(quickstepKeyGestureEventsManagerSpy)
.unregisterAllAppsKeyGestureEvent()
doNothing()
.whenever(quickstepKeyGestureEventsManagerSpy)
.registerOverviewKeyGestureEvent(any())
doNothing()
.whenever(quickstepKeyGestureEventsManagerSpy)
.unregisterOverviewKeyGestureEvent()
taskbarManager =
TestUtil.getOnUiThread {
object :
@@ -114,7 +132,7 @@ class TaskbarUnitTestRule(
AllAppsActionManager(
context,
UI_HELPER_EXECUTOR,
QuickstepKeyGestureEventsManager(context),
quickstepKeyGestureEventsManagerSpy,
) {
PendingIntent(IIntentSender.Default())
},