Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 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 android.net; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.os.Handler; |
| 21 | import android.os.Looper; |
| 22 | import android.os.Message; |
| 23 | import android.os.Messenger; |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 24 | import android.util.Log; |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 25 | |
| 26 | import com.android.internal.util.AsyncChannel; |
| 27 | import com.android.internal.util.Protocol; |
| 28 | |
Robert Greenwalt | 3192dec | 2014-05-27 13:20:24 -0700 | [diff] [blame] | 29 | import java.util.ArrayList; |
fenglu | 95ce803 | 2015-05-01 17:04:36 -0700 | [diff] [blame^] | 30 | import java.util.concurrent.atomic.AtomicBoolean; |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 31 | |
| 32 | /** |
Robert Greenwalt | 3192dec | 2014-05-27 13:20:24 -0700 | [diff] [blame] | 33 | * A Utility class for handling for communicating between bearer-specific |
| 34 | * code and ConnectivityService. |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 35 | * |
| 36 | * A bearer may have more than one NetworkAgent if it can simultaneously |
| 37 | * support separate networks (IMS / Internet / MMS Apns on cellular, or |
Robert Greenwalt | 3192dec | 2014-05-27 13:20:24 -0700 | [diff] [blame] | 38 | * perhaps connections with different SSID or P2P for Wi-Fi). |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 39 | * |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 40 | * @hide |
| 41 | */ |
| 42 | public abstract class NetworkAgent extends Handler { |
Paul Jensen | 31a94f4 | 2015-02-13 14:18:39 -0500 | [diff] [blame] | 43 | // Guaranteed to be valid (not NETID_UNSET), otherwise registerNetworkAgent() would have thrown |
| 44 | // an exception. |
| 45 | public final int netId; |
| 46 | |
Robert Greenwalt | 3192dec | 2014-05-27 13:20:24 -0700 | [diff] [blame] | 47 | private volatile AsyncChannel mAsyncChannel; |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 48 | private final String LOG_TAG; |
| 49 | private static final boolean DBG = true; |
Robert Greenwalt | fc0c689 | 2014-08-27 14:34:02 -0700 | [diff] [blame] | 50 | private static final boolean VDBG = false; |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 51 | private final Context mContext; |
Robert Greenwalt | 3192dec | 2014-05-27 13:20:24 -0700 | [diff] [blame] | 52 | private final ArrayList<Message>mPreConnectedQueue = new ArrayList<Message>(); |
fenglu | b15e72b | 2015-03-20 11:29:56 -0700 | [diff] [blame] | 53 | private volatile long mLastBwRefreshTime = 0; |
| 54 | private static final long BW_REFRESH_MIN_WIN_MS = 500; |
fenglu | 95ce803 | 2015-05-01 17:04:36 -0700 | [diff] [blame^] | 55 | private boolean mPollLceScheduled = false; |
| 56 | private AtomicBoolean mPollLcePending = new AtomicBoolean(false); |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 57 | |
| 58 | private static final int BASE = Protocol.BASE_NETWORK_AGENT; |
| 59 | |
| 60 | /** |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 61 | * Sent by ConnectivityService to the NetworkAgent to inform it of |
| 62 | * suspected connectivity problems on its network. The NetworkAgent |
| 63 | * should take steps to verify and correct connectivity. |
| 64 | */ |
Robert Greenwalt | 3192dec | 2014-05-27 13:20:24 -0700 | [diff] [blame] | 65 | public static final int CMD_SUSPECT_BAD = BASE; |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * Sent by the NetworkAgent (note the EVENT vs CMD prefix) to |
| 69 | * ConnectivityService to pass the current NetworkInfo (connection state). |
| 70 | * Sent when the NetworkInfo changes, mainly due to change of state. |
| 71 | * obj = NetworkInfo |
| 72 | */ |
Robert Greenwalt | 3192dec | 2014-05-27 13:20:24 -0700 | [diff] [blame] | 73 | public static final int EVENT_NETWORK_INFO_CHANGED = BASE + 1; |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * Sent by the NetworkAgent to ConnectivityService to pass the current |
| 77 | * NetworkCapabilties. |
| 78 | * obj = NetworkCapabilities |
| 79 | */ |
Robert Greenwalt | 3192dec | 2014-05-27 13:20:24 -0700 | [diff] [blame] | 80 | public static final int EVENT_NETWORK_CAPABILITIES_CHANGED = BASE + 2; |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * Sent by the NetworkAgent to ConnectivityService to pass the current |
| 84 | * NetworkProperties. |
| 85 | * obj = NetworkProperties |
| 86 | */ |
Robert Greenwalt | 3192dec | 2014-05-27 13:20:24 -0700 | [diff] [blame] | 87 | public static final int EVENT_NETWORK_PROPERTIES_CHANGED = BASE + 3; |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 88 | |
vandwalle | 2ab9089 | 2014-06-02 15:30:39 -0700 | [diff] [blame] | 89 | /* centralize place where base network score, and network score scaling, will be |
| 90 | * stored, so as we can consistently compare apple and oranges, or wifi, ethernet and LTE |
| 91 | */ |
| 92 | public static final int WIFI_BASE_SCORE = 60; |
| 93 | |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 94 | /** |
| 95 | * Sent by the NetworkAgent to ConnectivityService to pass the current |
| 96 | * network score. |
Robert Greenwalt | 3192dec | 2014-05-27 13:20:24 -0700 | [diff] [blame] | 97 | * obj = network score Integer |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 98 | */ |
Robert Greenwalt | 3192dec | 2014-05-27 13:20:24 -0700 | [diff] [blame] | 99 | public static final int EVENT_NETWORK_SCORE_CHANGED = BASE + 4; |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 100 | |
Paul Jensen | 6bc2c2c | 2014-05-07 15:27:40 -0400 | [diff] [blame] | 101 | /** |
| 102 | * Sent by the NetworkAgent to ConnectivityService to add new UID ranges |
| 103 | * to be forced into this Network. For VPNs only. |
| 104 | * obj = UidRange[] to forward |
| 105 | */ |
| 106 | public static final int EVENT_UID_RANGES_ADDED = BASE + 5; |
| 107 | |
| 108 | /** |
| 109 | * Sent by the NetworkAgent to ConnectivityService to remove UID ranges |
| 110 | * from being forced into this Network. For VPNs only. |
| 111 | * obj = UidRange[] to stop forwarding |
| 112 | */ |
| 113 | public static final int EVENT_UID_RANGES_REMOVED = BASE + 6; |
| 114 | |
Sreeram Ramachandran | 42065ac | 2014-07-27 00:37:35 -0700 | [diff] [blame] | 115 | /** |
Lorenzo Colitti | e03c3c7 | 2015-04-03 16:38:52 +0900 | [diff] [blame] | 116 | * Sent by ConnectivityService to the NetworkAgent to inform the agent of the |
Robert Greenwalt | 49f63fb | 2014-09-13 12:04:12 -0700 | [diff] [blame] | 117 | * networks status - whether we could use the network or could not, due to |
| 118 | * either a bad network configuration (no internet link) or captive portal. |
| 119 | * |
| 120 | * arg1 = either {@code VALID_NETWORK} or {@code INVALID_NETWORK} |
| 121 | */ |
Lorenzo Colitti | 6044616 | 2014-09-20 00:14:31 +0900 | [diff] [blame] | 122 | public static final int CMD_REPORT_NETWORK_STATUS = BASE + 7; |
Robert Greenwalt | 49f63fb | 2014-09-13 12:04:12 -0700 | [diff] [blame] | 123 | |
| 124 | public static final int VALID_NETWORK = 1; |
| 125 | public static final int INVALID_NETWORK = 2; |
| 126 | |
Robert Greenwalt | e73cc46 | 2014-09-07 16:50:01 -0700 | [diff] [blame] | 127 | /** |
| 128 | * Sent by the NetworkAgent to ConnectivityService to indicate this network was |
| 129 | * explicitly selected. This should be sent before the NetworkInfo is marked |
| 130 | * CONNECTED so it can be given special treatment at that time. |
Lorenzo Colitti | e03c3c7 | 2015-04-03 16:38:52 +0900 | [diff] [blame] | 131 | * |
| 132 | * obj = boolean indicating whether to use this network even if unvalidated |
Robert Greenwalt | e73cc46 | 2014-09-07 16:50:01 -0700 | [diff] [blame] | 133 | */ |
Lorenzo Colitti | 6044616 | 2014-09-20 00:14:31 +0900 | [diff] [blame] | 134 | public static final int EVENT_SET_EXPLICITLY_SELECTED = BASE + 8; |
Robert Greenwalt | e73cc46 | 2014-09-07 16:50:01 -0700 | [diff] [blame] | 135 | |
Lorenzo Colitti | e03c3c7 | 2015-04-03 16:38:52 +0900 | [diff] [blame] | 136 | /** |
| 137 | * Sent by ConnectivityService to the NetworkAgent to inform the agent of |
| 138 | * whether the network should in the future be used even if not validated. |
| 139 | * This decision is made by the user, but it is the network transport's |
| 140 | * responsibility to remember it. |
| 141 | * |
| 142 | * arg1 = 1 if true, 0 if false |
| 143 | */ |
| 144 | public static final int CMD_SAVE_ACCEPT_UNVALIDATED = BASE + 9; |
| 145 | |
fenglu | b15e72b | 2015-03-20 11:29:56 -0700 | [diff] [blame] | 146 | /** Sent by ConnectivityService to the NetworkAgent to inform the agent to pull |
| 147 | * the underlying network connection for updated bandwidth information. |
| 148 | */ |
| 149 | public static final int CMD_REQUEST_BANDWIDTH_UPDATE = BASE + 10; |
| 150 | |
Robert Greenwalt | 3192dec | 2014-05-27 13:20:24 -0700 | [diff] [blame] | 151 | public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni, |
| 152 | NetworkCapabilities nc, LinkProperties lp, int score) { |
Sreeram Ramachandran | 8cd33ed | 2014-07-23 15:23:15 -0700 | [diff] [blame] | 153 | this(looper, context, logTag, ni, nc, lp, score, null); |
| 154 | } |
| 155 | |
| 156 | public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni, |
| 157 | NetworkCapabilities nc, LinkProperties lp, int score, NetworkMisc misc) { |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 158 | super(looper); |
| 159 | LOG_TAG = logTag; |
| 160 | mContext = context; |
Robert Greenwalt | 3192dec | 2014-05-27 13:20:24 -0700 | [diff] [blame] | 161 | if (ni == null || nc == null || lp == null) { |
| 162 | throw new IllegalArgumentException(); |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 163 | } |
Robert Greenwalt | 3192dec | 2014-05-27 13:20:24 -0700 | [diff] [blame] | 164 | |
Robert Greenwalt | fc0c689 | 2014-08-27 14:34:02 -0700 | [diff] [blame] | 165 | if (VDBG) log("Registering NetworkAgent"); |
Robert Greenwalt | 3192dec | 2014-05-27 13:20:24 -0700 | [diff] [blame] | 166 | ConnectivityManager cm = (ConnectivityManager)mContext.getSystemService( |
| 167 | Context.CONNECTIVITY_SERVICE); |
Paul Jensen | 31a94f4 | 2015-02-13 14:18:39 -0500 | [diff] [blame] | 168 | netId = cm.registerNetworkAgent(new Messenger(this), new NetworkInfo(ni), |
Sreeram Ramachandran | 8cd33ed | 2014-07-23 15:23:15 -0700 | [diff] [blame] | 169 | new LinkProperties(lp), new NetworkCapabilities(nc), score, misc); |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | @Override |
| 173 | public void handleMessage(Message msg) { |
| 174 | switch (msg.what) { |
| 175 | case AsyncChannel.CMD_CHANNEL_FULL_CONNECTION: { |
Robert Greenwalt | 3192dec | 2014-05-27 13:20:24 -0700 | [diff] [blame] | 176 | if (mAsyncChannel != null) { |
| 177 | log("Received new connection while already connected!"); |
| 178 | } else { |
Robert Greenwalt | fc0c689 | 2014-08-27 14:34:02 -0700 | [diff] [blame] | 179 | if (VDBG) log("NetworkAgent fully connected"); |
Robert Greenwalt | 3192dec | 2014-05-27 13:20:24 -0700 | [diff] [blame] | 180 | AsyncChannel ac = new AsyncChannel(); |
| 181 | ac.connected(null, this, msg.replyTo); |
| 182 | ac.replyToMessage(msg, AsyncChannel.CMD_CHANNEL_FULLY_CONNECTED, |
| 183 | AsyncChannel.STATUS_SUCCESSFUL); |
| 184 | synchronized (mPreConnectedQueue) { |
| 185 | mAsyncChannel = ac; |
| 186 | for (Message m : mPreConnectedQueue) { |
| 187 | ac.sendMessage(m); |
| 188 | } |
| 189 | mPreConnectedQueue.clear(); |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | break; |
| 193 | } |
| 194 | case AsyncChannel.CMD_CHANNEL_DISCONNECT: { |
Robert Greenwalt | fc0c689 | 2014-08-27 14:34:02 -0700 | [diff] [blame] | 195 | if (VDBG) log("CMD_CHANNEL_DISCONNECT"); |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 196 | if (mAsyncChannel != null) mAsyncChannel.disconnect(); |
| 197 | break; |
| 198 | } |
| 199 | case AsyncChannel.CMD_CHANNEL_DISCONNECTED: { |
| 200 | if (DBG) log("NetworkAgent channel lost"); |
Robert Greenwalt | 3192dec | 2014-05-27 13:20:24 -0700 | [diff] [blame] | 201 | // let the client know CS is done with us. |
| 202 | unwanted(); |
| 203 | synchronized (mPreConnectedQueue) { |
| 204 | mAsyncChannel = null; |
| 205 | } |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 206 | break; |
| 207 | } |
| 208 | case CMD_SUSPECT_BAD: { |
| 209 | log("Unhandled Message " + msg); |
| 210 | break; |
| 211 | } |
fenglu | b15e72b | 2015-03-20 11:29:56 -0700 | [diff] [blame] | 212 | case CMD_REQUEST_BANDWIDTH_UPDATE: { |
fenglu | 95ce803 | 2015-05-01 17:04:36 -0700 | [diff] [blame^] | 213 | long currentTimeMs = System.currentTimeMillis(); |
fenglu | b15e72b | 2015-03-20 11:29:56 -0700 | [diff] [blame] | 214 | if (VDBG) { |
| 215 | log("CMD_REQUEST_BANDWIDTH_UPDATE request received."); |
| 216 | } |
fenglu | 95ce803 | 2015-05-01 17:04:36 -0700 | [diff] [blame^] | 217 | if (currentTimeMs >= (mLastBwRefreshTime + BW_REFRESH_MIN_WIN_MS)) { |
| 218 | mPollLceScheduled = false; |
| 219 | if (mPollLcePending.getAndSet(true) == false) { |
| 220 | pollLceData(); |
| 221 | } |
| 222 | } else { |
| 223 | // deliver the request at a later time rather than discard it completely. |
| 224 | if (!mPollLceScheduled) { |
| 225 | long waitTime = mLastBwRefreshTime + BW_REFRESH_MIN_WIN_MS - |
| 226 | currentTimeMs + 1; |
| 227 | mPollLceScheduled = sendEmptyMessageDelayed( |
| 228 | CMD_REQUEST_BANDWIDTH_UPDATE, waitTime); |
| 229 | } |
fenglu | b15e72b | 2015-03-20 11:29:56 -0700 | [diff] [blame] | 230 | } |
| 231 | break; |
| 232 | } |
Robert Greenwalt | 49f63fb | 2014-09-13 12:04:12 -0700 | [diff] [blame] | 233 | case CMD_REPORT_NETWORK_STATUS: { |
| 234 | if (VDBG) { |
| 235 | log("CMD_REPORT_NETWORK_STATUS(" + |
| 236 | (msg.arg1 == VALID_NETWORK ? "VALID)" : "INVALID)")); |
| 237 | } |
| 238 | networkStatus(msg.arg1); |
| 239 | break; |
| 240 | } |
Lorenzo Colitti | e03c3c7 | 2015-04-03 16:38:52 +0900 | [diff] [blame] | 241 | case CMD_SAVE_ACCEPT_UNVALIDATED: { |
| 242 | saveAcceptUnvalidated(msg.arg1 != 0); |
| 243 | } |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
Robert Greenwalt | 3192dec | 2014-05-27 13:20:24 -0700 | [diff] [blame] | 247 | private void queueOrSendMessage(int what, Object obj) { |
| 248 | synchronized (mPreConnectedQueue) { |
| 249 | if (mAsyncChannel != null) { |
| 250 | mAsyncChannel.sendMessage(what, obj); |
| 251 | } else { |
| 252 | Message msg = Message.obtain(); |
| 253 | msg.what = what; |
| 254 | msg.obj = obj; |
| 255 | mPreConnectedQueue.add(msg); |
Lorenzo Colitti | 9a6a11a | 2014-05-24 02:25:55 +0900 | [diff] [blame] | 256 | } |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 260 | /** |
| 261 | * Called by the bearer code when it has new LinkProperties data. |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 262 | */ |
| 263 | public void sendLinkProperties(LinkProperties linkProperties) { |
Robert Greenwalt | 3192dec | 2014-05-27 13:20:24 -0700 | [diff] [blame] | 264 | queueOrSendMessage(EVENT_NETWORK_PROPERTIES_CHANGED, new LinkProperties(linkProperties)); |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | /** |
| 268 | * Called by the bearer code when it has new NetworkInfo data. |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 269 | */ |
| 270 | public void sendNetworkInfo(NetworkInfo networkInfo) { |
Robert Greenwalt | 3192dec | 2014-05-27 13:20:24 -0700 | [diff] [blame] | 271 | queueOrSendMessage(EVENT_NETWORK_INFO_CHANGED, new NetworkInfo(networkInfo)); |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | /** |
| 275 | * Called by the bearer code when it has new NetworkCapabilities data. |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 276 | */ |
| 277 | public void sendNetworkCapabilities(NetworkCapabilities networkCapabilities) { |
fenglu | 95ce803 | 2015-05-01 17:04:36 -0700 | [diff] [blame^] | 278 | mPollLcePending.set(false); |
fenglu | b15e72b | 2015-03-20 11:29:56 -0700 | [diff] [blame] | 279 | mLastBwRefreshTime = System.currentTimeMillis(); |
Robert Greenwalt | 3192dec | 2014-05-27 13:20:24 -0700 | [diff] [blame] | 280 | queueOrSendMessage(EVENT_NETWORK_CAPABILITIES_CHANGED, |
| 281 | new NetworkCapabilities(networkCapabilities)); |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | /** |
| 285 | * Called by the bearer code when it has a new score for this network. |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 286 | */ |
Robert Greenwalt | 3192dec | 2014-05-27 13:20:24 -0700 | [diff] [blame] | 287 | public void sendNetworkScore(int score) { |
Robert Greenwalt | 35f7a94 | 2014-09-09 14:46:37 -0700 | [diff] [blame] | 288 | if (score < 0) { |
| 289 | throw new IllegalArgumentException("Score must be >= 0"); |
| 290 | } |
Robert Greenwalt | 3192dec | 2014-05-27 13:20:24 -0700 | [diff] [blame] | 291 | queueOrSendMessage(EVENT_NETWORK_SCORE_CHANGED, new Integer(score)); |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Robert Greenwalt | 3192dec | 2014-05-27 13:20:24 -0700 | [diff] [blame] | 294 | /** |
Paul Jensen | 6bc2c2c | 2014-05-07 15:27:40 -0400 | [diff] [blame] | 295 | * Called by the VPN code when it wants to add ranges of UIDs to be routed |
| 296 | * through the VPN network. |
| 297 | */ |
| 298 | public void addUidRanges(UidRange[] ranges) { |
| 299 | queueOrSendMessage(EVENT_UID_RANGES_ADDED, ranges); |
| 300 | } |
| 301 | |
| 302 | /** |
| 303 | * Called by the VPN code when it wants to remove ranges of UIDs from being routed |
| 304 | * through the VPN network. |
| 305 | */ |
| 306 | public void removeUidRanges(UidRange[] ranges) { |
| 307 | queueOrSendMessage(EVENT_UID_RANGES_REMOVED, ranges); |
| 308 | } |
| 309 | |
| 310 | /** |
Robert Greenwalt | e73cc46 | 2014-09-07 16:50:01 -0700 | [diff] [blame] | 311 | * Called by the bearer to indicate this network was manually selected by the user. |
| 312 | * This should be called before the NetworkInfo is marked CONNECTED so that this |
Lorenzo Colitti | e03c3c7 | 2015-04-03 16:38:52 +0900 | [diff] [blame] | 313 | * Network can be given special treatment at that time. If {@code acceptUnvalidated} is |
| 314 | * {@code true}, then the system will switch to this network. If it is {@code false} and the |
| 315 | * network cannot be validated, the system will ask the user whether to switch to this network. |
| 316 | * If the user confirms and selects "don't ask again", then the system will call |
| 317 | * {@link #saveAcceptUnvalidated} to persist the user's choice. Thus, if the transport ever |
| 318 | * calls this method with {@code acceptUnvalidated} set to {@code false}, it must also implement |
| 319 | * {@link #saveAcceptUnvalidated} to respect the user's choice. |
Robert Greenwalt | e73cc46 | 2014-09-07 16:50:01 -0700 | [diff] [blame] | 320 | */ |
Lorenzo Colitti | e03c3c7 | 2015-04-03 16:38:52 +0900 | [diff] [blame] | 321 | public void explicitlySelected(boolean acceptUnvalidated) { |
| 322 | queueOrSendMessage(EVENT_SET_EXPLICITLY_SELECTED, acceptUnvalidated); |
Robert Greenwalt | e73cc46 | 2014-09-07 16:50:01 -0700 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | /** |
Robert Greenwalt | 3192dec | 2014-05-27 13:20:24 -0700 | [diff] [blame] | 326 | * Called when ConnectivityService has indicated they no longer want this network. |
| 327 | * The parent factory should (previously) have received indication of the change |
| 328 | * as well, either canceling NetworkRequests or altering their score such that this |
| 329 | * network won't be immediately requested again. |
| 330 | */ |
| 331 | abstract protected void unwanted(); |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 332 | |
Robert Greenwalt | 49f63fb | 2014-09-13 12:04:12 -0700 | [diff] [blame] | 333 | /** |
fenglu | b15e72b | 2015-03-20 11:29:56 -0700 | [diff] [blame] | 334 | * Called when ConnectivityService request a bandwidth update. The parent factory |
| 335 | * shall try to overwrite this method and produce a bandwidth update if capable. |
| 336 | */ |
| 337 | protected void pollLceData() { |
| 338 | } |
| 339 | |
| 340 | /** |
Robert Greenwalt | 49f63fb | 2014-09-13 12:04:12 -0700 | [diff] [blame] | 341 | * Called when the system determines the usefulness of this network. |
| 342 | * |
| 343 | * Networks claiming internet connectivity will have their internet |
| 344 | * connectivity verified. |
| 345 | * |
| 346 | * Currently there are two possible values: |
| 347 | * {@code VALID_NETWORK} if the system is happy with the connection, |
| 348 | * {@code INVALID_NETWORK} if the system is not happy. |
| 349 | * TODO - add indications of captive portal-ness and related success/failure, |
| 350 | * ie, CAPTIVE_SUCCESS_NETWORK, CAPTIVE_NETWORK for successful login and detection |
| 351 | * |
| 352 | * This may be called multiple times as the network status changes and may |
| 353 | * generate false negatives if we lose ip connectivity before the link is torn down. |
| 354 | */ |
| 355 | protected void networkStatus(int status) { |
| 356 | } |
| 357 | |
Lorenzo Colitti | e03c3c7 | 2015-04-03 16:38:52 +0900 | [diff] [blame] | 358 | /** |
| 359 | * Called when the user asks to remember the choice to use this network even if unvalidated. |
| 360 | * The transport is responsible for remembering the choice, and the next time the user connects |
| 361 | * to the network, should explicitlySelected with {@code acceptUnvalidated} set to {@code true}. |
| 362 | * This method will only be called if {@link #explicitlySelected} was called with |
| 363 | * {@code acceptUnvalidated} set to {@code false}. |
| 364 | */ |
| 365 | protected void saveAcceptUnvalidated(boolean accept) { |
| 366 | } |
| 367 | |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame] | 368 | protected void log(String s) { |
| 369 | Log.d(LOG_TAG, "NetworkAgent: " + s); |
| 370 | } |
| 371 | } |