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 /**
22  * Represents the configuration of a WM container
23  *
24  * This is a generic object that is reused by both Flicker and Winscope and cannot access internal
25  * Java/Android functionality
26  */
27 class Configuration
28 private constructor(
29     val windowConfiguration: WindowConfiguration? = null,
30     val densityDpi: Int = 0,
31     val orientation: Int = 0,
32     val screenHeightDp: Int = 0,
33     val screenWidthDp: Int = 0,
34     val smallestScreenWidthDp: Int = 0,
35     val screenLayout: Int = 0,
36     val uiMode: Int = 0
37 ) {
38     val isEmpty: Boolean
39         get() =
40             (windowConfiguration == null) &&
41                 densityDpi == 0 &&
42                 orientation == 0 &&
43                 screenHeightDp == 0 &&
44                 screenWidthDp == 0 &&
45                 smallestScreenWidthDp == 0 &&
46                 screenLayout == 0 &&
47                 uiMode == 0
48 
equalsnull49     override fun equals(other: Any?): Boolean {
50         if (this === other) return true
51         if (other !is Configuration) return false
52 
53         if (windowConfiguration != other.windowConfiguration) return false
54         if (densityDpi != other.densityDpi) return false
55         if (orientation != other.orientation) return false
56         if (screenHeightDp != other.screenHeightDp) return false
57         if (screenWidthDp != other.screenWidthDp) return false
58         if (smallestScreenWidthDp != other.smallestScreenWidthDp) return false
59         if (screenLayout != other.screenLayout) return false
60         if (uiMode != other.uiMode) return false
61 
62         return true
63     }
64 
hashCodenull65     override fun hashCode(): Int {
66         var result = windowConfiguration?.hashCode() ?: 0
67         result = 31 * result + densityDpi
68         result = 31 * result + orientation
69         result = 31 * result + screenHeightDp
70         result = 31 * result + screenWidthDp
71         result = 31 * result + smallestScreenWidthDp
72         result = 31 * result + screenLayout
73         result = 31 * result + uiMode
74         return result
75     }
76 
77     companion object {
78         val EMPTY: Configuration
<lambda>null79             get() = withCache { Configuration() }
80 
fromnull81         fun from(
82             windowConfiguration: WindowConfiguration?,
83             densityDpi: Int,
84             orientation: Int,
85             screenHeightDp: Int,
86             screenWidthDp: Int,
87             smallestScreenWidthDp: Int,
88             screenLayout: Int,
89             uiMode: Int
90         ): Configuration = withCache {
91             Configuration(
92                 windowConfiguration,
93                 densityDpi,
94                 orientation,
95                 screenHeightDp,
96                 screenWidthDp,
97                 smallestScreenWidthDp,
98                 screenLayout,
99                 uiMode
100             )
101         }
102     }
103 }
104