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_MULTI_WINDOW; 28 import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; 29 import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; 30 import static android.server.wm.ComponentNameUtils.getActivityName; 31 import static android.server.wm.ComponentNameUtils.getWindowName; 32 33 import android.content.ComponentName; 34 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_FREEFORM: return "FREEFORM"; 93 case WINDOWING_MODE_MULTI_WINDOW: return "MULTI_WINDOW"; 94 default: 95 return "Unknown WINDOWING_MODE_: " + windowingMode; 96 } 97 } 98 activityTypeName(int activityType)99 private static String activityTypeName(int activityType) { 100 switch (activityType) { 101 case ACTIVITY_TYPE_UNDEFINED: return "UNDEFINED"; 102 case ACTIVITY_TYPE_STANDARD: return "STANDARD"; 103 case ACTIVITY_TYPE_HOME: return "HOME"; 104 case ACTIVITY_TYPE_RECENTS: return "RECENTS"; 105 case ACTIVITY_TYPE_ASSISTANT: return "ASSISTANT"; 106 default: 107 throw new IllegalArgumentException("Unknown ACTIVITY_TYPE_: " + activityType); 108 } 109 } 110 111 public static class Builder { 112 @Nullable 113 private ComponentName mActivityName = null; 114 @Nullable 115 private String mWindowName = null; 116 private int mStackId = INVALID_STACK_ID; 117 private int mWindowingMode = WINDOWING_MODE_UNDEFINED; 118 private int mActivityType = ACTIVITY_TYPE_UNDEFINED; 119 Builder()120 private Builder() {} 121 Builder(final ComponentName activityName)122 public Builder(final ComponentName activityName) { 123 mActivityName = activityName; 124 mWindowName = getWindowName(activityName); 125 } 126 setWindowName(String windowName)127 private Builder setWindowName(String windowName) { 128 mWindowName = windowName; 129 return this; 130 } 131 setRootTaskId(int stackId)132 public Builder setRootTaskId(int stackId) { 133 mStackId = stackId; 134 return this; 135 } 136 setWindowingMode(int windowingMode)137 public Builder setWindowingMode(int windowingMode) { 138 mWindowingMode = windowingMode; 139 return this; 140 } 141 setActivityType(int activityType)142 public Builder setActivityType(int activityType) { 143 mActivityType = activityType; 144 return this; 145 } 146 build()147 public WaitForValidActivityState build() { 148 return new WaitForValidActivityState(this); 149 } 150 } 151 } 152