Skip to content

Commit 7a685e8

Browse files
Chia-chi YehAndroid (Google) Code Review
authored andcommitted
Merge "SIP: fix keep-alive measurement and increase the timeout."
2 parents fa6dfdc + d17b6d5 commit 7a685e8

File tree

2 files changed

+34
-32
lines changed

2 files changed

+34
-32
lines changed

voip/java/com/android/server/sip/SipService.java

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ private synchronized void onConnectivityChanged(
442442

443443
if (wasConnected) {
444444
mLocalIp = null;
445+
stopPortMappingMeasurement();
445446
for (SipSessionGroupExt group : mSipGroups.values()) {
446447
group.onConnectivityChanged(false);
447448
}
@@ -457,7 +458,6 @@ private synchronized void onConnectivityChanged(
457458
if (isWifi && (mWifiLock != null)) stopWifiScanner();
458459
} else {
459460
mMyWakeLock.reset(); // in case there's a leak
460-
stopPortMappingMeasurement();
461461
if (isWifi && (mWifiLock != null)) startWifiScanner();
462462
}
463463
} catch (SipException e) {
@@ -784,52 +784,50 @@ private class IntervalMeasurementProcess implements Runnable,
784784
private static final int PASS_THRESHOLD = 10;
785785
private static final int MAX_RETRY_COUNT = 5;
786786
private static final int NAT_MEASUREMENT_RETRY_INTERVAL = 120; // in seconds
787+
private SipProfile mLocalProfile;
787788
private SipSessionGroupExt mGroup;
788789
private SipSessionGroup.SipSessionImpl mSession;
789790
private int mMinInterval;
790791
private int mMaxInterval;
791792
private int mInterval;
792-
private int mPassCount = 0;
793+
private int mPassCount;
793794

794795
public IntervalMeasurementProcess(SipProfile localProfile,
795796
int minInterval, int maxInterval) {
796797
mMaxInterval = maxInterval;
797798
mMinInterval = minInterval;
798-
mInterval = (maxInterval + minInterval) / 2;
799-
800-
// Don't start measurement if the interval is too small
801-
if (mInterval < DEFAULT_KEEPALIVE_INTERVAL) {
802-
Log.w(TAG, "interval is too small; measurement aborted; "
803-
+ "maxInterval=" + mMaxInterval);
804-
return;
805-
} else if (checkTermination()) {
806-
Log.w(TAG, "interval is too small; measurement aborted; "
807-
+ "interval=[" + mMinInterval + "," + mMaxInterval
808-
+ "]");
809-
return;
810-
}
811-
812-
try {
813-
mGroup = new SipSessionGroupExt(localProfile, null, null);
814-
// TODO: remove this line once SipWakeupTimer can better handle
815-
// variety of timeout values
816-
mGroup.setWakeupTimer(new SipWakeupTimer(mContext, mExecutor));
817-
} catch (Exception e) {
818-
Log.w(TAG, "start interval measurement error: " + e);
819-
}
799+
mLocalProfile = localProfile;
820800
}
821801

822802
public void start() {
823803
synchronized (SipService.this) {
824-
Log.d(TAG, "start measurement w interval=" + mInterval);
825-
if (mSession == null) {
826-
mSession = (SipSessionGroup.SipSessionImpl)
827-
mGroup.createSession(null);
804+
if (mSession != null) {
805+
return;
828806
}
807+
808+
mInterval = (mMaxInterval + mMinInterval) / 2;
809+
mPassCount = 0;
810+
811+
// Don't start measurement if the interval is too small
812+
if (mInterval < DEFAULT_KEEPALIVE_INTERVAL || checkTermination()) {
813+
Log.w(TAG, "measurement aborted; interval=[" +
814+
mMinInterval + "," + mMaxInterval + "]");
815+
return;
816+
}
817+
829818
try {
819+
Log.d(TAG, "start measurement w interval=" + mInterval);
820+
821+
mGroup = new SipSessionGroupExt(mLocalProfile, null, null);
822+
// TODO: remove this line once SipWakeupTimer can better handle
823+
// variety of timeout values
824+
mGroup.setWakeupTimer(new SipWakeupTimer(mContext, mExecutor));
825+
826+
mSession = (SipSessionGroup.SipSessionImpl)
827+
mGroup.createSession(null);
830828
mSession.startKeepAliveProcess(mInterval, this);
831-
} catch (SipException e) {
832-
Log.e(TAG, "start()", e);
829+
} catch (Throwable t) {
830+
onError(SipErrorCode.CLIENT_ERROR, t.toString());
833831
}
834832
}
835833
}
@@ -840,6 +838,10 @@ public void stop() {
840838
mSession.stopKeepAliveProcess();
841839
mSession = null;
842840
}
841+
if (mGroup != null) {
842+
mGroup.close();
843+
mGroup = null;
844+
}
843845
mTimer.cancel(this);
844846
}
845847
}

voip/java/com/android/server/sip/SipSessionGroup.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class SipSessionGroup implements SipListener {
100100
private static final int EXPIRY_TIME = 3600; // in seconds
101101
private static final int CANCEL_CALL_TIMER = 3; // in seconds
102102
private static final int END_CALL_TIMER = 3; // in seconds
103-
private static final int KEEPALIVE_TIMEOUT = 3; // in seconds
103+
private static final int KEEPALIVE_TIMEOUT = 5; // in seconds
104104
private static final int INCALL_KEEPALIVE_INTERVAL = 10; // in seconds
105105
private static final long WAKE_LOCK_HOLDING_TIME = 500; // in milliseconds
106106

@@ -1555,7 +1555,7 @@ public void run() {
15551555
try {
15561556
sendKeepAlive();
15571557
} catch (Throwable t) {
1558-
Log.w(TAG, "keepalive error: " + ": "
1558+
Log.w(TAG, "keepalive error: "
15591559
+ mLocalProfile.getUriString(), getRootCause(t));
15601560
// It's possible that the keepalive process is being stopped
15611561
// during session.sendKeepAlive() so need to check mRunning

0 commit comments

Comments
 (0)