Merge "Refactored DataProfile and ApnSetting" am: bcafa9a7b1 am: 0ffc04a539 am: 026856ae7a

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1883556

Change-Id: I863da96487553b7c276801a8e58b5e06aa90905d
This commit is contained in:
Treehugger Robot
2021-11-06 06:15:30 +00:00
committed by Automerger Merge Worker
2 changed files with 462 additions and 624 deletions

View File

@@ -147,7 +147,12 @@ public class ApnSetting implements Parcelable {
} }
// Possible values for authentication types. // Possible values for authentication types.
/** No authentication type. */ /**
* Authentication type is unknown.
* @hide
*/
public static final int AUTH_TYPE_UNKNOWN = -1;
/** Authentication is not required. */
public static final int AUTH_TYPE_NONE = 0; public static final int AUTH_TYPE_NONE = 0;
/** Authentication type for PAP. */ /** Authentication type for PAP. */
public static final int AUTH_TYPE_PAP = 1; public static final int AUTH_TYPE_PAP = 1;
@@ -357,6 +362,7 @@ public class ApnSetting implements Parcelable {
/** @hide */ /** @hide */
@IntDef(prefix = { "AUTH_TYPE_" }, value = { @IntDef(prefix = { "AUTH_TYPE_" }, value = {
AUTH_TYPE_UNKNOWN,
AUTH_TYPE_NONE, AUTH_TYPE_NONE,
AUTH_TYPE_PAP, AUTH_TYPE_PAP,
AUTH_TYPE_CHAP, AUTH_TYPE_CHAP,
@@ -498,7 +504,8 @@ public class ApnSetting implements Parcelable {
private final String mOperatorNumeric; private final String mOperatorNumeric;
private final int mProtocol; private final int mProtocol;
private final int mRoamingProtocol; private final int mRoamingProtocol;
private final int mMtu; private final int mMtuV4;
private final int mMtuV6;
private final boolean mCarrierEnabled; private final boolean mCarrierEnabled;
@@ -522,13 +529,25 @@ public class ApnSetting implements Parcelable {
private final int mSkip464Xlat; private final int mSkip464Xlat;
/** /**
* Returns the MTU size of the mobile interface to which the APN connected. * Returns the MTU size of the IPv4 mobile interface to which the APN connected. Note this value
* is used only if MTU size is not provided in {@link DataCallResponse}.
* *
* @return the MTU size of the APN * @return the MTU size of the APN
* @hide * @hide
*/ */
public int getMtu() { public int getMtuV4() {
return mMtu; return mMtuV4;
}
/**
* Returns the MTU size of the IPv6 mobile interface to which the APN connected. Note this value
* is used only if MTU size is not provided in {@link DataCallResponse}.
*
* @return the MTU size of the APN
* @hide
*/
public int getMtuV6() {
return mMtuV6;
} }
/** /**
@@ -879,13 +898,18 @@ public class ApnSetting implements Parcelable {
this.mMmsProxyPort = builder.mMmsProxyPort; this.mMmsProxyPort = builder.mMmsProxyPort;
this.mUser = builder.mUser; this.mUser = builder.mUser;
this.mPassword = builder.mPassword; this.mPassword = builder.mPassword;
this.mAuthType = builder.mAuthType; this.mAuthType = (builder.mAuthType != AUTH_TYPE_UNKNOWN)
? builder.mAuthType
: TextUtils.isEmpty(builder.mUser)
? AUTH_TYPE_NONE
: AUTH_TYPE_PAP_OR_CHAP;
this.mApnTypeBitmask = builder.mApnTypeBitmask; this.mApnTypeBitmask = builder.mApnTypeBitmask;
this.mId = builder.mId; this.mId = builder.mId;
this.mOperatorNumeric = builder.mOperatorNumeric; this.mOperatorNumeric = builder.mOperatorNumeric;
this.mProtocol = builder.mProtocol; this.mProtocol = builder.mProtocol;
this.mRoamingProtocol = builder.mRoamingProtocol; this.mRoamingProtocol = builder.mRoamingProtocol;
this.mMtu = builder.mMtu; this.mMtuV4 = builder.mMtuV4;
this.mMtuV6 = builder.mMtuV6;
this.mCarrierEnabled = builder.mCarrierEnabled; this.mCarrierEnabled = builder.mCarrierEnabled;
this.mNetworkTypeBitmask = builder.mNetworkTypeBitmask; this.mNetworkTypeBitmask = builder.mNetworkTypeBitmask;
this.mProfileId = builder.mProfileId; this.mProfileId = builder.mProfileId;
@@ -900,66 +924,6 @@ public class ApnSetting implements Parcelable {
this.mSkip464Xlat = builder.mSkip464Xlat; this.mSkip464Xlat = builder.mSkip464Xlat;
} }
/**
* @hide
*/
public static ApnSetting makeApnSetting(int id, String operatorNumeric, String entryName,
String apnName, String proxyAddress, int proxyPort, Uri mmsc,
String mmsProxyAddress, int mmsProxyPort, String user, String password,
int authType, int mApnTypeBitmask, int protocol, int roamingProtocol,
boolean carrierEnabled, int networkTypeBitmask, int profileId,
boolean modemCognitive, int maxConns, int waitTime, int maxConnsTime, int mtu,
int mvnoType, String mvnoMatchData, int apnSetId, int carrierId, int skip464xlat) {
return new Builder()
.setId(id)
.setOperatorNumeric(operatorNumeric)
.setEntryName(entryName)
.setApnName(apnName)
.setProxyAddress(proxyAddress)
.setProxyPort(proxyPort)
.setMmsc(mmsc)
.setMmsProxyAddress(mmsProxyAddress)
.setMmsProxyPort(mmsProxyPort)
.setUser(user)
.setPassword(password)
.setAuthType(authType)
.setApnTypeBitmask(mApnTypeBitmask)
.setProtocol(protocol)
.setRoamingProtocol(roamingProtocol)
.setCarrierEnabled(carrierEnabled)
.setNetworkTypeBitmask(networkTypeBitmask)
.setProfileId(profileId)
.setModemCognitive(modemCognitive)
.setMaxConns(maxConns)
.setWaitTime(waitTime)
.setMaxConnsTime(maxConnsTime)
.setMtu(mtu)
.setMvnoType(mvnoType)
.setMvnoMatchData(mvnoMatchData)
.setApnSetId(apnSetId)
.setCarrierId(carrierId)
.setSkip464Xlat(skip464xlat)
.buildWithoutCheck();
}
/**
* @hide
*/
public static ApnSetting makeApnSetting(int id, String operatorNumeric, String entryName,
String apnName, String proxyAddress, int proxyPort, Uri mmsc,
String mmsProxyAddress, int mmsProxyPort, String user, String password,
int authType, int mApnTypeBitmask, int protocol, int roamingProtocol,
boolean carrierEnabled, int networkTypeBitmask, int profileId, boolean modemCognitive,
int maxConns, int waitTime, int maxConnsTime, int mtu, int mvnoType,
String mvnoMatchData) {
return makeApnSetting(id, operatorNumeric, entryName, apnName, proxyAddress, proxyPort,
mmsc, mmsProxyAddress, mmsProxyPort, user, password, authType, mApnTypeBitmask,
protocol, roamingProtocol, carrierEnabled, networkTypeBitmask, profileId,
modemCognitive, maxConns, waitTime, maxConnsTime, mtu, mvnoType, mvnoMatchData,
Carriers.NO_APN_SET_ID, TelephonyManager.UNKNOWN_CARRIER_ID,
Carriers.SKIP_464XLAT_DEFAULT);
}
/** /**
* @hide * @hide
*/ */
@@ -975,272 +939,99 @@ public class ApnSetting implements Parcelable {
ServiceState.convertBearerBitmaskToNetworkTypeBitmask(bearerBitmask); ServiceState.convertBearerBitmaskToNetworkTypeBitmask(bearerBitmask);
} }
return makeApnSetting( return new Builder()
cursor.getInt(cursor.getColumnIndexOrThrow(Telephony.Carriers._ID)), .setId(cursor.getInt(cursor.getColumnIndexOrThrow(Telephony.Carriers._ID)))
cursor.getString(cursor.getColumnIndexOrThrow(Telephony.Carriers.NUMERIC)), .setOperatorNumeric(cursor.getString(
cursor.getString(cursor.getColumnIndexOrThrow(Telephony.Carriers.NAME)), cursor.getColumnIndexOrThrow(Telephony.Carriers.NUMERIC)))
cursor.getString(cursor.getColumnIndexOrThrow(Telephony.Carriers.APN)), .setEntryName(cursor.getString(
cursor.getString( cursor.getColumnIndexOrThrow(Telephony.Carriers.NAME)))
cursor.getColumnIndexOrThrow(Telephony.Carriers.PROXY)), .setApnName(cursor.getString(cursor.getColumnIndexOrThrow(Telephony.Carriers.APN)))
portFromString(cursor.getString( .setProxyAddress(cursor.getString(
cursor.getColumnIndexOrThrow(Telephony.Carriers.PORT))), cursor.getColumnIndexOrThrow(Telephony.Carriers.PROXY)))
UriFromString(cursor.getString( .setProxyPort(portFromString(cursor.getString(
cursor.getColumnIndexOrThrow(Telephony.Carriers.MMSC))), cursor.getColumnIndexOrThrow(Telephony.Carriers.PORT))))
cursor.getString( .setMmsc(UriFromString(cursor.getString(
cursor.getColumnIndexOrThrow(Telephony.Carriers.MMSPROXY)), cursor.getColumnIndexOrThrow(Telephony.Carriers.MMSC))))
portFromString(cursor.getString( .setMmsProxyAddress(cursor.getString(
cursor.getColumnIndexOrThrow(Telephony.Carriers.MMSPORT))), cursor.getColumnIndexOrThrow(Telephony.Carriers.MMSPROXY)))
cursor.getString(cursor.getColumnIndexOrThrow(Telephony.Carriers.USER)), .setMmsProxyPort(portFromString(cursor.getString(
cursor.getString(cursor.getColumnIndexOrThrow(Telephony.Carriers.PASSWORD)), cursor.getColumnIndexOrThrow(Telephony.Carriers.MMSPORT))))
cursor.getInt(cursor.getColumnIndexOrThrow(Telephony.Carriers.AUTH_TYPE)), .setUser(cursor.getString(
apnTypesBitmask, cursor.getColumnIndexOrThrow(Telephony.Carriers.USER)))
getProtocolIntFromString( .setPassword(cursor.getString(
cursor.getString(cursor.getColumnIndexOrThrow(Telephony.Carriers.PROTOCOL))), cursor.getColumnIndexOrThrow(Telephony.Carriers.PASSWORD)))
getProtocolIntFromString( .setAuthType(cursor.getInt(
cursor.getString(cursor.getColumnIndexOrThrow( cursor.getColumnIndexOrThrow(Telephony.Carriers.AUTH_TYPE)))
Telephony.Carriers.ROAMING_PROTOCOL))), .setApnTypeBitmask(apnTypesBitmask)
cursor.getInt(cursor.getColumnIndexOrThrow( .setProtocol(getProtocolIntFromString(
Telephony.Carriers.CARRIER_ENABLED)) == 1, cursor.getString(
networkTypeBitmask, cursor.getColumnIndexOrThrow(Telephony.Carriers.PROTOCOL))))
cursor.getInt(cursor.getColumnIndexOrThrow(Telephony.Carriers.PROFILE_ID)), .setRoamingProtocol(getProtocolIntFromString(
cursor.getInt(cursor.getColumnIndexOrThrow( cursor.getString(cursor.getColumnIndexOrThrow(
Telephony.Carriers.MODEM_PERSIST)) == 1, Telephony.Carriers.ROAMING_PROTOCOL))))
cursor.getInt(cursor.getColumnIndexOrThrow(Telephony.Carriers.MAX_CONNECTIONS)), .setCarrierEnabled(cursor.getInt(cursor.getColumnIndexOrThrow(
cursor.getInt(cursor.getColumnIndexOrThrow(Telephony.Carriers.WAIT_TIME_RETRY)), Telephony.Carriers.CARRIER_ENABLED)) == 1)
cursor.getInt(cursor.getColumnIndexOrThrow( .setNetworkTypeBitmask(networkTypeBitmask)
Telephony.Carriers.TIME_LIMIT_FOR_MAX_CONNECTIONS)), .setProfileId(cursor.getInt(
cursor.getInt(cursor.getColumnIndexOrThrow(Telephony.Carriers.MTU)), cursor.getColumnIndexOrThrow(Telephony.Carriers.PROFILE_ID)))
getMvnoTypeIntFromString( .setModemCognitive(cursor.getInt(cursor.getColumnIndexOrThrow(
cursor.getString(cursor.getColumnIndexOrThrow( Telephony.Carriers.MODEM_PERSIST)) == 1)
Telephony.Carriers.MVNO_TYPE))), .setMaxConns(cursor.getInt(
cursor.getString(cursor.getColumnIndexOrThrow( cursor.getColumnIndexOrThrow(Telephony.Carriers.MAX_CONNECTIONS)))
Telephony.Carriers.MVNO_MATCH_DATA)), .setWaitTime(cursor.getInt(
cursor.getInt(cursor.getColumnIndexOrThrow(Telephony.Carriers.APN_SET_ID)), cursor.getColumnIndexOrThrow(Telephony.Carriers.WAIT_TIME_RETRY)))
cursor.getInt(cursor.getColumnIndexOrThrow(Telephony.Carriers.CARRIER_ID)), .setMaxConnsTime(cursor.getInt(cursor.getColumnIndexOrThrow(
cursor.getInt(cursor.getColumnIndexOrThrow(Carriers.SKIP_464XLAT))); Telephony.Carriers.TIME_LIMIT_FOR_MAX_CONNECTIONS)))
.setMtuV4(cursor.getInt(cursor.getColumnIndexOrThrow(Telephony.Carriers.MTU)))
.setMtuV6(UNSET_MTU) // TODO: Add corresponding support in telephony provider
.setMvnoType(getMvnoTypeIntFromString(
cursor.getString(cursor.getColumnIndexOrThrow(
Telephony.Carriers.MVNO_TYPE))))
.setMvnoMatchData(cursor.getString(cursor.getColumnIndexOrThrow(
Telephony.Carriers.MVNO_MATCH_DATA)))
.setApnSetId(cursor.getInt(
cursor.getColumnIndexOrThrow(Telephony.Carriers.APN_SET_ID)))
.setCarrierId(cursor.getInt(
cursor.getColumnIndexOrThrow(Telephony.Carriers.CARRIER_ID)))
.setSkip464Xlat(cursor.getInt(cursor.getColumnIndexOrThrow(Carriers.SKIP_464XLAT)))
.buildWithoutCheck();
} }
/** /**
* @hide * @hide
*/ */
public static ApnSetting makeApnSetting(ApnSetting apn) { public static ApnSetting makeApnSetting(ApnSetting apn) {
return makeApnSetting(apn.mId, apn.mOperatorNumeric, apn.mEntryName, apn.mApnName, return new Builder()
apn.mProxyAddress, apn.mProxyPort, apn.mMmsc, apn.mMmsProxyAddress, .setId(apn.mId)
apn.mMmsProxyPort, apn.mUser, apn.mPassword, apn.mAuthType, apn.mApnTypeBitmask, .setOperatorNumeric(apn.mOperatorNumeric)
apn.mProtocol, apn.mRoamingProtocol, apn.mCarrierEnabled, apn.mNetworkTypeBitmask, .setEntryName(apn.mEntryName)
apn.mProfileId, apn.mPersistent, apn.mMaxConns, apn.mWaitTime, .setApnName(apn.mApnName)
apn.mMaxConnsTime, apn.mMtu, apn.mMvnoType, apn.mMvnoMatchData, apn.mApnSetId, .setProxyAddress(apn.mProxyAddress)
apn.mCarrierId, apn.mSkip464Xlat); .setProxyPort(apn.mProxyPort)
} .setMmsc(apn.mMmsc)
.setMmsProxyAddress(apn.mMmsProxyAddress)
/** .setMmsProxyPort(apn.mMmsProxyPort)
* Creates an ApnSetting object from a string. .setUser(apn.mUser)
* .setPassword(apn.mPassword)
* @param data the string to read. .setAuthType(apn.mAuthType)
* .setApnTypeBitmask(apn.mApnTypeBitmask)
* The string must be in one of two formats (newlines added for clarity, .setProtocol(apn.mProtocol)
* spaces are optional): .setRoamingProtocol(apn.mRoamingProtocol)
* .setCarrierEnabled(apn.mCarrierEnabled)
* v1 format: .setNetworkTypeBitmask(apn.mNetworkTypeBitmask)
* <carrier>, <apn>, <proxy>, <port>, <user>, <password>, <server>, .setProfileId(apn.mProfileId)
* <mmsc>, <mmsproxy>, <mmsport>, <mcc>, <mnc>, <authtype>, .setModemCognitive(apn.mPersistent)
* <type>[| <type>...], .setMaxConns(apn.mMaxConns)
* .setWaitTime(apn.mWaitTime)
* v2 format: .setMaxConnsTime(apn.mMaxConnsTime)
* [ApnSettingV2] <carrier>, <apn>, <proxy>, <port>, <user>, <password>, <server>, .setMtuV4(apn.mMtuV4)
* <mmsc>, <mmsproxy>, <mmsport>, <mcc>, <mnc>, <authtype>, .setMtuV6(apn.mMtuV6)
* <type>[| <type>...], <protocol>, <roaming_protocol>, <carrierEnabled>, <bearerBitmask>, .setMvnoType(apn.mMvnoType)
* .setMvnoMatchData(apn.mMvnoMatchData)
* v3 format: .setApnSetId(apn.mApnSetId)
* [ApnSettingV3] <carrier>, <apn>, <proxy>, <port>, <user>, <password>, <server>, .setCarrierId(apn.mCarrierId)
* <mmsc>, <mmsproxy>, <mmsport>, <mcc>, <mnc>, <authtype>, .setSkip464Xlat(apn.mSkip464Xlat)
* <type>[| <type>...], <protocol>, <roaming_protocol>, <carrierEnabled>, <bearerBitmask>, .buildWithoutCheck();
* <profileId>, <modemCognitive>, <maxConns>, <waitTime>, <maxConnsTime>, <mtu>,
* <mvnoType>, <mvnoMatchData>
*
* v4 format:
* [ApnSettingV4] <carrier>, <apn>, <proxy>, <port>, <user>, <password>, <server>,
* <mmsc>, <mmsproxy>, <mmsport>, <mcc>, <mnc>, <authtype>,
* <type>[| <type>...], <protocol>, <roaming_protocol>, <carrierEnabled>, <bearerBitmask>,
* <profileId>, <modemCognitive>, <maxConns>, <waitTime>, <maxConnsTime>, <mtu>,
* <mvnoType>, <mvnoMatchData>, <networkTypeBitmask>
*
* v5 format:
* [ApnSettingV5] <carrier>, <apn>, <proxy>, <port>, <user>, <password>, <server>,
* <mmsc>, <mmsproxy>, <mmsport>, <mcc>, <mnc>, <authtype>,
* <type>[| <type>...], <protocol>, <roaming_protocol>, <carrierEnabled>, <bearerBitmask>,
* <profileId>, <modemCognitive>, <maxConns>, <waitTime>, <maxConnsTime>, <mtu>,
* <mvnoType>, <mvnoMatchData>, <networkTypeBitmask>, <apnSetId>
*
* v6 format:
* [ApnSettingV6] <carrier>, <apn>, <proxy>, <port>, <user>, <password>, <server>,
* <mmsc>, <mmsproxy>, <mmsport>, <mcc>, <mnc>, <authtype>,
* <type>[| <type>...], <protocol>, <roaming_protocol>, <carrierEnabled>, <bearerBitmask>,
* <profileId>, <modemCognitive>, <maxConns>, <waitTime>, <maxConnsTime>, <mtu>,
* <mvnoType>, <mvnoMatchData>, <networkTypeBitmask>, <apnSetId>, <carrierId>
*
* v7 format:
* [ApnSettingV7] <carrier>, <apn>, <proxy>, <port>, <user>, <password>, <server>,
* <mmsc>, <mmsproxy>, <mmsport>, <mcc>, <mnc>, <authtype>,
* <type>[| <type>...], <protocol>, <roaming_protocol>, <carrierEnabled>, <bearerBitmask>,
* <profileId>, <modemCognitive>, <maxConns>, <waitTime>, <maxConnsTime>, <mtu>,
* <mvnoType>, <mvnoMatchData>, <networkTypeBitmask>, <apnSetId>, <carrierId>, <skip464xlat>
*
* Note that the strings generated by {@link #toString()} do not contain the username
* and password and thus cannot be read by this method.
*
* This method may return {@code null} if the input string is invalid.
*
* @hide
*/
public static ApnSetting fromString(String data) {
if (data == null) return null;
int version;
// matches() operates on the whole string, so append .* to the regex.
if (data.matches(V7_FORMAT_REGEX + ".*")) {
version = 7;
data = data.replaceFirst(V7_FORMAT_REGEX, "");
} else if (data.matches(V6_FORMAT_REGEX + ".*")) {
version = 6;
data = data.replaceFirst(V6_FORMAT_REGEX, "");
} else if (data.matches(V5_FORMAT_REGEX + ".*")) {
version = 5;
data = data.replaceFirst(V5_FORMAT_REGEX, "");
} else if (data.matches(V4_FORMAT_REGEX + ".*")) {
version = 4;
data = data.replaceFirst(V4_FORMAT_REGEX, "");
} else if (data.matches(V3_FORMAT_REGEX + ".*")) {
version = 3;
data = data.replaceFirst(V3_FORMAT_REGEX, "");
} else if (data.matches(V2_FORMAT_REGEX + ".*")) {
version = 2;
data = data.replaceFirst(V2_FORMAT_REGEX, "");
} else {
version = 1;
}
String[] a = data.split("\\s*,\\s*", -1);
if (a.length < 14) {
return null;
}
int authType;
try {
authType = Integer.parseInt(a[12]);
} catch (NumberFormatException e) {
authType = 0;
}
String[] typeArray;
String protocol, roamingProtocol;
boolean carrierEnabled;
int bearerBitmask = 0;
int networkTypeBitmask = 0;
int profileId = 0;
boolean modemCognitive = false;
int maxConns = 0;
int waitTime = 0;
int maxConnsTime = 0;
int mtu = UNSET_MTU;
String mvnoType = "";
String mvnoMatchData = "";
int apnSetId = Carriers.NO_APN_SET_ID;
int carrierId = TelephonyManager.UNKNOWN_CARRIER_ID;
int skip464xlat = Carriers.SKIP_464XLAT_DEFAULT;
if (version == 1) {
typeArray = new String[a.length - 13];
System.arraycopy(a, 13, typeArray, 0, a.length - 13);
protocol = PROTOCOL_INT_MAP.get(PROTOCOL_IP);
roamingProtocol = PROTOCOL_INT_MAP.get(PROTOCOL_IP);
carrierEnabled = true;
} else {
if (a.length < 18) {
return null;
}
typeArray = a[13].split("\\s*\\|\\s*");
protocol = a[14];
roamingProtocol = a[15];
carrierEnabled = Boolean.parseBoolean(a[16]);
bearerBitmask = ServiceState.getBitmaskFromString(a[17]);
if (a.length > 22) {
modemCognitive = Boolean.parseBoolean(a[19]);
try {
profileId = Integer.parseInt(a[18]);
maxConns = Integer.parseInt(a[20]);
waitTime = Integer.parseInt(a[21]);
maxConnsTime = Integer.parseInt(a[22]);
} catch (NumberFormatException e) {
}
}
if (a.length > 23) {
try {
mtu = Integer.parseInt(a[23]);
} catch (NumberFormatException e) {
}
}
if (a.length > 25) {
mvnoType = a[24];
mvnoMatchData = a[25];
}
if (a.length > 26) {
networkTypeBitmask = ServiceState.getBitmaskFromString(a[26]);
}
if (a.length > 27) {
apnSetId = Integer.parseInt(a[27]);
}
if (a.length > 28) {
carrierId = Integer.parseInt(a[28]);
}
if (a.length > 29) {
try {
skip464xlat = Integer.parseInt(a[29]);
} catch (NumberFormatException e) {
}
}
}
// If both bearerBitmask and networkTypeBitmask were specified, bearerBitmask would be
// ignored.
if (networkTypeBitmask == 0) {
networkTypeBitmask =
ServiceState.convertBearerBitmaskToNetworkTypeBitmask(bearerBitmask);
}
return makeApnSetting(-1, a[10] + a[11], a[0], a[1], a[2],
portFromString(a[3]), UriFromString(a[7]), a[8],
portFromString(a[9]), a[4], a[5], authType,
getApnTypesBitmaskFromString(TextUtils.join(",", typeArray)),
getProtocolIntFromString(protocol), getProtocolIntFromString(roamingProtocol),
carrierEnabled, networkTypeBitmask, profileId, modemCognitive, maxConns, waitTime,
maxConnsTime, mtu, getMvnoTypeIntFromString(mvnoType), mvnoMatchData, apnSetId,
carrierId, skip464xlat);
}
/**
* Creates an array of ApnSetting objects from a string.
*
* @param data the string to read.
*
* Builds on top of the same format used by fromString, but allows for multiple entries
* separated by ";".
*
* @hide
*/
public static List<ApnSetting> arrayFromString(String data) {
List<ApnSetting> retVal = new ArrayList<ApnSetting>();
if (TextUtils.isEmpty(data)) {
return retVal;
}
String[] apnStrings = data.split("\\s*;\\s*");
for (String apnString : apnStrings) {
ApnSetting apn = fromString(apnString);
if (apn != null) {
retVal.add(apn);
}
}
return retVal;
} }
/** /**
@@ -1251,7 +1042,7 @@ public class ApnSetting implements Parcelable {
*/ */
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("[ApnSettingV7] ") sb.append("[ApnSetting] ")
.append(mEntryName) .append(mEntryName)
.append(", ").append(mId) .append(", ").append(mId)
.append(", ").append(mOperatorNumeric) .append(", ").append(mOperatorNumeric)
@@ -1272,7 +1063,8 @@ public class ApnSetting implements Parcelable {
sb.append(", ").append(mMaxConns); sb.append(", ").append(mMaxConns);
sb.append(", ").append(mWaitTime); sb.append(", ").append(mWaitTime);
sb.append(", ").append(mMaxConnsTime); sb.append(", ").append(mMaxConnsTime);
sb.append(", ").append(mMtu); sb.append(", ").append(mMtuV4);
sb.append(", ").append(mMtuV6);
sb.append(", ").append(MVNO_TYPE_INT_MAP.get(mMvnoType)); sb.append(", ").append(MVNO_TYPE_INT_MAP.get(mMvnoType));
sb.append(", ").append(mMvnoMatchData); sb.append(", ").append(mMvnoMatchData);
sb.append(", ").append(mPermanentFailed); sb.append(", ").append(mPermanentFailed);
@@ -1343,9 +1135,9 @@ public class ApnSetting implements Parcelable {
public int hashCode() { public int hashCode() {
return Objects.hash(mApnName, mProxyAddress, mProxyPort, mMmsc, mMmsProxyAddress, return Objects.hash(mApnName, mProxyAddress, mProxyPort, mMmsc, mMmsProxyAddress,
mMmsProxyPort, mUser, mPassword, mAuthType, mApnTypeBitmask, mId, mOperatorNumeric, mMmsProxyPort, mUser, mPassword, mAuthType, mApnTypeBitmask, mId, mOperatorNumeric,
mProtocol, mRoamingProtocol, mMtu, mCarrierEnabled, mNetworkTypeBitmask, mProfileId, mProtocol, mRoamingProtocol, mMtuV4, mMtuV6, mCarrierEnabled, mNetworkTypeBitmask,
mPersistent, mMaxConns, mWaitTime, mMaxConnsTime, mMvnoType, mMvnoMatchData, mProfileId, mPersistent, mMaxConns, mWaitTime, mMaxConnsTime, mMvnoType,
mApnSetId, mCarrierId, mSkip464Xlat); mMvnoMatchData, mApnSetId, mCarrierId, mSkip464Xlat);
} }
@Override @Override
@@ -1357,33 +1149,34 @@ public class ApnSetting implements Parcelable {
ApnSetting other = (ApnSetting) o; ApnSetting other = (ApnSetting) o;
return mEntryName.equals(other.mEntryName) return mEntryName.equals(other.mEntryName)
&& Objects.equals(mId, other.mId) && Objects.equals(mId, other.mId)
&& Objects.equals(mOperatorNumeric, other.mOperatorNumeric) && Objects.equals(mOperatorNumeric, other.mOperatorNumeric)
&& Objects.equals(mApnName, other.mApnName) && Objects.equals(mApnName, other.mApnName)
&& Objects.equals(mProxyAddress, other.mProxyAddress) && Objects.equals(mProxyAddress, other.mProxyAddress)
&& Objects.equals(mMmsc, other.mMmsc) && Objects.equals(mMmsc, other.mMmsc)
&& Objects.equals(mMmsProxyAddress, other.mMmsProxyAddress) && Objects.equals(mMmsProxyAddress, other.mMmsProxyAddress)
&& Objects.equals(mMmsProxyPort, other.mMmsProxyPort) && Objects.equals(mMmsProxyPort, other.mMmsProxyPort)
&& Objects.equals(mProxyPort, other.mProxyPort) && Objects.equals(mProxyPort, other.mProxyPort)
&& Objects.equals(mUser, other.mUser) && Objects.equals(mUser, other.mUser)
&& Objects.equals(mPassword, other.mPassword) && Objects.equals(mPassword, other.mPassword)
&& Objects.equals(mAuthType, other.mAuthType) && Objects.equals(mAuthType, other.mAuthType)
&& Objects.equals(mApnTypeBitmask, other.mApnTypeBitmask) && Objects.equals(mApnTypeBitmask, other.mApnTypeBitmask)
&& Objects.equals(mProtocol, other.mProtocol) && Objects.equals(mProtocol, other.mProtocol)
&& Objects.equals(mRoamingProtocol, other.mRoamingProtocol) && Objects.equals(mRoamingProtocol, other.mRoamingProtocol)
&& Objects.equals(mCarrierEnabled, other.mCarrierEnabled) && Objects.equals(mCarrierEnabled, other.mCarrierEnabled)
&& Objects.equals(mProfileId, other.mProfileId) && Objects.equals(mProfileId, other.mProfileId)
&& Objects.equals(mPersistent, other.mPersistent) && Objects.equals(mPersistent, other.mPersistent)
&& Objects.equals(mMaxConns, other.mMaxConns) && Objects.equals(mMaxConns, other.mMaxConns)
&& Objects.equals(mWaitTime, other.mWaitTime) && Objects.equals(mWaitTime, other.mWaitTime)
&& Objects.equals(mMaxConnsTime, other.mMaxConnsTime) && Objects.equals(mMaxConnsTime, other.mMaxConnsTime)
&& Objects.equals(mMtu, other.mMtu) && Objects.equals(mMtuV4, other.mMtuV4)
&& Objects.equals(mMvnoType, other.mMvnoType) && Objects.equals(mMtuV6, other.mMtuV6)
&& Objects.equals(mMvnoMatchData, other.mMvnoMatchData) && Objects.equals(mMvnoType, other.mMvnoType)
&& Objects.equals(mNetworkTypeBitmask, other.mNetworkTypeBitmask) && Objects.equals(mMvnoMatchData, other.mMvnoMatchData)
&& Objects.equals(mApnSetId, other.mApnSetId) && Objects.equals(mNetworkTypeBitmask, other.mNetworkTypeBitmask)
&& Objects.equals(mCarrierId, other.mCarrierId) && Objects.equals(mApnSetId, other.mApnSetId)
&& Objects.equals(mSkip464Xlat, other.mSkip464Xlat); && Objects.equals(mCarrierId, other.mCarrierId)
&& Objects.equals(mSkip464Xlat, other.mSkip464Xlat);
} }
/** /**
@@ -1406,31 +1199,32 @@ public class ApnSetting implements Parcelable {
ApnSetting other = (ApnSetting) o; ApnSetting other = (ApnSetting) o;
return mEntryName.equals(other.mEntryName) return mEntryName.equals(other.mEntryName)
&& Objects.equals(mOperatorNumeric, other.mOperatorNumeric) && Objects.equals(mOperatorNumeric, other.mOperatorNumeric)
&& Objects.equals(mApnName, other.mApnName) && Objects.equals(mApnName, other.mApnName)
&& Objects.equals(mProxyAddress, other.mProxyAddress) && Objects.equals(mProxyAddress, other.mProxyAddress)
&& Objects.equals(mMmsc, other.mMmsc) && Objects.equals(mMmsc, other.mMmsc)
&& Objects.equals(mMmsProxyAddress, other.mMmsProxyAddress) && Objects.equals(mMmsProxyAddress, other.mMmsProxyAddress)
&& Objects.equals(mMmsProxyPort, other.mMmsProxyPort) && Objects.equals(mMmsProxyPort, other.mMmsProxyPort)
&& Objects.equals(mProxyPort, other.mProxyPort) && Objects.equals(mProxyPort, other.mProxyPort)
&& Objects.equals(mUser, other.mUser) && Objects.equals(mUser, other.mUser)
&& Objects.equals(mPassword, other.mPassword) && Objects.equals(mPassword, other.mPassword)
&& Objects.equals(mAuthType, other.mAuthType) && Objects.equals(mAuthType, other.mAuthType)
&& Objects.equals(mApnTypeBitmask, other.mApnTypeBitmask) && Objects.equals(mApnTypeBitmask, other.mApnTypeBitmask)
&& (isDataRoaming || Objects.equals(mProtocol, other.mProtocol)) && (isDataRoaming || Objects.equals(mProtocol, other.mProtocol))
&& (!isDataRoaming || Objects.equals(mRoamingProtocol, other.mRoamingProtocol)) && (!isDataRoaming || Objects.equals(mRoamingProtocol, other.mRoamingProtocol))
&& Objects.equals(mCarrierEnabled, other.mCarrierEnabled) && Objects.equals(mCarrierEnabled, other.mCarrierEnabled)
&& Objects.equals(mProfileId, other.mProfileId) && Objects.equals(mProfileId, other.mProfileId)
&& Objects.equals(mPersistent, other.mPersistent) && Objects.equals(mPersistent, other.mPersistent)
&& Objects.equals(mMaxConns, other.mMaxConns) && Objects.equals(mMaxConns, other.mMaxConns)
&& Objects.equals(mWaitTime, other.mWaitTime) && Objects.equals(mWaitTime, other.mWaitTime)
&& Objects.equals(mMaxConnsTime, other.mMaxConnsTime) && Objects.equals(mMaxConnsTime, other.mMaxConnsTime)
&& Objects.equals(mMtu, other.mMtu) && Objects.equals(mMtuV4, other.mMtuV4)
&& Objects.equals(mMvnoType, other.mMvnoType) && Objects.equals(mMtuV6, other.mMtuV6)
&& Objects.equals(mMvnoMatchData, other.mMvnoMatchData) && Objects.equals(mMvnoType, other.mMvnoType)
&& Objects.equals(mApnSetId, other.mApnSetId) && Objects.equals(mMvnoMatchData, other.mMvnoMatchData)
&& Objects.equals(mCarrierId, other.mCarrierId) && Objects.equals(mApnSetId, other.mApnSetId)
&& Objects.equals(mSkip464Xlat, other.mSkip464Xlat); && Objects.equals(mCarrierId, other.mCarrierId)
&& Objects.equals(mSkip464Xlat, other.mSkip464Xlat);
} }
/** /**
@@ -1732,7 +1526,7 @@ public class ApnSetting implements Parcelable {
dest.writeString(mApnName); dest.writeString(mApnName);
dest.writeString(mProxyAddress); dest.writeString(mProxyAddress);
dest.writeInt(mProxyPort); dest.writeInt(mProxyPort);
dest.writeValue(mMmsc); dest.writeParcelable(mMmsc, flags);
dest.writeString(mMmsProxyAddress); dest.writeString(mMmsProxyAddress);
dest.writeInt(mMmsProxyPort); dest.writeInt(mMmsProxyPort);
dest.writeString(mUser); dest.writeString(mUser);
@@ -1742,40 +1536,53 @@ public class ApnSetting implements Parcelable {
dest.writeInt(mProtocol); dest.writeInt(mProtocol);
dest.writeInt(mRoamingProtocol); dest.writeInt(mRoamingProtocol);
dest.writeBoolean(mCarrierEnabled); dest.writeBoolean(mCarrierEnabled);
dest.writeInt(mMvnoType);
dest.writeInt(mNetworkTypeBitmask); dest.writeInt(mNetworkTypeBitmask);
dest.writeInt(mProfileId);
dest.writeBoolean(mPersistent);
dest.writeInt(mMaxConns);
dest.writeInt(mWaitTime);
dest.writeInt(mMaxConnsTime);
dest.writeInt(mMtuV4);
dest.writeInt(mMtuV6);
dest.writeInt(mMvnoType);
dest.writeString(mMvnoMatchData);
dest.writeInt(mApnSetId); dest.writeInt(mApnSetId);
dest.writeInt(mCarrierId); dest.writeInt(mCarrierId);
dest.writeInt(mSkip464Xlat); dest.writeInt(mSkip464Xlat);
} }
private static ApnSetting readFromParcel(Parcel in) { private static ApnSetting readFromParcel(Parcel in) {
final int id = in.readInt(); return new Builder()
final String operatorNumeric = in.readString(); .setId(in.readInt())
final String entryName = in.readString(); .setOperatorNumeric(in.readString())
final String apnName = in.readString(); .setEntryName(in.readString())
final String proxy = in.readString(); .setApnName(in.readString())
final int port = in.readInt(); .setProxyAddress(in.readString())
final Uri mmsc = (Uri) in.readValue(Uri.class.getClassLoader()); .setProxyPort(in.readInt())
final String mmsProxy = in.readString(); .setMmsc(in.readParcelable(Uri.class.getClassLoader()))
final int mmsPort = in.readInt(); .setMmsProxyAddress(in.readString())
final String user = in.readString(); .setMmsProxyPort(in.readInt())
final String password = in.readString(); .setUser(in.readString())
final int authType = in.readInt(); .setPassword(in.readString())
final int apnTypesBitmask = in.readInt(); .setAuthType(in.readInt())
final int protocol = in.readInt(); .setApnTypeBitmask(in.readInt())
final int roamingProtocol = in.readInt(); .setProtocol(in.readInt())
final boolean carrierEnabled = in.readBoolean(); .setRoamingProtocol(in.readInt())
final int mvnoType = in.readInt(); .setCarrierEnabled(in.readBoolean())
final int networkTypeBitmask = in.readInt(); .setNetworkTypeBitmask(in.readInt())
final int apnSetId = in.readInt(); .setProfileId(in.readInt())
final int carrierId = in.readInt(); .setModemCognitive(in.readBoolean())
final int skip464xlat = in.readInt(); .setMaxConns(in.readInt())
.setWaitTime(in.readInt())
return makeApnSetting(id, operatorNumeric, entryName, apnName, .setMaxConnsTime(in.readInt())
proxy, port, mmsc, mmsProxy, mmsPort, user, password, authType, apnTypesBitmask, .setMtuV4(in.readInt())
protocol, roamingProtocol, carrierEnabled, networkTypeBitmask, 0, false, .setMtuV6(in.readInt())
0, 0, 0, 0, mvnoType, null, apnSetId, carrierId, skip464xlat); .setMvnoType(in.readInt())
.setMvnoMatchData(in.readString())
.setApnSetId(in.readInt())
.setCarrierId(in.readInt())
.setSkip464Xlat(in.readInt())
.buildWithoutCheck();
} }
public static final @android.annotation.NonNull Parcelable.Creator<ApnSetting> CREATOR = public static final @android.annotation.NonNull Parcelable.Creator<ApnSetting> CREATOR =
@@ -1834,13 +1641,14 @@ public class ApnSetting implements Parcelable {
private int mMmsProxyPort = UNSPECIFIED_INT; private int mMmsProxyPort = UNSPECIFIED_INT;
private String mUser; private String mUser;
private String mPassword; private String mPassword;
private int mAuthType; private int mAuthType = AUTH_TYPE_UNKNOWN;
private int mApnTypeBitmask; private int mApnTypeBitmask;
private int mId; private int mId;
private String mOperatorNumeric; private String mOperatorNumeric;
private int mProtocol = UNSPECIFIED_INT; private int mProtocol = UNSPECIFIED_INT;
private int mRoamingProtocol = UNSPECIFIED_INT; private int mRoamingProtocol = UNSPECIFIED_INT;
private int mMtu; private int mMtuV4;
private int mMtuV6;
private int mNetworkTypeBitmask; private int mNetworkTypeBitmask;
private boolean mCarrierEnabled; private boolean mCarrierEnabled;
private int mProfileId; private int mProfileId;
@@ -1863,20 +1671,34 @@ public class ApnSetting implements Parcelable {
* Sets the unique database id for this entry. * Sets the unique database id for this entry.
* *
* @param id the unique database id to set for this entry * @param id the unique database id to set for this entry
* @hide
*/ */
private Builder setId(int id) { public Builder setId(int id) {
this.mId = id; this.mId = id;
return this; return this;
} }
/** /**
* Set the MTU size of the mobile interface to which the APN connected. * Set the MTU size of the IPv4 mobile interface to which the APN connected. Note this value
* is used only if MTU size is not provided in {@link DataCallResponse}.
* *
* @param mtu the MTU size to set for the APN * @param mtuV4 the MTU size to set for the APN
* @hide * @hide
*/ */
public Builder setMtu(int mtu) { public Builder setMtuV4(int mtuV4) {
this.mMtu = mtu; this.mMtuV4 = mtuV4;
return this;
}
/**
* Set the MTU size of the IPv6 mobile interface to which the APN connected. Note this value
* is used only if MTU size is not provided in {@link DataCallResponse}.
*
* @param mtuV6 the MTU size to set for the APN
* @hide
*/
public Builder setMtuV6(int mtuV6) {
this.mMtuV6 = mtuV6;
return this; return this;
} }
@@ -2237,7 +2059,8 @@ public class ApnSetting implements Parcelable {
| TYPE_FOTA | TYPE_IMS | TYPE_CBS | TYPE_IA | TYPE_EMERGENCY | TYPE_MCX | TYPE_FOTA | TYPE_IMS | TYPE_CBS | TYPE_IA | TYPE_EMERGENCY | TYPE_MCX
| TYPE_XCAP | TYPE_VSIM | TYPE_BIP | TYPE_ENTERPRISE)) == 0 | TYPE_XCAP | TYPE_VSIM | TYPE_BIP | TYPE_ENTERPRISE)) == 0
|| TextUtils.isEmpty(mApnName) || TextUtils.isEmpty(mEntryName)) { || TextUtils.isEmpty(mApnName) || TextUtils.isEmpty(mEntryName)) {
return null; throw new IllegalArgumentException("mApName=" + mApnName + ", mEntryName="
+ mEntryName + ", mApnTypeBitmask=" + mApnTypeBitmask);
} }
return new ApnSetting(this); return new ApnSetting(this);
} }

View File

@@ -25,13 +25,11 @@ import android.annotation.SystemApi;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.telephony.Annotation.ApnType; import android.telephony.Annotation.ApnType;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager.NetworkTypeBitMask; import android.telephony.TelephonyManager.NetworkTypeBitMask;
import android.telephony.data.ApnSetting.AuthType; import android.telephony.data.ApnSetting.AuthType;
import android.text.TextUtils; import android.text.TextUtils;
import com.android.internal.telephony.RILConstants;
import com.android.internal.telephony.util.TelephonyUtils;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.util.Objects; import java.util.Objects;
@@ -62,152 +60,141 @@ public final class DataProfile implements Parcelable {
/** 3GPP2 type data profile */ /** 3GPP2 type data profile */
public static final int TYPE_3GPP2 = 2; public static final int TYPE_3GPP2 = 2;
private final int mProfileId; private final @Type int mType;
private final String mApn; private final @Nullable ApnSetting mApnSetting;
@ProtocolType private final @Nullable TrafficDescriptor mTrafficDescriptor;
private final int mProtocolType;
@AuthType
private final int mAuthType;
private final String mUserName;
private final String mPassword;
@Type
private final int mType;
private final int mMaxConnectionsTime;
private final int mMaxConnections;
private final int mWaitTime;
private final boolean mEnabled;
@ApnType
private final int mSupportedApnTypesBitmask;
@ProtocolType
private final int mRoamingProtocolType;
@NetworkTypeBitMask
private final int mBearerBitmask;
private final int mMtuV4;
private final int mMtuV6;
private final boolean mPersistent;
private final boolean mPreferred; private final boolean mPreferred;
/** @hide */ private DataProfile(@NonNull Builder builder) {
private DataProfile(int profileId, String apn, @ProtocolType int protocolType, int authType, mApnSetting = builder.mApnSetting;
String userName, String password, int type, int maxConnectionsTime, mTrafficDescriptor = builder.mTrafficDescriptor;
int maxConnections, int waitTime, boolean enabled, mPreferred = builder.mPreferred;
@ApnType int supportedApnTypesBitmask, @ProtocolType int roamingProtocolType,
@NetworkTypeBitMask int bearerBitmask, int mtuV4, int mtuV6, boolean persistent, if (builder.mType != -1) {
boolean preferred) { mType = builder.mType;
this.mProfileId = profileId; } else if (mApnSetting != null) {
this.mApn = apn; int networkTypes = mApnSetting.getNetworkTypeBitmask();
this.mProtocolType = protocolType;
if (authType == -1) { if (networkTypes == 0) {
authType = TextUtils.isEmpty(userName) ? RILConstants.SETUP_DATA_AUTH_NONE mType = DataProfile.TYPE_COMMON;
: RILConstants.SETUP_DATA_AUTH_PAP_CHAP; } else if ((networkTypes & TelephonyManager.NETWORK_STANDARDS_FAMILY_BITMASK_3GPP2)
== networkTypes) {
mType = DataProfile.TYPE_3GPP2;
} else if ((networkTypes & TelephonyManager.NETWORK_STANDARDS_FAMILY_BITMASK_3GPP)
== networkTypes) {
mType = DataProfile.TYPE_3GPP;
} else {
mType = DataProfile.TYPE_COMMON;
}
} else {
mType = DataProfile.TYPE_COMMON;
} }
this.mAuthType = authType;
this.mUserName = userName;
this.mPassword = password;
this.mType = type;
this.mMaxConnectionsTime = maxConnectionsTime;
this.mMaxConnections = maxConnections;
this.mWaitTime = waitTime;
this.mEnabled = enabled;
this.mSupportedApnTypesBitmask = supportedApnTypesBitmask;
this.mRoamingProtocolType = roamingProtocolType;
this.mBearerBitmask = bearerBitmask;
this.mMtuV4 = mtuV4;
this.mMtuV6 = mtuV6;
this.mPersistent = persistent;
this.mPreferred = preferred;
} }
private DataProfile(Parcel source) { private DataProfile(Parcel source) {
mProfileId = source.readInt();
mApn = source.readString();
mProtocolType = source.readInt();
mAuthType = source.readInt();
mUserName = source.readString();
mPassword = source.readString();
mType = source.readInt(); mType = source.readInt();
mMaxConnectionsTime = source.readInt(); mApnSetting = source.readParcelable(ApnSetting.class.getClassLoader());
mMaxConnections = source.readInt(); mTrafficDescriptor = source.readParcelable(TrafficDescriptor.class.getClassLoader());
mWaitTime = source.readInt();
mEnabled = source.readBoolean();
mSupportedApnTypesBitmask = source.readInt();
mRoamingProtocolType = source.readInt();
mBearerBitmask = source.readInt();
mMtuV4 = source.readInt();
mMtuV6 = source.readInt();
mPersistent = source.readBoolean();
mPreferred = source.readBoolean(); mPreferred = source.readBoolean();
} }
/** /**
* @return Id of the data profile. * @return Id of the data profile.
*/ */
public int getProfileId() { return mProfileId; } public int getProfileId() {
if (mApnSetting != null) {
return mApnSetting.getProfileId();
}
return 0;
}
/** /**
* @return The APN (Access Point Name) to establish data connection. This is a string * @return The APN (Access Point Name) to establish data connection. This is a string
* specifically defined by the carrier. * specifically defined by the carrier.
*/ */
@NonNull @NonNull
public String getApn() { return mApn; } public String getApn() {
if (mApnSetting != null) {
return TextUtils.emptyIfNull(mApnSetting.getApnName());
}
return "";
}
/** /**
* @return The connection protocol defined in 3GPP TS 27.007 section 10.1.1. * @return The connection protocol defined in 3GPP TS 27.007 section 10.1.1.
*/ */
public @ProtocolType int getProtocolType() { return mProtocolType; } public @ProtocolType int getProtocolType() {
if (mApnSetting != null) {
return mApnSetting.getProtocol();
}
return ApnSetting.PROTOCOL_IP;
}
/** /**
* @return The authentication protocol used for this PDP context. * @return The authentication protocol used for this PDP context.
*/ */
public @AuthType int getAuthType() { return mAuthType; } public @AuthType int getAuthType() {
if (mApnSetting != null) {
return mApnSetting.getAuthType();
}
return ApnSetting.AUTH_TYPE_NONE;
}
/** /**
* @return The username for APN. Can be null. * @return The username for APN. Can be null.
*/ */
@Nullable @Nullable
public String getUserName() { return mUserName; } public String getUserName() {
if (mApnSetting != null) {
return mApnSetting.getUser();
}
return null;
}
/** /**
* @return The password for APN. Can be null. * @return The password for APN. Can be null.
*/ */
@Nullable @Nullable
public String getPassword() { return mPassword; } public String getPassword() {
if (mApnSetting != null) {
return mApnSetting.getPassword();
}
return null;
}
/** /**
* @return The profile type. * @return The profile type.
*/ */
public @Type int getType() { return mType; } public @Type int getType() {
return mType;
}
/** /**
* @return The period in seconds to limit the maximum connections. * @return The period in seconds to limit the maximum connections.
* *
* @hide * @hide
*/ */
public int getMaxConnectionsTime() { return mMaxConnectionsTime; } public int getMaxConnectionsTime() {
if (mApnSetting != null) {
return mApnSetting.getMaxConnsTime();
}
return 0;
}
/** /**
* @return The maximum connections allowed. * @return The maximum connections allowed.
* *
* @hide * @hide
*/ */
public int getMaxConnections() { return mMaxConnections; } public int getMaxConnections() {
if (mApnSetting != null) {
return mApnSetting.getMaxConns();
}
return 0;
}
/** /**
* @return The required wait time in seconds after a successful UE initiated disconnect of a * @return The required wait time in seconds after a successful UE initiated disconnect of a
@@ -216,57 +203,117 @@ public final class DataProfile implements Parcelable {
* *
* @hide * @hide
*/ */
public int getWaitTime() { return mWaitTime; } public int getWaitTime() {
if (mApnSetting != null) {
return mApnSetting.getWaitTime();
}
return 0;
}
/** /**
* @return True if the profile is enabled. * @return True if the profile is enabled.
*/ */
public boolean isEnabled() { return mEnabled; } public boolean isEnabled() {
if (mApnSetting != null) {
return mApnSetting.isEnabled();
}
return false;
}
/** /**
* @return The supported APN types bitmask. * @return The supported APN types bitmask.
*/ */
public @ApnType int getSupportedApnTypesBitmask() { return mSupportedApnTypesBitmask; } public @ApnType int getSupportedApnTypesBitmask() {
if (mApnSetting != null) {
return mApnSetting.getApnTypeBitmask();
}
return ApnSetting.TYPE_NONE;
}
/** /**
* @return The connection protocol on roaming network defined in 3GPP TS 27.007 section 10.1.1. * @return The connection protocol on roaming network defined in 3GPP TS 27.007 section 10.1.1.
*/ */
public @ProtocolType int getRoamingProtocolType() { return mRoamingProtocolType; } public @ProtocolType int getRoamingProtocolType() {
if (mApnSetting != null) {
return mApnSetting.getRoamingProtocol();
}
return ApnSetting.PROTOCOL_IP;
}
/** /**
* @return The bearer bitmask indicating the applicable networks for this data profile. * @return The bearer bitmask indicating the applicable networks for this data profile.
*/ */
public @NetworkTypeBitMask int getBearerBitmask() { return mBearerBitmask; } public @NetworkTypeBitMask int getBearerBitmask() {
if (mApnSetting != null) {
return mApnSetting.getNetworkTypeBitmask();
}
return (int) TelephonyManager.NETWORK_TYPE_BITMASK_UNKNOWN;
}
/** /**
* @return The maximum transmission unit (MTU) size in bytes. * @return The maximum transmission unit (MTU) size in bytes.
* @deprecated use {@link #getMtuV4} or {@link #getMtuV6} instead. * @deprecated use {@link #getMtuV4} or {@link #getMtuV6} instead.
*/ */
@Deprecated @Deprecated
public int getMtu() { return mMtuV4; } public int getMtu() {
return getMtuV4();
}
/** /**
* This replaces the deprecated method getMtu. * This replaces the deprecated method getMtu.
* @return The maximum transmission unit (MTU) size in bytes, for IPv4. * @return The maximum transmission unit (MTU) size in bytes, for IPv4.
*/ */
public int getMtuV4() { return mMtuV4; } public int getMtuV4() {
if (mApnSetting != null) {
return mApnSetting.getMtuV4();
}
return 0;
}
/** /**
* @return The maximum transmission unit (MTU) size in bytes, for IPv6. * @return The maximum transmission unit (MTU) size in bytes, for IPv6.
*/ */
public int getMtuV6() { return mMtuV6; } public int getMtuV6() {
if (mApnSetting != null) {
return mApnSetting.getMtuV6();
}
return 0;
}
/** /**
* @return {@code true} if modem must persist this data profile. * @return {@code true} if modem must persist this data profile.
*/ */
public boolean isPersistent() { return mPersistent; } public boolean isPersistent() {
if (mApnSetting != null) {
return mApnSetting.isPersistent();
}
return false;
}
/** /**
* @return {@code true} if this data profile was used to bring up the last default * @return {@code true} if this data profile was used to bring up the last default
* (i.e internet) data connection successfully, or the one chosen by the user in Settings' * (i.e internet) data connection successfully, or the one chosen by the user in Settings'
* APN editor. For one carrier there can be only one profiled preferred. * APN editor. For one carrier there can be only one profiled preferred.
*/ */
public boolean isPreferred() { return mPreferred; } public boolean isPreferred() {
return mPreferred;
}
/**
* @return The APN setting
* @hide TODO: Remove before T is released.
*/
public @Nullable ApnSetting getApnSetting() {
return mApnSetting;
}
/**
* @return The traffic descriptor
* @hide TODO: Remove before T is released.
*/
public @Nullable TrafficDescriptor getTrafficDescriptor() {
return mTrafficDescriptor;
}
@Override @Override
public int describeContents() { public int describeContents() {
@@ -276,34 +323,15 @@ public final class DataProfile implements Parcelable {
@NonNull @NonNull
@Override @Override
public String toString() { public String toString() {
return "DataProfile=" + mProfileId + "/" + mProtocolType + "/" + mAuthType return "DataProfile=" + mApnSetting + ", " + mTrafficDescriptor + ", preferred="
+ "/" + (TelephonyUtils.IS_USER ? "***/***/***" : + mPreferred;
(mApn + "/" + mUserName + "/" + mPassword)) + "/" + mType + "/"
+ mMaxConnectionsTime + "/" + mMaxConnections + "/"
+ mWaitTime + "/" + mEnabled + "/" + mSupportedApnTypesBitmask + "/"
+ mRoamingProtocolType + "/" + mBearerBitmask + "/" + mMtuV4 + "/" + mMtuV6 + "/"
+ mPersistent + "/" + mPreferred;
} }
@Override @Override
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(mProfileId);
dest.writeString(mApn);
dest.writeInt(mProtocolType);
dest.writeInt(mAuthType);
dest.writeString(mUserName);
dest.writeString(mPassword);
dest.writeInt(mType); dest.writeInt(mType);
dest.writeInt(mMaxConnectionsTime); dest.writeParcelable(mApnSetting, flags);
dest.writeInt(mMaxConnections); dest.writeParcelable(mTrafficDescriptor, flags);
dest.writeInt(mWaitTime);
dest.writeBoolean(mEnabled);
dest.writeInt(mSupportedApnTypesBitmask);
dest.writeInt(mRoamingProtocolType);
dest.writeInt(mBearerBitmask);
dest.writeInt(mMtuV4);
dest.writeInt(mMtuV6);
dest.writeBoolean(mPersistent);
dest.writeBoolean(mPreferred); dest.writeBoolean(mPreferred);
} }
@@ -321,36 +349,18 @@ public final class DataProfile implements Parcelable {
}; };
@Override @Override
public boolean equals(@Nullable Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
DataProfile that = (DataProfile) o; DataProfile that = (DataProfile) o;
return mProfileId == that.mProfileId return mType == that.mType
&& mProtocolType == that.mProtocolType && Objects.equals(mApnSetting, that.mApnSetting)
&& mAuthType == that.mAuthType && Objects.equals(mTrafficDescriptor, that.mTrafficDescriptor);
&& mType == that.mType
&& mMaxConnectionsTime == that.mMaxConnectionsTime
&& mMaxConnections == that.mMaxConnections
&& mWaitTime == that.mWaitTime
&& mEnabled == that.mEnabled
&& mSupportedApnTypesBitmask == that.mSupportedApnTypesBitmask
&& mRoamingProtocolType == that.mRoamingProtocolType
&& mBearerBitmask == that.mBearerBitmask
&& mMtuV4 == that.mMtuV4
&& mMtuV6 == that.mMtuV6
&& mPersistent == that.mPersistent
&& mPreferred == that.mPreferred
&& Objects.equals(mApn, that.mApn)
&& Objects.equals(mUserName, that.mUserName)
&& Objects.equals(mPassword, that.mPassword);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(mProfileId, mApn, mProtocolType, mAuthType, mUserName, mPassword, mType, return Objects.hash(mType, mApnSetting, mTrafficDescriptor);
mMaxConnectionsTime, mMaxConnections, mWaitTime, mEnabled,
mSupportedApnTypesBitmask, mRoamingProtocolType, mBearerBitmask, mMtuV4, mMtuV6,
mPersistent, mPreferred);
} }
/** /**
@@ -383,13 +393,7 @@ public final class DataProfile implements Parcelable {
private String mPassword; private String mPassword;
@Type @Type
private int mType; private int mType = -1;
private int mMaxConnectionsTime;
private int mMaxConnections;
private int mWaitTime;
private boolean mEnabled; private boolean mEnabled;
@@ -410,6 +414,10 @@ public final class DataProfile implements Parcelable {
private boolean mPreferred; private boolean mPreferred;
private ApnSetting mApnSetting;
private TrafficDescriptor mTrafficDescriptor;
/** /**
* Default constructor for Builder. * Default constructor for Builder.
*/ */
@@ -495,48 +503,6 @@ public final class DataProfile implements Parcelable {
return this; return this;
} }
/**
* Set the period in seconds to limit the maximum connections.
*
* @param maxConnectionsTime The profile type
* @return The same instance of the builder.
*
* @hide
*/
public @NonNull Builder setMaxConnectionsTime(int maxConnectionsTime) {
mMaxConnectionsTime = maxConnectionsTime;
return this;
}
/**
* Set the maximum connections allowed.
*
* @param maxConnections The maximum connections allowed.
* @return The same instance of the builder.
*
* @hide
*/
public @NonNull Builder setMaxConnections(int maxConnections) {
mMaxConnections = maxConnections;
return this;
}
/**
* Set the period in seconds to limit the maximum connections.
*
* @param waitTime The required wait time in seconds after a successful UE initiated
* disconnect of a given PDN connection before the device can send a new PDN connection
* request for that given PDN.
*
* @return The same instance of the builder.
*
* @hide
*/
public @NonNull Builder setWaitTime(int waitTime) {
mWaitTime = waitTime;
return this;
}
/** /**
* Enable the data profile * Enable the data profile
* *
@@ -587,8 +553,9 @@ public final class DataProfile implements Parcelable {
* *
* @param mtu The maximum transmission unit (MTU) size in bytes. * @param mtu The maximum transmission unit (MTU) size in bytes.
* @return The same instance of the builder. * @return The same instance of the builder.
* @deprecated use {@link #setMtuV4} or {@link #setMtuV6} instead. * @deprecated use {@link #setApnSetting(ApnSetting)} instead.
*/ */
@Deprecated
public @NonNull Builder setMtu(int mtu) { public @NonNull Builder setMtu(int mtu) {
mMtuV4 = mMtuV6 = mtu; mMtuV4 = mMtuV6 = mtu;
return this; return this;
@@ -631,7 +598,7 @@ public final class DataProfile implements Parcelable {
} }
/** /**
* Set data profile as persistent/non-persistent * Set data profile as persistent/non-persistent.
* *
* @param isPersistent {@code true} if this data profile was used to bring up the last * @param isPersistent {@code true} if this data profile was used to bring up the last
* default (i.e internet) data connection successfully. * default (i.e internet) data connection successfully.
@@ -642,16 +609,64 @@ public final class DataProfile implements Parcelable {
return this; return this;
} }
/**
* Set APN setting.
*
* @param apnSetting APN setting
* @return The same instance of the builder
*
* @hide // TODO: Remove before T is released.
*/
public @NonNull Builder setApnSetting(@NonNull ApnSetting apnSetting) {
mApnSetting = apnSetting;
return this;
}
/**
* Set traffic descriptor.
*
* @param trafficDescriptor Traffic descriptor
* @return The same instance of the builder
*
* @hide // TODO: Remove before T is released.
*/
public @NonNull Builder setTrafficDescriptor(@NonNull TrafficDescriptor trafficDescriptor) {
mTrafficDescriptor = trafficDescriptor;
return this;
}
/** /**
* Build the DataProfile object * Build the DataProfile object
* *
* @return The data profile object * @return The data profile object
*/ */
public @NonNull DataProfile build() { public @NonNull DataProfile build() {
return new DataProfile(mProfileId, mApn, mProtocolType, mAuthType, mUserName, mPassword, if (mApnSetting == null && mApn != null) {
mType, mMaxConnectionsTime, mMaxConnections, mWaitTime, mEnabled, // This is for backwards compatibility.
mSupportedApnTypesBitmask, mRoamingProtocolType, mBearerBitmask, mMtuV4, mMtuV6, mApnSetting = new ApnSetting.Builder()
mPersistent, mPreferred); .setEntryName(mApn)
.setApnName(mApn)
.setApnTypeBitmask(mSupportedApnTypesBitmask)
.setAuthType(mAuthType)
.setCarrierEnabled(mEnabled)
.setModemCognitive(mPersistent)
.setMtuV4(mMtuV4)
.setMtuV6(mMtuV6)
.setNetworkTypeBitmask(mBearerBitmask)
.setProfileId(mProfileId)
.setPassword(mPassword)
.setProtocol(mProtocolType)
.setRoamingProtocol(mRoamingProtocolType)
.setUser(mUserName)
.build();
}
if (mApnSetting == null && mTrafficDescriptor == null) {
throw new IllegalArgumentException("APN setting and traffic descriptor can't be "
+ "both null.");
}
return new DataProfile(this);
} }
} }
} }