1 /*
2  * Copyright (C) 2020 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.wmshell;
18 
19 import android.content.Context;
20 import android.os.Handler;
21 import android.view.IWindowManager;
22 
23 import com.android.systemui.car.CarServiceProvider;
24 import com.android.systemui.car.users.CarSystemUIUserUtil;
25 import com.android.systemui.car.wm.CarFullscreenTaskMonitorListener;
26 import com.android.systemui.dagger.qualifiers.Main;
27 import com.android.systemui.wm.DisplaySystemBarsController;
28 import com.android.systemui.wm.MDSystemBarsController;
29 import com.android.wm.shell.ShellTaskOrganizer;
30 import com.android.wm.shell.common.DisplayController;
31 import com.android.wm.shell.common.DisplayInsetsController;
32 import com.android.wm.shell.common.SyncTransactionQueue;
33 import com.android.wm.shell.dagger.DynamicOverride;
34 import com.android.wm.shell.dagger.WMShellBaseModule;
35 import com.android.wm.shell.dagger.WMSingleton;
36 import com.android.wm.shell.fullscreen.FullscreenTaskListener;
37 import com.android.wm.shell.pip.Pip;
38 import com.android.wm.shell.recents.RecentTasksController;
39 import com.android.wm.shell.sysui.ShellInit;
40 import com.android.wm.shell.windowdecor.WindowDecorViewModel;
41 
42 import dagger.BindsOptionalOf;
43 import dagger.Module;
44 import dagger.Provides;
45 
46 import java.util.Optional;
47 
48 /** Provides dependencies from {@link com.android.wm.shell} for CarSystemUI. */
49 @Module(includes = WMShellBaseModule.class)
50 public abstract class CarWMShellModule {
51 
52     @WMSingleton
53     @Provides
provideDisplaySystemBarsController(Context context, IWindowManager wmService, DisplayController displayController, DisplayInsetsController displayInsetsController, @Main Handler mainHandler)54     static DisplaySystemBarsController provideDisplaySystemBarsController(Context context,
55             IWindowManager wmService, DisplayController displayController,
56             DisplayInsetsController displayInsetsController,
57             @Main Handler mainHandler) {
58         return new DisplaySystemBarsController(context, wmService, displayController,
59                 displayInsetsController, mainHandler);
60     }
61 
62     @WMSingleton
63     @Provides
provideMUMDPerDisplayInsetsChangeController( IWindowManager windowManager, @Main Handler mainHandler, Context context)64     static Optional<MDSystemBarsController> provideMUMDPerDisplayInsetsChangeController(
65             IWindowManager windowManager,
66             @Main Handler mainHandler,
67             Context context) {
68         if (CarSystemUIUserUtil.isSecondaryMUMDSystemUI()) {
69             return Optional.of(
70                     new MDSystemBarsController(windowManager, mainHandler, context));
71         }
72         return Optional.empty();
73     }
74 
75     @BindsOptionalOf
optionalPip()76     abstract Pip optionalPip();
77 
78     @WMSingleton
79     @Provides
80     @DynamicOverride
provideFullScreenTaskListener(Context context, CarServiceProvider carServiceProvider, ShellInit shellInit, ShellTaskOrganizer shellTaskOrganizer, SyncTransactionQueue syncQueue, Optional<RecentTasksController> recentTasksOptional, Optional<WindowDecorViewModel> windowDecorViewModelOptional)81     static FullscreenTaskListener provideFullScreenTaskListener(Context context,
82             CarServiceProvider carServiceProvider,
83             ShellInit shellInit,
84             ShellTaskOrganizer shellTaskOrganizer,
85             SyncTransactionQueue syncQueue,
86             Optional<RecentTasksController> recentTasksOptional,
87             Optional<WindowDecorViewModel> windowDecorViewModelOptional) {
88         return new CarFullscreenTaskMonitorListener(context,
89                 carServiceProvider,
90                 shellInit,
91                 shellTaskOrganizer,
92                 syncQueue,
93                 recentTasksOptional,
94                 windowDecorViewModelOptional);
95     }
96 }
97