From ef3e18715be1b28ba340c99aa023ac0e62096340 Mon Sep 17 00:00:00 2001 From: Schneider Victor-Tulias Date: Tue, 7 Jan 2025 10:31:12 -0500 Subject: [PATCH] Fix test Dagger initialization deadlock in RecentsDisplayModel - Fixes a deadlock created when initializing RecentsDisplayModel - Also fixes an IllegalStateException when initializing RecentsDisplayModel before the default display has initialized Flag: com.android.launcher3.enable_fallback_overview_in_window Bug: 377678992 Test: pre/post submit Change-Id: I5d3e000d722c311e0d5431034b68635c402c8109 --- .../fallback/window/RecentsDisplayModel.kt | 33 ++++++++++++++++--- .../quickstep/LauncherSwipeHandlerV2Test.kt | 7 +--- .../recents/window/RecentsDisplayModelTest.kt | 20 ----------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/quickstep/src/com/android/quickstep/fallback/window/RecentsDisplayModel.kt b/quickstep/src/com/android/quickstep/fallback/window/RecentsDisplayModel.kt index a9259d932b..505f2cbb39 100644 --- a/quickstep/src/com/android/quickstep/fallback/window/RecentsDisplayModel.kt +++ b/quickstep/src/com/android/quickstep/fallback/window/RecentsDisplayModel.kt @@ -24,6 +24,8 @@ import com.android.launcher3.Flags import com.android.launcher3.dagger.ApplicationContext import com.android.launcher3.dagger.LauncherAppSingleton import com.android.launcher3.util.DaggerSingletonObject +import com.android.launcher3.util.DaggerSingletonTracker +import com.android.launcher3.util.Executors.MAIN_EXECUTOR import com.android.quickstep.DisplayModel import com.android.quickstep.FallbackWindowInterface import com.android.quickstep.dagger.QuickstepBaseAppComponent @@ -31,7 +33,9 @@ import com.android.quickstep.fallback.window.RecentsDisplayModel.RecentsDisplayR import javax.inject.Inject @LauncherAppSingleton -class RecentsDisplayModel @Inject constructor(@ApplicationContext context: Context) : +class RecentsDisplayModel +@Inject +constructor(@ApplicationContext context: Context, tracker: DaggerSingletonTracker) : DisplayModel(context) { companion object { @@ -47,17 +51,38 @@ class RecentsDisplayModel @Inject constructor(@ApplicationContext context: Conte init { if (Flags.enableFallbackOverviewInWindow() || Flags.enableLauncherOverviewInWindow()) { - displayManager.registerDisplayListener(displayListener, Handler.getMain()) - createDisplayResource(Display.DEFAULT_DISPLAY) + MAIN_EXECUTOR.execute { + displayManager.registerDisplayListener(displayListener, Handler.getMain()) + // In the scenario where displays were added before this display listener was + // registered, we should store the RecentsDisplayResources for those displays + // directly. + displayManager.displays + .filter { getDisplayResource(it.displayId) == null } + .forEach { storeRecentsDisplayResource(it.displayId, it) } + } + tracker.addCloseable { destroy() } } } override fun createDisplayResource(displayId: Int) { - if (DEBUG) Log.d(TAG, "create: displayId=$displayId") + if (DEBUG) Log.d(TAG, "createDisplayResource: displayId=$displayId") getDisplayResource(displayId)?.let { return } val display = displayManager.getDisplay(displayId) + if (display == null) { + if (DEBUG) + Log.w( + TAG, + "createDisplayResource: could not create display for displayId=$displayId", + Exception(), + ) + return + } + storeRecentsDisplayResource(displayId, display) + } + + private fun storeRecentsDisplayResource(displayId: Int, display: Display) { displayResourceArray[displayId] = RecentsDisplayResource(displayId, context.createDisplayContext(display)) } diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2Test.kt b/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2Test.kt index 648776ce10..c02b8aacab 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2Test.kt +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2Test.kt @@ -25,7 +25,6 @@ import com.android.launcher3.dagger.LauncherAppModule import com.android.launcher3.dagger.LauncherAppSingleton import com.android.launcher3.util.LauncherModelHelper import com.android.launcher3.util.MSDLPlayerWrapper -import com.android.quickstep.fallback.window.RecentsDisplayModel import com.android.systemui.contextualeducation.GestureType import com.android.systemui.shared.system.InputConsumerController import dagger.BindsInstance @@ -68,9 +67,7 @@ class LauncherSwipeHandlerV2Test { @Before fun setup() { sandboxContext.initDaggerComponent( - DaggerTestComponent.builder() - .bindSystemUiProxy(systemUiProxy) - .bindRecentsDisplayModel(RecentsDisplayModel(sandboxContext)) + DaggerTestComponent.builder().bindSystemUiProxy(systemUiProxy) ) val deviceState = mock(RecentsAnimationDeviceState::class.java) @@ -120,8 +117,6 @@ interface TestComponent : LauncherAppComponent { interface Builder : LauncherAppComponent.Builder { @BindsInstance fun bindSystemUiProxy(proxy: SystemUiProxy): Builder - @BindsInstance fun bindRecentsDisplayModel(model: RecentsDisplayModel): Builder - override fun build(): TestComponent } } diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/window/RecentsDisplayModelTest.kt b/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/window/RecentsDisplayModelTest.kt index d2aa6ac2a1..44ea73e7f4 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/window/RecentsDisplayModelTest.kt +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/window/RecentsDisplayModelTest.kt @@ -28,14 +28,9 @@ import androidx.test.filters.SmallTest import androidx.test.platform.app.InstrumentationRegistry import com.android.launcher3.Flags.FLAG_ENABLE_FALLBACK_OVERVIEW_IN_WINDOW import com.android.launcher3.Flags.FLAG_ENABLE_LAUNCHER_OVERVIEW_IN_WINDOW -import com.android.launcher3.dagger.LauncherAppComponent -import com.android.launcher3.dagger.LauncherAppModule -import com.android.launcher3.dagger.LauncherAppSingleton import com.android.launcher3.util.LauncherModelHelper import com.android.launcher3.util.window.CachedDisplayInfo import com.android.quickstep.fallback.window.RecentsDisplayModel -import dagger.BindsInstance -import dagger.Component import org.junit.Assert import org.junit.Before import org.junit.Rule @@ -75,10 +70,6 @@ class RecentsDisplayModelTest { whenever(displayManager.getDisplay(anyInt())).thenReturn(display) runOnMainSync { recentsDisplayModel = RecentsDisplayModel.INSTANCE.get(context) } - context.initDaggerComponent( - DaggerRecentsDisplayModelComponent.builder() - .bindRecentsDisplayModel(recentsDisplayModel) - ) } @Test @@ -125,14 +116,3 @@ class RecentsDisplayModelTest { InstrumentationRegistry.getInstrumentation().runOnMainSync { f.run() } } } - -@LauncherAppSingleton -@Component(modules = [LauncherAppModule::class]) -interface RecentsDisplayModelComponent : LauncherAppComponent { - @Component.Builder - interface Builder : LauncherAppComponent.Builder { - @BindsInstance fun bindRecentsDisplayModel(model: RecentsDisplayModel): Builder - - override fun build(): RecentsDisplayModelComponent - } -}