diff options
author | Paul Jensen <pauljensen@google.com> | 2014-11-17 12:34:51 -0500 |
---|---|---|
committer | Paul Jensen <pauljensen@google.com> | 2014-11-20 21:00:35 -0500 |
commit | 2c311d61eaf331818e601f97485f88c4cf26384d (patch) | |
tree | bf407d1ca2770a57535ef050f69e0100f94f6f27 /services/core/java/com/android/server/connectivity/NetworkMonitor.java | |
parent | 1ca6af34b48b18b8c4b5e2cdf3f1bd4295d8ac2e (diff) | |
download | frameworks_base-2c311d61eaf331818e601f97485f88c4cf26384d.zip frameworks_base-2c311d61eaf331818e601f97485f88c4cf26384d.tar.gz frameworks_base-2c311d61eaf331818e601f97485f88c4cf26384d.tar.bz2 |
Don't bother validating networks that don't satisfy the default request.
The only immediate change in behavior is not validating untrusted networks.
bug:18299572
bug:18394654
Change-Id: I8d626baf37db0bd0f55ddf3af8a0abf094a12369
Diffstat (limited to 'services/core/java/com/android/server/connectivity/NetworkMonitor.java')
-rw-r--r-- | services/core/java/com/android/server/connectivity/NetworkMonitor.java | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/services/core/java/com/android/server/connectivity/NetworkMonitor.java b/services/core/java/com/android/server/connectivity/NetworkMonitor.java index 593a28a..78f3705 100644 --- a/services/core/java/com/android/server/connectivity/NetworkMonitor.java +++ b/services/core/java/com/android/server/connectivity/NetworkMonitor.java @@ -27,6 +27,7 @@ import android.net.ConnectivityManager; import android.net.Network; import android.net.NetworkCapabilities; import android.net.NetworkInfo; +import android.net.NetworkRequest; import android.net.TrafficStats; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; @@ -222,6 +223,7 @@ public class NetworkMonitor extends StateMachine { private final TelephonyManager mTelephonyManager; private final WifiManager mWifiManager; private final AlarmManager mAlarmManager; + private final NetworkRequest mDefaultRequest; private String mServer; private boolean mIsCaptivePortalCheckEnabled = false; @@ -239,7 +241,8 @@ public class NetworkMonitor extends StateMachine { private State mCaptivePortalState = new CaptivePortalState(); private State mLingeringState = new LingeringState(); - public NetworkMonitor(Context context, Handler handler, NetworkAgentInfo networkAgentInfo) { + public NetworkMonitor(Context context, Handler handler, NetworkAgentInfo networkAgentInfo, + NetworkRequest defaultRequest) { // Add suffix indicating which NetworkMonitor we're talking about. super(TAG + networkAgentInfo.name()); @@ -249,6 +252,7 @@ public class NetworkMonitor extends StateMachine { mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); + mDefaultRequest = defaultRequest; addState(mDefaultState); addState(mOfflineState, mDefaultState); @@ -369,14 +373,25 @@ public class NetworkMonitor extends StateMachine { case CMD_REEVALUATE: if (message.arg1 != mReevaluateToken) return HANDLED; - if (mNetworkAgentInfo.isVPN()) { - transitionTo(mValidatedState); - return HANDLED; - } - // If network provides no internet connectivity adjust evaluation. - if (!mNetworkAgentInfo.networkCapabilities.hasCapability( - NetworkCapabilities.NET_CAPABILITY_INTERNET)) { - // TODO: Try to verify something works. Do all gateways respond to pings? + // Don't bother validating networks that don't satisify the default request. + // This includes: + // - VPNs which can be considered explicitly desired by the user and the + // user's desire trumps whether the network validates. + // - Networks that don't provide internet access. It's unclear how to + // validate such networks. + // - Untrusted networks. It's unsafe to prompt the user to sign-in to + // such networks and the user didn't express interest in connecting to + // such networks (an app did) so the user may be unhappily surprised when + // asked to sign-in to a network they didn't want to connect to in the + // first place. Validation could be done to adjust the network scores + // however these networks are app-requested and may not be intended for + // general usage, in which case general validation may not be an accurate + // measure of the network's quality. Only the app knows how to evaluate + // the network so don't bother validating here. Furthermore sending HTTP + // packets over the network may be undesirable, for example an extremely + // expensive metered network, or unwanted leaking of the User Agent string. + if (!mDefaultRequest.networkCapabilities.satisfiedByNetworkCapabilities( + mNetworkAgentInfo.networkCapabilities)) { transitionTo(mValidatedState); return HANDLED; } |