1 /* 2 * Copyright (C) 2014 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.policy; 18 19 import android.content.Context; 20 import android.content.Intent; 21 import android.telephony.SubscriptionInfo; 22 23 import com.android.settingslib.net.DataUsageController; 24 import com.android.systemui.demomode.DemoMode; 25 import com.android.systemui.statusbar.policy.NetworkController.SignalCallback; 26 import com.android.wifitrackerlib.WifiEntry; 27 28 import java.util.List; 29 30 public interface NetworkController extends CallbackController<SignalCallback>, DemoMode { 31 hasMobileDataFeature()32 boolean hasMobileDataFeature(); setWifiEnabled(boolean enabled)33 void setWifiEnabled(boolean enabled); getAccessPointController()34 AccessPointController getAccessPointController(); getMobileDataController()35 DataUsageController getMobileDataController(); getDataSaverController()36 DataSaverController getDataSaverController(); getMobileDataNetworkName()37 String getMobileDataNetworkName(); isMobileDataNetworkInService()38 boolean isMobileDataNetworkInService(); getNumberSubscriptions()39 int getNumberSubscriptions(); 40 hasVoiceCallingFeature()41 boolean hasVoiceCallingFeature(); 42 addEmergencyListener(EmergencyListener listener)43 void addEmergencyListener(EmergencyListener listener); removeEmergencyListener(EmergencyListener listener)44 void removeEmergencyListener(EmergencyListener listener); hasEmergencyCryptKeeperText()45 boolean hasEmergencyCryptKeeperText(); 46 isRadioOn()47 boolean isRadioOn(); 48 49 /** 50 * Wrapper class for all the WiFi signals used for WiFi indicators. 51 */ 52 final class WifiIndicators { 53 public boolean enabled; 54 public IconState statusIcon; 55 public IconState qsIcon; 56 public boolean activityIn; 57 public boolean activityOut; 58 public String description; 59 public boolean isTransient; 60 public String statusLabel; 61 WifiIndicators(boolean enabled, IconState statusIcon, IconState qsIcon, boolean activityIn, boolean activityOut, String description, boolean isTransient, String statusLabel)62 public WifiIndicators(boolean enabled, IconState statusIcon, IconState qsIcon, 63 boolean activityIn, boolean activityOut, String description, 64 boolean isTransient, String statusLabel) { 65 this.enabled = enabled; 66 this.statusIcon = statusIcon; 67 this.qsIcon = qsIcon; 68 this.activityIn = activityIn; 69 this.activityOut = activityOut; 70 this.description = description; 71 this.isTransient = isTransient; 72 this.statusLabel = statusLabel; 73 } 74 75 @Override toString()76 public String toString() { 77 return new StringBuilder("WifiIndicators[") 78 .append("enabled=").append(enabled) 79 .append(",statusIcon=").append(statusIcon == null ? "" : statusIcon.toString()) 80 .append(",qsIcon=").append(qsIcon == null ? "" : qsIcon.toString()) 81 .append(",activityIn=").append(activityIn) 82 .append(",activityOut=").append(activityOut) 83 .append(",description=").append(description) 84 .append(",isTransient=").append(isTransient) 85 .append(",statusLabel=").append(statusLabel) 86 .append(']').toString(); 87 } 88 } 89 90 /** 91 * Wrapper class for all the mobile signals used for mobile data indicators. 92 */ 93 final class MobileDataIndicators { 94 public IconState statusIcon; 95 public IconState qsIcon; 96 public int statusType; 97 public int qsType; 98 public boolean activityIn; 99 public boolean activityOut; 100 public CharSequence typeContentDescription; 101 public CharSequence typeContentDescriptionHtml; 102 public CharSequence description; 103 public boolean isWide; 104 public int subId; 105 public boolean roaming; 106 public boolean showTriangle; 107 MobileDataIndicators(IconState statusIcon, IconState qsIcon, int statusType, int qsType, boolean activityIn, boolean activityOut, CharSequence typeContentDescription, CharSequence typeContentDescriptionHtml, CharSequence description, boolean isWide, int subId, boolean roaming, boolean showTriangle)108 public MobileDataIndicators(IconState statusIcon, IconState qsIcon, int statusType, 109 int qsType, boolean activityIn, boolean activityOut, 110 CharSequence typeContentDescription, CharSequence typeContentDescriptionHtml, 111 CharSequence description, boolean isWide, int subId, boolean roaming, 112 boolean showTriangle) { 113 this.statusIcon = statusIcon; 114 this.qsIcon = qsIcon; 115 this.statusType = statusType; 116 this.qsType = qsType; 117 this.activityIn = activityIn; 118 this.activityOut = activityOut; 119 this.typeContentDescription = typeContentDescription; 120 this.typeContentDescriptionHtml = typeContentDescriptionHtml; 121 this.description = description; 122 this.isWide = isWide; 123 this.subId = subId; 124 this.roaming = roaming; 125 this.showTriangle = showTriangle; 126 } 127 128 @Override toString()129 public String toString() { 130 return new StringBuilder("MobileDataIndicators[") 131 .append("statusIcon=").append(statusIcon == null ? "" : statusIcon.toString()) 132 .append(",qsIcon=").append(qsIcon == null ? "" : qsIcon.toString()) 133 .append(",statusType=").append(statusType) 134 .append(",qsType=").append(qsType) 135 .append(",activityIn=").append(activityIn) 136 .append(",activityOut=").append(activityOut) 137 .append(",typeContentDescription=").append(typeContentDescription) 138 .append(",typeContentDescriptionHtml=").append(typeContentDescriptionHtml) 139 .append(",description=").append(description) 140 .append(",isWide=").append(isWide) 141 .append(",subId=").append(subId) 142 .append(",roaming=").append(roaming) 143 .append(",showTriangle=").append(showTriangle) 144 .append(']').toString(); 145 } 146 } 147 148 public interface SignalCallback { 149 /** 150 * Callback for listeners to be able to update the state of any UI tracking connectivity of 151 * WiFi networks. 152 */ setWifiIndicators(WifiIndicators wifiIndicators)153 default void setWifiIndicators(WifiIndicators wifiIndicators) {} 154 155 /** 156 * Callback for listeners to be able to update the state of any UI tracking connectivity 157 * of Mobile networks. 158 */ setMobileDataIndicators(MobileDataIndicators mobileDataIndicators)159 default void setMobileDataIndicators(MobileDataIndicators mobileDataIndicators) {} 160 setSubs(List<SubscriptionInfo> subs)161 default void setSubs(List<SubscriptionInfo> subs) {} 162 setNoSims(boolean show, boolean simDetected)163 default void setNoSims(boolean show, boolean simDetected) {} 164 setEthernetIndicators(IconState icon)165 default void setEthernetIndicators(IconState icon) {} 166 setIsAirplaneMode(IconState icon)167 default void setIsAirplaneMode(IconState icon) {} 168 setMobileDataEnabled(boolean enabled)169 default void setMobileDataEnabled(boolean enabled) {} 170 171 /** 172 * Callback for listeners to be able to update the connectivity status 173 * @param noDefaultNetwork whether there is any default network. 174 * @param noValidatedNetwork whether there is any validated network. 175 * @param noNetworksAvailable whether there is any WiFi networks available. 176 */ setConnectivityStatus(boolean noDefaultNetwork, boolean noValidatedNetwork, boolean noNetworksAvailable)177 default void setConnectivityStatus(boolean noDefaultNetwork, boolean noValidatedNetwork, 178 boolean noNetworksAvailable) {} 179 180 /** 181 * Callback for listeners to be able to update the call indicator 182 * @param statusIcon the icon for the call indicator 183 * @param subId subscription ID for which to update the UI 184 */ setCallIndicator(IconState statusIcon, int subId)185 default void setCallIndicator(IconState statusIcon, int subId) {} 186 } 187 188 public interface EmergencyListener { setEmergencyCallsOnly(boolean emergencyOnly)189 void setEmergencyCallsOnly(boolean emergencyOnly); 190 } 191 192 public static class IconState { 193 public final boolean visible; 194 public final int icon; 195 public final String contentDescription; 196 IconState(boolean visible, int icon, String contentDescription)197 public IconState(boolean visible, int icon, String contentDescription) { 198 this.visible = visible; 199 this.icon = icon; 200 this.contentDescription = contentDescription; 201 } 202 IconState(boolean visible, int icon, int contentDescription, Context context)203 public IconState(boolean visible, int icon, int contentDescription, 204 Context context) { 205 this(visible, icon, context.getString(contentDescription)); 206 } 207 208 @Override toString()209 public String toString() { 210 StringBuilder builder = new StringBuilder(); 211 return builder.append("[visible=").append(visible).append(',') 212 .append("icon=").append(icon).append(',') 213 .append("contentDescription=").append(contentDescription).append(']') 214 .toString(); 215 } 216 } 217 218 /** 219 * Tracks changes in access points. Allows listening for changes, scanning for new APs, 220 * and connecting to new ones. 221 */ 222 public interface AccessPointController { addAccessPointCallback(AccessPointCallback callback)223 void addAccessPointCallback(AccessPointCallback callback); removeAccessPointCallback(AccessPointCallback callback)224 void removeAccessPointCallback(AccessPointCallback callback); scanForAccessPoints()225 void scanForAccessPoints(); getIcon(WifiEntry ap)226 int getIcon(WifiEntry ap); connect(WifiEntry ap)227 boolean connect(WifiEntry ap); canConfigWifi()228 boolean canConfigWifi(); 229 230 public interface AccessPointCallback { onAccessPointsChanged(List<WifiEntry> accessPoints)231 void onAccessPointsChanged(List<WifiEntry> accessPoints); onSettingsActivityTriggered(Intent settingsIntent)232 void onSettingsActivityTriggered(Intent settingsIntent); 233 } 234 } 235 } 236