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 @JsExport 24 /** {@inheritDoc} */ 25 class ConfigurationContainer 26 private constructor( 27 override val overrideConfiguration: Configuration?, 28 override val fullConfiguration: Configuration?, 29 override val mergedOverrideConfiguration: Configuration? 30 ) : IConfigurationContainer { 31 override val windowingMode: Int 32 get() = fullConfiguration?.windowConfiguration?.windowingMode ?: 0 33 34 override val activityType: Int 35 get() = fullConfiguration?.windowConfiguration?.activityType ?: 0 36 37 override val isEmpty: Boolean 38 get() = 39 (overrideConfiguration?.isEmpty 40 ?: true) && 41 (fullConfiguration?.isEmpty ?: true) && 42 (mergedOverrideConfiguration?.isEmpty ?: true) 43 equalsnull44 override fun equals(other: Any?): Boolean { 45 if (this === other) return true 46 if (other !is ConfigurationContainer) return false 47 48 if (overrideConfiguration != other.overrideConfiguration) return false 49 if (fullConfiguration != other.fullConfiguration) return false 50 if (mergedOverrideConfiguration != other.mergedOverrideConfiguration) return false 51 52 return true 53 } 54 hashCodenull55 override fun hashCode(): Int { 56 var result = overrideConfiguration?.hashCode() ?: 0 57 result = 31 * result + (fullConfiguration?.hashCode() ?: 0) 58 result = 31 * result + (mergedOverrideConfiguration?.hashCode() ?: 0) 59 return result 60 } 61 62 companion object { 63 @JsName("EMPTY") 64 val EMPTY: ConfigurationContainer <lambda>null65 get() = withCache { ConfigurationContainer(null, null, null) } 66 67 @JsName("from") fromnull68 fun from( 69 overrideConfiguration: Configuration?, 70 fullConfiguration: Configuration?, 71 mergedOverrideConfiguration: Configuration? 72 ): ConfigurationContainer = withCache { 73 ConfigurationContainer( 74 overrideConfiguration, 75 fullConfiguration, 76 mergedOverrideConfiguration 77 ) 78 } 79 } 80 } 81