Skip to content

Commit 259db3f

Browse files
Wink SavilleAndroid (Google) Code Review
authored andcommitted
Merge "Have all connections disconnected before turning off radio." into ics-factoryrom
2 parents 1afeea0 + ea0d54b commit 259db3f

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

telephony/java/com/android/internal/telephony/ApnContext.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ public synchronized DataConnectionTracker.State getState() {
154154
return mState;
155155
}
156156

157+
public boolean isDisconnected() {
158+
DataConnectionTracker.State currentState = getState();
159+
return ((currentState == DataConnectionTracker.State.IDLE) ||
160+
currentState == DataConnectionTracker.State.FAILED);
161+
}
162+
157163
public synchronized void setReason(String reason) {
158164
if (DBG) {
159165
log("set reason as " + reason + ", for type " + mApnType + ",current state " + mState);

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -787,9 +787,7 @@ private void cleanUpConnection(boolean tearDown, ApnContext apnContext) {
787787
}
788788
DataConnectionAc dcac = apnContext.getDataConnectionAc();
789789
if (tearDown) {
790-
boolean isConnected = (apnContext.getState() != State.IDLE
791-
&& apnContext.getState() != State.FAILED);
792-
if (!isConnected) {
790+
if (apnContext.isDisconnected()) {
793791
// The request is tearDown and but ApnContext is not connected.
794792
// If apnContext is not enabled anymore, break the linkage to the DCAC/DC.
795793
apnContext.setState(State.IDLE);
@@ -1019,11 +1017,9 @@ private boolean setupData(ApnContext apnContext) {
10191017
*/
10201018
private void onApnChanged() {
10211019
// TODO: How to handle when multiple APNs are active?
1022-
boolean isConnected;
10231020

10241021
ApnContext defaultApnContext = mApnContexts.get(Phone.APN_TYPE_DEFAULT);
1025-
isConnected = (defaultApnContext.getState() != State.IDLE
1026-
&& defaultApnContext.getState() != State.FAILED);
1022+
boolean defaultApnIsDisconnected = defaultApnContext.isDisconnected();
10271023

10281024
if (mPhone instanceof GSMPhone) {
10291025
// The "current" may no longer be valid. MMS depends on this to send properly. TBD
@@ -1034,8 +1030,8 @@ private void onApnChanged() {
10341030
// match the current operator.
10351031
if (DBG) log("onApnChanged: createAllApnList and cleanUpAllConnections");
10361032
createAllApnList();
1037-
cleanUpAllConnections(isConnected, Phone.REASON_APN_CHANGED);
1038-
if (!isConnected) {
1033+
cleanUpAllConnections(!defaultApnIsDisconnected, Phone.REASON_APN_CHANGED);
1034+
if (defaultApnIsDisconnected) {
10391035
setupDataOnReadyApns(Phone.REASON_APN_CHANGED);
10401036
}
10411037
}
@@ -1885,7 +1881,7 @@ protected void onDisconnectDone(int connId, AsyncResult ar) {
18851881

18861882
// if all data connection are gone, check whether Airplane mode request was
18871883
// pending.
1888-
if (!isConnected()) {
1884+
if (isDisconnected()) {
18891885
if (mPhone.getServiceStateTracker().processPendingRadioPowerOffAfterDataOff()) {
18901886
// Radio will be turned off. No need to retry data setup
18911887
apnContext.setApnSetting(null);
@@ -1957,12 +1953,25 @@ protected void onCleanUpConnection(boolean tearDown, int apnId, String reason) {
19571953
protected boolean isConnected() {
19581954
for (ApnContext apnContext : mApnContexts.values()) {
19591955
if (apnContext.getState() == State.CONNECTED) {
1960-
return true;
1956+
// At least one context is connected, return true
1957+
return true;
19611958
}
19621959
}
1960+
// There are not any contexts connected, return false
19631961
return false;
19641962
}
19651963

1964+
protected boolean isDisconnected() {
1965+
for (ApnContext apnContext : mApnContexts.values()) {
1966+
if (!apnContext.isDisconnected()) {
1967+
// At least one context was not disconnected return false
1968+
return false;
1969+
}
1970+
}
1971+
// All contexts were disconnected so return true
1972+
return true;
1973+
}
1974+
19661975
@Override
19671976
protected void notifyDataConnection(String reason) {
19681977
if (DBG) log("notifyDataConnection: reason=" + reason);

0 commit comments

Comments
 (0)