• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 android.window;
18 
19 import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
20 
21 import android.annotation.NonNull;
22 import android.annotation.UserIdInt;
23 import android.app.WindowConfiguration;
24 import android.content.ComponentName;
25 import android.content.Intent;
26 import android.content.pm.ActivityInfo;
27 import android.util.ArraySet;
28 
29 import java.io.PrintWriter;
30 import java.util.List;
31 import java.util.Set;
32 
33 /**
34  * Abstract class to control the policies of the windows that can be displayed on the virtual
35  * display.
36  *
37  * @hide
38  */
39 public abstract class DisplayWindowPolicyController {
40     /**
41      * The window flags that we are interested in.
42      * @see android.view.WindowManager.LayoutParams
43      * @see #keepActivityOnWindowFlagsChanged
44      */
45     private int mWindowFlags;
46 
47     /**
48      * The system window flags that we are interested in.
49      * @see android.view.WindowManager.LayoutParams
50      * @see #keepActivityOnWindowFlagsChanged
51      */
52     private int mSystemWindowFlags;
53 
54     /**
55      * The set of windowing mode that are supported in this display.
56      * @see android.app.WindowConfiguration.WindowingMode
57      */
58     private final Set<Integer> mSupportedWindowingModes = new ArraySet<>();
59 
60     /**
61      * A controller to control the policies of the windows that can be displayed on the virtual
62      * display.
63      */
DisplayWindowPolicyController()64     public DisplayWindowPolicyController() {
65         synchronized (mSupportedWindowingModes) {
66             mSupportedWindowingModes.add(WindowConfiguration.WINDOWING_MODE_FULLSCREEN);
67         }
68     }
69 
70     /**
71      * Returns {@code true} if the given window flags contain the flags that we're interested in.
72      */
isInterestedWindowFlags(int windowFlags, int systemWindowFlags)73     public final boolean isInterestedWindowFlags(int windowFlags, int systemWindowFlags) {
74         return (mWindowFlags & windowFlags) != 0 || (mSystemWindowFlags & systemWindowFlags) != 0;
75     }
76 
77     /**
78      * Sets the window flags that we’re interested in and expected
79      * #keepActivityOnWindowFlagsChanged to be called if any changes.
80      */
setInterestedWindowFlags(int windowFlags, int systemWindowFlags)81     public final void setInterestedWindowFlags(int windowFlags, int systemWindowFlags) {
82         mWindowFlags = windowFlags;
83         mSystemWindowFlags = systemWindowFlags;
84     }
85 
86     /**
87      * Returns {@code true} if the given windowing mode is supported in this display.
88      */
isWindowingModeSupported( @indowConfiguration.WindowingMode int windowingMode)89     public final boolean isWindowingModeSupported(
90             @WindowConfiguration.WindowingMode int windowingMode) {
91         synchronized (mSupportedWindowingModes) {
92             return mSupportedWindowingModes.contains(windowingMode);
93         }
94     }
95 
96     /**
97      * Sets the windowing modes are supported in this display.
98      *
99      * @param supportedWindowingModes The set of
100      * {@link android.app.WindowConfiguration.WindowingMode}.
101      */
setSupportedWindowingModes(Set<Integer> supportedWindowingModes)102     public final void setSupportedWindowingModes(Set<Integer> supportedWindowingModes) {
103         synchronized (mSupportedWindowingModes) {
104             mSupportedWindowingModes.clear();
105             mSupportedWindowingModes.addAll(supportedWindowingModes);
106         }
107     }
108 
109     /**
110      * Returns {@code true} if the given activities can be displayed on this virtual display and
111      * the windowing mode is supported.
112      */
canContainActivities(@onNull List<ActivityInfo> activities, @WindowConfiguration.WindowingMode int windowingMode)113     public abstract boolean canContainActivities(@NonNull List<ActivityInfo> activities,
114             @WindowConfiguration.WindowingMode int windowingMode);
115 
116     /**
117      * Returns {@code true} if the given new task can be launched on this virtual display.
118      */
canActivityBeLaunched(@onNull ActivityInfo activityInfo, Intent intent, @WindowConfiguration.WindowingMode int windowingMode, int launchingFromDisplayId, boolean isNewTask)119     public abstract boolean canActivityBeLaunched(@NonNull ActivityInfo activityInfo, Intent intent,
120             @WindowConfiguration.WindowingMode int windowingMode, int launchingFromDisplayId,
121             boolean isNewTask);
122 
123     /**
124      * Called when an Activity window is layouted with the new changes where contains the
125      * window flags that we’re interested in.
126      * Returns {@code false} if the Activity cannot remain on the display and the activity task will
127      * be moved back to default display.
128      */
keepActivityOnWindowFlagsChanged( ActivityInfo activityInfo, int windowFlags, int systemWindowFlags)129     public abstract boolean keepActivityOnWindowFlagsChanged(
130             ActivityInfo activityInfo, int windowFlags, int systemWindowFlags);
131 
132     /**
133      * Returns {@code true} if the tasks which is on this virtual display can be showed in the
134      * host device of the recently launched activities list.
135      */
canShowTasksInHostDeviceRecents()136     public abstract boolean canShowTasksInHostDeviceRecents();
137 
138     /**
139      * This is called when the top activity of the display is changed.
140      */
onTopActivityChanged(ComponentName topActivity, int uid, @UserIdInt int userId)141     public void onTopActivityChanged(ComponentName topActivity, int uid, @UserIdInt int userId) {}
142 
143     /**
144      * This is called when the apps that contains running activities on the display has changed.
145      * The running activities refer to the non-finishing activities regardless of they are running
146      * in a process.
147      */
onRunningAppsChanged(ArraySet<Integer> runningUids)148     public void onRunningAppsChanged(ArraySet<Integer> runningUids) {}
149 
150     /**
151      * This is called when an Activity is entering PIP.
152      * Returns {@code true} if the Activity is allowed to enter PIP.
153      */
isEnteringPipAllowed(int uid)154     public boolean isEnteringPipAllowed(int uid) {
155         return isWindowingModeSupported(WINDOWING_MODE_PINNED);
156     }
157 
158     /** Dump debug data */
dump(String prefix, final PrintWriter pw)159     public void dump(String prefix, final PrintWriter pw) {
160         pw.println(prefix + "DisplayWindowPolicyController{" + super.toString() + "}");
161         pw.println(prefix + "  mWindowFlags=" + mWindowFlags);
162         pw.println(prefix + "  mSystemWindowFlags=" + mSystemWindowFlags);
163     }
164 }
165