• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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.systemui.display.dagger
18 
19 import com.android.systemui.display.dagger.SystemUIDisplaySubcomponent.PerDisplaySingleton
20 import dagger.BindsInstance
21 import dagger.Subcomponent
22 import javax.inject.Qualifier
23 import javax.inject.Scope
24 import kotlinx.coroutines.CoroutineScope
25 
26 /**
27  * Subcomponent for SysUI classes that should be instantiated once per display.
28  *
29  * All display specific classes should be provided with the @DisplayAware annotation. Once the
30  * display is removed, [displayCoroutineScope] gets cancelled. This means that if classes have some
31  * teardown step it should be executed when the scope is cancelled. Also note that the scope is
32  * cancelled in the background, so any teardown logic should be threadsafe. Cancelling on the main
33  * thread is not feasible as it would cause jank.
34  */
35 @PerDisplaySingleton
36 @Subcomponent(modules = [PerDisplayCommonModule::class])
37 interface SystemUIDisplaySubcomponent {
38 
39     @get:DisplayAware val displayCoroutineScope: CoroutineScope
40 
41     @Subcomponent.Factory
42     interface Factory {
createnull43         fun create(@BindsInstance @DisplayId displayId: Int): SystemUIDisplaySubcomponent
44     }
45 
46     /** Scope annotation for singletons associated to a display. */
47     @MustBeDocumented
48     @Retention(AnnotationRetention.RUNTIME)
49     @Scope
50     annotation class PerDisplaySingleton
51 
52     /** Qualifier used to represent that the object is provided/bound with the proper display. */
53     @Qualifier @Retention(AnnotationRetention.RUNTIME) annotation class DisplayAware
54 
55     /** Annotates the display id inside the subcomponent. */
56     @Qualifier @Retention(AnnotationRetention.RUNTIME) annotation class DisplayId
57 }
58