am 13f6270e: SipAudioCall: use SipErrorCode instead of string in onError()

Merge commit '13f6270eb14b409709c936b828e2a2fd40e427c4' into gingerbread-plus-aosp

* commit '13f6270eb14b409709c936b828e2a2fd40e427c4':
  SipAudioCall: use SipErrorCode instead of string in onError()
This commit is contained in:
Hung-ying Tyan
2010-09-14 09:44:03 -07:00
committed by Android Git Automerger
3 changed files with 54 additions and 26 deletions

View File

@@ -819,9 +819,9 @@ public class SipPhone extends SipPhoneBase {
} }
@Override @Override
public void onError(SipAudioCall call, String errorCode, public void onError(SipAudioCall call, SipErrorCode errorCode,
String errorMessage) { String errorMessage) {
switch (Enum.valueOf(SipErrorCode.class, errorCode)) { switch (errorCode) {
case INVALID_REMOTE_URI: case INVALID_REMOTE_URI:
onError(Connection.DisconnectCause.INVALID_NUMBER); onError(Connection.DisconnectCause.INVALID_NUMBER);
break; break;

View File

@@ -88,10 +88,11 @@ public interface SipAudioCall {
* Called when an error occurs. * Called when an error occurs.
* *
* @param call the call object that carries out the audio call * @param call the call object that carries out the audio call
* @param errorCode error code defined in {@link SipErrorCode} * @param errorCode error code of this error
* @param errorMessage error message * @param errorMessage error message
*/ */
void onError(SipAudioCall call, String errorCode, String errorMessage); void onError(SipAudioCall call, SipErrorCode errorCode,
String errorMessage);
} }
/** /**
@@ -125,7 +126,7 @@ public interface SipAudioCall {
public void onCallHeld(SipAudioCall call) { public void onCallHeld(SipAudioCall call) {
onChanged(call); onChanged(call);
} }
public void onError(SipAudioCall call, String errorCode, public void onError(SipAudioCall call, SipErrorCode errorCode,
String errorMessage) { String errorMessage) {
onChanged(call); onChanged(call);
} }

View File

@@ -79,6 +79,9 @@ public class SipAudioCallImpl extends SipSessionAdapter
private WifiManager mWm; private WifiManager mWm;
private WifiManager.WifiLock mWifiHighPerfLock; private WifiManager.WifiLock mWifiHighPerfLock;
private SipErrorCode mErrorCode;
private String mErrorMessage;
public SipAudioCallImpl(Context context, SipProfile localProfile) { public SipAudioCallImpl(Context context, SipProfile localProfile) {
mContext = context; mContext = context;
mLocalProfile = localProfile; mLocalProfile = localProfile;
@@ -92,23 +95,33 @@ public class SipAudioCallImpl extends SipSessionAdapter
public void setListener(SipAudioCall.Listener listener, public void setListener(SipAudioCall.Listener listener,
boolean callbackImmediately) { boolean callbackImmediately) {
mListener = listener; mListener = listener;
if ((listener == null) || !callbackImmediately) return;
try { try {
SipSessionState state = getState(); if ((listener == null) || !callbackImmediately) {
switch (state) { // do nothing
case READY_TO_CALL: } else if (mErrorCode != null) {
listener.onReadyToCall(this); listener.onError(this, mErrorCode, mErrorMessage);
break; } else if (mInCall) {
case INCOMING_CALL: if (mHold) {
listener.onRinging(this, getPeerProfile(mSipSession)); listener.onCallHeld(this);
startRinging(); } else {
break; listener.onCallEstablished(this);
case OUTGOING_CALL: }
listener.onCalling(this); } else {
break; SipSessionState state = getState();
default: switch (state) {
listener.onError(this, SipErrorCode.CLIENT_ERROR.toString(), case READY_TO_CALL:
"wrong state to attach call: " + state); listener.onReadyToCall(this);
break;
case INCOMING_CALL:
listener.onRinging(this, getPeerProfile(mSipSession));
break;
case OUTGOING_CALL:
listener.onCalling(this);
break;
case OUTGOING_CALL_RING_BACK:
listener.onRingingBack(this);
break;
}
} }
} catch (Throwable t) { } catch (Throwable t) {
Log.e(TAG, "setListener()", t); Log.e(TAG, "setListener()", t);
@@ -135,6 +148,8 @@ public class SipAudioCallImpl extends SipSessionAdapter
mInCall = false; mInCall = false;
mHold = false; mHold = false;
mSessionId = -1L; mSessionId = -1L;
mErrorCode = null;
mErrorMessage = null;
} }
public synchronized SipProfile getLocalProfile() { public synchronized SipProfile getLocalProfile() {
@@ -274,14 +289,20 @@ public class SipAudioCallImpl extends SipSessionAdapter
} }
} }
private SipErrorCode getErrorCode(String errorCode) {
return Enum.valueOf(SipErrorCode.class, errorCode);
}
@Override @Override
public void onCallChangeFailed(ISipSession session, String errorCode, public void onCallChangeFailed(ISipSession session, String errorCode,
String message) { String message) {
Log.d(TAG, "sip call change failed: " + message); Log.d(TAG, "sip call change failed: " + message);
mErrorCode = getErrorCode(errorCode);
mErrorMessage = message;
Listener listener = mListener; Listener listener = mListener;
if (listener != null) { if (listener != null) {
try { try {
listener.onError(SipAudioCallImpl.this, errorCode, message); listener.onError(SipAudioCallImpl.this, mErrorCode, message);
} catch (Throwable t) { } catch (Throwable t) {
Log.e(TAG, "onCallBusy()", t); Log.e(TAG, "onCallBusy()", t);
} }
@@ -289,16 +310,20 @@ public class SipAudioCallImpl extends SipSessionAdapter
} }
@Override @Override
public void onError(ISipSession session, String errorCode, public void onError(ISipSession session, String errorCode, String message) {
String message) {
Log.d(TAG, "sip session error: " + errorCode + ": " + message); Log.d(TAG, "sip session error: " + errorCode + ": " + message);
mErrorCode = getErrorCode(errorCode);
mErrorMessage = message;
synchronized (this) { synchronized (this) {
if (!isInCall()) close(true); if ((mErrorCode == SipErrorCode.DATA_CONNECTION_LOST)
|| !isInCall()) {
close(true);
}
} }
Listener listener = mListener; Listener listener = mListener;
if (listener != null) { if (listener != null) {
try { try {
listener.onError(SipAudioCallImpl.this, errorCode, message); listener.onError(SipAudioCallImpl.this, mErrorCode, message);
} catch (Throwable t) { } catch (Throwable t) {
Log.e(TAG, "onError()", t); Log.e(TAG, "onError()", t);
} }
@@ -311,6 +336,8 @@ public class SipAudioCallImpl extends SipSessionAdapter
try { try {
mPeerSd = new SdpSessionDescription(sessionDescription); mPeerSd = new SdpSessionDescription(sessionDescription);
session.setListener(this); session.setListener(this);
if (getState() == SipSessionState.INCOMING_CALL) startRinging();
} catch (Throwable e) { } catch (Throwable e) {
Log.e(TAG, "attachCall()", e); Log.e(TAG, "attachCall()", e);
throwSipException(e); throwSipException(e);