Merge change 21659 into eclair

* changes:
  Fix for Mms without wifi.
This commit is contained in:
Android (Google) Code Review
2009-08-19 07:19:06 -07:00

View File

@@ -49,6 +49,7 @@ public class MobileDataStateTracker extends NetworkStateTracker {
private String mApnType; private String mApnType;
private boolean mEnabled; private boolean mEnabled;
private BroadcastReceiver mStateReceiver;
/** /**
* Create a new MobileDataStateTracker * Create a new MobileDataStateTracker
@@ -94,7 +95,8 @@ public class MobileDataStateTracker extends NetworkStateTracker {
filter.addAction(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED); filter.addAction(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
filter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED); 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) if (intent != null)
mMobileDataState = getMobileDataState(intent); mMobileDataState = getMobileDataState(intent);
else else
@@ -130,74 +132,84 @@ public class MobileDataStateTracker extends NetworkStateTracker {
private class MobileDataStateReceiver extends BroadcastReceiver { private class MobileDataStateReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(TelephonyIntents. synchronized(this) {
ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) { if (intent.getAction().equals(TelephonyIntents.
Phone.DataState state = getMobileDataState(intent); ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) {
String reason = Phone.DataState state = getMobileDataState(intent);
intent.getStringExtra(Phone.STATE_CHANGE_REASON_KEY); String reason = intent.getStringExtra(Phone.STATE_CHANGE_REASON_KEY);
String apnName = intent.getStringExtra(Phone.DATA_APN_KEY); String apnName = intent.getStringExtra(Phone.DATA_APN_KEY);
String apnTypeList = intent.getStringExtra(Phone.DATA_APN_TYPES_KEY);
String apnTypeList = boolean unavailable = intent.getBooleanExtra(Phone.NETWORK_UNAVAILABLE_KEY,
intent.getStringExtra(Phone.DATA_APN_TYPES_KEY); false);
if (DBG) Log.d(TAG, mApnType + " Received " + intent.getAction() +
" broadcast - state = " + state + ", unavailable = " + unavailable +
", reason = " + (reason == null ? "(unspecified)" : reason));
boolean unavailable = intent.getBooleanExtra( if (isApnTypeIncluded(apnTypeList)) {
Phone.NETWORK_UNAVAILABLE_KEY, false); if (mEnabled == false) {
if (DBG) Log.d(TAG, mApnType + " Received " // if we're not enabled but the APN Type is supported by this connection
+ intent.getAction() + " broadcast - state = " // we should record the interface name if one's provided. If the user
+ state + ", unavailable = " + unavailable // turns on this network we will need the interfacename but won't get
+ ", reason = " // a fresh connected message - TODO fix this..
+ (reason == null ? "(unspecified)" : reason)); if (mInterfaceName == null && state == Phone.DataState.CONNECTED) {
mInterfaceName = intent.getStringExtra(Phone.DATA_IFACE_NAME_KEY);
if ((!isApnTypeIncluded(apnTypeList)) || mEnabled == false) { } else if (state == Phone.DataState.DISCONNECTED) {
if (DBG) Log.e(TAG, " dropped - mEnabled = "+mEnabled); mInterfaceName = null;
return; }
} if (DBG) Log.d(TAG, " dropped - mEnabled = false");
return;
mNetworkInfo.setIsAvailable(!unavailable);
if (mMobileDataState != state) {
mMobileDataState = state;
switch (state) {
case DISCONNECTED:
if(isTeardownRequested()) {
mEnabled = false;
setTeardownRequested(false);
} }
} else {
setDetailedState(DetailedState.DISCONNECTED, reason, apnName); if (DBG) Log.d(TAG, " dropped - wrong Apn");
if (mInterfaceName != null) { return;
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.");
}
setDetailedState(DetailedState.CONNECTED, reason, apnName);
break;
} }
mNetworkInfo.setIsAvailable(!unavailable);
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);
}
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);
} }
} else if (intent.getAction().equals(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED)) { TelephonyManager tm = TelephonyManager.getDefault();
mEnabled = false; setRoamingStatus(tm.isNetworkRoaming());
String reason = intent.getStringExtra(Phone.FAILURE_REASON_KEY); setSubtype(tm.getNetworkType(), tm.getNetworkTypeName());
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());
} }
} }
@@ -285,10 +297,33 @@ public class MobileDataStateTracker extends NetworkStateTracker {
* Re-enable mobile data connectivity after a {@link #teardown()}. * Re-enable mobile data connectivity after a {@link #teardown()}.
*/ */
public boolean reconnect() { public boolean reconnect() {
mEnabled = true;
setTeardownRequested(false); setTeardownRequested(false);
mEnabled = (setEnableApn(mApnType, true) != switch (setEnableApn(mApnType, true)) {
Phone.APN_REQUEST_FAILED); case Phone.APN_ALREADY_ACTIVE:
mEnabled = true;
//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_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:
case Phone.APN_TYPE_NOT_AVAILABLE:
mEnabled = false;
break;
default:
Log.e(TAG, "Error in reconnect - unexpected response.");
mEnabled = false;
break;
}
return mEnabled; return mEnabled;
} }