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