Skip to content

Commit c8711ca

Browse files
Robert GreenwaltAndroid (Google) Code Review
authored andcommitted
Merge "Stop using shared DUN APN when tethering stops." into ics-mr1
2 parents fc19160 + 2384386 commit c8711ca

File tree

7 files changed

+146
-39
lines changed

7 files changed

+146
-39
lines changed

services/java/com/android/server/ConnectivityService.java

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,9 +1031,14 @@ public int startUsingNetworkFeature(int networkType, String feature,
10311031
if ((ni.isConnectedOrConnecting() == true) &&
10321032
!network.isTeardownRequested()) {
10331033
if (ni.isConnected() == true) {
1034-
// add the pid-specific dns
1035-
handleDnsConfigurationChange(usedNetworkType);
1036-
if (VDBG) log("special network already active");
1034+
final long token = Binder.clearCallingIdentity();
1035+
try {
1036+
// add the pid-specific dns
1037+
handleDnsConfigurationChange(usedNetworkType);
1038+
if (VDBG) log("special network already active");
1039+
} finally {
1040+
Binder.restoreCallingIdentity(token);
1041+
}
10371042
return Phone.APN_ALREADY_ACTIVE;
10381043
}
10391044
if (VDBG) log("special network already connecting");
@@ -1221,6 +1226,7 @@ public boolean requestRouteToHostAddress(int networkType, byte[] hostAddress) {
12211226
}
12221227

12231228
if (!ConnectivityManager.isNetworkTypeValid(networkType)) {
1229+
if (DBG) log("requestRouteToHostAddress on invalid network: " + networkType);
12241230
return false;
12251231
}
12261232
NetworkStateTracker tracker = mNetTrackers[networkType];
@@ -1233,11 +1239,16 @@ public boolean requestRouteToHostAddress(int networkType, byte[] hostAddress) {
12331239
}
12341240
return false;
12351241
}
1242+
final long token = Binder.clearCallingIdentity();
12361243
try {
12371244
InetAddress addr = InetAddress.getByAddress(hostAddress);
12381245
LinkProperties lp = tracker.getLinkProperties();
12391246
return addRouteToAddress(lp, addr);
1240-
} catch (UnknownHostException e) {}
1247+
} catch (UnknownHostException e) {
1248+
if (DBG) log("requestRouteToHostAddress got " + e.toString());
1249+
} finally {
1250+
Binder.restoreCallingIdentity(token);
1251+
}
12411252
return false;
12421253
}
12431254

@@ -1277,7 +1288,10 @@ private boolean modifyRouteToAddress(LinkProperties lp, InetAddress addr, boolea
12771288

12781289
private boolean modifyRoute(String ifaceName, LinkProperties lp, RouteInfo r, int cycleCount,
12791290
boolean doAdd, boolean toDefaultTable) {
1280-
if ((ifaceName == null) || (lp == null) || (r == null)) return false;
1291+
if ((ifaceName == null) || (lp == null) || (r == null)) {
1292+
if (DBG) log("modifyRoute got unexpected null: " + ifaceName + ", " + lp + ", " + r);
1293+
return false;
1294+
}
12811295

12821296
if (cycleCount > MAX_HOSTROUTE_CYCLE_COUNT) {
12831297
loge("Error modifying route - too much recursion");
@@ -1309,7 +1323,7 @@ private boolean modifyRoute(String ifaceName, LinkProperties lp, RouteInfo r, in
13091323
}
13101324
} catch (Exception e) {
13111325
// never crash - catch them all
1312-
if (VDBG) loge("Exception trying to add a route: " + e);
1326+
if (DBG) loge("Exception trying to add a route: " + e);
13131327
return false;
13141328
}
13151329
} else {
@@ -1323,7 +1337,7 @@ private boolean modifyRoute(String ifaceName, LinkProperties lp, RouteInfo r, in
13231337
mNetd.removeRoute(ifaceName, r);
13241338
} catch (Exception e) {
13251339
// never crash - catch them all
1326-
if (VDBG) loge("Exception trying to remove a route: " + e);
1340+
if (DBG) loge("Exception trying to remove a route: " + e);
13271341
return false;
13281342
}
13291343
} else {
@@ -1335,7 +1349,7 @@ private boolean modifyRoute(String ifaceName, LinkProperties lp, RouteInfo r, in
13351349
mNetd.removeSecondaryRoute(ifaceName, r);
13361350
} catch (Exception e) {
13371351
// never crash - catch them all
1338-
if (VDBG) loge("Exception trying to remove a route: " + e);
1352+
if (DBG) loge("Exception trying to remove a route: " + e);
13391353
return false;
13401354
}
13411355
}
@@ -2004,7 +2018,7 @@ private boolean updateRoutes(LinkProperties newLp, LinkProperties curLp,
20042018
mNetd.removeRoute(ifaceName, r);
20052019
} catch (Exception e) {
20062020
// never crash - catch them all
2007-
if (VDBG) loge("Exception trying to remove a route: " + e);
2021+
if (DBG) loge("Exception trying to remove a route: " + e);
20082022
}
20092023
}
20102024
}
@@ -2218,7 +2232,7 @@ private boolean updateDns(String network, String iface,
22182232
mNetd.setDnsServersForInterface(iface, NetworkUtils.makeStrings(dnses));
22192233
mNetd.setDefaultInterfaceForDns(iface);
22202234
} catch (Exception e) {
2221-
if (VDBG) loge("exception setting default dns interface: " + e);
2235+
if (DBG) loge("exception setting default dns interface: " + e);
22222236
}
22232237
}
22242238
if (!domains.equals(SystemProperties.get("net.dns.search"))) {
@@ -2248,7 +2262,7 @@ private void handleDnsConfigurationChange(int netType) {
22482262
mNetd.setDnsServersForInterface(p.getInterfaceName(),
22492263
NetworkUtils.makeStrings(dnses));
22502264
} catch (Exception e) {
2251-
if (VDBG) loge("exception setting dns servers: " + e);
2265+
if (DBG) loge("exception setting dns servers: " + e);
22522266
}
22532267
// set per-pid dns for attached secondary nets
22542268
List pids = mNetRequestersPids[netType];

telephony/java/com/android/internal/telephony/DataConnection.java

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public abstract class DataConnection extends StateMachine {
6868
private List<ApnContext> mApnList = null;
6969
PendingIntent mReconnectIntent = null;
7070

71+
private DataConnectionTracker mDataConnectionTracker = null;
72+
7173
/**
7274
* Used internally for saving connecting parameters.
7375
*/
@@ -202,6 +204,7 @@ public int getRetryOverride() {
202204
protected static final int EVENT_DEACTIVATE_DONE = BASE + 3;
203205
protected static final int EVENT_DISCONNECT = BASE + 4;
204206
protected static final int EVENT_RIL_CONNECTED = BASE + 5;
207+
protected static final int EVENT_DISCONNECT_ALL = BASE + 6;
205208

206209
//***** Tag IDs for EventLog
207210
protected static final int EVENT_LOG_BAD_DNS_ADDRESS = 50100;
@@ -234,10 +237,12 @@ public int getRetryOverride() {
234237

235238

236239
//***** Constructor
237-
protected DataConnection(PhoneBase phone, String name, int id, RetryManager rm) {
240+
protected DataConnection(PhoneBase phone, String name, int id, RetryManager rm,
241+
DataConnectionTracker dct) {
238242
super(name);
239243
if (DBG) log("DataConnection constructor E");
240244
this.phone = phone;
245+
this.mDataConnectionTracker = dct;
241246
mId = id;
242247
mRetryMgr = rm;
243248
this.cid = -1;
@@ -316,18 +321,37 @@ private void notifyConnectCompleted(ConnectionParams cp, FailCause cause) {
316321
*
317322
* @param dp is the DisconnectParams.
318323
*/
319-
private void notifyDisconnectCompleted(DisconnectParams dp) {
324+
private void notifyDisconnectCompleted(DisconnectParams dp, boolean sendAll) {
320325
if (VDBG) log("NotifyDisconnectCompleted");
321326

327+
ApnContext alreadySent = null;
328+
String reason = null;
329+
322330
if (dp.onCompletedMsg != null) {
331+
// Get ApnContext, but only valid on GSM devices this is a string on CDMA devices.
323332
Message msg = dp.onCompletedMsg;
333+
if (msg.obj instanceof ApnContext) {
334+
alreadySent = (ApnContext)msg.obj;
335+
}
336+
reason = dp.reason;
324337
if (VDBG) {
325338
log(String.format("msg=%s msg.obj=%s", msg.toString(),
326339
((msg.obj instanceof String) ? (String) msg.obj : "<no-reason>")));
327340
}
328341
AsyncResult.forMessage(msg);
329342
msg.sendToTarget();
330343
}
344+
if (sendAll) {
345+
for (ApnContext a : mApnList) {
346+
if (a == alreadySent) continue;
347+
if (reason != null) a.setReason(reason);
348+
Message msg = mDataConnectionTracker.obtainMessage(
349+
DataConnectionTracker.EVENT_DISCONNECT_DONE, a);
350+
AsyncResult.forMessage(msg);
351+
msg.sendToTarget();
352+
}
353+
}
354+
331355
if (DBG) log("NotifyDisconnectCompleted DisconnectParams=" + dp);
332356
}
333357

@@ -706,6 +730,13 @@ public boolean processMessage(Message msg) {
706730
deferMessage(msg);
707731
break;
708732

733+
case EVENT_DISCONNECT_ALL:
734+
if (DBG) {
735+
log("DcDefaultState deferring msg.what=EVENT_DISCONNECT_ALL" + mRefCount);
736+
}
737+
deferMessage(msg);
738+
break;
739+
709740
case EVENT_RIL_CONNECTED:
710741
ar = (AsyncResult)msg.obj;
711742
if (ar.exception == null) {
@@ -771,7 +802,7 @@ public void enter() {
771802
}
772803
if (mDisconnectParams != null) {
773804
if (VDBG) log("DcInactiveState: enter notifyDisconnectCompleted");
774-
notifyDisconnectCompleted(mDisconnectParams);
805+
notifyDisconnectCompleted(mDisconnectParams, true);
775806
}
776807
clearSettings();
777808
}
@@ -812,7 +843,13 @@ public boolean processMessage(Message msg) {
812843

813844
case EVENT_DISCONNECT:
814845
if (DBG) log("DcInactiveState: msg.what=EVENT_DISCONNECT");
815-
notifyDisconnectCompleted((DisconnectParams)msg.obj);
846+
notifyDisconnectCompleted((DisconnectParams)msg.obj, false);
847+
retVal = HANDLED;
848+
break;
849+
850+
case EVENT_DISCONNECT_ALL:
851+
if (DBG) log("DcInactiveState: msg.what=EVENT_DISCONNECT_ALL");
852+
notifyDisconnectCompleted((DisconnectParams)msg.obj, false);
816853
retVal = HANDLED;
817854
break;
818855

@@ -989,12 +1026,24 @@ public boolean processMessage(Message msg) {
9891026
transitionTo(mDisconnectingState);
9901027
} else {
9911028
if (msg.obj != null) {
992-
notifyDisconnectCompleted((DisconnectParams) msg.obj);
1029+
notifyDisconnectCompleted((DisconnectParams) msg.obj, false);
9931030
}
9941031
}
9951032
retVal = HANDLED;
9961033
break;
9971034

1035+
case EVENT_DISCONNECT_ALL:
1036+
if (DBG) {
1037+
log("DcActiveState msg.what=EVENT_DISCONNECT_ALL RefCount=" + mRefCount);
1038+
}
1039+
mRefCount = 0;
1040+
DisconnectParams dp = (DisconnectParams) msg.obj;
1041+
dp.tag = mTag;
1042+
tearDownData(dp);
1043+
transitionTo(mDisconnectingState);
1044+
retVal = HANDLED;
1045+
break;
1046+
9981047
default:
9991048
if (VDBG) {
10001049
log("DcActiveState not handled msg.what=0x" +
@@ -1124,4 +1173,16 @@ public void bringUp(Message onCompletedMsg, ApnSetting apn) {
11241173
public void tearDown(String reason, Message onCompletedMsg) {
11251174
sendMessage(obtainMessage(EVENT_DISCONNECT, new DisconnectParams(reason, onCompletedMsg)));
11261175
}
1176+
1177+
/**
1178+
* Tear down the connection through the apn on the network. Ignores refcount and
1179+
* and always tears down.
1180+
*
1181+
* @param onCompletedMsg is sent with its msg.obj as an AsyncResult object.
1182+
* With AsyncResult.userObj set to the original msg.obj.
1183+
*/
1184+
public void tearDownAll(String reason, Message onCompletedMsg) {
1185+
sendMessage(obtainMessage(EVENT_DISCONNECT_ALL,
1186+
new DisconnectParams(reason, onCompletedMsg)));
1187+
}
11271188
}

telephony/java/com/android/internal/telephony/DataConnectionTracker.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,8 @@ protected void onEnableApn(int apnId, int enabled) {
10301030
}
10311031
}
10321032
if (didDisable) {
1033-
if (enabledCount == 0) {
1033+
if ((enabledCount == 0) || (apnId == APN_DUN_ID)) {
1034+
mRequestedApnType = Phone.APN_TYPE_DEFAULT;
10341035
onCleanUpConnection(true, apnId, Phone.REASON_DATA_DISABLED);
10351036
}
10361037

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import android.util.Log;
2121

2222
import com.android.internal.telephony.DataConnection;
23+
import com.android.internal.telephony.DataConnectionTracker;
2324
import com.android.internal.telephony.Phone;
2425
import com.android.internal.telephony.RILConstants;
2526
import com.android.internal.telephony.RetryManager;
@@ -32,8 +33,9 @@ public class CdmaDataConnection extends DataConnection {
3233
private static final String LOG_TAG = "CDMA";
3334

3435
// ***** Constructor
35-
private CdmaDataConnection(CDMAPhone phone, String name, int id, RetryManager rm) {
36-
super(phone, name, id, rm);
36+
private CdmaDataConnection(CDMAPhone phone, String name, int id, RetryManager rm,
37+
DataConnectionTracker dct) {
38+
super(phone, name, id, rm, dct);
3739
}
3840

3941
/**
@@ -44,12 +46,13 @@ private CdmaDataConnection(CDMAPhone phone, String name, int id, RetryManager rm
4446
* @param rm the RetryManager
4547
* @return CdmaDataConnection that was created.
4648
*/
47-
static CdmaDataConnection makeDataConnection(CDMAPhone phone, int id, RetryManager rm) {
49+
static CdmaDataConnection makeDataConnection(CDMAPhone phone, int id, RetryManager rm,
50+
DataConnectionTracker dct) {
4851
synchronized (mCountLock) {
4952
mCount += 1;
5053
}
5154
CdmaDataConnection cdmaDc = new CdmaDataConnection(phone, "CdmaDC-" + mCount,
52-
id, rm);
55+
id, rm, dct);
5356
cdmaDc.start();
5457
if (DBG) cdmaDc.log("Made " + cdmaDc.getName());
5558
return cdmaDc;

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public final class CdmaDataConnectionTracker extends DataConnectionTracker {
140140

141141
@Override
142142
public void dispose() {
143-
cleanUpConnection(false, null);
143+
cleanUpConnection(false, null, false);
144144

145145
super.dispose();
146146

@@ -295,7 +295,7 @@ private boolean trySetupData(String reason) {
295295
* @param tearDown true if the underlying DataConnection should be disconnected.
296296
* @param reason for the clean up.
297297
*/
298-
private void cleanUpConnection(boolean tearDown, String reason) {
298+
private void cleanUpConnection(boolean tearDown, String reason, boolean doAll) {
299299
if (DBG) log("cleanUpConnection: reason: " + reason);
300300

301301
// Clear the reconnect alarm, if set.
@@ -315,9 +315,15 @@ private void cleanUpConnection(boolean tearDown, String reason) {
315315
DataConnectionAc dcac =
316316
mDataConnectionAsyncChannels.get(conn.getDataConnectionId());
317317
if (tearDown) {
318-
if (DBG) log("cleanUpConnection: teardown, call conn.disconnect");
319-
conn.tearDown(reason, obtainMessage(EVENT_DISCONNECT_DONE,
320-
conn.getDataConnectionId(), 0, reason));
318+
if (doAll) {
319+
if (DBG) log("cleanUpConnection: teardown, conn.tearDownAll");
320+
conn.tearDownAll(reason, obtainMessage(EVENT_DISCONNECT_DONE,
321+
conn.getDataConnectionId(), 0, reason));
322+
} else {
323+
if (DBG) log("cleanUpConnection: teardown, conn.tearDown");
324+
conn.tearDown(reason, obtainMessage(EVENT_DISCONNECT_DONE,
325+
conn.getDataConnectionId(), 0, reason));
326+
}
321327
notificationDeferred = true;
322328
} else {
323329
if (DBG) log("cleanUpConnection: !tearDown, call conn.resetSynchronously");
@@ -599,7 +605,7 @@ protected void onNVReady() {
599605
@Override
600606
protected void onEnableNewApn() {
601607
// No mRequestedApnType check; only one connection is supported
602-
cleanUpConnection(true, Phone.REASON_APN_SWITCHED);
608+
cleanUpConnection(true, Phone.REASON_APN_SWITCHED, false);
603609
}
604610

605611
/**
@@ -781,13 +787,13 @@ protected void onVoiceCallEnded() {
781787
@Override
782788
protected void onCleanUpConnection(boolean tearDown, int apnId, String reason) {
783789
// No apnId check; only one connection is supported
784-
cleanUpConnection(tearDown, reason);
790+
cleanUpConnection(tearDown, reason, (apnId == APN_DUN_ID));
785791
}
786792

787793
@Override
788794
protected void onCleanUpAllConnections(String cause) {
789795
// Only one CDMA connection is supported
790-
cleanUpConnection(true, cause);
796+
cleanUpConnection(true, cause, false);
791797
}
792798

793799
private void createAllDataConnectionList() {
@@ -806,7 +812,7 @@ private void createAllDataConnectionList() {
806812
}
807813

808814
int id = mUniqueIdGenerator.getAndIncrement();
809-
dataConn = CdmaDataConnection.makeDataConnection(mCdmaPhone, id, rm);
815+
dataConn = CdmaDataConnection.makeDataConnection(mCdmaPhone, id, rm, this);
810816
mDataConnections.put(id, dataConn);
811817
DataConnectionAc dcac = new DataConnectionAc(dataConn, LOG_TAG);
812818
int status = dcac.fullyConnectSync(mPhone.getContext(), this, dataConn.getHandler());
@@ -833,7 +839,7 @@ private void onCdmaDataDetached() {
833839
notifyDataConnection(Phone.REASON_CDMA_DATA_DETACHED);
834840
} else {
835841
if (mState == State.FAILED) {
836-
cleanUpConnection(false, Phone.REASON_CDMA_DATA_DETACHED);
842+
cleanUpConnection(false, Phone.REASON_CDMA_DATA_DETACHED, false);
837843
mDataConnections.get(0).resetRetryCount();
838844

839845
CdmaCellLocation loc = (CdmaCellLocation)(mPhone.getCellLocation());
@@ -912,7 +918,7 @@ protected void onDataStateChanged(AsyncResult ar) {
912918
log("onDataStateChanged: No active connection"
913919
+ "state is CONNECTED, disconnecting/cleanup");
914920
writeEventLogCdmaDataDrop();
915-
cleanUpConnection(true, null);
921+
cleanUpConnection(true, null, false);
916922
return;
917923
}
918924

0 commit comments

Comments
 (0)