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 android.annotation.SuppressLint 20 import com.android.settingslib.SignalIcon.IconGroup 21 import java.text.SimpleDateFormat 22 23 /** 24 * Base type for various connectivity states, for use with [SignalController] and its subtypes 25 */ 26 open class ConnectivityState { 27 @JvmField var connected = false 28 @JvmField var enabled = false 29 @JvmField var activityIn = false 30 @JvmField var activityOut = false 31 @JvmField var level = 0 32 @JvmField var iconGroup: IconGroup? = null 33 @JvmField var inetCondition = 0 34 // Only for logging. 35 @JvmField var rssi = 0 36 // Not used for comparison, just used for logging. 37 @JvmField var time: Long = 0 38 toStringnull39 override fun toString(): String { 40 return if (time != 0L) { 41 val builder = StringBuilder() 42 toString(builder) 43 builder.toString() 44 } else { 45 "Empty " + javaClass.simpleName 46 } 47 } 48 tableColumnsnull49 protected open fun tableColumns(): List<String> { 50 return listOf( 51 "connected", 52 "enabled", 53 "activityIn", 54 "activityOut", 55 "level", 56 "iconGroup", 57 "inetCondition", 58 "rssi", 59 "time") 60 } 61 tableDatanull62 protected open fun tableData(): List<String> { 63 return listOf( 64 connected, 65 enabled, 66 activityIn, 67 activityOut, 68 level, 69 iconGroup, 70 inetCondition, 71 rssi, 72 sSDF.format(time)).map { 73 it.toString() 74 } 75 } 76 copyFromnull77 protected open fun copyFrom(other: ConnectivityState) { 78 connected = other.connected 79 enabled = other.enabled 80 activityIn = other.activityIn 81 activityOut = other.activityOut 82 level = other.level 83 iconGroup = other.iconGroup 84 inetCondition = other.inetCondition 85 rssi = other.rssi 86 time = other.time 87 } 88 toStringnull89 protected open fun toString(builder: StringBuilder) { 90 builder.append("connected=$connected,") 91 .append("enabled=$enabled,") 92 .append("level=$level,") 93 .append("inetCondition=$inetCondition,") 94 .append("iconGroup=$iconGroup,") 95 .append("activityIn=$activityIn,") 96 .append("activityOut=$activityOut,") 97 .append("rssi=$rssi,") 98 .append("lastModified=${sSDF.format(time)}") 99 } 100 equalsnull101 override fun equals(other: Any?): Boolean { 102 if (other == null) return false 103 if (other.javaClass != javaClass) return false 104 105 val o = other as ConnectivityState 106 return o.connected == connected && 107 o.enabled == enabled && 108 o.level == level && 109 o.inetCondition == inetCondition && 110 o.iconGroup === iconGroup && 111 o.activityIn == activityIn && 112 o.activityOut == activityOut && 113 o.rssi == rssi 114 } 115 hashCodenull116 override fun hashCode(): Int { 117 var result = connected.hashCode() 118 result = 31 * result + enabled.hashCode() 119 result = 31 * result + activityIn.hashCode() 120 result = 31 * result + activityOut.hashCode() 121 result = 31 * result + level 122 result = 31 * result + (iconGroup?.hashCode() ?: 0) 123 result = 31 * result + inetCondition 124 result = 31 * result + rssi 125 result = 31 * result + time.hashCode() 126 return result 127 } 128 } 129 130 // No locale as it's only used for logging purposes 131 @SuppressLint("SimpleDateFormat") 132 private val sSDF = SimpleDateFormat("MM-dd HH:mm:ss.SSS") 133