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.withCache 20 import kotlin.js.JsExport 21 import kotlin.js.JsName 22 23 /** 24 * Represents the keyguard controller in the window manager hierarchy 25 * 26 * This is a generic object that is reused by both Flicker and Winscope and cannot access internal 27 * Java/Android functionality 28 */ 29 @JsExport 30 class KeyguardControllerState 31 private constructor( 32 val isAodShowing: Boolean, 33 val isKeyguardShowing: Boolean, 34 val keyguardOccludedStates: Map<Int, Boolean> 35 ) { isKeyguardOccludednull36 fun isKeyguardOccluded(displayId: Int): Boolean = keyguardOccludedStates[displayId] ?: false 37 38 override fun toString(): String { 39 return "KeyguardControllerState: {aod=$isAodShowing keyguard=$isKeyguardShowing}" 40 } 41 equalsnull42 override fun equals(other: Any?): Boolean { 43 if (this === other) return true 44 if (other !is KeyguardControllerState) return false 45 46 if (isAodShowing != other.isAodShowing) return false 47 if (isKeyguardShowing != other.isKeyguardShowing) return false 48 if (keyguardOccludedStates != other.keyguardOccludedStates) return false 49 50 return true 51 } 52 hashCodenull53 override fun hashCode(): Int { 54 var result = isAodShowing.hashCode() 55 result = 31 * result + isKeyguardShowing.hashCode() 56 result = 31 * result + keyguardOccludedStates.hashCode() 57 return result 58 } 59 60 companion object { 61 @JsName("from") fromnull62 fun from( 63 isAodShowing: Boolean, 64 isKeyguardShowing: Boolean, 65 keyguardOccludedStates: Map<Int, Boolean> 66 ): KeyguardControllerState = withCache { 67 KeyguardControllerState(isAodShowing, isKeyguardShowing, keyguardOccludedStates) 68 } 69 } 70 } 71