Skip to content

Commit f9610b3

Browse files
Robert GreenwaltAndroid (Google) Code Review
authored andcommitted
Merge "Make the DUN apn data secure." into froyo
2 parents 4b33092 + 77b32dd commit f9610b3

File tree

5 files changed

+90
-5
lines changed

5 files changed

+90
-5
lines changed

core/java/android/provider/Settings.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2367,6 +2367,24 @@ public static final String getBluetoothA2dpSinkPriorityKey(String address) {
23672367
*/
23682368
public static final String TETHER_SUPPORTED = "tether_supported";
23692369

2370+
/**
2371+
* Used to require DUN APN on the device or not - defaults to a build config value
2372+
* which defaults to false
2373+
* @hide
2374+
*/
2375+
public static final String TETHER_DUN_REQUIRED = "tether_dun_required";
2376+
2377+
/**
2378+
* Used to hold a gservices-provisioned apn value for DUN. If set, or the
2379+
* corresponding build config values are set it will override the APN DB
2380+
* values.
2381+
* Consists of a comma seperated list of strings:
2382+
* "name,apn,proxy,port,username,password,server,mmsc,mmsproxy,mmsport,mcc,mnc,auth,type"
2383+
* note that empty fields can be ommitted: "name,apn,,,,,,,,,310,260,,DUN"
2384+
* @hide
2385+
*/
2386+
public static final String TETHER_DUN_APN = "tether_dun_apn";
2387+
23702388
/**
23712389
* No longer supported.
23722390
*/

core/res/res/values/config.xml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,18 @@
9191
<string-array translatable="false" name="config_tether_upstream_regexs">
9292
</string-array>
9393

94-
<!-- Boolean indicating if we require the use of DUN on mobile for tethering -->
95-
<bool translatable="false" name="config_tether_dun_required">true</bool>
94+
<!-- Boolean indicating if we require the use of DUN on mobile for tethering.
95+
Note that this defaults to false so that if you move to a carrier that
96+
hasn't configured anything tethering will still work. If you'd rather
97+
make the device untetherable on unconfigured devices, set to true -->
98+
<bool translatable="false" name="config_tether_dun_required">false</bool>
99+
100+
<!-- String containing the apn value for tethering. May be overriden by secure settings
101+
TETHER_DUN_APN. Value is a comma separated series of strings:
102+
"name,apn,proxy,port,username,password,server,mmsc,mmsproxy,mmsport,mcc,mnc,auth,type"
103+
note that empty fields can be ommitted: "name,apn,,,,,,,,,310,260,,DUN" -->
104+
<string translatable="false" name="config_tether_apndata"></string>
105+
96106

97107
<!-- Flag indicating whether the keyguard should be bypassed when
98108
the slider is open. This can be set or unset depending how easily

services/java/com/android/server/connectivity/Tethering.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
9898
private static final String DNS_DEFAULT_SERVER1 = "8.8.8.8";
9999
private static final String DNS_DEFAULT_SERVER2 = "4.2.2.2";
100100

101+
// resampled each time we turn on tethering - used as cache for settings/config-val
101102
private boolean mDunRequired; // configuration info - must use DUN apn on 3g
102103

103104
private HierarchicalStateMachine mTetherMasterSM;
@@ -157,8 +158,7 @@ public Tethering(Context context, Looper looper) {
157158
mDhcpRange[2] = DHCP_DEFAULT_RANGE2_START;
158159
mDhcpRange[3] = DHCP_DEFAULT_RANGE2_STOP;
159160
}
160-
mDunRequired = context.getResources().getBoolean(
161-
com.android.internal.R.bool.config_tether_dun_required);
161+
mDunRequired = false; // resample when we turn on
162162

163163
mTetherableUsbRegexs = context.getResources().getStringArray(
164164
com.android.internal.R.array.config_tether_usb_regexs);
@@ -555,7 +555,11 @@ public String[] getUpstreamIfaceRegexs() {
555555
}
556556

557557
public boolean isDunRequired() {
558-
return mDunRequired;
558+
boolean defaultVal = mContext.getResources().getBoolean(
559+
com.android.internal.R.bool.config_tether_dun_required);
560+
boolean result = (Settings.Secure.getInt(mContext.getContentResolver(),
561+
Settings.Secure.TETHER_DUN_REQUIRED, (defaultVal ? 1 : 0)) == 1);
562+
return result;
559563
}
560564

561565
public String[] getTetheredIfaces() {
@@ -1263,6 +1267,7 @@ public boolean processMessage(Message message) {
12631267
boolean retValue = true;
12641268
switch (message.what) {
12651269
case CMD_TETHER_MODE_REQUESTED:
1270+
mDunRequired = isDunRequired();
12661271
TetherInterfaceSM who = (TetherInterfaceSM)message.obj;
12671272
Log.d(TAG, "Tether Mode requested by " + who.toString());
12681273
mNotifyList.add(who);

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,35 @@ public ApnSetting(int id, String numeric, String carrier, String apn, String pro
5555
this.types = types;
5656
}
5757

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...
72+
public static ApnSetting fromString(String data) {
73+
if (data == null) return null;
74+
String[] a = data.split("\\s*,\\s*");
75+
if (a.length < 14) return null;
76+
int authType = 0;
77+
try {
78+
authType = Integer.parseInt(a[12]);
79+
} catch (Exception e) {
80+
}
81+
String[] typeArray = new String[a.length - 13];
82+
System.arraycopy(a, 13, typeArray, 0, a.length - 13);
83+
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);
85+
}
86+
5887
public String toString() {
5988
StringBuilder sb = new StringBuilder();
6089
sb.append(carrier)

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import android.util.EventLog;
5050
import android.util.Log;
5151

52+
import com.android.internal.R;
5253
import com.android.internal.telephony.DataCallState;
5354
import com.android.internal.telephony.DataConnection;
5455
import com.android.internal.telephony.DataConnectionTracker;
@@ -366,6 +367,10 @@ protected boolean isApnTypeActive(String type) {
366367

367368
@Override
368369
protected boolean isApnTypeAvailable(String type) {
370+
if (type.equals(Phone.APN_TYPE_DUN)) {
371+
return (fetchDunApn() != null);
372+
}
373+
369374
if (allApns != null) {
370375
for (ApnSetting apn : allApns) {
371376
if (apn.canHandleType(type)) {
@@ -1303,13 +1308,31 @@ private void destroyAllPdpList() {
13031308
}
13041309
}
13051310

1311+
private ApnSetting fetchDunApn() {
1312+
Context c = phone.getContext();
1313+
String apnData = Settings.Secure.getString(c.getContentResolver(),
1314+
Settings.Secure.TETHER_DUN_APN);
1315+
ApnSetting dunSetting = ApnSetting.fromString(apnData);
1316+
if (dunSetting != null) return dunSetting;
1317+
1318+
apnData = c.getResources().getString(R.string.config_tether_apndata);
1319+
return ApnSetting.fromString(apnData);
1320+
}
1321+
13061322
/**
13071323
*
13081324
* @return waitingApns list to be used to create PDP
13091325
* error when waitingApns.isEmpty()
13101326
*/
13111327
private ArrayList<ApnSetting> buildWaitingApns() {
13121328
ArrayList<ApnSetting> apnList = new ArrayList<ApnSetting>();
1329+
1330+
if (mRequestedApnType.equals(Phone.APN_TYPE_DUN)) {
1331+
ApnSetting dun = fetchDunApn();
1332+
if (dun != null) apnList.add(dun);
1333+
return apnList;
1334+
}
1335+
13131336
String operator = mGsmPhone.mSIMRecords.getSIMOperatorNumeric();
13141337

13151338
if (mRequestedApnType.equals(Phone.APN_TYPE_DEFAULT)) {

0 commit comments

Comments
 (0)