Skip to content

Commit b028ce5

Browse files
lcolittiAndroid (Google) Code Review
authored andcommitted
Merge "Add a protocol property to the APNs and use it." into gingerbread
2 parents 6987036 + 3c4e929 commit b028ce5

File tree

6 files changed

+215
-29
lines changed

6 files changed

+215
-29
lines changed

core/java/android/provider/Telephony.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,6 +1712,21 @@ public static final class Carriers implements BaseColumns {
17121712

17131713
public static final String TYPE = "type";
17141714

1715+
/**
1716+
* The protocol to be used to connect to this APN.
1717+
*
1718+
* One of the PDP_type values in TS 27.007 section 10.1.1.
1719+
* For example, "IP", "IPV6", "IPV4V6", or "PPP".
1720+
*/
1721+
public static final String PROTOCOL = "protocol";
1722+
1723+
/**
1724+
* The protocol to be used to connect to this APN when roaming.
1725+
*
1726+
* The syntax is the same as protocol.
1727+
*/
1728+
public static final String ROAMING_PROTOCOL = "roaming_protocol";
1729+
17151730
public static final String CURRENT = "current";
17161731
}
17171732

telephony/java/com/android/internal/telephony/cdma/CdmaDataConnectionTracker.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,8 @@ private boolean setupData(String reason) {
432432
} else {
433433
types = mDefaultApnTypes;
434434
}
435-
mActiveApn = new ApnSetting(0, "", "", "", "", "", "", "", "", "", "", 0, types);
435+
mActiveApn = new ApnSetting(0, "", "", "", "", "", "", "", "", "", "",
436+
0, types, "IP", "IP");
436437

437438
Message msg = obtainMessage();
438439
msg.what = EVENT_DATA_SETUP_COMPLETE;

telephony/java/com/android/internal/telephony/gsm/ApnSetting.java

Lines changed: 77 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
*/
2323
public class ApnSetting {
2424

25+
static final String V2_FORMAT_REGEX = "^\\[ApnSettingV2\\]\\s*";
26+
2527
String carrier;
2628
String apn;
2729
String proxy;
@@ -35,11 +37,14 @@ public class ApnSetting {
3537
public String[] types;
3638
int id;
3739
String numeric;
40+
String protocol;
41+
String roamingProtocol;
3842

39-
40-
public ApnSetting(int id, String numeric, String carrier, String apn, String proxy, String port,
43+
public ApnSetting(int id, String numeric, String carrier, String apn,
44+
String proxy, String port,
4145
String mmsc, String mmsProxy, String mmsPort,
42-
String user, String password, int authType, String[] types) {
46+
String user, String password, int authType, String[] types,
47+
String protocol, String roamingProtocol) {
4348
this.id = id;
4449
this.numeric = numeric;
4550
this.carrier = carrier;
@@ -53,40 +58,81 @@ public ApnSetting(int id, String numeric, String carrier, String apn, String pro
5358
this.password = password;
5459
this.authType = authType;
5560
this.types = types;
61+
this.protocol = protocol;
62+
this.roamingProtocol = roamingProtocol;
5663
}
5764

58-
// data[0] = name
59-
// data[1] = apn
60-
// data[2] = proxy
61-
// data[3] = port
62-
// data[4] = username
63-
// data[5] = password
64-
// data[6] = server
65-
// data[7] = mmsc
66-
// data[8] = mmsproxy
67-
// data[9] = mmsport
68-
// data[10] = mcc
69-
// data[11] = mnc
70-
// data[12] = auth
71-
// data[13] = first type...
65+
/**
66+
* Creates an ApnSetting object from a string.
67+
*
68+
* @param data the string to read.
69+
*
70+
* The string must be in one of two formats (newlines added for clarity,
71+
* spaces are optional):
72+
*
73+
* v1 format:
74+
* <carrier>, <apn>, <proxy>, <port>, <mmsc>, <mmsproxy>,
75+
* <mmsport>, <user>, <password>, <authtype>, <mcc>,<mnc>,
76+
* <type>[, <type>...]
77+
*
78+
* v2 format:
79+
* [ApnSettingV2] <carrier>, <apn>, <proxy>, <port>, <mmsc>, <mmsproxy>,
80+
* <mmsport>, <user>, <password, <authtype>, <mcc>, <mnc>,
81+
* <type>[| <type>...], <protocol>, <roaming_protocol>
82+
*
83+
* Note that the strings generated by toString() do not contain the username
84+
* and password and thus cannot be read by this method.
85+
*
86+
* @see ApnSettingTest
87+
*/
7288
public static ApnSetting fromString(String data) {
7389
if (data == null) return null;
90+
91+
int version;
92+
// matches() operates on the whole string, so append .* to the regex.
93+
if (data.matches(V2_FORMAT_REGEX + ".*")) {
94+
version = 2;
95+
data = data.replaceFirst(V2_FORMAT_REGEX, "");
96+
} else {
97+
version = 1;
98+
}
99+
74100
String[] a = data.split("\\s*,\\s*");
75-
if (a.length < 14) return null;
76-
int authType = 0;
101+
if (a.length < 14) {
102+
return null;
103+
}
104+
105+
int authType;
77106
try {
78107
authType = Integer.parseInt(a[12]);
79108
} catch (Exception e) {
109+
authType = 0;
80110
}
81-
String[] typeArray = new String[a.length - 13];
82-
System.arraycopy(a, 13, typeArray, 0, a.length - 13);
111+
112+
String[] typeArray;
113+
String protocol, roamingProtocol;
114+
if (version == 1) {
115+
typeArray = new String[a.length - 13];
116+
System.arraycopy(a, 13, typeArray, 0, a.length - 13);
117+
protocol = RILConstants.SETUP_DATA_PROTOCOL_IP;
118+
roamingProtocol = RILConstants.SETUP_DATA_PROTOCOL_IP;
119+
} else {
120+
if (a.length < 16) {
121+
return null;
122+
}
123+
typeArray = a[13].split("\\s*\\|\\s*");
124+
protocol = a[14];
125+
roamingProtocol = a[15];
126+
}
127+
83128
return new ApnSetting(-1,a[10]+a[11],a[0],a[1],a[2],a[3],a[7],a[8],
84-
a[9],a[4],a[5],authType,typeArray);
129+
a[9],a[4],a[5],authType,typeArray,protocol,roamingProtocol);
85130
}
86131

87132
public String toString() {
88133
StringBuilder sb = new StringBuilder();
89-
sb.append(carrier)
134+
sb.append("[ApnSettingV2] ")
135+
.append(carrier)
90136
.append(", ").append(id)
91137
.append(", ").append(numeric)
92138
.append(", ").append(apn)
@@ -95,10 +141,15 @@ public String toString() {
95141
.append(", ").append(mmsProxy)
96142
.append(", ").append(mmsPort)
97143
.append(", ").append(port)
98-
.append(", ").append(authType);
99-
for (String t : types) {
100-
sb.append(", ").append(t);
144+
.append(", ").append(authType).append(", ");
145+
for (int i = 0; i < types.length; i++) {
146+
sb.append(types[i]);
147+
if (i < types.length - 1) {
148+
sb.append(" | ");
149+
}
101150
}
151+
sb.append(", ").append(protocol);
152+
sb.append(", ").append(roamingProtocol);
102153
return sb.toString();
103154
}
104155

telephony/java/com/android/internal/telephony/gsm/GsmDataConnection.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,19 @@ void onConnect(ConnectionParams cp) {
104104
authType = (apn.user != null) ? RILConstants.SETUP_DATA_AUTH_PAP_CHAP :
105105
RILConstants.SETUP_DATA_AUTH_NONE;
106106
}
107+
108+
String protocol;
109+
if (phone.getServiceState().getRoaming()) {
110+
protocol = apn.roamingProtocol;
111+
} else {
112+
protocol = apn.protocol;
113+
}
114+
107115
phone.mCM.setupDataCall(
108116
Integer.toString(RILConstants.SETUP_DATA_TECH_GSM),
109117
Integer.toString(RILConstants.DATA_PROFILE_DEFAULT),
110118
apn.apn, apn.user, apn.password, Integer.toString(authType),
111-
RILConstants.SETUP_DATA_PROTOCOL_IP, msg);
119+
protocol, msg);
112120
}
113121

114122
@Override

telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,10 @@ private ArrayList<ApnSetting> createApnList(Cursor cursor) {
559559
cursor.getString(cursor.getColumnIndexOrThrow(Telephony.Carriers.USER)),
560560
cursor.getString(cursor.getColumnIndexOrThrow(Telephony.Carriers.PASSWORD)),
561561
cursor.getInt(cursor.getColumnIndexOrThrow(Telephony.Carriers.AUTH_TYPE)),
562-
types);
562+
types,
563+
cursor.getString(cursor.getColumnIndexOrThrow(Telephony.Carriers.PROTOCOL)),
564+
cursor.getString(cursor.getColumnIndexOrThrow(
565+
Telephony.Carriers.ROAMING_PROTOCOL)));
563566
result.add(apn);
564567
} while (cursor.moveToNext());
565568
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright (C) 2010 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.android.internal.telephony.gsm;
18+
19+
import junit.framework.TestCase;
20+
21+
import android.test.suitebuilder.annotation.SmallTest;
22+
23+
public class ApnSettingTest extends TestCase {
24+
25+
public static final String[] TYPES = {"default", "*"};
26+
27+
public static void assertApnSettingEqual(ApnSetting a1, ApnSetting a2) {
28+
assertEquals(a1.carrier, a2.carrier);
29+
assertEquals(a1.apn, a2.apn);
30+
assertEquals(a1.proxy, a2.proxy);
31+
assertEquals(a1.port, a2.port);
32+
assertEquals(a1.mmsc, a2.mmsc);
33+
assertEquals(a1.mmsProxy, a2.mmsProxy);
34+
assertEquals(a1.mmsPort, a2.mmsPort);
35+
assertEquals(a1.user, a2.user);
36+
assertEquals(a1.password, a2.password);
37+
assertEquals(a1.authType, a2.authType);
38+
assertEquals(a1.id, a2.id);
39+
assertEquals(a1.numeric, a2.numeric);
40+
assertEquals(a1.protocol, a2.protocol);
41+
assertEquals(a1.roamingProtocol, a2.roamingProtocol);
42+
assertEquals(a1.types.length, a2.types.length);
43+
int i;
44+
for (i = 0; i < a1.types.length; i++) {
45+
assertEquals(a1.types[i], a2.types[i]);
46+
}
47+
}
48+
49+
@SmallTest
50+
public void testFromString() throws Exception {
51+
String[] dunTypes = {"DUN"};
52+
String[] mmsTypes = {"mms", "*"};
53+
54+
ApnSetting expected_apn;
55+
String testString;
56+
57+
// A real-world v1 example string.
58+
testString = "Vodafone IT,web.omnitel.it,,,,,,,,,222,10,,DUN";
59+
expected_apn = new ApnSetting(
60+
-1, "22210", "Vodafone IT", "web.omnitel.it", "", "",
61+
"", "", "", "", "", 0, dunTypes, "IP", "IP");
62+
assertApnSettingEqual(expected_apn, ApnSetting.fromString(testString));
63+
64+
// A v2 string.
65+
testString = "[ApnSettingV2] Name,apn,,,,,,,,,123,45,,mms|*,IPV6,IP";
66+
expected_apn = new ApnSetting(
67+
-1, "12345", "Name", "apn", "", "",
68+
"", "", "", "", "", 0, mmsTypes, "IPV6", "IP");
69+
assertApnSettingEqual(expected_apn, ApnSetting.fromString(testString));
70+
71+
// A v2 string with spaces.
72+
testString = "[ApnSettingV2] Name,apn, ,,,,,,,,123,45,,mms|*,IPV4V6, IP";
73+
expected_apn = new ApnSetting(
74+
-1, "12345", "Name", "apn", "", "",
75+
"", "", "", "", "", 0, mmsTypes, "IPV4V6", "IP");
76+
assertApnSettingEqual(expected_apn, ApnSetting.fromString(testString));
77+
78+
// Return null if insufficient fields given.
79+
testString = "[ApnSettingV2] Name,apn,,,,,,,,,123, 45,,mms|*";
80+
assertEquals(null, ApnSetting.fromString(testString));
81+
82+
testString = "Name,apn,,,,,,,,,123, 45,";
83+
assertEquals(null, ApnSetting.fromString(testString));
84+
85+
// Parse (incorrect) V2 format without the tag as V1.
86+
testString = "Name,apn,,,,,,,,,123, 45,,mms|*,IPV6";
87+
String[] incorrectTypes = {"mms|*", "IPV6"};
88+
expected_apn = new ApnSetting(
89+
-1, "12345", "Name", "apn", "", "",
90+
"", "", "", "", "", 0, incorrectTypes, "IP", "IP");
91+
assertApnSettingEqual(expected_apn, ApnSetting.fromString(testString));
92+
}
93+
94+
95+
@SmallTest
96+
public void testToString() throws Exception {
97+
String[] types = {"default", "*"};
98+
ApnSetting apn = new ApnSetting(
99+
99, "12345", "Name", "apn", "proxy", "port",
100+
"mmsc", "mmsproxy", "mmsport", "user", "password", 0,
101+
types, "IPV4V6", "IP");
102+
String expected = "[ApnSettingV2] Name, 99, 12345, apn, proxy, " +
103+
"mmsc, mmsproxy, mmsport, port, 0, default | *, " +
104+
"IPV4V6, IP";
105+
assertEquals(expected, apn.toString());
106+
}
107+
}
108+

0 commit comments

Comments
 (0)