summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWink Saville <wink@google.com>2013-01-22 16:01:58 -0800
committerWink Saville <wink@google.com>2013-01-22 16:01:58 -0800
commit9329db04f13480ccdff013dcc00cdb96f12a921c (patch)
treebd9d2ed8dbc74c83b3d96f4053f7e7c0c066b5d2
parent17745436aa6d76765791f3c877360399b6a95487 (diff)
downloadvoip-9329db04f13480ccdff013dcc00cdb96f12a921c.tar.gz
Add debug and some cleanup
Change-Id: I866676a1ec4a338dcfe089cbf0483e5e546ded85
-rw-r--r--java/android/net/sip/SipAudioCall.java95
-rw-r--r--java/android/net/sip/SipManager.java5
-rw-r--r--java/android/net/sip/SipSession.java45
-rw-r--r--java/com/android/server/sip/SipHelper.java40
-rw-r--r--java/com/android/server/sip/SipService.java271
-rw-r--r--java/com/android/server/sip/SipSessionGroup.java272
-rw-r--r--java/com/android/server/sip/SipSessionListenerProxy.java40
-rw-r--r--java/com/android/server/sip/SipWakeLock.java14
-rw-r--r--java/com/android/server/sip/SipWakeupTimer.java61
9 files changed, 499 insertions, 344 deletions
diff --git a/java/android/net/sip/SipAudioCall.java b/java/android/net/sip/SipAudioCall.java
index 1d67055..ea943e9 100644
--- a/java/android/net/sip/SipAudioCall.java
+++ b/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/java/android/net/sip/SipManager.java b/java/android/net/sip/SipManager.java
index 74c3672..a94232a 100644
--- a/java/android/net/sip/SipManager.java
+++ b/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/java/android/net/sip/SipSession.java b/java/android/net/sip/SipSession.java
index e03cf9f..edbc66f 100644
--- a/java/android/net/sip/SipSession.java
+++ b/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);
+ }
}
diff --git a/java/com/android/server/sip/SipHelper.java b/java/com/android/server/sip/SipHelper.java
index 113f007..c708be8 100644
--- a/java/com/android/server/sip/SipHelper.java
+++ b/java/com/android/server/sip/SipHelper.java
@@ -24,7 +24,7 @@ import gov.nist.javax.sip.header.extensions.ReferredByHeader;
import gov.nist.javax.sip.header.extensions.ReplacesHeader;
import android.net.sip.SipProfile;
-import android.util.Log;
+import android.telephony.Rlog;
import java.text.ParseException;
import java.util.ArrayList;
@@ -46,9 +46,7 @@ import javax.sip.SipFactory;
import javax.sip.SipProvider;
import javax.sip.SipStack;
import javax.sip.Transaction;
-import javax.sip.TransactionAlreadyExistsException;
import javax.sip.TransactionTerminatedEvent;
-import javax.sip.TransactionUnavailableException;
import javax.sip.TransactionState;
import javax.sip.address.Address;
import javax.sip.address.AddressFactory;
@@ -73,8 +71,8 @@ import javax.sip.message.Response;
*/
class SipHelper {
private static final String TAG = SipHelper.class.getSimpleName();
- private static final boolean DEBUG = false;
- private static final boolean DEBUG_PING = false;
+ private static final boolean DBG = false;
+ private static final boolean DBG_PING = false;
private SipStack mSipStack;
private SipProvider mSipProvider;
@@ -262,7 +260,7 @@ class SipHelper {
ClientTransaction tid = responseEvent.getClientTransaction();
ClientTransaction ct = authenticationHelper.handleChallenge(
responseEvent.getResponse(), tid, mSipProvider, 5);
- if (DEBUG) Log.d(TAG, "send request with challenge response: "
+ if (DBG) log("send request with challenge response: "
+ ct.getRequest());
ct.sendRequest();
return ct;
@@ -301,7 +299,7 @@ class SipHelper {
"application", "sdp"));
ClientTransaction clientTransaction =
mSipProvider.getNewClientTransaction(request);
- if (DEBUG) Log.d(TAG, "send INVITE: " + request);
+ if (DBG) log("send INVITE: " + request);
clientTransaction.sendRequest();
return clientTransaction;
} catch (ParseException e) {
@@ -326,7 +324,7 @@ class SipHelper {
ClientTransaction clientTransaction =
mSipProvider.getNewClientTransaction(request);
- if (DEBUG) Log.d(TAG, "send RE-INVITE: " + request);
+ if (DBG) log("send RE-INVITE: " + request);
dialog.sendRequest(clientTransaction);
return clientTransaction;
} catch (ParseException e) {
@@ -360,7 +358,7 @@ class SipHelper {
ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
toHeader.setTag(tag);
response.addHeader(toHeader);
- if (DEBUG) Log.d(TAG, "send RINGING: " + response);
+ if (DBG) log("send RINGING: " + response);
transaction.sendResponse(response);
return transaction;
} catch (ParseException e) {
@@ -390,7 +388,7 @@ class SipHelper {
}
if (inviteTransaction.getState() != TransactionState.COMPLETED) {
- if (DEBUG) Log.d(TAG, "send OK: " + response);
+ if (DBG) log("send OK: " + response);
inviteTransaction.sendResponse(response);
}
@@ -412,7 +410,7 @@ class SipHelper {
}
if (inviteTransaction.getState() != TransactionState.COMPLETED) {
- if (DEBUG) Log.d(TAG, "send BUSY HERE: " + response);
+ if (DBG) log("send BUSY HERE: " + response);
inviteTransaction.sendResponse(response);
}
} catch (ParseException e) {
@@ -429,20 +427,20 @@ class SipHelper {
long cseq = ((CSeqHeader) response.getHeader(CSeqHeader.NAME))
.getSeqNumber();
Request ack = dialog.createAck(cseq);
- if (DEBUG) Log.d(TAG, "send ACK: " + ack);
+ if (DBG) log("send ACK: " + ack);
dialog.sendAck(ack);
}
public void sendBye(Dialog dialog) throws SipException {
Request byeRequest = dialog.createRequest(Request.BYE);
- if (DEBUG) Log.d(TAG, "send BYE: " + byeRequest);
+ if (DBG) log("send BYE: " + byeRequest);
dialog.sendRequest(mSipProvider.getNewClientTransaction(byeRequest));
}
public void sendCancel(ClientTransaction inviteTransaction)
throws SipException {
Request cancelRequest = inviteTransaction.createCancel();
- if (DEBUG) Log.d(TAG, "send CANCEL: " + cancelRequest);
+ if (DBG) log("send CANCEL: " + cancelRequest);
mSipProvider.getNewClientTransaction(cancelRequest).sendRequest();
}
@@ -452,9 +450,9 @@ class SipHelper {
Request request = event.getRequest();
Response response = mMessageFactory.createResponse(
responseCode, request);
- if (DEBUG && (!Request.OPTIONS.equals(request.getMethod())
- || DEBUG_PING)) {
- Log.d(TAG, "send response: " + response);
+ if (DBG && (!Request.OPTIONS.equals(request.getMethod())
+ || DBG_PING)) {
+ log("send response: " + response);
}
getServerTransaction(event).sendResponse(response);
} catch (ParseException e) {
@@ -474,7 +472,7 @@ class SipHelper {
"message", "sipfrag"));
request.addHeader(mHeaderFactory.createEventHeader(
ReferencesHeader.REFER));
- if (DEBUG) Log.d(TAG, "send NOTIFY: " + request);
+ if (DBG) log("send NOTIFY: " + request);
dialog.sendRequest(mSipProvider.getNewClientTransaction(request));
} catch (ParseException e) {
throw new SipException("sendReferNotify()", e);
@@ -486,7 +484,7 @@ class SipHelper {
try {
Response response = mMessageFactory.createResponse(
Response.REQUEST_TERMINATED, inviteRequest);
- if (DEBUG) Log.d(TAG, "send response: " + response);
+ if (DBG) log("send response: " + response);
inviteTransaction.sendResponse(response);
} catch (ParseException e) {
throw new SipException("sendInviteRequestTerminated()", e);
@@ -532,4 +530,8 @@ class SipHelper {
private static String getCallId(Dialog dialog) {
return dialog.getCallId().getCallId();
}
+
+ private void log(String s) {
+ Rlog.d(TAG, s);
+ }
}
diff --git a/java/com/android/server/sip/SipService.java b/java/com/android/server/sip/SipService.java
index a477fd1..80fe68c 100644
--- a/java/com/android/server/sip/SipService.java
+++ b/java/com/android/server/sip/SipService.java
@@ -16,7 +16,6 @@
package com.android.server.sip;
-import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -44,22 +43,15 @@ import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
-import android.text.TextUtils;
-import android.util.Log;
+import android.telephony.Rlog;
import java.io.IOException;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Comparator;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.TreeSet;
import java.util.concurrent.Executor;
import javax.sip.SipException;
@@ -68,7 +60,7 @@ import javax.sip.SipException;
*/
public final class SipService extends ISipService.Stub {
static final String TAG = "SipService";
- static final boolean DEBUG = false;
+ static final boolean DBG = true;
private static final int EXPIRY_TIME = 3600;
private static final int SHORT_EXPIRY_TIME = 10;
private static final int MIN_EXPIRY_TIME = 60;
@@ -82,7 +74,7 @@ public final class SipService extends ISipService.Stub {
private WifiManager.WifiLock mWifiLock;
private boolean mSipOnWifiOnly;
- private IntervalMeasurementProcess mIntervalMeasurementProcess;
+ private SipKeepAliveProcessCallback mSipKeepAliveProcessCallback;
private MyExecutor mExecutor = new MyExecutor();
@@ -107,12 +99,12 @@ public final class SipService extends ISipService.Stub {
if (SipManager.isApiSupported(context)) {
ServiceManager.addService("sip", new SipService(context));
context.sendBroadcast(new Intent(SipManager.ACTION_SIP_SERVICE_UP));
- if (DEBUG) Log.d(TAG, "SIP service started");
+ if (DBG) slog("start:");
}
}
private SipService(Context context) {
- if (DEBUG) Log.d(TAG, " service started!");
+ if (DBG) log("SipService: started!");
mContext = context;
mConnectivityReceiver = new ConnectivityReceiver();
@@ -128,6 +120,7 @@ public final class SipService extends ISipService.Stub {
mTimer = new SipWakeupTimer(context, mExecutor);
}
+ @Override
public synchronized SipProfile[] getListOfProfiles() {
mContext.enforceCallingOrSelfPermission(
android.Manifest.permission.USE_SIP, null);
@@ -141,6 +134,7 @@ public final class SipService extends ISipService.Stub {
return profiles.toArray(new SipProfile[profiles.size()]);
}
+ @Override
public synchronized void open(SipProfile localProfile) {
mContext.enforceCallingOrSelfPermission(
android.Manifest.permission.USE_SIP, null);
@@ -148,11 +142,12 @@ public final class SipService extends ISipService.Stub {
try {
createGroup(localProfile);
} catch (SipException e) {
- Log.e(TAG, "openToMakeCalls()", e);
+ loge("openToMakeCalls()", e);
// TODO: how to send the exception back
}
}
+ @Override
public synchronized void open3(SipProfile localProfile,
PendingIntent incomingCallPendingIntent,
ISipSessionListener listener) {
@@ -160,11 +155,11 @@ public final class SipService extends ISipService.Stub {
android.Manifest.permission.USE_SIP, null);
localProfile.setCallingUid(Binder.getCallingUid());
if (incomingCallPendingIntent == null) {
- Log.w(TAG, "incomingCallPendingIntent cannot be null; "
+ if (DBG) log("open3: incomingCallPendingIntent cannot be null; "
+ "the profile is not opened");
return;
}
- if (DEBUG) Log.d(TAG, "open3: " + localProfile.getUriString() + ": "
+ if (DBG) log("open3: " + localProfile.getUriString() + ": "
+ incomingCallPendingIntent + ": " + listener);
try {
SipSessionGroupExt group = createGroup(localProfile,
@@ -174,7 +169,7 @@ public final class SipService extends ISipService.Stub {
updateWakeLocks();
}
} catch (SipException e) {
- Log.e(TAG, "openToReceiveCalls()", e);
+ loge("open3:", e);
// TODO: how to send the exception back
}
}
@@ -192,13 +187,14 @@ public final class SipService extends ISipService.Stub {
return (Binder.getCallingUid() == Process.PHONE_UID);
}
+ @Override
public synchronized void close(String localProfileUri) {
mContext.enforceCallingOrSelfPermission(
android.Manifest.permission.USE_SIP, null);
SipSessionGroupExt group = mSipGroups.get(localProfileUri);
if (group == null) return;
if (!isCallerCreatorOrRadio(group)) {
- Log.w(TAG, "only creator or radio can close this profile");
+ if (DBG) log("only creator or radio can close this profile");
return;
}
@@ -209,6 +205,7 @@ public final class SipService extends ISipService.Stub {
updateWakeLocks();
}
+ @Override
public synchronized boolean isOpened(String localProfileUri) {
mContext.enforceCallingOrSelfPermission(
android.Manifest.permission.USE_SIP, null);
@@ -217,11 +214,12 @@ public final class SipService extends ISipService.Stub {
if (isCallerCreatorOrRadio(group)) {
return true;
} else {
- Log.w(TAG, "only creator or radio can query on the profile");
+ if (DBG) log("only creator or radio can query on the profile");
return false;
}
}
+ @Override
public synchronized boolean isRegistered(String localProfileUri) {
mContext.enforceCallingOrSelfPermission(
android.Manifest.permission.USE_SIP, null);
@@ -230,11 +228,12 @@ public final class SipService extends ISipService.Stub {
if (isCallerCreatorOrRadio(group)) {
return group.isRegistered();
} else {
- Log.w(TAG, "only creator or radio can query on the profile");
+ if (DBG) log("only creator or radio can query on the profile");
return false;
}
}
+ @Override
public synchronized void setRegistrationListener(String localProfileUri,
ISipSessionListener listener) {
mContext.enforceCallingOrSelfPermission(
@@ -244,25 +243,31 @@ public final class SipService extends ISipService.Stub {
if (isCallerCreator(group)) {
group.setListener(listener);
} else {
- Log.w(TAG, "only creator can set listener on the profile");
+ if (DBG) log("only creator can set listener on the profile");
}
}
+ @Override
public synchronized ISipSession createSession(SipProfile localProfile,
ISipSessionListener listener) {
+ if (DBG) log("createSession: profile" + localProfile);
mContext.enforceCallingOrSelfPermission(
android.Manifest.permission.USE_SIP, null);
localProfile.setCallingUid(Binder.getCallingUid());
- if (mNetworkType == -1) return null;
+ if (mNetworkType == -1) {
+ if (DBG) log("createSession: mNetworkType==-1 ret=null");
+ return null;
+ }
try {
SipSessionGroupExt group = createGroup(localProfile);
return group.createSession(listener);
} catch (SipException e) {
- if (DEBUG) Log.d(TAG, "createSession()", e);
+ if (DBG) loge("createSession;", e);
return null;
}
}
+ @Override
public synchronized ISipSession getPendingSession(String callId) {
mContext.enforceCallingOrSelfPermission(
android.Manifest.permission.USE_SIP, null);
@@ -276,7 +281,7 @@ public final class SipService extends ISipService.Stub {
s.connect(InetAddress.getByName("192.168.1.1"), 80);
return s.getLocalAddress().getHostAddress();
} catch (IOException e) {
- if (DEBUG) Log.d(TAG, "determineLocalIp()", e);
+ if (DBG) loge("determineLocalIp()", e);
// dont do anything; there should be a connectivity change going
return null;
}
@@ -317,7 +322,7 @@ public final class SipService extends ISipService.Stub {
}
private void notifyProfileAdded(SipProfile localProfile) {
- if (DEBUG) Log.d(TAG, "notify: profile added: " + localProfile);
+ if (DBG) log("notify: profile added: " + localProfile);
Intent intent = new Intent(SipManager.ACTION_SIP_ADD_PHONE);
intent.putExtra(SipManager.EXTRA_LOCAL_URI, localProfile.getUriString());
mContext.sendBroadcast(intent);
@@ -327,7 +332,7 @@ public final class SipService extends ISipService.Stub {
}
private void notifyProfileRemoved(SipProfile localProfile) {
- if (DEBUG) Log.d(TAG, "notify: profile removed: " + localProfile);
+ if (DBG) log("notify: profile removed: " + localProfile);
Intent intent = new Intent(SipManager.ACTION_SIP_REMOVE_PHONE);
intent.putExtra(SipManager.EXTRA_LOCAL_URI, localProfile.getUriString());
mContext.sendBroadcast(intent);
@@ -337,9 +342,9 @@ public final class SipService extends ISipService.Stub {
}
private void stopPortMappingMeasurement() {
- if (mIntervalMeasurementProcess != null) {
- mIntervalMeasurementProcess.stop();
- mIntervalMeasurementProcess = null;
+ if (mSipKeepAliveProcessCallback != null) {
+ mSipKeepAliveProcessCallback.stop();
+ mSipKeepAliveProcessCallback = null;
}
}
@@ -351,10 +356,10 @@ public final class SipService extends ISipService.Stub {
private void startPortMappingLifetimeMeasurement(
SipProfile localProfile, int maxInterval) {
- if ((mIntervalMeasurementProcess == null)
+ if ((mSipKeepAliveProcessCallback == null)
&& (mKeepAliveInterval == -1)
&& isBehindNAT(mLocalIp)) {
- Log.d(TAG, "start NAT port mapping timeout measurement on "
+ if (DBG) log("startPortMappingLifetimeMeasurement: profile="
+ localProfile.getUriString());
int minInterval = mLastGoodKeepAliveInterval;
@@ -363,11 +368,11 @@ public final class SipService extends ISipService.Stub {
// to the default min
minInterval = mLastGoodKeepAliveInterval
= DEFAULT_KEEPALIVE_INTERVAL;
- Log.d(TAG, " reset min interval to " + minInterval);
+ log(" reset min interval to " + minInterval);
}
- mIntervalMeasurementProcess = new IntervalMeasurementProcess(
+ mSipKeepAliveProcessCallback = new SipKeepAliveProcessCallback(
localProfile, minInterval, maxInterval);
- mIntervalMeasurementProcess.start();
+ mSipKeepAliveProcessCallback.start();
}
}
@@ -382,10 +387,10 @@ public final class SipService extends ISipService.Stub {
try {
cleanUpPendingSessions();
mPendingSessions.put(session.getCallId(), session);
- if (DEBUG) Log.d(TAG, "#pending sess=" + mPendingSessions.size());
+ if (DBG) log("#pending sess=" + mPendingSessions.size());
} catch (RemoteException e) {
// should not happen with a local call
- Log.e(TAG, "addPendingSession()", e);
+ loge("addPendingSession()", e);
}
}
@@ -405,7 +410,7 @@ public final class SipService extends ISipService.Stub {
String callId = ringingSession.getCallId();
for (SipSessionGroupExt group : mSipGroups.values()) {
if ((group != ringingGroup) && group.containsSession(callId)) {
- if (DEBUG) Log.d(TAG, "call self: "
+ if (DBG) log("call self: "
+ ringingSession.getLocalProfile().getUriString()
+ " -> " + group.getLocalProfile().getUriString());
return true;
@@ -428,31 +433,36 @@ public final class SipService extends ISipService.Stub {
private boolean isBehindNAT(String address) {
try {
+ // TODO: How is isBehindNAT used and why these constanst address:
+ // 10.x.x.x | 192.168.x.x | 172.16.x.x .. 172.19.x.x
byte[] d = InetAddress.getByName(address).getAddress();
if ((d[0] == 10) ||
- (((0x000000FF & ((int)d[0])) == 172) &&
- ((0x000000F0 & ((int)d[1])) == 16)) ||
- (((0x000000FF & ((int)d[0])) == 192) &&
- ((0x000000FF & ((int)d[1])) == 168))) {
+ (((0x000000FF & d[0]) == 172) &&
+ ((0x000000F0 & d[1]) == 16)) ||
+ (((0x000000FF & d[0]) == 192) &&
+ ((0x000000FF & d[1]) == 168))) {
return true;
}
} catch (UnknownHostException e) {
- Log.e(TAG, "isBehindAT()" + address, e);
+ loge("isBehindAT()" + address, e);
}
return false;
}
private class SipSessionGroupExt extends SipSessionAdapter {
+ private static final String SSGE_TAG = "SipSessionGroupExt";
+ private static final boolean SSGE_DBG = true;
private SipSessionGroup mSipGroup;
private PendingIntent mIncomingCallPendingIntent;
private boolean mOpenedToReceiveCalls;
- private AutoRegistrationProcess mAutoRegistration =
- new AutoRegistrationProcess();
+ private SipAutoReg mAutoRegistration =
+ new SipAutoReg();
public SipSessionGroupExt(SipProfile localProfile,
PendingIntent incomingCallPendingIntent,
ISipSessionListener listener) throws SipException {
+ if (SSGE_DBG) log("SipSessionGroupExt: profile=" + localProfile);
mSipGroup = new SipSessionGroup(duplicate(localProfile),
localProfile.getPassword(), mTimer, mMyWakeLock);
mIncomingCallPendingIntent = incomingCallPendingIntent;
@@ -481,7 +491,7 @@ public final class SipService extends ISipService.Stub {
try {
return new SipProfile.Builder(p).setPassword("*").build();
} catch (Exception e) {
- Log.wtf(TAG, "duplicate()", e);
+ loge("duplicate()", e);
throw new RuntimeException("duplicate profile", e);
}
}
@@ -500,20 +510,21 @@ public final class SipService extends ISipService.Stub {
mSipGroup.openToReceiveCalls(this);
mAutoRegistration.start(mSipGroup);
}
- if (DEBUG) Log.d(TAG, " openToReceiveCalls: " + getUri() + ": "
+ if (SSGE_DBG) log("openToReceiveCalls: " + getUri() + ": "
+ mIncomingCallPendingIntent);
}
public void onConnectivityChanged(boolean connected)
throws SipException {
+ if (SSGE_DBG) {
+ log("onConnectivityChanged: connected=" + connected + " uri="
+ + getUri() + ": " + mIncomingCallPendingIntent);
+ }
mSipGroup.onConnectivityChanged();
if (connected) {
mSipGroup.reset();
if (mOpenedToReceiveCalls) openToReceiveCalls();
} else {
- // close mSipGroup but remember mOpenedToReceiveCalls
- if (DEBUG) Log.d(TAG, " close auto reg temporarily: "
- + getUri() + ": " + mIncomingCallPendingIntent);
mSipGroup.close();
mAutoRegistration.stop();
}
@@ -523,23 +534,23 @@ public final class SipService extends ISipService.Stub {
mOpenedToReceiveCalls = false;
mSipGroup.close();
mAutoRegistration.stop();
- if (DEBUG) Log.d(TAG, " close: " + getUri() + ": "
- + mIncomingCallPendingIntent);
+ if (SSGE_DBG) log("close: " + getUri() + ": " + mIncomingCallPendingIntent);
}
public ISipSession createSession(ISipSessionListener listener) {
+ if (SSGE_DBG) log("createSession");
return mSipGroup.createSession(listener);
}
@Override
public void onRinging(ISipSession s, SipProfile caller,
String sessionDescription) {
- if (DEBUG) Log.d(TAG, "<<<<< onRinging()");
SipSessionGroup.SipSessionImpl session =
(SipSessionGroup.SipSessionImpl) s;
synchronized (SipService.this) {
try {
if (!isRegistered() || callingSelf(this, session)) {
+ if (SSGE_DBG) log("onRinging: end notReg or self");
session.endCall();
return;
}
@@ -548,13 +559,13 @@ public final class SipService extends ISipService.Stub {
addPendingSession(session);
Intent intent = SipManager.createIncomingCallBroadcast(
session.getCallId(), sessionDescription);
- if (DEBUG) Log.d(TAG, " ringing~~ " + getUri() + ": "
+ if (SSGE_DBG) log("onRinging: uri=" + getUri() + ": "
+ caller.getUri() + ": " + session.getCallId()
+ " " + mIncomingCallPendingIntent);
mIncomingCallPendingIntent.send(mContext,
SipManager.INCOMING_CALL_RESULT_CODE, intent);
} catch (PendingIntent.CanceledException e) {
- Log.w(TAG, "pendingIntent is canceled, drop incoming call");
+ loge("onRinging: pendingIntent is canceled, drop incoming call", e);
session.endCall();
}
}
@@ -563,7 +574,7 @@ public final class SipService extends ISipService.Stub {
@Override
public void onError(ISipSession session, int errorCode,
String message) {
- if (DEBUG) Log.d(TAG, "sip session error: "
+ if (SSGE_DBG) log("onError: errorCode=" + errorCode + " desc="
+ SipErrorCode.toString(errorCode) + ": " + message);
}
@@ -578,14 +589,23 @@ public final class SipService extends ISipService.Stub {
private String getUri() {
return mSipGroup.getLocalProfileUri();
}
+
+ private void log(String s) {
+ Rlog.d(SSGE_TAG, s);
+ }
+
+ private void loge(String s, Throwable t) {
+ Rlog.e(SSGE_TAG, s, t);
+ }
+
}
- private class IntervalMeasurementProcess implements Runnable,
+ private class SipKeepAliveProcessCallback implements Runnable,
SipSessionGroup.KeepAliveProcessCallback {
- private static final String TAG = "SipKeepAliveInterval";
+ private static final String SKAI_TAG = "SipKeepAliveProcessCallback";
+ private static final boolean SKAI_DBG = true;
private static final int MIN_INTERVAL = 5; // in seconds
private static final int PASS_THRESHOLD = 10;
- private static final int MAX_RETRY_COUNT = 5;
private static final int NAT_MEASUREMENT_RETRY_INTERVAL = 120; // in seconds
private SipProfile mLocalProfile;
private SipSessionGroupExt mGroup;
@@ -595,7 +615,7 @@ public final class SipService extends ISipService.Stub {
private int mInterval;
private int mPassCount;
- public IntervalMeasurementProcess(SipProfile localProfile,
+ public SipKeepAliveProcessCallback(SipProfile localProfile,
int minInterval, int maxInterval) {
mMaxInterval = maxInterval;
mMinInterval = minInterval;
@@ -613,13 +633,13 @@ public final class SipService extends ISipService.Stub {
// Don't start measurement if the interval is too small
if (mInterval < DEFAULT_KEEPALIVE_INTERVAL || checkTermination()) {
- Log.w(TAG, "measurement aborted; interval=[" +
+ if (SKAI_DBG) log("start: measurement aborted; interval=[" +
mMinInterval + "," + mMaxInterval + "]");
return;
}
try {
- Log.d(TAG, "start measurement w interval=" + mInterval);
+ if (SKAI_DBG) log("start: interval=" + mInterval);
mGroup = new SipSessionGroupExt(mLocalProfile, null, null);
// TODO: remove this line once SipWakeupTimer can better handle
@@ -646,6 +666,7 @@ public final class SipService extends ISipService.Stub {
mGroup = null;
}
mTimer.cancel(this);
+ if (SKAI_DBG) log("stop");
}
}
@@ -654,13 +675,13 @@ public final class SipService extends ISipService.Stub {
// Return immediately if the measurement process is stopped
if (mSession == null) return;
- Log.d(TAG, "restart measurement w interval=" + mInterval);
+ if (SKAI_DBG) log("restart: interval=" + mInterval);
try {
mSession.stopKeepAliveProcess();
mPassCount = 0;
mSession.startKeepAliveProcess(mInterval, this);
} catch (SipException e) {
- Log.e(TAG, "restart()", e);
+ loge("restart", e);
}
}
}
@@ -681,8 +702,8 @@ public final class SipService extends ISipService.Stub {
mLastGoodKeepAliveInterval = mKeepAliveInterval;
}
mKeepAliveInterval = mMinInterval = mInterval;
- if (DEBUG) {
- Log.d(TAG, "measured good keepalive interval: "
+ if (SKAI_DBG) {
+ log("onResponse: portChanged=" + portChanged + " mKeepAliveInterval="
+ mKeepAliveInterval);
}
onKeepAliveIntervalChanged();
@@ -698,16 +719,16 @@ public final class SipService extends ISipService.Stub {
// measurement with min interval=DEFAULT_KEEPALIVE_INTERVAL
// will be conducted.
mKeepAliveInterval = mMinInterval;
- if (DEBUG) {
- Log.d(TAG, "measured keepalive interval: "
+ if (SKAI_DBG) {
+ log("onResponse: checkTermination mKeepAliveInterval="
+ mKeepAliveInterval);
}
} else {
// calculate the new interval and continue.
mInterval = (mMaxInterval + mMinInterval) / 2;
- if (DEBUG) {
- Log.d(TAG, "current interval: " + mKeepAliveInterval
- + ", test new interval: " + mInterval);
+ if (SKAI_DBG) {
+ log("onResponse: mKeepAliveInterval=" + mKeepAliveInterval
+ + ", new mInterval=" + mInterval);
}
restart();
}
@@ -717,7 +738,7 @@ public final class SipService extends ISipService.Stub {
// SipSessionGroup.KeepAliveProcessCallback
@Override
public void onError(int errorCode, String description) {
- Log.w(TAG, "interval measurement error: " + description);
+ if (SKAI_DBG) loge("onError: errorCode=" + errorCode + " desc=" + description);
restartLater();
}
@@ -735,12 +756,25 @@ public final class SipService extends ISipService.Stub {
mTimer.set(interval * 1000, this);
}
}
+
+ private void log(String s) {
+ Rlog.d(SKAI_TAG, s);
+ }
+
+ private void loge(String s) {
+ Rlog.d(SKAI_TAG, s);
+ }
+
+ private void loge(String s, Throwable t) {
+ Rlog.d(SKAI_TAG, s, t);
+ }
}
- private class AutoRegistrationProcess extends SipSessionAdapter
+ private class SipAutoReg extends SipSessionAdapter
implements Runnable, SipSessionGroup.KeepAliveProcessCallback {
+ private String SAR_TAG;
+ private static final boolean SAR_DBG = true;
private static final int MIN_KEEPALIVE_SUCCESS_COUNT = 10;
- private String TAG = "SipAutoReg";
private SipSessionGroup.SipSessionImpl mSession;
private SipSessionGroup.SipSessionImpl mKeepAliveSession;
@@ -754,10 +788,6 @@ public final class SipService extends ISipService.Stub {
private int mKeepAliveSuccessCount = 0;
- private String getAction() {
- return toString();
- }
-
public void start(SipSessionGroup group) {
if (!mRunning) {
mRunning = true;
@@ -772,12 +802,13 @@ public final class SipService extends ISipService.Stub {
// in registration to avoid adding duplicate entries to server
mMyWakeLock.acquire(mSession);
mSession.unregister();
- TAG = "SipAutoReg:" + mSession.getLocalProfile().getUriString();
+ SAR_TAG = "SipAutoReg:" + mSession.getLocalProfile().getUriString();
+ if (SAR_DBG) log("start: group=" + group);
}
}
private void startKeepAliveProcess(int interval) {
- if (DEBUG) Log.d(TAG, "start keepalive w interval=" + interval);
+ if (SAR_DBG) log("startKeepAliveProcess: interval=" + interval);
if (mKeepAliveSession == null) {
mKeepAliveSession = mSession.duplicate();
} else {
@@ -786,8 +817,7 @@ public final class SipService extends ISipService.Stub {
try {
mKeepAliveSession.startKeepAliveProcess(interval, this);
} catch (SipException e) {
- Log.e(TAG, "failed to start keepalive w interval=" + interval,
- e);
+ loge("startKeepAliveProcess: interval=" + interval, e);
}
}
@@ -806,17 +836,19 @@ public final class SipService extends ISipService.Stub {
if (portChanged) {
int interval = getKeepAliveInterval();
if (mKeepAliveSuccessCount < MIN_KEEPALIVE_SUCCESS_COUNT) {
- Log.i(TAG, "keepalive doesn't work with interval "
- + interval + ", past success count="
- + mKeepAliveSuccessCount);
+ if (SAR_DBG) {
+ log("onResponse: keepalive doesn't work with interval "
+ + interval + ", past success count="
+ + mKeepAliveSuccessCount);
+ }
if (interval > DEFAULT_KEEPALIVE_INTERVAL) {
restartPortMappingLifetimeMeasurement(
mSession.getLocalProfile(), interval);
mKeepAliveSuccessCount = 0;
}
} else {
- if (DEBUG) {
- Log.i(TAG, "keep keepalive going with interval "
+ if (SAR_DBG) {
+ log("keep keepalive going with interval "
+ interval + ", past success count="
+ mKeepAliveSuccessCount);
}
@@ -847,8 +879,8 @@ public final class SipService extends ISipService.Stub {
// SipSessionGroup.KeepAliveProcessCallback
@Override
public void onError(int errorCode, String description) {
- if (DEBUG) {
- Log.e(TAG, "keepalive error: " + description);
+ if (SAR_DBG) {
+ loge("onError: errorCode=" + errorCode + " desc=" + description);
}
onResponse(true); // re-register immediately
}
@@ -872,8 +904,8 @@ public final class SipService extends ISipService.Stub {
public void onKeepAliveIntervalChanged() {
if (mKeepAliveSession != null) {
int newInterval = getKeepAliveInterval();
- if (DEBUG) {
- Log.v(TAG, "restart keepalive w interval=" + newInterval);
+ if (SAR_DBG) {
+ log("onKeepAliveIntervalChanged: interval=" + newInterval);
}
mKeepAliveSuccessCount = 0;
startKeepAliveProcess(newInterval);
@@ -916,7 +948,7 @@ public final class SipService extends ISipService.Stub {
String.valueOf(state));
}
} catch (Throwable t) {
- Log.w(TAG, "setListener(): " + t);
+ loge("setListener: ", t);
}
}
}
@@ -933,7 +965,7 @@ public final class SipService extends ISipService.Stub {
mErrorCode = SipErrorCode.NO_ERROR;
mErrorMessage = null;
- if (DEBUG) Log.d(TAG, "registering");
+ if (SAR_DBG) log("run: registering");
if (mNetworkType != -1) {
mMyWakeLock.acquire(mSession);
mSession.register(EXPIRY_TIME);
@@ -942,7 +974,7 @@ public final class SipService extends ISipService.Stub {
}
private void restart(int duration) {
- Log.d(TAG, "Refresh registration " + duration + "s later.");
+ if (SAR_DBG) log("restart: duration=" + duration + "s later.");
mTimer.cancel(this);
mTimer.set(duration * 1000, this);
}
@@ -959,7 +991,7 @@ public final class SipService extends ISipService.Stub {
@Override
public void onRegistering(ISipSession session) {
- if (DEBUG) Log.d(TAG, "onRegistering(): " + session);
+ if (SAR_DBG) log("onRegistering: " + session);
synchronized (SipService.this) {
if (notCurrentSession(session)) return;
@@ -979,7 +1011,7 @@ public final class SipService extends ISipService.Stub {
@Override
public void onRegistrationDone(ISipSession session, int duration) {
- if (DEBUG) Log.d(TAG, "onRegistrationDone(): " + session);
+ if (SAR_DBG) log("onRegistrationDone: " + session);
synchronized (SipService.this) {
if (notCurrentSession(session)) return;
@@ -1008,7 +1040,7 @@ public final class SipService extends ISipService.Stub {
} else {
mRegistered = false;
mExpiryTime = -1L;
- if (DEBUG) Log.d(TAG, "Refresh registration immediately");
+ if (SAR_DBG) log("Refresh registration immediately");
run();
}
}
@@ -1017,7 +1049,7 @@ public final class SipService extends ISipService.Stub {
@Override
public void onRegistrationFailed(ISipSession session, int errorCode,
String message) {
- if (DEBUG) Log.d(TAG, "onRegistrationFailed(): " + session + ": "
+ if (SAR_DBG) log("onRegistrationFailed: " + session + ": "
+ SipErrorCode.toString(errorCode) + ": " + message);
synchronized (SipService.this) {
if (notCurrentSession(session)) return;
@@ -1025,7 +1057,7 @@ public final class SipService extends ISipService.Stub {
switch (errorCode) {
case SipErrorCode.INVALID_CREDENTIALS:
case SipErrorCode.SERVER_UNREACHABLE:
- if (DEBUG) Log.d(TAG, " pause auto-registration");
+ if (SAR_DBG) log(" pause auto-registration");
stop();
break;
default:
@@ -1041,7 +1073,7 @@ public final class SipService extends ISipService.Stub {
@Override
public void onRegistrationTimeout(ISipSession session) {
- if (DEBUG) Log.d(TAG, "onRegistrationTimeout(): " + session);
+ if (SAR_DBG) log("onRegistrationTimeout: " + session);
synchronized (SipService.this) {
if (notCurrentSession(session)) return;
@@ -1053,9 +1085,22 @@ public final class SipService extends ISipService.Stub {
}
private void restartLater() {
+ if (SAR_DBG) loge("restartLater");
mRegistered = false;
restart(backoffDuration());
}
+
+ private void log(String s) {
+ Rlog.d(SAR_TAG, s);
+ }
+
+ private void loge(String s) {
+ Rlog.e(SAR_TAG, s);
+ }
+
+ private void loge(String s, Throwable e) {
+ Rlog.e(SAR_TAG, s, e);
+ }
}
private class ConnectivityReceiver extends BroadcastReceiver {
@@ -1068,6 +1113,7 @@ public final class SipService extends ISipService.Stub {
// Run the handler in MyExecutor to be protected by wake lock
mExecutor.execute(new Runnable() {
+ @Override
public void run() {
onConnectivityChanged(info);
}
@@ -1079,12 +1125,12 @@ public final class SipService extends ISipService.Stub {
private void registerReceivers() {
mContext.registerReceiver(mConnectivityReceiver,
new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
- if (DEBUG) Log.d(TAG, " +++ register receivers");
+ if (DBG) log("registerReceivers:");
}
private void unregisterReceivers() {
mContext.unregisterReceiver(mConnectivityReceiver);
- if (DEBUG) Log.d(TAG, " --- unregister receivers");
+ if (DBG) log("unregisterReceivers:");
// Reset variables maintained by ConnectivityReceiver.
mWifiLock.release();
@@ -1131,10 +1177,11 @@ public final class SipService extends ISipService.Stub {
// Ignore the event if the current active network is not changed.
if (mNetworkType == networkType) {
+ // TODO: Maybe we need to send seq/generation number
return;
}
- if (DEBUG) {
- Log.d(TAG, "onConnectivityChanged(): " + mNetworkType +
+ if (DBG) {
+ log("onConnectivityChanged: " + mNetworkType +
" -> " + networkType);
}
@@ -1158,7 +1205,7 @@ public final class SipService extends ISipService.Stub {
}
updateWakeLocks();
} catch (SipException e) {
- Log.e(TAG, "onConnectivityChanged()", e);
+ loge("onConnectivityChanged()", e);
}
}
@@ -1186,7 +1233,7 @@ public final class SipService extends ISipService.Stub {
if (msg.obj instanceof Runnable) {
executeInternal((Runnable) msg.obj);
} else {
- Log.w(TAG, "can't handle msg: " + msg);
+ if (DBG) log("handleMessage: not Runnable ignore msg=" + msg);
}
}
@@ -1194,10 +1241,22 @@ public final class SipService extends ISipService.Stub {
try {
task.run();
} catch (Throwable t) {
- Log.e(TAG, "run task: " + task, t);
+ loge("run task: " + task, t);
} finally {
mMyWakeLock.release(task);
}
}
}
+
+ private void log(String s) {
+ Rlog.d(TAG, s);
+ }
+
+ private static void slog(String s) {
+ Rlog.d(TAG, s);
+ }
+
+ private void loge(String s, Throwable e) {
+ Rlog.e(TAG, s, e);
+ }
}
diff --git a/java/com/android/server/sip/SipSessionGroup.java b/java/com/android/server/sip/SipSessionGroup.java
index 6acd456..e820f35 100644
--- a/java/com/android/server/sip/SipSessionGroup.java
+++ b/java/com/android/server/sip/SipSessionGroup.java
@@ -35,7 +35,7 @@ import android.net.sip.SipProfile;
import android.net.sip.SipSession;
import android.net.sip.SipSessionAdapter;
import android.text.TextUtils;
-import android.util.Log;
+import android.telephony.Rlog;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
@@ -43,7 +43,6 @@ import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.ParseException;
-import java.util.Collection;
import java.util.EventObject;
import java.util.HashMap;
import java.util.Map;
@@ -53,7 +52,6 @@ import javax.sip.ClientTransaction;
import javax.sip.Dialog;
import javax.sip.DialogTerminatedEvent;
import javax.sip.IOExceptionEvent;
-import javax.sip.ListeningPoint;
import javax.sip.ObjectInUseException;
import javax.sip.RequestEvent;
import javax.sip.ResponseEvent;
@@ -65,9 +63,7 @@ import javax.sip.SipProvider;
import javax.sip.SipStack;
import javax.sip.TimeoutEvent;
import javax.sip.Transaction;
-import javax.sip.TransactionState;
import javax.sip.TransactionTerminatedEvent;
-import javax.sip.TransactionUnavailableException;
import javax.sip.address.Address;
import javax.sip.address.SipURI;
import javax.sip.header.CSeqHeader;
@@ -88,8 +84,8 @@ import javax.sip.message.Response;
*/
class SipSessionGroup implements SipListener {
private static final String TAG = "SipSession";
- private static final boolean DEBUG = false;
- private static final boolean DEBUG_PING = false;
+ private static final boolean DBG = false;
+ private static final boolean DBG_PING = false;
private static final String ANONYMOUS = "anonymous";
// Limit the size of thread pool to 1 for the order issue when the phone is
// waken up from sleep and there are many packets to be processed in the SIP
@@ -105,9 +101,6 @@ class SipSessionGroup implements SipListener {
private static final EventObject DEREGISTER = new EventObject("Deregister");
private static final EventObject END_CALL = new EventObject("End call");
- private static final EventObject HOLD_CALL = new EventObject("Hold call");
- private static final EventObject CONTINUE_CALL
- = new EventObject("Continue call");
private final SipProfile mLocalProfile;
private final String mPassword;
@@ -133,7 +126,7 @@ class SipSessionGroup implements SipListener {
/**
* @param profile the local profile with password crossed out
* @param password the password of the profile
- * @throws IOException if cannot assign requested address
+ * @throws SipException if cannot assign requested address
*/
public SipSessionGroup(SipProfile profile, String password,
SipWakeupTimer timer, SipWakeLock wakeLock) throws SipException {
@@ -206,7 +199,7 @@ class SipSessionGroup implements SipListener {
throw new SipException("failed to initialize SIP stack", e);
}
- Log.d(TAG, " start stack for " + mLocalProfile.getUriString());
+ if (DBG) log("reset: start stack for " + mLocalProfile.getUriString());
mSipStack.start();
}
@@ -224,8 +217,8 @@ class SipSessionGroup implements SipListener {
}
synchronized void resetExternalAddress() {
- if (DEBUG) {
- Log.d(TAG, " reset external addr on " + mSipStack);
+ if (DBG) {
+ log("resetExternalAddress: " + mSipStack);
}
mExternalIp = null;
mExternalPort = 0;
@@ -244,7 +237,7 @@ class SipSessionGroup implements SipListener {
}
public synchronized void close() {
- Log.d(TAG, " close stack for " + mLocalProfile.getUriString());
+ if (DBG) log("close: " + mLocalProfile.getUriString());
onConnectivityChanged();
mSessionMap.clear();
closeToNotReceiveCalls();
@@ -285,10 +278,10 @@ class SipSessionGroup implements SipListener {
String key = SipHelper.getCallId(event);
SipSessionImpl session = mSessionMap.get(key);
if ((session != null) && isLoggable(session)) {
- Log.d(TAG, "session key from event: " + key);
- Log.d(TAG, "active sessions:");
+ if (DBG) log("getSipSession: event=" + key);
+ if (DBG) log("getSipSession: active sessions:");
for (String k : mSessionMap.keySet()) {
- Log.d(TAG, " ..." + k + ": " + mSessionMap.get(k));
+ if (DBG) log("getSipSession: ..." + k + ": " + mSessionMap.get(k));
}
}
return ((session != null) ? session : mCallReceiverSession);
@@ -299,9 +292,9 @@ class SipSessionGroup implements SipListener {
String key = newSession.getCallId();
mSessionMap.put(key, newSession);
if (isLoggable(newSession)) {
- Log.d(TAG, "+++ add a session with key: '" + key + "'");
+ if (DBG) log("addSipSession: key='" + key + "'");
for (String k : mSessionMap.keySet()) {
- Log.d(TAG, " " + k + ": " + mSessionMap.get(k));
+ if (DBG) log("addSipSession: " + k + ": " + mSessionMap.get(k));
}
}
}
@@ -312,7 +305,7 @@ class SipSessionGroup implements SipListener {
SipSessionImpl s = mSessionMap.remove(key);
// sanity check
if ((s != null) && (s != session)) {
- Log.w(TAG, "session " + session + " is not associated with key '"
+ if (DBG) log("removeSession: " + session + " is not associated with key '"
+ key + "'");
mSessionMap.put(key, s);
for (Map.Entry<String, SipSessionImpl> entry
@@ -325,16 +318,17 @@ class SipSessionGroup implements SipListener {
}
if ((s != null) && isLoggable(s)) {
- Log.d(TAG, "remove session " + session + " @key '" + key + "'");
+ if (DBG) log("removeSession: " + session + " @key '" + key + "'");
for (String k : mSessionMap.keySet()) {
- Log.d(TAG, " " + k + ": " + mSessionMap.get(k));
+ if (DBG) log("removeSession: " + k + ": " + mSessionMap.get(k));
}
}
}
+ @Override
public void processRequest(final RequestEvent event) {
if (isRequestEvent(Request.INVITE, event)) {
- if (DEBUG) Log.d(TAG, "<<<<< got INVITE, thread:"
+ if (DBG) log("processRequest: mWakeLock.acquire got INVITE, thread:"
+ Thread.currentThread());
// Acquire a wake lock and keep it for WAKE_LOCK_HOLDING_TIME;
// should be large enough to bring up the app.
@@ -343,22 +337,27 @@ class SipSessionGroup implements SipListener {
process(event);
}
+ @Override
public void processResponse(ResponseEvent event) {
process(event);
}
+ @Override
public void processIOException(IOExceptionEvent event) {
process(event);
}
+ @Override
public void processTimeout(TimeoutEvent event) {
process(event);
}
+ @Override
public void processTransactionTerminated(TransactionTerminatedEvent event) {
process(event);
}
+ @Override
public void processDialogTerminated(DialogTerminatedEvent event) {
process(event);
}
@@ -369,11 +368,11 @@ class SipSessionGroup implements SipListener {
boolean isLoggable = isLoggable(session, event);
boolean processed = (session != null) && session.process(event);
if (isLoggable && processed) {
- Log.d(TAG, "new state after: "
+ log("process: event new state after: "
+ SipSession.State.toString(session.mState));
}
} catch (Throwable e) {
- Log.w(TAG, "event process error: " + event, getRootCause(e));
+ loge("process: error event=" + event, getRootCause(e));
session.onError(e);
}
}
@@ -404,8 +403,8 @@ class SipSessionGroup implements SipListener {
if ((rport > 0) && (externalIp != null)) {
mExternalIp = externalIp;
mExternalPort = rport;
- if (DEBUG) {
- Log.d(TAG, " got external addr " + externalIp + ":" + rport
+ if (DBG) {
+ log("extractExternalAddress: external addr " + externalIp + ":" + rport
+ " on " + mSipStack);
}
}
@@ -436,6 +435,9 @@ class SipSessionGroup implements SipListener {
}
private class SipSessionCallReceiverImpl extends SipSessionImpl {
+ private static final String SSCRI_TAG = "SipSessionCallReceiverImpl";
+ private static final boolean SSCRI_DBG = true;
+
public SipSessionCallReceiverImpl(ISipSessionListener listener) {
super(listener);
}
@@ -473,8 +475,8 @@ class SipSessionGroup implements SipListener {
SipSessionImpl newSession = null;
if (replaces != null) {
int response = processInviteWithReplaces(event, replaces);
- if (DEBUG) {
- Log.v(TAG, "ReplacesHeader: " + replaces
+ if (SSCRI_DBG) {
+ log("processNewInviteRequest: " + replaces
+ " response=" + response);
}
if (response == Response.OK) {
@@ -501,10 +503,11 @@ class SipSessionGroup implements SipListener {
if (newSession != null) addSipSession(newSession);
}
+ @Override
public boolean process(EventObject evt) throws SipException {
- if (isLoggable(this, evt)) Log.d(TAG, " ~~~~~ " + this + ": "
+ if (isLoggable(this, evt)) log("process: " + this + ": "
+ SipSession.State.toString(mState) + ": processing "
- + log(evt));
+ + logEvt(evt));
if (isRequestEvent(Request.INVITE, evt)) {
processNewInviteRequest((RequestEvent) evt);
return true;
@@ -515,6 +518,10 @@ class SipSessionGroup implements SipListener {
return false;
}
}
+
+ private void log(String s) {
+ Rlog.d(SSCRI_TAG, s);
+ }
}
static interface KeepAliveProcessCallback {
@@ -524,6 +531,9 @@ class SipSessionGroup implements SipListener {
}
class SipSessionImpl extends ISipSession.Stub {
+ private static final String SSI_TAG = "SipSessionImpl";
+ private static final boolean SSI_DBG = true;
+
SipProfile mPeerProfile;
SipSessionListenerProxy mProxy = new SipSessionListenerProxy();
int mState = SipSession.State.READY_TO_CALL;
@@ -536,9 +546,9 @@ class SipSessionGroup implements SipListener {
SessionTimer mSessionTimer;
int mAuthenticationRetryCount;
- private KeepAliveProcess mKeepAliveProcess;
+ private SipKeepAlive mSipKeepAlive;
- private SipSessionImpl mKeepAliveSession;
+ private SipSessionImpl mSipSessionImpl;
// the following three members are used for handling refer request.
SipSessionImpl mReferSession;
@@ -551,6 +561,7 @@ class SipSessionGroup implements SipListener {
void start(final int timeout) {
new Thread(new Runnable() {
+ @Override
public void run() {
sleep(timeout);
if (mRunning) timeout();
@@ -573,7 +584,7 @@ class SipSessionGroup implements SipListener {
try {
this.wait(timeout * 1000);
} catch (InterruptedException e) {
- Log.e(TAG, "session timer interrupted!");
+ loge("session timer interrupted!", e);
}
}
}
@@ -617,28 +628,33 @@ class SipSessionGroup implements SipListener {
cancelSessionTimer();
- if (mKeepAliveSession != null) {
- mKeepAliveSession.stopKeepAliveProcess();
- mKeepAliveSession = null;
+ if (mSipSessionImpl != null) {
+ mSipSessionImpl.stopKeepAliveProcess();
+ mSipSessionImpl = null;
}
}
+ @Override
public boolean isInCall() {
return mInCall;
}
+ @Override
public String getLocalIp() {
return mLocalIp;
}
+ @Override
public SipProfile getLocalProfile() {
return mLocalProfile;
}
+ @Override
public SipProfile getPeerProfile() {
return mPeerProfile;
}
+ @Override
public String getCallId() {
return SipHelper.getCallId(getTransaction());
}
@@ -649,10 +665,12 @@ class SipSessionGroup implements SipListener {
return null;
}
+ @Override
public int getState() {
return mState;
}
+ @Override
public void setListener(ISipSessionListener listener) {
mProxy.setListener((listener instanceof SipSessionListenerProxy)
? ((SipSessionListenerProxy) listener).getListener()
@@ -662,11 +680,12 @@ class SipSessionGroup implements SipListener {
// process the command in a new thread
private void doCommandAsync(final EventObject command) {
new Thread(new Runnable() {
+ @Override
public void run() {
try {
processCommand(command);
} catch (Throwable e) {
- Log.w(TAG, "command error: " + command + ": "
+ loge("command error: " + command + ": "
+ mLocalProfile.getUriString(),
getRootCause(e));
onError(e);
@@ -675,12 +694,14 @@ class SipSessionGroup implements SipListener {
}, "SipSessionAsyncCmdThread").start();
}
+ @Override
public void makeCall(SipProfile peerProfile, String sessionDescription,
int timeout) {
doCommandAsync(new MakeCallCommand(peerProfile, sessionDescription,
timeout));
}
+ @Override
public void answerCall(String sessionDescription, int timeout) {
synchronized (SipSessionGroup.this) {
if (mPeerProfile == null) return;
@@ -689,10 +710,12 @@ class SipSessionGroup implements SipListener {
}
}
+ @Override
public void endCall() {
doCommandAsync(END_CALL);
}
+ @Override
public void changeCall(String sessionDescription, int timeout) {
synchronized (SipSessionGroup.this) {
if (mPeerProfile == null) return;
@@ -701,16 +724,18 @@ class SipSessionGroup implements SipListener {
}
}
+ @Override
public void register(int duration) {
doCommandAsync(new RegisterCommand(duration));
}
+ @Override
public void unregister() {
doCommandAsync(DEREGISTER);
}
private void processCommand(EventObject command) throws SipException {
- if (isLoggable(command)) Log.d(TAG, "process cmd: " + command);
+ if (isLoggable(command)) log("process cmd: " + command);
if (!process(command)) {
onError(SipErrorCode.IN_PROGRESS,
"cannot initiate a new transaction to execute: "
@@ -723,6 +748,7 @@ class SipSessionGroup implements SipListener {
return String.valueOf((long) (Math.random() * 0x100000000L));
}
+ @Override
public String toString() {
try {
String s = super.toString();
@@ -734,15 +760,15 @@ class SipSessionGroup implements SipListener {
}
public boolean process(EventObject evt) throws SipException {
- if (isLoggable(this, evt)) Log.d(TAG, " ~~~~~ " + this + ": "
+ if (isLoggable(this, evt)) log(" ~~~~~ " + this + ": "
+ SipSession.State.toString(mState) + ": processing "
- + log(evt));
+ + logEvt(evt));
synchronized (SipSessionGroup.this) {
if (isClosed()) return false;
- if (mKeepAliveProcess != null) {
+ if (mSipKeepAlive != null) {
// event consumed by keepalive process
- if (mKeepAliveProcess.process(evt)) return true;
+ if (mSipKeepAlive.process(evt)) return true;
}
Dialog dialog = null;
@@ -824,7 +850,7 @@ class SipSessionGroup implements SipListener {
if (mDialog == event.getDialog()) {
onError(new SipException("dialog terminated"));
} else {
- Log.d(TAG, "not the current dialog; current=" + mDialog
+ if (SSI_DBG) log("not the current dialog; current=" + mDialog
+ ", terminated=" + event.getDialog());
}
}
@@ -838,11 +864,11 @@ class SipSessionGroup implements SipListener {
: event.getClientTransaction();
if ((current != target) && (mState != SipSession.State.PINGING)) {
- Log.d(TAG, "not the current transaction; current="
+ if (SSI_DBG) log("not the current transaction; current="
+ toString(current) + ", target=" + toString(target));
return false;
} else if (current != null) {
- Log.d(TAG, "transaction terminated: " + toString(current));
+ if (SSI_DBG) log("transaction terminated: " + toString(current));
return true;
} else {
// no transaction; shouldn't be here; ignored
@@ -865,17 +891,17 @@ class SipSessionGroup implements SipListener {
switch (mState) {
case SipSession.State.IN_CALL:
case SipSession.State.READY_TO_CALL:
- Log.d(TAG, "Transaction terminated; do nothing");
+ if (SSI_DBG) log("Transaction terminated; do nothing");
break;
default:
- Log.d(TAG, "Transaction terminated early: " + this);
+ if (SSI_DBG) log("Transaction terminated early: " + this);
onError(SipErrorCode.TRANSACTION_TERMINTED,
"transaction terminated");
}
}
private void processTimeout(TimeoutEvent event) {
- Log.d(TAG, "processing Timeout...");
+ if (SSI_DBG) log("processing Timeout...");
switch (mState) {
case SipSession.State.REGISTERING:
case SipSession.State.DEREGISTERING:
@@ -890,7 +916,7 @@ class SipSessionGroup implements SipListener {
break;
default:
- Log.d(TAG, " do nothing");
+ if (SSI_DBG) log(" do nothing");
break;
}
}
@@ -912,8 +938,8 @@ class SipSessionGroup implements SipListener {
if (expires != null && time < expires.getExpires()) {
time = expires.getExpires();
}
- if (DEBUG) {
- Log.v(TAG, "Expiry time = " + time);
+ if (SSI_DBG) {
+ log("Expiry time = " + time);
}
return time;
}
@@ -960,7 +986,7 @@ class SipSessionGroup implements SipListener {
mDialog = mClientTransaction.getDialog();
mAuthenticationRetryCount++;
if (isLoggable(this, event)) {
- Log.d(TAG, " authentication retry count="
+ if (SSI_DBG) log(" authentication retry count="
+ mAuthenticationRetryCount);
}
return true;
@@ -984,19 +1010,23 @@ class SipSessionGroup implements SipListener {
private AccountManager getAccountManager() {
return new AccountManager() {
+ @Override
public UserCredentials getCredentials(ClientTransaction
challengedTransaction, String realm) {
return new UserCredentials() {
+ @Override
public String getUserName() {
String username = mLocalProfile.getAuthUserName();
return (!TextUtils.isEmpty(username) ? username :
mLocalProfile.getUserName());
}
+ @Override
public String getPassword() {
return mPassword;
}
+ @Override
public String getSipDomain() {
return mLocalProfile.getSipDomain();
}
@@ -1097,8 +1127,7 @@ class SipSessionGroup implements SipListener {
return false;
}
- private boolean incomingCallToInCall(EventObject evt)
- throws SipException {
+ private boolean incomingCallToInCall(EventObject evt) {
// expect ACK, CANCEL request
if (isRequestEvent(Request.ACK, evt)) {
String sdp = extractContent(((RequestEvent) evt).getRequest());
@@ -1154,8 +1183,7 @@ class SipSessionGroup implements SipListener {
}
return true;
case Response.REQUEST_PENDING:
- // TODO:
- // rfc3261#section-14.1; re-schedule invite
+ // TODO: rfc3261#section-14.1; re-schedule invite
return true;
default:
if (mReferSession != null) {
@@ -1342,17 +1370,17 @@ class SipSessionGroup implements SipListener {
}
private void enableKeepAlive() {
- if (mKeepAliveSession != null) {
- mKeepAliveSession.stopKeepAliveProcess();
+ if (mSipSessionImpl != null) {
+ mSipSessionImpl.stopKeepAliveProcess();
} else {
- mKeepAliveSession = duplicate();
+ mSipSessionImpl = duplicate();
}
try {
- mKeepAliveSession.startKeepAliveProcess(
+ mSipSessionImpl.startKeepAliveProcess(
INCALL_KEEPALIVE_INTERVAL, mPeerProfile, null);
} catch (SipException e) {
- Log.w(TAG, "keepalive cannot be enabled; ignored", e);
- mKeepAliveSession.stopKeepAliveProcess();
+ loge("keepalive cannot be enabled; ignored", e);
+ mSipSessionImpl.stopKeepAliveProcess();
}
}
@@ -1454,12 +1482,6 @@ class SipSessionGroup implements SipListener {
mProxy.onRegistrationFailed(this, errorCode, message);
}
- private void onRegistrationFailed(Throwable exception) {
- exception = getRootCause(exception);
- onRegistrationFailed(getErrorCode(exception),
- exception.toString());
- }
-
private void onRegistrationFailed(Response response) {
int statusCode = response.getStatusCode();
onRegistrationFailed(getErrorCode(statusCode),
@@ -1480,28 +1502,30 @@ class SipSessionGroup implements SipListener {
public void startKeepAliveProcess(int interval, SipProfile peerProfile,
KeepAliveProcessCallback callback) throws SipException {
synchronized (SipSessionGroup.this) {
- if (mKeepAliveProcess != null) {
+ if (mSipKeepAlive != null) {
throw new SipException("Cannot create more than one "
+ "keepalive process in a SipSession");
}
mPeerProfile = peerProfile;
- mKeepAliveProcess = new KeepAliveProcess();
- mProxy.setListener(mKeepAliveProcess);
- mKeepAliveProcess.start(interval, callback);
+ mSipKeepAlive = new SipKeepAlive();
+ mProxy.setListener(mSipKeepAlive);
+ mSipKeepAlive.start(interval, callback);
}
}
public void stopKeepAliveProcess() {
synchronized (SipSessionGroup.this) {
- if (mKeepAliveProcess != null) {
- mKeepAliveProcess.stop();
- mKeepAliveProcess = null;
+ if (mSipKeepAlive != null) {
+ mSipKeepAlive.stop();
+ mSipKeepAlive = null;
}
}
}
- class KeepAliveProcess extends SipSessionAdapter implements Runnable {
- private static final String TAG = "SipKeepAlive";
+ class SipKeepAlive extends SipSessionAdapter implements Runnable {
+ private static final String SKA_TAG = "SipKeepAlive";
+ private static final boolean SKA_DBG = true;
+
private boolean mRunning = false;
private KeepAliveProcessCallback mCallback;
@@ -1516,8 +1540,8 @@ class SipSessionGroup implements SipListener {
mInterval = interval;
mCallback = new KeepAliveProcessCallbackProxy(callback);
mWakeupTimer.set(interval * 1000, this);
- if (DEBUG) {
- Log.d(TAG, "start keepalive:"
+ if (SKA_DBG) {
+ log("start keepalive:"
+ mLocalProfile.getUriString());
}
@@ -1526,7 +1550,7 @@ class SipSessionGroup implements SipListener {
}
// return true if the event is consumed
- boolean process(EventObject evt) throws SipException {
+ boolean process(EventObject evt) {
if (mRunning && (mState == SipSession.State.PINGING)) {
if (evt instanceof ResponseEvent) {
if (parseOptionsResult(evt)) {
@@ -1560,18 +1584,18 @@ class SipSessionGroup implements SipListener {
synchronized (SipSessionGroup.this) {
if (!mRunning) return;
- if (DEBUG_PING) {
+ if (DBG_PING) {
String peerUri = (mPeerProfile == null)
? "null"
: mPeerProfile.getUriString();
- Log.d(TAG, "keepalive: " + mLocalProfile.getUriString()
+ log("keepalive: " + mLocalProfile.getUriString()
+ " --> " + peerUri + ", interval=" + mInterval);
}
try {
sendKeepAlive();
} catch (Throwable t) {
- if (DEBUG) {
- Log.w(TAG, "keepalive error: "
+ if (SKA_DBG) {
+ loge("keepalive error: "
+ mLocalProfile.getUriString(), getRootCause(t));
}
// It's possible that the keepalive process is being stopped
@@ -1584,8 +1608,8 @@ class SipSessionGroup implements SipListener {
void stop() {
synchronized (SipSessionGroup.this) {
- if (DEBUG) {
- Log.d(TAG, "stop keepalive:" + mLocalProfile.getUriString()
+ if (SKA_DBG) {
+ log("stop keepalive:" + mLocalProfile.getUriString()
+ ",RPort=" + mRPort);
}
mRunning = false;
@@ -1594,7 +1618,7 @@ class SipSessionGroup implements SipListener {
}
}
- private void sendKeepAlive() throws SipException, InterruptedException {
+ private void sendKeepAlive() throws SipException {
synchronized (SipSessionGroup.this) {
mState = SipSession.State.PINGING;
mClientTransaction = mSipHelper.sendOptions(
@@ -1615,14 +1639,14 @@ class SipSessionGroup implements SipListener {
if (mRPort == 0) mRPort = rPort;
if (mRPort != rPort) {
mPortChanged = true;
- if (DEBUG) Log.d(TAG, String.format(
+ if (SKA_DBG) log(String.format(
"rport is changed: %d <> %d", mRPort, rPort));
mRPort = rPort;
} else {
- if (DEBUG) Log.d(TAG, "rport is the same: " + rPort);
+ if (SKA_DBG) log("rport is the same: " + rPort);
}
} else {
- if (DEBUG) Log.w(TAG, "peer did not respond rport");
+ if (SKA_DBG) log("peer did not respond rport");
}
return true;
}
@@ -1634,6 +1658,14 @@ class SipSessionGroup implements SipListener {
SIPHeaderNames.VIA));
return (viaHeader == null) ? -1 : viaHeader.getRPort();
}
+
+ private void log(String s) {
+ Rlog.d(SKA_TAG, s);
+ }
+ }
+
+ private void log(String s) {
+ Rlog.d(SSI_TAG, s);
}
}
@@ -1670,22 +1702,6 @@ class SipSessionGroup implements SipListener {
return false;
}
- /**
- * @return true if the event is a response event and the response code and
- * CSeqHeader method match the given arguments; false otherwise
- */
- private static boolean expectResponse(
- int responseCode, String expectedMethod, EventObject evt) {
- if (evt instanceof ResponseEvent) {
- ResponseEvent event = (ResponseEvent) evt;
- Response response = event.getResponse();
- if (response.getStatusCode() == responseCode) {
- return expectedMethod.equalsIgnoreCase(getCseqMethod(response));
- }
- }
- return false;
- }
-
private static SipProfile createPeerProfile(HeaderAddress header)
throws SipException {
try {
@@ -1710,10 +1726,10 @@ class SipSessionGroup implements SipListener {
if (s != null) {
switch (s.mState) {
case SipSession.State.PINGING:
- return DEBUG_PING;
+ return DBG_PING;
}
}
- return DEBUG;
+ return DBG;
}
private static boolean isLoggable(EventObject evt) {
@@ -1727,19 +1743,19 @@ class SipSessionGroup implements SipListener {
if (evt instanceof ResponseEvent) {
Response response = ((ResponseEvent) evt).getResponse();
if (Request.OPTIONS.equals(response.getHeader(CSeqHeader.NAME))) {
- return DEBUG_PING;
+ return DBG_PING;
}
- return DEBUG;
+ return DBG;
} else if (evt instanceof RequestEvent) {
if (isRequestEvent(Request.OPTIONS, evt)) {
- return DEBUG_PING;
+ return DBG_PING;
}
- return DEBUG;
+ return DBG;
}
return false;
}
- private static String log(EventObject evt) {
+ private static String logEvt(EventObject evt) {
if (evt instanceof RequestEvent) {
return ((RequestEvent) evt).getRequest().toString();
} else if (evt instanceof ResponseEvent) {
@@ -1767,11 +1783,6 @@ class SipSessionGroup implements SipListener {
private int mTimeout; // in seconds
public MakeCallCommand(SipProfile peerProfile,
- String sessionDescription) {
- this(peerProfile, sessionDescription, -1);
- }
-
- public MakeCallCommand(SipProfile peerProfile,
String sessionDescription, int timeout) {
super(peerProfile);
mSessionDescription = sessionDescription;
@@ -1793,6 +1804,7 @@ class SipSessionGroup implements SipListener {
/** Class to help safely run KeepAliveProcessCallback in a different thread. */
static class KeepAliveProcessCallbackProxy implements KeepAliveProcessCallback {
+ private static final String KAPCP_TAG = "KeepAliveProcessCallbackProxy";
private KeepAliveProcessCallback mCallback;
KeepAliveProcessCallbackProxy(KeepAliveProcessCallback callback) {
@@ -1806,30 +1818,46 @@ class SipSessionGroup implements SipListener {
new Thread(runnable, "SIP-KeepAliveProcessCallbackThread").start();
}
+ @Override
public void onResponse(final boolean portChanged) {
if (mCallback == null) return;
proxy(new Runnable() {
+ @Override
public void run() {
try {
mCallback.onResponse(portChanged);
} catch (Throwable t) {
- Log.w(TAG, "onResponse", t);
+ loge("onResponse", t);
}
}
});
}
+ @Override
public void onError(final int errorCode, final String description) {
if (mCallback == null) return;
proxy(new Runnable() {
+ @Override
public void run() {
try {
mCallback.onError(errorCode, description);
} catch (Throwable t) {
- Log.w(TAG, "onError", t);
+ loge("onError", t);
}
}
});
}
+
+ private void loge(String s, Throwable t) {
+ Rlog.e(KAPCP_TAG, s, t);
+ }
+ }
+
+ private void log(String s) {
+ Rlog.d(TAG, s);
+ }
+
+ private void loge(String s, Throwable t) {
+ Rlog.e(TAG, s, t);
}
}
diff --git a/java/com/android/server/sip/SipSessionListenerProxy.java b/java/com/android/server/sip/SipSessionListenerProxy.java
index 8655a3a..7a4ae8d 100644
--- a/java/com/android/server/sip/SipSessionListenerProxy.java
+++ b/java/com/android/server/sip/SipSessionListenerProxy.java
@@ -20,11 +20,11 @@ import android.net.sip.ISipSession;
import android.net.sip.ISipSessionListener;
import android.net.sip.SipProfile;
import android.os.DeadObjectException;
-import android.util.Log;
+import android.telephony.Rlog;
/** Class to help safely run a callback in a different thread. */
class SipSessionListenerProxy extends ISipSessionListener.Stub {
- private static final String TAG = "SipSession";
+ private static final String TAG = "SipSessionListnerProxy";
private ISipSessionListener mListener;
@@ -43,9 +43,11 @@ class SipSessionListenerProxy extends ISipSessionListener.Stub {
new Thread(runnable, "SipSessionCallbackThread").start();
}
+ @Override
public void onCalling(final ISipSession session) {
if (mListener == null) return;
proxy(new Runnable() {
+ @Override
public void run() {
try {
mListener.onCalling(session);
@@ -56,10 +58,12 @@ class SipSessionListenerProxy extends ISipSessionListener.Stub {
});
}
+ @Override
public void onRinging(final ISipSession session, final SipProfile caller,
final String sessionDescription) {
if (mListener == null) return;
proxy(new Runnable() {
+ @Override
public void run() {
try {
mListener.onRinging(session, caller, sessionDescription);
@@ -70,9 +74,11 @@ class SipSessionListenerProxy extends ISipSessionListener.Stub {
});
}
+ @Override
public void onRingingBack(final ISipSession session) {
if (mListener == null) return;
proxy(new Runnable() {
+ @Override
public void run() {
try {
mListener.onRingingBack(session);
@@ -83,10 +89,12 @@ class SipSessionListenerProxy extends ISipSessionListener.Stub {
});
}
+ @Override
public void onCallEstablished(final ISipSession session,
final String sessionDescription) {
if (mListener == null) return;
proxy(new Runnable() {
+ @Override
public void run() {
try {
mListener.onCallEstablished(session, sessionDescription);
@@ -97,9 +105,11 @@ class SipSessionListenerProxy extends ISipSessionListener.Stub {
});
}
+ @Override
public void onCallEnded(final ISipSession session) {
if (mListener == null) return;
proxy(new Runnable() {
+ @Override
public void run() {
try {
mListener.onCallEnded(session);
@@ -110,10 +120,12 @@ class SipSessionListenerProxy extends ISipSessionListener.Stub {
});
}
+ @Override
public void onCallTransferring(final ISipSession newSession,
final String sessionDescription) {
if (mListener == null) return;
proxy(new Runnable() {
+ @Override
public void run() {
try {
mListener.onCallTransferring(newSession, sessionDescription);
@@ -124,9 +136,11 @@ class SipSessionListenerProxy extends ISipSessionListener.Stub {
});
}
+ @Override
public void onCallBusy(final ISipSession session) {
if (mListener == null) return;
proxy(new Runnable() {
+ @Override
public void run() {
try {
mListener.onCallBusy(session);
@@ -137,10 +151,12 @@ class SipSessionListenerProxy extends ISipSessionListener.Stub {
});
}
+ @Override
public void onCallChangeFailed(final ISipSession session,
final int errorCode, final String message) {
if (mListener == null) return;
proxy(new Runnable() {
+ @Override
public void run() {
try {
mListener.onCallChangeFailed(session, errorCode, message);
@@ -151,10 +167,12 @@ class SipSessionListenerProxy extends ISipSessionListener.Stub {
});
}
+ @Override
public void onError(final ISipSession session, final int errorCode,
final String message) {
if (mListener == null) return;
proxy(new Runnable() {
+ @Override
public void run() {
try {
mListener.onError(session, errorCode, message);
@@ -165,9 +183,11 @@ class SipSessionListenerProxy extends ISipSessionListener.Stub {
});
}
+ @Override
public void onRegistering(final ISipSession session) {
if (mListener == null) return;
proxy(new Runnable() {
+ @Override
public void run() {
try {
mListener.onRegistering(session);
@@ -178,10 +198,12 @@ class SipSessionListenerProxy extends ISipSessionListener.Stub {
});
}
+ @Override
public void onRegistrationDone(final ISipSession session,
final int duration) {
if (mListener == null) return;
proxy(new Runnable() {
+ @Override
public void run() {
try {
mListener.onRegistrationDone(session, duration);
@@ -192,10 +214,12 @@ class SipSessionListenerProxy extends ISipSessionListener.Stub {
});
}
+ @Override
public void onRegistrationFailed(final ISipSession session,
final int errorCode, final String message) {
if (mListener == null) return;
proxy(new Runnable() {
+ @Override
public void run() {
try {
mListener.onRegistrationFailed(session, errorCode, message);
@@ -206,9 +230,11 @@ class SipSessionListenerProxy extends ISipSessionListener.Stub {
});
}
+ @Override
public void onRegistrationTimeout(final ISipSession session) {
if (mListener == null) return;
proxy(new Runnable() {
+ @Override
public void run() {
try {
mListener.onRegistrationTimeout(session);
@@ -225,7 +251,15 @@ class SipSessionListenerProxy extends ISipSessionListener.Stub {
// This creates race but it's harmless. Just don't log the error
// when it happens.
} else if (mListener != null) {
- Log.w(TAG, message, t);
+ loge(message, t);
}
}
+
+ private void log(String s) {
+ Rlog.d(TAG, s);
+ }
+
+ private void loge(String s, Throwable t) {
+ Rlog.e(TAG, s, t);
+ }
}
diff --git a/java/com/android/server/sip/SipWakeLock.java b/java/com/android/server/sip/SipWakeLock.java
index 0c4d14c..b3fbb56 100644
--- a/java/com/android/server/sip/SipWakeLock.java
+++ b/java/com/android/server/sip/SipWakeLock.java
@@ -17,13 +17,13 @@
package com.android.server.sip;
import android.os.PowerManager;
-import android.util.Log;
+import android.telephony.Rlog;
import java.util.HashSet;
class SipWakeLock {
- private static final boolean DEBUG = false;
private static final String TAG = "SipWakeLock";
+ private static final boolean DBG = false;
private PowerManager mPowerManager;
private PowerManager.WakeLock mWakeLock;
private PowerManager.WakeLock mTimerWakeLock;
@@ -34,7 +34,7 @@ class SipWakeLock {
}
synchronized void reset() {
- if (DEBUG) Log.v(TAG, "reset count=" + mHolders.size());
+ if (DBG) log("reset count=" + mHolders.size());
mHolders.clear();
release(null);
}
@@ -55,7 +55,7 @@ class SipWakeLock {
PowerManager.PARTIAL_WAKE_LOCK, "SipWakeLock");
}
if (!mWakeLock.isHeld()) mWakeLock.acquire();
- if (DEBUG) Log.v(TAG, "acquire count=" + mHolders.size());
+ if (DBG) log("acquire count=" + mHolders.size());
}
synchronized void release(Object holder) {
@@ -64,6 +64,10 @@ class SipWakeLock {
&& mWakeLock.isHeld()) {
mWakeLock.release();
}
- if (DEBUG) Log.v(TAG, "release count=" + mHolders.size());
+ if (DBG) log("release count=" + mHolders.size());
+ }
+
+ private void log(String s) {
+ Rlog.d(TAG, s);
}
}
diff --git a/java/com/android/server/sip/SipWakeupTimer.java b/java/com/android/server/sip/SipWakeupTimer.java
index 00d47ac..3ba4331 100644
--- a/java/com/android/server/sip/SipWakeupTimer.java
+++ b/java/com/android/server/sip/SipWakeupTimer.java
@@ -23,31 +23,20 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.SystemClock;
-import android.util.Log;
-
-import java.io.IOException;
-import java.net.DatagramSocket;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.Collection;
+import android.telephony.Rlog;
+
import java.util.Comparator;
-import java.util.HashMap;
import java.util.Iterator;
-import java.util.Map;
-import java.util.Timer;
-import java.util.TimerTask;
import java.util.TreeSet;
import java.util.concurrent.Executor;
-import javax.sip.SipException;
/**
* Timer that can schedule events to occur even when the device is in sleep.
*/
class SipWakeupTimer extends BroadcastReceiver {
- private static final String TAG = "_SIP.WkTimer_";
+ private static final String TAG = "SipWakeupTimer";
+ private static final boolean DBG = SipService.DBG && true; // STOPSHIP if true
private static final String TRIGGER_TIME = "TriggerTime";
- private static final boolean DEBUG_TIMER = SipService.DEBUG && false;
private Context mContext;
private AlarmManager mAlarmManager;
@@ -85,7 +74,7 @@ class SipWakeupTimer extends BroadcastReceiver {
private boolean stopped() {
if (mEventQueue == null) {
- Log.w(TAG, "Timer stopped");
+ if (DBG) log("Timer stopped");
return true;
} else {
return false;
@@ -112,11 +101,11 @@ class SipWakeupTimer extends BroadcastReceiver {
}
TreeSet<MyEvent> newQueue = new TreeSet<MyEvent>(
mEventQueue.comparator());
- newQueue.addAll((Collection<MyEvent>) mEventQueue);
+ newQueue.addAll(mEventQueue);
mEventQueue.clear();
mEventQueue = newQueue;
- if (DEBUG_TIMER) {
- Log.d(TAG, "queue re-calculated");
+ if (DBG) {
+ log("queue re-calculated");
printQueue();
}
}
@@ -172,8 +161,8 @@ class SipWakeupTimer extends BroadcastReceiver {
}
long triggerTime = event.mTriggerTime;
- if (DEBUG_TIMER) {
- Log.d(TAG, " add event " + event + " scheduled on "
+ if (DBG) {
+ log("set: add event " + event + " scheduled on "
+ showTime(triggerTime) + " at " + showTime(now)
+ ", #events=" + mEventQueue.size());
printQueue();
@@ -187,7 +176,7 @@ class SipWakeupTimer extends BroadcastReceiver {
*/
public synchronized void cancel(Runnable callback) {
if (stopped() || mEventQueue.isEmpty()) return;
- if (DEBUG_TIMER) Log.d(TAG, "cancel:" + callback);
+ if (DBG) log("cancel:" + callback);
MyEvent firstEvent = mEventQueue.first();
for (Iterator<MyEvent> iter = mEventQueue.iterator();
@@ -195,7 +184,7 @@ class SipWakeupTimer extends BroadcastReceiver {
MyEvent event = iter.next();
if (event.mCallback == callback) {
iter.remove();
- if (DEBUG_TIMER) Log.d(TAG, " cancel found:" + event);
+ if (DBG) log(" cancel found:" + event);
}
}
if (mEventQueue.isEmpty()) {
@@ -209,8 +198,8 @@ class SipWakeupTimer extends BroadcastReceiver {
recalculatePeriods();
scheduleNext();
}
- if (DEBUG_TIMER) {
- Log.d(TAG, "after cancel:");
+ if (DBG) {
+ log("cancel: X");
printQueue();
}
}
@@ -242,33 +231,33 @@ class SipWakeupTimer extends BroadcastReceiver {
long triggerTime = intent.getLongExtra(TRIGGER_TIME, -1L);
execute(triggerTime);
} else {
- Log.d(TAG, "unrecognized intent: " + intent);
+ log("onReceive: unrecognized intent: " + intent);
}
}
private void printQueue() {
int count = 0;
for (MyEvent event : mEventQueue) {
- Log.d(TAG, " " + event + ": scheduled at "
+ log(" " + event + ": scheduled at "
+ showTime(event.mTriggerTime) + ": last at "
+ showTime(event.mLastTriggerTime));
if (++count >= 5) break;
}
if (mEventQueue.size() > count) {
- Log.d(TAG, " .....");
+ log(" .....");
} else if (count == 0) {
- Log.d(TAG, " <empty>");
+ log(" <empty>");
}
}
private void execute(long triggerTime) {
- if (DEBUG_TIMER) Log.d(TAG, "time's up, triggerTime = "
+ if (DBG) log("time's up, triggerTime = "
+ showTime(triggerTime) + ": " + mEventQueue.size());
if (stopped() || mEventQueue.isEmpty()) return;
for (MyEvent event : mEventQueue) {
if (event.mTriggerTime != triggerTime) continue;
- if (DEBUG_TIMER) Log.d(TAG, "execute " + event);
+ if (DBG) log("execute " + event);
event.mLastTriggerTime = triggerTime;
event.mTriggerTime += event.mPeriod;
@@ -276,8 +265,8 @@ class SipWakeupTimer extends BroadcastReceiver {
// run the callback in the handler thread to prevent deadlock
mExecutor.execute(event.mCallback);
}
- if (DEBUG_TIMER) {
- Log.d(TAG, "after timeout execution");
+ if (DBG) {
+ log("after timeout execution");
printQueue();
}
scheduleNext();
@@ -327,6 +316,7 @@ class SipWakeupTimer extends BroadcastReceiver {
// Sort the events by mMaxPeriod so that the first event can be used to
// align events with larger periods
private static class MyEventComparator implements Comparator<MyEvent> {
+ @Override
public int compare(MyEvent e1, MyEvent e2) {
if (e1 == e2) return 0;
int diff = e1.mMaxPeriod - e2.mMaxPeriod;
@@ -334,8 +324,13 @@ class SipWakeupTimer extends BroadcastReceiver {
return diff;
}
+ @Override
public boolean equals(Object that) {
return (this == that);
}
}
+
+ private void log(String s) {
+ Rlog.d(TAG, s);
+ }
}