1 /* 2 * Copyright (C) 2023 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.statusbar.data.repository 18 19 import com.android.systemui.CoreStartable 20 import com.android.systemui.dagger.SysUISingleton 21 import com.android.systemui.dagger.qualifiers.DisplayId 22 import com.android.systemui.statusbar.core.StatusBarInitializer 23 import com.android.systemui.statusbar.phone.fragment.dagger.StatusBarFragmentComponent 24 import dagger.Binds 25 import dagger.Module 26 import dagger.multibindings.ClassKey 27 import dagger.multibindings.IntoMap 28 import dagger.multibindings.IntoSet 29 import java.io.PrintWriter 30 import javax.inject.Inject 31 32 interface StatusBarModeRepositoryStore { 33 val defaultDisplay: StatusBarModePerDisplayRepository forDisplaynull34 fun forDisplay(displayId: Int): StatusBarModePerDisplayRepository 35 } 36 37 @SysUISingleton 38 class StatusBarModeRepositoryImpl 39 @Inject 40 constructor( 41 @DisplayId private val displayId: Int, 42 factory: StatusBarModePerDisplayRepositoryFactory 43 ) : 44 StatusBarModeRepositoryStore, 45 CoreStartable, 46 StatusBarInitializer.OnStatusBarViewInitializedListener { 47 override val defaultDisplay = factory.create(displayId) 48 49 override fun forDisplay(displayId: Int) = 50 if (this.displayId == displayId) { 51 defaultDisplay 52 } else { 53 TODO("b/127878649 implement multi-display state management") 54 } 55 56 override fun start() { 57 defaultDisplay.start() 58 } 59 60 override fun onStatusBarViewInitialized(component: StatusBarFragmentComponent) { 61 defaultDisplay.onStatusBarViewInitialized(component) 62 } 63 64 override fun dump(pw: PrintWriter, args: Array<out String>) { 65 defaultDisplay.dump(pw, args) 66 } 67 } 68 69 @Module 70 interface StatusBarModeRepositoryModule { bindImplnull71 @Binds fun bindImpl(impl: StatusBarModeRepositoryImpl): StatusBarModeRepositoryStore 72 73 @Binds 74 @IntoMap 75 @ClassKey(StatusBarModeRepositoryStore::class) 76 fun bindCoreStartable(impl: StatusBarModeRepositoryImpl): CoreStartable 77 78 @Binds 79 @IntoSet 80 fun bindViewInitListener( 81 impl: StatusBarModeRepositoryImpl 82 ): StatusBarInitializer.OnStatusBarViewInitializedListener 83 } 84