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