diff options
Diffstat (limited to 'core/java/android/net')
-rw-r--r-- | core/java/android/net/ConnectivityManager.java | 59 | ||||
-rw-r--r-- | core/java/android/net/IConnectivityManager.aidl | 4 | ||||
-rw-r--r-- | core/java/android/net/MobileDataStateTracker.java | 416 | ||||
-rw-r--r-- | core/java/android/net/NetworkInfo.java | 2 | ||||
-rw-r--r-- | core/java/android/net/NetworkStateTracker.java | 82 | ||||
-rw-r--r-- | core/java/android/net/NetworkUtils.java | 3 | ||||
-rw-r--r-- | core/java/android/net/WebAddress.java | 2 | ||||
-rw-r--r-- | core/java/android/net/http/Connection.java | 16 | ||||
-rw-r--r-- | core/java/android/net/http/ConnectionThread.java | 29 | ||||
-rw-r--r-- | core/java/android/net/http/Request.java | 30 | ||||
-rw-r--r-- | core/java/android/net/http/RequestHandle.java | 2 | ||||
-rw-r--r-- | core/java/android/net/http/RequestQueue.java | 212 |
12 files changed, 411 insertions, 446 deletions
diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java index 1429bc1..a127df0 100644 --- a/core/java/android/net/ConnectivityManager.java +++ b/core/java/android/net/ConnectivityManager.java @@ -18,6 +18,7 @@ package android.net; import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; +import android.os.Binder; import android.os.RemoteException; /** @@ -114,15 +115,64 @@ public class ConnectivityManager public static final String ACTION_BACKGROUND_DATA_SETTING_CHANGED = "android.net.conn.BACKGROUND_DATA_SETTING_CHANGED"; - public static final int TYPE_MOBILE = 0; - public static final int TYPE_WIFI = 1; + /** + * The Default Mobile data connection. When active, all data traffic + * will use this connection by default. Should not coexist with other + * default connections. + */ + public static final int TYPE_MOBILE = 0; + /** + * The Default WIFI data connection. When active, all data traffic + * will use this connection by default. Should not coexist with other + * default connections. + */ + public static final int TYPE_WIFI = 1; + /** + * An MMS-specific Mobile data connection. This connection may be the + * same as {@link #TYPEMOBILE} but it may be different. This is used + * by applications needing to talk to the carrier's Multimedia Messaging + * Service servers. It may coexist with default data connections. + * {@hide} + */ + public static final int TYPE_MOBILE_MMS = 2; + /** + * A SUPL-specific Mobile data connection. This connection may be the + * same as {@link #TYPEMOBILE} but it may be different. This is used + * by applications needing to talk to the carrier's Secure User Plane + * Location servers for help locating the device. It may coexist with + * default data connections. + * {@hide} + */ + public static final int TYPE_MOBILE_SUPL = 3; + /** + * A DUN-specific Mobile data connection. This connection may be the + * same as {@link #TYPEMOBILE} but it may be different. This is used + * by applicaitons performing a Dial Up Networking bridge so that + * the carrier is aware of DUN traffic. It may coexist with default data + * connections. + * {@hide} + */ + public static final int TYPE_MOBILE_DUN = 4; + /** + * A High Priority Mobile data connection. This connection is typically + * the same as {@link #TYPEMOBILE} but the routing setup is different. + * Only requesting processes will have access to the Mobile DNS servers + * and only IP's explicitly requested via {@link #requestRouteToHost} + * will route over this interface. + *{@hide} + */ + public static final int TYPE_MOBILE_HIPRI = 5; + /** {@hide} */ + public static final int MAX_RADIO_TYPE = TYPE_WIFI; + /** {@hide} */ + public static final int MAX_NETWORK_TYPE = TYPE_MOBILE_HIPRI; public static final int DEFAULT_NETWORK_PREFERENCE = TYPE_WIFI; private IConnectivityManager mService; static public boolean isNetworkTypeValid(int networkType) { - return networkType == TYPE_WIFI || networkType == TYPE_MOBILE; + return networkType >= 0 && networkType <= MAX_NETWORK_TYPE; } public void setNetworkPreference(int preference) { @@ -195,7 +245,8 @@ public class ConnectivityManager */ public int startUsingNetworkFeature(int networkType, String feature) { try { - return mService.startUsingNetworkFeature(networkType, feature); + return mService.startUsingNetworkFeature(networkType, feature, + new Binder()); } catch (RemoteException e) { return -1; } diff --git a/core/java/android/net/IConnectivityManager.aidl b/core/java/android/net/IConnectivityManager.aidl index de68598..9f59cce 100644 --- a/core/java/android/net/IConnectivityManager.aidl +++ b/core/java/android/net/IConnectivityManager.aidl @@ -17,6 +17,7 @@ package android.net; import android.net.NetworkInfo; +import android.os.IBinder; /** * Interface that answers queries about, and allows changing, the @@ -39,7 +40,8 @@ interface IConnectivityManager boolean setRadio(int networkType, boolean turnOn); - int startUsingNetworkFeature(int networkType, in String feature); + int startUsingNetworkFeature(int networkType, in String feature, + in IBinder binder); int stopUsingNetworkFeature(int networkType, in String feature); diff --git a/core/java/android/net/MobileDataStateTracker.java b/core/java/android/net/MobileDataStateTracker.java index 1064fb6..538e51a 100644 --- a/core/java/android/net/MobileDataStateTracker.java +++ b/core/java/android/net/MobileDataStateTracker.java @@ -32,9 +32,6 @@ import android.telephony.TelephonyManager; import android.util.Log; import android.text.TextUtils; -import java.util.List; -import java.util.ArrayList; - /** * Track the state of mobile data connectivity. This is done by * receiving broadcast intents from the Phone process whenever @@ -45,36 +42,49 @@ import java.util.ArrayList; public class MobileDataStateTracker extends NetworkStateTracker { private static final String TAG = "MobileDataStateTracker"; - private static final boolean DBG = false; + private static final boolean DBG = true; private Phone.DataState mMobileDataState; private ITelephony mPhoneService; - private static final String[] sDnsPropNames = { - "net.rmnet0.dns1", - "net.rmnet0.dns2", - "net.eth0.dns1", - "net.eth0.dns2", - "net.eth0.dns3", - "net.eth0.dns4", - "net.gprs.dns1", - "net.gprs.dns2" - }; - private List<String> mDnsServers; - private String mInterfaceName; - private int mDefaultGatewayAddr; - private int mLastCallingPid = -1; + + private String mApnType; + private String mApnName; + private boolean mEnabled; + private BroadcastReceiver mStateReceiver; /** * Create a new MobileDataStateTracker * @param context the application context of the caller * @param target a message handler for getting callbacks about state changes + * @param netType the ConnectivityManager network type + * @param apnType the Phone apnType + * @param tag the name of this network */ - public MobileDataStateTracker(Context context, Handler target) { - super(context, target, ConnectivityManager.TYPE_MOBILE, - TelephonyManager.getDefault().getNetworkType(), "MOBILE", - TelephonyManager.getDefault().getNetworkTypeName()); + public MobileDataStateTracker(Context context, Handler target, + int netType, String apnType, String tag) { + super(context, target, netType, + TelephonyManager.getDefault().getNetworkType(), tag, + TelephonyManager.getDefault().getNetworkTypeName()); + mApnType = apnType; mPhoneService = null; - mDnsServers = new ArrayList<String>(); + if(netType == ConnectivityManager.TYPE_MOBILE) { + mEnabled = true; + } else { + mEnabled = false; + } + + mDnsPropNames = new String[] { + "net.rmnet0.dns1", + "net.rmnet0.dns2", + "net.eth0.dns1", + "net.eth0.dns2", + "net.eth0.dns3", + "net.eth0.dns4", + "net.gprs.dns1", + "net.gprs.dns2", + "net.ppp0.dns1", + "net.ppp0.dns2"}; + } /** @@ -86,105 +96,133 @@ public class MobileDataStateTracker extends NetworkStateTracker { filter.addAction(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED); filter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED); - Intent intent = mContext.registerReceiver(new MobileDataStateReceiver(), filter); + mStateReceiver = new MobileDataStateReceiver(); + Intent intent = mContext.registerReceiver(mStateReceiver, filter); if (intent != null) mMobileDataState = getMobileDataState(intent); else mMobileDataState = Phone.DataState.DISCONNECTED; } - private static Phone.DataState getMobileDataState(Intent intent) { + private Phone.DataState getMobileDataState(Intent intent) { String str = intent.getStringExtra(Phone.STATE_KEY); - if (str != null) - return Enum.valueOf(Phone.DataState.class, str); - else - return Phone.DataState.DISCONNECTED; - } - - private class MobileDataStateReceiver extends BroadcastReceiver { - public void onReceive(Context context, Intent intent) { - if (intent.getAction().equals(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) { - Phone.DataState state = getMobileDataState(intent); - String reason = intent.getStringExtra(Phone.STATE_CHANGE_REASON_KEY); - String apnName = intent.getStringExtra(Phone.DATA_APN_KEY); - boolean unavailable = intent.getBooleanExtra(Phone.NETWORK_UNAVAILABLE_KEY, false); - if (DBG) Log.d(TAG, "Received " + intent.getAction() + - " broadcast - state = " + state - + ", unavailable = " + unavailable - + ", reason = " + (reason == null ? "(unspecified)" : reason)); - mNetworkInfo.setIsAvailable(!unavailable); - if (mMobileDataState != state) { - mMobileDataState = state; - - switch (state) { - case DISCONNECTED: - setDetailedState(DetailedState.DISCONNECTED, reason, apnName); - if (mInterfaceName != null) { - NetworkUtils.resetConnections(mInterfaceName); - } - mInterfaceName = null; - mDefaultGatewayAddr = 0; - break; - case CONNECTING: - setDetailedState(DetailedState.CONNECTING, reason, apnName); - break; - case SUSPENDED: - setDetailedState(DetailedState.SUSPENDED, reason, apnName); - break; - case CONNECTED: - mInterfaceName = intent.getStringExtra(Phone.DATA_IFACE_NAME_KEY); - if (mInterfaceName == null) { - Log.d(TAG, "CONNECTED event did not supply interface name."); - } - setupDnsProperties(); - setDetailedState(DetailedState.CONNECTED, reason, apnName); - break; - } - } - } else if (intent.getAction().equals(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED)) { - String reason = intent.getStringExtra(Phone.FAILURE_REASON_KEY); - String apnName = intent.getStringExtra(Phone.DATA_APN_KEY); - if (DBG) Log.d(TAG, "Received " + intent.getAction() + " broadcast" + - reason == null ? "" : "(" + reason + ")"); - setDetailedState(DetailedState.FAILED, reason, apnName); + if (str != null) { + String apnTypeList = + intent.getStringExtra(Phone.DATA_APN_TYPES_KEY); + if (isApnTypeIncluded(apnTypeList)) { + return Enum.valueOf(Phone.DataState.class, str); } - TelephonyManager tm = TelephonyManager.getDefault(); - setRoamingStatus(tm.isNetworkRoaming()); - setSubtype(tm.getNetworkType(), tm.getNetworkTypeName()); } + return Phone.DataState.DISCONNECTED; } - /** - * Make sure that route(s) exist to the carrier DNS server(s). - */ - public void addPrivateRoutes() { - if (mInterfaceName != null) { - for (String addrString : mDnsServers) { - int addr = NetworkUtils.lookupHost(addrString); - if (addr != -1) { - NetworkUtils.addHostRoute(mInterfaceName, addr); - } - } - } - } + private boolean isApnTypeIncluded(String typeList) { + /* comma seperated list - split and check */ + if (typeList == null) + return false; - public void removePrivateRoutes() { - if(mInterfaceName != null) { - NetworkUtils.removeHostRoutes(mInterfaceName); + String[] list = typeList.split(","); + for(int i=0; i< list.length; i++) { + if (TextUtils.equals(list[i], mApnType) || + TextUtils.equals(list[i], Phone.APN_TYPE_ALL)) { + return true; + } } + return false; } - public void removeDefaultRoute() { - if(mInterfaceName != null) { - mDefaultGatewayAddr = NetworkUtils.getDefaultRoute(mInterfaceName); - NetworkUtils.removeDefaultRoute(mInterfaceName); - } - } + private class MobileDataStateReceiver extends BroadcastReceiver { + public void onReceive(Context context, Intent intent) { + synchronized(this) { + if (intent.getAction().equals(TelephonyIntents. + ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) { + Phone.DataState state = getMobileDataState(intent); + String reason = intent.getStringExtra(Phone.STATE_CHANGE_REASON_KEY); + String apnName = intent.getStringExtra(Phone.DATA_APN_KEY); + String apnTypeList = intent.getStringExtra(Phone.DATA_APN_TYPES_KEY); + mApnName = apnName; + + boolean unavailable = intent.getBooleanExtra(Phone.NETWORK_UNAVAILABLE_KEY, + false); + + // set this regardless of the apnTypeList. It's all the same radio/network + // underneath + mNetworkInfo.setIsAvailable(!unavailable); + + if (isApnTypeIncluded(apnTypeList)) { + if (mEnabled == false) { + // if we're not enabled but the APN Type is supported by this connection + // we should record the interface name if one's provided. If the user + // turns on this network we will need the interfacename but won't get + // a fresh connected message - TODO fix this when we get per-APN + // notifications + if (state == Phone.DataState.CONNECTED) { + if (DBG) Log.d(TAG, "replacing old mInterfaceName (" + + mInterfaceName + ") with " + + intent.getStringExtra(Phone.DATA_IFACE_NAME_KEY) + + " for " + mApnType); + mInterfaceName = intent.getStringExtra(Phone.DATA_IFACE_NAME_KEY); + } + return; + } + } else { + return; + } - public void restoreDefaultRoute() { - // 0 is not a valid address for a gateway - if (mInterfaceName != null && mDefaultGatewayAddr != 0) { - NetworkUtils.setDefaultRoute(mInterfaceName, mDefaultGatewayAddr); + if (DBG) Log.d(TAG, mApnType + " Received state= " + state + ", old= " + + mMobileDataState + ", reason= " + + (reason == null ? "(unspecified)" : reason) + + ", apnTypeList= " + apnTypeList); + + if (mMobileDataState != state) { + mMobileDataState = state; + switch (state) { + case DISCONNECTED: + if(isTeardownRequested()) { + mEnabled = false; + setTeardownRequested(false); + } + + setDetailedState(DetailedState.DISCONNECTED, reason, apnName); + if (mInterfaceName != null) { + NetworkUtils.resetConnections(mInterfaceName); + } + // can't do this here - ConnectivityService needs it to clear stuff + // it's ok though - just leave it to be refreshed next time + // we connect. + //if (DBG) Log.d(TAG, "clearing mInterfaceName for "+ mApnType + + // " as it DISCONNECTED"); + //mInterfaceName = null; + //mDefaultGatewayAddr = 0; + break; + case CONNECTING: + setDetailedState(DetailedState.CONNECTING, reason, apnName); + break; + case SUSPENDED: + setDetailedState(DetailedState.SUSPENDED, reason, apnName); + break; + case CONNECTED: + mInterfaceName = intent.getStringExtra(Phone.DATA_IFACE_NAME_KEY); + if (mInterfaceName == null) { + Log.d(TAG, "CONNECTED event did not supply interface name."); + } + setDetailedState(DetailedState.CONNECTED, reason, apnName); + break; + } + } + } else if (intent.getAction(). + equals(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED)) { + mEnabled = false; + String reason = intent.getStringExtra(Phone.FAILURE_REASON_KEY); + String apnName = intent.getStringExtra(Phone.DATA_APN_KEY); + if (DBG) Log.d(TAG, "Received " + intent.getAction() + " broadcast" + + reason == null ? "" : "(" + reason + ")"); + setDetailedState(DetailedState.FAILED, reason, apnName); + } + TelephonyManager tm = TelephonyManager.getDefault(); + setRoamingStatus(tm.isNetworkRoaming()); + setSubtype(tm.getNetworkType(), tm.getNetworkTypeName()); + } } } @@ -219,15 +257,6 @@ public class MobileDataStateTracker extends NetworkStateTracker { } /** - * Return the IP addresses of the DNS servers available for the mobile data - * network interface. - * @return a list of DNS addresses, with no holes. - */ - public String[] getNameServers() { - return getNameServerList(sDnsPropNames); - } - - /** * {@inheritDoc} * The mobile data network subtype indicates what generation network technology is in effect, * e.g., GPRS, EDGE, UMTS, etc. @@ -254,9 +283,21 @@ public class MobileDataStateTracker extends NetworkStateTracker { case TelephonyManager.NETWORK_TYPE_UMTS: networkTypeStr = "umts"; break; + case TelephonyManager.NETWORK_TYPE_HSDPA: + networkTypeStr = "hsdpa"; + break; + case TelephonyManager.NETWORK_TYPE_HSUPA: + networkTypeStr = "hsupa"; + break; + case TelephonyManager.NETWORK_TYPE_HSPA: + networkTypeStr = "hspa"; + break; case TelephonyManager.NETWORK_TYPE_CDMA: networkTypeStr = "cdma"; break; + case TelephonyManager.NETWORK_TYPE_1xRTT: + networkTypeStr = "1xrtt"; + break; case TelephonyManager.NETWORK_TYPE_EVDO_0: networkTypeStr = "evdo"; break; @@ -273,54 +314,58 @@ public class MobileDataStateTracker extends NetworkStateTracker { */ @Override public boolean teardown() { - getPhoneService(false); - /* - * If the phone process has crashed in the past, we'll get a - * RemoteException and need to re-reference the service. - */ - for (int retry = 0; retry < 2; retry++) { - if (mPhoneService == null) { - Log.w(TAG, - "Ignoring mobile data teardown request because could not acquire PhoneService"); - break; - } - - try { - return mPhoneService.disableDataConnectivity(); - } catch (RemoteException e) { - if (retry == 0) getPhoneService(true); - } - } - - Log.w(TAG, "Failed to tear down mobile data connectivity"); - return false; + // since we won't get a notification currently (TODO - per APN notifications) + // we won't get a disconnect message until all APN's on the current connection's + // APN list are disabled. That means privateRoutes for DNS and such will remain on - + // not a problem since that's all shared with whatever other APN is still on, but + // ugly. + setTeardownRequested(true); + return (setEnableApn(mApnType, false) != Phone.APN_REQUEST_FAILED); } /** * Re-enable mobile data connectivity after a {@link #teardown()}. */ public boolean reconnect() { - getPhoneService(false); - /* - * If the phone process has crashed in the past, we'll get a - * RemoteException and need to re-reference the service. - */ - for (int retry = 0; retry < 2; retry++) { - if (mPhoneService == null) { - Log.w(TAG, - "Ignoring mobile data connect request because could not acquire PhoneService"); + setTeardownRequested(false); + switch (setEnableApn(mApnType, true)) { + case Phone.APN_ALREADY_ACTIVE: + // TODO - remove this when we get per-apn notifications + mEnabled = true; + // need to set self to CONNECTING so the below message is handled. + mMobileDataState = Phone.DataState.CONNECTING; + setDetailedState(DetailedState.CONNECTING, Phone.REASON_APN_CHANGED, null); + //send out a connected message + Intent intent = new Intent(TelephonyIntents. + ACTION_ANY_DATA_CONNECTION_STATE_CHANGED); + intent.putExtra(Phone.STATE_KEY, Phone.DataState.CONNECTED.toString()); + intent.putExtra(Phone.STATE_CHANGE_REASON_KEY, Phone.REASON_APN_CHANGED); + intent.putExtra(Phone.DATA_APN_TYPES_KEY, mApnType); + intent.putExtra(Phone.DATA_APN_KEY, mApnName); + intent.putExtra(Phone.DATA_IFACE_NAME_KEY, mInterfaceName); + intent.putExtra(Phone.NETWORK_UNAVAILABLE_KEY, false); + if (mStateReceiver != null) mStateReceiver.onReceive(mContext, intent); + break; + case Phone.APN_REQUEST_STARTED: + mEnabled = true; + // no need to do anything - we're already due some status update intents + break; + case Phone.APN_REQUEST_FAILED: + if (mPhoneService == null && mApnType == Phone.APN_TYPE_DEFAULT) { + // on startup we may try to talk to the phone before it's ready + // just leave mEnabled as it is for the default apn. + return false; + } + // else fall through + case Phone.APN_TYPE_NOT_AVAILABLE: + mEnabled = false; + break; + default: + Log.e(TAG, "Error in reconnect - unexpected response."); + mEnabled = false; break; - } - - try { - return mPhoneService.enableDataConnectivity(); - } catch (RemoteException e) { - if (retry == 0) getPhoneService(true); - } } - - Log.w(TAG, "Failed to set up mobile data connectivity"); - return false; + return mEnabled; } /** @@ -374,14 +419,7 @@ public class MobileDataStateTracker extends NetworkStateTracker { * </ul> */ public int startUsingNetworkFeature(String feature, int callingPid, int callingUid) { - if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_MMS)) { - mLastCallingPid = callingPid; - return setEnableApn(Phone.APN_TYPE_MMS, true); - } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_SUPL)) { - return setEnableApn(Phone.APN_TYPE_SUPL, true); - } else { - return -1; - } + return -1; } /** @@ -397,13 +435,7 @@ public class MobileDataStateTracker extends NetworkStateTracker { * the value {@code -1} always indicates failure. */ public int stopUsingNetworkFeature(String feature, int callingPid, int callingUid) { - if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_MMS)) { - return setEnableApn(Phone.APN_TYPE_MMS, false); - } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_SUPL)) { - return setEnableApn(Phone.APN_TYPE_SUPL, false); - } else { - return -1; - } + return -1; } /** @@ -415,10 +447,11 @@ public class MobileDataStateTracker extends NetworkStateTracker { */ @Override public boolean requestRouteToHost(int hostAddress) { + if (DBG) { + Log.d(TAG, "Requested host route to " + Integer.toHexString(hostAddress) + + " for " + mApnType + "(" + mInterfaceName + ")"); + } if (mInterfaceName != null && hostAddress != -1) { - if (DBG) { - Log.d(TAG, "Requested host route to " + Integer.toHexString(hostAddress)); - } return NetworkUtils.addHostRoute(mInterfaceName, hostAddress) == 0; } else { return false; @@ -433,43 +466,6 @@ public class MobileDataStateTracker extends NetworkStateTracker { return sb.toString(); } - private void setupDnsProperties() { - mDnsServers.clear(); - // Set up per-process DNS server list on behalf of the MMS process - int i = 1; - if (mInterfaceName != null) { - for (String propName : sDnsPropNames) { - if (propName.indexOf(mInterfaceName) != -1) { - String propVal = SystemProperties.get(propName); - if (propVal != null && propVal.length() != 0 && !propVal.equals("0.0.0.0")) { - mDnsServers.add(propVal); - if (mLastCallingPid != -1) { - SystemProperties.set("net.dns" + i + "." + mLastCallingPid, propVal); - } - ++i; - } - } - } - } - if (i == 1) { - Log.d(TAG, "DNS server addresses are not known."); - } else if (mLastCallingPid != -1) { - /* - * Bump the property that tells the name resolver library - * to reread the DNS server list from the properties. - */ - String propVal = SystemProperties.get("net.dnschange"); - if (propVal.length() != 0) { - try { - int n = Integer.parseInt(propVal); - SystemProperties.set("net.dnschange", "" + (n+1)); - } catch (NumberFormatException e) { - } - } - } - mLastCallingPid = -1; - } - /** * Internal method supporting the ENABLE_MMS feature. * @param apnType the type of APN to be enabled or disabled (e.g., mms) diff --git a/core/java/android/net/NetworkInfo.java b/core/java/android/net/NetworkInfo.java index 9f53937..649cb8c 100644 --- a/core/java/android/net/NetworkInfo.java +++ b/core/java/android/net/NetworkInfo.java @@ -131,7 +131,7 @@ public class NetworkInfo implements Parcelable { mSubtypeName = subtypeName; setDetailedState(DetailedState.IDLE, null, null); mState = State.UNKNOWN; - mIsAvailable = true; + mIsAvailable = false; // until we're told otherwise, assume unavailable mIsRoaming = false; } diff --git a/core/java/android/net/NetworkStateTracker.java b/core/java/android/net/NetworkStateTracker.java index 37087ac..1fb0144 100644 --- a/core/java/android/net/NetworkStateTracker.java +++ b/core/java/android/net/NetworkStateTracker.java @@ -27,6 +27,7 @@ import android.text.TextUtils; import android.util.Config; import android.util.Log; + /** * Each subclass of this class keeps track of the state of connectivity * of a network interface. All state information for a network should @@ -40,11 +41,16 @@ public abstract class NetworkStateTracker extends Handler { protected NetworkInfo mNetworkInfo; protected Context mContext; protected Handler mTarget; + protected String mInterfaceName; + protected String[] mDnsPropNames; + private boolean mPrivateDnsRouteSet; + protected int mDefaultGatewayAddr; + private boolean mDefaultRouteSet; private boolean mTeardownRequested; - private static boolean DBG = Config.LOGV; + private static boolean DBG = true; private static final String TAG = "NetworkStateTracker"; - + public static final int EVENT_STATE_CHANGED = 1; public static final int EVENT_SCAN_RESULTS_AVAILABLE = 2; /** @@ -56,6 +62,7 @@ public abstract class NetworkStateTracker extends Handler { public static final int EVENT_CONFIGURATION_CHANGED = 4; public static final int EVENT_ROAMING_CHANGED = 5; public static final int EVENT_NETWORK_SUBTYPE_CHANGED = 6; + public static final int EVENT_RESTORE_DEFAULT_NETWORK = 7; public NetworkStateTracker(Context context, Handler target, @@ -67,6 +74,7 @@ public abstract class NetworkStateTracker extends Handler { mContext = context; mTarget = target; mTeardownRequested = false; + this.mNetworkInfo = new NetworkInfo(networkType, subType, typeName, subtypeName); } @@ -75,19 +83,21 @@ public abstract class NetworkStateTracker extends Handler { } /** - * Return the list of DNS servers associated with this network. - * @return a list of the IP addresses of the DNS servers available - * for the network. - */ - public abstract String[] getNameServers(); - - /** * Return the system properties name associated with the tcp buffer sizes * for this network. */ public abstract String getTcpBufferSizesPropName(); /** + * Return the IP addresses of the DNS servers available for the mobile data + * network interface. + * @return a list of DNS addresses, with no holes. + */ + public String[] getNameServers() { + return getNameServerList(mDnsPropNames); + } + + /** * Return the IP addresses of the DNS servers available for this * network interface. * @param propertyNames the names of the system properties whose values @@ -112,6 +122,59 @@ public abstract class NetworkStateTracker extends Handler { return dnsAddresses; } + public void addPrivateDnsRoutes() { + if (DBG) { + Log.d(TAG, "addPrivateDnsRoutes for " + this + + "(" + mInterfaceName + ") - mPrivateDnsRouteSet = "+mPrivateDnsRouteSet); + } + if (mInterfaceName != null && !mPrivateDnsRouteSet) { + for (String addrString : getNameServers()) { + int addr = NetworkUtils.lookupHost(addrString); + if (addr != -1 && addr != 0) { + if (DBG) Log.d(TAG, " adding "+addrString+" ("+addr+")"); + NetworkUtils.addHostRoute(mInterfaceName, addr); + } + } + mPrivateDnsRouteSet = true; + } + } + + public void removePrivateDnsRoutes() { + // TODO - we should do this explicitly but the NetUtils api doesnt + // support this yet - must remove all. No worse than before + if (mInterfaceName != null && mPrivateDnsRouteSet) { + if (DBG) { + Log.d(TAG, "removePrivateDnsRoutes for " + mNetworkInfo.getTypeName() + + " (" + mInterfaceName + ")"); + } + NetworkUtils.removeHostRoutes(mInterfaceName); + mPrivateDnsRouteSet = false; + } + } + + public void addDefaultRoute() { + if ((mInterfaceName != null) && (mDefaultGatewayAddr != 0) && + mDefaultRouteSet == false) { + if (DBG) { + Log.d(TAG, "addDefaultRoute for " + mNetworkInfo.getTypeName() + + " (" + mInterfaceName + "), GatewayAddr=" + mDefaultGatewayAddr); + } + NetworkUtils.setDefaultRoute(mInterfaceName, mDefaultGatewayAddr); + mDefaultRouteSet = true; + } + } + + public void removeDefaultRoute() { + if (mInterfaceName != null && mDefaultRouteSet == true) { + if (DBG) { + Log.d(TAG, "removeDefaultRoute for " + mNetworkInfo.getTypeName() + " (" + + mInterfaceName + ")"); + } + NetworkUtils.removeDefaultRoute(mInterfaceName); + mDefaultRouteSet = false; + } + } + /** * Reads the network specific TCP buffer sizes from SystemProperties * net.tcp.buffersize.[default|wifi|umts|edge|gprs] and set them for system @@ -209,6 +272,7 @@ public abstract class NetworkStateTracker extends Handler { * @param extraInfo optional {@code String} providing extra information about the state change */ public void setDetailedState(NetworkInfo.DetailedState state, String reason, String extraInfo) { + if (DBG) Log.d(TAG, "setDetailed state, old ="+mNetworkInfo.getDetailedState()+" and new state="+state); if (state != mNetworkInfo.getDetailedState()) { boolean wasConnecting = (mNetworkInfo.getState() == NetworkInfo.State.CONNECTING); String lastReason = mNetworkInfo.getReason(); diff --git a/core/java/android/net/NetworkUtils.java b/core/java/android/net/NetworkUtils.java index 1153648..a3ae01b 100644 --- a/core/java/android/net/NetworkUtils.java +++ b/core/java/android/net/NetworkUtils.java @@ -25,6 +25,9 @@ import java.net.UnknownHostException; * {@hide} */ public class NetworkUtils { + /** Bring the named network interface up. */ + public native static int enableInterface(String interfaceName); + /** Bring the named network interface down. */ public native static int disableInterface(String interfaceName); diff --git a/core/java/android/net/WebAddress.java b/core/java/android/net/WebAddress.java index f4a2a6a..f4ae66a 100644 --- a/core/java/android/net/WebAddress.java +++ b/core/java/android/net/WebAddress.java @@ -54,7 +54,7 @@ public class WebAddress { static Pattern sAddressPattern = Pattern.compile( /* scheme */ "(?:(http|HTTP|https|HTTPS|file|FILE)\\:\\/\\/)?" + /* authority */ "(?:([-A-Za-z0-9$_.+!*'(),;?&=]+(?:\\:[-A-Za-z0-9$_.+!*'(),;?&=]+)?)@)?" + - /* host */ "([-A-Za-z0-9%]+(?:\\.[-A-Za-z0-9%]+)*)?" + + /* host */ "([-A-Za-z0-9%_]+(?:\\.[-A-Za-z0-9%_]+)*|\\[[0-9a-fA-F:\\.]+\\])?" + /* port */ "(?:\\:([0-9]+))?" + /* path */ "(\\/?.*)?"); diff --git a/core/java/android/net/http/Connection.java b/core/java/android/net/http/Connection.java index 563634f..2d39e39 100644 --- a/core/java/android/net/http/Connection.java +++ b/core/java/android/net/http/Connection.java @@ -251,9 +251,7 @@ abstract class Connection { pipe.addLast(req); } exception = null; - state = (clearPipe(pipe) || - !mConnectionManager.isNetworkConnected()) ? - DONE : SEND; + state = clearPipe(pipe) ? DONE : SEND; minPipe = maxPipe = 1; break; } @@ -314,9 +312,7 @@ abstract class Connection { mHttpContext.removeAttribute(HTTP_CONNECTION); clearPipe(pipe); minPipe = maxPipe = 1; - /* If network active continue to service this queue */ - state = mConnectionManager.isNetworkConnected() ? - SEND : DONE; + state = SEND; } break; } @@ -408,8 +404,7 @@ abstract class Connection { if (error == EventHandler.OK) { return true; } else { - if (mConnectionManager.isNetworkConnected() == false || - req.mFailCount < RETRY_REQUEST_LIMIT) { + if (req.mFailCount < RETRY_REQUEST_LIMIT) { // requeue mRequestFeeder.requeueRequest(req); req.mFailCount++; @@ -432,14 +427,13 @@ abstract class Connection { */ private boolean httpFailure(Request req, int errorId, Exception e) { boolean ret = true; - boolean networkConnected = mConnectionManager.isNetworkConnected(); // e.printStackTrace(); if (HttpLog.LOGV) HttpLog.v( "httpFailure() ******* " + e + " count " + req.mFailCount + - " networkConnected " + networkConnected + " " + mHost + " " + req.getUri()); + " " + mHost + " " + req.getUri()); - if (networkConnected && ++req.mFailCount >= RETRY_REQUEST_LIMIT) { + if (++req.mFailCount >= RETRY_REQUEST_LIMIT) { ret = false; String error; if (errorId < 0) { diff --git a/core/java/android/net/http/ConnectionThread.java b/core/java/android/net/http/ConnectionThread.java index 8e759e2..0b30e58 100644 --- a/core/java/android/net/http/ConnectionThread.java +++ b/core/java/android/net/http/ConnectionThread.java @@ -32,8 +32,8 @@ class ConnectionThread extends Thread { static final int WAIT_TICK = 1000; // Performance probe - long mStartThreadTime; long mCurrentThreadTime; + long mTotalThreadTime; private boolean mWaiting; private volatile boolean mRunning = true; @@ -69,12 +69,21 @@ class ConnectionThread extends Thread { */ public void run() { android.os.Process.setThreadPriority( + android.os.Process.THREAD_PRIORITY_DEFAULT + android.os.Process.THREAD_PRIORITY_LESS_FAVORABLE); - mStartThreadTime = -1; - mCurrentThreadTime = SystemClock.currentThreadTimeMillis(); + // these are used to get performance data. When it is not in the timing, + // mCurrentThreadTime is 0. When it starts timing, mCurrentThreadTime is + // first set to -1, it will be set to the current thread time when the + // next request starts. + mCurrentThreadTime = 0; + mTotalThreadTime = 0; while (mRunning) { + if (mCurrentThreadTime == -1) { + mCurrentThreadTime = SystemClock.currentThreadTimeMillis(); + } + Request request; /* Get a request to process */ @@ -86,14 +95,14 @@ class ConnectionThread extends Thread { if (HttpLog.LOGV) HttpLog.v("ConnectionThread: Waiting for work"); mWaiting = true; try { - if (mStartThreadTime != -1) { - mCurrentThreadTime = SystemClock - .currentThreadTimeMillis(); - } mRequestFeeder.wait(); } catch (InterruptedException e) { } mWaiting = false; + if (mCurrentThreadTime != 0) { + mCurrentThreadTime = SystemClock + .currentThreadTimeMillis(); + } } } else { if (HttpLog.LOGV) HttpLog.v("ConnectionThread: new request " + @@ -123,6 +132,12 @@ class ConnectionThread extends Thread { mConnection.closeConnection(); } mConnection = null; + + if (mCurrentThreadTime > 0) { + long start = mCurrentThreadTime; + mCurrentThreadTime = SystemClock.currentThreadTimeMillis(); + mTotalThreadTime += mCurrentThreadTime - start; + } } } diff --git a/core/java/android/net/http/Request.java b/core/java/android/net/http/Request.java index df4fff0..1b6568e 100644 --- a/core/java/android/net/http/Request.java +++ b/core/java/android/net/http/Request.java @@ -67,9 +67,6 @@ class Request { /** Set if I'm using a proxy server */ HttpHost mProxyHost; - /** True if request is .html, .js, .css */ - boolean mHighPriority; - /** True if request has been cancelled */ volatile boolean mCancelled = false; @@ -102,26 +99,29 @@ class Request { * @param eventHandler request will make progress callbacks on * this interface * @param headers reqeust headers - * @param highPriority true for .html, css, .cs */ Request(String method, HttpHost host, HttpHost proxyHost, String path, InputStream bodyProvider, int bodyLength, EventHandler eventHandler, - Map<String, String> headers, boolean highPriority) { + Map<String, String> headers) { mEventHandler = eventHandler; mHost = host; mProxyHost = proxyHost; mPath = path; - mHighPriority = highPriority; mBodyProvider = bodyProvider; mBodyLength = bodyLength; - if (bodyProvider == null) { + if (bodyProvider == null && !"POST".equalsIgnoreCase(method)) { mHttpRequest = new BasicHttpRequest(method, getUri()); } else { mHttpRequest = new BasicHttpEntityEnclosingRequest( method, getUri()); - setBodyProvider(bodyProvider, bodyLength); + // it is ok to have null entity for BasicHttpEntityEnclosingRequest. + // By using BasicHttpEntityEnclosingRequest, it will set up the + // correct content-length, content-type and content-encoding. + if (bodyProvider != null) { + setBodyProvider(bodyProvider, bodyLength); + } } addHeader(HOST_HEADER, getHostPort()); @@ -255,6 +255,8 @@ class Request { // process gzip content encoding Header contentEncoding = entity.getContentEncoding(); InputStream nis = null; + byte[] buf = null; + int count = 0; try { if (contentEncoding != null && contentEncoding.getValue().equals("gzip")) { @@ -265,9 +267,8 @@ class Request { /* accumulate enough data to make it worth pushing it * up the stack */ - byte[] buf = mConnection.getBuf(); + buf = mConnection.getBuf(); int len = 0; - int count = 0; int lowWater = buf.length / 2; while (len != -1) { len = nis.read(buf, count, buf.length - count); @@ -284,6 +285,10 @@ class Request { /* InflaterInputStream throws an EOFException when the server truncates gzipped content. Handle this case as we do truncated non-gzipped content: no error */ + if (count > 0) { + // if there is uncommited content, we should commit them + mEventHandler.data(buf, count); + } if (HttpLog.LOGV) HttpLog.v( "readResponse() handling " + e); } catch(IOException e) { // don't throw if we have a non-OK status code @@ -346,7 +351,7 @@ class Request { * for debugging */ public String toString() { - return (mHighPriority ? "P*" : "") + mPath; + return mPath; } @@ -412,8 +417,7 @@ class Request { } return status >= HttpStatus.SC_OK && status != HttpStatus.SC_NO_CONTENT - && status != HttpStatus.SC_NOT_MODIFIED - && status != HttpStatus.SC_RESET_CONTENT; + && status != HttpStatus.SC_NOT_MODIFIED; } /** diff --git a/core/java/android/net/http/RequestHandle.java b/core/java/android/net/http/RequestHandle.java index 6a97951..190ae7a 100644 --- a/core/java/android/net/http/RequestHandle.java +++ b/core/java/android/net/http/RequestHandle.java @@ -419,6 +419,6 @@ public class RequestHandle { mRequest = mRequestQueue.queueRequest( mUrl, mUri, mMethod, mHeaders, mRequest.mEventHandler, mBodyProvider, - mBodyLength, mRequest.mHighPriority).mRequest; + mBodyLength).mRequest; } } diff --git a/core/java/android/net/http/RequestQueue.java b/core/java/android/net/http/RequestQueue.java index 66d5722..875caa0 100644 --- a/core/java/android/net/http/RequestQueue.java +++ b/core/java/android/net/http/RequestQueue.java @@ -26,7 +26,6 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.net.ConnectivityManager; -import android.net.NetworkConnectivityListener; import android.net.NetworkInfo; import android.net.Proxy; import android.net.WebAddress; @@ -50,154 +49,22 @@ import org.apache.http.HttpHost; */ public class RequestQueue implements RequestFeeder { - private Context mContext; /** * Requests, indexed by HttpHost (scheme, host, port) */ - private LinkedHashMap<HttpHost, LinkedList<Request>> mPending; - - /* Support for notifying a client when queue is empty */ - private boolean mClientWaiting = false; - - /** true if connected */ - boolean mNetworkConnected = true; + private final LinkedHashMap<HttpHost, LinkedList<Request>> mPending; + private final Context mContext; + private final ActivePool mActivePool; + private final ConnectivityManager mConnectivityManager; private HttpHost mProxyHost = null; private BroadcastReceiver mProxyChangeReceiver; - private ActivePool mActivePool; - /* default simultaneous connection count */ private static final int CONNECTION_COUNT = 4; /** - * This intent broadcast when http is paused or unpaused due to - * net availability toggling - */ - public final static String HTTP_NETWORK_STATE_CHANGED_INTENT = - "android.net.http.NETWORK_STATE"; - public final static String HTTP_NETWORK_STATE_UP = "up"; - - /** - * Listen to platform network state. On a change, - * (1) kick stack on or off as appropriate - * (2) send an intent to my host app telling - * it what I've done - */ - private NetworkStateTracker mNetworkStateTracker; - class NetworkStateTracker { - - final static int EVENT_DATA_STATE_CHANGED = 100; - - Context mContext; - NetworkConnectivityListener mConnectivityListener; - NetworkInfo.State mLastNetworkState = NetworkInfo.State.CONNECTED; - int mCurrentNetworkType; - - NetworkStateTracker(Context context) { - mContext = context; - } - - /** - * register for updates - */ - protected void enable() { - if (mConnectivityListener == null) { - /* - * Initializing the network type is really unnecessary, - * since as soon as we register with the NCL, we'll - * get a CONNECTED event for the active network, and - * we'll configure the HTTP proxy accordingly. However, - * as a fallback in case that doesn't happen for some - * reason, initializing to type WIFI would mean that - * we'd start out without a proxy. This seems better - * than thinking we have a proxy (which is probably - * private to the carrier network and therefore - * unreachable outside of that network) when we really - * shouldn't. - */ - mCurrentNetworkType = ConnectivityManager.TYPE_WIFI; - mConnectivityListener = new NetworkConnectivityListener(); - mConnectivityListener.registerHandler(mHandler, EVENT_DATA_STATE_CHANGED); - mConnectivityListener.startListening(mContext); - } - } - - protected void disable() { - if (mConnectivityListener != null) { - mConnectivityListener.unregisterHandler(mHandler); - mConnectivityListener.stopListening(); - mConnectivityListener = null; - } - } - - private Handler mHandler = new Handler() { - public void handleMessage(Message msg) { - switch (msg.what) { - case EVENT_DATA_STATE_CHANGED: - networkStateChanged(); - break; - } - } - }; - - int getCurrentNetworkType() { - return mCurrentNetworkType; - } - - void networkStateChanged() { - if (mConnectivityListener == null) - return; - - - NetworkConnectivityListener.State connectivityState = mConnectivityListener.getState(); - NetworkInfo info = mConnectivityListener.getNetworkInfo(); - if (info == null) { - /** - * We've been seeing occasional NPEs here. I believe recent changes - * have made this impossible, but in the interest of being totally - * paranoid, check and log this here. - */ - HttpLog.v("NetworkStateTracker: connectivity broadcast" - + " has null network info - ignoring"); - return; - } - NetworkInfo.State state = info.getState(); - - if (HttpLog.LOGV) { - HttpLog.v("NetworkStateTracker " + info.getTypeName() + - " state= " + state + " last= " + mLastNetworkState + - " connectivityState= " + connectivityState.toString()); - } - - boolean newConnection = - state != mLastNetworkState && state == NetworkInfo.State.CONNECTED; - - if (state == NetworkInfo.State.CONNECTED) { - mCurrentNetworkType = info.getType(); - setProxyConfig(); - } - - mLastNetworkState = state; - if (connectivityState == NetworkConnectivityListener.State.NOT_CONNECTED) { - setNetworkState(false); - broadcastState(false); - } else if (newConnection) { - setNetworkState(true); - broadcastState(true); - } - - } - - void broadcastState(boolean connected) { - Intent intent = new Intent(HTTP_NETWORK_STATE_CHANGED_INTENT); - intent.putExtra(HTTP_NETWORK_STATE_UP, connected); - mContext.sendBroadcast(intent); - } - } - - /** * This class maintains active connection threads */ class ActivePool implements ConnectionManager { @@ -233,10 +100,6 @@ public class RequestQueue implements RequestFeeder { } } - public boolean isNetworkConnected() { - return mNetworkConnected; - } - void startConnectionThread() { synchronized (RequestQueue.this) { RequestQueue.this.notify(); @@ -245,7 +108,9 @@ public class RequestQueue implements RequestFeeder { public void startTiming() { for (int i = 0; i < mConnectionCount; i++) { - mThreads[i].mStartThreadTime = mThreads[i].mCurrentThreadTime; + ConnectionThread rt = mThreads[i]; + rt.mCurrentThreadTime = -1; + rt.mTotalThreadTime = 0; } mTotalRequest = 0; mTotalConnection = 0; @@ -255,12 +120,14 @@ public class RequestQueue implements RequestFeeder { int totalTime = 0; for (int i = 0; i < mConnectionCount; i++) { ConnectionThread rt = mThreads[i]; - totalTime += (rt.mCurrentThreadTime - rt.mStartThreadTime); - rt.mStartThreadTime = -1; + if (rt.mCurrentThreadTime != -1) { + totalTime += rt.mTotalThreadTime; + } + rt.mCurrentThreadTime = 0; } Log.d("Http", "Http thread used " + totalTime + " ms " + " for " + mTotalRequest + " requests and " + mTotalConnection - + " connections"); + + " new connections"); } void logState() { @@ -348,6 +215,9 @@ public class RequestQueue implements RequestFeeder { mActivePool = new ActivePool(connectionCount); mActivePool.startup(); + + mConnectivityManager = (ConnectivityManager) + context.getSystemService(Context.CONNECTIVITY_SERVICE); } /** @@ -367,18 +237,6 @@ public class RequestQueue implements RequestFeeder { mContext.registerReceiver(mProxyChangeReceiver, new IntentFilter(Proxy.PROXY_CHANGE_ACTION)); } - - /* Network state notification is broken on the simulator - don't register for notifications on SIM */ - String device = SystemProperties.get("ro.product.device"); - boolean simulation = TextUtils.isEmpty(device); - - if (!simulation) { - if (mNetworkStateTracker == null) { - mNetworkStateTracker = new NetworkStateTracker(mContext); - } - mNetworkStateTracker.enable(); - } } /** @@ -388,10 +246,6 @@ public class RequestQueue implements RequestFeeder { public synchronized void disablePlatformNotifications() { if (HttpLog.LOGV) HttpLog.v("RequestQueue.disablePlatformNotifications() network"); - if (mNetworkStateTracker != null) { - mNetworkStateTracker.disable(); - } - if (mProxyChangeReceiver != null) { mContext.unregisterReceiver(mProxyChangeReceiver); mProxyChangeReceiver = null; @@ -403,7 +257,8 @@ public class RequestQueue implements RequestFeeder { * synchronize setting the proxy */ private synchronized void setProxyConfig() { - if (mNetworkStateTracker.getCurrentNetworkType() == ConnectivityManager.TYPE_WIFI) { + NetworkInfo info = mConnectivityManager.getActiveNetworkInfo(); + if (info != null && info.getType() == ConnectivityManager.TYPE_WIFI) { mProxyHost = null; } else { String host = Proxy.getHost(mContext); @@ -434,16 +289,14 @@ public class RequestQueue implements RequestFeeder { * data. Callbacks will be made on the supplied instance. * @param bodyProvider InputStream providing HTTP body, null if none * @param bodyLength length of body, must be 0 if bodyProvider is null - * @param highPriority If true, queues before low priority - * requests if possible */ public RequestHandle queueRequest( String url, String method, Map<String, String> headers, EventHandler eventHandler, - InputStream bodyProvider, int bodyLength, boolean highPriority) { + InputStream bodyProvider, int bodyLength) { WebAddress uri = new WebAddress(url); return queueRequest(url, uri, method, headers, eventHandler, - bodyProvider, bodyLength, highPriority); + bodyProvider, bodyLength); } /** @@ -456,14 +309,11 @@ public class RequestQueue implements RequestFeeder { * data. Callbacks will be made on the supplied instance. * @param bodyProvider InputStream providing HTTP body, null if none * @param bodyLength length of body, must be 0 if bodyProvider is null - * @param highPriority If true, queues before low priority - * requests if possible */ public RequestHandle queueRequest( String url, WebAddress uri, String method, Map<String, String> headers, EventHandler eventHandler, - InputStream bodyProvider, int bodyLength, - boolean highPriority) { + InputStream bodyProvider, int bodyLength) { if (HttpLog.LOGV) HttpLog.v("RequestQueue.queueRequest " + uri); @@ -478,9 +328,9 @@ public class RequestQueue implements RequestFeeder { // set up request req = new Request(method, httpHost, mProxyHost, uri.mPath, bodyProvider, - bodyLength, eventHandler, headers, highPriority); + bodyLength, eventHandler, headers); - queueRequest(req, highPriority); + queueRequest(req, false); mActivePool.mTotalRequest++; @@ -493,19 +343,6 @@ public class RequestQueue implements RequestFeeder { } /** - * Called by the NetworkStateTracker -- updates when network connectivity - * is lost/restored. - * - * If isNetworkConnected is true, start processing requests - */ - public void setNetworkState(boolean isNetworkConnected) { - if (HttpLog.LOGV) HttpLog.v("RequestQueue.setNetworkState() " + isNetworkConnected); - mNetworkConnected = isNetworkConnected; - if (isNetworkConnected) - mActivePool.startConnectionThread(); - } - - /** * @return true iff there are any non-active requests pending */ synchronized boolean requestsPending() { @@ -550,7 +387,7 @@ public class RequestQueue implements RequestFeeder { public synchronized Request getRequest() { Request ret = null; - if (mNetworkConnected && !mPending.isEmpty()) { + if (!mPending.isEmpty()) { ret = removeFirst(mPending); } if (HttpLog.LOGV) HttpLog.v("RequestQueue.getRequest() => " + ret); @@ -563,7 +400,7 @@ public class RequestQueue implements RequestFeeder { public synchronized Request getRequest(HttpHost host) { Request ret = null; - if (mNetworkConnected && mPending.containsKey(host)) { + if (mPending.containsKey(host)) { LinkedList<Request> reqList = mPending.get(host); ret = reqList.removeFirst(); if (reqList.isEmpty()) { @@ -639,7 +476,6 @@ public class RequestQueue implements RequestFeeder { * This interface is exposed to each connection */ interface ConnectionManager { - boolean isNetworkConnected(); HttpHost getProxyHost(); Connection getConnection(Context context, HttpHost host); boolean recycleConnection(HttpHost host, Connection connection); |