Skip to content

Commit 49348e7

Browse files
author
Robert Greenwalt
committed
Fix Tethering settings.
Two issues. A mcc/mnc-driven overlay means that the config at boot may not be the config we wish to use - the sim card is read later which may switch the config. Changed to read the configuration each time rather than once at boot. Second, the secure-setting override was always trumping the resource config as we weren't discriminating between a not-set default and a real setting. This meant the config could never make DUN-required. bug:5495862 Change-Id: Icd4e90ac1d32bbb704c0ff9cc69e954fb0a0b58c
1 parent 11116b8 commit 49348e7

File tree

1 file changed

+42
-16
lines changed

1 file changed

+42
-16
lines changed

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

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,24 @@ public Tethering(Context context, INetworkManagementService nmService,
160160
mDhcpRange = DHCP_DEFAULT_RANGE;
161161
}
162162

163-
mTetherableUsbRegexs = context.getResources().getStringArray(
163+
// load device config info
164+
updateConfiguration();
165+
166+
// TODO - remove and rely on real notifications of the current iface
167+
mDnsServers = new String[2];
168+
mDnsServers[0] = DNS_DEFAULT_SERVER1;
169+
mDnsServers[1] = DNS_DEFAULT_SERVER2;
170+
}
171+
172+
void updateConfiguration() {
173+
mTetherableUsbRegexs = mContext.getResources().getStringArray(
164174
com.android.internal.R.array.config_tether_usb_regexs);
165-
mTetherableWifiRegexs = context.getResources().getStringArray(
175+
mTetherableWifiRegexs = mContext.getResources().getStringArray(
166176
com.android.internal.R.array.config_tether_wifi_regexs);
167-
mTetherableBluetoothRegexs = context.getResources().getStringArray(
177+
mTetherableBluetoothRegexs = mContext.getResources().getStringArray(
168178
com.android.internal.R.array.config_tether_bluetooth_regexs);
169-
int ifaceTypes[] = context.getResources().getIntArray(
179+
180+
int ifaceTypes[] = mContext.getResources().getIntArray(
170181
com.android.internal.R.array.config_tether_upstream_types);
171182
mUpstreamIfaceTypes = new ArrayList();
172183
for (int i : ifaceTypes) {
@@ -175,11 +186,6 @@ public Tethering(Context context, INetworkManagementService nmService,
175186

176187
// check if the upstream type list needs to be modified due to secure-settings
177188
checkDunRequired();
178-
179-
// TODO - remove and rely on real notifications of the current iface
180-
mDnsServers = new String[2];
181-
mDnsServers[0] = DNS_DEFAULT_SERVER1;
182-
mDnsServers[1] = DNS_DEFAULT_SERVER2;
183189
}
184190

185191
public void interfaceStatusChanged(String iface, boolean up) {
@@ -575,6 +581,7 @@ public int setUsbTethering(boolean enable) {
575581
}
576582

577583
public int[] getUpstreamIfaceTypes() {
584+
updateConfiguration();
578585
int values[] = new int[mUpstreamIfaceTypes.size()];
579586
Iterator<Integer> iterator = mUpstreamIfaceTypes.iterator();
580587
for (int i=0; i < mUpstreamIfaceTypes.size(); i++) {
@@ -584,11 +591,13 @@ public int[] getUpstreamIfaceTypes() {
584591
}
585592

586593
public void checkDunRequired() {
587-
int requiredApn = ((Settings.Secure.getInt(mContext.getContentResolver(),
588-
Settings.Secure.TETHER_DUN_REQUIRED, 0) == 1) ?
589-
ConnectivityManager.TYPE_MOBILE_DUN :
590-
ConnectivityManager.TYPE_MOBILE_HIPRI);
591-
if (mPreferredUpstreamMobileApn != requiredApn) {
594+
int secureSetting = Settings.Secure.getInt(mContext.getContentResolver(),
595+
Settings.Secure.TETHER_DUN_REQUIRED, 2);
596+
// 2 = not set, 0 = DUN not required, 1 = DUN required
597+
if (secureSetting != 2) {
598+
int requiredApn = (secureSetting == 1 ?
599+
ConnectivityManager.TYPE_MOBILE_DUN :
600+
ConnectivityManager.TYPE_MOBILE_HIPRI);
592601
if (requiredApn == ConnectivityManager.TYPE_MOBILE_DUN) {
593602
while (mUpstreamIfaceTypes.contains(MOBILE_TYPE)) {
594603
mUpstreamIfaceTypes.remove(MOBILE_TYPE);
@@ -610,7 +619,11 @@ public void checkDunRequired() {
610619
mUpstreamIfaceTypes.add(HIPRI_TYPE);
611620
}
612621
}
613-
mPreferredUpstreamMobileApn = requiredApn;
622+
}
623+
if (mUpstreamIfaceTypes.contains(DUN_TYPE)) {
624+
mPreferredUpstreamMobileApn = ConnectivityManager.TYPE_MOBILE_DUN;
625+
} else {
626+
mPreferredUpstreamMobileApn = ConnectivityManager.TYPE_MOBILE_HIPRI;
614627
}
615628
}
616629

@@ -1251,6 +1264,15 @@ protected void chooseUpstreamType(boolean tryCell) {
12511264
int upType = ConnectivityManager.TYPE_NONE;
12521265
String iface = null;
12531266

1267+
updateConfiguration();
1268+
1269+
if (VDBG) {
1270+
Log.d(TAG, "chooseUpstreamType has upstream iface types:");
1271+
for (Integer netType : mUpstreamIfaceTypes) {
1272+
Log.d(TAG, " " + netType);
1273+
}
1274+
}
1275+
12541276
for (Integer netType : mUpstreamIfaceTypes) {
12551277
NetworkInfo info = null;
12561278
try {
@@ -1314,7 +1336,6 @@ public boolean processMessage(Message message) {
13141336
boolean retValue = true;
13151337
switch (message.what) {
13161338
case CMD_TETHER_MODE_REQUESTED:
1317-
checkDunRequired();
13181339
TetherInterfaceSM who = (TetherInterfaceSM)message.obj;
13191340
if (VDBG) Log.d(TAG, "Tether Mode requested by " + who.toString());
13201341
mNotifyList.add(who);
@@ -1487,6 +1508,11 @@ public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
14871508
return;
14881509
}
14891510

1511+
pw.println("mUpstreamIfaceTypes: ");
1512+
for (Integer netType : mUpstreamIfaceTypes) {
1513+
pw.println(" " + netType);
1514+
}
1515+
14901516
pw.println();
14911517
pw.println("Tether state:");
14921518
synchronized (mIfaces) {

0 commit comments

Comments
 (0)