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.annotation.NonNull; 20 import android.content.Context; 21 import android.os.Handler; 22 23 import com.android.wm.shell.ShellTaskOrganizer; 24 import com.android.wm.shell.common.DisplayController; 25 import com.android.wm.shell.common.DisplayInsetsController; 26 import com.android.wm.shell.common.FloatingContentCoordinator; 27 import com.android.wm.shell.common.ShellExecutor; 28 import com.android.wm.shell.common.SystemWindows; 29 import com.android.wm.shell.common.TaskStackListenerImpl; 30 import com.android.wm.shell.common.pip.PipBoundsAlgorithm; 31 import com.android.wm.shell.common.pip.PipBoundsState; 32 import com.android.wm.shell.common.pip.PipDisplayLayoutState; 33 import com.android.wm.shell.common.pip.PipMediaController; 34 import com.android.wm.shell.common.pip.PipPerfHintController; 35 import com.android.wm.shell.common.pip.PipSnapAlgorithm; 36 import com.android.wm.shell.common.pip.PipUiEventLogger; 37 import com.android.wm.shell.common.pip.PipUtils; 38 import com.android.wm.shell.common.pip.SizeSpecSource; 39 import com.android.wm.shell.dagger.WMShellBaseModule; 40 import com.android.wm.shell.dagger.WMSingleton; 41 import com.android.wm.shell.pip2.phone.PhonePipMenuController; 42 import com.android.wm.shell.pip2.phone.PipController; 43 import com.android.wm.shell.pip2.phone.PipMotionHelper; 44 import com.android.wm.shell.pip2.phone.PipScheduler; 45 import com.android.wm.shell.pip2.phone.PipTouchHandler; 46 import com.android.wm.shell.pip2.phone.PipTransition; 47 import com.android.wm.shell.pip2.phone.PipTransitionState; 48 import com.android.wm.shell.shared.annotations.ShellMainThread; 49 import com.android.wm.shell.sysui.ShellCommandHandler; 50 import com.android.wm.shell.sysui.ShellController; 51 import com.android.wm.shell.sysui.ShellInit; 52 import com.android.wm.shell.transition.Transitions; 53 54 import dagger.Module; 55 import dagger.Provides; 56 57 import java.util.Optional; 58 59 /** 60 * Provides dependencies from {@link com.android.wm.shell.pip2}, this implementation is meant to be 61 * the successor of its sibling {@link Pip1Module}. 62 */ 63 @Module(includes = WMShellBaseModule.class) 64 public abstract class Pip2Module { 65 @WMSingleton 66 @Provides providePipTransition(Context context, @NonNull ShellInit shellInit, @NonNull ShellTaskOrganizer shellTaskOrganizer, @NonNull Transitions transitions, PipBoundsState pipBoundsState, PipBoundsAlgorithm pipBoundsAlgorithm, Optional<PipController> pipController, PipTouchHandler pipTouchHandler, @NonNull PipScheduler pipScheduler, @NonNull PipTransitionState pipStackListenerController)67 static PipTransition providePipTransition(Context context, 68 @NonNull ShellInit shellInit, 69 @NonNull ShellTaskOrganizer shellTaskOrganizer, 70 @NonNull Transitions transitions, 71 PipBoundsState pipBoundsState, 72 PipBoundsAlgorithm pipBoundsAlgorithm, 73 Optional<PipController> pipController, 74 PipTouchHandler pipTouchHandler, 75 @NonNull PipScheduler pipScheduler, 76 @NonNull PipTransitionState pipStackListenerController) { 77 return new PipTransition(context, shellInit, shellTaskOrganizer, transitions, 78 pipBoundsState, null, pipBoundsAlgorithm, pipScheduler, 79 pipStackListenerController); 80 } 81 82 @WMSingleton 83 @Provides providePipController(Context context, ShellInit shellInit, ShellCommandHandler shellCommandHandler, ShellController shellController, DisplayController displayController, DisplayInsetsController displayInsetsController, PipBoundsState pipBoundsState, PipBoundsAlgorithm pipBoundsAlgorithm, PipDisplayLayoutState pipDisplayLayoutState, PipScheduler pipScheduler, TaskStackListenerImpl taskStackListener, ShellTaskOrganizer shellTaskOrganizer, PipTransitionState pipTransitionState, @ShellMainThread ShellExecutor mainExecutor)84 static Optional<PipController> providePipController(Context context, 85 ShellInit shellInit, 86 ShellCommandHandler shellCommandHandler, 87 ShellController shellController, 88 DisplayController displayController, 89 DisplayInsetsController displayInsetsController, 90 PipBoundsState pipBoundsState, 91 PipBoundsAlgorithm pipBoundsAlgorithm, 92 PipDisplayLayoutState pipDisplayLayoutState, 93 PipScheduler pipScheduler, 94 TaskStackListenerImpl taskStackListener, 95 ShellTaskOrganizer shellTaskOrganizer, 96 PipTransitionState pipTransitionState, 97 @ShellMainThread ShellExecutor mainExecutor) { 98 if (!PipUtils.isPip2ExperimentEnabled()) { 99 return Optional.empty(); 100 } else { 101 return Optional.ofNullable(PipController.create( 102 context, shellInit, shellCommandHandler, shellController, displayController, 103 displayInsetsController, pipBoundsState, pipBoundsAlgorithm, 104 pipDisplayLayoutState, pipScheduler, taskStackListener, shellTaskOrganizer, 105 pipTransitionState, mainExecutor)); 106 } 107 } 108 109 @WMSingleton 110 @Provides providePipScheduler(Context context, PipBoundsState pipBoundsState, @ShellMainThread ShellExecutor mainExecutor, PipTransitionState pipTransitionState)111 static PipScheduler providePipScheduler(Context context, 112 PipBoundsState pipBoundsState, 113 @ShellMainThread ShellExecutor mainExecutor, 114 PipTransitionState pipTransitionState) { 115 return new PipScheduler(context, pipBoundsState, mainExecutor, pipTransitionState); 116 } 117 118 @WMSingleton 119 @Provides providePipPhoneMenuController(Context context, PipBoundsState pipBoundsState, PipMediaController pipMediaController, SystemWindows systemWindows, PipUiEventLogger pipUiEventLogger, @ShellMainThread ShellExecutor mainExecutor, @ShellMainThread Handler mainHandler)120 static PhonePipMenuController providePipPhoneMenuController(Context context, 121 PipBoundsState pipBoundsState, PipMediaController pipMediaController, 122 SystemWindows systemWindows, 123 PipUiEventLogger pipUiEventLogger, 124 @ShellMainThread ShellExecutor mainExecutor, 125 @ShellMainThread Handler mainHandler) { 126 return new PhonePipMenuController(context, pipBoundsState, pipMediaController, 127 systemWindows, pipUiEventLogger, mainExecutor, mainHandler); 128 } 129 130 131 @WMSingleton 132 @Provides providePipTouchHandler(Context context, ShellInit shellInit, ShellCommandHandler shellCommandHandler, PhonePipMenuController menuPhoneController, PipBoundsAlgorithm pipBoundsAlgorithm, @NonNull PipBoundsState pipBoundsState, @NonNull PipTransitionState pipTransitionState, @NonNull PipScheduler pipScheduler, @NonNull SizeSpecSource sizeSpecSource, PipMotionHelper pipMotionHelper, FloatingContentCoordinator floatingContentCoordinator, PipUiEventLogger pipUiEventLogger, @ShellMainThread ShellExecutor mainExecutor, Optional<PipPerfHintController> pipPerfHintControllerOptional)133 static PipTouchHandler providePipTouchHandler(Context context, 134 ShellInit shellInit, 135 ShellCommandHandler shellCommandHandler, 136 PhonePipMenuController menuPhoneController, 137 PipBoundsAlgorithm pipBoundsAlgorithm, 138 @NonNull PipBoundsState pipBoundsState, 139 @NonNull PipTransitionState pipTransitionState, 140 @NonNull PipScheduler pipScheduler, 141 @NonNull SizeSpecSource sizeSpecSource, 142 PipMotionHelper pipMotionHelper, 143 FloatingContentCoordinator floatingContentCoordinator, 144 PipUiEventLogger pipUiEventLogger, 145 @ShellMainThread ShellExecutor mainExecutor, 146 Optional<PipPerfHintController> pipPerfHintControllerOptional) { 147 return new PipTouchHandler(context, shellInit, shellCommandHandler, menuPhoneController, 148 pipBoundsAlgorithm, pipBoundsState, pipTransitionState, pipScheduler, 149 sizeSpecSource, pipMotionHelper, floatingContentCoordinator, pipUiEventLogger, 150 mainExecutor, pipPerfHintControllerOptional); 151 } 152 153 @WMSingleton 154 @Provides providePipMotionHelper(Context context, PipBoundsState pipBoundsState, PhonePipMenuController menuController, PipSnapAlgorithm pipSnapAlgorithm, FloatingContentCoordinator floatingContentCoordinator, PipScheduler pipScheduler, Optional<PipPerfHintController> pipPerfHintControllerOptional, PipBoundsAlgorithm pipBoundsAlgorithm, PipTransitionState pipTransitionState)155 static PipMotionHelper providePipMotionHelper(Context context, 156 PipBoundsState pipBoundsState, PhonePipMenuController menuController, 157 PipSnapAlgorithm pipSnapAlgorithm, 158 FloatingContentCoordinator floatingContentCoordinator, 159 PipScheduler pipScheduler, 160 Optional<PipPerfHintController> pipPerfHintControllerOptional, 161 PipBoundsAlgorithm pipBoundsAlgorithm, 162 PipTransitionState pipTransitionState) { 163 return new PipMotionHelper(context, pipBoundsState, menuController, pipSnapAlgorithm, 164 floatingContentCoordinator, pipScheduler, pipPerfHintControllerOptional, 165 pipBoundsAlgorithm, pipTransitionState); 166 } 167 168 @WMSingleton 169 @Provides providePipTransitionState(@hellMainThread Handler handler)170 static PipTransitionState providePipTransitionState(@ShellMainThread Handler handler) { 171 return new PipTransitionState(handler); 172 } 173 } 174