blob: 9fa362c8776dc3491c8364f905c7fecf74cf808d [file] [log] [blame]
Paul Jensenca8f16a2014-05-09 12:47:55 -04001/*
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
17package com.android.server.connectivity;
18
Paul Jensen79a08052014-08-21 12:44:07 -040019import android.app.AlarmManager;
Paul Jensen869868be2014-05-15 10:33:05 -040020import android.app.PendingIntent;
21import android.content.BroadcastReceiver;
22import android.content.ComponentName;
Paul Jensenca8f16a2014-05-09 12:47:55 -040023import android.content.Context;
Paul Jensen869868be2014-05-15 10:33:05 -040024import android.content.Intent;
25import android.content.IntentFilter;
26import android.net.ConnectivityManager;
27import android.net.Network;
Paul Jensenca8f16a2014-05-09 12:47:55 -040028import android.net.NetworkCapabilities;
29import android.net.NetworkInfo;
Paul Jensen2c311d62014-11-17 12:34:51 -050030import android.net.NetworkRequest;
Paul Jensen7ccd3df2014-08-29 09:54:01 -040031import android.net.TrafficStats;
Paul Jensen71b645f2014-10-13 14:13:07 -040032import android.net.Uri;
Paul Jensen306f1a42014-08-04 10:59:01 -040033import android.net.wifi.WifiInfo;
34import android.net.wifi.WifiManager;
Paul Jensenca8f16a2014-05-09 12:47:55 -040035import android.os.Handler;
36import android.os.Message;
Paul Jensen306f1a42014-08-04 10:59:01 -040037import android.os.SystemClock;
Paul Jensenca8f16a2014-05-09 12:47:55 -040038import android.os.SystemProperties;
Paul Jensen869868be2014-05-15 10:33:05 -040039import android.os.UserHandle;
Paul Jensenca8f16a2014-05-09 12:47:55 -040040import android.provider.Settings;
Paul Jensen306f1a42014-08-04 10:59:01 -040041import android.telephony.CellIdentityCdma;
42import android.telephony.CellIdentityGsm;
43import android.telephony.CellIdentityLte;
44import android.telephony.CellIdentityWcdma;
45import android.telephony.CellInfo;
46import android.telephony.CellInfoCdma;
47import android.telephony.CellInfoGsm;
48import android.telephony.CellInfoLte;
49import android.telephony.CellInfoWcdma;
50import android.telephony.TelephonyManager;
Paul Jensen532b61432014-11-10 09:50:02 -050051import android.util.Log;
Paul Jensenca8f16a2014-05-09 12:47:55 -040052
53import com.android.internal.util.Protocol;
54import com.android.internal.util.State;
55import com.android.internal.util.StateMachine;
Paul Jensen869868be2014-05-15 10:33:05 -040056import com.android.server.ConnectivityService;
Paul Jensenca8f16a2014-05-09 12:47:55 -040057import com.android.server.connectivity.NetworkAgentInfo;
58
Paul Jensenca8f16a2014-05-09 12:47:55 -040059import java.io.IOException;
Paul Jensenca8f16a2014-05-09 12:47:55 -040060import java.net.HttpURLConnection;
Paul Jensenca8f16a2014-05-09 12:47:55 -040061import java.net.URL;
Paul Jensen306f1a42014-08-04 10:59:01 -040062import java.util.List;
Paul Jensen71b645f2014-10-13 14:13:07 -040063import java.util.Random;
Paul Jensenca8f16a2014-05-09 12:47:55 -040064
65/**
66 * {@hide}
67 */
68public class NetworkMonitor extends StateMachine {
69 private static final boolean DBG = true;
70 private static final String TAG = "NetworkMonitor";
71 private static final String DEFAULT_SERVER = "clients3.google.com";
72 private static final int SOCKET_TIMEOUT_MS = 10000;
Paul Jensen306f1a42014-08-04 10:59:01 -040073 public static final String ACTION_NETWORK_CONDITIONS_MEASURED =
74 "android.net.conn.NETWORK_CONDITIONS_MEASURED";
75 public static final String EXTRA_CONNECTIVITY_TYPE = "extra_connectivity_type";
76 public static final String EXTRA_NETWORK_TYPE = "extra_network_type";
77 public static final String EXTRA_RESPONSE_RECEIVED = "extra_response_received";
78 public static final String EXTRA_IS_CAPTIVE_PORTAL = "extra_is_captive_portal";
79 public static final String EXTRA_CELL_ID = "extra_cellid";
80 public static final String EXTRA_SSID = "extra_ssid";
81 public static final String EXTRA_BSSID = "extra_bssid";
82 /** real time since boot */
83 public static final String EXTRA_REQUEST_TIMESTAMP_MS = "extra_request_timestamp_ms";
84 public static final String EXTRA_RESPONSE_TIMESTAMP_MS = "extra_response_timestamp_ms";
85
86 private static final String PERMISSION_ACCESS_NETWORK_CONDITIONS =
87 "android.permission.ACCESS_NETWORK_CONDITIONS";
Paul Jensenca8f16a2014-05-09 12:47:55 -040088
Paul Jensen869868be2014-05-15 10:33:05 -040089 // Keep these in sync with CaptivePortalLoginActivity.java.
90 // Intent broadcast from CaptivePortalLogin indicating sign-in is complete.
91 // Extras:
92 // EXTRA_TEXT = netId
Paul Jensen71b645f2014-10-13 14:13:07 -040093 // LOGGED_IN_RESULT = one of the CAPTIVE_PORTAL_APP_RETURN_* values below.
94 // RESPONSE_TOKEN = data fragment from launching Intent
Paul Jensen869868be2014-05-15 10:33:05 -040095 private static final String ACTION_CAPTIVE_PORTAL_LOGGED_IN =
96 "android.net.netmon.captive_portal_logged_in";
97 private static final String LOGGED_IN_RESULT = "result";
Paul Jensen71b645f2014-10-13 14:13:07 -040098 private static final String RESPONSE_TOKEN = "response_token";
Paul Jensen869868be2014-05-15 10:33:05 -040099
Paul Jensenad50a1f2014-09-05 12:06:44 -0400100 // After a network has been tested this result can be sent with EVENT_NETWORK_TESTED.
101 // The network should be used as a default internet connection. It was found to be:
102 // 1. a functioning network providing internet access, or
103 // 2. a captive portal and the user decided to use it as is.
104 public static final int NETWORK_TEST_RESULT_VALID = 0;
105 // After a network has been tested this result can be sent with EVENT_NETWORK_TESTED.
106 // The network should not be used as a default internet connection. It was found to be:
107 // 1. a captive portal and the user is prompted to sign-in, or
108 // 2. a captive portal and the user did not want to use it, or
109 // 3. a broken network (e.g. DNS failed, connect failed, HTTP request failed).
110 public static final int NETWORK_TEST_RESULT_INVALID = 1;
111
Paul Jensenca8f16a2014-05-09 12:47:55 -0400112 private static final int BASE = Protocol.BASE_NETWORK_MONITOR;
113
114 /**
115 * Inform NetworkMonitor that their network is connected.
116 * Initiates Network Validation.
117 */
118 public static final int CMD_NETWORK_CONNECTED = BASE + 1;
119
120 /**
Paul Jensenad50a1f2014-09-05 12:06:44 -0400121 * Inform ConnectivityService that the network has been tested.
Paul Jensenca8f16a2014-05-09 12:47:55 -0400122 * obj = NetworkAgentInfo
Paul Jensenad50a1f2014-09-05 12:06:44 -0400123 * arg1 = One of the NETWORK_TESTED_RESULT_* constants.
Paul Jensenca8f16a2014-05-09 12:47:55 -0400124 */
Paul Jensenad50a1f2014-09-05 12:06:44 -0400125 public static final int EVENT_NETWORK_TESTED = BASE + 2;
Paul Jensenca8f16a2014-05-09 12:47:55 -0400126
127 /**
128 * Inform NetworkMonitor to linger a network. The Monitor should
129 * start a timer and/or start watching for zero live connections while
130 * moving towards LINGER_COMPLETE. After the Linger period expires
131 * (or other events mark the end of the linger state) the LINGER_COMPLETE
132 * event should be sent and the network will be shut down. If a
133 * CMD_NETWORK_CONNECTED happens before the LINGER completes
134 * it indicates further desire to keep the network alive and so
135 * the LINGER is aborted.
136 */
137 public static final int CMD_NETWORK_LINGER = BASE + 3;
138
139 /**
140 * Message to self indicating linger delay has expired.
141 * arg1 = Token to ignore old messages.
142 */
143 private static final int CMD_LINGER_EXPIRED = BASE + 4;
144
145 /**
146 * Inform ConnectivityService that the network LINGER period has
147 * expired.
148 * obj = NetworkAgentInfo
149 */
150 public static final int EVENT_NETWORK_LINGER_COMPLETE = BASE + 5;
151
152 /**
Paul Jensenca8f16a2014-05-09 12:47:55 -0400153 * Message to self indicating it's time to evaluate a network's connectivity.
154 * arg1 = Token to ignore old messages.
155 */
Paul Jensen869868be2014-05-15 10:33:05 -0400156 private static final int CMD_REEVALUATE = BASE + 6;
Paul Jensenca8f16a2014-05-09 12:47:55 -0400157
158 /**
Paul Jensenca8f16a2014-05-09 12:47:55 -0400159 * Inform NetworkMonitor that the network has disconnected.
160 */
Paul Jensen7ccd3df2014-08-29 09:54:01 -0400161 public static final int CMD_NETWORK_DISCONNECTED = BASE + 7;
Paul Jensenca8f16a2014-05-09 12:47:55 -0400162
163 /**
164 * Force evaluation even if it has succeeded in the past.
Paul Jensen7ccd3df2014-08-29 09:54:01 -0400165 * arg1 = UID responsible for requesting this reeval. Will be billed for data.
Paul Jensenca8f16a2014-05-09 12:47:55 -0400166 */
Paul Jensen7ccd3df2014-08-29 09:54:01 -0400167 public static final int CMD_FORCE_REEVALUATION = BASE + 8;
Paul Jensen869868be2014-05-15 10:33:05 -0400168
169 /**
Paul Jensen71b645f2014-10-13 14:13:07 -0400170 * Message to self indicating captive portal app finished.
171 * arg1 = one of: CAPTIVE_PORTAL_APP_RETURN_APPEASED,
172 * CAPTIVE_PORTAL_APP_RETURN_UNWANTED,
173 * CAPTIVE_PORTAL_APP_RETURN_WANTED_AS_IS
Paul Jensen869868be2014-05-15 10:33:05 -0400174 */
Paul Jensen71b645f2014-10-13 14:13:07 -0400175 private static final int CMD_CAPTIVE_PORTAL_APP_FINISHED = BASE + 9;
Paul Jensen869868be2014-05-15 10:33:05 -0400176
177 /**
178 * Request ConnectivityService display provisioning notification.
179 * arg1 = Whether to make the notification visible.
Paul Jensenfdc4e4a2014-07-15 12:07:36 -0400180 * arg2 = NetID.
181 * obj = Intent to be launched when notification selected by user, null if !arg1.
Paul Jensen869868be2014-05-15 10:33:05 -0400182 */
Paul Jensen71b645f2014-10-13 14:13:07 -0400183 public static final int EVENT_PROVISIONING_NOTIFICATION = BASE + 10;
Paul Jensen869868be2014-05-15 10:33:05 -0400184
185 /**
186 * Message to self indicating sign-in app bypassed captive portal.
187 */
Paul Jensen71b645f2014-10-13 14:13:07 -0400188 private static final int EVENT_APP_BYPASSED_CAPTIVE_PORTAL = BASE + 11;
Paul Jensen869868be2014-05-15 10:33:05 -0400189
190 /**
191 * Message to self indicating no sign-in app responded.
192 */
Paul Jensen71b645f2014-10-13 14:13:07 -0400193 private static final int EVENT_NO_APP_RESPONSE = BASE + 12;
Paul Jensen869868be2014-05-15 10:33:05 -0400194
195 /**
196 * Message to self indicating sign-in app indicates sign-in is not possible.
197 */
Paul Jensen71b645f2014-10-13 14:13:07 -0400198 private static final int EVENT_APP_INDICATES_SIGN_IN_IMPOSSIBLE = BASE + 13;
199
200 /**
201 * Return codes from captive portal sign-in app.
202 */
203 public static final int CAPTIVE_PORTAL_APP_RETURN_APPEASED = 0;
204 public static final int CAPTIVE_PORTAL_APP_RETURN_UNWANTED = 1;
205 public static final int CAPTIVE_PORTAL_APP_RETURN_WANTED_AS_IS = 2;
Paul Jensenca8f16a2014-05-09 12:47:55 -0400206
207 private static final String LINGER_DELAY_PROPERTY = "persist.netmon.linger";
208 // Default to 30s linger time-out.
209 private static final int DEFAULT_LINGER_DELAY_MS = 30000;
210 private final int mLingerDelayMs;
211 private int mLingerToken = 0;
212
Paul Jensenca8f16a2014-05-09 12:47:55 -0400213 // Negative values disable reevaluation.
214 private static final String REEVALUATE_DELAY_PROPERTY = "persist.netmon.reeval_delay";
215 // Default to 5s reevaluation delay.
216 private static final int DEFAULT_REEVALUATE_DELAY_MS = 5000;
Paul Jensen869868be2014-05-15 10:33:05 -0400217 private static final int MAX_RETRIES = 10;
Paul Jensen7bd8eaf2014-12-03 09:44:31 -0500218 // Between groups of MAX_RETRIES evaluation attempts, pause 10 mins in hopes ISP outage passes.
219 private static final int REEVALUATE_PAUSE_MS = 10*60*1000;
Paul Jensenca8f16a2014-05-09 12:47:55 -0400220 private final int mReevaluateDelayMs;
221 private int mReevaluateToken = 0;
Paul Jensen7ccd3df2014-08-29 09:54:01 -0400222 private static final int INVALID_UID = -1;
223 private int mUidResponsibleForReeval = INVALID_UID;
Paul Jensenca8f16a2014-05-09 12:47:55 -0400224
225 private final Context mContext;
226 private final Handler mConnectivityServiceHandler;
227 private final NetworkAgentInfo mNetworkAgentInfo;
Paul Jensen306f1a42014-08-04 10:59:01 -0400228 private final TelephonyManager mTelephonyManager;
229 private final WifiManager mWifiManager;
Paul Jensen79a08052014-08-21 12:44:07 -0400230 private final AlarmManager mAlarmManager;
Paul Jensen2c311d62014-11-17 12:34:51 -0500231 private final NetworkRequest mDefaultRequest;
Paul Jensenca8f16a2014-05-09 12:47:55 -0400232
233 private String mServer;
234 private boolean mIsCaptivePortalCheckEnabled = false;
235
Paul Jensenad50a1f2014-09-05 12:06:44 -0400236 // Set if the user explicitly selected "Do not use this network" in captive portal sign-in app.
237 private boolean mUserDoesNotWant = false;
238
Robert Greenwaltfb68f8f2014-08-13 13:43:32 -0700239 public boolean systemReady = false;
240
Paul Jensen71b645f2014-10-13 14:13:07 -0400241 private final State mDefaultState = new DefaultState();
242 private final State mOfflineState = new OfflineState();
243 private final State mValidatedState = new ValidatedState();
244 private final State mMaybeNotifyState = new MaybeNotifyState();
245 private final State mEvaluatingState = new EvaluatingState();
246 private final State mCaptivePortalState = new CaptivePortalState();
247 private final State mLingeringState = new LingeringState();
248
249 private CaptivePortalLoggedInBroadcastReceiver mCaptivePortalLoggedInBroadcastReceiver = null;
250 private String mCaptivePortalLoggedInResponseToken = null;
Paul Jensenca8f16a2014-05-09 12:47:55 -0400251
Paul Jensen2c311d62014-11-17 12:34:51 -0500252 public NetworkMonitor(Context context, Handler handler, NetworkAgentInfo networkAgentInfo,
253 NetworkRequest defaultRequest) {
Paul Jensenca8f16a2014-05-09 12:47:55 -0400254 // Add suffix indicating which NetworkMonitor we're talking about.
255 super(TAG + networkAgentInfo.name());
256
257 mContext = context;
258 mConnectivityServiceHandler = handler;
259 mNetworkAgentInfo = networkAgentInfo;
Paul Jensen306f1a42014-08-04 10:59:01 -0400260 mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
261 mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
Paul Jensen79a08052014-08-21 12:44:07 -0400262 mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Paul Jensen2c311d62014-11-17 12:34:51 -0500263 mDefaultRequest = defaultRequest;
Paul Jensenca8f16a2014-05-09 12:47:55 -0400264
265 addState(mDefaultState);
266 addState(mOfflineState, mDefaultState);
267 addState(mValidatedState, mDefaultState);
Paul Jensen71b645f2014-10-13 14:13:07 -0400268 addState(mMaybeNotifyState, mDefaultState);
269 addState(mEvaluatingState, mMaybeNotifyState);
270 addState(mCaptivePortalState, mMaybeNotifyState);
Paul Jensenca8f16a2014-05-09 12:47:55 -0400271 addState(mLingeringState, mDefaultState);
Robert Greenwalt49f63fb2014-09-13 12:04:12 -0700272 setInitialState(mDefaultState);
Paul Jensenca8f16a2014-05-09 12:47:55 -0400273
274 mServer = Settings.Global.getString(mContext.getContentResolver(),
275 Settings.Global.CAPTIVE_PORTAL_SERVER);
276 if (mServer == null) mServer = DEFAULT_SERVER;
277
278 mLingerDelayMs = SystemProperties.getInt(LINGER_DELAY_PROPERTY, DEFAULT_LINGER_DELAY_MS);
279 mReevaluateDelayMs = SystemProperties.getInt(REEVALUATE_DELAY_PROPERTY,
280 DEFAULT_REEVALUATE_DELAY_MS);
281
Paul Jensen869868be2014-05-15 10:33:05 -0400282 mIsCaptivePortalCheckEnabled = Settings.Global.getInt(mContext.getContentResolver(),
283 Settings.Global.CAPTIVE_PORTAL_DETECTION_ENABLED, 1) == 1;
Paul Jensenca8f16a2014-05-09 12:47:55 -0400284
Paul Jensen71b645f2014-10-13 14:13:07 -0400285 mCaptivePortalLoggedInResponseToken = String.valueOf(new Random().nextLong());
286
Paul Jensenca8f16a2014-05-09 12:47:55 -0400287 start();
288 }
289
Paul Jensen532b61432014-11-10 09:50:02 -0500290 @Override
291 protected void log(String s) {
Paul Jensen71b645f2014-10-13 14:13:07 -0400292 Log.d(TAG + "/" + mNetworkAgentInfo.name(), s);
Paul Jensen532b61432014-11-10 09:50:02 -0500293 }
294
Paul Jensen71b645f2014-10-13 14:13:07 -0400295 // DefaultState is the parent of all States. It exists only to handle CMD_* messages but
296 // does not entail any real state (hence no enter() or exit() routines).
Paul Jensenca8f16a2014-05-09 12:47:55 -0400297 private class DefaultState extends State {
298 @Override
299 public boolean processMessage(Message message) {
300 if (DBG) log(getName() + message.toString());
301 switch (message.what) {
302 case CMD_NETWORK_LINGER:
303 if (DBG) log("Lingering");
304 transitionTo(mLingeringState);
Paul Jensend6a3f7e2014-08-19 09:40:11 -0400305 return HANDLED;
Paul Jensenca8f16a2014-05-09 12:47:55 -0400306 case CMD_NETWORK_CONNECTED:
307 if (DBG) log("Connected");
308 transitionTo(mEvaluatingState);
Paul Jensend6a3f7e2014-08-19 09:40:11 -0400309 return HANDLED;
Paul Jensenca8f16a2014-05-09 12:47:55 -0400310 case CMD_NETWORK_DISCONNECTED:
Robert Greenwalt1fd9aee2014-07-17 16:11:38 -0700311 if (DBG) log("Disconnected - quitting");
Paul Jensen71b645f2014-10-13 14:13:07 -0400312 if (mCaptivePortalLoggedInBroadcastReceiver != null) {
313 mContext.unregisterReceiver(mCaptivePortalLoggedInBroadcastReceiver);
314 mCaptivePortalLoggedInBroadcastReceiver = null;
315 }
Robert Greenwalt1fd9aee2014-07-17 16:11:38 -0700316 quit();
Paul Jensend6a3f7e2014-08-19 09:40:11 -0400317 return HANDLED;
Paul Jensenca8f16a2014-05-09 12:47:55 -0400318 case CMD_FORCE_REEVALUATION:
319 if (DBG) log("Forcing reevaluation");
Paul Jensen7ccd3df2014-08-29 09:54:01 -0400320 mUidResponsibleForReeval = message.arg1;
Paul Jensenca8f16a2014-05-09 12:47:55 -0400321 transitionTo(mEvaluatingState);
Paul Jensend6a3f7e2014-08-19 09:40:11 -0400322 return HANDLED;
Paul Jensen71b645f2014-10-13 14:13:07 -0400323 case CMD_CAPTIVE_PORTAL_APP_FINISHED:
324 // Previous token was broadcast, come up with a new one.
325 mCaptivePortalLoggedInResponseToken = String.valueOf(new Random().nextLong());
326 switch (message.arg1) {
327 case CAPTIVE_PORTAL_APP_RETURN_APPEASED:
328 case CAPTIVE_PORTAL_APP_RETURN_WANTED_AS_IS:
329 transitionTo(mValidatedState);
330 break;
331 case CAPTIVE_PORTAL_APP_RETURN_UNWANTED:
332 mUserDoesNotWant = true;
333 // TODO: Should teardown network.
334 transitionTo(mOfflineState);
335 break;
336 }
337 return HANDLED;
Paul Jensenca8f16a2014-05-09 12:47:55 -0400338 default:
Paul Jensend6a3f7e2014-08-19 09:40:11 -0400339 return HANDLED;
Paul Jensenca8f16a2014-05-09 12:47:55 -0400340 }
Paul Jensenca8f16a2014-05-09 12:47:55 -0400341 }
342 }
343
Paul Jensen71b645f2014-10-13 14:13:07 -0400344 // Being in the OfflineState State indicates a Network is unwanted or failed validation.
Paul Jensenca8f16a2014-05-09 12:47:55 -0400345 private class OfflineState extends State {
346 @Override
Paul Jensenad50a1f2014-09-05 12:06:44 -0400347 public void enter() {
348 mConnectivityServiceHandler.sendMessage(obtainMessage(EVENT_NETWORK_TESTED,
349 NETWORK_TEST_RESULT_INVALID, 0, mNetworkAgentInfo));
Paul Jensen7bd8eaf2014-12-03 09:44:31 -0500350 if (!mUserDoesNotWant) sendMessageDelayed(CMD_FORCE_REEVALUATION, REEVALUATE_PAUSE_MS);
Paul Jensenad50a1f2014-09-05 12:06:44 -0400351 }
352
353 @Override
Paul Jensenca8f16a2014-05-09 12:47:55 -0400354 public boolean processMessage(Message message) {
355 if (DBG) log(getName() + message.toString());
Paul Jensenad50a1f2014-09-05 12:06:44 -0400356 switch (message.what) {
357 case CMD_FORCE_REEVALUATION:
358 // If the user has indicated they explicitly do not want to use this network,
359 // don't allow a reevaluation as this will be pointless and could result in
360 // the user being annoyed with repeated unwanted notifications.
361 return mUserDoesNotWant ? HANDLED : NOT_HANDLED;
362 default:
363 return NOT_HANDLED;
364 }
Paul Jensenca8f16a2014-05-09 12:47:55 -0400365 }
Paul Jensen7bd8eaf2014-12-03 09:44:31 -0500366
367 @Override
368 public void exit() {
369 // NOTE: This removes the delayed message posted by enter() but will inadvertently
370 // remove any other CMD_FORCE_REEVALUATION in the message queue. At the moment this
371 // is harmless. If in the future this becomes problematic a different message could
372 // be used.
373 removeMessages(CMD_FORCE_REEVALUATION);
374 }
Paul Jensenca8f16a2014-05-09 12:47:55 -0400375 }
376
Paul Jensen71b645f2014-10-13 14:13:07 -0400377 // Being in the ValidatedState State indicates a Network is:
378 // - Successfully validated, or
379 // - Wanted "as is" by the user, or
380 // - Does not satsify the default NetworkRequest and so validation has been skipped.
Paul Jensenca8f16a2014-05-09 12:47:55 -0400381 private class ValidatedState extends State {
382 @Override
383 public void enter() {
384 if (DBG) log("Validated");
Paul Jensenad50a1f2014-09-05 12:06:44 -0400385 mConnectivityServiceHandler.sendMessage(obtainMessage(EVENT_NETWORK_TESTED,
386 NETWORK_TEST_RESULT_VALID, 0, mNetworkAgentInfo));
Paul Jensenca8f16a2014-05-09 12:47:55 -0400387 }
388
389 @Override
390 public boolean processMessage(Message message) {
391 if (DBG) log(getName() + message.toString());
392 switch (message.what) {
393 case CMD_NETWORK_CONNECTED:
394 transitionTo(mValidatedState);
Paul Jensend6a3f7e2014-08-19 09:40:11 -0400395 return HANDLED;
Paul Jensenca8f16a2014-05-09 12:47:55 -0400396 default:
397 return NOT_HANDLED;
398 }
Paul Jensenca8f16a2014-05-09 12:47:55 -0400399 }
400 }
401
Paul Jensen71b645f2014-10-13 14:13:07 -0400402 // Being in the MaybeNotifyState State indicates the user may have been notified that sign-in
403 // is required. This State takes care to clear the notification upon exit from the State.
404 private class MaybeNotifyState extends State {
405 @Override
406 public void exit() {
407 Message message = obtainMessage(EVENT_PROVISIONING_NOTIFICATION, 0,
408 mNetworkAgentInfo.network.netId, null);
409 mConnectivityServiceHandler.sendMessage(message);
410 }
411 }
412
413 // Being in the EvaluatingState State indicates the Network is being evaluated for internet
414 // connectivity.
Paul Jensenca8f16a2014-05-09 12:47:55 -0400415 private class EvaluatingState extends State {
Paul Jensen869868be2014-05-15 10:33:05 -0400416 private int mRetries;
417
Paul Jensenca8f16a2014-05-09 12:47:55 -0400418 @Override
419 public void enter() {
Paul Jensen869868be2014-05-15 10:33:05 -0400420 mRetries = 0;
Paul Jensenca8f16a2014-05-09 12:47:55 -0400421 sendMessage(CMD_REEVALUATE, ++mReevaluateToken, 0);
Paul Jensen7ccd3df2014-08-29 09:54:01 -0400422 if (mUidResponsibleForReeval != INVALID_UID) {
423 TrafficStats.setThreadStatsUid(mUidResponsibleForReeval);
424 mUidResponsibleForReeval = INVALID_UID;
425 }
Paul Jensenca8f16a2014-05-09 12:47:55 -0400426 }
427
428 @Override
429 public boolean processMessage(Message message) {
430 if (DBG) log(getName() + message.toString());
431 switch (message.what) {
432 case CMD_REEVALUATE:
433 if (message.arg1 != mReevaluateToken)
Paul Jensend6a3f7e2014-08-19 09:40:11 -0400434 return HANDLED;
Paul Jensen2c311d62014-11-17 12:34:51 -0500435 // Don't bother validating networks that don't satisify the default request.
436 // This includes:
437 // - VPNs which can be considered explicitly desired by the user and the
438 // user's desire trumps whether the network validates.
439 // - Networks that don't provide internet access. It's unclear how to
440 // validate such networks.
441 // - Untrusted networks. It's unsafe to prompt the user to sign-in to
442 // such networks and the user didn't express interest in connecting to
443 // such networks (an app did) so the user may be unhappily surprised when
444 // asked to sign-in to a network they didn't want to connect to in the
445 // first place. Validation could be done to adjust the network scores
446 // however these networks are app-requested and may not be intended for
447 // general usage, in which case general validation may not be an accurate
448 // measure of the network's quality. Only the app knows how to evaluate
449 // the network so don't bother validating here. Furthermore sending HTTP
450 // packets over the network may be undesirable, for example an extremely
451 // expensive metered network, or unwanted leaking of the User Agent string.
452 if (!mDefaultRequest.networkCapabilities.satisfiedByNetworkCapabilities(
453 mNetworkAgentInfo.networkCapabilities)) {
Paul Jensenca8f16a2014-05-09 12:47:55 -0400454 transitionTo(mValidatedState);
Paul Jensend6a3f7e2014-08-19 09:40:11 -0400455 return HANDLED;
Paul Jensenca8f16a2014-05-09 12:47:55 -0400456 }
Paul Jensen71b645f2014-10-13 14:13:07 -0400457 // Note: This call to isCaptivePortal() could take minutes. Resolving the
458 // server's IP addresses could hit the DNS timeout and attempting connections
459 // to each of the server's several (e.g. 11) IP addresses could each take
460 // SOCKET_TIMEOUT_MS. During this time this StateMachine will be unresponsive.
461 // isCaptivePortal() could be executed on another Thread if this is found to
462 // cause problems.
Paul Jensen7ccd3df2014-08-29 09:54:01 -0400463 int httpResponseCode = isCaptivePortal();
Paul Jensenca8f16a2014-05-09 12:47:55 -0400464 if (httpResponseCode == 204) {
465 transitionTo(mValidatedState);
466 } else if (httpResponseCode >= 200 && httpResponseCode <= 399) {
Paul Jensen71b645f2014-10-13 14:13:07 -0400467 transitionTo(mCaptivePortalState);
Paul Jensen869868be2014-05-15 10:33:05 -0400468 } else if (++mRetries > MAX_RETRIES) {
469 transitionTo(mOfflineState);
470 } else if (mReevaluateDelayMs >= 0) {
471 Message msg = obtainMessage(CMD_REEVALUATE, ++mReevaluateToken, 0);
472 sendMessageDelayed(msg, mReevaluateDelayMs);
Paul Jensenca8f16a2014-05-09 12:47:55 -0400473 }
Paul Jensend6a3f7e2014-08-19 09:40:11 -0400474 return HANDLED;
Paul Jensen7ccd3df2014-08-29 09:54:01 -0400475 case CMD_FORCE_REEVALUATION:
476 // Ignore duplicate requests.
477 return HANDLED;
Paul Jensenca8f16a2014-05-09 12:47:55 -0400478 default:
479 return NOT_HANDLED;
480 }
Paul Jensenca8f16a2014-05-09 12:47:55 -0400481 }
Paul Jensen7ccd3df2014-08-29 09:54:01 -0400482
483 @Override
484 public void exit() {
485 TrafficStats.clearThreadStatsUid();
486 }
Paul Jensenca8f16a2014-05-09 12:47:55 -0400487 }
488
Paul Jensendcbe8352014-09-16 16:28:34 -0400489 // BroadcastReceiver that waits for a particular Intent and then posts a message.
490 private class CustomIntentReceiver extends BroadcastReceiver {
Paul Jensen71b645f2014-10-13 14:13:07 -0400491 private final int mToken;
492 private final int mWhat;
Paul Jensendcbe8352014-09-16 16:28:34 -0400493 private final String mAction;
Paul Jensen71b645f2014-10-13 14:13:07 -0400494 CustomIntentReceiver(String action, int token, int what) {
495 mToken = token;
496 mWhat = what;
Paul Jensendcbe8352014-09-16 16:28:34 -0400497 mAction = action + "_" + mNetworkAgentInfo.network.netId + "_" + token;
498 mContext.registerReceiver(this, new IntentFilter(mAction));
Paul Jensen869868be2014-05-15 10:33:05 -0400499 }
Paul Jensendcbe8352014-09-16 16:28:34 -0400500 public PendingIntent getPendingIntent() {
501 return PendingIntent.getBroadcast(mContext, 0, new Intent(mAction), 0);
502 }
503 @Override
504 public void onReceive(Context context, Intent intent) {
Paul Jensen71b645f2014-10-13 14:13:07 -0400505 if (intent.getAction().equals(mAction)) sendMessage(obtainMessage(mWhat, mToken));
Paul Jensendcbe8352014-09-16 16:28:34 -0400506 }
507 }
Paul Jensen869868be2014-05-15 10:33:05 -0400508
Paul Jensen71b645f2014-10-13 14:13:07 -0400509 private class CaptivePortalLoggedInBroadcastReceiver extends BroadcastReceiver {
510 @Override
511 public void onReceive(Context context, Intent intent) {
512 if (Integer.parseInt(intent.getStringExtra(Intent.EXTRA_TEXT)) ==
513 mNetworkAgentInfo.network.netId &&
514 mCaptivePortalLoggedInResponseToken.equals(
515 intent.getStringExtra(RESPONSE_TOKEN))) {
516 sendMessage(obtainMessage(CMD_CAPTIVE_PORTAL_APP_FINISHED,
517 Integer.parseInt(intent.getStringExtra(LOGGED_IN_RESULT)), 0));
518 }
519 }
520 }
Paul Jensendcbe8352014-09-16 16:28:34 -0400521
Paul Jensen71b645f2014-10-13 14:13:07 -0400522 // Being in the CaptivePortalState State indicates a captive portal was detected and the user
523 // has been shown a notification to sign-in.
524 private class CaptivePortalState extends State {
Paul Jensen869868be2014-05-15 10:33:05 -0400525 @Override
526 public void enter() {
Paul Jensenad50a1f2014-09-05 12:06:44 -0400527 mConnectivityServiceHandler.sendMessage(obtainMessage(EVENT_NETWORK_TESTED,
528 NETWORK_TEST_RESULT_INVALID, 0, mNetworkAgentInfo));
Paul Jensenca8f16a2014-05-09 12:47:55 -0400529
Paul Jensen71b645f2014-10-13 14:13:07 -0400530 // Assemble Intent to launch captive portal sign-in app.
531 final Intent intent = new Intent(Intent.ACTION_SEND);
532 // Intent cannot use extras because PendingIntent.getActivity will merge matching
533 // Intents erasing extras. Use data instead of extras to encode NetID.
534 intent.setData(Uri.fromParts("netid", Integer.toString(mNetworkAgentInfo.network.netId),
535 mCaptivePortalLoggedInResponseToken));
Paul Jensen869868be2014-05-15 10:33:05 -0400536 intent.setComponent(new ComponentName("com.android.captiveportallogin",
537 "com.android.captiveportallogin.CaptivePortalLoginActivity"));
538 intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
539
Paul Jensen71b645f2014-10-13 14:13:07 -0400540 if (mCaptivePortalLoggedInBroadcastReceiver == null) {
541 // Wait for result.
542 mCaptivePortalLoggedInBroadcastReceiver =
543 new CaptivePortalLoggedInBroadcastReceiver();
544 final IntentFilter filter = new IntentFilter(ACTION_CAPTIVE_PORTAL_LOGGED_IN);
545 mContext.registerReceiver(mCaptivePortalLoggedInBroadcastReceiver, filter);
546 }
547 // Initiate notification to sign-in.
548 Message message = obtainMessage(EVENT_PROVISIONING_NOTIFICATION, 1,
549 mNetworkAgentInfo.network.netId,
550 PendingIntent.getActivity(mContext, 0, intent, 0));
551 mConnectivityServiceHandler.sendMessage(message);
Paul Jensen869868be2014-05-15 10:33:05 -0400552 }
553
554 @Override
555 public boolean processMessage(Message message) {
556 if (DBG) log(getName() + message.toString());
Paul Jensen71b645f2014-10-13 14:13:07 -0400557 return NOT_HANDLED;
Paul Jensen869868be2014-05-15 10:33:05 -0400558 }
Paul Jensenca8f16a2014-05-09 12:47:55 -0400559 }
560
Paul Jensen71b645f2014-10-13 14:13:07 -0400561 // Being in the LingeringState State indicates a Network's validated bit is true and it once
562 // was the highest scoring Network satisfying a particular NetworkRequest, but since then
563 // another Network satsified the NetworkRequest with a higher score and hence this Network
564 // is "lingered" for a fixed period of time before it is disconnected. This period of time
565 // allows apps to wrap up communication and allows for seamless reactivation if the other
566 // higher scoring Network happens to disconnect.
Paul Jensenca8f16a2014-05-09 12:47:55 -0400567 private class LingeringState extends State {
Paul Jensen79a08052014-08-21 12:44:07 -0400568 private static final String ACTION_LINGER_EXPIRED = "android.net.netmon.lingerExpired";
Paul Jensen79a08052014-08-21 12:44:07 -0400569
Paul Jensendcbe8352014-09-16 16:28:34 -0400570 private CustomIntentReceiver mBroadcastReceiver;
Paul Jensen79a08052014-08-21 12:44:07 -0400571 private PendingIntent mIntent;
572
Paul Jensenca8f16a2014-05-09 12:47:55 -0400573 @Override
574 public void enter() {
Paul Jensen71b645f2014-10-13 14:13:07 -0400575 mLingerToken = new Random().nextInt();
576 mBroadcastReceiver = new CustomIntentReceiver(ACTION_LINGER_EXPIRED, mLingerToken,
Paul Jensendcbe8352014-09-16 16:28:34 -0400577 CMD_LINGER_EXPIRED);
578 mIntent = mBroadcastReceiver.getPendingIntent();
Paul Jensen79a08052014-08-21 12:44:07 -0400579 long wakeupTime = SystemClock.elapsedRealtime() + mLingerDelayMs;
580 mAlarmManager.setWindow(AlarmManager.ELAPSED_REALTIME_WAKEUP, wakeupTime,
581 // Give a specific window so we aren't subject to unknown inexactitude.
582 mLingerDelayMs / 6, mIntent);
Paul Jensenca8f16a2014-05-09 12:47:55 -0400583 }
584
585 @Override
586 public boolean processMessage(Message message) {
587 if (DBG) log(getName() + message.toString());
588 switch (message.what) {
589 case CMD_NETWORK_CONNECTED:
590 // Go straight to active as we've already evaluated.
591 transitionTo(mValidatedState);
Paul Jensend6a3f7e2014-08-19 09:40:11 -0400592 return HANDLED;
Paul Jensenca8f16a2014-05-09 12:47:55 -0400593 case CMD_LINGER_EXPIRED:
594 if (message.arg1 != mLingerToken)
Paul Jensend6a3f7e2014-08-19 09:40:11 -0400595 return HANDLED;
Paul Jensenca8f16a2014-05-09 12:47:55 -0400596 mConnectivityServiceHandler.sendMessage(
597 obtainMessage(EVENT_NETWORK_LINGER_COMPLETE, mNetworkAgentInfo));
Paul Jensend6a3f7e2014-08-19 09:40:11 -0400598 return HANDLED;
Paul Jensenad50a1f2014-09-05 12:06:44 -0400599 case CMD_FORCE_REEVALUATION:
600 // Ignore reevaluation attempts when lingering. A reevaluation could result
601 // in a transition to the validated state which would abort the linger
602 // timeout. Lingering is the result of score assessment; validity is
603 // irrelevant.
604 return HANDLED;
Paul Jensen71b645f2014-10-13 14:13:07 -0400605 case CMD_CAPTIVE_PORTAL_APP_FINISHED:
606 // Ignore user network determination as this could abort linger timeout.
607 // Networks are only lingered once validated because:
608 // - Unvalidated networks are never lingered (see rematchNetworkAndRequests).
609 // - Once validated, a Network's validated bit is never cleared.
610 // Since networks are only lingered after being validated a user's
611 // determination will not change the death sentence that lingering entails:
612 // - If the user wants to use the network or bypasses the captive portal,
613 // the network's score will not be increased beyond its current value
614 // because it is already validated. Without a score increase there is no
615 // chance of reactivation (i.e. aborting linger timeout).
616 // - If the user does not want the network, lingering will disconnect the
617 // network anyhow.
618 return HANDLED;
Paul Jensenca8f16a2014-05-09 12:47:55 -0400619 default:
620 return NOT_HANDLED;
621 }
Paul Jensenca8f16a2014-05-09 12:47:55 -0400622 }
Paul Jensen79a08052014-08-21 12:44:07 -0400623
624 @Override
625 public void exit() {
626 mAlarmManager.cancel(mIntent);
627 mContext.unregisterReceiver(mBroadcastReceiver);
628 }
Paul Jensenca8f16a2014-05-09 12:47:55 -0400629 }
630
631 /**
632 * Do a URL fetch on a known server to see if we get the data we expect.
633 * Returns HTTP response code.
634 */
635 private int isCaptivePortal() {
636 if (!mIsCaptivePortalCheckEnabled) return 204;
637
Paul Jensenca8f16a2014-05-09 12:47:55 -0400638 HttpURLConnection urlConnection = null;
Paul Jensen869868be2014-05-15 10:33:05 -0400639 int httpResponseCode = 599;
Paul Jensenca8f16a2014-05-09 12:47:55 -0400640 try {
Paul Jensene547ff22014-08-04 09:12:24 -0400641 URL url = new URL("http", mServer, "/generate_204");
642 if (DBG) {
643 log("Checking " + url.toString() + " on " +
644 mNetworkAgentInfo.networkInfo.getExtraInfo());
Paul Jensenca8f16a2014-05-09 12:47:55 -0400645 }
Lorenzo Colitti9f1274b2014-08-21 11:45:54 -0700646 urlConnection = (HttpURLConnection) mNetworkAgentInfo.network.openConnection(url);
Paul Jensene547ff22014-08-04 09:12:24 -0400647 urlConnection.setInstanceFollowRedirects(false);
648 urlConnection.setConnectTimeout(SOCKET_TIMEOUT_MS);
649 urlConnection.setReadTimeout(SOCKET_TIMEOUT_MS);
650 urlConnection.setUseCaches(false);
Paul Jensen306f1a42014-08-04 10:59:01 -0400651
652 // Time how long it takes to get a response to our request
653 long requestTimestamp = SystemClock.elapsedRealtime();
654
Paul Jensene547ff22014-08-04 09:12:24 -0400655 urlConnection.getInputStream();
Paul Jensen306f1a42014-08-04 10:59:01 -0400656
657 // Time how long it takes to get a response to our request
658 long responseTimestamp = SystemClock.elapsedRealtime();
659
Paul Jensene547ff22014-08-04 09:12:24 -0400660 httpResponseCode = urlConnection.getResponseCode();
661 if (DBG) {
662 log("isCaptivePortal: ret=" + httpResponseCode +
663 " headers=" + urlConnection.getHeaderFields());
664 }
665 // NOTE: We may want to consider an "HTTP/1.0 204" response to be a captive
666 // portal. The only example of this seen so far was a captive portal. For
667 // the time being go with prior behavior of assuming it's not a captive
668 // portal. If it is considered a captive portal, a different sign-in URL
669 // is needed (i.e. can't browse a 204). This could be the result of an HTTP
670 // proxy server.
671
672 // Consider 200 response with "Content-length=0" to not be a captive portal.
673 // There's no point in considering this a captive portal as the user cannot
674 // sign-in to an empty page. Probably the result of a broken transparent proxy.
675 // See http://b/9972012.
676 if (httpResponseCode == 200 && urlConnection.getContentLength() == 0) {
677 if (DBG) log("Empty 200 response interpreted as 204 response.");
678 httpResponseCode = 204;
679 }
Paul Jensen306f1a42014-08-04 10:59:01 -0400680
Jeff Davidsonf9fff922014-12-05 16:56:08 -0800681 sendNetworkConditionsBroadcast(true /* response received */,
682 httpResponseCode != 204 /* isCaptivePortal */,
Paul Jensen306f1a42014-08-04 10:59:01 -0400683 requestTimestamp, responseTimestamp);
Paul Jensenca8f16a2014-05-09 12:47:55 -0400684 } catch (IOException e) {
685 if (DBG) log("Probably not a portal: exception " + e);
Paul Jensen869868be2014-05-15 10:33:05 -0400686 if (httpResponseCode == 599) {
687 // TODO: Ping gateway and DNS server and log results.
688 }
Paul Jensenca8f16a2014-05-09 12:47:55 -0400689 } finally {
690 if (urlConnection != null) {
691 urlConnection.disconnect();
692 }
Paul Jensenca8f16a2014-05-09 12:47:55 -0400693 }
694 return httpResponseCode;
695 }
Paul Jensen306f1a42014-08-04 10:59:01 -0400696
697 /**
698 * @param responseReceived - whether or not we received a valid HTTP response to our request.
699 * If false, isCaptivePortal and responseTimestampMs are ignored
700 * TODO: This should be moved to the transports. The latency could be passed to the transports
701 * along with the captive portal result. Currently the TYPE_MOBILE broadcasts appear unused so
702 * perhaps this could just be added to the WiFi transport only.
703 */
704 private void sendNetworkConditionsBroadcast(boolean responseReceived, boolean isCaptivePortal,
705 long requestTimestampMs, long responseTimestampMs) {
706 if (Settings.Global.getInt(mContext.getContentResolver(),
707 Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 0) {
708 if (DBG) log("Don't send network conditions - lacking user consent.");
709 return;
710 }
711
Robert Greenwaltfb68f8f2014-08-13 13:43:32 -0700712 if (systemReady == false) return;
713
Paul Jensen306f1a42014-08-04 10:59:01 -0400714 Intent latencyBroadcast = new Intent(ACTION_NETWORK_CONDITIONS_MEASURED);
715 switch (mNetworkAgentInfo.networkInfo.getType()) {
716 case ConnectivityManager.TYPE_WIFI:
717 WifiInfo currentWifiInfo = mWifiManager.getConnectionInfo();
718 if (currentWifiInfo != null) {
719 // NOTE: getSSID()'s behavior changed in API 17; before that, SSIDs were not
720 // surrounded by double quotation marks (thus violating the Javadoc), but this
721 // was changed to match the Javadoc in API 17. Since clients may have started
722 // sanitizing the output of this method since API 17 was released, we should
723 // not change it here as it would become impossible to tell whether the SSID is
724 // simply being surrounded by quotes due to the API, or whether those quotes
725 // are actually part of the SSID.
726 latencyBroadcast.putExtra(EXTRA_SSID, currentWifiInfo.getSSID());
727 latencyBroadcast.putExtra(EXTRA_BSSID, currentWifiInfo.getBSSID());
728 } else {
729 if (DBG) logw("network info is TYPE_WIFI but no ConnectionInfo found");
730 return;
731 }
732 break;
733 case ConnectivityManager.TYPE_MOBILE:
734 latencyBroadcast.putExtra(EXTRA_NETWORK_TYPE, mTelephonyManager.getNetworkType());
735 List<CellInfo> info = mTelephonyManager.getAllCellInfo();
736 if (info == null) return;
737 int numRegisteredCellInfo = 0;
738 for (CellInfo cellInfo : info) {
739 if (cellInfo.isRegistered()) {
740 numRegisteredCellInfo++;
741 if (numRegisteredCellInfo > 1) {
742 if (DBG) log("more than one registered CellInfo. Can't " +
743 "tell which is active. Bailing.");
744 return;
745 }
746 if (cellInfo instanceof CellInfoCdma) {
747 CellIdentityCdma cellId = ((CellInfoCdma) cellInfo).getCellIdentity();
748 latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId);
749 } else if (cellInfo instanceof CellInfoGsm) {
750 CellIdentityGsm cellId = ((CellInfoGsm) cellInfo).getCellIdentity();
751 latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId);
752 } else if (cellInfo instanceof CellInfoLte) {
753 CellIdentityLte cellId = ((CellInfoLte) cellInfo).getCellIdentity();
754 latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId);
755 } else if (cellInfo instanceof CellInfoWcdma) {
756 CellIdentityWcdma cellId = ((CellInfoWcdma) cellInfo).getCellIdentity();
757 latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId);
758 } else {
759 if (DBG) logw("Registered cellinfo is unrecognized");
760 return;
761 }
762 }
763 }
764 break;
765 default:
766 return;
767 }
768 latencyBroadcast.putExtra(EXTRA_CONNECTIVITY_TYPE, mNetworkAgentInfo.networkInfo.getType());
769 latencyBroadcast.putExtra(EXTRA_RESPONSE_RECEIVED, responseReceived);
770 latencyBroadcast.putExtra(EXTRA_REQUEST_TIMESTAMP_MS, requestTimestampMs);
771
772 if (responseReceived) {
773 latencyBroadcast.putExtra(EXTRA_IS_CAPTIVE_PORTAL, isCaptivePortal);
774 latencyBroadcast.putExtra(EXTRA_RESPONSE_TIMESTAMP_MS, responseTimestampMs);
775 }
Paul Jensen55298582014-08-20 11:01:41 -0400776 mContext.sendBroadcastAsUser(latencyBroadcast, UserHandle.CURRENT,
777 PERMISSION_ACCESS_NETWORK_CONDITIONS);
Paul Jensen306f1a42014-08-04 10:59:01 -0400778 }
Paul Jensenca8f16a2014-05-09 12:47:55 -0400779}