1 /*
2  * Copyright (C) 2022 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.freeform;
18 
19 import static android.content.pm.PackageManager.FEATURE_FREEFORM_WINDOW_MANAGEMENT;
20 import static android.provider.Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT;
21 
22 import android.content.Context;
23 import android.provider.Settings;
24 
25 import com.android.wm.shell.ShellTaskOrganizer;
26 import com.android.wm.shell.transition.Transitions;
27 
28 import java.util.Optional;
29 
30 /**
31  * Class that holds freeform related classes. It serves as the single injection point of
32  * all freeform classes to avoid leaking implementation details to the base Dagger module.
33  */
34 public class FreeformComponents {
35     public final ShellTaskOrganizer.TaskListener mTaskListener;
36     public final Optional<Transitions.TransitionHandler> mTransitionHandler;
37     public final Optional<Transitions.TransitionObserver> mTransitionObserver;
38 
39     /**
40      * Creates an instance with the given components.
41      */
FreeformComponents( ShellTaskOrganizer.TaskListener taskListener, Optional<Transitions.TransitionHandler> transitionHandler, Optional<Transitions.TransitionObserver> transitionObserver)42     public FreeformComponents(
43             ShellTaskOrganizer.TaskListener taskListener,
44             Optional<Transitions.TransitionHandler> transitionHandler,
45             Optional<Transitions.TransitionObserver> transitionObserver) {
46         mTaskListener = taskListener;
47         mTransitionHandler = transitionHandler;
48         mTransitionObserver = transitionObserver;
49     }
50 
51     /**
52      * Returns if this device supports freeform.
53      */
isFreeformEnabled(Context context)54     public static boolean isFreeformEnabled(Context context) {
55         return context.getPackageManager().hasSystemFeature(FEATURE_FREEFORM_WINDOW_MANAGEMENT)
56                 || Settings.Global.getInt(context.getContentResolver(),
57                 DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT, 0) != 0;
58     }
59 }
60