Merge "Tighten test for warm sim and add more debug." into klp-dev

This commit is contained in:
Wink Saville
2013-09-09 01:32:44 +00:00
committed by Android (Google) Code Review

View File

@@ -3929,39 +3929,41 @@ public class ConnectivityService extends IConnectivityManager.Stub {
/** /**
* No connection was possible to the network. * 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. * 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; private 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;
/** /**
* A connection was made but no dns server was available to resolve a name to address. * 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. * 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. * 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 @Override
public int checkMobileProvisioning(int suggestedTimeOutMs) { public int checkMobileProvisioning(int suggestedTimeOutMs) {
@@ -4036,7 +4038,9 @@ public class ConnectivityService extends IConnectivityManager.Stub {
mNetTrackers[ConnectivityManager.TYPE_MOBILE_HIPRI].getNetworkInfo(); mNetTrackers[ConnectivityManager.TYPE_MOBILE_HIPRI].getNetworkInfo();
switch(result) { switch(result) {
case CMP_RESULT_CODE_CONNECTABLE: 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"); if (DBG) log("CheckMp.onComplete: ignore, connected or no connection");
break; break;
} }
@@ -4055,8 +4059,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
} }
break; break;
} }
case CMP_RESULT_CODE_NO_DNS: case CMP_RESULT_CODE_PROVISIONING_NETWORK: {
case CMP_RESULT_CODE_NO_TCP_CONNECTION: {
String url = getMobileProvisioningUrl(); String url = getMobileProvisioningUrl();
if (TextUtils.isEmpty(url) == false) { if (TextUtils.isEmpty(url) == false) {
if (DBG) log("CheckMp.onComplete: warm (no dns/tcp), url=" + url); if (DBG) log("CheckMp.onComplete: warm (no dns/tcp), url=" + url);
@@ -4222,8 +4225,8 @@ public class ConnectivityService extends IConnectivityManager.Stub {
MobileDataStateTracker mdst = (MobileDataStateTracker) MobileDataStateTracker mdst = (MobileDataStateTracker)
mCs.mNetTrackers[ConnectivityManager.TYPE_MOBILE_HIPRI]; mCs.mNetTrackers[ConnectivityManager.TYPE_MOBILE_HIPRI];
if (mdst.isProvisioningNetwork()) { if (mdst.isProvisioningNetwork()) {
if (DBG) log("isMobileOk: isProvisioningNetwork is true, no TCP conn"); if (DBG) log("isMobileOk: isProvisioningNetwork is true");
result = CMP_RESULT_CODE_NO_TCP_CONNECTION; result = CMP_RESULT_CODE_PROVISIONING_NETWORK;
return result; return result;
} else { } else {
if (DBG) log("isMobileOk: isProvisioningNetwork is false, continue"); if (DBG) log("isMobileOk: isProvisioningNetwork is false, continue");
@@ -4303,25 +4306,37 @@ public class ConnectivityService extends IConnectivityManager.Stub {
urlConn.setAllowUserInteraction(false); urlConn.setAllowUserInteraction(false);
urlConn.setRequestProperty("Connection", "close"); urlConn.setRequestProperty("Connection", "close");
int responseCode = urlConn.getResponseCode(); int responseCode = urlConn.getResponseCode();
if (responseCode == 204) {
result = CMP_RESULT_CODE_CONNECTABLE; // For debug display the headers
} else { Map<String, List<String>> headers = urlConn.getHeaderFields();
result = CMP_RESULT_CODE_REDIRECTED; log("isMobileOk: headers=" + headers);
}
log("isMobileOk: connected responseCode=" + responseCode); // Close the connection
urlConn.disconnect(); urlConn.disconnect();
urlConn = null; 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) { } catch (Exception e) {
log("isMobileOk: HttpURLConnection Exception e=" + e); log("isMobileOk: HttpURLConnection Exception e=" + e);
result = CMP_RESULT_CODE_NO_TCP_CONNECTION;
if (urlConn != null) { if (urlConn != null) {
urlConn.disconnect(); urlConn.disconnect();
urlConn = null; urlConn = null;
} }
} }
} }
result = CMP_RESULT_CODE_NO_TCP_CONNECTION; log("isMobileOk: loops|timed out result=" + result);
log("isMobileOk: loops|timed out");
return result; return result;
} catch (Exception e) { } catch (Exception e) {
log("isMobileOk: Exception e=" + e); log("isMobileOk: Exception e=" + e);