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.withCache 20 21 /** {@inheritDoc} */ 22 class ConfigurationContainerImpl 23 private constructor( 24 override val overrideConfiguration: Configuration?, 25 override val fullConfiguration: Configuration?, 26 override val mergedOverrideConfiguration: Configuration? 27 ) : ConfigurationContainer { 28 override val windowingMode: Int 29 get() = fullConfiguration?.windowConfiguration?.windowingMode ?: 0 30 31 override val activityType: Int 32 get() = fullConfiguration?.windowConfiguration?.activityType ?: 0 33 34 override val isEmpty: Boolean 35 get() = 36 (overrideConfiguration?.isEmpty 37 ?: true) && 38 (fullConfiguration?.isEmpty ?: true) && 39 (mergedOverrideConfiguration?.isEmpty ?: true) 40 isWindowingModeCompatiblenull41 override fun isWindowingModeCompatible(requestedWindowingMode: Int): Boolean { 42 return when (requestedWindowingMode) { 43 WindowingMode.WINDOWING_MODE_UNDEFINED.value -> true 44 else -> windowingMode == requestedWindowingMode 45 } 46 } 47 equalsnull48 override fun equals(other: Any?): Boolean { 49 if (this === other) return true 50 if (other !is ConfigurationContainerImpl) return false 51 52 if (overrideConfiguration != other.overrideConfiguration) return false 53 if (fullConfiguration != other.fullConfiguration) return false 54 if (mergedOverrideConfiguration != other.mergedOverrideConfiguration) return false 55 56 return true 57 } 58 hashCodenull59 override fun hashCode(): Int { 60 var result = overrideConfiguration?.hashCode() ?: 0 61 result = 31 * result + (fullConfiguration?.hashCode() ?: 0) 62 result = 31 * result + (mergedOverrideConfiguration?.hashCode() ?: 0) 63 return result 64 } 65 66 companion object { 67 val EMPTY: ConfigurationContainerImpl <lambda>null68 get() = withCache { ConfigurationContainerImpl(null, null, null) } 69 fromnull70 fun from( 71 overrideConfiguration: Configuration?, 72 fullConfiguration: Configuration?, 73 mergedOverrideConfiguration: Configuration? 74 ): ConfigurationContainerImpl = withCache { 75 ConfigurationContainerImpl( 76 overrideConfiguration, 77 fullConfiguration, 78 mergedOverrideConfiguration 79 ) 80 } 81 } 82 } 83