• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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.tools.common.traces.wm
18 
19 import android.tools.common.Rotation
20 import android.tools.common.withCache
21 import kotlin.js.JsExport
22 import kotlin.js.JsName
23 
24 /**
25  * Represents the requested policy of a WM container
26  *
27  * This is a generic object that is reused by both Flicker and Winscope and cannot access internal
28  * Java/Android functionality
29  */
30 @JsExport
31 class WindowManagerPolicy
32 private constructor(
33     val focusedAppToken: String = "",
34     val forceStatusBar: Boolean = false,
35     val forceStatusBarFromKeyguard: Boolean = false,
36     val keyguardDrawComplete: Boolean = false,
37     val keyguardOccluded: Boolean = false,
38     val keyguardOccludedChanged: Boolean = false,
39     val keyguardOccludedPending: Boolean = false,
40     val lastSystemUiFlags: Int = 0,
41     val orientation: Int = 0,
42     val rotation: Rotation = Rotation.ROTATION_0,
43     val rotationMode: Int = 0,
44     val screenOnFully: Boolean = false,
45     val windowManagerDrawComplete: Boolean = false
46 ) {
47     val isOrientationNoSensor: Boolean
48         get() = orientation == SCREEN_ORIENTATION_NOSENSOR
49 
50     val isFixedOrientation: Boolean
51         get() =
52             isFixedOrientationLandscape ||
53                 isFixedOrientationPortrait ||
54                 orientation == SCREEN_ORIENTATION_LOCKED
55 
56     private val isFixedOrientationLandscape
57         get() =
58             orientation == SCREEN_ORIENTATION_LANDSCAPE ||
59                 orientation == SCREEN_ORIENTATION_SENSOR_LANDSCAPE ||
60                 orientation == SCREEN_ORIENTATION_REVERSE_LANDSCAPE ||
61                 orientation == SCREEN_ORIENTATION_USER_LANDSCAPE
62 
63     private val isFixedOrientationPortrait
64         get() =
65             orientation == SCREEN_ORIENTATION_PORTRAIT ||
66                 orientation == SCREEN_ORIENTATION_SENSOR_PORTRAIT ||
67                 orientation == SCREEN_ORIENTATION_REVERSE_PORTRAIT ||
68                 orientation == SCREEN_ORIENTATION_USER_PORTRAIT
69 
equalsnull70     override fun equals(other: Any?): Boolean {
71         if (this === other) return true
72         if (other !is WindowManagerPolicy) return false
73 
74         if (focusedAppToken != other.focusedAppToken) return false
75         if (forceStatusBar != other.forceStatusBar) return false
76         if (forceStatusBarFromKeyguard != other.forceStatusBarFromKeyguard) return false
77         if (keyguardDrawComplete != other.keyguardDrawComplete) return false
78         if (keyguardOccluded != other.keyguardOccluded) return false
79         if (keyguardOccludedChanged != other.keyguardOccludedChanged) return false
80         if (keyguardOccludedPending != other.keyguardOccludedPending) return false
81         if (lastSystemUiFlags != other.lastSystemUiFlags) return false
82         if (orientation != other.orientation) return false
83         if (rotation != other.rotation) return false
84         if (rotationMode != other.rotationMode) return false
85         if (screenOnFully != other.screenOnFully) return false
86         if (windowManagerDrawComplete != other.windowManagerDrawComplete) return false
87 
88         return true
89     }
90 
hashCodenull91     override fun hashCode(): Int {
92         var result = focusedAppToken.hashCode()
93         result = 31 * result + forceStatusBar.hashCode()
94         result = 31 * result + forceStatusBarFromKeyguard.hashCode()
95         result = 31 * result + keyguardDrawComplete.hashCode()
96         result = 31 * result + keyguardOccluded.hashCode()
97         result = 31 * result + keyguardOccludedChanged.hashCode()
98         result = 31 * result + keyguardOccludedPending.hashCode()
99         result = 31 * result + lastSystemUiFlags
100         result = 31 * result + orientation
101         result = 31 * result + rotation.hashCode()
102         result = 31 * result + rotationMode
103         result = 31 * result + screenOnFully.hashCode()
104         result = 31 * result + windowManagerDrawComplete.hashCode()
105         return result
106     }
107 
toStringnull108     override fun toString(): String {
109         return "${this::class.simpleName} (focusedAppToken='$focusedAppToken', " +
110             "forceStatusBar=$forceStatusBar, " +
111             "forceStatusBarFromKeyguard=$forceStatusBarFromKeyguard, " +
112             "keyguardDrawComplete=$keyguardDrawComplete, keyguardOccluded=$keyguardOccluded, " +
113             "keyguardOccludedChanged=$keyguardOccludedChanged, " +
114             "keyguardOccludedPending=$keyguardOccludedPending, " +
115             "lastSystemUiFlags=$lastSystemUiFlags, orientation=$orientation, " +
116             "rotation=$rotation, rotationMode=$rotationMode, " +
117             "screenOnFully=$screenOnFully, " +
118             "windowManagerDrawComplete=$windowManagerDrawComplete)"
119     }
120 
121     companion object {
122         @JsName("EMPTY")
123         val EMPTY: WindowManagerPolicy
<lambda>null124             get() = withCache { WindowManagerPolicy() }
125 
126         /** From [android.content.pm.ActivityInfo] */
127         private const val SCREEN_ORIENTATION_LANDSCAPE = 0
128         private const val SCREEN_ORIENTATION_PORTRAIT = 1
129         private const val SCREEN_ORIENTATION_NOSENSOR = 5
130         private const val SCREEN_ORIENTATION_SENSOR_LANDSCAPE = 6
131         private const val SCREEN_ORIENTATION_SENSOR_PORTRAIT = 7
132         private const val SCREEN_ORIENTATION_REVERSE_LANDSCAPE = 8
133         private const val SCREEN_ORIENTATION_REVERSE_PORTRAIT = 9
134         private const val SCREEN_ORIENTATION_USER_LANDSCAPE = 11
135         private const val SCREEN_ORIENTATION_USER_PORTRAIT = 12
136         private const val SCREEN_ORIENTATION_LOCKED = 14
137 
138         @JsName("from")
fromnull139         fun from(
140             focusedAppToken: String = "",
141             forceStatusBar: Boolean = false,
142             forceStatusBarFromKeyguard: Boolean = false,
143             keyguardDrawComplete: Boolean = false,
144             keyguardOccluded: Boolean = false,
145             keyguardOccludedChanged: Boolean = false,
146             keyguardOccludedPending: Boolean = false,
147             lastSystemUiFlags: Int = 0,
148             orientation: Int = 0,
149             rotation: Rotation = Rotation.ROTATION_0,
150             rotationMode: Int = 0,
151             screenOnFully: Boolean = false,
152             windowManagerDrawComplete: Boolean = false
153         ): WindowManagerPolicy = withCache {
154             WindowManagerPolicy(
155                 focusedAppToken,
156                 forceStatusBar,
157                 forceStatusBarFromKeyguard,
158                 keyguardDrawComplete,
159                 keyguardOccluded,
160                 keyguardOccludedChanged,
161                 keyguardOccludedPending,
162                 lastSystemUiFlags,
163                 orientation,
164                 rotation,
165                 rotationMode,
166                 screenOnFully,
167                 windowManagerDrawComplete
168             )
169         }
170     }
171 }
172