diff options
Diffstat (limited to 'voip/java/android/net/sip')
-rw-r--r-- | voip/java/android/net/sip/SipAudioCall.java | 95 | ||||
-rw-r--r-- | voip/java/android/net/sip/SipManager.java | 5 | ||||
-rw-r--r-- | voip/java/android/net/sip/SipSession.java | 45 |
3 files changed, 89 insertions, 56 deletions
diff --git a/voip/java/android/net/sip/SipAudioCall.java b/voip/java/android/net/sip/SipAudioCall.java index 1d67055..ea943e9 100644 --- a/voip/java/android/net/sip/SipAudioCall.java +++ b/voip/java/android/net/sip/SipAudioCall.java @@ -25,17 +25,11 @@ import android.net.rtp.RtpStream; import android.net.sip.SimpleSessionDescription.Media; import android.net.wifi.WifiManager; import android.os.Message; -import android.os.RemoteException; +import android.telephony.Rlog; import android.text.TextUtils; -import android.util.Log; - import java.io.IOException; import java.net.InetAddress; import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; /** * Handles an Internet audio call over SIP. You can instantiate this class with {@link SipManager}, @@ -60,7 +54,8 @@ import java.util.Map; * </div> */ public class SipAudioCall { - private static final String TAG = SipAudioCall.class.getSimpleName(); + private static final String LOG_TAG = SipAudioCall.class.getSimpleName(); + private static final boolean DBG = true; private static final boolean RELEASE_SOCKET = true; private static final boolean DONT_RELEASE_SOCKET = false; private static final int SESSION_TIMEOUT = 5; // in seconds @@ -191,7 +186,6 @@ public class SipAudioCall { private boolean mMuted = false; private boolean mHold = false; - private SipProfile mPendingCallRequest; private WifiManager mWm; private WifiManager.WifiLock mWifiHighPerfLock; @@ -261,7 +255,7 @@ public class SipAudioCall { } } } catch (Throwable t) { - Log.e(TAG, "setListener()", t); + loge("setListener()", t); } } @@ -371,7 +365,7 @@ public class SipAudioCall { mAudioStream = new AudioStream(InetAddress.getByName( getLocalIp())); } catch (Throwable t) { - Log.i(TAG, "transferToNewSession(): " + t); + loge("transferToNewSession():", t); } } if (origin != null) origin.endCall(); @@ -382,26 +376,26 @@ public class SipAudioCall { return new SipSession.Listener() { @Override public void onCalling(SipSession session) { - Log.d(TAG, "calling... " + session); + if (DBG) log("onCalling: session=" + session); Listener listener = mListener; if (listener != null) { try { listener.onCalling(SipAudioCall.this); } catch (Throwable t) { - Log.i(TAG, "onCalling(): " + t); + loge("onCalling():", t); } } } @Override public void onRingingBack(SipSession session) { - Log.d(TAG, "sip call ringing back: " + session); + if (DBG) log("onRingingBackk: " + session); Listener listener = mListener; if (listener != null) { try { listener.onRingingBack(SipAudioCall.this); } catch (Throwable t) { - Log.i(TAG, "onRingingBack(): " + t); + loge("onRingingBack():", t); } } } @@ -424,7 +418,7 @@ public class SipAudioCall { String answer = createAnswer(sessionDescription).encode(); mSipSession.answerCall(answer, SESSION_TIMEOUT); } catch (Throwable e) { - Log.e(TAG, "onRinging()", e); + loge("onRinging():", e); session.endCall(); } } @@ -434,7 +428,7 @@ public class SipAudioCall { public void onCallEstablished(SipSession session, String sessionDescription) { mPeerSd = sessionDescription; - Log.v(TAG, "onCallEstablished()" + mPeerSd); + if (DBG) log("onCallEstablished(): " + mPeerSd); // TODO: how to notify the UI that the remote party is changed if ((mTransferringSession != null) @@ -452,14 +446,14 @@ public class SipAudioCall { listener.onCallEstablished(SipAudioCall.this); } } catch (Throwable t) { - Log.i(TAG, "onCallEstablished(): " + t); + loge("onCallEstablished(): ", t); } } } @Override public void onCallEnded(SipSession session) { - Log.d(TAG, "sip call ended: " + session + " mSipSession:" + mSipSession); + if (DBG) log("onCallEnded: " + session + " mSipSession:" + mSipSession); // reset the trasnferring session if it is the one. if (session == mTransferringSession) { mTransferringSession = null; @@ -475,7 +469,7 @@ public class SipAudioCall { try { listener.onCallEnded(SipAudioCall.this); } catch (Throwable t) { - Log.i(TAG, "onCallEnded(): " + t); + loge("onCallEnded(): ", t); } } close(); @@ -483,13 +477,13 @@ public class SipAudioCall { @Override public void onCallBusy(SipSession session) { - Log.d(TAG, "sip call busy: " + session); + if (DBG) log("onCallBusy: " + session); Listener listener = mListener; if (listener != null) { try { listener.onCallBusy(SipAudioCall.this); } catch (Throwable t) { - Log.i(TAG, "onCallBusy(): " + t); + loge("onCallBusy(): ", t); } } close(false); @@ -498,7 +492,7 @@ public class SipAudioCall { @Override public void onCallChangeFailed(SipSession session, int errorCode, String message) { - Log.d(TAG, "sip call change failed: " + message); + if (DBG) log("onCallChangedFailed: " + message); mErrorCode = errorCode; mErrorMessage = message; Listener listener = mListener; @@ -507,7 +501,7 @@ public class SipAudioCall { listener.onError(SipAudioCall.this, mErrorCode, message); } catch (Throwable t) { - Log.i(TAG, "onCallBusy(): " + t); + loge("onCallBusy():", t); } } } @@ -542,8 +536,8 @@ public class SipAudioCall { @Override public void onCallTransferring(SipSession newSession, String sessionDescription) { - Log.v(TAG, "onCallTransferring mSipSession:" - + mSipSession + " newSession:" + newSession); + if (DBG) log("onCallTransferring: mSipSession=" + + mSipSession + " newSession=" + newSession); mTransferringSession = newSession; try { if (sessionDescription == null) { @@ -554,7 +548,7 @@ public class SipAudioCall { newSession.answerCall(answer, SESSION_TIMEOUT); } } catch (Throwable e) { - Log.e(TAG, "onCallTransferring()", e); + loge("onCallTransferring()", e); newSession.endCall(); } } @@ -562,7 +556,7 @@ public class SipAudioCall { } private void onError(int errorCode, String message) { - Log.d(TAG, "sip session error: " + if (DBG) log("onError: " + SipErrorCode.toString(errorCode) + ": " + message); mErrorCode = errorCode; mErrorMessage = message; @@ -571,7 +565,7 @@ public class SipAudioCall { try { listener.onError(this, errorCode, message); } catch (Throwable t) { - Log.i(TAG, "onError(): " + t); + loge("onError():", t); } } synchronized (this) { @@ -600,11 +594,11 @@ public class SipAudioCall { synchronized (this) { mSipSession = session; mPeerSd = sessionDescription; - Log.v(TAG, "attachCall()" + mPeerSd); + if (DBG) log("attachCall(): " + mPeerSd); try { session.setListener(createListener()); } catch (Throwable e) { - Log.e(TAG, "attachCall()", e); + loge("attachCall()", e); throwSipException(e); } } @@ -627,6 +621,7 @@ public class SipAudioCall { */ public void makeCall(SipProfile peerProfile, SipSession sipSession, int timeout) throws SipException { + if (DBG) log("makeCall: " + peerProfile + " session=" + sipSession + " timeout=" + timeout); if (!SipManager.isVoipSupported(mContext)) { throw new SipException("VOIP API is not supported"); } @@ -640,6 +635,7 @@ public class SipAudioCall { sipSession.makeCall(peerProfile, createOffer().encode(), timeout); } catch (IOException e) { + loge("makeCall:", e); throw new SipException("makeCall()", e); } } @@ -650,6 +646,7 @@ public class SipAudioCall { * @throws SipException if the SIP service fails to end the call */ public void endCall() throws SipException { + if (DBG) log("endCall: mSipSession" + mSipSession); synchronized (this) { stopCall(RELEASE_SOCKET); mInCall = false; @@ -672,9 +669,11 @@ public class SipAudioCall { * @throws SipException if the SIP service fails to hold the call */ public void holdCall(int timeout) throws SipException { + if (DBG) log("holdCall: mSipSession" + mSipSession + " timeout=" + timeout); synchronized (this) { if (mHold) return; if (mSipSession == null) { + loge("holdCall:"); throw new SipException("Not in a call to hold call"); } mSipSession.changeCall(createHoldOffer().encode(), timeout); @@ -695,6 +694,7 @@ public class SipAudioCall { * @throws SipException if the SIP service fails to answer the call */ public void answerCall(int timeout) throws SipException { + if (DBG) log("answerCall: mSipSession" + mSipSession + " timeout=" + timeout); synchronized (this) { if (mSipSession == null) { throw new SipException("No call to answer"); @@ -704,6 +704,7 @@ public class SipAudioCall { getLocalIp())); mSipSession.answerCall(createAnswer(mPeerSd).encode(), timeout); } catch (IOException e) { + loge("answerCall:", e); throw new SipException("answerCall()", e); } } @@ -722,6 +723,7 @@ public class SipAudioCall { * @throws SipException if the SIP service fails to unhold the call */ public void continueCall(int timeout) throws SipException { + if (DBG) log("continueCall: mSipSession" + mSipSession + " timeout=" + timeout); synchronized (this) { if (!mHold) return; mSipSession.changeCall(createContinueOffer().encode(), timeout); @@ -740,6 +742,7 @@ public class SipAudioCall { media.setRtpPayload(codec.type, codec.rtpmap, codec.fmtp); } media.setRtpPayload(127, "telephone-event/8000", "0-15"); + if (DBG) log("createOffer: offer=" + offer); return offer; } @@ -798,18 +801,22 @@ public class SipAudioCall { } } if (codec == null) { + loge("createAnswer: no suitable codes"); throw new IllegalStateException("Reject SDP: no suitable codecs"); } + if (DBG) log("createAnswer: answer=" + answer); return answer; } private SimpleSessionDescription createHoldOffer() { SimpleSessionDescription offer = createContinueOffer(); offer.setAttribute("sendonly", ""); + if (DBG) log("createHoldOffer: offer=" + offer); return offer; } private SimpleSessionDescription createContinueOffer() { + if (DBG) log("createContinueOffer"); SimpleSessionDescription offer = new SimpleSessionDescription(mSessionId, getLocalIp()); Media media = offer.newMedia( @@ -825,17 +832,17 @@ public class SipAudioCall { private void grabWifiHighPerfLock() { if (mWifiHighPerfLock == null) { - Log.v(TAG, "acquire wifi high perf lock"); + if (DBG) log("grabWifiHighPerfLock:"); mWifiHighPerfLock = ((WifiManager) mContext.getSystemService(Context.WIFI_SERVICE)) - .createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, TAG); + .createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, LOG_TAG); mWifiHighPerfLock.acquire(); } } private void releaseWifiHighPerfLock() { if (mWifiHighPerfLock != null) { - Log.v(TAG, "release wifi high perf lock"); + if (DBG) log("releaseWifiHighPerfLock:"); mWifiHighPerfLock.release(); mWifiHighPerfLock = null; } @@ -912,7 +919,7 @@ public class SipAudioCall { AudioGroup audioGroup = getAudioGroup(); if ((audioGroup != null) && (mSipSession != null) && (SipSession.State.IN_CALL == getState())) { - Log.v(TAG, "send DTMF: " + code); + if (DBG) log("sendDtmf: code=" + code + " result=" + result); audioGroup.sendDtmf(code); } if (result != null) result.sendToTarget(); @@ -971,6 +978,7 @@ public class SipAudioCall { */ public void setAudioGroup(AudioGroup group) { synchronized (this) { + if (DBG) log("setAudioGroup: group=" + group); if ((mAudioStream != null) && (mAudioStream.getGroup() != null)) { mAudioStream.join(group); } @@ -997,8 +1005,8 @@ public class SipAudioCall { } private synchronized void startAudioInternal() throws UnknownHostException { + if (DBG) loge("startAudioInternal: mPeerSd=" + mPeerSd); if (mPeerSd == null) { - Log.v(TAG, "startAudioInternal() mPeerSd = null"); throw new IllegalStateException("mPeerSd = null"); } @@ -1082,6 +1090,7 @@ public class SipAudioCall { // set audio group mode based on current audio configuration private void setAudioGroupMode() { AudioGroup audioGroup = getAudioGroup(); + if (DBG) log("setAudioGroupMode: audioGroup=" + audioGroup); if (audioGroup != null) { if (mHold) { audioGroup.setMode(AudioGroup.MODE_ON_HOLD); @@ -1096,7 +1105,7 @@ public class SipAudioCall { } private void stopCall(boolean releaseSocket) { - Log.d(TAG, "stop audiocall"); + if (DBG) log("stopCall: releaseSocket=" + releaseSocket); releaseWifiHighPerfLock(); if (mAudioStream != null) { mAudioStream.join(null); @@ -1120,7 +1129,15 @@ public class SipAudioCall { } } - private SipProfile getPeerProfile(SipSession session) { - return session.getPeerProfile(); + private void log(String s) { + Rlog.d(LOG_TAG, s); + } + + private void loge(String s) { + Rlog.e(LOG_TAG, s); + } + + private void loge(String s, Throwable t) { + Rlog.e(LOG_TAG, s, t); } } diff --git a/voip/java/android/net/sip/SipManager.java b/voip/java/android/net/sip/SipManager.java index 74c3672..a94232a 100644 --- a/voip/java/android/net/sip/SipManager.java +++ b/voip/java/android/net/sip/SipManager.java @@ -21,10 +21,9 @@ import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.os.IBinder; -import android.os.Looper; import android.os.RemoteException; import android.os.ServiceManager; -import android.util.Log; +import android.telephony.Rlog; import java.text.ParseException; @@ -591,7 +590,7 @@ public class SipManager { : session.getLocalProfile().getUriString()); } catch (Throwable e) { // SipService died? SIP stack died? - Log.w(TAG, "getUri(): " + e); + Rlog.e(TAG, "getUri(): ", e); return null; } } diff --git a/voip/java/android/net/sip/SipSession.java b/voip/java/android/net/sip/SipSession.java index e03cf9f..edbc66f 100644 --- a/voip/java/android/net/sip/SipSession.java +++ b/voip/java/android/net/sip/SipSession.java @@ -17,7 +17,7 @@ package android.net.sip; import android.os.RemoteException; -import android.util.Log; +import android.telephony.Rlog; /** * Represents a SIP session that is associated with a SIP dialog or a standalone @@ -242,7 +242,7 @@ public final class SipSession { try { realSession.setListener(createListener()); } catch (RemoteException e) { - Log.e(TAG, "SipSession.setListener(): " + e); + loge("SipSession.setListener:", e); } } } @@ -261,7 +261,7 @@ public final class SipSession { try { return mSession.getLocalIp(); } catch (RemoteException e) { - Log.e(TAG, "getLocalIp(): " + e); + loge("getLocalIp:", e); return "127.0.0.1"; } } @@ -275,7 +275,7 @@ public final class SipSession { try { return mSession.getLocalProfile(); } catch (RemoteException e) { - Log.e(TAG, "getLocalProfile(): " + e); + loge("getLocalProfile:", e); return null; } } @@ -290,7 +290,7 @@ public final class SipSession { try { return mSession.getPeerProfile(); } catch (RemoteException e) { - Log.e(TAG, "getPeerProfile(): " + e); + loge("getPeerProfile:", e); return null; } } @@ -305,7 +305,7 @@ public final class SipSession { try { return mSession.getState(); } catch (RemoteException e) { - Log.e(TAG, "getState(): " + e); + loge("getState:", e); return State.NOT_DEFINED; } } @@ -319,7 +319,7 @@ public final class SipSession { try { return mSession.isInCall(); } catch (RemoteException e) { - Log.e(TAG, "isInCall(): " + e); + loge("isInCall:", e); return false; } } @@ -333,7 +333,7 @@ public final class SipSession { try { return mSession.getCallId(); } catch (RemoteException e) { - Log.e(TAG, "getCallId(): " + e); + loge("getCallId:", e); return null; } } @@ -364,7 +364,7 @@ public final class SipSession { try { mSession.register(duration); } catch (RemoteException e) { - Log.e(TAG, "register(): " + e); + loge("register:", e); } } @@ -381,7 +381,7 @@ public final class SipSession { try { mSession.unregister(); } catch (RemoteException e) { - Log.e(TAG, "unregister(): " + e); + loge("unregister:", e); } } @@ -402,7 +402,7 @@ public final class SipSession { try { mSession.makeCall(callee, sessionDescription, timeout); } catch (RemoteException e) { - Log.e(TAG, "makeCall(): " + e); + loge("makeCall:", e); } } @@ -420,7 +420,7 @@ public final class SipSession { try { mSession.answerCall(sessionDescription, timeout); } catch (RemoteException e) { - Log.e(TAG, "answerCall(): " + e); + loge("answerCall:", e); } } @@ -436,7 +436,7 @@ public final class SipSession { try { mSession.endCall(); } catch (RemoteException e) { - Log.e(TAG, "endCall(): " + e); + loge("endCall:", e); } } @@ -453,7 +453,7 @@ public final class SipSession { try { mSession.changeCall(sessionDescription, timeout); } catch (RemoteException e) { - Log.e(TAG, "changeCall(): " + e); + loge("changeCall:", e); } } @@ -463,12 +463,14 @@ public final class SipSession { private ISipSessionListener createListener() { return new ISipSessionListener.Stub() { + @Override public void onCalling(ISipSession session) { if (mListener != null) { mListener.onCalling(SipSession.this); } } + @Override public void onRinging(ISipSession session, SipProfile caller, String sessionDescription) { if (mListener != null) { @@ -477,12 +479,14 @@ public final class SipSession { } } + @Override public void onRingingBack(ISipSession session) { if (mListener != null) { mListener.onRingingBack(SipSession.this); } } + @Override public void onCallEstablished(ISipSession session, String sessionDescription) { if (mListener != null) { @@ -491,18 +495,21 @@ public final class SipSession { } } + @Override public void onCallEnded(ISipSession session) { if (mListener != null) { mListener.onCallEnded(SipSession.this); } } + @Override public void onCallBusy(ISipSession session) { if (mListener != null) { mListener.onCallBusy(SipSession.this); } } + @Override public void onCallTransferring(ISipSession session, String sessionDescription) { if (mListener != null) { @@ -513,6 +520,7 @@ public final class SipSession { } } + @Override public void onCallChangeFailed(ISipSession session, int errorCode, String message) { if (mListener != null) { @@ -521,24 +529,28 @@ public final class SipSession { } } + @Override public void onError(ISipSession session, int errorCode, String message) { if (mListener != null) { mListener.onError(SipSession.this, errorCode, message); } } + @Override public void onRegistering(ISipSession session) { if (mListener != null) { mListener.onRegistering(SipSession.this); } } + @Override public void onRegistrationDone(ISipSession session, int duration) { if (mListener != null) { mListener.onRegistrationDone(SipSession.this, duration); } } + @Override public void onRegistrationFailed(ISipSession session, int errorCode, String message) { if (mListener != null) { @@ -547,6 +559,7 @@ public final class SipSession { } } + @Override public void onRegistrationTimeout(ISipSession session) { if (mListener != null) { mListener.onRegistrationTimeout(SipSession.this); @@ -554,4 +567,8 @@ public final class SipSession { } }; } + + private void loge(String s, Throwable t) { + Rlog.e(TAG, s, t); + } } |