• 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 com.android.wm.shell.startingsurface.phone;
18 
19 import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
20 import static android.window.StartingWindowInfo.STARTING_WINDOW_TYPE_LEGACY_SPLASH_SCREEN;
21 import static android.window.StartingWindowInfo.STARTING_WINDOW_TYPE_NONE;
22 import static android.window.StartingWindowInfo.STARTING_WINDOW_TYPE_SNAPSHOT;
23 import static android.window.StartingWindowInfo.STARTING_WINDOW_TYPE_SOLID_COLOR_SPLASH_SCREEN;
24 import static android.window.StartingWindowInfo.STARTING_WINDOW_TYPE_SPLASH_SCREEN;
25 import static android.window.StartingWindowInfo.TYPE_PARAMETER_ACTIVITY_CREATED;
26 import static android.window.StartingWindowInfo.TYPE_PARAMETER_ACTIVITY_DRAWN;
27 import static android.window.StartingWindowInfo.TYPE_PARAMETER_ALLOW_TASK_SNAPSHOT;
28 import static android.window.StartingWindowInfo.TYPE_PARAMETER_LEGACY_SPLASH_SCREEN;
29 import static android.window.StartingWindowInfo.TYPE_PARAMETER_NEW_TASK;
30 import static android.window.StartingWindowInfo.TYPE_PARAMETER_PROCESS_RUNNING;
31 import static android.window.StartingWindowInfo.TYPE_PARAMETER_TASK_SWITCH;
32 import static android.window.StartingWindowInfo.TYPE_PARAMETER_USE_SOLID_COLOR_SPLASH_SCREEN;
33 
34 import android.window.StartingWindowInfo;
35 
36 import com.android.internal.protolog.common.ProtoLog;
37 import com.android.wm.shell.protolog.ShellProtoLogGroup;
38 import com.android.wm.shell.startingsurface.StartingWindowTypeAlgorithm;
39 
40 /**
41  * Algorithm for determining the type of a new starting window on handheld devices.
42  * At the moment also used on Android Auto and Wear OS.
43  */
44 public class PhoneStartingWindowTypeAlgorithm implements StartingWindowTypeAlgorithm {
45     @Override
getSuggestedWindowType(StartingWindowInfo windowInfo)46     public int getSuggestedWindowType(StartingWindowInfo windowInfo) {
47         final int parameter = windowInfo.startingWindowTypeParameter;
48         final boolean newTask = (parameter & TYPE_PARAMETER_NEW_TASK) != 0;
49         final boolean taskSwitch = (parameter & TYPE_PARAMETER_TASK_SWITCH) != 0;
50         final boolean processRunning = (parameter & TYPE_PARAMETER_PROCESS_RUNNING) != 0;
51         final boolean allowTaskSnapshot = (parameter & TYPE_PARAMETER_ALLOW_TASK_SNAPSHOT) != 0;
52         final boolean activityCreated = (parameter & TYPE_PARAMETER_ACTIVITY_CREATED) != 0;
53         final boolean isSolidColorSplashScreen =
54                 (parameter & TYPE_PARAMETER_USE_SOLID_COLOR_SPLASH_SCREEN) != 0;
55         final boolean legacySplashScreen =
56                 ((parameter & TYPE_PARAMETER_LEGACY_SPLASH_SCREEN) != 0);
57         final boolean activityDrawn = (parameter & TYPE_PARAMETER_ACTIVITY_DRAWN) != 0;
58         final boolean topIsHome = windowInfo.taskInfo.topActivityType == ACTIVITY_TYPE_HOME;
59 
60         ProtoLog.v(ShellProtoLogGroup.WM_SHELL_STARTING_WINDOW,
61                 "preferredStartingWindowType "
62                         + "newTask=%b, "
63                         + "taskSwitch=%b, "
64                         + "processRunning=%b, "
65                         + "allowTaskSnapshot=%b, "
66                         + "activityCreated=%b, "
67                         + "isSolidColorSplashScreen=%b, "
68                         + "legacySplashScreen=%b, "
69                         + "activityDrawn=%b, "
70                         + "topIsHome=%b",
71                 newTask, taskSwitch, processRunning, allowTaskSnapshot, activityCreated,
72                 isSolidColorSplashScreen, legacySplashScreen, activityDrawn, topIsHome);
73 
74         if (!topIsHome) {
75             if (!processRunning || newTask || (taskSwitch && !activityCreated)) {
76                 return getSplashscreenType(isSolidColorSplashScreen, legacySplashScreen);
77             }
78         }
79 
80         if (taskSwitch) {
81             if (allowTaskSnapshot) {
82                 if (windowInfo.taskSnapshot != null) {
83                     return STARTING_WINDOW_TYPE_SNAPSHOT;
84                 }
85                 if (!topIsHome) {
86                     return STARTING_WINDOW_TYPE_SOLID_COLOR_SPLASH_SCREEN;
87                 }
88             }
89             if (!activityDrawn && !topIsHome) {
90                 return getSplashscreenType(isSolidColorSplashScreen, legacySplashScreen);
91             }
92         }
93         return STARTING_WINDOW_TYPE_NONE;
94     }
95 
getSplashscreenType(boolean solidColorSplashScreen, boolean legacySplashScreen)96     private static int getSplashscreenType(boolean solidColorSplashScreen,
97             boolean legacySplashScreen) {
98         return solidColorSplashScreen
99                 ? STARTING_WINDOW_TYPE_SOLID_COLOR_SPLASH_SCREEN
100                 : legacySplashScreen
101                         ? STARTING_WINDOW_TYPE_LEGACY_SPLASH_SCREEN
102                         : STARTING_WINDOW_TYPE_SPLASH_SCREEN;
103     }
104 }
105