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.animation.AnimationHandler; 20 import android.content.Context; 21 import android.os.Handler; 22 import android.view.IWindowManager; 23 24 import com.android.systemui.dagger.WMComponent; 25 import com.android.systemui.dagger.WMSingleton; 26 import com.android.wm.shell.ShellTaskOrganizer; 27 import com.android.wm.shell.WindowManagerShellWrapper; 28 import com.android.wm.shell.apppairs.AppPairsController; 29 import com.android.wm.shell.common.DisplayController; 30 import com.android.wm.shell.common.DisplayImeController; 31 import com.android.wm.shell.common.FloatingContentCoordinator; 32 import com.android.wm.shell.common.ShellExecutor; 33 import com.android.wm.shell.common.SyncTransactionQueue; 34 import com.android.wm.shell.common.SystemWindows; 35 import com.android.wm.shell.common.TaskStackListenerImpl; 36 import com.android.wm.shell.common.TransactionPool; 37 import com.android.wm.shell.common.annotations.ChoreographerSfVsync; 38 import com.android.wm.shell.common.annotations.ShellMainThread; 39 import com.android.wm.shell.legacysplitscreen.LegacySplitScreenController; 40 import com.android.wm.shell.onehanded.OneHandedController; 41 import com.android.wm.shell.pip.Pip; 42 import com.android.wm.shell.pip.PipAnimationController; 43 import com.android.wm.shell.pip.PipBoundsAlgorithm; 44 import com.android.wm.shell.pip.PipBoundsState; 45 import com.android.wm.shell.pip.PipMediaController; 46 import com.android.wm.shell.pip.PipSnapAlgorithm; 47 import com.android.wm.shell.pip.PipSurfaceTransactionHelper; 48 import com.android.wm.shell.pip.PipTaskOrganizer; 49 import com.android.wm.shell.pip.PipTransition; 50 import com.android.wm.shell.pip.PipTransitionController; 51 import com.android.wm.shell.pip.PipUiEventLogger; 52 import com.android.wm.shell.pip.phone.PhonePipMenuController; 53 import com.android.wm.shell.pip.phone.PipAppOpsListener; 54 import com.android.wm.shell.pip.phone.PipController; 55 import com.android.wm.shell.pip.phone.PipMotionHelper; 56 import com.android.wm.shell.pip.phone.PipTouchHandler; 57 import com.android.wm.shell.startingsurface.StartingWindowTypeAlgorithm; 58 import com.android.wm.shell.startingsurface.phone.PhoneStartingWindowTypeAlgorithm; 59 import com.android.wm.shell.transition.Transitions; 60 61 import java.util.Optional; 62 63 import dagger.Module; 64 import dagger.Provides; 65 66 /** 67 * Provides dependencies from {@link com.android.wm.shell}, these dependencies are only 68 * accessible from components within the WM subcomponent (can be explicitly exposed to the 69 * SysUIComponent, see {@link WMComponent}). 70 * 71 * This module only defines Shell dependencies for handheld SystemUI implementation. Common 72 * dependencies should go into {@link WMShellBaseModule}. 73 */ 74 @Module(includes = WMShellBaseModule.class) 75 public class WMShellModule { 76 77 // 78 // Internal common - Components used internally by multiple shell features 79 // 80 81 @WMSingleton 82 @Provides provideDisplayImeController(IWindowManager wmService, DisplayController displayController, @ShellMainThread ShellExecutor mainExecutor, TransactionPool transactionPool)83 static DisplayImeController provideDisplayImeController(IWindowManager wmService, 84 DisplayController displayController, @ShellMainThread ShellExecutor mainExecutor, 85 TransactionPool transactionPool) { 86 return new DisplayImeController(wmService, displayController, mainExecutor, 87 transactionPool); 88 } 89 90 // 91 // Split/multiwindow 92 // 93 94 @WMSingleton 95 @Provides provideLegacySplitScreen(Context context, DisplayController displayController, SystemWindows systemWindows, DisplayImeController displayImeController, TransactionPool transactionPool, ShellTaskOrganizer shellTaskOrganizer, SyncTransactionQueue syncQueue, TaskStackListenerImpl taskStackListener, Transitions transitions, @ShellMainThread ShellExecutor mainExecutor, @ChoreographerSfVsync AnimationHandler sfVsyncAnimationHandler)96 static LegacySplitScreenController provideLegacySplitScreen(Context context, 97 DisplayController displayController, SystemWindows systemWindows, 98 DisplayImeController displayImeController, TransactionPool transactionPool, 99 ShellTaskOrganizer shellTaskOrganizer, SyncTransactionQueue syncQueue, 100 TaskStackListenerImpl taskStackListener, Transitions transitions, 101 @ShellMainThread ShellExecutor mainExecutor, 102 @ChoreographerSfVsync AnimationHandler sfVsyncAnimationHandler) { 103 return new LegacySplitScreenController(context, displayController, systemWindows, 104 displayImeController, transactionPool, shellTaskOrganizer, syncQueue, 105 taskStackListener, transitions, mainExecutor, sfVsyncAnimationHandler); 106 } 107 108 @WMSingleton 109 @Provides provideAppPairs(ShellTaskOrganizer shellTaskOrganizer, SyncTransactionQueue syncQueue, DisplayController displayController, @ShellMainThread ShellExecutor mainExecutor, DisplayImeController displayImeController)110 static AppPairsController provideAppPairs(ShellTaskOrganizer shellTaskOrganizer, 111 SyncTransactionQueue syncQueue, DisplayController displayController, 112 @ShellMainThread ShellExecutor mainExecutor, 113 DisplayImeController displayImeController) { 114 return new AppPairsController(shellTaskOrganizer, syncQueue, displayController, 115 mainExecutor, displayImeController); 116 } 117 118 // 119 // Pip 120 // 121 122 @WMSingleton 123 @Provides providePip(Context context, DisplayController displayController, PipAppOpsListener pipAppOpsListener, PipBoundsAlgorithm pipBoundsAlgorithm, PipBoundsState pipBoundsState, PipMediaController pipMediaController, PhonePipMenuController phonePipMenuController, PipTaskOrganizer pipTaskOrganizer, PipTouchHandler pipTouchHandler, PipTransitionController pipTransitionController, WindowManagerShellWrapper windowManagerShellWrapper, TaskStackListenerImpl taskStackListener, Optional<OneHandedController> oneHandedController, @ShellMainThread ShellExecutor mainExecutor)124 static Optional<Pip> providePip(Context context, DisplayController displayController, 125 PipAppOpsListener pipAppOpsListener, PipBoundsAlgorithm pipBoundsAlgorithm, 126 PipBoundsState pipBoundsState, PipMediaController pipMediaController, 127 PhonePipMenuController phonePipMenuController, PipTaskOrganizer pipTaskOrganizer, 128 PipTouchHandler pipTouchHandler, PipTransitionController pipTransitionController, 129 WindowManagerShellWrapper windowManagerShellWrapper, 130 TaskStackListenerImpl taskStackListener, 131 Optional<OneHandedController> oneHandedController, 132 @ShellMainThread ShellExecutor mainExecutor) { 133 return Optional.ofNullable(PipController.create(context, displayController, 134 pipAppOpsListener, pipBoundsAlgorithm, pipBoundsState, pipMediaController, 135 phonePipMenuController, pipTaskOrganizer, pipTouchHandler, pipTransitionController, 136 windowManagerShellWrapper, taskStackListener, oneHandedController, mainExecutor)); 137 } 138 139 @WMSingleton 140 @Provides providePipBoundsState(Context context)141 static PipBoundsState providePipBoundsState(Context context) { 142 return new PipBoundsState(context); 143 } 144 145 @WMSingleton 146 @Provides providePipSnapAlgorithm()147 static PipSnapAlgorithm providePipSnapAlgorithm() { 148 return new PipSnapAlgorithm(); 149 } 150 151 @WMSingleton 152 @Provides providesPipBoundsAlgorithm(Context context, PipBoundsState pipBoundsState, PipSnapAlgorithm pipSnapAlgorithm)153 static PipBoundsAlgorithm providesPipBoundsAlgorithm(Context context, 154 PipBoundsState pipBoundsState, PipSnapAlgorithm pipSnapAlgorithm) { 155 return new PipBoundsAlgorithm(context, pipBoundsState, pipSnapAlgorithm); 156 } 157 158 // Handler is used by Icon.loadDrawableAsync 159 @WMSingleton 160 @Provides providesPipPhoneMenuController(Context context, PipBoundsState pipBoundsState, PipMediaController pipMediaController, SystemWindows systemWindows, @ShellMainThread ShellExecutor mainExecutor, @ShellMainThread Handler mainHandler)161 static PhonePipMenuController providesPipPhoneMenuController(Context context, 162 PipBoundsState pipBoundsState, PipMediaController pipMediaController, 163 SystemWindows systemWindows, 164 @ShellMainThread ShellExecutor mainExecutor, 165 @ShellMainThread Handler mainHandler) { 166 return new PhonePipMenuController(context, pipBoundsState, pipMediaController, 167 systemWindows, mainExecutor, mainHandler); 168 } 169 170 @WMSingleton 171 @Provides providePipTouchHandler(Context context, PhonePipMenuController menuPhoneController, PipBoundsAlgorithm pipBoundsAlgorithm, PipBoundsState pipBoundsState, PipTaskOrganizer pipTaskOrganizer, PipMotionHelper pipMotionHelper, FloatingContentCoordinator floatingContentCoordinator, PipUiEventLogger pipUiEventLogger, @ShellMainThread ShellExecutor mainExecutor)172 static PipTouchHandler providePipTouchHandler(Context context, 173 PhonePipMenuController menuPhoneController, PipBoundsAlgorithm pipBoundsAlgorithm, 174 PipBoundsState pipBoundsState, 175 PipTaskOrganizer pipTaskOrganizer, 176 PipMotionHelper pipMotionHelper, 177 FloatingContentCoordinator floatingContentCoordinator, 178 PipUiEventLogger pipUiEventLogger, 179 @ShellMainThread ShellExecutor mainExecutor) { 180 return new PipTouchHandler(context, menuPhoneController, pipBoundsAlgorithm, 181 pipBoundsState, pipTaskOrganizer, pipMotionHelper, 182 floatingContentCoordinator, pipUiEventLogger, mainExecutor); 183 } 184 185 @WMSingleton 186 @Provides providePipTaskOrganizer(Context context, SyncTransactionQueue syncTransactionQueue, PipBoundsState pipBoundsState, PipBoundsAlgorithm pipBoundsAlgorithm, PhonePipMenuController menuPhoneController, PipAnimationController pipAnimationController, PipSurfaceTransactionHelper pipSurfaceTransactionHelper, PipTransitionController pipTransitionController, Optional<LegacySplitScreenController> splitScreenOptional, DisplayController displayController, PipUiEventLogger pipUiEventLogger, ShellTaskOrganizer shellTaskOrganizer, @ShellMainThread ShellExecutor mainExecutor)187 static PipTaskOrganizer providePipTaskOrganizer(Context context, 188 SyncTransactionQueue syncTransactionQueue, 189 PipBoundsState pipBoundsState, 190 PipBoundsAlgorithm pipBoundsAlgorithm, 191 PhonePipMenuController menuPhoneController, 192 PipAnimationController pipAnimationController, 193 PipSurfaceTransactionHelper pipSurfaceTransactionHelper, 194 PipTransitionController pipTransitionController, 195 Optional<LegacySplitScreenController> splitScreenOptional, 196 DisplayController displayController, 197 PipUiEventLogger pipUiEventLogger, ShellTaskOrganizer shellTaskOrganizer, 198 @ShellMainThread ShellExecutor mainExecutor) { 199 return new PipTaskOrganizer(context, 200 syncTransactionQueue, pipBoundsState, pipBoundsAlgorithm, 201 menuPhoneController, pipAnimationController, pipSurfaceTransactionHelper, 202 pipTransitionController, splitScreenOptional, displayController, pipUiEventLogger, 203 shellTaskOrganizer, mainExecutor); 204 } 205 206 @WMSingleton 207 @Provides providePipAnimationController(PipSurfaceTransactionHelper pipSurfaceTransactionHelper)208 static PipAnimationController providePipAnimationController(PipSurfaceTransactionHelper 209 pipSurfaceTransactionHelper) { 210 return new PipAnimationController(pipSurfaceTransactionHelper); 211 } 212 213 @WMSingleton 214 @Provides providePipTransitionController(Context context, Transitions transitions, ShellTaskOrganizer shellTaskOrganizer, PipAnimationController pipAnimationController, PipBoundsAlgorithm pipBoundsAlgorithm, PipBoundsState pipBoundsState, PhonePipMenuController pipMenuController)215 static PipTransitionController providePipTransitionController(Context context, 216 Transitions transitions, ShellTaskOrganizer shellTaskOrganizer, 217 PipAnimationController pipAnimationController, PipBoundsAlgorithm pipBoundsAlgorithm, 218 PipBoundsState pipBoundsState, PhonePipMenuController pipMenuController) { 219 return new PipTransition(context, pipBoundsState, pipMenuController, 220 pipBoundsAlgorithm, pipAnimationController, transitions, shellTaskOrganizer); 221 } 222 223 @WMSingleton 224 @Provides providePipMotionHelper(Context context, PipBoundsState pipBoundsState, PipTaskOrganizer pipTaskOrganizer, PhonePipMenuController menuController, PipSnapAlgorithm pipSnapAlgorithm, PipTransitionController pipTransitionController, FloatingContentCoordinator floatingContentCoordinator)225 static PipMotionHelper providePipMotionHelper(Context context, 226 PipBoundsState pipBoundsState, PipTaskOrganizer pipTaskOrganizer, 227 PhonePipMenuController menuController, PipSnapAlgorithm pipSnapAlgorithm, 228 PipTransitionController pipTransitionController, 229 FloatingContentCoordinator floatingContentCoordinator) { 230 return new PipMotionHelper(context, pipBoundsState, pipTaskOrganizer, 231 menuController, pipSnapAlgorithm, pipTransitionController, 232 floatingContentCoordinator); 233 } 234 235 // 236 // Starting Windows (Splash Screen) 237 // 238 239 @WMSingleton 240 @Provides provideStartingWindowTypeAlgorithm()241 static StartingWindowTypeAlgorithm provideStartingWindowTypeAlgorithm() { 242 return new PhoneStartingWindowTypeAlgorithm(); 243 } 244 } 245