diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java index ab0eb23a2f..02a78dea33 100644 --- a/services/java/com/android/server/ConnectivityService.java +++ b/services/java/com/android/server/ConnectivityService.java @@ -3929,39 +3929,41 @@ public class ConnectivityService extends IConnectivityManager.Stub { /** * No connection was possible to the network. + * This is NOT a warm sim. */ - public static final int CMP_RESULT_CODE_NO_CONNECTION = 0; + private static final int CMP_RESULT_CODE_NO_CONNECTION = 0; /** * A connection was made to the internet, all is well. + * This is NOT a warm sim. */ - public static final int CMP_RESULT_CODE_CONNECTABLE = 1; - - /** - * A connection was made but there was a redirection, we appear to be in walled garden. - * This is an indication of a warm sim on a mobile network. - */ - public static final int CMP_RESULT_CODE_REDIRECTED = 2; + private static final int CMP_RESULT_CODE_CONNECTABLE = 1; /** * A connection was made but no dns server was available to resolve a name to address. - * This is an indication of a warm sim on a mobile network. + * This is NOT a warm sim since provisioning network is supported. */ - public static final int CMP_RESULT_CODE_NO_DNS = 3; + private static final int CMP_RESULT_CODE_NO_DNS = 2; /** * A connection was made but could not open a TCP connection. - * This is an indication of a warm sim on a mobile network. + * This is NOT a warm sim since provisioning network is supported. */ - public static final int CMP_RESULT_CODE_NO_TCP_CONNECTION = 4; + private static final int CMP_RESULT_CODE_NO_TCP_CONNECTION = 3; + + /** + * A connection was made but there was a redirection, we appear to be in walled garden. + * This is an indication of a warm sim on a mobile network such as T-Mobile. + */ + private static final int CMP_RESULT_CODE_REDIRECTED = 4; /** * The mobile network is a provisioning network. - * This is an indication of a warm sim on a mobile network. + * This is an indication of a warm sim on a mobile network such as AT&T. */ - public static final int CMP_RESULT_CODE_PROVISIONING_NETWORK = 5; + private static final int CMP_RESULT_CODE_PROVISIONING_NETWORK = 5; - AtomicBoolean mIsCheckingMobileProvisioning = new AtomicBoolean(false); + private AtomicBoolean mIsCheckingMobileProvisioning = new AtomicBoolean(false); @Override public int checkMobileProvisioning(int suggestedTimeOutMs) { @@ -4036,7 +4038,9 @@ public class ConnectivityService extends IConnectivityManager.Stub { mNetTrackers[ConnectivityManager.TYPE_MOBILE_HIPRI].getNetworkInfo(); switch(result) { case CMP_RESULT_CODE_CONNECTABLE: - case CMP_RESULT_CODE_NO_CONNECTION: { + case CMP_RESULT_CODE_NO_CONNECTION: + case CMP_RESULT_CODE_NO_DNS: + case CMP_RESULT_CODE_NO_TCP_CONNECTION: { if (DBG) log("CheckMp.onComplete: ignore, connected or no connection"); break; } @@ -4055,8 +4059,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { } break; } - case CMP_RESULT_CODE_NO_DNS: - case CMP_RESULT_CODE_NO_TCP_CONNECTION: { + case CMP_RESULT_CODE_PROVISIONING_NETWORK: { String url = getMobileProvisioningUrl(); if (TextUtils.isEmpty(url) == false) { if (DBG) log("CheckMp.onComplete: warm (no dns/tcp), url=" + url); @@ -4222,8 +4225,8 @@ public class ConnectivityService extends IConnectivityManager.Stub { MobileDataStateTracker mdst = (MobileDataStateTracker) mCs.mNetTrackers[ConnectivityManager.TYPE_MOBILE_HIPRI]; if (mdst.isProvisioningNetwork()) { - if (DBG) log("isMobileOk: isProvisioningNetwork is true, no TCP conn"); - result = CMP_RESULT_CODE_NO_TCP_CONNECTION; + if (DBG) log("isMobileOk: isProvisioningNetwork is true"); + result = CMP_RESULT_CODE_PROVISIONING_NETWORK; return result; } else { if (DBG) log("isMobileOk: isProvisioningNetwork is false, continue"); @@ -4303,25 +4306,37 @@ public class ConnectivityService extends IConnectivityManager.Stub { urlConn.setAllowUserInteraction(false); urlConn.setRequestProperty("Connection", "close"); int responseCode = urlConn.getResponseCode(); - if (responseCode == 204) { - result = CMP_RESULT_CODE_CONNECTABLE; - } else { - result = CMP_RESULT_CODE_REDIRECTED; - } - log("isMobileOk: connected responseCode=" + responseCode); + + // For debug display the headers + Map> headers = urlConn.getHeaderFields(); + log("isMobileOk: headers=" + headers); + + // Close the connection urlConn.disconnect(); urlConn = null; - return result; + + if (responseCode == 204) { + // Return + log("isMobileOk: expected responseCode=" + responseCode); + result = CMP_RESULT_CODE_CONNECTABLE; + return result; + } else { + // Retry to be sure this was redirected, we've gotten + // occasions where a server returned 200 even though + // the device didn't have a "warm" sim. + log("isMobileOk: not expected responseCode=" + responseCode); + result = CMP_RESULT_CODE_REDIRECTED; + } } catch (Exception e) { log("isMobileOk: HttpURLConnection Exception e=" + e); + result = CMP_RESULT_CODE_NO_TCP_CONNECTION; if (urlConn != null) { urlConn.disconnect(); urlConn = null; } } } - result = CMP_RESULT_CODE_NO_TCP_CONNECTION; - log("isMobileOk: loops|timed out"); + log("isMobileOk: loops|timed out result=" + result); return result; } catch (Exception e) { log("isMobileOk: Exception e=" + e);