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.telephony.SubscriptionInfo 20 21 /** 22 * SignalCallback contains all of the connectivity updates from [NetworkController]. Implement this 23 * interface to be able to draw iconography for Wi-Fi, mobile data, ethernet, call strength 24 * indicators, etc. 25 */ 26 interface SignalCallback { 27 /** 28 * Called when the Wi-Fi iconography has been updated. Implement this method to draw Wi-Fi icons 29 * 30 * @param wifiIndicators a box type containing enough information to properly draw a Wi-Fi icon 31 */ 32 @JvmDefault 33 fun setWifiIndicators(wifiIndicators: WifiIndicators) {} 34 35 /** 36 * Called when the mobile iconography has been updated. Implement this method to draw mobile 37 * indicators 38 * 39 * @param mobileDataIndicators a box type containing enough information to properly draw 40 * mobile data icons 41 * 42 * NOTE: phones can have multiple subscriptions, so this [mobileDataIndicators] object should be 43 * indexed based on its [subId][MobileDataIndicators.subId] 44 */ 45 @JvmDefault 46 fun setMobileDataIndicators(mobileDataIndicators: MobileDataIndicators) {} 47 48 /** 49 * Called when the list of mobile data subscriptions has changed. Use this method as a chance 50 * to remove views that are no longer needed, or to make room for new icons to come in 51 * 52 * @param subs a [SubscriptionInfo] for each subscription that we know about 53 */ 54 @JvmDefault 55 fun setSubs(subs: List<@JvmSuppressWildcards SubscriptionInfo>) {} 56 57 /** 58 * Called when: 59 * 1. The number of [MobileSignalController]s goes to 0 while mobile data is enabled 60 * OR 61 * 2. The presence of any SIM changes 62 * 63 * @param show whether or not to show a "no sim" view 64 * @param simDetected whether any SIM is detected or not 65 */ 66 @JvmDefault 67 fun setNoSims(show: Boolean, simDetected: Boolean) {} 68 69 /** 70 * Called when there is any update to the ethernet iconography. Implement this method to set an 71 * ethernet icon 72 * 73 * @param icon an [IconState] for the current ethernet status 74 */ 75 @JvmDefault 76 fun setEthernetIndicators(icon: IconState) {} 77 78 /** 79 * Called whenever airplane mode changes 80 * 81 * @param icon an [IconState] for the current airplane mode status 82 */ 83 @JvmDefault 84 fun setIsAirplaneMode(icon: IconState) {} 85 86 /** 87 * Called whenever the mobile data feature enabled state changes 88 * 89 * @param enabled the current mobile data feature ennabled state 90 */ 91 @JvmDefault 92 fun setMobileDataEnabled(enabled: Boolean) {} 93 94 /** 95 * Callback for listeners to be able to update the connectivity status 96 * @param noDefaultNetwork whether there is any default network. 97 * @param noValidatedNetwork whether there is any validated network. 98 * @param noNetworksAvailable whether there is any WiFi networks available. 99 */ 100 @JvmDefault 101 fun setConnectivityStatus( 102 noDefaultNetwork: Boolean, 103 noValidatedNetwork: Boolean, 104 noNetworksAvailable: Boolean 105 ) { } 106 107 /** 108 * Callback for listeners to be able to update the call indicator 109 * @param statusIcon the icon for the call indicator 110 * @param subId subscription ID for which to update the UI 111 */ 112 @JvmDefault 113 fun setCallIndicator(statusIcon: IconState, subId: Int) {} 114 } 115 116 /** Box type for [SignalCallback.setWifiIndicators] */ 117 data class WifiIndicators( 118 @JvmField val enabled: Boolean, 119 @JvmField val statusIcon: IconState?, 120 @JvmField val qsIcon: IconState?, 121 @JvmField val activityIn: Boolean, 122 @JvmField val activityOut: Boolean, 123 @JvmField val description: String?, 124 @JvmField val isTransient: Boolean, 125 @JvmField val statusLabel: String? 126 ) { 127 override fun toString(): String { 128 return StringBuilder("WifiIndicators[") 129 .append("enabled=").append(enabled) 130 .append(",statusIcon=").append(statusIcon?.toString() ?: "") 131 .append(",qsIcon=").append(qsIcon?.toString() ?: "") 132 .append(",activityIn=").append(activityIn) 133 .append(",activityOut=").append(activityOut) 134 .append(",qsDescription=").append(description) 135 .append(",isTransient=").append(isTransient) 136 .append(",statusLabel=").append(statusLabel) 137 .append(']').toString() 138 } 139 } 140 141 /** Box type for [SignalCallback.setMobileDataIndicators] */ 142 data class MobileDataIndicators( 143 @JvmField val statusIcon: IconState?, 144 @JvmField val qsIcon: IconState?, 145 @JvmField val statusType: Int, 146 @JvmField val qsType: Int, 147 @JvmField val activityIn: Boolean, 148 @JvmField val activityOut: Boolean, 149 @JvmField val typeContentDescription: CharSequence?, 150 @JvmField val typeContentDescriptionHtml: CharSequence?, 151 @JvmField val qsDescription: CharSequence?, 152 @JvmField val subId: Int, 153 @JvmField val roaming: Boolean, 154 @JvmField val showTriangle: Boolean 155 ) { 156 override fun toString(): String { 157 return java.lang.StringBuilder("MobileDataIndicators[") 158 .append("statusIcon=").append(statusIcon?.toString() ?: "") 159 .append(",qsIcon=").append(qsIcon?.toString() ?: "") 160 .append(",statusType=").append(statusType) 161 .append(",qsType=").append(qsType) 162 .append(",activityIn=").append(activityIn) 163 .append(",activityOut=").append(activityOut) 164 .append(",typeContentDescription=").append(typeContentDescription) 165 .append(",typeContentDescriptionHtml=").append(typeContentDescriptionHtml) 166 .append(",description=").append(qsDescription) 167 .append(",subId=").append(subId) 168 .append(",roaming=").append(roaming) 169 .append(",showTriangle=").append(showTriangle) 170 .append(']').toString() 171 } 172 } 173 174 /** Box for an icon with its visibility and content description */ 175 data class IconState( 176 @JvmField val visible: Boolean, 177 @JvmField val icon: Int, 178 @JvmField val contentDescription: String 179 ) { 180 override fun toString(): String { 181 val builder = java.lang.StringBuilder() 182 return builder.append("[visible=").append(visible).append(',') 183 .append("icon=").append(icon).append(',') 184 .append("contentDescription=").append(contentDescription).append(']') 185 .toString() 186 } 187 }