1 /* 2 * Copyright (C) 2021 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.unfold 18 19 import com.android.keyguard.KeyguardUnfoldTransition 20 import com.android.systemui.CoreStartable 21 import com.android.systemui.dagger.SysUISingleton 22 import com.android.systemui.shade.NotificationPanelUnfoldAnimationController 23 import com.android.systemui.statusbar.phone.StatusBarMoveFromCenterAnimationController 24 import com.android.systemui.unfold.dagger.NaturalRotation 25 import com.android.systemui.unfold.dagger.UnfoldBg 26 import com.android.systemui.unfold.util.NaturalRotationUnfoldProgressProvider 27 import com.android.systemui.unfold.util.ScopedUnfoldTransitionProgressProvider 28 import com.android.systemui.unfold.util.UnfoldKeyguardVisibilityManager 29 import com.android.systemui.util.kotlin.getOrNull 30 import dagger.Binds 31 import dagger.BindsInstance 32 import dagger.Module 33 import dagger.Provides 34 import dagger.Subcomponent 35 import dagger.multibindings.ClassKey 36 import dagger.multibindings.IntoMap 37 import dagger.multibindings.IntoSet 38 import java.util.Optional 39 import javax.inject.Named 40 import javax.inject.Qualifier 41 import javax.inject.Scope 42 43 @Scope @MustBeDocumented @Retention(AnnotationRetention.RUNTIME) annotation class SysUIUnfoldScope 44 45 /** 46 * Creates an injectable [SysUIUnfoldComponent] that provides objects that have been scoped with 47 * [@SysUIUnfoldScope]. 48 * 49 * Since [SysUIUnfoldComponent] depends upon: 50 * * [Optional<UnfoldTransitionProgressProvider>] 51 * * [Optional<ScopedUnfoldTransitionProgressProvider>] 52 * * [Optional<NaturalRotationProgressProvider>] 53 * 54 * no objects will get constructed if these parameters are empty. 55 */ 56 @Module(subcomponents = [SysUIUnfoldComponent::class]) 57 class SysUIUnfoldModule { 58 59 /** 60 * Qualifier for dependencies bound in [com.android.systemui.unfold.SysUIUnfoldModule] 61 */ 62 @Qualifier 63 @MustBeDocumented 64 @Retention(AnnotationRetention.RUNTIME) 65 annotation class BoundFromSysUiUnfoldModule 66 67 @Provides 68 @SysUISingleton 69 @BoundFromSysUiUnfoldModule provideSysUIUnfoldComponentnull70 fun provideSysUIUnfoldComponent( 71 provider: Optional<UnfoldTransitionProgressProvider>, 72 rotationProvider: Optional<NaturalRotationUnfoldProgressProvider>, 73 @Named(UNFOLD_STATUS_BAR) scopedProvider: Optional<ScopedUnfoldTransitionProgressProvider>, 74 @UnfoldBg bgProvider: Optional<UnfoldTransitionProgressProvider>, 75 factory: SysUIUnfoldComponent.Factory 76 ): Optional<SysUIUnfoldComponent> { 77 val p1 = provider.getOrNull() 78 val p2 = rotationProvider.getOrNull() 79 val p3 = scopedProvider.getOrNull() 80 val p4 = bgProvider.getOrNull() 81 return if (p1 == null || p2 == null || p3 == null || p4 == null) { 82 Optional.empty() 83 } else { 84 Optional.of(factory.create(p1, p2, p3, p4)) 85 } 86 } 87 } 88 89 @Module 90 interface SysUIUnfoldStartableModule { 91 @Binds 92 @IntoMap 93 @ClassKey(UnfoldInitializationStartable::class) bindsUnfoldInitializationStartablenull94 fun bindsUnfoldInitializationStartable(impl: UnfoldInitializationStartable): CoreStartable 95 } 96 97 @Module 98 abstract class SysUIUnfoldInternalModule { 99 @Binds 100 @IntoSet 101 @SysUIUnfoldScope 102 abstract fun bindsUnfoldLightRevealOverlayAnimation( 103 anim: UnfoldLightRevealOverlayAnimation 104 ): FullscreenLightRevealAnimation 105 106 @Binds 107 @IntoSet 108 @SysUIUnfoldScope 109 abstract fun bindsFoldLightRevealOverlayAnimation( 110 anim: FoldLightRevealOverlayAnimation 111 ): FullscreenLightRevealAnimation 112 113 @Binds 114 @NaturalRotation 115 @SysUIUnfoldScope 116 abstract fun bindNaturalRotationUnfoldProgressProvider( 117 provider: NaturalRotationUnfoldProgressProvider 118 ): UnfoldTransitionProgressProvider 119 } 120 121 @SysUIUnfoldScope 122 @Subcomponent(modules = [SysUIUnfoldInternalModule::class]) 123 interface SysUIUnfoldComponent { 124 125 @Subcomponent.Factory 126 interface Factory { createnull127 fun create( 128 @BindsInstance p1: UnfoldTransitionProgressProvider, 129 @BindsInstance p2: NaturalRotationUnfoldProgressProvider, 130 @BindsInstance p3: ScopedUnfoldTransitionProgressProvider, 131 @BindsInstance @UnfoldBg p4: UnfoldTransitionProgressProvider 132 ): SysUIUnfoldComponent 133 } 134 135 fun getKeyguardUnfoldTransition(): KeyguardUnfoldTransition 136 137 fun getStatusBarMoveFromCenterAnimationController(): StatusBarMoveFromCenterAnimationController 138 139 fun getNotificationPanelUnfoldAnimationController(): NotificationPanelUnfoldAnimationController 140 141 fun getFoldAodAnimationController(): FoldAodAnimationController 142 143 fun getFullScreenLightRevealAnimations(): Set<FullscreenLightRevealAnimation> 144 145 fun getUnfoldTransitionWallpaperController(): UnfoldTransitionWallpaperController 146 147 fun getUnfoldHapticsPlayer(): UnfoldHapticsPlayer 148 149 fun getUnfoldKeyguardVisibilityManager(): UnfoldKeyguardVisibilityManager 150 151 fun getUnfoldLatencyTracker(): UnfoldLatencyTracker 152 153 fun getNaturalRotationUnfoldProgressProvider(): NaturalRotationUnfoldProgressProvider 154 } 155