Merge "Fix test Dagger initialization deadlock in RecentsDisplayModel" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
5488f3571e
@@ -25,6 +25,7 @@ import com.android.launcher3.dagger.LauncherAppSingleton
|
||||
import com.android.launcher3.util.DaggerSingletonObject
|
||||
import com.android.launcher3.util.DaggerSingletonTracker
|
||||
import com.android.launcher3.util.Executors
|
||||
import com.android.launcher3.util.WallpaperColorHints
|
||||
import com.android.quickstep.DisplayModel
|
||||
import com.android.quickstep.FallbackWindowInterface
|
||||
import com.android.quickstep.dagger.QuickstepBaseAppComponent
|
||||
@@ -34,8 +35,11 @@ import javax.inject.Inject
|
||||
@LauncherAppSingleton
|
||||
class RecentsDisplayModel
|
||||
@Inject
|
||||
constructor(@ApplicationContext context: Context, tracker: DaggerSingletonTracker) :
|
||||
DisplayModel<RecentsDisplayResource>(context) {
|
||||
constructor(
|
||||
@ApplicationContext context: Context,
|
||||
private val wallpaperColorHints: WallpaperColorHints,
|
||||
tracker: DaggerSingletonTracker,
|
||||
) : DisplayModel<RecentsDisplayResource>(context) {
|
||||
|
||||
companion object {
|
||||
private const val TAG = "RecentsDisplayModel"
|
||||
@@ -81,7 +85,11 @@ constructor(@ApplicationContext context: Context, tracker: DaggerSingletonTracke
|
||||
|
||||
private fun storeRecentsDisplayResource(displayId: Int, display: Display) {
|
||||
displayResourceArray[displayId] =
|
||||
RecentsDisplayResource(displayId, context.createDisplayContext(display))
|
||||
RecentsDisplayResource(
|
||||
displayId,
|
||||
context.createDisplayContext(display),
|
||||
wallpaperColorHints.hints,
|
||||
)
|
||||
}
|
||||
|
||||
fun getRecentsWindowManager(displayId: Int): RecentsWindowManager? {
|
||||
@@ -92,9 +100,12 @@ constructor(@ApplicationContext context: Context, tracker: DaggerSingletonTracke
|
||||
return getDisplayResource(displayId)?.fallbackWindowInterface
|
||||
}
|
||||
|
||||
data class RecentsDisplayResource(var displayId: Int, var displayContext: Context) :
|
||||
DisplayResource() {
|
||||
val recentsWindowManager = RecentsWindowManager(displayContext)
|
||||
data class RecentsDisplayResource(
|
||||
var displayId: Int,
|
||||
var displayContext: Context,
|
||||
val wallpaperColorHints: Int,
|
||||
) : DisplayResource() {
|
||||
val recentsWindowManager = RecentsWindowManager(displayContext, wallpaperColorHints)
|
||||
val fallbackWindowInterface: FallbackWindowInterface =
|
||||
FallbackWindowInterface(recentsWindowManager)
|
||||
|
||||
|
||||
@@ -32,11 +32,16 @@ import com.android.quickstep.fallback.RecentsDragLayer
|
||||
|
||||
/**
|
||||
* Window context for the Overview overlays.
|
||||
*
|
||||
* <p>
|
||||
* Overlays have their own window and need a window context.
|
||||
*/
|
||||
open class RecentsWindowContext(windowContext: Context) :
|
||||
ContextThemeWrapper(windowContext, Themes.getActivityThemeRes(windowContext)), ActivityContext {
|
||||
open class RecentsWindowContext(windowContext: Context, wallpaperColorHints: Int) :
|
||||
ContextThemeWrapper(
|
||||
windowContext,
|
||||
Themes.getActivityThemeRes(windowContext, wallpaperColorHints),
|
||||
),
|
||||
ActivityContext {
|
||||
|
||||
private var deviceProfile: DeviceProfile? = null
|
||||
private var dragLayer: RecentsDragLayer<RecentsWindowManager> = RecentsDragLayer(this, null)
|
||||
@@ -48,7 +53,9 @@ open class RecentsWindowContext(windowContext: Context) :
|
||||
|
||||
protected var windowLayoutParams: WindowManager.LayoutParams? =
|
||||
createDefaultWindowLayoutParams(
|
||||
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY, windowTitle)
|
||||
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
|
||||
windowTitle,
|
||||
)
|
||||
|
||||
override fun getDragLayer(): BaseDragLayer<RecentsWindowManager> {
|
||||
return dragLayer
|
||||
@@ -56,8 +63,7 @@ open class RecentsWindowContext(windowContext: Context) :
|
||||
|
||||
override fun getDeviceProfile(): DeviceProfile {
|
||||
if (deviceProfile == null) {
|
||||
deviceProfile = InvariantDeviceProfile.INSTANCE[this].getDeviceProfile(this)
|
||||
.copy(this)
|
||||
deviceProfile = InvariantDeviceProfile.INSTANCE[this].getDeviceProfile(this).copy(this)
|
||||
}
|
||||
return deviceProfile!!
|
||||
}
|
||||
|
||||
@@ -88,8 +88,10 @@ import java.util.function.Predicate
|
||||
* To add new protologs, see [RecentsWindowProtoLogProxy]. To enable logging to logcat, see
|
||||
* [QuickstepProtoLogGroup.Constants.DEBUG_RECENTS_WINDOW]
|
||||
*/
|
||||
class RecentsWindowManager(context: Context) :
|
||||
RecentsWindowContext(context), RecentsViewContainer, StatefulContainer<RecentsState> {
|
||||
class RecentsWindowManager(context: Context, wallpaperColorHints: Int) :
|
||||
RecentsWindowContext(context, wallpaperColorHints),
|
||||
RecentsViewContainer,
|
||||
StatefulContainer<RecentsState> {
|
||||
|
||||
companion object {
|
||||
private const val HOME_APPEAR_DURATION: Long = 250
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.android.launcher3.util.PluginManagerWrapper;
|
||||
import com.android.launcher3.util.ScreenOnTracker;
|
||||
import com.android.launcher3.util.SettingsCache;
|
||||
import com.android.launcher3.util.VibratorWrapper;
|
||||
import com.android.launcher3.util.WallpaperColorHints;
|
||||
import com.android.launcher3.util.window.RefreshRateTracker;
|
||||
import com.android.launcher3.util.window.WindowManagerProxy;
|
||||
import com.android.launcher3.widget.custom.CustomWidgetManager;
|
||||
@@ -66,6 +67,7 @@ public interface LauncherBaseAppComponent {
|
||||
LauncherPrefs getLauncherPrefs();
|
||||
ThemeManager getThemeManager();
|
||||
DisplayController getDisplayController();
|
||||
WallpaperColorHints getWallpaperColorHints();
|
||||
|
||||
/** Builder for LauncherBaseAppComponent. */
|
||||
interface Builder {
|
||||
|
||||
@@ -23,14 +23,21 @@ import android.app.WallpaperManager.OnColorsChangedListener
|
||||
import android.content.Context
|
||||
import androidx.annotation.MainThread
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import com.android.launcher3.dagger.ApplicationContext
|
||||
import com.android.launcher3.dagger.LauncherAppComponent
|
||||
import com.android.launcher3.dagger.LauncherAppSingleton
|
||||
import com.android.launcher3.util.Executors.MAIN_EXECUTOR
|
||||
import com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* This class caches the system's wallpaper color hints for use by other classes as a performance
|
||||
* enhancer. It also centralizes all the WallpaperManager color hint code in one location.
|
||||
*/
|
||||
class WallpaperColorHints(private val context: Context) : SafeCloseable {
|
||||
@LauncherAppSingleton
|
||||
class WallpaperColorHints
|
||||
@Inject
|
||||
constructor(@ApplicationContext private val context: Context, tracker: DaggerSingletonTracker) {
|
||||
var hints: Int = 0
|
||||
private set
|
||||
|
||||
@@ -38,7 +45,6 @@ class WallpaperColorHints(private val context: Context) : SafeCloseable {
|
||||
get() = context.getSystemService(WallpaperManager::class.java)!!
|
||||
|
||||
private val onColorHintsChangedListeners = mutableListOf<OnColorHintListener>()
|
||||
private val onClose: SafeCloseable
|
||||
|
||||
init {
|
||||
hints = wallpaperManager.getWallpaperColors(FLAG_SYSTEM)?.colorHints ?: 0
|
||||
@@ -51,7 +57,7 @@ class WallpaperColorHints(private val context: Context) : SafeCloseable {
|
||||
MAIN_EXECUTOR.handler,
|
||||
)
|
||||
}
|
||||
onClose = SafeCloseable {
|
||||
tracker.addCloseable {
|
||||
UI_HELPER_EXECUTOR.execute {
|
||||
wallpaperManager.removeOnColorsChangedListener(onColorsChangedListener)
|
||||
}
|
||||
@@ -69,8 +75,6 @@ class WallpaperColorHints(private val context: Context) : SafeCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
override fun close() = onClose.close()
|
||||
|
||||
fun registerOnColorHintsChangedListener(listener: OnColorHintListener) {
|
||||
onColorHintsChangedListeners.add(listener)
|
||||
}
|
||||
@@ -82,7 +86,7 @@ class WallpaperColorHints(private val context: Context) : SafeCloseable {
|
||||
companion object {
|
||||
@VisibleForTesting
|
||||
@JvmField
|
||||
val INSTANCE = MainThreadInitializedObject { WallpaperColorHints(it) }
|
||||
val INSTANCE = DaggerSingletonObject(LauncherAppComponent::getWallpaperColorHints)
|
||||
|
||||
@JvmStatic fun get(context: Context): WallpaperColorHints = INSTANCE.get(context)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user