Fix CDMA to startup/shutdown based on apn en/disab

Fixes MMS during wifi.
Also fixes CDMA for ConnectivityManager change.
This commit is contained in:
Robert Greenwalt
2009-08-13 15:59:51 -07:00
parent 60fae2af3c
commit 25a5d3db3f
7 changed files with 310 additions and 414 deletions

View File

@@ -49,7 +49,6 @@ public class MobileDataStateTracker extends NetworkStateTracker {
private String mApnType;
private boolean mEnabled;
private boolean mTeardownRequested;
/**
* Create a new MobileDataStateTracker
@@ -66,7 +65,6 @@ public class MobileDataStateTracker extends NetworkStateTracker {
TelephonyManager.getDefault().getNetworkTypeName());
mApnType = apnType;
mPhoneService = null;
mTeardownRequested = false;
if(netType == ConnectivityManager.TYPE_MOBILE) {
mEnabled = true;
} else {
@@ -81,7 +79,9 @@ public class MobileDataStateTracker extends NetworkStateTracker {
"net.eth0.dns3",
"net.eth0.dns4",
"net.gprs.dns1",
"net.gprs.dns2"};
"net.gprs.dns2",
"net.ppp0.dns1",
"net.ppp0.dns2"};
}
@@ -160,9 +160,9 @@ public class MobileDataStateTracker extends NetworkStateTracker {
switch (state) {
case DISCONNECTED:
if(mTeardownRequested) {
if(isTeardownRequested()) {
mEnabled = false;
mTeardownRequested = false;
setTeardownRequested(false);
}
setDetailedState(DetailedState.DISCONNECTED, reason, apnName);
@@ -277,7 +277,7 @@ public class MobileDataStateTracker extends NetworkStateTracker {
*/
@Override
public boolean teardown() {
mTeardownRequested = true;
setTeardownRequested(true);
return (setEnableApn(mApnType, false) != Phone.APN_REQUEST_FAILED);
}
@@ -286,7 +286,7 @@ public class MobileDataStateTracker extends NetworkStateTracker {
*/
public boolean reconnect() {
mEnabled = true;
mTeardownRequested = false;
setTeardownRequested(false);
mEnabled = (setEnableApn(mApnType, true) !=
Phone.APN_REQUEST_FAILED);
return mEnabled;

View File

@@ -24,14 +24,18 @@ import android.os.Message;
import android.os.RemoteException;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.text.TextUtils;
import android.util.Log;
import java.util.ArrayList;
/**
* {@hide}
*
*/
public abstract class DataConnectionTracker extends Handler {
private static final boolean DBG = true;
protected static final boolean DBG = true;
protected final String LOG_TAG = "DataConnectionTracker";
/**
* IDLE: ready to start data connection setup, default state
@@ -98,6 +102,20 @@ public abstract class DataConnectionTracker extends Handler {
//***** Constants
protected static final int APN_INVALID_ID = -1;
protected static final int APN_DEFAULT_ID = 0;
protected static final int APN_MMS_ID = 1;
protected static final int APN_SUPL_ID = 2;
protected static final int APN_DUN_ID = 3;
protected static final int APN_HIPRI_ID = 4;
protected static final int APN_NUM_TYPES = 5;
protected boolean[] dataEnabled = new boolean[APN_NUM_TYPES];
protected int enabledCount = 0;
/* Currently requested APN type */
protected String mRequestedApnType = Phone.APN_TYPE_DEFAULT;
/** Retry configuration: A doubling of retry times from 5secs to 30minutes */
protected static final String DEFAULT_DATA_RETRY_CONFIG = "default_randomization=2000,"
+ "5000,10000,20000,40000,80000:5000,160000:5000,"
@@ -167,6 +185,8 @@ public abstract class DataConnectionTracker extends Handler {
this.phone = phone;
}
public abstract void dispose();
public Activity getActivity() {
return activity;
}
@@ -301,24 +321,18 @@ public abstract class DataConnectionTracker extends Handler {
* @return {@code false} if data connectivity has been explicitly disabled,
* {@code true} otherwise.
*/
public abstract boolean getDataEnabled();
public boolean getDataEnabled() {
return dataEnabled[APN_DEFAULT_ID];
}
/**
* Report on whether data connectivity is enabled
* @return {@code false} if data connectivity has been explicitly disabled,
* {@code true} otherwise.
*/
public abstract boolean getAnyDataEnabled();
/**
* Prevent mobile data connections from being established,
* or once again allow mobile data connections. If the state
* toggles, then either tear down or set up data, as
* appropriate to match the new state.
* @param enable indicates whether to enable ({@code true}) or disable ({@code false}) data
* @return {@code true} if the operation succeeded
*/
public abstract boolean setDataEnabled(boolean enable);
public boolean getAnyDataEnabled() {
return (enabledCount != 0);
}
protected abstract void startNetStatPoll();
@@ -327,4 +341,162 @@ public abstract class DataConnectionTracker extends Handler {
protected abstract void restartRadio();
protected abstract void log(String s);
protected int apnTypeToId(String type) {
if (TextUtils.equals(type, Phone.APN_TYPE_DEFAULT)) {
return APN_DEFAULT_ID;
} else if (TextUtils.equals(type, Phone.APN_TYPE_MMS)) {
return APN_MMS_ID;
} else if (TextUtils.equals(type, Phone.APN_TYPE_SUPL)) {
return APN_SUPL_ID;
} else if (TextUtils.equals(type, Phone.APN_TYPE_DUN)) {
return APN_DUN_ID;
} else if (TextUtils.equals(type, Phone.APN_TYPE_HIPRI)) {
return APN_HIPRI_ID;
} else {
return APN_INVALID_ID;
}
}
protected abstract boolean isApnTypeActive(String type);
protected abstract boolean isApnTypeAvailable(String type);
protected abstract String[] getActiveApnTypes();
protected abstract String getActiveApnString();
public abstract ArrayList<DataConnection> getAllDataConnections();
protected abstract String getInterfaceName(String apnType);
protected abstract String getIpAddress(String apnType);
protected abstract String getGateway(String apnType);
protected abstract String[] getDnsServers(String apnType);
protected abstract void setState(State s);
protected boolean isEnabled(int id) {
if (id != APN_INVALID_ID) {
return dataEnabled[id];
}
return false;
}
/**
* Ensure that we are connected to an APN of the specified type.
* @param type the APN type (currently the only valid values
* are {@link Phone#APN_TYPE_MMS} and {@link Phone#APN_TYPE_SUPL})
* @return the result of the operation. Success is indicated by
* a return value of either {@code Phone.APN_ALREADY_ACTIVE} or
* {@code Phone.APN_REQUEST_STARTED}. In the latter case, a broadcast
* will be sent by the ConnectivityManager when a connection to
* the APN has been established.
*/
public int enableApnType(String type) {
int id = apnTypeToId(type);
if (id == APN_INVALID_ID) {
return Phone.APN_REQUEST_FAILED;
}
// If already active, return
if(DBG) Log.d(LOG_TAG, "enableApnType("+type+"), isApnTypeActive = "
+ isApnTypeActive(type) + " and state = " + state);
if (isApnTypeActive(type)) {
if (state == State.INITING) return Phone.APN_REQUEST_STARTED;
else if (state == State.CONNECTED) return Phone.APN_ALREADY_ACTIVE;
}
if (!isApnTypeAvailable(type)) {
return Phone.APN_TYPE_NOT_AVAILABLE;
}
setEnabled(id, true);
mRequestedApnType = type;
sendMessage(obtainMessage(EVENT_ENABLE_NEW_APN));
return Phone.APN_REQUEST_STARTED;
}
/**
* The APN of the specified type is no longer needed. Ensure that if
* use of the default APN has not been explicitly disabled, we are connected
* to the default APN.
* @param type the APN type. The only valid values are currently
* {@link Phone#APN_TYPE_MMS} and {@link Phone#APN_TYPE_SUPL}.
* @return
*/
public int disableApnType(String type) {
if (DBG) Log.d(LOG_TAG, "disableApnType("+type+")");
int id = apnTypeToId(type);
if (id == APN_INVALID_ID) {
return Phone.APN_REQUEST_FAILED;
}
if (isEnabled(id)) {
setEnabled(id, false);
if (isApnTypeActive(Phone.APN_TYPE_DEFAULT)) {
mRequestedApnType = Phone.APN_TYPE_DEFAULT;
if (dataEnabled[APN_DEFAULT_ID]) {
return Phone.APN_ALREADY_ACTIVE;
} else {
return Phone.APN_REQUEST_STARTED;
}
} else {
return Phone.APN_REQUEST_STARTED;
}
} else {
return Phone.APN_REQUEST_FAILED;
}
}
protected synchronized void setEnabled(int id, boolean enable) {
if (DBG) Log.d(LOG_TAG, "setEnabled(" + id + ", " + enable + ')');
if (dataEnabled[id] != enable) {
dataEnabled[id] = enable;
if (enable) {
enabledCount++;
} else {
enabledCount--;
}
if (enabledCount == 0) {
setPrivateDataEnabled(false);
} else if (enabledCount == 1) {
setPrivateDataEnabled(true);
}
}
}
/**
* Prevent mobile data connections from being established,
* or once again allow mobile data connections. If the state
* toggles, then either tear down or set up data, as
* appropriate to match the new state.
* <p>This operation only affects the default APN, and if the same APN is
* currently being used for MMS traffic, the teardown will not happen
* even when {@code enable} is {@code false}.</p>
* @param enable indicates whether to enable ({@code true}) or disable ({@code false}) data
* @return {@code true} if the operation succeeded
*/
public boolean setDataEnabled(boolean enable) {
if (DBG) Log.d(LOG_TAG, "setDataEnabled("+enable+")");
setEnabled(APN_DEFAULT_ID, enable);
return true;
}
private void setPrivateDataEnabled(boolean enable) {
if (DBG) Log.d(LOG_TAG, "setPrivateDataEnabled("+enable+")");
if (enable) {
sendMessage(obtainMessage(EVENT_TRY_SETUP_DATA));
} else {
Message msg = obtainMessage(EVENT_CLEAN_UP_CONNECTION);
msg.arg1 = 1; // tearDown is true
msg.obj = Phone.REASON_DATA_DISABLED;
sendMessage(msg);
}
}
}

View File

@@ -109,6 +109,7 @@ public abstract class PhoneBase implements Phone {
public CommandsInterface mCM;
protected IccFileHandler mIccFileHandler;
boolean mDnsCheckDisabled = false;
public DataConnectionTracker mDataConnection;
/**
* Set a system property, unless we're in unit test mode
@@ -824,4 +825,71 @@ public abstract class PhoneBase implements Phone {
// This function should be overridden by the class CDMAPhone. Not implemented in GSMPhone.
Log.e(LOG_TAG, "Error! This function should never be executed, inactive CDMAPhone.");
}
public String getInterfaceName(String apnType) {
return mDataConnection.getInterfaceName(apnType);
}
public String getIpAddress(String apnType) {
return mDataConnection.getIpAddress(apnType);
}
public boolean isDataConnectivityEnabled() {
return mDataConnection.getDataEnabled();
}
public String getGateway(String apnType) {
return mDataConnection.getGateway(apnType);
}
public String[] getDnsServers(String apnType) {
return mDataConnection.getDnsServers(apnType);
}
public String[] getActiveApnTypes() {
return mDataConnection.getActiveApnTypes();
}
public String getActiveApn() {
return mDataConnection.getActiveApnString();
}
public int enableApnType(String type) {
return mDataConnection.enableApnType(type);
}
public int disableApnType(String type) {
return mDataConnection.disableApnType(type);
}
/**
* simulateDataConnection
*
* simulates various data connection states. This messes with
* DataConnectionTracker's internal states, but doesn't actually change
* the underlying radio connection states.
*
* @param state Phone.DataState enum.
*/
public void simulateDataConnection(Phone.DataState state) {
DataConnectionTracker.State dcState;
switch (state) {
case CONNECTED:
dcState = DataConnectionTracker.State.CONNECTED;
break;
case SUSPENDED:
dcState = DataConnectionTracker.State.CONNECTED;
break;
case DISCONNECTED:
dcState = DataConnectionTracker.State.FAILED;
break;
default:
dcState = DataConnectionTracker.State.CONNECTING;
break;
}
mDataConnection.setState(dcState);
notifyDataConnection(null);
}
}

View File

@@ -95,7 +95,6 @@ public class CDMAPhone extends PhoneBase {
CdmaCallTracker mCT;
CdmaSMSDispatcher mSMS;
CdmaServiceStateTracker mSST;
CdmaDataConnectionTracker mDataConnection;
RuimFileHandler mRuimFileHandler;
RuimRecords mRuimRecords;
RuimCard mRuimCard;
@@ -369,42 +368,11 @@ public class CDMAPhone extends PhoneBase {
return mCT.backgroundCall;
}
public String getGateway(String apnType) {
return mDataConnection.getGateway();
}
public boolean handleInCallMmiCommands(String dialString) {
Log.e(LOG_TAG, "method handleInCallMmiCommands is NOT supported in CDMA!");
return false;
}
public int enableApnType(String type) {
// This request is mainly used to enable MMS APN
// In CDMA there is no need to enable/disable a different APN for MMS
Log.d(LOG_TAG, "Request to enableApnType("+type+")");
if (TextUtils.equals(type, Phone.APN_TYPE_MMS)) {
return Phone.APN_ALREADY_ACTIVE;
} else {
return Phone.APN_REQUEST_FAILED;
}
}
public int disableApnType(String type) {
// This request is mainly used to disable MMS APN
// In CDMA there is no need to enable/disable a different APN for MMS
Log.d(LOG_TAG, "Request to disableApnType("+type+")");
if (TextUtils.equals(type, Phone.APN_TYPE_MMS)) {
return Phone.APN_REQUEST_STARTED;
} else {
return Phone.APN_REQUEST_FAILED;
}
}
public String getActiveApn() {
Log.d(LOG_TAG, "Request to getActiveApn()");
return null;
}
public void
setNetworkSelectionModeAutomatic(Message response) {
Log.e(LOG_TAG, "method setNetworkSelectionModeAutomatic is NOT supported in CDMA!");
@@ -481,10 +449,6 @@ public class CDMAPhone extends PhoneBase {
return false;
}
public String getInterfaceName(String apnType) {
return mDataConnection.getInterfaceName();
}
public CellLocation getCellLocation() {
return mSST.cellLoc;
}
@@ -512,10 +476,6 @@ public class CDMAPhone extends PhoneBase {
return false;
}
public boolean isDataConnectivityEnabled() {
return mDataConnection.getDataEnabled();
}
public boolean isDataConnectivityPossible() {
boolean noData = mDataConnection.getDataEnabled() &&
getDataConnectionState() == DataState.DISCONNECTED;
@@ -528,10 +488,6 @@ public class CDMAPhone extends PhoneBase {
Log.e(LOG_TAG, "setLine1Number: not possible in CDMA");
}
public String[] getDnsServers(String apnType) {
return mDataConnection.getDnsServers();
}
public IccCard getIccCard() {
return mRuimCard;
}
@@ -584,10 +540,6 @@ public class CDMAPhone extends PhoneBase {
mCT.unregisterForCallWaiting(h);
}
public String getIpAddress(String apnType) {
return mDataConnection.getIpAddress();
}
public void
getNeighboringCids(Message response) {
/*
@@ -701,14 +653,6 @@ public class CDMAPhone extends PhoneBase {
Log.e(LOG_TAG, "getAvailableNetworks: not possible in CDMA");
}
public String[] getActiveApnTypes() {
String[] result;
Log.d(LOG_TAG, "Request to getActiveApn()");
result = new String[1];
result[0] = Phone.APN_TYPE_DEFAULT;
return result;
}
public void setOutgoingCallerIdDisplay(int commandInterfaceCLIRMode, Message onComplete) {
Log.e(LOG_TAG, "setOutgoingCallerIdDisplay: not possible in CDMA");
}

View File

@@ -57,8 +57,7 @@ import java.util.ArrayList;
* {@hide}
*/
public final class CdmaDataConnectionTracker extends DataConnectionTracker {
private static final String LOG_TAG = "CDMA";
private static final boolean DBG = true;
protected final String LOG_TAG = "CDMA";
private CDMAPhone mCdmaPhone;
@@ -77,12 +76,6 @@ public final class CdmaDataConnectionTracker extends DataConnectionTracker {
/** Currently active CdmaDataConnection */
private CdmaDataConnection mActiveDataConnection;
/** Defined cdma connection profiles */
private static final int EXTERNAL_NETWORK_DEFAULT_ID = 0;
private static final int EXTERNAL_NETWORK_NUM_TYPES = 1;
private boolean[] dataEnabled = new boolean[EXTERNAL_NETWORK_NUM_TYPES];
/**
* Pool size of CdmaDataConnection objects.
*/
@@ -101,6 +94,11 @@ public final class CdmaDataConnectionTracker extends DataConnectionTracker {
private static final int DATA_CONNECTION_ACTIVE_PH_LINK_DOWN = 1;
private static final int DATA_CONNECTION_ACTIVE_PH_LINK_UP = 2;
private static final String[] mSupportedApnTypes = {
Phone.APN_TYPE_DEFAULT,
Phone.APN_TYPE_MMS,
Phone.APN_TYPE_HIPRI };
// Possibly promoate to base class, the only difference is
// the INTENT_RECONNECT_ALARM action is a different string.
// Do consider technology changes if it is promoted.
@@ -182,9 +180,12 @@ public final class CdmaDataConnectionTracker extends DataConnectionTracker {
// and 2) whether the RIL will setup the baseband to auto-PS attach.
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(phone.getContext());
dataEnabled[EXTERNAL_NETWORK_DEFAULT_ID] =
dataEnabled[APN_DEFAULT_ID] =
!sp.getBoolean(CDMAPhone.DATA_DISABLED_ON_BOOT_KEY, false);
noAutoAttach = !dataEnabled[EXTERNAL_NETWORK_DEFAULT_ID];
if (dataEnabled[APN_DEFAULT_ID]) {
enabledCount++;
}
noAutoAttach = !dataEnabled[APN_DEFAULT_ID];
if (!mRetryMgr.configure(SystemProperties.get("ro.cdma.data_retry_config"))) {
if (!mRetryMgr.configure(DEFAULT_DATA_RETRY_CONFIG)) {
@@ -219,7 +220,7 @@ public final class CdmaDataConnectionTracker extends DataConnectionTracker {
if(DBG) Log.d(LOG_TAG, "CdmaDataConnectionTracker finalized");
}
void setState(State s) {
protected void setState(State s) {
if (DBG) log ("setState: " + s);
if (state != s) {
if (s == State.INITING) { // request Data connection context
@@ -236,39 +237,33 @@ public final class CdmaDataConnectionTracker extends DataConnectionTracker {
state = s;
}
public int enableApnType(String type) {
// This request is mainly used to enable MMS APN
// In CDMA there is no need to enable/disable a different APN for MMS
Log.d(LOG_TAG, "Request to enableApnType("+type+")");
if (TextUtils.equals(type, Phone.APN_TYPE_MMS)) {
return Phone.APN_ALREADY_ACTIVE;
} else if (TextUtils.equals(type, Phone.APN_TYPE_SUPL)) {
Log.w(LOG_TAG, "Phone.APN_TYPE_SUPL not enabled for CDMA");
return Phone.APN_REQUEST_FAILED;
} else {
return Phone.APN_REQUEST_FAILED;
@Override
protected boolean isApnTypeActive(String type) {
return (isApnTypeAvailable(type) &&
mCdmaPhone.mSST.getCurrentCdmaDataConnectionState() ==
ServiceState.STATE_IN_SERVICE);
}
@Override
protected boolean isApnTypeAvailable(String type) {
for (String s : mSupportedApnTypes) {
if (TextUtils.equals(type, s)) {
return true;
}
}
return false;
}
public int disableApnType(String type) {
// This request is mainly used to disable MMS APN
// In CDMA there is no need to enable/disable a different APN for MMS
Log.d(LOG_TAG, "Request to disableApnType("+type+")");
if (TextUtils.equals(type, Phone.APN_TYPE_MMS)) {
return Phone.APN_REQUEST_STARTED;
} else {
return Phone.APN_REQUEST_FAILED;
protected String[] getActiveApnTypes() {
if (mCdmaPhone.mSST.getCurrentCdmaDataConnectionState() ==
ServiceState.STATE_IN_SERVICE) {
return mSupportedApnTypes.clone();
}
return new String[0];
}
private boolean isEnabled(int cdmaDataProfile) {
return dataEnabled[cdmaDataProfile];
}
private void setEnabled(int cdmaDataProfile, boolean enable) {
Log.d(LOG_TAG, "setEnabled(" + cdmaDataProfile + ", " + enable + ')');
dataEnabled[cdmaDataProfile] = enable;
Log.d(LOG_TAG, "dataEnabled[DEFAULT_PROFILE]=" + dataEnabled[EXTERNAL_NETWORK_DEFAULT_ID]);
protected String getActiveApnString() {
return null;
}
/**
@@ -294,54 +289,6 @@ public final class CdmaDataConnectionTracker extends DataConnectionTracker {
return true;
}
/**
* Prevent mobile data connections from being established,
* or once again allow mobile data connections. If the state
* toggles, then either tear down or set up data, as
* appropriate to match the new state.
* <p>This operation only affects the default connection
* @param enable indicates whether to enable ({@code true}) or disable ({@code false}) data
* @return {@code true} if the operation succeeded
*/
public boolean setDataEnabled(boolean enable) {
boolean isEnabled = isEnabled(EXTERNAL_NETWORK_DEFAULT_ID);
Log.d(LOG_TAG, "setDataEnabled("+enable+") isEnabled=" + isEnabled);
if (!isEnabled && enable) {
setEnabled(EXTERNAL_NETWORK_DEFAULT_ID, true);
sendMessage(obtainMessage(EVENT_TRY_SETUP_DATA));
} else if (!enable) {
setEnabled(EXTERNAL_NETWORK_DEFAULT_ID, false);
Message msg = obtainMessage(EVENT_CLEAN_UP_CONNECTION);
msg.arg1 = 1; // tearDown is true
msg.obj = Phone.REASON_DATA_DISABLED;
sendMessage(msg);
}
return true;
}
/**
* Report the current state of data connectivity (enabled or disabled)
* @return {@code false} if data connectivity has been explicitly disabled,
* {@code true} otherwise.
*/
public boolean getDataEnabled() {
return dataEnabled[EXTERNAL_NETWORK_DEFAULT_ID];
}
/**
* Report on whether data connectivity is enabled
* @return {@code false} if data connectivity has been explicitly disabled,
* {@code true} otherwise.
*/
public boolean getAnyDataEnabled() {
for (int i=0; i < EXTERNAL_NETWORK_NUM_TYPES; i++) {
if (isEnabled(i)) return true;
}
return false;
}
private boolean isDataAllowed() {
boolean roaming = phone.getServiceState().getRoaming();
return getAnyDataEnabled() && (!roaming || getDataOnRoamingEnabled());
@@ -921,28 +868,28 @@ public final class CdmaDataConnectionTracker extends DataConnectionTracker {
}
}
String getInterfaceName() {
protected String getInterfaceName(String apnType) {
if (mActiveDataConnection != null) {
return mActiveDataConnection.getInterface();
}
return null;
}
protected String getIpAddress() {
protected String getIpAddress(String apnType) {
if (mActiveDataConnection != null) {
return mActiveDataConnection.getIpAddress();
}
return null;
}
String getGateway() {
protected String getGateway(String apnType) {
if (mActiveDataConnection != null) {
return mActiveDataConnection.getGatewayAddress();
}
return null;
}
protected String[] getDnsServers() {
protected String[] getDnsServers(String apnType) {
if (mActiveDataConnection != null) {
return mActiveDataConnection.getDnsServers();
}

View File

@@ -102,7 +102,6 @@ public class GSMPhone extends PhoneBase {
GsmCallTracker mCT;
GsmServiceStateTracker mSST;
GsmSMSDispatcher mSMS;
GsmDataConnectionTracker mDataConnection;
SIMRecords mSIMRecords;
SimCard mSimCard;
StkService mStkService;
@@ -280,14 +279,6 @@ public class GSMPhone extends PhoneBase {
return "GSM";
}
public String[] getActiveApnTypes() {
return mDataConnection.getActiveApnTypes();
}
public String getActiveApn() {
return mDataConnection.getActiveApnString();
}
public SignalStrength getSignalStrength() {
return mSST.mSignalStrength;
}
@@ -1145,38 +1136,10 @@ public class GSMPhone extends PhoneBase {
return mDataConnection.setDataEnabled(true);
}
public int enableApnType(String type) {
return mDataConnection.enableApnType(type);
}
public int disableApnType(String type) {
return mDataConnection.disableApnType(type);
}
public boolean disableDataConnectivity() {
return mDataConnection.setDataEnabled(false);
}
public String getInterfaceName(String apnType) {
return mDataConnection.getInterfaceName(apnType);
}
public String getIpAddress(String apnType) {
return mDataConnection.getIpAddress(apnType);
}
public String getGateway(String apnType) {
return mDataConnection.getGateway(apnType);
}
public String[] getDnsServers(String apnType) {
return mDataConnection.getDnsServers(apnType);
}
public boolean isDataConnectivityEnabled() {
return mDataConnection.getDataEnabled();
}
/**
* The only circumstances under which we report that data connectivity is not
* possible are
@@ -1543,36 +1506,6 @@ public class GSMPhone extends PhoneBase {
}
}
}
/**
* simulateDataConnection
*
* simulates various data connection states. This messes with
* DataConnectionTracker's internal states, but doesn't actually change
* the underlying radio connection states.
*
* @param state Phone.DataState enum.
*/
public void simulateDataConnection(Phone.DataState state) {
DataConnectionTracker.State dcState;
switch (state) {
case CONNECTED:
dcState = DataConnectionTracker.State.CONNECTED;
break;
case SUSPENDED:
dcState = DataConnectionTracker.State.CONNECTED;
break;
case DISCONNECTED:
dcState = DataConnectionTracker.State.FAILED;
break;
default:
dcState = DataConnectionTracker.State.CONNECTING;
break;
}
mDataConnection.setState(dcState);
notifyDataConnection(null);
}
/**
* Retrieves the PhoneSubInfo of the GSMPhone

View File

@@ -63,8 +63,7 @@ import java.util.ArrayList;
* {@hide}
*/
public final class GsmDataConnectionTracker extends DataConnectionTracker {
private static final String LOG_TAG = "GSM";
private static final boolean DBG = true;
protected final String LOG_TAG = "GSM";
private GSMPhone mGsmPhone;
/**
@@ -119,31 +118,17 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
private ApnSetting preferredApn = null;
/* Currently active APN */
protected ApnSetting mActiveApn;
/**
* pdpList holds all the PDP connection, i.e. IP Link in GPRS
*/
private ArrayList<DataConnection> pdpList;
/** Currently requested APN type */
private String mRequestedApnType = Phone.APN_TYPE_DEFAULT;
/** Currently active APN */
private ApnSetting mActiveApn;
/** Currently active PdpConnection */
private PdpConnection mActivePdp;
private static int APN_INVALID_ID = -1;
private static int APN_DEFAULT_ID = 0;
private static int APN_MMS_ID = 1;
private static int APN_SUPL_ID = 2;
private static int APN_DUN_ID = 3;
private static int APN_HIPRI_ID = 4;
private static int APN_NUM_TYPES = 5;
private boolean[] dataEnabled = new boolean[APN_NUM_TYPES];
private int enabledCount = 0;
/** Is packet service restricted by network */
private boolean mIsPsRestricted = false;
@@ -293,7 +278,7 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
if(DBG) Log.d(LOG_TAG, "GsmDataConnectionTracker finalized");
}
void setState(State s) {
protected void setState(State s) {
if (DBG) log ("setState: " + s);
if (state != s) {
if (s == State.INITING) { // request PDP context
@@ -317,7 +302,7 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
}
}
String[] getActiveApnTypes() {
public String[] getActiveApnTypes() {
String[] result;
if (mActiveApn != null) {
result = mActiveApn.types;
@@ -336,87 +321,6 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
return result;
}
protected int apnTypeToId(String type) {
if (TextUtils.equals(type, Phone.APN_TYPE_DEFAULT)) {
return APN_DEFAULT_ID;
} else if (TextUtils.equals(type, Phone.APN_TYPE_MMS)) {
return APN_MMS_ID;
} else if (TextUtils.equals(type, Phone.APN_TYPE_SUPL)) {
return APN_SUPL_ID;
} else if (TextUtils.equals(type, Phone.APN_TYPE_DUN)) {
return APN_DUN_ID;
} else if (TextUtils.equals(type, Phone.APN_TYPE_HIPRI)) {
return APN_HIPRI_ID;
} else {
return APN_INVALID_ID;
}
}
/**
* Ensure that we are connected to an APN of the specified type.
* @param type the APN type (currently the only valid values
* are {@link Phone#APN_TYPE_MMS} and {@link Phone#APN_TYPE_SUPL})
* @return the result of the operation. Success is indicated by
* a return value of either {@code Phone.APN_ALREADY_ACTIVE} or
* {@code Phone.APN_REQUEST_STARTED}. In the latter case, a broadcast
* will be sent by the ConnectivityManager when a connection to
* the APN has been established.
*/
protected int enableApnType(String type) {
int id = apnTypeToId(type);
if (id == APN_INVALID_ID) {
return Phone.APN_REQUEST_FAILED;
}
// If already active, return
if(DBG) Log.d(LOG_TAG, "enableApnType("+type+"), isApnTypeActive = "
+ isApnTypeActive(type) + " and state = " + state);
if (isApnTypeActive(type)) {
if (state == State.INITING) return Phone.APN_REQUEST_STARTED;
else if (state == State.CONNECTED) return Phone.APN_ALREADY_ACTIVE;
}
if (!isApnTypeAvailable(type)) {
return Phone.APN_TYPE_NOT_AVAILABLE;
}
setEnabled(id, true);
mRequestedApnType = type;
sendMessage(obtainMessage(EVENT_ENABLE_NEW_APN));
return Phone.APN_REQUEST_STARTED;
}
/**
* The APN of the specified type is no longer needed. Ensure that if
* use of the default APN has not been explicitly disabled, we are connected
* to the default APN.
* @param type the APN type. The only valid values are currently
* {@link Phone#APN_TYPE_MMS} and {@link Phone#APN_TYPE_SUPL}.
* @return
*/
protected int disableApnType(String type) {
if (DBG) Log.d(LOG_TAG, "disableApnType("+type+")");
int id = apnTypeToId(type);
if (id == APN_INVALID_ID) {
return Phone.APN_REQUEST_FAILED;
}
if (isEnabled(id)) {
setEnabled(id, false);
if (isApnTypeActive(Phone.APN_TYPE_DEFAULT)) {
mRequestedApnType = Phone.APN_TYPE_DEFAULT;
if (dataEnabled[APN_DEFAULT_ID]) {
return Phone.APN_ALREADY_ACTIVE;
} else {
return Phone.APN_REQUEST_STARTED;
}
} else {
return Phone.APN_REQUEST_STARTED;
}
} else {
return Phone.APN_REQUEST_FAILED;
}
}
/**
* The data connection is expected to be setup while device
* 1. has sim card
@@ -439,12 +343,14 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
return true;
}
private boolean isApnTypeActive(String type) {
// TODO: to support simultaneous, mActiveApn can be a List instead.
@Override
protected boolean isApnTypeActive(String type) {
// TODO: support simultaneous with List instead
return mActiveApn != null && mActiveApn.canHandleType(type);
}
private boolean isApnTypeAvailable(String type) {
@Override
protected boolean isApnTypeAvailable(String type) {
if (allApns != null) {
for (ApnSetting apn : allApns) {
if (apn.canHandleType(type)) {
@@ -455,80 +361,6 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
return false;
}
private boolean isEnabled(int id) {
if (id != APN_INVALID_ID) {
return dataEnabled[id];
}
return false;
}
private void setEnabled(int id, boolean enable) {
if (DBG) Log.d(LOG_TAG, "setEnabled(" + id + ", " + enable + ')');
if (dataEnabled[id] != enable) {
dataEnabled[id] = enable;
if (enable) {
enabledCount++;
} else {
enabledCount--;
}
if (enabledCount == 0) {
setPrivateDataEnabled(false);
} else if (enabledCount == 1) {
setPrivateDataEnabled(true);
}
}
}
/**
* Prevent mobile data connections from being established,
* or once again allow mobile data connections. If the state
* toggles, then either tear down or set up data, as
* appropriate to match the new state.
* <p>This operation only affects the default APN, and if the same APN is
* currently being used for MMS traffic, the teardown will not happen
* even when {@code enable} is {@code false}.</p>
* @param enable indicates whether to enable ({@code true}) or disable ({@code false}) data
* @return {@code true} if the operation succeeded
*/
public boolean setDataEnabled(boolean enable) {
if (DBG) Log.d(LOG_TAG, "setDataEnabled("+enable+")");
setEnabled(APN_DEFAULT_ID, enable);
return true;
}
private void setPrivateDataEnabled(boolean enable) {
if (DBG) Log.d(LOG_TAG, "setPrivateDataEnabled("+enable+")");
if (enable) {
sendMessage(obtainMessage(EVENT_TRY_SETUP_DATA));
} else {
Message msg = obtainMessage(EVENT_CLEAN_UP_CONNECTION);
msg.arg1 = 1; // tearDown is true
msg.obj = Phone.REASON_DATA_DISABLED;
sendMessage(msg);
}
}
/**
* Report the current state of data connectivity (enabled or disabled) for
* the default APN.
* @return {@code false} if data connectivity has been explicitly disabled,
* {@code true} otherwise.
*/
public boolean getDataEnabled() {
return dataEnabled[APN_DEFAULT_ID];
}
/**
* Report on whether data connectivity is enabled for any APN.
* @return {@code false} if data connectivity has been explicitly disabled,
* {@code true} otherwise.
*/
public boolean getAnyDataEnabled() {
return (enabledCount != 0);
}
/**
* Formerly this method was ArrayList<PdpConnection> getAllPdps()
*/
@@ -744,7 +576,7 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
return true;
}
String getInterfaceName(String apnType) {
protected String getInterfaceName(String apnType) {
if (mActivePdp != null
&& (apnType == null || mActiveApn.canHandleType(apnType))) {
return mActivePdp.getInterface();
@@ -760,7 +592,7 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
return null;
}
String getGateway(String apnType) {
public String getGateway(String apnType) {
if (mActivePdp != null
&& (apnType == null || mActiveApn.canHandleType(apnType))) {
return mActivePdp.getGatewayAddress();