• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 com.android.wm.shell.common.pip.PipUtils;
20 import com.android.wm.shell.dagger.WMSingleton;
21 import com.android.wm.shell.pip.Pip;
22 import com.android.wm.shell.pip.PipTransitionController;
23 import com.android.wm.shell.pip2.phone.PipController;
24 import com.android.wm.shell.pip2.phone.PipTransition;
25 
26 import dagger.Module;
27 import dagger.Provides;
28 
29 import java.util.Optional;
30 
31 /**
32  * Provides dependencies for external components / modules reference PiP and extracts away the
33  * selection of legacy and new PiP implementation.
34  */
35 @Module(includes = {
36         Pip1Module.class,
37         Pip2Module.class
38 })
39 public abstract class PipModule {
40     @WMSingleton
41     @Provides
providePipTransitionController( com.android.wm.shell.pip.PipTransition legacyPipTransition, PipTransition newPipTransition)42     static PipTransitionController providePipTransitionController(
43             com.android.wm.shell.pip.PipTransition legacyPipTransition,
44             PipTransition newPipTransition) {
45         if (PipUtils.isPip2ExperimentEnabled()) {
46             return newPipTransition;
47         } else {
48             return legacyPipTransition;
49         }
50     }
51 
52     @WMSingleton
53     @Provides
providePip( Optional<com.android.wm.shell.pip.phone.PipController.PipImpl> pip1, Optional<PipController.PipImpl> pip2)54     static Optional<Pip> providePip(
55             Optional<com.android.wm.shell.pip.phone.PipController.PipImpl> pip1,
56             Optional<PipController.PipImpl> pip2) {
57         if (PipUtils.isPip2ExperimentEnabled()) {
58             return Optional.ofNullable(pip2.orElse(null));
59 
60         } else {
61             return Optional.ofNullable(pip1.orElse(null));
62         }
63     }
64 }
65