diff options
Diffstat (limited to 'core/java/android/net/MobileDataStateTracker.java')
-rw-r--r-- | core/java/android/net/MobileDataStateTracker.java | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/core/java/android/net/MobileDataStateTracker.java b/core/java/android/net/MobileDataStateTracker.java index 8113aaa..214510d 100644 --- a/core/java/android/net/MobileDataStateTracker.java +++ b/core/java/android/net/MobileDataStateTracker.java @@ -48,6 +48,7 @@ public class MobileDataStateTracker extends NetworkStateTracker { private ITelephony mPhoneService; private String mApnType; + private String mApnTypeToWatchFor; private String mApnName; private boolean mEnabled; private BroadcastReceiver mStateReceiver; @@ -60,12 +61,17 @@ public class MobileDataStateTracker extends NetworkStateTracker { * @param apnType the Phone apnType * @param tag the name of this network */ - public MobileDataStateTracker(Context context, Handler target, - int netType, String apnType, String tag) { + public MobileDataStateTracker(Context context, Handler target, int netType, String tag) { super(context, target, netType, TelephonyManager.getDefault().getNetworkType(), tag, TelephonyManager.getDefault().getNetworkTypeName()); - mApnType = apnType; + mApnType = networkTypeToApnType(netType); + if (TextUtils.equals(mApnType, Phone.APN_TYPE_HIPRI)) { + mApnTypeToWatchFor = Phone.APN_TYPE_DEFAULT; + } else { + mApnTypeToWatchFor = mApnType; + } + mPhoneService = null; if(netType == ConnectivityManager.TYPE_MOBILE) { mEnabled = true; @@ -123,7 +129,7 @@ public class MobileDataStateTracker extends NetworkStateTracker { String[] list = typeList.split(","); for(int i=0; i< list.length; i++) { - if (TextUtils.equals(list[i], mApnType) || + if (TextUtils.equals(list[i], mApnTypeToWatchFor) || TextUtils.equals(list[i], Phone.APN_TYPE_ALL)) { return true; } @@ -343,7 +349,7 @@ public class MobileDataStateTracker extends NetworkStateTracker { 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_TYPES_KEY, mApnTypeToWatchFor); intent.putExtra(Phone.DATA_APN_KEY, mApnName); intent.putExtra(Phone.DATA_IFACE_NAME_KEY, mInterfaceName); intent.putExtra(Phone.NETWORK_UNAVAILABLE_KEY, false); @@ -356,12 +362,21 @@ public class MobileDataStateTracker extends NetworkStateTracker { 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. + // since the phone will come up enabled, go with that. + // TODO - this also comes up on telephony crash: if we think mobile data is + // off and the telephony stuff crashes and has to restart it will come up + // enabled (making a data connection). We will then be out of sync. + // A possible solution is a broadcast when telephony restarts. + mEnabled = true; return false; } // else fall through case Phone.APN_TYPE_NOT_AVAILABLE: - mEnabled = false; + // Default is always available, but may be off due to + // AirplaneMode or E-Call or whatever.. + if (mApnType != Phone.APN_TYPE_DEFAULT) { + mEnabled = false; + } break; default: Log.e(TAG, "Error in reconnect - unexpected response."); @@ -504,4 +519,22 @@ public class MobileDataStateTracker extends NetworkStateTracker { + " APN type \"" + apnType + "\""); return Phone.APN_REQUEST_FAILED; } + + public static String networkTypeToApnType(int netType) { + switch(netType) { + case ConnectivityManager.TYPE_MOBILE: + return Phone.APN_TYPE_DEFAULT; // TODO - use just one of these + case ConnectivityManager.TYPE_MOBILE_MMS: + return Phone.APN_TYPE_MMS; + case ConnectivityManager.TYPE_MOBILE_SUPL: + return Phone.APN_TYPE_SUPL; + case ConnectivityManager.TYPE_MOBILE_DUN: + return Phone.APN_TYPE_DUN; + case ConnectivityManager.TYPE_MOBILE_HIPRI: + return Phone.APN_TYPE_HIPRI; + default: + Log.e(TAG, "Error mapping networkType " + netType + " to apnType."); + return null; + } + } } |