1 /*
2  * Copyright (C) 2022 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.screenshot.dagger;
18 
19 import static com.android.systemui.Flags.screenshotShelfUi2;
20 
21 import android.app.Service;
22 import android.view.accessibility.AccessibilityManager;
23 
24 import com.android.systemui.dagger.SysUISingleton;
25 import com.android.systemui.screenshot.ImageCapture;
26 import com.android.systemui.screenshot.ImageCaptureImpl;
27 import com.android.systemui.screenshot.LegacyScreenshotViewProxy;
28 import com.android.systemui.screenshot.ScreenshotPolicy;
29 import com.android.systemui.screenshot.ScreenshotPolicyImpl;
30 import com.android.systemui.screenshot.ScreenshotShelfViewProxy;
31 import com.android.systemui.screenshot.ScreenshotSoundController;
32 import com.android.systemui.screenshot.ScreenshotSoundControllerImpl;
33 import com.android.systemui.screenshot.ScreenshotSoundProvider;
34 import com.android.systemui.screenshot.ScreenshotSoundProviderImpl;
35 import com.android.systemui.screenshot.ScreenshotViewProxy;
36 import com.android.systemui.screenshot.TakeScreenshotExecutor;
37 import com.android.systemui.screenshot.TakeScreenshotExecutorImpl;
38 import com.android.systemui.screenshot.TakeScreenshotService;
39 import com.android.systemui.screenshot.appclips.AppClipsScreenshotHelperService;
40 import com.android.systemui.screenshot.appclips.AppClipsService;
41 import com.android.systemui.screenshot.message.MessageModule;
42 import com.android.systemui.screenshot.policy.ScreenshotPolicyModule;
43 import com.android.systemui.screenshot.proxy.SystemUiProxyModule;
44 import com.android.systemui.screenshot.ui.viewmodel.ScreenshotViewModel;
45 
46 import dagger.Binds;
47 import dagger.Module;
48 import dagger.Provides;
49 import dagger.multibindings.ClassKey;
50 import dagger.multibindings.IntoMap;
51 
52 /**
53  * Defines injectable resources for Screenshots
54  */
55 @Module(includes = {ScreenshotPolicyModule.class, SystemUiProxyModule.class, MessageModule.class})
56 public abstract class ScreenshotModule {
57 
58     @Binds
59     @IntoMap
60     @ClassKey(TakeScreenshotService.class)
bindTakeScreenshotService(TakeScreenshotService service)61     abstract Service bindTakeScreenshotService(TakeScreenshotService service);
62 
63     @Binds
64     @SysUISingleton
bindTakeScreenshotExecutor( TakeScreenshotExecutorImpl impl)65     abstract TakeScreenshotExecutor bindTakeScreenshotExecutor(
66             TakeScreenshotExecutorImpl impl);
67 
68     @Binds
bindScreenshotPolicyImpl(ScreenshotPolicyImpl impl)69     abstract ScreenshotPolicy bindScreenshotPolicyImpl(ScreenshotPolicyImpl impl);
70 
71     @Binds
bindImageCaptureImpl(ImageCaptureImpl capture)72     abstract ImageCapture bindImageCaptureImpl(ImageCaptureImpl capture);
73 
74     @Binds
75     @IntoMap
76     @ClassKey(AppClipsScreenshotHelperService.class)
bindAppClipsScreenshotHelperService(AppClipsScreenshotHelperService service)77     abstract Service bindAppClipsScreenshotHelperService(AppClipsScreenshotHelperService service);
78 
79     @Binds
80     @IntoMap
81     @ClassKey(AppClipsService.class)
bindAppClipsService(AppClipsService service)82     abstract Service bindAppClipsService(AppClipsService service);
83 
84     @Binds
bindScreenshotSoundProvider( ScreenshotSoundProviderImpl screenshotSoundProviderImpl)85     abstract ScreenshotSoundProvider bindScreenshotSoundProvider(
86             ScreenshotSoundProviderImpl screenshotSoundProviderImpl);
87 
88     @Binds
bindScreenshotSoundController( ScreenshotSoundControllerImpl screenshotSoundProviderImpl)89     abstract ScreenshotSoundController bindScreenshotSoundController(
90             ScreenshotSoundControllerImpl screenshotSoundProviderImpl);
91 
92     @Provides
93     @SysUISingleton
providesScreenshotViewModel( AccessibilityManager accessibilityManager)94     static ScreenshotViewModel providesScreenshotViewModel(
95             AccessibilityManager accessibilityManager) {
96         return new ScreenshotViewModel(accessibilityManager);
97     }
98 
99     @Provides
providesScreenshotViewProxyFactory( ScreenshotShelfViewProxy.Factory shelfScreenshotViewProxyFactory, LegacyScreenshotViewProxy.Factory legacyScreenshotViewProxyFactory)100     static ScreenshotViewProxy.Factory providesScreenshotViewProxyFactory(
101             ScreenshotShelfViewProxy.Factory shelfScreenshotViewProxyFactory,
102             LegacyScreenshotViewProxy.Factory legacyScreenshotViewProxyFactory) {
103         if (screenshotShelfUi2()) {
104             return shelfScreenshotViewProxyFactory;
105         } else {
106             return legacyScreenshotViewProxyFactory;
107         }
108     }
109 }
110