summaryrefslogtreecommitdiffstats
path: root/voip
diff options
context:
space:
mode:
authorHung-ying Tyan <tyanh@google.com>2010-09-17 16:58:51 +0800
committerHung-ying Tyan <tyanh@google.com>2010-09-20 09:51:31 +0800
commit97963794af1e18674dd111e3ad344d90b16c922c (patch)
tree837c389d57da8ef0a39b2e480bd4f641a2f37ffb /voip
parent5b930c49b12bdb1461a18491db768c642c38d498 (diff)
downloadframeworks_base-97963794af1e18674dd111e3ad344d90b16c922c.zip
frameworks_base-97963794af1e18674dd111e3ad344d90b16c922c.tar.gz
frameworks_base-97963794af1e18674dd111e3ad344d90b16c922c.tar.bz2
SIP: convert enum to static final int.
Converts SipErrorCode and SipSessionState. Change-Id: Iee3a465649ea89d395b2336bbd673c25113e5f93
Diffstat (limited to 'voip')
-rw-r--r--voip/java/android/net/sip/ISipSession.aidl7
-rw-r--r--voip/java/android/net/sip/ISipSessionListener.aidl7
-rw-r--r--voip/java/android/net/sip/SipAudioCall.java9
-rw-r--r--voip/java/android/net/sip/SipAudioCallImpl.java40
-rw-r--r--voip/java/android/net/sip/SipErrorCode.java57
-rw-r--r--voip/java/android/net/sip/SipManager.java5
-rw-r--r--voip/java/android/net/sip/SipRegistrationListener.java3
-rw-r--r--voip/java/android/net/sip/SipSessionAdapter.java6
-rw-r--r--voip/java/android/net/sip/SipSessionState.java64
9 files changed, 127 insertions, 71 deletions
diff --git a/voip/java/android/net/sip/ISipSession.aidl b/voip/java/android/net/sip/ISipSession.aidl
index 5661b8f..2d515db 100644
--- a/voip/java/android/net/sip/ISipSession.aidl
+++ b/voip/java/android/net/sip/ISipSession.aidl
@@ -49,14 +49,11 @@ interface ISipSession {
/**
* Gets the session state. The value returned must be one of the states in
- * {@link SipSessionState}. One may convert it to {@link SipSessionState} by
- * <code>
- * Enum.valueOf(SipSessionState.class, session.getState());
- * </code>
+ * {@link SipSessionState}.
*
* @return the session state
*/
- String getState();
+ int getState();
/**
* Checks if the session is in a call.
diff --git a/voip/java/android/net/sip/ISipSessionListener.aidl b/voip/java/android/net/sip/ISipSessionListener.aidl
index 0a6220b..5920bca 100644
--- a/voip/java/android/net/sip/ISipSessionListener.aidl
+++ b/voip/java/android/net/sip/ISipSessionListener.aidl
@@ -79,8 +79,7 @@ interface ISipSessionListener {
* @param errorCode error code defined in {@link SipErrorCode}
* @param errorMessage error message
*/
- void onError(in ISipSession session, String errorCode,
- String errorMessage);
+ void onError(in ISipSession session, int errorCode, String errorMessage);
/**
* Called when an error occurs during session modification negotiation.
@@ -89,7 +88,7 @@ interface ISipSessionListener {
* @param errorCode error code defined in {@link SipErrorCode}
* @param errorMessage error message
*/
- void onCallChangeFailed(in ISipSession session, String errorCode,
+ void onCallChangeFailed(in ISipSession session, int errorCode,
String errorMessage);
/**
@@ -114,7 +113,7 @@ interface ISipSessionListener {
* @param errorCode error code defined in {@link SipErrorCode}
* @param errorMessage error message
*/
- void onRegistrationFailed(in ISipSession session, String errorCode,
+ void onRegistrationFailed(in ISipSession session, int errorCode,
String errorMessage);
/**
diff --git a/voip/java/android/net/sip/SipAudioCall.java b/voip/java/android/net/sip/SipAudioCall.java
index 4abea20..0069fe0 100644
--- a/voip/java/android/net/sip/SipAudioCall.java
+++ b/voip/java/android/net/sip/SipAudioCall.java
@@ -90,9 +90,9 @@ public interface SipAudioCall {
* @param call the call object that carries out the audio call
* @param errorCode error code of this error
* @param errorMessage error message
+ * @see SipErrorCode
*/
- void onError(SipAudioCall call, SipErrorCode errorCode,
- String errorMessage);
+ void onError(SipAudioCall call, int errorCode, String errorMessage);
}
/**
@@ -126,7 +126,7 @@ public interface SipAudioCall {
public void onCallHeld(SipAudioCall call) {
onChanged(call);
}
- public void onError(SipAudioCall call, SipErrorCode errorCode,
+ public void onError(SipAudioCall call, int errorCode,
String errorMessage) {
onChanged(call);
}
@@ -318,10 +318,11 @@ public interface SipAudioCall {
/**
* 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
*/
- SipSessionState getState();
+ int getState();
/**
* Gets the {@link ISipSession} that carries this call.
diff --git a/voip/java/android/net/sip/SipAudioCallImpl.java b/voip/java/android/net/sip/SipAudioCallImpl.java
index e61e878..111bfff 100644
--- a/voip/java/android/net/sip/SipAudioCallImpl.java
+++ b/voip/java/android/net/sip/SipAudioCallImpl.java
@@ -81,7 +81,7 @@ public class SipAudioCallImpl extends SipSessionAdapter
private WifiManager mWm;
private WifiManager.WifiLock mWifiHighPerfLock;
- private SipErrorCode mErrorCode;
+ private int mErrorCode = SipErrorCode.NO_ERROR;
private String mErrorMessage;
public SipAudioCallImpl(Context context, SipProfile localProfile) {
@@ -100,7 +100,7 @@ public class SipAudioCallImpl extends SipSessionAdapter
try {
if ((listener == null) || !callbackImmediately) {
// do nothing
- } else if (mErrorCode != null) {
+ } else if (mErrorCode != SipErrorCode.NO_ERROR) {
listener.onError(this, mErrorCode, mErrorMessage);
} else if (mInCall) {
if (mHold) {
@@ -109,18 +109,18 @@ public class SipAudioCallImpl extends SipSessionAdapter
listener.onCallEstablished(this);
}
} else {
- SipSessionState state = getState();
+ int state = getState();
switch (state) {
- case READY_TO_CALL:
+ case SipSessionState.READY_TO_CALL:
listener.onReadyToCall(this);
break;
- case INCOMING_CALL:
+ case SipSessionState.INCOMING_CALL:
listener.onRinging(this, getPeerProfile(mSipSession));
break;
- case OUTGOING_CALL:
+ case SipSessionState.OUTGOING_CALL:
listener.onCalling(this);
break;
- case OUTGOING_CALL_RING_BACK:
+ case SipSessionState.OUTGOING_CALL_RING_BACK:
listener.onRingingBack(this);
break;
}
@@ -150,7 +150,7 @@ public class SipAudioCallImpl extends SipSessionAdapter
mInCall = false;
mHold = false;
mSessionId = -1L;
- mErrorCode = null;
+ mErrorCode = SipErrorCode.NO_ERROR;
mErrorMessage = 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;
try {
- return Enum.valueOf(SipSessionState.class, mSipSession.getState());
+ return mSipSession.getState();
} catch (RemoteException e) {
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
- public void onCallChangeFailed(ISipSession session, String errorCode,
+ public void onCallChangeFailed(ISipSession session, int errorCode,
String message) {
Log.d(TAG, "sip call change failed: " + message);
- mErrorCode = getErrorCode(errorCode);
+ mErrorCode = errorCode;
mErrorMessage = message;
Listener listener = mListener;
if (listener != null) {
@@ -315,10 +311,10 @@ public class SipAudioCallImpl extends SipSessionAdapter
}
@Override
- public void onError(ISipSession session, String errorCodeString,
- String message) {
- Log.d(TAG, "sip session error: " + errorCodeString + ": " + message);
- SipErrorCode errorCode = mErrorCode = getErrorCode(errorCodeString);
+ public void onError(ISipSession session, int errorCode, String message) {
+ Log.d(TAG, "sip session error: " + SipErrorCode.toString(errorCode)
+ + ": " + message);
+ mErrorCode = errorCode;
mErrorMessage = message;
synchronized (this) {
if ((mErrorCode == SipErrorCode.DATA_CONNECTION_LOST)
@@ -608,10 +604,10 @@ public class SipAudioCallImpl extends SipSessionAdapter
try {
startAudioInternal();
} catch (UnknownHostException e) {
- onError(mSipSession, SipErrorCode.PEER_NOT_REACHABLE.toString(),
+ onError(mSipSession, SipErrorCode.PEER_NOT_REACHABLE,
e.getMessage());
} catch (Throwable e) {
- onError(mSipSession, SipErrorCode.CLIENT_ERROR.toString(),
+ onError(mSipSession, SipErrorCode.CLIENT_ERROR,
e.getMessage());
}
}
diff --git a/voip/java/android/net/sip/SipErrorCode.java b/voip/java/android/net/sip/SipErrorCode.java
index a27f740..7496d28 100644
--- a/voip/java/android/net/sip/SipErrorCode.java
+++ b/voip/java/android/net/sip/SipErrorCode.java
@@ -24,34 +24,69 @@ package android.net.sip;
* {@link ISipSessionListener#onRegistrationFailed}.
* @hide
*/
-public enum SipErrorCode {
+public class SipErrorCode {
+ /** Not an error. */
+ public static final int NO_ERROR = 0;
+
/** When some socket error occurs. */
- SOCKET_ERROR,
+ public static final int SOCKET_ERROR = -1;
/** When server responds with an error. */
- SERVER_ERROR,
+ public static final int SERVER_ERROR = -2;
/** 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. */
- CLIENT_ERROR,
+ public static final int CLIENT_ERROR = -4;
/** When the transaction gets timed out. */
- TIME_OUT,
+ public static final int TIME_OUT = -5;
/** When the remote URI is not valid. */
- INVALID_REMOTE_URI,
+ public static final int INVALID_REMOTE_URI = -6;
/** When the peer is not reachable. */
- PEER_NOT_REACHABLE,
+ public static final int PEER_NOT_REACHABLE = -7;
/** 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. */
- IN_PROGRESS,
+ public static final int IN_PROGRESS = -9;
/** 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() {
+ }
}
diff --git a/voip/java/android/net/sip/SipManager.java b/voip/java/android/net/sip/SipManager.java
index 9ee6f34..31768d7 100644
--- a/voip/java/android/net/sip/SipManager.java
+++ b/voip/java/android/net/sip/SipManager.java
@@ -511,10 +511,9 @@ public class SipManager {
}
@Override
- public void onRegistrationFailed(ISipSession session, String errorCode,
+ public void onRegistrationFailed(ISipSession session, int errorCode,
String message) {
- mListener.onRegistrationFailed(getUri(session),
- Enum.valueOf(SipErrorCode.class, errorCode), message);
+ mListener.onRegistrationFailed(getUri(session), errorCode, message);
}
@Override
diff --git a/voip/java/android/net/sip/SipRegistrationListener.java b/voip/java/android/net/sip/SipRegistrationListener.java
index 705f271..37c9ce2 100644
--- a/voip/java/android/net/sip/SipRegistrationListener.java
+++ b/voip/java/android/net/sip/SipRegistrationListener.java
@@ -42,7 +42,8 @@ public interface SipRegistrationListener {
* @param localProfileUri the URI string of the SIP profile to register with
* @param errorCode error code of this error
* @param errorMessage error message
+ * @see SipErrorCode
*/
- void onRegistrationFailed(String localProfileUri, SipErrorCode errorCode,
+ void onRegistrationFailed(String localProfileUri, int errorCode,
String errorMessage);
}
diff --git a/voip/java/android/net/sip/SipSessionAdapter.java b/voip/java/android/net/sip/SipSessionAdapter.java
index 6020f2c..86aca37 100644
--- a/voip/java/android/net/sip/SipSessionAdapter.java
+++ b/voip/java/android/net/sip/SipSessionAdapter.java
@@ -42,11 +42,11 @@ public class SipSessionAdapter extends ISipSessionListener.Stub {
public void onCallBusy(ISipSession session) {
}
- public void onCallChangeFailed(ISipSession session, String errorCode,
+ public void onCallChangeFailed(ISipSession session, int errorCode,
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) {
@@ -55,7 +55,7 @@ public class SipSessionAdapter extends ISipSessionListener.Stub {
public void onRegistrationDone(ISipSession session, int duration) {
}
- public void onRegistrationFailed(ISipSession session, String errorCode,
+ public void onRegistrationFailed(ISipSession session, int errorCode,
String message) {
}
diff --git a/voip/java/android/net/sip/SipSessionState.java b/voip/java/android/net/sip/SipSessionState.java
index 5bab112..31e9d3f 100644
--- a/voip/java/android/net/sip/SipSessionState.java
+++ b/voip/java/android/net/sip/SipSessionState.java
@@ -20,47 +20,75 @@ package android.net.sip;
* Defines {@link ISipSession} states.
* @hide
*/
-public enum SipSessionState {
+public class SipSessionState {
/** 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. */
- REGISTERING,
+ public static final int REGISTERING = 1;
/** When the unregistration request is sent out. */
- DEREGISTERING,
+ public static final int DEREGISTERING = 2;
/** 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. */
- INCOMING_CALL_ANSWERING,
+ public static final int INCOMING_CALL_ANSWERING = 4;
/** 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. */
- OUTGOING_CALL_RING_BACK,
+ public static final int OUTGOING_CALL_RING_BACK = 6;
/** 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. */
- IN_CALL,
+ public static final int IN_CALL = 8;
/** 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. */
- 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.
- *
- * @return true if the specified string represents the same state as this
- * object
+ * Converts the state to string.
*/
- public boolean equals(String state) {
- return toString().equals(state);
+ public static String toString(int 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() {
}
}