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