1 /* 2 * Copyright (C) 2023 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.wm.shell.dagger.pip; 18 19 import android.content.Context; 20 import android.os.Handler; 21 import android.os.SystemClock; 22 23 import com.android.wm.shell.ShellTaskOrganizer; 24 import com.android.wm.shell.WindowManagerShellWrapper; 25 import com.android.wm.shell.common.DisplayController; 26 import com.android.wm.shell.common.ShellExecutor; 27 import com.android.wm.shell.common.SyncTransactionQueue; 28 import com.android.wm.shell.common.SystemWindows; 29 import com.android.wm.shell.common.TaskStackListenerImpl; 30 import com.android.wm.shell.common.annotations.ShellMainThread; 31 import com.android.wm.shell.common.pip.LegacySizeSpecSource; 32 import com.android.wm.shell.common.pip.PipAppOpsListener; 33 import com.android.wm.shell.common.pip.PipDisplayLayoutState; 34 import com.android.wm.shell.common.pip.PipMediaController; 35 import com.android.wm.shell.common.pip.PipSnapAlgorithm; 36 import com.android.wm.shell.common.pip.PipUiEventLogger; 37 import com.android.wm.shell.dagger.WMShellBaseModule; 38 import com.android.wm.shell.dagger.WMSingleton; 39 import com.android.wm.shell.pip.Pip; 40 import com.android.wm.shell.pip.PipAnimationController; 41 import com.android.wm.shell.pip.PipParamsChangedForwarder; 42 import com.android.wm.shell.pip.PipSurfaceTransactionHelper; 43 import com.android.wm.shell.pip.PipTaskOrganizer; 44 import com.android.wm.shell.pip.PipTransitionController; 45 import com.android.wm.shell.pip.PipTransitionState; 46 import com.android.wm.shell.pip.tv.TvPipBoundsAlgorithm; 47 import com.android.wm.shell.pip.tv.TvPipBoundsController; 48 import com.android.wm.shell.pip.tv.TvPipBoundsState; 49 import com.android.wm.shell.pip.tv.TvPipController; 50 import com.android.wm.shell.pip.tv.TvPipMenuController; 51 import com.android.wm.shell.pip.tv.TvPipNotificationController; 52 import com.android.wm.shell.pip.tv.TvPipTaskOrganizer; 53 import com.android.wm.shell.pip.tv.TvPipTransition; 54 import com.android.wm.shell.splitscreen.SplitScreenController; 55 import com.android.wm.shell.sysui.ShellController; 56 import com.android.wm.shell.sysui.ShellInit; 57 import com.android.wm.shell.transition.Transitions; 58 59 import dagger.Module; 60 import dagger.Provides; 61 62 import java.util.Optional; 63 64 /** 65 * Provides TV specific dependencies for Pip. 66 */ 67 @Module(includes = { 68 WMShellBaseModule.class, 69 Pip1SharedModule.class}) 70 public abstract class TvPipModule { 71 @WMSingleton 72 @Provides providePip( Context context, ShellInit shellInit, ShellController shellController, TvPipBoundsState tvPipBoundsState, PipDisplayLayoutState pipDisplayLayoutState, TvPipBoundsAlgorithm tvPipBoundsAlgorithm, TvPipBoundsController tvPipBoundsController, PipAppOpsListener pipAppOpsListener, PipTaskOrganizer pipTaskOrganizer, TvPipMenuController tvPipMenuController, PipMediaController pipMediaController, PipTransitionController pipTransitionController, TvPipNotificationController tvPipNotificationController, TaskStackListenerImpl taskStackListener, PipParamsChangedForwarder pipParamsChangedForwarder, DisplayController displayController, WindowManagerShellWrapper windowManagerShellWrapper, @ShellMainThread Handler mainHandler, @ShellMainThread ShellExecutor mainExecutor)73 static Optional<Pip> providePip( 74 Context context, 75 ShellInit shellInit, 76 ShellController shellController, 77 TvPipBoundsState tvPipBoundsState, 78 PipDisplayLayoutState pipDisplayLayoutState, 79 TvPipBoundsAlgorithm tvPipBoundsAlgorithm, 80 TvPipBoundsController tvPipBoundsController, 81 PipAppOpsListener pipAppOpsListener, 82 PipTaskOrganizer pipTaskOrganizer, 83 TvPipMenuController tvPipMenuController, 84 PipMediaController pipMediaController, 85 PipTransitionController pipTransitionController, 86 TvPipNotificationController tvPipNotificationController, 87 TaskStackListenerImpl taskStackListener, 88 PipParamsChangedForwarder pipParamsChangedForwarder, 89 DisplayController displayController, 90 WindowManagerShellWrapper windowManagerShellWrapper, 91 @ShellMainThread Handler mainHandler, // needed for registerReceiverForAllUsers() 92 @ShellMainThread ShellExecutor mainExecutor) { 93 return Optional.of( 94 TvPipController.create( 95 context, 96 shellInit, 97 shellController, 98 tvPipBoundsState, 99 pipDisplayLayoutState, 100 tvPipBoundsAlgorithm, 101 tvPipBoundsController, 102 pipAppOpsListener, 103 pipTaskOrganizer, 104 pipTransitionController, 105 tvPipMenuController, 106 pipMediaController, 107 tvPipNotificationController, 108 taskStackListener, 109 pipParamsChangedForwarder, 110 displayController, 111 windowManagerShellWrapper, 112 mainHandler, 113 mainExecutor)); 114 } 115 116 @WMSingleton 117 @Provides provideTvPipBoundsController( Context context, @ShellMainThread Handler mainHandler, TvPipBoundsState tvPipBoundsState, TvPipBoundsAlgorithm tvPipBoundsAlgorithm)118 static TvPipBoundsController provideTvPipBoundsController( 119 Context context, 120 @ShellMainThread Handler mainHandler, 121 TvPipBoundsState tvPipBoundsState, 122 TvPipBoundsAlgorithm tvPipBoundsAlgorithm) { 123 return new TvPipBoundsController( 124 context, 125 SystemClock::uptimeMillis, 126 mainHandler, 127 tvPipBoundsState, 128 tvPipBoundsAlgorithm); 129 } 130 131 @WMSingleton 132 @Provides provideTvPipBoundsAlgorithm(Context context, TvPipBoundsState tvPipBoundsState, PipSnapAlgorithm pipSnapAlgorithm, PipDisplayLayoutState pipDisplayLayoutState, LegacySizeSpecSource sizeSpecSource)133 static TvPipBoundsAlgorithm provideTvPipBoundsAlgorithm(Context context, 134 TvPipBoundsState tvPipBoundsState, PipSnapAlgorithm pipSnapAlgorithm, 135 PipDisplayLayoutState pipDisplayLayoutState, LegacySizeSpecSource sizeSpecSource) { 136 return new TvPipBoundsAlgorithm(context, tvPipBoundsState, pipSnapAlgorithm, 137 pipDisplayLayoutState, sizeSpecSource); 138 } 139 140 @WMSingleton 141 @Provides provideTvPipBoundsState(Context context, LegacySizeSpecSource sizeSpecSource, PipDisplayLayoutState pipDisplayLayoutState)142 static TvPipBoundsState provideTvPipBoundsState(Context context, 143 LegacySizeSpecSource sizeSpecSource, PipDisplayLayoutState pipDisplayLayoutState) { 144 return new TvPipBoundsState(context, sizeSpecSource, pipDisplayLayoutState); 145 } 146 147 @WMSingleton 148 @Provides provideSizeSpecSource(Context context, PipDisplayLayoutState pipDisplayLayoutState)149 static LegacySizeSpecSource provideSizeSpecSource(Context context, 150 PipDisplayLayoutState pipDisplayLayoutState) { 151 return new LegacySizeSpecSource(context, pipDisplayLayoutState); 152 } 153 154 // Handler needed for loadDrawableAsync() in PipControlsViewController 155 @WMSingleton 156 @Provides provideTvPipTransition( Context context, ShellInit shellInit, ShellTaskOrganizer shellTaskOrganizer, Transitions transitions, TvPipBoundsState tvPipBoundsState, PipDisplayLayoutState pipDisplayLayoutState, PipTransitionState pipTransitionState, TvPipMenuController pipMenuController, TvPipBoundsAlgorithm tvPipBoundsAlgorithm, PipAnimationController pipAnimationController, PipSurfaceTransactionHelper pipSurfaceTransactionHelper)157 static PipTransitionController provideTvPipTransition( 158 Context context, 159 ShellInit shellInit, 160 ShellTaskOrganizer shellTaskOrganizer, 161 Transitions transitions, 162 TvPipBoundsState tvPipBoundsState, 163 PipDisplayLayoutState pipDisplayLayoutState, 164 PipTransitionState pipTransitionState, 165 TvPipMenuController pipMenuController, 166 TvPipBoundsAlgorithm tvPipBoundsAlgorithm, 167 PipAnimationController pipAnimationController, 168 PipSurfaceTransactionHelper pipSurfaceTransactionHelper) { 169 return new TvPipTransition(context, shellInit, shellTaskOrganizer, transitions, 170 tvPipBoundsState, pipDisplayLayoutState, pipTransitionState, pipMenuController, 171 tvPipBoundsAlgorithm, pipAnimationController, pipSurfaceTransactionHelper, 172 Optional.empty()); 173 } 174 175 @WMSingleton 176 @Provides providesTvPipMenuController( Context context, TvPipBoundsState tvPipBoundsState, SystemWindows systemWindows, @ShellMainThread Handler mainHandler)177 static TvPipMenuController providesTvPipMenuController( 178 Context context, 179 TvPipBoundsState tvPipBoundsState, 180 SystemWindows systemWindows, 181 @ShellMainThread Handler mainHandler) { 182 return new TvPipMenuController(context, tvPipBoundsState, systemWindows, mainHandler); 183 } 184 185 @WMSingleton 186 @Provides provideTvPipNotificationController(Context context, PipMediaController pipMediaController, PipParamsChangedForwarder pipParamsChangedForwarder)187 static TvPipNotificationController provideTvPipNotificationController(Context context, 188 PipMediaController pipMediaController, 189 PipParamsChangedForwarder pipParamsChangedForwarder) { 190 return new TvPipNotificationController(context, pipMediaController, 191 pipParamsChangedForwarder); 192 } 193 194 @WMSingleton 195 @Provides providePipTransitionState()196 static PipTransitionState providePipTransitionState() { 197 return new PipTransitionState(); 198 } 199 200 @WMSingleton 201 @Provides providePipTaskOrganizer(Context context, TvPipMenuController tvPipMenuController, SyncTransactionQueue syncTransactionQueue, TvPipBoundsState tvPipBoundsState, PipDisplayLayoutState pipDisplayLayoutState, PipTransitionState pipTransitionState, TvPipBoundsAlgorithm tvPipBoundsAlgorithm, PipAnimationController pipAnimationController, PipTransitionController pipTransitionController, PipParamsChangedForwarder pipParamsChangedForwarder, PipSurfaceTransactionHelper pipSurfaceTransactionHelper, Optional<SplitScreenController> splitScreenControllerOptional, DisplayController displayController, PipUiEventLogger pipUiEventLogger, ShellTaskOrganizer shellTaskOrganizer, @ShellMainThread ShellExecutor mainExecutor)202 static PipTaskOrganizer providePipTaskOrganizer(Context context, 203 TvPipMenuController tvPipMenuController, 204 SyncTransactionQueue syncTransactionQueue, 205 TvPipBoundsState tvPipBoundsState, 206 PipDisplayLayoutState pipDisplayLayoutState, 207 PipTransitionState pipTransitionState, 208 TvPipBoundsAlgorithm tvPipBoundsAlgorithm, 209 PipAnimationController pipAnimationController, 210 PipTransitionController pipTransitionController, 211 PipParamsChangedForwarder pipParamsChangedForwarder, 212 PipSurfaceTransactionHelper pipSurfaceTransactionHelper, 213 Optional<SplitScreenController> splitScreenControllerOptional, 214 DisplayController displayController, 215 PipUiEventLogger pipUiEventLogger, ShellTaskOrganizer shellTaskOrganizer, 216 @ShellMainThread ShellExecutor mainExecutor) { 217 return new TvPipTaskOrganizer(context, 218 syncTransactionQueue, pipTransitionState, tvPipBoundsState, pipDisplayLayoutState, 219 tvPipBoundsAlgorithm, tvPipMenuController, pipAnimationController, 220 pipSurfaceTransactionHelper, pipTransitionController, pipParamsChangedForwarder, 221 splitScreenControllerOptional, displayController, pipUiEventLogger, 222 shellTaskOrganizer, mainExecutor); 223 } 224 225 @WMSingleton 226 @Provides providePipParamsChangedForwarder()227 static PipParamsChangedForwarder providePipParamsChangedForwarder() { 228 return new PipParamsChangedForwarder(); 229 } 230 231 @WMSingleton 232 @Provides providePipAppOpsListener(Context context, PipTaskOrganizer pipTaskOrganizer, @ShellMainThread ShellExecutor mainExecutor)233 static PipAppOpsListener providePipAppOpsListener(Context context, 234 PipTaskOrganizer pipTaskOrganizer, 235 @ShellMainThread ShellExecutor mainExecutor) { 236 return new PipAppOpsListener(context, pipTaskOrganizer::removePip, mainExecutor); 237 } 238 } 239