1 /*
2  * Copyright (C) 2021 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 com.android.systemui.statusbar.connectivity
18 
19 import java.lang.StringBuilder
20 
21 internal class WifiState(
22     @JvmField var ssid: String? = null,
23     @JvmField var isTransient: Boolean = false,
24     @JvmField var isDefault: Boolean = false,
25     @JvmField var statusLabel: String? = null,
26     @JvmField var isCarrierMerged: Boolean = false,
27     /**
28      * True if the current default connection is validated for *any* transport, not just wifi.
29      * (Specifically TRANSPORT_CELLULAR *or* TRANSPORT_WIFI.)
30      *
31      * This should *only* be used when calculating information for the carrier merged connection and
32      * *not* for typical wifi connections. See b/225902574.
33      */
34     @JvmField var isDefaultConnectionValidated: Boolean = false,
35     @JvmField var subId: Int = 0
36 ) : ConnectivityState() {
37 
38     public override fun copyFrom(s: ConnectivityState) {
39         super.copyFrom(s)
40         val state = s as WifiState
41         ssid = state.ssid
42         isTransient = state.isTransient
43         isDefault = state.isDefault
44         statusLabel = state.statusLabel
45         isCarrierMerged = state.isCarrierMerged
46         isDefaultConnectionValidated = state.isDefaultConnectionValidated
47         subId = state.subId
48     }
49 
50     override fun toString(builder: StringBuilder) {
51         super.toString(builder)
52         builder.append(",ssid=").append(ssid)
53                 .append(",isTransient=").append(isTransient)
54                 .append(",isDefault=").append(isDefault)
55                 .append(",statusLabel=").append(statusLabel)
56                 .append(",isCarrierMerged=").append(isCarrierMerged)
57                 .append(",isDefaultConnectionValidated=").append(isDefaultConnectionValidated)
58                 .append(",subId=").append(subId)
59     }
60 
61     override fun tableColumns(): List<String> {
62         val columns = listOf("ssid",
63                 "isTransient",
64                 "isDefault",
65                 "statusLabel",
66                 "isCarrierMerged",
67                 "isDefaultConnectionValidated",
68                 "subId")
69 
70         return super.tableColumns() + columns
71     }
72 
73     override fun tableData(): List<String> {
74         val data = listOf(ssid,
75         isTransient,
76         isDefault,
77         statusLabel,
78         isCarrierMerged,
79         isDefaultConnectionValidated,
80         subId).map {
81             it.toString()
82         }
83 
84         return super.tableData() + data
85     }
86 
87     override fun equals(other: Any?): Boolean {
88         if (this === other) return true
89         if (javaClass != other?.javaClass) return false
90         if (!super.equals(other)) return false
91 
92         other as WifiState
93 
94         if (ssid != other.ssid) return false
95         if (isTransient != other.isTransient) return false
96         if (isDefault != other.isDefault) return false
97         if (statusLabel != other.statusLabel) return false
98         if (isCarrierMerged != other.isCarrierMerged) return false
99         if (isDefaultConnectionValidated != other.isDefaultConnectionValidated) return false
100         if (subId != other.subId) return false
101 
102         return true
103     }
104 
105     override fun hashCode(): Int {
106         var result = super.hashCode()
107         result = 31 * result + (ssid?.hashCode() ?: 0)
108         result = 31 * result + isTransient.hashCode()
109         result = 31 * result + isDefault.hashCode()
110         result = 31 * result + (statusLabel?.hashCode() ?: 0)
111         result = 31 * result + isCarrierMerged.hashCode()
112         result = 31 * result + isDefaultConnectionValidated.hashCode()
113         result = 31 * result + subId
114         return result
115     }
116 }
117