Skip to content

Commit f186b07

Browse files
Wink SavilleThe Android Automerger
authored andcommitted
Preserve retryCount when retrying.
Bug: 6529189 Change-Id: I743aed08aa161d91899aeb2ccacffcd224e48c0a
1 parent f48658a commit f186b07

File tree

5 files changed

+100
-28
lines changed

5 files changed

+100
-28
lines changed

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public class ApnContext {
5050

5151
String mReason;
5252

53+
int mRetryCount;
54+
5355
/**
5456
* user/app requested connection on this APN
5557
*/
@@ -64,6 +66,7 @@ public ApnContext(String apnType, String logTag) {
6466
mApnType = apnType;
6567
mState = DataConnectionTracker.State.IDLE;
6668
setReason(Phone.REASON_DATA_ENABLED);
69+
setRetryCount(0);
6770
mDataEnabled = new AtomicBoolean(false);
6871
mDependencyMet = new AtomicBoolean(true);
6972
mWaitingApnsPermanentFailureCountDown = new AtomicInteger(0);
@@ -182,6 +185,21 @@ public synchronized String getReason() {
182185
return mReason;
183186
}
184187

188+
public synchronized void setRetryCount(int retryCount) {
189+
if (DBG) {
190+
log("setRetryCount: " + retryCount);
191+
}
192+
mRetryCount = retryCount;
193+
DataConnection dc = mDataConnection;
194+
if (dc != null) {
195+
dc.setRetryCount(retryCount);
196+
}
197+
}
198+
199+
public synchronized int getRetryCount() {
200+
return mRetryCount;
201+
}
202+
185203
public boolean isReady() {
186204
return mDataEnabled.get() && mDependencyMet.get();
187205
}
@@ -214,8 +232,8 @@ public String toString() {
214232
return "{mApnType=" + mApnType + " mState=" + getState() + " mWaitingApns=" + mWaitingApns +
215233
" mWaitingApnsPermanentFailureCountDown=" + mWaitingApnsPermanentFailureCountDown +
216234
" mApnSetting=" + mApnSetting + " mDataConnectionAc=" + mDataConnectionAc +
217-
" mReason=" + mReason + " mDataEnabled=" + mDataEnabled +
218-
" mDependencyMet=" + mDependencyMet + "}";
235+
" mReason=" + mReason + " mRetryCount=" + mRetryCount +
236+
" mDataEnabled=" + mDataEnabled + " mDependencyMet=" + mDependencyMet + "}";
219237
}
220238

221239
protected void log(String s) {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,14 @@ public int getRetryCount() {
425425
return mRetryMgr.getRetryCount();
426426
}
427427

428+
/**
429+
* set retry manager retryCount
430+
*/
431+
public void setRetryCount(int retryCount) {
432+
if (DBG) log("setRetryCount: " + retryCount);
433+
mRetryMgr.setRetryCount(retryCount);
434+
}
435+
428436
/**
429437
* @return retry manager retryTimer
430438
*/

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ public enum Activity {
303303
new HashMap<String, Integer>();
304304

305305
/** Phone.APN_TYPE_* ===> ApnContext */
306-
protected ConcurrentHashMap<String, ApnContext> mApnContexts;
306+
protected ConcurrentHashMap<String, ApnContext> mApnContexts =
307+
new ConcurrentHashMap<String, ApnContext>();
307308

308309
/* Currently active APN */
309310
protected ApnSetting mActiveApn;
@@ -1203,6 +1204,9 @@ protected String getReryConfig(boolean forDefault) {
12031204
}
12041205

12051206
protected void resetAllRetryCounts() {
1207+
for (ApnContext ac : mApnContexts.values()) {
1208+
ac.setRetryCount(0);
1209+
}
12061210
for (DataConnection dc : mDataConnections.values()) {
12071211
dc.resetRetryCount();
12081212
}

telephony/java/com/android/internal/telephony/RetryManager.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
* {@hide}
7474
*/
7575
public class RetryManager {
76-
static public final String LOG_TAG = "RetryManager";
76+
static public final String LOG_TAG = "GSM";
7777
static public final boolean DBG = true;
7878
static public final boolean VDBG = false;
7979

@@ -304,7 +304,6 @@ public void increaseRetryCount() {
304304

305305
/**
306306
* Set retry count to the specified value
307-
* and turns off retrying forever.
308307
*/
309308
public void setRetryCount(int count) {
310309
mRetryCount = count;
@@ -316,10 +315,17 @@ public void setRetryCount(int count) {
316315
mRetryCount = 0;
317316
}
318317

319-
mRetryForever = false;
320318
if (DBG) log("setRetryCount: " + mRetryCount);
321319
}
322320

321+
/**
322+
* Set retry forever to the specified value
323+
*/
324+
public void setRetryForever(boolean retryForever) {
325+
mRetryForever = retryForever;
326+
if (DBG) log("setRetryForever: " + mRetryForever);
327+
}
328+
323329
/**
324330
* Clear the data-retry counter
325331
*/
@@ -399,6 +405,6 @@ private int nextRandomizationTime(int index) {
399405
}
400406

401407
private void log(String s) {
402-
Log.d(LOG_TAG, s);
408+
Log.d(LOG_TAG, "[RM] " + s);
403409
}
404410
}

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

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ public void putRecoveryAction(int action) {
134134
private static final String INTENT_RECONNECT_ALARM =
135135
"com.android.internal.telephony.gprs-reconnect";
136136
private static final String INTENT_RECONNECT_ALARM_EXTRA_TYPE = "reconnect_alarm_extra_type";
137+
private static final String INTENT_RECONNECT_ALARM_EXTRA_RETRY_COUNT =
138+
"reconnect_alaram_extra_retry_count";
137139

138140
private static final String INTENT_DATA_STALL_ALARM =
139141
"com.android.internal.telephony.gprs-data-stall";
@@ -148,18 +150,23 @@ public void putRecoveryAction(int action) {
148150

149151
@Override
150152
protected void onActionIntentReconnectAlarm(Intent intent) {
151-
if (DBG) log("GPRS reconnect alarm. Previous state was " + mState);
152-
153153
String reason = intent.getStringExtra(INTENT_RECONNECT_ALARM_EXTRA_REASON);
154154
int connectionId = intent.getIntExtra(INTENT_RECONNECT_ALARM_EXTRA_TYPE, -1);
155+
int retryCount = intent.getIntExtra(INTENT_RECONNECT_ALARM_EXTRA_RETRY_COUNT, 0);
155156

156157
DataConnectionAc dcac= mDataConnectionAsyncChannels.get(connectionId);
157158

159+
if (DBG) {
160+
log("onActionIntentReconnectAlarm: mState=" + mState + " reason=" + reason +
161+
" connectionId=" + connectionId + " retryCount=" + retryCount);
162+
}
163+
158164
if (dcac != null) {
159165
for (ApnContext apnContext : dcac.getApnListSync()) {
160166
apnContext.setDataConnectionAc(null);
161167
apnContext.setDataConnection(null);
162168
apnContext.setReason(reason);
169+
apnContext.setRetryCount(retryCount);
163170
if (apnContext.getState() == State.FAILED) {
164171
apnContext.setState(State.IDLE);
165172
}
@@ -207,7 +214,6 @@ public GsmDataConnectionTracker(PhoneBase p) {
207214
p.getContext().getContentResolver().registerContentObserver(
208215
Telephony.Carriers.CONTENT_URI, true, mApnObserver);
209216

210-
mApnContexts = new ConcurrentHashMap<String, ApnContext>();
211217
initApnContextsAndDataConnection();
212218
broadcastMessenger();
213219
}
@@ -674,10 +680,15 @@ private void setupDataOnReadyApns(String reason) {
674680
break;
675681
}
676682
}
677-
configureRetry(dcac.dataConnection, hasDefault);
683+
configureRetry(dcac.dataConnection, hasDefault, 0);
678684
}
679685
}
680686

687+
// Be sure retry counts for Apncontexts and DC's are sync'd.
688+
// When DCT/ApnContexts are refactored and we cleanup retrying
689+
// this won't be needed.
690+
resetAllRetryCounts();
691+
681692
// Only check for default APN state
682693
for (ApnContext apnContext : mApnContexts.values()) {
683694
if (apnContext.getState() == State.FAILED) {
@@ -1078,7 +1089,8 @@ private boolean setupData(ApnContext apnContext) {
10781089

10791090
// configure retry count if no other Apn is using the same connection.
10801091
if (refCount == 0) {
1081-
configureRetry(dc, apn.canHandleType(Phone.APN_TYPE_DEFAULT));
1092+
configureRetry(dc, apn.canHandleType(Phone.APN_TYPE_DEFAULT),
1093+
apnContext.getRetryCount());
10821094
}
10831095
apnContext.setDataConnectionAc(dcac);
10841096
apnContext.setDataConnection(dc);
@@ -1330,7 +1342,7 @@ private void notifyDefaultData(ApnContext apnContext) {
13301342
startNetStatPoll();
13311343
startDataStallAlarm(DATA_STALL_NOT_SUSPECTED);
13321344
// reset reconnect timer
1333-
apnContext.getDataConnection().resetRetryCount();
1345+
apnContext.setRetryCount(0);
13341346
}
13351347

13361348
// TODO: For multiple Active APNs not exactly sure how to do this.
@@ -1601,6 +1613,10 @@ private void reconnectAfterFail(FailCause lastFailCauseCode,
16011613
loge("reconnectAfterFail: apnContext == null, impossible");
16021614
return;
16031615
}
1616+
if (DBG) {
1617+
log("reconnectAfterFail: lastFailCause=" + lastFailCauseCode +
1618+
" retryOverride=" + retryOverride + " apnContext=" + apnContext);
1619+
}
16041620
if ((apnContext.getState() == State.FAILED) &&
16051621
(apnContext.getDataConnection() != null)) {
16061622
if (!apnContext.getDataConnection().isRetryNeeded()) {
@@ -1616,7 +1632,7 @@ private void reconnectAfterFail(FailCause lastFailCauseCode,
16161632
if (DBG) log("reconnectAfterFail: activate failed, Reregistering to network");
16171633
mReregisterOnReconnectFailure = true;
16181634
mPhone.getServiceStateTracker().reRegisterNetwork(null);
1619-
apnContext.getDataConnection().resetRetryCount();
1635+
apnContext.setRetryCount(0);
16201636
return;
16211637
}
16221638
}
@@ -1627,6 +1643,11 @@ private void reconnectAfterFail(FailCause lastFailCauseCode,
16271643
if (nextReconnectDelay < 0) {
16281644
nextReconnectDelay = apnContext.getDataConnection().getRetryTimer();
16291645
apnContext.getDataConnection().increaseRetryCount();
1646+
if (DBG) {
1647+
log("reconnectAfterFail: increaseRetryCount=" +
1648+
apnContext.getDataConnection().getRetryCount() +
1649+
" nextReconnectDelay=" + nextReconnectDelay);
1650+
}
16301651
}
16311652
startAlarmForReconnect(nextReconnectDelay, apnContext);
16321653

@@ -1643,16 +1664,11 @@ private void reconnectAfterFail(FailCause lastFailCauseCode,
16431664

16441665
private void startAlarmForReconnect(int delay, ApnContext apnContext) {
16451666

1646-
if (DBG) {
1647-
log("Schedule alarm for reconnect: activate failed. Scheduling next attempt for "
1648-
+ (delay / 1000) + "s");
1649-
}
1650-
16511667
DataConnectionAc dcac = apnContext.getDataConnectionAc();
16521668

16531669
if ((dcac == null) || (dcac.dataConnection == null)) {
16541670
// should not happen, but just in case.
1655-
loge("null dcac or dc.");
1671+
loge("startAlarmForReconnect: null dcac or dc.");
16561672
return;
16571673
}
16581674

@@ -1661,12 +1677,29 @@ private void startAlarmForReconnect(int delay, ApnContext apnContext) {
16611677

16621678
Intent intent = new Intent(INTENT_RECONNECT_ALARM + '.' +
16631679
dcac.dataConnection.getDataConnectionId());
1664-
intent.putExtra(INTENT_RECONNECT_ALARM_EXTRA_REASON, apnContext.getReason());
1665-
intent.putExtra(INTENT_RECONNECT_ALARM_EXTRA_TYPE,
1666-
dcac.dataConnection.getDataConnectionId());
1680+
String reason = apnContext.getReason();
1681+
intent.putExtra(INTENT_RECONNECT_ALARM_EXTRA_REASON, reason);
1682+
int connectionId = dcac.dataConnection.getDataConnectionId();
1683+
intent.putExtra(INTENT_RECONNECT_ALARM_EXTRA_TYPE, connectionId);
1684+
1685+
// TODO: Until a real fix is created, which probably entails pushing
1686+
// retires into the DC itself, this fix gets the retry count and
1687+
// puts it in the reconnect alarm. When the reconnect alarm fires
1688+
// onActionIntentReconnectAlarm is called which will use the value saved
1689+
// here and save it in the ApnContext and send the EVENT_CONNECT message
1690+
// which invokes setupData. Then setupData will use the value in the ApnContext
1691+
// and to tell the DC to set the retry count in the retry manager.
1692+
int retryCount = dcac.dataConnection.getRetryCount();
1693+
intent.putExtra(INTENT_RECONNECT_ALARM_EXTRA_RETRY_COUNT, retryCount);
1694+
1695+
if (DBG) {
1696+
log("startAlarmForReconnect: next attempt in " + (delay / 1000) + "s" +
1697+
" reason='" + reason + "' connectionId=" + connectionId +
1698+
" retryCount=" + retryCount);
1699+
}
16671700

16681701
PendingIntent alarmIntent = PendingIntent.getBroadcast (mPhone.getContext(), 0,
1669-
intent, 0);
1702+
intent, PendingIntent.FLAG_UPDATE_CURRENT);
16701703
dcac.setReconnectIntentSync(alarmIntent);
16711704
am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
16721705
SystemClock.elapsedRealtime() + delay, alarmIntent);
@@ -1942,9 +1975,7 @@ protected void onRadioOffOrNotAvailable() {
19421975
// Make sure our reconnect delay starts at the initial value
19431976
// next time the radio comes on
19441977

1945-
for (DataConnection dc : mDataConnections.values()) {
1946-
dc.resetRetryCount();
1947-
}
1978+
resetAllRetryCounts();
19481979
mReregisterOnReconnectFailure = false;
19491980

19501981
if (mPhone.getSimulatedRadioControl() != null) {
@@ -2287,7 +2318,11 @@ private GsmDataConnection createDataConnection() {
22872318
return conn;
22882319
}
22892320

2290-
private void configureRetry(DataConnection dc, boolean forDefault) {
2321+
private void configureRetry(DataConnection dc, boolean forDefault, int retryCount) {
2322+
if (DBG) {
2323+
log("configureRetry: forDefault=" + forDefault + " retryCount=" + retryCount +
2324+
" dc=" + dc);
2325+
}
22912326
if (dc == null) return;
22922327

22932328
if (!dc.configureRetry(getReryConfig(forDefault))) {
@@ -2307,6 +2342,7 @@ private void configureRetry(DataConnection dc, boolean forDefault) {
23072342
}
23082343
}
23092344
}
2345+
dc.setRetryCount(retryCount);
23102346
}
23112347

23122348
private void destroyDataConnections() {

0 commit comments

Comments
 (0)