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