• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 com.android.server.wm.traces.parser.windowmanager
18 
19 import android.app.ActivityTaskManager
20 import android.app.WindowConfiguration
21 import com.android.server.wm.traces.common.FlickerComponentName
22 
23 data class WaitForValidActivityState(
24     @JvmField
25     val activityName: FlickerComponentName?,
26     @JvmField
27     val windowName: String?,
28     @JvmField
29     val stackId: Int,
30     @JvmField
31     val windowingMode: Int,
32     @JvmField
33     val activityType: Int
34 ) {
35     constructor(activityName: FlickerComponentName) : this(
36         activityName,
37         windowName = activityName.toWindowName(),
38         stackId = ActivityTaskManager.INVALID_STACK_ID,
39         windowingMode = WindowConfiguration.WINDOWING_MODE_UNDEFINED,
40         activityType = WindowConfiguration.ACTIVITY_TYPE_UNDEFINED
41     )
42 
43     private constructor(builder: Builder) : this(
44         activityName = builder.activityName,
45         windowName = builder.windowName,
46         stackId = builder.stackId,
47         windowingMode = builder.windowingMode,
48         activityType = builder.activityType
49     )
50 
toStringnull51     override fun toString(): String {
52         val sb = StringBuilder("wait:")
53         if (activityName != null) {
54             sb.append(" activity=").append(activityName.toActivityName())
55         }
56         if (activityType != WindowConfiguration.ACTIVITY_TYPE_UNDEFINED) {
57             sb.append(" type=").append(activityTypeName(activityType))
58         }
59         if (windowName != null) {
60             sb.append(" window=").append(windowName)
61         }
62         if (windowingMode != WindowConfiguration.WINDOWING_MODE_UNDEFINED) {
63             sb.append(" mode=").append(windowingModeName(windowingMode))
64         }
65         if (stackId != ActivityTaskManager.INVALID_STACK_ID) {
66             sb.append(" stack=").append(stackId)
67         }
68         return sb.toString()
69     }
70 
71     class Builder constructor(internal var activityName: FlickerComponentName? = null) {
72         internal var windowName: String? = activityName?.toWindowName()
73         internal var stackId = ActivityTaskManager.INVALID_STACK_ID
74         internal var windowingMode = WindowConfiguration.WINDOWING_MODE_UNDEFINED
75         internal var activityType = WindowConfiguration.ACTIVITY_TYPE_UNDEFINED
76 
setWindowNamenull77         fun setWindowName(windowName: String): Builder {
78             this.windowName = windowName
79             return this
80         }
81 
setStackIdnull82         fun setStackId(stackId: Int): Builder {
83             this.stackId = stackId
84             return this
85         }
86 
setWindowingModenull87         fun setWindowingMode(windowingMode: Int): Builder {
88             this.windowingMode = windowingMode
89             return this
90         }
91 
setActivityTypenull92         fun setActivityType(activityType: Int): Builder {
93             this.activityType = activityType
94             return this
95         }
96 
buildnull97         fun build(): WaitForValidActivityState {
98             return WaitForValidActivityState(this)
99         }
100     }
101 
102     companion object {
103         @JvmStatic
forWindownull104         fun forWindow(windowName: String): WaitForValidActivityState {
105             return Builder().setWindowName(windowName).build()
106         }
107 
windowingModeNamenull108         private fun windowingModeName(windowingMode: Int): String {
109             return when (windowingMode) {
110                 WindowConfiguration.WINDOWING_MODE_UNDEFINED -> "UNDEFINED"
111                 WindowConfiguration.WINDOWING_MODE_FULLSCREEN -> "FULLSCREEN"
112                 WindowConfiguration.WINDOWING_MODE_PINNED -> "PINNED"
113                 WindowConfiguration.WINDOWING_MODE_FREEFORM -> "FREEFORM"
114                 else -> throw IllegalArgumentException("Unknown WINDOWING_MODE_: $windowingMode")
115             }
116         }
117 
activityTypeNamenull118         private fun activityTypeName(activityType: Int): String {
119             return when (activityType) {
120                 WindowConfiguration.ACTIVITY_TYPE_UNDEFINED -> "UNDEFINED"
121                 WindowConfiguration.ACTIVITY_TYPE_STANDARD -> "STANDARD"
122                 WindowConfiguration.ACTIVITY_TYPE_HOME -> "HOME"
123                 WindowConfiguration.ACTIVITY_TYPE_RECENTS -> "RECENTS"
124                 WindowConfiguration.ACTIVITY_TYPE_ASSISTANT -> "ASSISTANT"
125                 else -> throw IllegalArgumentException("Unknown ACTIVITY_TYPE_: $activityType")
126             }
127         }
128     }
129 }