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 18 package com.android.systemui.keyguard 19 20 import android.content.Context 21 import com.android.internal.jank.InteractionJankMonitor 22 import com.android.systemui.CoreStartable 23 import com.android.systemui.biometrics.ui.binder.DeviceEntryUnlockTrackerViewBinder 24 import com.android.systemui.common.ui.ConfigurationState 25 import com.android.systemui.dagger.SysUISingleton 26 import com.android.systemui.dagger.qualifiers.Main 27 import com.android.systemui.deviceentry.domain.interactor.DeviceEntryHapticsInteractor 28 import com.android.systemui.keyguard.domain.interactor.KeyguardClockInteractor 29 import com.android.systemui.keyguard.ui.binder.KeyguardBlueprintViewBinder 30 import com.android.systemui.keyguard.ui.binder.KeyguardJankBinder 31 import com.android.systemui.keyguard.ui.binder.KeyguardRootViewBinder 32 import com.android.systemui.keyguard.ui.binder.LightRevealScrimViewBinder 33 import com.android.systemui.keyguard.ui.view.KeyguardIndicationArea 34 import com.android.systemui.keyguard.ui.view.KeyguardRootView 35 import com.android.systemui.keyguard.ui.viewmodel.KeyguardBlueprintViewModel 36 import com.android.systemui.keyguard.ui.viewmodel.KeyguardClockViewModel 37 import com.android.systemui.keyguard.ui.viewmodel.KeyguardJankViewModel 38 import com.android.systemui.keyguard.ui.viewmodel.KeyguardRootViewModel 39 import com.android.systemui.keyguard.ui.viewmodel.KeyguardSmartspaceViewModel 40 import com.android.systemui.keyguard.ui.viewmodel.LightRevealScrimViewModel 41 import com.android.systemui.keyguard.ui.viewmodel.OccludingAppDeviceEntryMessageViewModel 42 import com.android.systemui.log.LogBuffer 43 import com.android.systemui.log.dagger.KeyguardBlueprintLog 44 import com.android.systemui.plugins.FalsingManager 45 import com.android.systemui.scene.shared.flag.SceneContainerFlag 46 import com.android.systemui.shade.ShadeDisplayAware 47 import com.android.systemui.shade.domain.interactor.ShadeInteractor 48 import com.android.systemui.shared.Flags.ambientAod 49 import com.android.systemui.statusbar.KeyguardIndicationController 50 import com.android.systemui.statusbar.LightRevealScrim 51 import com.android.systemui.statusbar.VibratorHelper 52 import com.android.systemui.statusbar.phone.ScreenOffAnimationController 53 import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager 54 import com.android.systemui.temporarydisplay.chipbar.ChipbarCoordinator 55 import com.android.systemui.wallpapers.domain.interactor.WallpaperFocalAreaInteractor 56 import com.android.systemui.wallpapers.ui.viewmodel.WallpaperFocalAreaViewModel 57 import com.android.systemui.wallpapers.ui.viewmodel.WallpaperViewModel 58 import com.google.android.msdl.domain.MSDLPlayer 59 import java.util.Optional 60 import javax.inject.Inject 61 import kotlinx.coroutines.CoroutineDispatcher 62 import kotlinx.coroutines.DisposableHandle 63 64 /** Binds keyguard views on startup, and also exposes methods to allow rebinding if views change */ 65 @SysUISingleton 66 class KeyguardViewConfigurator 67 @Inject 68 constructor( 69 private val keyguardRootView: KeyguardRootView, 70 private val keyguardRootViewModel: KeyguardRootViewModel, 71 private val keyguardJankViewModel: KeyguardJankViewModel, 72 private val screenOffAnimationController: ScreenOffAnimationController, 73 private val occludingAppDeviceEntryMessageViewModel: OccludingAppDeviceEntryMessageViewModel, 74 private val chipbarCoordinator: ChipbarCoordinator, 75 private val keyguardBlueprintViewModel: KeyguardBlueprintViewModel, 76 @ShadeDisplayAware private val configuration: ConfigurationState, 77 @ShadeDisplayAware private val context: Context, 78 private val keyguardIndicationController: KeyguardIndicationController, 79 private val shadeInteractor: ShadeInteractor, 80 private val interactionJankMonitor: InteractionJankMonitor, 81 private val deviceEntryHapticsInteractor: DeviceEntryHapticsInteractor, 82 private val vibratorHelper: VibratorHelper, 83 private val falsingManager: FalsingManager, 84 private val keyguardClockViewModel: KeyguardClockViewModel, 85 private val smartspaceViewModel: KeyguardSmartspaceViewModel, 86 private val clockInteractor: KeyguardClockInteractor, 87 private val wallpaperFocalAreaInteractor: WallpaperFocalAreaInteractor, 88 private val keyguardViewMediator: KeyguardViewMediator, 89 private val deviceEntryUnlockTrackerViewBinder: Optional<DeviceEntryUnlockTrackerViewBinder>, 90 private val statusBarKeyguardViewManager: StatusBarKeyguardViewManager, 91 private val lightRevealScrimViewModel: LightRevealScrimViewModel, 92 private val lightRevealScrim: LightRevealScrim, 93 private val wallpaperViewModel: WallpaperViewModel, 94 @Main private val mainDispatcher: CoroutineDispatcher, 95 private val msdlPlayer: MSDLPlayer, 96 @KeyguardBlueprintLog private val blueprintLog: LogBuffer, 97 private val wallpaperFocalAreaViewModel: WallpaperFocalAreaViewModel, 98 ) : CoreStartable { 99 100 private var rootViewHandle: DisposableHandle? = null 101 private var jankHandle: DisposableHandle? = null 102 startnull103 override fun start() { 104 bindKeyguardRootView() 105 bindJankViewModel() 106 initializeViews() 107 108 if (ambientAod()) { 109 LightRevealScrimViewBinder.bind( 110 lightRevealScrim, 111 lightRevealScrimViewModel, 112 wallpaperViewModel, 113 ) 114 } 115 116 if (!SceneContainerFlag.isEnabled) { 117 KeyguardBlueprintViewBinder.bind( 118 keyguardRootView, 119 keyguardBlueprintViewModel, 120 keyguardClockViewModel, 121 smartspaceViewModel, 122 blueprintLog, 123 ) 124 } 125 if (deviceEntryUnlockTrackerViewBinder.isPresent) { 126 deviceEntryUnlockTrackerViewBinder.get().bind(keyguardRootView) 127 } 128 } 129 130 /** Initialize views so that corresponding controllers have a view set. */ initializeViewsnull131 private fun initializeViews() { 132 val indicationArea = KeyguardIndicationArea(context, null) 133 keyguardIndicationController.setIndicationArea(indicationArea) 134 } 135 bindKeyguardRootViewnull136 private fun bindKeyguardRootView() { 137 if (SceneContainerFlag.isEnabled) { 138 return 139 } 140 141 rootViewHandle?.dispose() 142 rootViewHandle = 143 KeyguardRootViewBinder.bind( 144 keyguardRootView, 145 keyguardRootViewModel, 146 keyguardBlueprintViewModel, 147 configuration, 148 occludingAppDeviceEntryMessageViewModel, 149 chipbarCoordinator, 150 shadeInteractor, 151 smartspaceViewModel, 152 deviceEntryHapticsInteractor, 153 vibratorHelper, 154 falsingManager, 155 statusBarKeyguardViewManager, 156 mainDispatcher, 157 msdlPlayer, 158 blueprintLog, 159 wallpaperFocalAreaViewModel, 160 ) 161 } 162 bindJankViewModelnull163 private fun bindJankViewModel() { 164 jankHandle?.dispose() 165 jankHandle = 166 KeyguardJankBinder.bind( 167 keyguardRootView, 168 keyguardJankViewModel, 169 interactionJankMonitor, 170 clockInteractor, 171 keyguardViewMediator, 172 mainDispatcher, 173 ) 174 } 175 getKeyguardRootViewnull176 fun getKeyguardRootView() = keyguardRootView 177 } 178