• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.IntDef;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.app.ActivityManager;
23 import android.app.TaskInfo;
24 import android.content.pm.ActivityInfo;
25 import android.graphics.Rect;
26 import android.os.IBinder;
27 import android.os.Parcel;
28 import android.os.Parcelable;
29 import android.os.RemoteException;
30 import android.view.SurfaceControl;
31 import android.view.WindowInsets;
32 import android.view.WindowInsets.Type.InsetsType;
33 import android.view.WindowManager;
34 
35 /**
36  * Information you can retrieve about a starting window of a particular task that is currently
37  * start in the system.
38  * @hide
39  */
40 public final class StartingWindowInfo implements Parcelable {
41     /**
42      * Prefer nothing or not care the type of starting window.
43      * @hide
44      */
45     public static final int STARTING_WINDOW_TYPE_NONE = 0;
46     /**
47      * Prefer splash screen starting window.
48      * @hide
49      */
50     public static final int STARTING_WINDOW_TYPE_SPLASH_SCREEN = 1;
51     /**
52      * Prefer snapshot starting window.
53      * @hide
54      */
55     public static final int STARTING_WINDOW_TYPE_SNAPSHOT = 2;
56     /**
57      * Prefer solid color splash screen starting window.
58      * @hide
59      */
60     public static final int STARTING_WINDOW_TYPE_SOLID_COLOR_SPLASH_SCREEN = 3;
61 
62     /** @hide **/
63     public static final int STARTING_WINDOW_TYPE_LEGACY_SPLASH_SCREEN = 4;
64 
65     public static final int STARTING_WINDOW_TYPE_WINDOWLESS = 5;
66 
67     /**
68      * @hide
69      */
70     @IntDef(flag = true, prefix = "STARTING_WINDOW_TYPE_", value = {
71             STARTING_WINDOW_TYPE_NONE,
72             STARTING_WINDOW_TYPE_SPLASH_SCREEN,
73             STARTING_WINDOW_TYPE_SNAPSHOT,
74             STARTING_WINDOW_TYPE_SOLID_COLOR_SPLASH_SCREEN,
75             STARTING_WINDOW_TYPE_LEGACY_SPLASH_SCREEN,
76             STARTING_WINDOW_TYPE_WINDOWLESS
77     })
78     public @interface StartingWindowType {}
79 
80     /**
81      * The {@link TaskInfo} from this task.
82      * <p>Note that the configuration of this taskInfo could be from the top activity of its task.
83      * Because only activity contains persisted configuration (e.g. night mode, language). Besides,
84      * it can also be used for activity level snapshot.
85      */
86     @NonNull
87     public ActivityManager.RunningTaskInfo taskInfo;
88 
89     /** The bounds of the target task. */
90     @NonNull
91     public final Rect taskBounds = new Rect();
92 
93     /**
94      * The {@link ActivityInfo} of the target activity which to create the starting window.
95      * It can be null if the info is the same as the top in task info.
96      * @hide
97      */
98     @Nullable
99     public ActivityInfo targetActivityInfo;
100 
101     /**
102      * LayoutParams of MainWindow
103      * @hide
104      */
105     @Nullable
106     public WindowManager.LayoutParams mainWindowLayoutParams;
107 
108     /**
109      * @hide
110      */
111     @IntDef(flag = true, prefix = "TYPE_PARAMETER_", value = {
112             TYPE_PARAMETER_NEW_TASK,
113             TYPE_PARAMETER_TASK_SWITCH,
114             TYPE_PARAMETER_PROCESS_RUNNING,
115             TYPE_PARAMETER_ALLOW_TASK_SNAPSHOT,
116             TYPE_PARAMETER_ACTIVITY_CREATED,
117             TYPE_PARAMETER_USE_SOLID_COLOR_SPLASH_SCREEN,
118             TYPE_PARAMETER_ALLOW_HANDLE_SOLID_COLOR_SCREEN,
119             TYPE_PARAMETER_WINDOWLESS,
120             TYPE_PARAMETER_LEGACY_SPLASH_SCREEN
121     })
122     public @interface StartingTypeParams {}
123 
124     /**
125      * The parameters of the starting window...
126      * @hide
127      */
128     public static final int TYPE_PARAMETER_NEW_TASK = 0x00000001;
129     /** @hide */
130     public static final int TYPE_PARAMETER_TASK_SWITCH = 0x00000002;
131     /** @hide */
132     public static final int TYPE_PARAMETER_PROCESS_RUNNING = 0x00000004;
133     /** @hide */
134     public static final int TYPE_PARAMETER_ALLOW_TASK_SNAPSHOT = 0x00000008;
135     /** @hide */
136     public static final int TYPE_PARAMETER_ACTIVITY_CREATED = 0x00000010;
137     /** @hide */
138     public static final int TYPE_PARAMETER_USE_SOLID_COLOR_SPLASH_SCREEN = 0x00000020;
139     /**
140      * The parameter which indicates if the activity has finished drawing.
141      * @hide
142      */
143     public static final int TYPE_PARAMETER_ACTIVITY_DRAWN = 0x00000040;
144     /**
145      * Application will receive the
146      * {@link
147      * android.window.SplashScreen.OnExitAnimationListener#onSplashScreenExit(SplashScreenView)}
148      * callback, even when the splash screen only shows a solid color.
149      *
150      * @hide
151      */
152     public static final int TYPE_PARAMETER_ALLOW_HANDLE_SOLID_COLOR_SCREEN = 0x00000080;
153 
154     /**
155      * Windowless surface
156      */
157     public static final int TYPE_PARAMETER_WINDOWLESS = 0x00000100;
158 
159     /**
160      * Application has set Window_windowSplashScreenBehavior to
161      * SPLASH_SCREEN_BEHAVIOR_ICON_PREFERRED.
162      * @hide
163      */
164     public static final int TYPE_PARAMETER_APP_PREFERS_ICON = 0x00000200;
165 
166     /**
167      * Application is allowed to use the legacy splash screen
168      * @hide
169      */
170     public static final int TYPE_PARAMETER_LEGACY_SPLASH_SCREEN = 0x80000000;
171 
172     /**
173      * The parameters which effect the starting window type.
174      * @see android.window.StartingWindowInfo.StartingTypeParams
175      * @hide
176      */
177     public int startingWindowTypeParameter;
178 
179     /**
180      * Specifies a theme for the splash screen.
181      * @hide
182      */
183     public int splashScreenThemeResId;
184 
185     /**
186      * Is keyguard occluded on default display.
187      * @hide
188      */
189     public boolean isKeyguardOccluded = false;
190 
191     /**
192      * TaskSnapshot.
193      * @hide
194      */
195     public TaskSnapshot taskSnapshot;
196 
197     @InsetsType public int requestedVisibleTypes = WindowInsets.Type.defaultVisible();
198 
199     /**
200      * App token where the starting window should add to.
201      */
202     public IBinder appToken;
203 
204     public IWindowlessStartingSurfaceCallback windowlessStartingSurfaceCallback;
205 
206     /**
207      * The root surface where windowless surface should attach on.
208      */
209     public SurfaceControl rootSurface;
210 
211     /**
212      * Notify windowless surface is created.
213      * @param addedSurface Created surface.
214      */
notifyAddComplete(SurfaceControl addedSurface)215     public void notifyAddComplete(SurfaceControl addedSurface) {
216         if (windowlessStartingSurfaceCallback != null) {
217             try {
218                 windowlessStartingSurfaceCallback.onSurfaceAdded(addedSurface);
219             } catch (RemoteException e) {
220                 //
221             }
222         }
223     }
224 
StartingWindowInfo()225     public StartingWindowInfo() {
226 
227     }
228 
StartingWindowInfo(@onNull Parcel source)229     private StartingWindowInfo(@NonNull Parcel source) {
230         readFromParcel(source);
231     }
232 
233     /**
234      * Return whether the application allow to handle the solid color style splash screen.
235      */
allowHandleSolidColorSplashScreen()236     public boolean allowHandleSolidColorSplashScreen() {
237         return (startingWindowTypeParameter & TYPE_PARAMETER_ALLOW_HANDLE_SOLID_COLOR_SCREEN) != 0;
238     }
239 
240     @Override
describeContents()241     public int describeContents() {
242         return 0;
243     }
244 
245     @Override
writeToParcel(@onNull Parcel dest, int flags)246     public void writeToParcel(@NonNull Parcel dest, int flags) {
247         dest.writeTypedObject(taskInfo, flags);
248         taskBounds.writeToParcel(dest, flags);
249         dest.writeTypedObject(targetActivityInfo, flags);
250         dest.writeInt(startingWindowTypeParameter);
251         dest.writeTypedObject(mainWindowLayoutParams, flags);
252         dest.writeInt(splashScreenThemeResId);
253         dest.writeBoolean(isKeyguardOccluded);
254         dest.writeTypedObject(taskSnapshot, flags);
255         dest.writeInt(requestedVisibleTypes);
256         dest.writeStrongBinder(appToken);
257         dest.writeStrongInterface(windowlessStartingSurfaceCallback);
258         dest.writeTypedObject(rootSurface, flags);
259     }
260 
readFromParcel(@onNull Parcel source)261     void readFromParcel(@NonNull Parcel source) {
262         taskInfo = source.readTypedObject(ActivityManager.RunningTaskInfo.CREATOR);
263         taskBounds.readFromParcel(source);
264         targetActivityInfo = source.readTypedObject(ActivityInfo.CREATOR);
265         startingWindowTypeParameter = source.readInt();
266         mainWindowLayoutParams = source.readTypedObject(WindowManager.LayoutParams.CREATOR);
267         splashScreenThemeResId = source.readInt();
268         isKeyguardOccluded = source.readBoolean();
269         taskSnapshot = source.readTypedObject(TaskSnapshot.CREATOR);
270         requestedVisibleTypes = source.readInt();
271         appToken = source.readStrongBinder();
272         windowlessStartingSurfaceCallback = IWindowlessStartingSurfaceCallback.Stub
273                 .asInterface(source.readStrongBinder());
274         rootSurface = source.readTypedObject(SurfaceControl.CREATOR);
275     }
276 
277     @Override
toString()278     public String toString() {
279         return "StartingWindowInfo{taskId=" + taskInfo.taskId
280                 + " targetActivityInfo=" + targetActivityInfo
281                 + " displayId=" + taskInfo.displayId
282                 + " topActivityType=" + taskInfo.topActivityType
283                 + " preferredStartingWindowType="
284                 + Integer.toHexString(startingWindowTypeParameter)
285                 + " mainWindowLayoutParams=" + mainWindowLayoutParams
286                 + " splashScreenThemeResId " + Integer.toHexString(splashScreenThemeResId);
287     }
288 
289     public static final @android.annotation.NonNull Creator<StartingWindowInfo> CREATOR =
290             new Creator<StartingWindowInfo>() {
291                 public StartingWindowInfo createFromParcel(@NonNull Parcel source) {
292                     return new StartingWindowInfo(source);
293                 }
294                 public StartingWindowInfo[] newArray(int size) {
295                     return new StartingWindowInfo[size];
296                 }
297             };
298 }
299