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 ?: true) && 37 (fullConfiguration?.isEmpty ?: true) && 38 (mergedOverrideConfiguration?.isEmpty ?: true) 39 isWindowingModeCompatiblenull40 override fun isWindowingModeCompatible(requestedWindowingMode: Int): Boolean { 41 return when (requestedWindowingMode) { 42 WindowingMode.WINDOWING_MODE_UNDEFINED.value -> true 43 else -> windowingMode == requestedWindowingMode 44 } 45 } 46 equalsnull47 override fun equals(other: Any?): Boolean { 48 if (this === other) return true 49 if (other !is ConfigurationContainerImpl) return false 50 51 if (overrideConfiguration != other.overrideConfiguration) return false 52 if (fullConfiguration != other.fullConfiguration) return false 53 if (mergedOverrideConfiguration != other.mergedOverrideConfiguration) return false 54 55 return true 56 } 57 hashCodenull58 override fun hashCode(): Int { 59 var result = overrideConfiguration?.hashCode() ?: 0 60 result = 31 * result + (fullConfiguration?.hashCode() ?: 0) 61 result = 31 * result + (mergedOverrideConfiguration?.hashCode() ?: 0) 62 return result 63 } 64 65 companion object { 66 val EMPTY: ConfigurationContainerImpl <lambda>null67 get() = withCache { ConfigurationContainerImpl(null, null, null) } 68 fromnull69 fun from( 70 overrideConfiguration: Configuration?, 71 fullConfiguration: Configuration?, 72 mergedOverrideConfiguration: Configuration?, 73 ): ConfigurationContainerImpl = withCache { 74 ConfigurationContainerImpl( 75 overrideConfiguration, 76 fullConfiguration, 77 mergedOverrideConfiguration, 78 ) 79 } 80 } 81 } 82