am 97963794: SIP: convert enum to static final int.

Merge commit '97963794af1e18674dd111e3ad344d90b16c922c' into gingerbread-plus-aosp

* commit '97963794af1e18674dd111e3ad344d90b16c922c':
  SIP: convert enum to static final int.
This commit is contained in:
Hung-ying Tyan
2010-09-19 18:56:27 -07:00
committed by Android Git Automerger
13 changed files with 208 additions and 153 deletions

View File

@@ -476,10 +476,10 @@ public final class SipService extends ISipService.Stub {
} }
@Override @Override
public void onError(ISipSession session, String errorClass, public void onError(ISipSession session, int errorCode,
String message) { String message) {
if (DEBUG) Log.d(TAG, "sip session error: " + errorClass + ": " if (DEBUG) Log.d(TAG, "sip session error: "
+ message); + SipErrorCode.toString(errorCode) + ": " + message);
} }
public boolean isOpened() { public boolean isOpened() {
@@ -535,7 +535,7 @@ public final class SipService extends ISipService.Stub {
private int mBackoff = 1; private int mBackoff = 1;
private boolean mRegistered; private boolean mRegistered;
private long mExpiryTime; private long mExpiryTime;
private SipErrorCode mErrorCode; private int mErrorCode;
private String mErrorMessage; private String mErrorMessage;
private String getAction() { private String getAction() {
@@ -591,10 +591,9 @@ public final class SipService extends ISipService.Stub {
if (mSession == null) return; if (mSession == null) return;
try { try {
SipSessionState state = (mSession == null) int state = (mSession == null)
? SipSessionState.READY_TO_CALL ? SipSessionState.READY_TO_CALL
: Enum.valueOf( : mSession.getState();
SipSessionState.class, mSession.getState());
if ((state == SipSessionState.REGISTERING) if ((state == SipSessionState.REGISTERING)
|| (state == SipSessionState.DEREGISTERING)) { || (state == SipSessionState.DEREGISTERING)) {
mProxy.onRegistering(mSession); mProxy.onRegistering(mSession);
@@ -602,12 +601,12 @@ public final class SipService extends ISipService.Stub {
int duration = (int) int duration = (int)
(mExpiryTime - SystemClock.elapsedRealtime()); (mExpiryTime - SystemClock.elapsedRealtime());
mProxy.onRegistrationDone(mSession, duration); mProxy.onRegistrationDone(mSession, duration);
} else if (mErrorCode != null) { } else if (mErrorCode != SipErrorCode.NO_ERROR) {
if (mErrorCode == SipErrorCode.TIME_OUT) { if (mErrorCode == SipErrorCode.TIME_OUT) {
mProxy.onRegistrationTimeout(mSession); mProxy.onRegistrationTimeout(mSession);
} else { } else {
mProxy.onRegistrationFailed(mSession, mProxy.onRegistrationFailed(mSession, mErrorCode,
mErrorCode.toString(), mErrorMessage); mErrorMessage);
} }
} }
} catch (Throwable t) { } catch (Throwable t) {
@@ -621,7 +620,7 @@ public final class SipService extends ISipService.Stub {
} }
public void run() { public void run() {
mErrorCode = null; mErrorCode = SipErrorCode.NO_ERROR;
mErrorMessage = null; mErrorMessage = null;
if (DEBUG) Log.d(TAG, "~~~ registering"); if (DEBUG) Log.d(TAG, "~~~ registering");
synchronized (SipService.this) { synchronized (SipService.this) {
@@ -714,18 +713,15 @@ public final class SipService extends ISipService.Stub {
} }
@Override @Override
public void onRegistrationFailed(ISipSession session, public void onRegistrationFailed(ISipSession session, int errorCode,
String errorCodeString, String message) { String message) {
SipErrorCode errorCode =
Enum.valueOf(SipErrorCode.class, errorCodeString);
if (DEBUG) Log.d(TAG, "onRegistrationFailed(): " + session + ": " if (DEBUG) Log.d(TAG, "onRegistrationFailed(): " + session + ": "
+ errorCode + ": " + message); + SipErrorCode.toString(errorCode) + ": " + message);
synchronized (SipService.this) { synchronized (SipService.this) {
if (!isStopped() && (session != mSession)) return; if (!isStopped() && (session != mSession)) return;
mErrorCode = errorCode; mErrorCode = errorCode;
mErrorMessage = message; mErrorMessage = message;
mProxy.onRegistrationFailed(session, errorCode.toString(), mProxy.onRegistrationFailed(session, errorCode, message);
message);
if (errorCode == SipErrorCode.INVALID_CREDENTIALS) { if (errorCode == SipErrorCode.INVALID_CREDENTIALS) {
if (DEBUG) Log.d(TAG, " pause auto-registration"); if (DEBUG) Log.d(TAG, " pause auto-registration");

View File

@@ -300,7 +300,8 @@ class SipSessionGroup implements SipListener {
boolean isLoggable = isLoggable(session, event); boolean isLoggable = isLoggable(session, event);
boolean processed = (session != null) && session.process(event); boolean processed = (session != null) && session.process(event);
if (isLoggable && processed) { if (isLoggable && processed) {
Log.d(TAG, "new state after: " + session.mState); Log.d(TAG, "new state after: "
+ SipSessionState.toString(session.mState));
} }
} catch (Throwable e) { } catch (Throwable e) {
Log.w(TAG, "event process error: " + event, e); Log.w(TAG, "event process error: " + event, e);
@@ -331,7 +332,8 @@ class SipSessionGroup implements SipListener {
public boolean process(EventObject evt) throws SipException { public boolean process(EventObject evt) throws SipException {
if (isLoggable(this, evt)) Log.d(TAG, " ~~~~~ " + this + ": " if (isLoggable(this, evt)) Log.d(TAG, " ~~~~~ " + this + ": "
+ mState + ": processing " + log(evt)); + SipSessionState.toString(mState) + ": processing "
+ log(evt));
if (isRequestEvent(Request.INVITE, evt)) { if (isRequestEvent(Request.INVITE, evt)) {
RequestEvent event = (RequestEvent) evt; RequestEvent event = (RequestEvent) evt;
SipSessionImpl newSession = new SipSessionImpl(mProxy); SipSessionImpl newSession = new SipSessionImpl(mProxy);
@@ -356,7 +358,7 @@ class SipSessionGroup implements SipListener {
class SipSessionImpl extends ISipSession.Stub { class SipSessionImpl extends ISipSession.Stub {
SipProfile mPeerProfile; SipProfile mPeerProfile;
SipSessionListenerProxy mProxy = new SipSessionListenerProxy(); SipSessionListenerProxy mProxy = new SipSessionListenerProxy();
SipSessionState mState = SipSessionState.READY_TO_CALL; int mState = SipSessionState.READY_TO_CALL;
RequestEvent mInviteReceived; RequestEvent mInviteReceived;
Dialog mDialog; Dialog mDialog;
ServerTransaction mServerTransaction; ServerTransaction mServerTransaction;
@@ -447,8 +449,8 @@ class SipSessionGroup implements SipListener {
return null; return null;
} }
public String getState() { public int getState() {
return mState.toString(); return mState;
} }
public void setListener(ISipSessionListener listener) { public void setListener(ISipSessionListener listener) {
@@ -521,7 +523,7 @@ class SipSessionGroup implements SipListener {
mState = SipSessionState.PINGING; mState = SipSessionState.PINGING;
try { try {
processCommand(new OptionsCommand()); processCommand(new OptionsCommand());
while (SipSessionState.PINGING.equals(mState)) { while (SipSessionState.PINGING == mState) {
Thread.sleep(1000); Thread.sleep(1000);
} }
} catch (SipException e) { } catch (SipException e) {
@@ -547,7 +549,8 @@ class SipSessionGroup implements SipListener {
public String toString() { public String toString() {
try { try {
String s = super.toString(); String s = super.toString();
return s.substring(s.indexOf("@")) + ":" + mState; return s.substring(s.indexOf("@")) + ":"
+ SipSessionState.toString(mState);
} catch (Throwable e) { } catch (Throwable e) {
return super.toString(); return super.toString();
} }
@@ -555,7 +558,8 @@ class SipSessionGroup implements SipListener {
public boolean process(EventObject evt) throws SipException { public boolean process(EventObject evt) throws SipException {
if (isLoggable(this, evt)) Log.d(TAG, " ~~~~~ " + this + ": " if (isLoggable(this, evt)) Log.d(TAG, " ~~~~~ " + this + ": "
+ mState + ": processing " + log(evt)); + SipSessionState.toString(mState) + ": processing "
+ log(evt));
synchronized (SipSessionGroup.this) { synchronized (SipSessionGroup.this) {
if (isClosed()) return false; if (isClosed()) return false;
@@ -570,30 +574,30 @@ class SipSessionGroup implements SipListener {
boolean processed; boolean processed;
switch (mState) { switch (mState) {
case REGISTERING: case SipSessionState.REGISTERING:
case DEREGISTERING: case SipSessionState.DEREGISTERING:
processed = registeringToReady(evt); processed = registeringToReady(evt);
break; break;
case PINGING: case SipSessionState.PINGING:
processed = keepAliveProcess(evt); processed = keepAliveProcess(evt);
break; break;
case READY_TO_CALL: case SipSessionState.READY_TO_CALL:
processed = readyForCall(evt); processed = readyForCall(evt);
break; break;
case INCOMING_CALL: case SipSessionState.INCOMING_CALL:
processed = incomingCall(evt); processed = incomingCall(evt);
break; break;
case INCOMING_CALL_ANSWERING: case SipSessionState.INCOMING_CALL_ANSWERING:
processed = incomingCallToInCall(evt); processed = incomingCallToInCall(evt);
break; break;
case OUTGOING_CALL: case SipSessionState.OUTGOING_CALL:
case OUTGOING_CALL_RING_BACK: case SipSessionState.OUTGOING_CALL_RING_BACK:
processed = outgoingCall(evt); processed = outgoingCall(evt);
break; break;
case OUTGOING_CALL_CANCELING: case SipSessionState.OUTGOING_CALL_CANCELING:
processed = outgoingCallToReady(evt); processed = outgoingCallToReady(evt);
break; break;
case IN_CALL: case SipSessionState.IN_CALL:
processed = inCall(evt); processed = inCall(evt);
break; break;
default: default:
@@ -640,8 +644,8 @@ class SipSessionGroup implements SipListener {
private void processTransactionTerminated( private void processTransactionTerminated(
TransactionTerminatedEvent event) { TransactionTerminatedEvent event) {
switch (mState) { switch (mState) {
case IN_CALL: case SipSessionState.IN_CALL:
case READY_TO_CALL: case SipSessionState.READY_TO_CALL:
Log.d(TAG, "Transaction terminated; do nothing"); Log.d(TAG, "Transaction terminated; do nothing");
break; break;
default: default:
@@ -666,18 +670,18 @@ class SipSessionGroup implements SipListener {
return; return;
} }
switch (mState) { switch (mState) {
case REGISTERING: case SipSessionState.REGISTERING:
case DEREGISTERING: case SipSessionState.DEREGISTERING:
reset(); reset();
mProxy.onRegistrationTimeout(this); mProxy.onRegistrationTimeout(this);
break; break;
case INCOMING_CALL: case SipSessionState.INCOMING_CALL:
case INCOMING_CALL_ANSWERING: case SipSessionState.INCOMING_CALL_ANSWERING:
case OUTGOING_CALL: case SipSessionState.OUTGOING_CALL:
case OUTGOING_CALL_CANCELING: case SipSessionState.OUTGOING_CALL_CANCELING:
onError(SipErrorCode.TIME_OUT, event.toString()); onError(SipErrorCode.TIME_OUT, event.toString());
break; break;
case PINGING: case SipSessionState.PINGING:
reset(); reset();
mReRegisterFlag = true; mReRegisterFlag = true;
mState = SipSessionState.READY_TO_CALL; mState = SipSessionState.READY_TO_CALL;
@@ -753,7 +757,7 @@ class SipSessionGroup implements SipListener {
int statusCode = response.getStatusCode(); int statusCode = response.getStatusCode();
switch (statusCode) { switch (statusCode) {
case Response.OK: case Response.OK:
SipSessionState state = mState; int state = mState;
onRegistrationDone((state == SipSessionState.REGISTERING) onRegistrationDone((state == SipSessionState.REGISTERING)
? getExpiryTime(((ResponseEvent) evt).getResponse()) ? getExpiryTime(((ResponseEvent) evt).getResponse())
: -1); : -1);
@@ -1062,10 +1066,9 @@ class SipSessionGroup implements SipListener {
mProxy.onCallEstablished(this, mPeerSessionDescription); mProxy.onCallEstablished(this, mPeerSessionDescription);
} }
private void fallbackToPreviousInCall(SipErrorCode errorCode, private void fallbackToPreviousInCall(int errorCode, String message) {
String message) {
mState = SipSessionState.IN_CALL; mState = SipSessionState.IN_CALL;
mProxy.onCallChangeFailed(this, errorCode.toString(), message); mProxy.onCallChangeFailed(this, errorCode, message);
} }
private void endCallNormally() { private void endCallNormally() {
@@ -1073,9 +1076,9 @@ class SipSessionGroup implements SipListener {
mProxy.onCallEnded(this); mProxy.onCallEnded(this);
} }
private void endCallOnError(SipErrorCode errorCode, String message) { private void endCallOnError(int errorCode, String message) {
reset(); reset();
mProxy.onError(this, errorCode.toString(), message); mProxy.onError(this, errorCode, message);
} }
private void endCallOnBusy() { private void endCallOnBusy() {
@@ -1083,11 +1086,11 @@ class SipSessionGroup implements SipListener {
mProxy.onCallBusy(this); mProxy.onCallBusy(this);
} }
private void onError(SipErrorCode errorCode, String message) { private void onError(int errorCode, String message) {
cancelSessionTimer(); cancelSessionTimer();
switch (mState) { switch (mState) {
case REGISTERING: case SipSessionState.REGISTERING:
case DEREGISTERING: case SipSessionState.DEREGISTERING:
onRegistrationFailed(errorCode, message); onRegistrationFailed(errorCode, message);
break; break;
default: default:
@@ -1115,7 +1118,7 @@ class SipSessionGroup implements SipListener {
} }
} }
private SipErrorCode getErrorCode(int responseStatusCode) { private int getErrorCode(int responseStatusCode) {
switch (responseStatusCode) { switch (responseStatusCode) {
case Response.TEMPORARILY_UNAVAILABLE: case Response.TEMPORARILY_UNAVAILABLE:
case Response.FORBIDDEN: case Response.FORBIDDEN:
@@ -1151,7 +1154,7 @@ class SipSessionGroup implements SipListener {
return exception; return exception;
} }
private SipErrorCode getErrorCode(Throwable exception) { private int getErrorCode(Throwable exception) {
String message = exception.getMessage(); String message = exception.getMessage();
if (exception instanceof UnknownHostException) { if (exception instanceof UnknownHostException) {
return SipErrorCode.INVALID_REMOTE_URI; return SipErrorCode.INVALID_REMOTE_URI;
@@ -1169,10 +1172,9 @@ class SipSessionGroup implements SipListener {
mProxy.onRegistrationDone(this, duration); mProxy.onRegistrationDone(this, duration);
} }
private void onRegistrationFailed(SipErrorCode errorCode, private void onRegistrationFailed(int errorCode, String message) {
String message) {
reset(); reset();
mProxy.onRegistrationFailed(this, errorCode.toString(), message); mProxy.onRegistrationFailed(this, errorCode, message);
} }
private void onRegistrationFailed(Throwable exception) { private void onRegistrationFailed(Throwable exception) {
@@ -1262,7 +1264,7 @@ class SipSessionGroup implements SipListener {
private static boolean isLoggable(SipSessionImpl s) { private static boolean isLoggable(SipSessionImpl s) {
if (s != null) { if (s != null) {
switch (s.mState) { switch (s.mState) {
case PINGING: case SipSessionState.PINGING:
return DEBUG_PING; return DEBUG_PING;
} }
} }

View File

@@ -124,7 +124,7 @@ class SipSessionListenerProxy extends ISipSessionListener.Stub {
} }
public void onCallChangeFailed(final ISipSession session, public void onCallChangeFailed(final ISipSession session,
final String errorCode, final String message) { final int errorCode, final String message) {
if (mListener == null) return; if (mListener == null) return;
proxy(new Runnable() { proxy(new Runnable() {
public void run() { public void run() {
@@ -137,7 +137,7 @@ class SipSessionListenerProxy extends ISipSessionListener.Stub {
}); });
} }
public void onError(final ISipSession session, final String errorCode, public void onError(final ISipSession session, final int errorCode,
final String message) { final String message) {
if (mListener == null) return; if (mListener == null) return;
proxy(new Runnable() { proxy(new Runnable() {
@@ -179,7 +179,7 @@ class SipSessionListenerProxy extends ISipSessionListener.Stub {
} }
public void onRegistrationFailed(final ISipSession session, public void onRegistrationFailed(final ISipSession session,
final String errorCode, final String message) { final int errorCode, final String message) {
if (mListener == null) return; if (mListener == null) return;
proxy(new Runnable() { proxy(new Runnable() {
public void run() { public void run() {

View File

@@ -802,15 +802,15 @@ public class SipPhone extends SipPhoneBase {
private static Call.State getCallStateFrom(SipAudioCall sipAudioCall) { private static Call.State getCallStateFrom(SipAudioCall sipAudioCall) {
if (sipAudioCall.isOnHold()) return Call.State.HOLDING; if (sipAudioCall.isOnHold()) return Call.State.HOLDING;
SipSessionState sessionState = sipAudioCall.getState(); int sessionState = sipAudioCall.getState();
switch (sessionState) { switch (sessionState) {
case READY_TO_CALL: return Call.State.IDLE; case SipSessionState.READY_TO_CALL: return Call.State.IDLE;
case INCOMING_CALL: case SipSessionState.INCOMING_CALL:
case INCOMING_CALL_ANSWERING: return Call.State.INCOMING; case SipSessionState.INCOMING_CALL_ANSWERING: return Call.State.INCOMING;
case OUTGOING_CALL: return Call.State.DIALING; case SipSessionState.OUTGOING_CALL: return Call.State.DIALING;
case OUTGOING_CALL_RING_BACK: return Call.State.ALERTING; case SipSessionState.OUTGOING_CALL_RING_BACK: return Call.State.ALERTING;
case OUTGOING_CALL_CANCELING: return Call.State.DISCONNECTING; case SipSessionState.OUTGOING_CALL_CANCELING: return Call.State.DISCONNECTING;
case IN_CALL: return Call.State.ACTIVE; case SipSessionState.IN_CALL: return Call.State.ACTIVE;
default: default:
Log.w(LOG_TAG, "illegal connection state: " + sessionState); Log.w(LOG_TAG, "illegal connection state: " + sessionState);
return Call.State.DISCONNECTED; return Call.State.DISCONNECTED;
@@ -832,30 +832,31 @@ public class SipPhone extends SipPhoneBase {
} }
@Override @Override
public void onError(SipAudioCall call, SipErrorCode errorCode, public void onError(SipAudioCall call, int errorCode,
String errorMessage) { String errorMessage) {
switch (errorCode) { switch (errorCode) {
case PEER_NOT_REACHABLE: case SipErrorCode.PEER_NOT_REACHABLE:
onError(Connection.DisconnectCause.NUMBER_UNREACHABLE); onError(Connection.DisconnectCause.NUMBER_UNREACHABLE);
break; break;
case INVALID_REMOTE_URI: case SipErrorCode.INVALID_REMOTE_URI:
onError(Connection.DisconnectCause.INVALID_NUMBER); onError(Connection.DisconnectCause.INVALID_NUMBER);
break; break;
case TIME_OUT: case SipErrorCode.TIME_OUT:
case TRANSACTION_TERMINTED: case SipErrorCode.TRANSACTION_TERMINTED:
onError(Connection.DisconnectCause.TIMED_OUT); onError(Connection.DisconnectCause.TIMED_OUT);
break; break;
case DATA_CONNECTION_LOST: case SipErrorCode.DATA_CONNECTION_LOST:
onError(Connection.DisconnectCause.LOST_SIGNAL); onError(Connection.DisconnectCause.LOST_SIGNAL);
break; break;
case INVALID_CREDENTIALS: case SipErrorCode.INVALID_CREDENTIALS:
onError(Connection.DisconnectCause.INVALID_CREDENTIALS); onError(Connection.DisconnectCause.INVALID_CREDENTIALS);
break; break;
case SOCKET_ERROR: case SipErrorCode.SOCKET_ERROR:
case SERVER_ERROR: case SipErrorCode.SERVER_ERROR:
case CLIENT_ERROR: case SipErrorCode.CLIENT_ERROR:
default: default:
Log.w(LOG_TAG, "error: " + errorCode + ": " + errorMessage); Log.w(LOG_TAG, "error: " + SipErrorCode.toString(errorCode)
+ ": " + errorMessage);
onError(Connection.DisconnectCause.ERROR_UNSPECIFIED); onError(Connection.DisconnectCause.ERROR_UNSPECIFIED);
} }
} }

View File

@@ -49,14 +49,11 @@ interface ISipSession {
/** /**
* Gets the session state. The value returned must be one of the states in * Gets the session state. The value returned must be one of the states in
* {@link SipSessionState}. One may convert it to {@link SipSessionState} by * {@link SipSessionState}.
* <code>
* Enum.valueOf(SipSessionState.class, session.getState());
* </code>
* *
* @return the session state * @return the session state
*/ */
String getState(); int getState();
/** /**
* Checks if the session is in a call. * Checks if the session is in a call.

View File

@@ -79,8 +79,7 @@ interface ISipSessionListener {
* @param errorCode error code defined in {@link SipErrorCode} * @param errorCode error code defined in {@link SipErrorCode}
* @param errorMessage error message * @param errorMessage error message
*/ */
void onError(in ISipSession session, String errorCode, void onError(in ISipSession session, int errorCode, String errorMessage);
String errorMessage);
/** /**
* Called when an error occurs during session modification negotiation. * Called when an error occurs during session modification negotiation.
@@ -89,7 +88,7 @@ interface ISipSessionListener {
* @param errorCode error code defined in {@link SipErrorCode} * @param errorCode error code defined in {@link SipErrorCode}
* @param errorMessage error message * @param errorMessage error message
*/ */
void onCallChangeFailed(in ISipSession session, String errorCode, void onCallChangeFailed(in ISipSession session, int errorCode,
String errorMessage); String errorMessage);
/** /**
@@ -114,7 +113,7 @@ interface ISipSessionListener {
* @param errorCode error code defined in {@link SipErrorCode} * @param errorCode error code defined in {@link SipErrorCode}
* @param errorMessage error message * @param errorMessage error message
*/ */
void onRegistrationFailed(in ISipSession session, String errorCode, void onRegistrationFailed(in ISipSession session, int errorCode,
String errorMessage); String errorMessage);
/** /**

View File

@@ -90,9 +90,9 @@ public interface SipAudioCall {
* @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 of this error * @param errorCode error code of this error
* @param errorMessage error message * @param errorMessage error message
* @see SipErrorCode
*/ */
void onError(SipAudioCall call, SipErrorCode errorCode, void onError(SipAudioCall call, int errorCode, String errorMessage);
String errorMessage);
} }
/** /**
@@ -126,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, SipErrorCode errorCode, public void onError(SipAudioCall call, int errorCode,
String errorMessage) { String errorMessage) {
onChanged(call); onChanged(call);
} }
@@ -318,10 +318,11 @@ public interface SipAudioCall {
/** /**
* Gets the state of the {@link ISipSession} that carries this call. * Gets the state of the {@link ISipSession} that carries this call.
* The value returned must be one of the states in {@link SipSessionState}.
* *
* @return the session state * @return the session state
*/ */
SipSessionState getState(); int getState();
/** /**
* Gets the {@link ISipSession} that carries this call. * Gets the {@link ISipSession} that carries this call.

View File

@@ -81,7 +81,7 @@ public class SipAudioCallImpl extends SipSessionAdapter
private WifiManager mWm; private WifiManager mWm;
private WifiManager.WifiLock mWifiHighPerfLock; private WifiManager.WifiLock mWifiHighPerfLock;
private SipErrorCode mErrorCode; private int mErrorCode = SipErrorCode.NO_ERROR;
private String mErrorMessage; private String mErrorMessage;
public SipAudioCallImpl(Context context, SipProfile localProfile) { public SipAudioCallImpl(Context context, SipProfile localProfile) {
@@ -100,7 +100,7 @@ public class SipAudioCallImpl extends SipSessionAdapter
try { try {
if ((listener == null) || !callbackImmediately) { if ((listener == null) || !callbackImmediately) {
// do nothing // do nothing
} else if (mErrorCode != null) { } else if (mErrorCode != SipErrorCode.NO_ERROR) {
listener.onError(this, mErrorCode, mErrorMessage); listener.onError(this, mErrorCode, mErrorMessage);
} else if (mInCall) { } else if (mInCall) {
if (mHold) { if (mHold) {
@@ -109,18 +109,18 @@ public class SipAudioCallImpl extends SipSessionAdapter
listener.onCallEstablished(this); listener.onCallEstablished(this);
} }
} else { } else {
SipSessionState state = getState(); int state = getState();
switch (state) { switch (state) {
case READY_TO_CALL: case SipSessionState.READY_TO_CALL:
listener.onReadyToCall(this); listener.onReadyToCall(this);
break; break;
case INCOMING_CALL: case SipSessionState.INCOMING_CALL:
listener.onRinging(this, getPeerProfile(mSipSession)); listener.onRinging(this, getPeerProfile(mSipSession));
break; break;
case OUTGOING_CALL: case SipSessionState.OUTGOING_CALL:
listener.onCalling(this); listener.onCalling(this);
break; break;
case OUTGOING_CALL_RING_BACK: case SipSessionState.OUTGOING_CALL_RING_BACK:
listener.onRingingBack(this); listener.onRingingBack(this);
break; break;
} }
@@ -150,7 +150,7 @@ public class SipAudioCallImpl extends SipSessionAdapter
mInCall = false; mInCall = false;
mHold = false; mHold = false;
mSessionId = -1L; mSessionId = -1L;
mErrorCode = null; mErrorCode = SipErrorCode.NO_ERROR;
mErrorMessage = null; mErrorMessage = null;
if (mSipSession != null) { if (mSipSession != null) {
@@ -175,10 +175,10 @@ public class SipAudioCallImpl extends SipSessionAdapter
} }
} }
public synchronized SipSessionState getState() { public synchronized int getState() {
if (mSipSession == null) return SipSessionState.READY_TO_CALL; if (mSipSession == null) return SipSessionState.READY_TO_CALL;
try { try {
return Enum.valueOf(SipSessionState.class, mSipSession.getState()); return mSipSession.getState();
} catch (RemoteException e) { } catch (RemoteException e) {
return SipSessionState.REMOTE_ERROR; return SipSessionState.REMOTE_ERROR;
} }
@@ -294,15 +294,11 @@ 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, int errorCode,
String message) { String message) {
Log.d(TAG, "sip call change failed: " + message); Log.d(TAG, "sip call change failed: " + message);
mErrorCode = getErrorCode(errorCode); mErrorCode = errorCode;
mErrorMessage = message; mErrorMessage = message;
Listener listener = mListener; Listener listener = mListener;
if (listener != null) { if (listener != null) {
@@ -315,10 +311,10 @@ public class SipAudioCallImpl extends SipSessionAdapter
} }
@Override @Override
public void onError(ISipSession session, String errorCodeString, public void onError(ISipSession session, int errorCode, String message) {
String message) { Log.d(TAG, "sip session error: " + SipErrorCode.toString(errorCode)
Log.d(TAG, "sip session error: " + errorCodeString + ": " + message); + ": " + message);
SipErrorCode errorCode = mErrorCode = getErrorCode(errorCodeString); mErrorCode = errorCode;
mErrorMessage = message; mErrorMessage = message;
synchronized (this) { synchronized (this) {
if ((mErrorCode == SipErrorCode.DATA_CONNECTION_LOST) if ((mErrorCode == SipErrorCode.DATA_CONNECTION_LOST)
@@ -608,10 +604,10 @@ public class SipAudioCallImpl extends SipSessionAdapter
try { try {
startAudioInternal(); startAudioInternal();
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
onError(mSipSession, SipErrorCode.PEER_NOT_REACHABLE.toString(), onError(mSipSession, SipErrorCode.PEER_NOT_REACHABLE,
e.getMessage()); e.getMessage());
} catch (Throwable e) { } catch (Throwable e) {
onError(mSipSession, SipErrorCode.CLIENT_ERROR.toString(), onError(mSipSession, SipErrorCode.CLIENT_ERROR,
e.getMessage()); e.getMessage());
} }
} }

View File

@@ -24,34 +24,69 @@ package android.net.sip;
* {@link ISipSessionListener#onRegistrationFailed}. * {@link ISipSessionListener#onRegistrationFailed}.
* @hide * @hide
*/ */
public enum SipErrorCode { public class SipErrorCode {
/** Not an error. */
public static final int NO_ERROR = 0;
/** When some socket error occurs. */ /** When some socket error occurs. */
SOCKET_ERROR, public static final int SOCKET_ERROR = -1;
/** When server responds with an error. */ /** When server responds with an error. */
SERVER_ERROR, public static final int SERVER_ERROR = -2;
/** When transaction is terminated unexpectedly. */ /** When transaction is terminated unexpectedly. */
TRANSACTION_TERMINTED, public static final int TRANSACTION_TERMINTED = -3;
/** When some error occurs on the device, possibly due to a bug. */ /** When some error occurs on the device, possibly due to a bug. */
CLIENT_ERROR, public static final int CLIENT_ERROR = -4;
/** When the transaction gets timed out. */ /** When the transaction gets timed out. */
TIME_OUT, public static final int TIME_OUT = -5;
/** When the remote URI is not valid. */ /** When the remote URI is not valid. */
INVALID_REMOTE_URI, public static final int INVALID_REMOTE_URI = -6;
/** When the peer is not reachable. */ /** When the peer is not reachable. */
PEER_NOT_REACHABLE, public static final int PEER_NOT_REACHABLE = -7;
/** When invalid credentials are provided. */ /** When invalid credentials are provided. */
INVALID_CREDENTIALS, public static final int INVALID_CREDENTIALS = -8;
/** The client is in a transaction and cannot initiate a new one. */ /** The client is in a transaction and cannot initiate a new one. */
IN_PROGRESS, public static final int IN_PROGRESS = -9;
/** When data connection is lost. */ /** When data connection is lost. */
DATA_CONNECTION_LOST; public static final int DATA_CONNECTION_LOST = -10;
public static String toString(int errorCode) {
switch (errorCode) {
case NO_ERROR:
return "NO_ERROR";
case SOCKET_ERROR:
return "SOCKET_ERROR";
case SERVER_ERROR:
return "SERVER_ERROR";
case TRANSACTION_TERMINTED:
return "TRANSACTION_TERMINTED";
case CLIENT_ERROR:
return "CLIENT_ERROR";
case TIME_OUT:
return "TIME_OUT";
case INVALID_REMOTE_URI:
return "INVALID_REMOTE_URI";
case PEER_NOT_REACHABLE:
return "PEER_NOT_REACHABLE";
case INVALID_CREDENTIALS:
return "INVALID_CREDENTIALS";
case IN_PROGRESS:
return "IN_PROGRESS";
case DATA_CONNECTION_LOST:
return "DATA_CONNECTION_LOST";
default:
return "UNKNOWN";
}
}
private SipErrorCode() {
}
} }

View File

@@ -511,10 +511,9 @@ public class SipManager {
} }
@Override @Override
public void onRegistrationFailed(ISipSession session, String errorCode, public void onRegistrationFailed(ISipSession session, int errorCode,
String message) { String message) {
mListener.onRegistrationFailed(getUri(session), mListener.onRegistrationFailed(getUri(session), errorCode, message);
Enum.valueOf(SipErrorCode.class, errorCode), message);
} }
@Override @Override

View File

@@ -42,7 +42,8 @@ public interface SipRegistrationListener {
* @param localProfileUri the URI string of the SIP profile to register with * @param localProfileUri the URI string of the SIP profile to register with
* @param errorCode error code of this error * @param errorCode error code of this error
* @param errorMessage error message * @param errorMessage error message
* @see SipErrorCode
*/ */
void onRegistrationFailed(String localProfileUri, SipErrorCode errorCode, void onRegistrationFailed(String localProfileUri, int errorCode,
String errorMessage); String errorMessage);
} }

View File

@@ -42,11 +42,11 @@ public class SipSessionAdapter extends ISipSessionListener.Stub {
public void onCallBusy(ISipSession session) { public void onCallBusy(ISipSession session) {
} }
public void onCallChangeFailed(ISipSession session, String errorCode, public void onCallChangeFailed(ISipSession session, int errorCode,
String message) { String message) {
} }
public void onError(ISipSession session, String errorCode, String message) { public void onError(ISipSession session, int errorCode, String message) {
} }
public void onRegistering(ISipSession session) { public void onRegistering(ISipSession session) {
@@ -55,7 +55,7 @@ public class SipSessionAdapter extends ISipSessionListener.Stub {
public void onRegistrationDone(ISipSession session, int duration) { public void onRegistrationDone(ISipSession session, int duration) {
} }
public void onRegistrationFailed(ISipSession session, String errorCode, public void onRegistrationFailed(ISipSession session, int errorCode,
String message) { String message) {
} }

View File

@@ -20,47 +20,75 @@ package android.net.sip;
* Defines {@link ISipSession} states. * Defines {@link ISipSession} states.
* @hide * @hide
*/ */
public enum SipSessionState { public class SipSessionState {
/** When session is ready to initiate a call or transaction. */ /** When session is ready to initiate a call or transaction. */
READY_TO_CALL, public static final int READY_TO_CALL = 0;
/** When the registration request is sent out. */ /** When the registration request is sent out. */
REGISTERING, public static final int REGISTERING = 1;
/** When the unregistration request is sent out. */ /** When the unregistration request is sent out. */
DEREGISTERING, public static final int DEREGISTERING = 2;
/** When an INVITE request is received. */ /** When an INVITE request is received. */
INCOMING_CALL, public static final int INCOMING_CALL = 3;
/** When an OK response is sent for the INVITE request received. */ /** When an OK response is sent for the INVITE request received. */
INCOMING_CALL_ANSWERING, public static final int INCOMING_CALL_ANSWERING = 4;
/** When an INVITE request is sent. */ /** When an INVITE request is sent. */
OUTGOING_CALL, public static final int OUTGOING_CALL = 5;
/** When a RINGING response is received for the INVITE request sent. */ /** When a RINGING response is received for the INVITE request sent. */
OUTGOING_CALL_RING_BACK, public static final int OUTGOING_CALL_RING_BACK = 6;
/** When a CANCEL request is sent for the INVITE request sent. */ /** When a CANCEL request is sent for the INVITE request sent. */
OUTGOING_CALL_CANCELING, public static final int OUTGOING_CALL_CANCELING = 7;
/** When a call is established. */ /** When a call is established. */
IN_CALL, public static final int IN_CALL = 8;
/** Some error occurs when making a remote call to {@link ISipSession}. */ /** Some error occurs when making a remote call to {@link ISipSession}. */
REMOTE_ERROR, public static final int REMOTE_ERROR = 9;
/** When an OPTIONS request is sent. */ /** When an OPTIONS request is sent. */
PINGING; public static final int PINGING = 10;
/** Not defined. */
public static final int NOT_DEFINED = 101;
/** /**
* Checks if the specified string represents the same state as this object. * Converts the state to string.
*
* @return true if the specified string represents the same state as this
* object
*/ */
public boolean equals(String state) { public static String toString(int state) {
return toString().equals(state); switch (state) {
case READY_TO_CALL:
return "READY_TO_CALL";
case REGISTERING:
return "REGISTERING";
case DEREGISTERING:
return "DEREGISTERING";
case INCOMING_CALL:
return "INCOMING_CALL";
case INCOMING_CALL_ANSWERING:
return "INCOMING_CALL_ANSWERING";
case OUTGOING_CALL:
return "OUTGOING_CALL";
case OUTGOING_CALL_RING_BACK:
return "OUTGOING_CALL_RING_BACK";
case OUTGOING_CALL_CANCELING:
return "OUTGOING_CALL_CANCELING";
case IN_CALL:
return "IN_CALL";
case REMOTE_ERROR:
return "REMOTE_ERROR";
case PINGING:
return "PINGING";
default:
return "NOT_DEFINED";
}
}
private SipSessionState() {
} }
} }