1 /* 2 * Copyright (C) 2017 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.server.wm; 18 19 import static android.app.ActivityTaskManager.INVALID_STACK_ID; 20 import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT; 21 import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; 22 import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; 23 import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; 24 import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; 25 import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; 26 import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; 27 import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; 28 import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; 29 import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; 30 import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; 31 import static android.server.wm.ComponentNameUtils.getActivityName; 32 import static android.server.wm.ComponentNameUtils.getWindowName; 33 34 import android.content.ComponentName; 35 import androidx.annotation.Nullable; 36 37 public class WaitForValidActivityState { 38 @Nullable 39 public final ComponentName activityName; 40 @Nullable 41 public final String windowName; 42 public final int stackId; 43 public final int windowingMode; 44 public final int activityType; 45 forWindow(final String windowName)46 public static WaitForValidActivityState forWindow(final String windowName) { 47 return new Builder().setWindowName(windowName).build(); 48 } 49 WaitForValidActivityState(final ComponentName activityName)50 public WaitForValidActivityState(final ComponentName activityName) { 51 this.activityName = activityName; 52 this.windowName = getWindowName(activityName); 53 this.stackId = INVALID_STACK_ID; 54 this.windowingMode = WINDOWING_MODE_UNDEFINED; 55 this.activityType = ACTIVITY_TYPE_UNDEFINED; 56 } 57 WaitForValidActivityState(final Builder builder)58 private WaitForValidActivityState(final Builder builder) { 59 this.activityName = builder.mActivityName; 60 this.windowName = builder.mWindowName; 61 this.stackId = builder.mStackId; 62 this.windowingMode = builder.mWindowingMode; 63 this.activityType = builder.mActivityType; 64 } 65 66 @Override toString()67 public String toString() { 68 final StringBuilder sb = new StringBuilder("wait:"); 69 if (activityName != null) { 70 sb.append(" activity=").append(getActivityName(activityName)); 71 } 72 if (activityType != ACTIVITY_TYPE_UNDEFINED) { 73 sb.append(" type=").append(activityTypeName(activityType)); 74 } 75 if (windowName != null) { 76 sb.append(" window=").append(windowName); 77 } 78 if (windowingMode != WINDOWING_MODE_UNDEFINED) { 79 sb.append(" mode=").append(windowingModeName(windowingMode)); 80 } 81 if (stackId != INVALID_STACK_ID) { 82 sb.append(" stack=").append(stackId); 83 } 84 return sb.toString(); 85 } 86 windowingModeName(int windowingMode)87 private static String windowingModeName(int windowingMode) { 88 switch (windowingMode) { 89 case WINDOWING_MODE_UNDEFINED: return "UNDEFINED"; 90 case WINDOWING_MODE_FULLSCREEN: return "FULLSCREEN"; 91 case WINDOWING_MODE_PINNED: return "PINNED"; 92 case WINDOWING_MODE_SPLIT_SCREEN_PRIMARY: return "SPLIT_SCREEN_PRIMARY"; 93 case WINDOWING_MODE_SPLIT_SCREEN_SECONDARY: return "SPLIT_SCREEN_SECONDARY"; 94 case WINDOWING_MODE_FREEFORM: return "FREEFORM"; 95 default: 96 throw new IllegalArgumentException("Unknown WINDOWING_MODE_: " + windowingMode); 97 } 98 } 99 activityTypeName(int activityType)100 private static String activityTypeName(int activityType) { 101 switch (activityType) { 102 case ACTIVITY_TYPE_UNDEFINED: return "UNDEFINED"; 103 case ACTIVITY_TYPE_STANDARD: return "STANDARD"; 104 case ACTIVITY_TYPE_HOME: return "HOME"; 105 case ACTIVITY_TYPE_RECENTS: return "RECENTS"; 106 case ACTIVITY_TYPE_ASSISTANT: return "ASSISTANT"; 107 default: 108 throw new IllegalArgumentException("Unknown ACTIVITY_TYPE_: " + activityType); 109 } 110 } 111 112 public static class Builder { 113 @Nullable 114 private ComponentName mActivityName = null; 115 @Nullable 116 private String mWindowName = null; 117 private int mStackId = INVALID_STACK_ID; 118 private int mWindowingMode = WINDOWING_MODE_UNDEFINED; 119 private int mActivityType = ACTIVITY_TYPE_UNDEFINED; 120 Builder()121 private Builder() {} 122 Builder(final ComponentName activityName)123 public Builder(final ComponentName activityName) { 124 mActivityName = activityName; 125 mWindowName = getWindowName(activityName); 126 } 127 setWindowName(String windowName)128 private Builder setWindowName(String windowName) { 129 mWindowName = windowName; 130 return this; 131 } 132 setStackId(int stackId)133 public Builder setStackId(int stackId) { 134 mStackId = stackId; 135 return this; 136 } 137 setWindowingMode(int windowingMode)138 public Builder setWindowingMode(int windowingMode) { 139 mWindowingMode = windowingMode; 140 return this; 141 } 142 setActivityType(int activityType)143 public Builder setActivityType(int activityType) { 144 mActivityType = activityType; 145 return this; 146 } 147 build()148 public WaitForValidActivityState build() { 149 return new WaitForValidActivityState(this); 150 } 151 } 152 } 153