Merge "Fix test Dagger initialization deadlock in RecentsDisplayModel" into main

This commit is contained in:
Schneider Victor-tulias
2025-01-08 07:16:41 -08:00
committed by Android (Google) Code Review
3 changed files with 30 additions and 30 deletions
@@ -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<RecentsDisplayResource>(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))
}
@@ -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
@@ -67,9 +66,7 @@ class LauncherSwipeHandlerV2Test {
@Before
fun setup() {
sandboxContext.initDaggerComponent(
DaggerTestComponent.builder()
.bindSystemUiProxy(systemUiProxy)
.bindRecentsDisplayModel(RecentsDisplayModel(sandboxContext))
DaggerTestComponent.builder().bindSystemUiProxy(systemUiProxy)
)
sandboxContext.putObject(
RotationTouchHelper.INSTANCE,
@@ -122,8 +119,6 @@ interface TestComponent : LauncherAppComponent {
interface Builder : LauncherAppComponent.Builder {
@BindsInstance fun bindSystemUiProxy(proxy: SystemUiProxy): Builder
@BindsInstance fun bindRecentsDisplayModel(model: RecentsDisplayModel): Builder
override fun build(): TestComponent
}
}
@@ -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
}
}