summaryrefslogtreecommitdiffstats
path: root/voip
diff options
context:
space:
mode:
authorHung-ying Tyan <tyanh@google.com>2010-10-06 08:33:47 +0800
committerHung-ying Tyan <tyanh@google.com>2010-10-07 07:04:46 +0800
commitee8a884f3504c981be8a1d6888b4590a0a394e05 (patch)
treecb0cdb532f993149557f7f740270ff1b44d04bc1 /voip
parenta2a0a98ac7ce53f282a9a4caac9d382a0eb01ef9 (diff)
downloadframeworks_base-ee8a884f3504c981be8a1d6888b4590a0a394e05.zip
frameworks_base-ee8a884f3504c981be8a1d6888b4590a0a394e05.tar.gz
frameworks_base-ee8a884f3504c981be8a1d6888b4590a0a394e05.tar.bz2
SIP: Fix busy authentication loop.
Add a retry count and give up after two attempts. Also stop auto registration when server is unreachable. And rename onError() to restartLater() for better readability. http://b/issue?id=3066573 Change-Id: Icfa65c58546a1e2bf8e59e29584a3926c53c479b
Diffstat (limited to 'voip')
-rw-r--r--voip/java/com/android/server/sip/SipService.java16
-rw-r--r--voip/java/com/android/server/sip/SipSessionGroup.java49
2 files changed, 30 insertions, 35 deletions
diff --git a/voip/java/com/android/server/sip/SipService.java b/voip/java/com/android/server/sip/SipService.java
index a7c61e5..d8a1572 100644
--- a/voip/java/com/android/server/sip/SipService.java
+++ b/voip/java/com/android/server/sip/SipService.java
@@ -825,11 +825,13 @@ public final class SipService extends ISipService.Stub {
synchronized (SipService.this) {
if (notCurrentSession(session)) return;
- if (errorCode == SipErrorCode.INVALID_CREDENTIALS) {
- if (DEBUG) Log.d(TAG, " pause auto-registration");
- stop();
- } else {
- onError();
+ switch (errorCode) {
+ case SipErrorCode.INVALID_CREDENTIALS:
+ case SipErrorCode.SERVER_UNREACHABLE:
+ if (DEBUG) Log.d(TAG, " pause auto-registration");
+ stop();
+ default:
+ restartLater();
}
mErrorCode = errorCode;
@@ -846,11 +848,11 @@ public final class SipService extends ISipService.Stub {
mErrorCode = SipErrorCode.TIME_OUT;
mProxy.onRegistrationTimeout(session);
- onError();
+ restartLater();
}
}
- private void onError() {
+ private void restartLater() {
mRegistered = false;
restart(backoffDuration());
if (mKeepAliveProcess != null) {
diff --git a/voip/java/com/android/server/sip/SipSessionGroup.java b/voip/java/com/android/server/sip/SipSessionGroup.java
index 37fffa8..57b3710 100644
--- a/voip/java/com/android/server/sip/SipSessionGroup.java
+++ b/voip/java/com/android/server/sip/SipSessionGroup.java
@@ -96,8 +96,6 @@ class SipSessionGroup implements SipListener {
private SipStack mSipStack;
private SipHelper mSipHelper;
- private String mLastNonce;
- private int mRPort;
// session that processes INVITE requests
private SipSessionImpl mCallReceiverSession;
@@ -150,7 +148,6 @@ class SipSessionGroup implements SipListener {
Log.d(TAG, " start stack for " + myself.getUriString());
stack.start();
- mLastNonce = null;
mCallReceiverSession = null;
mSessionMap.clear();
}
@@ -366,8 +363,12 @@ class SipSessionGroup implements SipListener {
ClientTransaction mClientTransaction;
String mPeerSessionDescription;
boolean mInCall;
- boolean mReRegisterFlag = false;
SessionTimer mTimer;
+ int mAuthenticationRetryCount;
+
+ // for registration
+ boolean mReRegisterFlag = false;
+ int mRPort;
// lightweight timer
class SessionTimer {
@@ -417,6 +418,8 @@ class SipSessionGroup implements SipListener {
mState = SipSession.State.READY_TO_CALL;
mInviteReceived = null;
mPeerSessionDescription = null;
+ mRPort = 0;
+ mAuthenticationRetryCount = 0;
if (mDialog != null) mDialog.delete();
mDialog = null;
@@ -799,22 +802,10 @@ class SipSessionGroup implements SipListener {
onRegistrationDone((state == SipSession.State.REGISTERING)
? getExpiryTime(((ResponseEvent) evt).getResponse())
: -1);
- mLastNonce = null;
- mRPort = 0;
return true;
case Response.UNAUTHORIZED:
case Response.PROXY_AUTHENTICATION_REQUIRED:
- if (!handleAuthentication(event)) {
- if (mLastNonce == null) {
- onRegistrationFailed(SipErrorCode.SERVER_ERROR,
- "server does not provide challenge");
- } else {
- Log.v(TAG, "Incorrect username/password");
- onRegistrationFailed(
- SipErrorCode.INVALID_CREDENTIALS,
- "incorrect username or password");
- }
- }
+ handleAuthentication(event);
return true;
default:
if (statusCode >= 500) {
@@ -830,16 +821,24 @@ class SipSessionGroup implements SipListener {
throws SipException {
Response response = event.getResponse();
String nonce = getNonceFromResponse(response);
- if (((nonce != null) && nonce.equals(mLastNonce)) ||
- (nonce == null)) {
- mLastNonce = nonce;
+ if (nonce == null) {
+ onError(SipErrorCode.SERVER_ERROR,
+ "server does not provide challenge");
return false;
- } else {
+ } else if (mAuthenticationRetryCount < 2) {
mClientTransaction = mSipHelper.handleChallenge(
event, getAccountManager());
mDialog = mClientTransaction.getDialog();
- mLastNonce = nonce;
+ mAuthenticationRetryCount++;
+ if (isLoggable(this, event)) {
+ Log.d(TAG, " authentication retry count="
+ + mAuthenticationRetryCount);
+ }
return true;
+ } else {
+ onError(SipErrorCode.INVALID_CREDENTIALS,
+ "incorrect username or password");
+ return false;
}
}
@@ -995,12 +994,6 @@ class SipSessionGroup implements SipListener {
getRealmFromResponse(response));
} else if (handleAuthentication(event)) {
addSipSession(this);
- } else if (mLastNonce == null) {
- onError(SipErrorCode.SERVER_ERROR,
- "server does not provide challenge");
- } else {
- onError(SipErrorCode.INVALID_CREDENTIALS,
- "incorrect username or password");
}
return true;
case Response.REQUEST_PENDING: