• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.quickstep.fallback.window
18 
19 import android.content.Context
20 import android.util.Log
21 import android.view.Display
22 import android.view.Display.DEFAULT_DISPLAY
23 import androidx.core.util.valueIterator
24 import com.android.launcher3.dagger.ApplicationContext
25 import com.android.launcher3.dagger.LauncherAppSingleton
26 import com.android.launcher3.util.DaggerSingletonObject
27 import com.android.launcher3.util.DaggerSingletonTracker
28 import com.android.launcher3.util.WallpaperColorHints
29 import com.android.quickstep.DisplayModel
30 import com.android.quickstep.FallbackWindowInterface
31 import com.android.quickstep.RecentsAnimationDeviceState
32 import com.android.quickstep.TaskAnimationManager
33 import com.android.quickstep.dagger.QuickstepBaseAppComponent
34 import com.android.quickstep.fallback.window.RecentsDisplayModel.RecentsDisplayResource
35 import com.android.quickstep.fallback.window.RecentsWindowFlags.Companion.enableOverviewInWindow
36 import java.io.PrintWriter
37 import javax.inject.Inject
38 
39 @LauncherAppSingleton
40 class RecentsDisplayModel
41 @Inject
42 constructor(
43     @ApplicationContext context: Context,
44     private val wallpaperColorHints: WallpaperColorHints,
45     tracker: DaggerSingletonTracker,
46 ) : DisplayModel<RecentsDisplayResource>(context) {
47 
48     companion object {
49         private const val TAG = "RecentsDisplayModel"
50         private const val DEBUG = false
51 
52         @JvmStatic
53         val INSTANCE: DaggerSingletonObject<RecentsDisplayModel> =
54             DaggerSingletonObject<RecentsDisplayModel>(
55                 QuickstepBaseAppComponent::getRecentsDisplayModel
56             )
57     }
58 
59     init {
60         if (enableOverviewInWindow) {
61             initializeDisplays()
62         } else {
63             // Always create resource for default display
64             storeDisplayResource(DEFAULT_DISPLAY)
65         }
<lambda>null66         tracker.addCloseable { destroy() }
67     }
68 
createDisplayResourcenull69     override fun createDisplayResource(display: Display): RecentsDisplayResource {
70         return RecentsDisplayResource(
71             display.displayId,
72             context.createDisplayContext(display),
73             wallpaperColorHints.hints,
74         )
75     }
76 
getRecentsWindowManagernull77     fun getRecentsWindowManager(displayId: Int): RecentsWindowManager? {
78         if (DEBUG) Log.d(TAG, "getRecentsWindowManager for display $displayId")
79         return getDisplayResource(displayId)?.recentsWindowManager
80     }
81 
getFallbackWindowInterfacenull82     fun getFallbackWindowInterface(displayId: Int): FallbackWindowInterface? {
83         if (DEBUG) Log.d(TAG, "getFallbackWindowInterface for display $displayId")
84         return getDisplayResource(displayId)?.fallbackWindowInterface
85     }
86 
getTaskAnimationManagernull87     fun getTaskAnimationManager(displayId: Int): TaskAnimationManager? {
88         return getDisplayResource(displayId)?.taskAnimationManager
89     }
90 
91     val activeDisplayResources: Iterable<RecentsDisplayResource>
92         get() =
93             object : Iterable<RecentsDisplayResource> {
iteratornull94                 override fun iterator() = displayResourceArray.valueIterator()
95             }
96 
97     data class RecentsDisplayResource(
98         val displayId: Int,
99         val displayContext: Context,
100         val wallpaperColorHints: Int,
101     ) : DisplayResource() {
102         val recentsWindowManager =
103             if (enableOverviewInWindow) RecentsWindowManager(displayContext, wallpaperColorHints)
104             else null
105         val fallbackWindowInterface =
106             if (enableOverviewInWindow) FallbackWindowInterface(recentsWindowManager) else null
107         val taskAnimationManager =
108             TaskAnimationManager(
109                 displayContext,
110                 RecentsAnimationDeviceState.INSTANCE.get(displayContext),
111                 displayId,
112             )
113 
114         override fun cleanup() {
115             recentsWindowManager?.destroy()
116         }
117 
118         override fun dump(prefix: String, writer: PrintWriter) {
119             writer.println("${prefix}RecentsDisplayResource:")
120 
121             writer.println("${prefix}\tdisplayId=${displayId}")
122             writer.println("${prefix}\tdisplayContext=${displayContext}")
123             writer.println("${prefix}\twallpaperColorHints=${wallpaperColorHints}")
124             writer.println("${prefix}\trecentsWindowManager=${recentsWindowManager}")
125             writer.println("${prefix}\tfallbackWindowInterface=${fallbackWindowInterface}")
126         }
127     }
128 }
129