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 package com.android.wallpaper
17 
18 import androidx.test.core.app.ApplicationProvider
19 import com.android.customization.model.color.ColorCustomizationManager
20 import com.android.customization.model.theme.OverlayManagerCompat
21 import com.android.customization.module.CustomizationInjector
22 import com.android.customization.module.CustomizationPreferences
23 import com.android.customization.module.logging.TestThemesUserEventLogger
24 import com.android.customization.module.logging.ThemesUserEventLogger
25 import com.android.customization.testing.TestCustomizationInjector
26 import com.android.customization.testing.TestDefaultCustomizationPreferences
27 import com.android.wallpaper.effects.EffectsController
28 import com.android.wallpaper.effects.FakeEffectsController
29 import com.android.wallpaper.module.Injector
30 import com.android.wallpaper.module.PartnerProvider
31 import com.android.wallpaper.module.WallpaperPreferences
32 import com.android.wallpaper.module.logging.TestUserEventLogger
33 import com.android.wallpaper.module.logging.UserEventLogger
34 import com.android.wallpaper.modules.ThemePickerAppModule
35 import com.android.wallpaper.network.Requester
36 import com.android.wallpaper.picker.customization.ui.binder.CustomizationOptionsBinder
37 import com.android.wallpaper.picker.customization.ui.binder.DefaultCustomizationOptionsBinder
38 import com.android.wallpaper.picker.di.modules.EffectsModule
39 import com.android.wallpaper.picker.preview.data.util.FakeLiveWallpaperDownloader
40 import com.android.wallpaper.picker.preview.data.util.LiveWallpaperDownloader
41 import com.android.wallpaper.picker.preview.ui.util.DefaultImageEffectDialogUtil
42 import com.android.wallpaper.picker.preview.ui.util.ImageEffectDialogUtil
43 import com.android.wallpaper.testing.FakeDefaultRequester
44 import com.android.wallpaper.testing.TestPartnerProvider
45 import com.android.wallpaper.util.converter.DefaultWallpaperModelFactory
46 import com.android.wallpaper.util.converter.WallpaperModelFactory
47 import dagger.Binds
48 import dagger.Module
49 import dagger.Provides
50 import dagger.hilt.components.SingletonComponent
51 import dagger.hilt.testing.TestInstallIn
52 import javax.inject.Singleton
53 
54 @Module
55 @TestInstallIn(
56     components = [SingletonComponent::class],
57     replaces = [EffectsModule::class, ThemePickerAppModule::class]
58 )
59 abstract class ThemePickerTestModule {
60     //// WallpaperPicker2 prod
61 
bindInjectornull62     @Binds @Singleton abstract fun bindInjector(impl: TestCustomizationInjector): Injector
63 
64     @Binds @Singleton abstract fun bindUserEventLogger(impl: TestUserEventLogger): UserEventLogger
65 
66     @Binds @Singleton abstract fun bindFakeRequester(impl: FakeDefaultRequester): Requester
67 
68     @Binds
69     @Singleton
70     abstract fun bindThemesUserEventLogger(impl: TestThemesUserEventLogger): ThemesUserEventLogger
71 
72     @Binds
73     @Singleton
74     abstract fun bindWallpaperPrefs(impl: TestDefaultCustomizationPreferences): WallpaperPreferences
75 
76     //// ThemePicker prod
77 
78     @Binds
79     @Singleton
80     abstract fun bindCustomizationInjector(impl: TestCustomizationInjector): CustomizationInjector
81 
82     @Binds
83     @Singleton
84     abstract fun bindCustomizationPrefs(
85         impl: TestDefaultCustomizationPreferences
86     ): CustomizationPreferences
87 
88     @Binds
89     @Singleton
90     abstract fun bindWallpaperModelFactory(
91         impl: DefaultWallpaperModelFactory
92     ): WallpaperModelFactory
93 
94     @Binds
95     @Singleton
96     abstract fun bindLiveWallpaperDownloader(
97         impl: FakeLiveWallpaperDownloader
98     ): LiveWallpaperDownloader
99 
100     @Binds
101     @Singleton
102     abstract fun providePartnerProvider(impl: TestPartnerProvider): PartnerProvider
103 
104     @Binds
105     @Singleton
106     abstract fun bindEffectsWallpaperDialogUtil(
107         impl: DefaultImageEffectDialogUtil
108     ): ImageEffectDialogUtil
109 
110     @Binds
111     @Singleton
112     abstract fun bindEffectsController(impl: FakeEffectsController): EffectsController
113 
114     @Binds
115     @Singleton
116     abstract fun bindCustomizationOptionsBinder(
117         impl: DefaultCustomizationOptionsBinder
118     ): CustomizationOptionsBinder
119 
120     companion object {
121         @Provides
122         @Singleton
123         fun provideColorCustomizationManager(): ColorCustomizationManager {
124             return ColorCustomizationManager.getInstance(
125                 ApplicationProvider.getApplicationContext(),
126                 OverlayManagerCompat(ApplicationProvider.getApplicationContext())
127             )
128         }
129     }
130 }
131