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