ConnectivityManager: Add support for bringing up the default APN.
The default APN can now be requested by calling ConnectivityManager.startUsingNetworkFeature(Phone.FEATURE_ENABLE_DEFAULT). Signed-off-by: Mike Lockwood <lockwood@android.com>
This commit is contained in:
@@ -377,6 +377,8 @@ public class MobileDataStateTracker extends NetworkStateTracker {
|
||||
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_DEFAULT)) {
|
||||
return setEnableApn(Phone.APN_TYPE_DEFAULT_FEATURE, true);
|
||||
} else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_SUPL)) {
|
||||
return setEnableApn(Phone.APN_TYPE_SUPL, true);
|
||||
} else {
|
||||
@@ -399,6 +401,8 @@ public class MobileDataStateTracker extends NetworkStateTracker {
|
||||
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_DEFAULT)) {
|
||||
return setEnableApn(Phone.APN_TYPE_DEFAULT_FEATURE, false);
|
||||
} else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_SUPL)) {
|
||||
return setEnableApn(Phone.APN_TYPE_SUPL, false);
|
||||
} else {
|
||||
|
||||
@@ -119,8 +119,11 @@ public interface Phone {
|
||||
static final String APN_TYPE_MMS = "mms";
|
||||
/** APN type for SUPL assisted GPS */
|
||||
static final String APN_TYPE_SUPL = "supl";
|
||||
/** APN type for default data traffic, when requested using startUsingNetworkFeature */
|
||||
static final String APN_TYPE_DEFAULT_FEATURE = "default-feature";
|
||||
|
||||
// "Features" accessible through the connectivity manager
|
||||
static final String FEATURE_ENABLE_DEFAULT = "enableDEFAULT";
|
||||
static final String FEATURE_ENABLE_MMS = "enableMMS";
|
||||
static final String FEATURE_ENABLE_SUPL = "enableSUPL";
|
||||
|
||||
|
||||
@@ -130,7 +130,8 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
|
||||
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_NUM_TYPES = 3;
|
||||
private static int APN_DEFAULT_FEATURE_ID = 3;
|
||||
private static int APN_NUM_TYPES = 4;
|
||||
|
||||
private boolean[] dataEnabled = new boolean[APN_NUM_TYPES];
|
||||
|
||||
@@ -317,7 +318,8 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
|
||||
/**
|
||||
* 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})
|
||||
* are {@link Phone#APN_TYPE_MMS}, {@link Phone#APN_TYPE_SUPL}
|
||||
* and {@link Phone#APN_TYPE_DEFAULT_FEATURE})
|
||||
* @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
|
||||
@@ -325,7 +327,13 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
|
||||
* the APN has been established.
|
||||
*/
|
||||
protected int enableApnType(String type) {
|
||||
if (!TextUtils.equals(type, Phone.APN_TYPE_MMS) &&
|
||||
/* FIXME: APN_TYPE_DEFAULT_FEATURE is used to request the default APN.
|
||||
* Due to the way mRequestedApnType is used, we needed to add
|
||||
* a different APN_TYPE for this rather than using APN_TYPE_DEFAULT.
|
||||
*/
|
||||
|
||||
if (!TextUtils.equals(type, Phone.APN_TYPE_DEFAULT_FEATURE) &&
|
||||
!TextUtils.equals(type, Phone.APN_TYPE_MMS) &&
|
||||
!TextUtils.equals(type, Phone.APN_TYPE_SUPL)) {
|
||||
return Phone.APN_REQUEST_FAILED;
|
||||
}
|
||||
@@ -363,12 +371,14 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
|
||||
* 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}.
|
||||
* {@link Phone#APN_TYPE_MMS} {@link Phone#APN_TYPE_SUPL} and
|
||||
* {@link Phone#APN_TYPE_DEFAULT_FEATURE}).
|
||||
* @return
|
||||
*/
|
||||
protected int disableApnType(String type) {
|
||||
Log.d(LOG_TAG, "disableApnType("+type+")");
|
||||
if ((TextUtils.equals(type, Phone.APN_TYPE_MMS) ||
|
||||
if ((TextUtils.equals(type, Phone.APN_TYPE_DEFAULT_FEATURE) ||
|
||||
TextUtils.equals(type, Phone.APN_TYPE_MMS) ||
|
||||
TextUtils.equals(type, Phone.APN_TYPE_SUPL))
|
||||
&& isEnabled(type)) {
|
||||
removeMessages(EVENT_RESTORE_DEFAULT_APN);
|
||||
@@ -419,6 +429,9 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
|
||||
|
||||
private boolean isApnTypeActive(String type) {
|
||||
// TODO: to support simultaneous, mActiveApn can be a List instead.
|
||||
if (TextUtils.equals(type, Phone.APN_TYPE_DEFAULT_FEATURE)) {
|
||||
type = Phone.APN_TYPE_DEFAULT;
|
||||
}
|
||||
return mActiveApn != null && mActiveApn.canHandleType(type);
|
||||
}
|
||||
|
||||
@@ -440,6 +453,8 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
|
||||
return dataEnabled[APN_MMS_ID];
|
||||
} else if (TextUtils.equals(apnType, Phone.APN_TYPE_SUPL)) {
|
||||
return dataEnabled[APN_SUPL_ID];
|
||||
} else if (TextUtils.equals(apnType, Phone.APN_TYPE_DEFAULT_FEATURE)) {
|
||||
return dataEnabled[APN_DEFAULT_FEATURE_ID];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -453,10 +468,13 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
|
||||
dataEnabled[APN_MMS_ID] = enable;
|
||||
} else if (TextUtils.equals(apnType, Phone.APN_TYPE_SUPL)) {
|
||||
dataEnabled[APN_SUPL_ID] = enable;
|
||||
} else if (TextUtils.equals(apnType, Phone.APN_TYPE_DEFAULT_FEATURE)) {
|
||||
dataEnabled[APN_DEFAULT_FEATURE_ID] = enable;
|
||||
}
|
||||
Log.d(LOG_TAG, "dataEnabled[DEFAULT_APN]=" + dataEnabled[APN_DEFAULT_ID] +
|
||||
" dataEnabled[MMS_APN]=" + dataEnabled[APN_MMS_ID] +
|
||||
" dataEnabled[SUPL_APN]=" + dataEnabled[APN_SUPL_ID]);
|
||||
" dataEnabled[SUPL_APN]=" + dataEnabled[APN_SUPL_ID] +
|
||||
" dataEnabled[APN_DEFAULT_FEATURE_ID]=" + dataEnabled[APN_DEFAULT_FEATURE_ID]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -484,7 +502,9 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
|
||||
// Don't tear down if there is an active APN and it handles MMS or SUPL.
|
||||
// TODO: This isn't very general.
|
||||
if ((isApnTypeActive(Phone.APN_TYPE_MMS) && isEnabled(Phone.APN_TYPE_MMS)) ||
|
||||
(isApnTypeActive(Phone.APN_TYPE_SUPL) && isEnabled(Phone.APN_TYPE_SUPL))) {
|
||||
(isApnTypeActive(Phone.APN_TYPE_SUPL) && isEnabled(Phone.APN_TYPE_SUPL)) ||
|
||||
(isApnTypeActive(Phone.APN_TYPE_DEFAULT_FEATURE) &&
|
||||
isEnabled(Phone.APN_TYPE_DEFAULT_FEATURE))) {
|
||||
return false;
|
||||
}
|
||||
Message msg = obtainMessage(EVENT_CLEAN_UP_CONNECTION);
|
||||
@@ -514,7 +534,8 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
|
||||
* {@code true} otherwise.
|
||||
*/
|
||||
public boolean getAnyDataEnabled() {
|
||||
return dataEnabled[APN_DEFAULT_ID] || dataEnabled[APN_MMS_ID] || dataEnabled[APN_SUPL_ID];
|
||||
return dataEnabled[APN_DEFAULT_ID] || dataEnabled[APN_MMS_ID] ||
|
||||
dataEnabled[APN_SUPL_ID] || dataEnabled[APN_DEFAULT_FEATURE_ID];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1289,7 +1310,8 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
|
||||
* rather an app that inadvertantly fails to reset to the
|
||||
* default APN, or that dies before doing so.
|
||||
*/
|
||||
if (dataEnabled[APN_MMS_ID] || dataEnabled[APN_SUPL_ID]) {
|
||||
if (dataEnabled[APN_MMS_ID] || dataEnabled[APN_SUPL_ID] ||
|
||||
dataEnabled[APN_DEFAULT_FEATURE_ID]) {
|
||||
removeMessages(EVENT_RESTORE_DEFAULT_APN);
|
||||
sendMessageDelayed(obtainMessage(EVENT_RESTORE_DEFAULT_APN),
|
||||
getRestoreDefaultApnDelay());
|
||||
|
||||
Reference in New Issue
Block a user