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.shared.desktopmode.DesktopModeStatus; 27 import com.android.wm.shell.transition.Transitions; 28 29 import java.util.Optional; 30 31 /** 32 * Class that holds freeform related classes. It serves as the single injection point of 33 * all freeform classes to avoid leaking implementation details to the base Dagger module. 34 */ 35 public class FreeformComponents { 36 public final ShellTaskOrganizer.TaskListener mTaskListener; 37 public final Optional<Transitions.TransitionHandler> mTransitionHandler; 38 public final Optional<Transitions.TransitionObserver> mTransitionObserver; 39 public final Optional<FreeformTaskTransitionStarterInitializer> mTransitionStarterInitializer; 40 41 /** 42 * Creates an instance with the given components. 43 */ FreeformComponents( ShellTaskOrganizer.TaskListener taskListener, Optional<Transitions.TransitionHandler> transitionHandler, Optional<Transitions.TransitionObserver> transitionObserver, Optional<FreeformTaskTransitionStarterInitializer> transitionStarterInitializer)44 public FreeformComponents( 45 ShellTaskOrganizer.TaskListener taskListener, 46 Optional<Transitions.TransitionHandler> transitionHandler, 47 Optional<Transitions.TransitionObserver> transitionObserver, 48 Optional<FreeformTaskTransitionStarterInitializer> transitionStarterInitializer) { 49 mTaskListener = taskListener; 50 mTransitionHandler = transitionHandler; 51 mTransitionObserver = transitionObserver; 52 mTransitionStarterInitializer = transitionStarterInitializer; 53 } 54 55 /** 56 * Returns if this device supports freeform. 57 */ isFreeformEnabled(Context context)58 public static boolean isFreeformEnabled(Context context) { 59 return context.getPackageManager().hasSystemFeature(FEATURE_FREEFORM_WINDOW_MANAGEMENT) 60 || Settings.Global.getInt(context.getContentResolver(), 61 DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT, 0) != 0; 62 } 63 64 /** 65 * Freeform is enabled or we need the components to enable the app handle when desktop mode is 66 * not enabled 67 */ requiresFreeformComponents(Context context)68 public static boolean requiresFreeformComponents(Context context) { 69 return isFreeformEnabled(context) || DesktopModeStatus.overridesShowAppHandle(context); 70 } 71 } 72