• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 configuration of a WM container
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 Configuration
31 private constructor(
32     @JsName("windowConfiguration") val windowConfiguration: WindowConfiguration? = null,
33     @JsName("densityDpi") val densityDpi: Int = 0,
34     @JsName("orientation") val orientation: Int = 0,
35     @JsName("screenHeightDp") val screenHeightDp: Int = 0,
36     @JsName("screenWidthDp") val screenWidthDp: Int = 0,
37     @JsName("smallestScreenWidthDp") val smallestScreenWidthDp: Int = 0,
38     @JsName("screenLayout") val screenLayout: Int = 0,
39     @JsName("uiMode") val uiMode: Int = 0
40 ) {
41     @JsName("isEmpty")
42     val isEmpty: Boolean
43         get() =
44             (windowConfiguration == null) &&
45                 densityDpi == 0 &&
46                 orientation == 0 &&
47                 screenHeightDp == 0 &&
48                 screenWidthDp == 0 &&
49                 smallestScreenWidthDp == 0 &&
50                 screenLayout == 0 &&
51                 uiMode == 0
52 
equalsnull53     override fun equals(other: Any?): Boolean {
54         if (this === other) return true
55         if (other !is Configuration) return false
56 
57         if (windowConfiguration != other.windowConfiguration) return false
58         if (densityDpi != other.densityDpi) return false
59         if (orientation != other.orientation) return false
60         if (screenHeightDp != other.screenHeightDp) return false
61         if (screenWidthDp != other.screenWidthDp) return false
62         if (smallestScreenWidthDp != other.smallestScreenWidthDp) return false
63         if (screenLayout != other.screenLayout) return false
64         if (uiMode != other.uiMode) return false
65 
66         return true
67     }
68 
hashCodenull69     override fun hashCode(): Int {
70         var result = windowConfiguration?.hashCode() ?: 0
71         result = 31 * result + densityDpi
72         result = 31 * result + orientation
73         result = 31 * result + screenHeightDp
74         result = 31 * result + screenWidthDp
75         result = 31 * result + smallestScreenWidthDp
76         result = 31 * result + screenLayout
77         result = 31 * result + uiMode
78         return result
79     }
80 
81     companion object {
82         @JsName("EMPTY")
83         val EMPTY: Configuration
<lambda>null84             get() = withCache { Configuration() }
85 
86         @JsName("from")
fromnull87         fun from(
88             windowConfiguration: WindowConfiguration?,
89             densityDpi: Int,
90             orientation: Int,
91             screenHeightDp: Int,
92             screenWidthDp: Int,
93             smallestScreenWidthDp: Int,
94             screenLayout: Int,
95             uiMode: Int
96         ): Configuration = withCache {
97             Configuration(
98                 windowConfiguration,
99                 densityDpi,
100                 orientation,
101                 screenHeightDp,
102                 screenWidthDp,
103                 smallestScreenWidthDp,
104                 screenLayout,
105                 uiMode
106             )
107         }
108     }
109 }
110