am c7510581: SipService: add log control, suppress ping log.

Merge commit 'c7510581b81d63536db7d46ca8533106c8cf57c6' into gingerbread-plus-aosp

* commit 'c7510581b81d63536db7d46ca8533106c8cf57c6':
  SipService: add log control, suppress ping log.
This commit is contained in:
Hung-ying Tyan
2010-09-16 04:50:25 -07:00
committed by Android Git Automerger
3 changed files with 146 additions and 84 deletions

View File

@@ -68,6 +68,7 @@ import javax.sip.message.Response;
*/ */
class SipHelper { class SipHelper {
private static final String TAG = SipHelper.class.getSimpleName(); private static final String TAG = SipHelper.class.getSimpleName();
private static final boolean DEBUG = true;
private SipStack mSipStack; private SipStack mSipStack;
private SipProvider mSipProvider; private SipProvider mSipProvider;
@@ -264,6 +265,7 @@ class SipHelper {
ClientTransaction clientTransaction = ClientTransaction clientTransaction =
mSipProvider.getNewClientTransaction(request); mSipProvider.getNewClientTransaction(request);
if (DEBUG) Log.d(TAG, "send INVITE: " + request);
clientTransaction.sendRequest(); clientTransaction.sendRequest();
return clientTransaction; return clientTransaction;
} catch (ParseException e) { } catch (ParseException e) {
@@ -281,6 +283,7 @@ class SipHelper {
ClientTransaction clientTransaction = ClientTransaction clientTransaction =
mSipProvider.getNewClientTransaction(request); mSipProvider.getNewClientTransaction(request);
if (DEBUG) Log.d(TAG, "send RE-INVITE: " + request);
dialog.sendRequest(clientTransaction); dialog.sendRequest(clientTransaction);
return clientTransaction; return clientTransaction;
} catch (ParseException e) { } catch (ParseException e) {
@@ -314,6 +317,7 @@ class SipHelper {
ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME); ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
toHeader.setTag(tag); toHeader.setTag(tag);
response.addHeader(toHeader); response.addHeader(toHeader);
if (DEBUG) Log.d(TAG, "send RINGING: " + response);
transaction.sendResponse(response); transaction.sendResponse(response);
return transaction; return transaction;
} catch (ParseException e) { } catch (ParseException e) {
@@ -340,7 +344,9 @@ class SipHelper {
if (inviteTransaction == null) { if (inviteTransaction == null) {
inviteTransaction = getServerTransaction(event); inviteTransaction = getServerTransaction(event);
} }
if (inviteTransaction.getState() != TransactionState.COMPLETED) { if (inviteTransaction.getState() != TransactionState.COMPLETED) {
if (DEBUG) Log.d(TAG, "send OK: " + response);
inviteTransaction.sendResponse(response); inviteTransaction.sendResponse(response);
} }
@@ -358,6 +364,7 @@ class SipHelper {
Response.BUSY_HERE, request); Response.BUSY_HERE, request);
if (inviteTransaction.getState() != TransactionState.COMPLETED) { if (inviteTransaction.getState() != TransactionState.COMPLETED) {
if (DEBUG) Log.d(TAG, "send BUSY HERE: " + response);
inviteTransaction.sendResponse(response); inviteTransaction.sendResponse(response);
} }
} catch (ParseException e) { } catch (ParseException e) {
@@ -373,27 +380,31 @@ class SipHelper {
Response response = event.getResponse(); Response response = event.getResponse();
long cseq = ((CSeqHeader) response.getHeader(CSeqHeader.NAME)) long cseq = ((CSeqHeader) response.getHeader(CSeqHeader.NAME))
.getSeqNumber(); .getSeqNumber();
dialog.sendAck(dialog.createAck(cseq)); Request ack = dialog.createAck(cseq);
if (DEBUG) Log.d(TAG, "send ACK: " + ack);
dialog.sendAck(ack);
} }
public void sendBye(Dialog dialog) throws SipException { public void sendBye(Dialog dialog) throws SipException {
Request byeRequest = dialog.createRequest(Request.BYE); Request byeRequest = dialog.createRequest(Request.BYE);
Log.d(TAG, "send BYE: " + byeRequest); if (DEBUG) Log.d(TAG, "send BYE: " + byeRequest);
dialog.sendRequest(mSipProvider.getNewClientTransaction(byeRequest)); dialog.sendRequest(mSipProvider.getNewClientTransaction(byeRequest));
} }
public void sendCancel(ClientTransaction inviteTransaction) public void sendCancel(ClientTransaction inviteTransaction)
throws SipException { throws SipException {
Request cancelRequest = inviteTransaction.createCancel(); Request cancelRequest = inviteTransaction.createCancel();
if (DEBUG) Log.d(TAG, "send CANCEL: " + cancelRequest);
mSipProvider.getNewClientTransaction(cancelRequest).sendRequest(); mSipProvider.getNewClientTransaction(cancelRequest).sendRequest();
} }
public void sendResponse(RequestEvent event, int responseCode) public void sendResponse(RequestEvent event, int responseCode)
throws SipException { throws SipException {
try { try {
getServerTransaction(event).sendResponse( Response response = mMessageFactory.createResponse(
mMessageFactory.createResponse( responseCode, event.getRequest());
responseCode, event.getRequest())); if (DEBUG) Log.d(TAG, "send response: " + response);
getServerTransaction(event).sendResponse(response);
} catch (ParseException e) { } catch (ParseException e) {
throw new SipException("sendResponse()", e); throw new SipException("sendResponse()", e);
} }
@@ -402,8 +413,10 @@ class SipHelper {
public void sendInviteRequestTerminated(Request inviteRequest, public void sendInviteRequestTerminated(Request inviteRequest,
ServerTransaction inviteTransaction) throws SipException { ServerTransaction inviteTransaction) throws SipException {
try { try {
inviteTransaction.sendResponse(mMessageFactory.createResponse( Response response = mMessageFactory.createResponse(
Response.REQUEST_TERMINATED, inviteRequest)); Response.REQUEST_TERMINATED, inviteRequest);
if (DEBUG) Log.d(TAG, "send response: " + response);
inviteTransaction.sendResponse(response);
} catch (ParseException e) { } catch (ParseException e) {
throw new SipException("sendInviteRequestTerminated()", e); throw new SipException("sendInviteRequestTerminated()", e);
} }

View File

@@ -59,6 +59,8 @@ import javax.sip.SipException;
*/ */
public final class SipService extends ISipService.Stub { public final class SipService extends ISipService.Stub {
private static final String TAG = "SipService"; private static final String TAG = "SipService";
private static final boolean DEBUG = true;
private static final boolean DEBUG_TIMER = DEBUG && false;
private static final int EXPIRY_TIME = 3600; private static final int EXPIRY_TIME = 3600;
private static final int SHORT_EXPIRY_TIME = 10; private static final int SHORT_EXPIRY_TIME = 10;
private static final int MIN_EXPIRY_TIME = 60; private static final int MIN_EXPIRY_TIME = 60;
@@ -90,7 +92,7 @@ public final class SipService extends ISipService.Stub {
} }
private SipService(Context context) { private SipService(Context context) {
Log.v(TAG, " service started!"); if (DEBUG) Log.d(TAG, " service started!");
mContext = context; mContext = context;
mConnectivityReceiver = new ConnectivityReceiver(); mConnectivityReceiver = new ConnectivityReceiver();
context.registerReceiver(mConnectivityReceiver, context.registerReceiver(mConnectivityReceiver,
@@ -137,7 +139,7 @@ public final class SipService extends ISipService.Stub {
throw new RuntimeException( throw new RuntimeException(
"empty broadcast action for incoming call"); "empty broadcast action for incoming call");
} }
Log.v(TAG, "open3: " + localProfile.getUriString() + ": " if (DEBUG) Log.d(TAG, "open3: " + localProfile.getUriString() + ": "
+ incomingCallBroadcastAction + ": " + listener); + incomingCallBroadcastAction + ": " + listener);
try { try {
SipSessionGroupExt group = createGroup(localProfile, SipSessionGroupExt group = createGroup(localProfile,
@@ -238,14 +240,14 @@ public final class SipService extends ISipService.Stub {
} }
private void notifyProfileAdded(SipProfile localProfile) { private void notifyProfileAdded(SipProfile localProfile) {
Log.d(TAG, "notify: profile added: " + localProfile); if (DEBUG) Log.d(TAG, "notify: profile added: " + localProfile);
Intent intent = new Intent(SipManager.SIP_ADD_PHONE_ACTION); Intent intent = new Intent(SipManager.SIP_ADD_PHONE_ACTION);
intent.putExtra(SipManager.LOCAL_URI_KEY, localProfile.getUriString()); intent.putExtra(SipManager.LOCAL_URI_KEY, localProfile.getUriString());
mContext.sendBroadcast(intent); mContext.sendBroadcast(intent);
} }
private void notifyProfileRemoved(SipProfile localProfile) { private void notifyProfileRemoved(SipProfile localProfile) {
Log.d(TAG, "notify: profile removed: " + localProfile); if (DEBUG) Log.d(TAG, "notify: profile removed: " + localProfile);
Intent intent = new Intent(SipManager.SIP_REMOVE_PHONE_ACTION); Intent intent = new Intent(SipManager.SIP_REMOVE_PHONE_ACTION);
intent.putExtra(SipManager.LOCAL_URI_KEY, localProfile.getUriString()); intent.putExtra(SipManager.LOCAL_URI_KEY, localProfile.getUriString());
mContext.sendBroadcast(intent); mContext.sendBroadcast(intent);
@@ -260,7 +262,7 @@ public final class SipService extends ISipService.Stub {
private void grabWifiLock() { private void grabWifiLock() {
if (mWifiLock == null) { if (mWifiLock == null) {
Log.v(TAG, "acquire wifi lock"); if (DEBUG) Log.d(TAG, "acquire wifi lock");
mWifiLock = ((WifiManager) mWifiLock = ((WifiManager)
mContext.getSystemService(Context.WIFI_SERVICE)) mContext.getSystemService(Context.WIFI_SERVICE))
.createWifiLock(WifiManager.WIFI_MODE_FULL, TAG); .createWifiLock(WifiManager.WIFI_MODE_FULL, TAG);
@@ -270,7 +272,7 @@ public final class SipService extends ISipService.Stub {
private void releaseWifiLock() { private void releaseWifiLock() {
if (mWifiLock != null) { if (mWifiLock != null) {
Log.v(TAG, "release wifi lock"); if (DEBUG) Log.d(TAG, "release wifi lock");
mWifiLock.release(); mWifiLock.release();
mWifiLock = null; mWifiLock = null;
} }
@@ -283,7 +285,7 @@ public final class SipService extends ISipService.Stub {
private synchronized void onConnectivityChanged( private synchronized void onConnectivityChanged(
String type, boolean connected) { String type, boolean connected) {
Log.v(TAG, "onConnectivityChanged(): " if (DEBUG) Log.d(TAG, "onConnectivityChanged(): "
+ mNetworkType + (mConnected? " CONNECTED" : " DISCONNECTED") + mNetworkType + (mConnected? " CONNECTED" : " DISCONNECTED")
+ " --> " + type + (connected? " CONNECTED" : " DISCONNECTED")); + " --> " + type + (connected? " CONNECTED" : " DISCONNECTED"));
@@ -398,7 +400,7 @@ public final class SipService extends ISipService.Stub {
mSipGroup.openToReceiveCalls(this); mSipGroup.openToReceiveCalls(this);
mAutoRegistration.start(mSipGroup); mAutoRegistration.start(mSipGroup);
} }
Log.v(TAG, " openToReceiveCalls: " + getUri() + ": " if (DEBUG) Log.d(TAG, " openToReceiveCalls: " + getUri() + ": "
+ mIncomingCallBroadcastAction); + mIncomingCallBroadcastAction);
} }
@@ -410,8 +412,8 @@ public final class SipService extends ISipService.Stub {
if (mOpened) openToReceiveCalls(); if (mOpened) openToReceiveCalls();
} else { } else {
// close mSipGroup but remember mOpened // close mSipGroup but remember mOpened
Log.v(TAG, " close auto reg temporarily: " + getUri() + ": " if (DEBUG) Log.d(TAG, " close auto reg temporarily: "
+ mIncomingCallBroadcastAction); + getUri() + ": " + mIncomingCallBroadcastAction);
mSipGroup.close(); mSipGroup.close();
mAutoRegistration.stop(); mAutoRegistration.stop();
} }
@@ -437,7 +439,7 @@ public final class SipService extends ISipService.Stub {
mOpened = false; mOpened = false;
mSipGroup.closeToNotReceiveCalls(); mSipGroup.closeToNotReceiveCalls();
mAutoRegistration.stop(); mAutoRegistration.stop();
Log.v(TAG, " close: " + getUri() + ": " if (DEBUG) Log.d(TAG, " close: " + getUri() + ": "
+ mIncomingCallBroadcastAction); + mIncomingCallBroadcastAction);
} }
@@ -456,13 +458,13 @@ public final class SipService extends ISipService.Stub {
} }
// send out incoming call broadcast // send out incoming call broadcast
Log.d(TAG, " ringing~~ " + getUri() + ": " + caller.getUri()
+ ": " + session.getCallId());
addPendingSession(session); addPendingSession(session);
Intent intent = SipManager.createIncomingCallBroadcast( Intent intent = SipManager.createIncomingCallBroadcast(
mIncomingCallBroadcastAction, session.getCallId(), mIncomingCallBroadcastAction, session.getCallId(),
sessionDescription); sessionDescription);
Log.d(TAG, " send out intent: " + intent); if (DEBUG) Log.d(TAG, " ringing~~ " + getUri() + ": "
+ caller.getUri() + ": " + session.getCallId()
+ " " + mIncomingCallBroadcastAction);
mContext.sendBroadcast(intent); mContext.sendBroadcast(intent);
} catch (RemoteException e) { } catch (RemoteException e) {
// should never happen with a local call // should never happen with a local call
@@ -474,7 +476,8 @@ public final class SipService extends ISipService.Stub {
@Override @Override
public void onError(ISipSession session, String errorClass, public void onError(ISipSession session, String errorClass,
String message) { String message) {
Log.v(TAG, "sip session error: " + errorClass + ": " + message); if (DEBUG) Log.d(TAG, "sip session error: " + errorClass + ": "
+ message);
} }
public boolean isOpened() { public boolean isOpened() {
@@ -506,7 +509,7 @@ public final class SipService extends ISipService.Stub {
public void run() { public void run() {
synchronized (SipService.this) { synchronized (SipService.this) {
SipSessionGroup.SipSessionImpl session = mSession.duplicate(); SipSessionGroup.SipSessionImpl session = mSession.duplicate();
Log.d(TAG, " ~~~ keepalive"); if (DEBUG) Log.d(TAG, "~~~ keepalive");
mTimer.cancel(this); mTimer.cancel(this);
session.sendKeepAlive(); session.sendKeepAlive();
if (session.isReRegisterRequired()) { if (session.isReRegisterRequired()) {
@@ -549,7 +552,7 @@ public final class SipService extends ISipService.Stub {
// TODO: when rfc5626 is deployed, use reg-id and sip.instance // TODO: when rfc5626 is deployed, use reg-id and sip.instance
// in registration to avoid adding duplicate entries to server // in registration to avoid adding duplicate entries to server
mSession.unregister(); mSession.unregister();
Log.v(TAG, "start AutoRegistrationProcess for " if (DEBUG) Log.d(TAG, "start AutoRegistrationProcess for "
+ mSession.getLocalProfile().getUriString()); + mSession.getLocalProfile().getUriString());
} }
} }
@@ -581,7 +584,6 @@ public final class SipService extends ISipService.Stub {
} }
public void setListener(ISipSessionListener listener) { public void setListener(ISipSessionListener listener) {
Log.v(TAG, "setListener(): " + listener);
synchronized (SipService.this) { synchronized (SipService.this) {
mProxy.setListener(listener); mProxy.setListener(listener);
if (mSession == null) return; if (mSession == null) return;
@@ -619,7 +621,7 @@ public final class SipService extends ISipService.Stub {
public void run() { public void run() {
mErrorCode = null; mErrorCode = null;
mErrorMessage = null; mErrorMessage = null;
Log.v(TAG, " ~~~ registering"); if (DEBUG) Log.d(TAG, "~~~ registering");
synchronized (SipService.this) { synchronized (SipService.this) {
if (mConnected && !isStopped()) mSession.register(EXPIRY_TIME); if (mConnected && !isStopped()) mSession.register(EXPIRY_TIME);
} }
@@ -642,7 +644,7 @@ public final class SipService extends ISipService.Stub {
} }
private void restart(int duration) { private void restart(int duration) {
Log.v(TAG, "Refresh registration " + duration + "s later."); if (DEBUG) Log.d(TAG, "Refresh registration " + duration + "s later.");
mTimer.cancel(this); mTimer.cancel(this);
mTimer.set(duration * 1000, this); mTimer.set(duration * 1000, this);
} }
@@ -659,7 +661,7 @@ public final class SipService extends ISipService.Stub {
@Override @Override
public void onRegistering(ISipSession session) { public void onRegistering(ISipSession session) {
Log.v(TAG, "onRegistering(): " + session + ": " + mSession); if (DEBUG) Log.d(TAG, "onRegistering(): " + session);
synchronized (SipService.this) { synchronized (SipService.this) {
if (!isStopped() && (session != mSession)) return; if (!isStopped() && (session != mSession)) return;
mRegistered = false; mRegistered = false;
@@ -669,7 +671,7 @@ public final class SipService extends ISipService.Stub {
@Override @Override
public void onRegistrationDone(ISipSession session, int duration) { public void onRegistrationDone(ISipSession session, int duration) {
Log.v(TAG, "onRegistrationDone(): " + session + ": " + mSession); if (DEBUG) Log.d(TAG, "onRegistrationDone(): " + session);
synchronized (SipService.this) { synchronized (SipService.this) {
if (!isStopped() && (session != mSession)) return; if (!isStopped() && (session != mSession)) return;
@@ -703,7 +705,7 @@ public final class SipService extends ISipService.Stub {
} else { } else {
mRegistered = false; mRegistered = false;
mExpiryTime = -1L; mExpiryTime = -1L;
Log.v(TAG, "Refresh registration immediately"); if (DEBUG) Log.d(TAG, "Refresh registration immediately");
run(); run();
} }
} }
@@ -714,8 +716,8 @@ public final class SipService extends ISipService.Stub {
String errorCodeString, String message) { String errorCodeString, String message) {
SipErrorCode errorCode = SipErrorCode errorCode =
Enum.valueOf(SipErrorCode.class, errorCodeString); Enum.valueOf(SipErrorCode.class, errorCodeString);
Log.v(TAG, "onRegistrationFailed(): " + session + ": " + mSession if (DEBUG) Log.d(TAG, "onRegistrationFailed(): " + session + ": "
+ ": " + errorCode + ": " + message); + errorCode + ": " + message);
synchronized (SipService.this) { synchronized (SipService.this) {
if (!isStopped() && (session != mSession)) return; if (!isStopped() && (session != mSession)) return;
mErrorCode = errorCode; mErrorCode = errorCode;
@@ -724,7 +726,7 @@ public final class SipService extends ISipService.Stub {
message); message);
if (errorCode == SipErrorCode.INVALID_CREDENTIALS) { if (errorCode == SipErrorCode.INVALID_CREDENTIALS) {
Log.d(TAG, " pause auto-registration"); if (DEBUG) Log.d(TAG, " pause auto-registration");
stopButKeepStates(); stopButKeepStates();
} else if (!isStopped()) { } else if (!isStopped()) {
onError(); onError();
@@ -734,7 +736,7 @@ public final class SipService extends ISipService.Stub {
@Override @Override
public void onRegistrationTimeout(ISipSession session) { public void onRegistrationTimeout(ISipSession session) {
Log.v(TAG, "onRegistrationTimeout(): " + session + ": " + mSession); if (DEBUG) Log.d(TAG, "onRegistrationTimeout(): " + session);
synchronized (SipService.this) { synchronized (SipService.this) {
if (!isStopped() && (session != mSession)) return; if (!isStopped() && (session != mSession)) return;
mErrorCode = SipErrorCode.TIME_OUT; mErrorCode = SipErrorCode.TIME_OUT;
@@ -773,30 +775,33 @@ public final class SipService extends ISipService.Stub {
NetworkInfo.State state = netInfo.getState(); NetworkInfo.State state = netInfo.getState();
NetworkInfo activeNetInfo = getActiveNetworkInfo(); NetworkInfo activeNetInfo = getActiveNetworkInfo();
if (DEBUG) {
if (activeNetInfo != null) { if (activeNetInfo != null) {
Log.v(TAG, "active network: " + activeNetInfo.getTypeName() Log.d(TAG, "active network: "
+ activeNetInfo.getTypeName()
+ ((activeNetInfo.getState() == NetworkInfo.State.CONNECTED) + ((activeNetInfo.getState() == NetworkInfo.State.CONNECTED)
? " CONNECTED" : " DISCONNECTED")); ? " CONNECTED" : " DISCONNECTED"));
} else { } else {
Log.v(TAG, "active network: null"); Log.d(TAG, "active network: null");
}
} }
if ((state == NetworkInfo.State.CONNECTED) if ((state == NetworkInfo.State.CONNECTED)
&& (activeNetInfo != null) && (activeNetInfo != null)
&& (activeNetInfo.getType() != netInfo.getType())) { && (activeNetInfo.getType() != netInfo.getType())) {
Log.d(TAG, "ignore connect event: " + type if (DEBUG) Log.d(TAG, "ignore connect event: " + type
+ ", active: " + activeNetInfo.getTypeName()); + ", active: " + activeNetInfo.getTypeName());
return; return;
} }
if (state == NetworkInfo.State.CONNECTED) { if (state == NetworkInfo.State.CONNECTED) {
Log.v(TAG, "Connectivity alert: CONNECTED " + type); if (DEBUG) Log.d(TAG, "Connectivity alert: CONNECTED " + type);
onChanged(type, true); onChanged(type, true);
} else if (state == NetworkInfo.State.DISCONNECTED) { } else if (state == NetworkInfo.State.DISCONNECTED) {
Log.v(TAG, "Connectivity alert: DISCONNECTED " + type); if (DEBUG) Log.d(TAG, "Connectivity alert: DISCONNECTED " + type);
onChanged(type, false); onChanged(type, false);
} else { } else {
Log.d(TAG, "Connectivity alert not processed: " + state if (DEBUG) Log.d(TAG, "Connectivity alert not processed: "
+ " " + type); + state + " " + type);
} }
} }
} }
@@ -847,7 +852,7 @@ public final class SipService extends ISipService.Stub {
return; return;
} }
mTask = null; mTask = null;
Log.v(TAG, " deliver change for " + mNetworkType if (DEBUG) Log.d(TAG, " deliver change for " + mNetworkType
+ (mConnected ? " CONNECTED" : "DISCONNECTED")); + (mConnected ? " CONNECTED" : "DISCONNECTED"));
onConnectivityChanged(mNetworkType, mConnected); onConnectivityChanged(mNetworkType, mConnected);
} }
@@ -929,9 +934,11 @@ public final class SipService extends ISipService.Stub {
newQueue.addAll((Collection<MyEvent>) mEventQueue); newQueue.addAll((Collection<MyEvent>) mEventQueue);
mEventQueue.clear(); mEventQueue.clear();
mEventQueue = newQueue; mEventQueue = newQueue;
Log.v(TAG, "queue re-calculated"); if (DEBUG_TIMER) {
Log.d(TAG, "queue re-calculated");
printQueue(); printQueue();
} }
}
// Determines the period and the trigger time of the new event and insert it // Determines the period and the trigger time of the new event and insert it
// to the queue. // to the queue.
@@ -984,11 +991,13 @@ public final class SipService extends ISipService.Stub {
} }
long triggerTime = event.mTriggerTime; long triggerTime = event.mTriggerTime;
Log.v(TAG, " add event " + event + " scheduled at " if (DEBUG_TIMER) {
Log.d(TAG, " add event " + event + " scheduled at "
+ showTime(triggerTime) + " at " + showTime(now) + showTime(triggerTime) + " at " + showTime(now)
+ ", #events=" + mEventQueue.size()); + ", #events=" + mEventQueue.size());
printQueue(); printQueue();
} }
}
/** /**
* Cancels all the timer events with the specified callback. * Cancels all the timer events with the specified callback.
@@ -997,7 +1006,7 @@ public final class SipService extends ISipService.Stub {
*/ */
public synchronized void cancel(Runnable callback) { public synchronized void cancel(Runnable callback) {
if (stopped() || mEventQueue.isEmpty()) return; if (stopped() || mEventQueue.isEmpty()) return;
Log.d(TAG, "cancel:" + callback); if (DEBUG_TIMER) Log.d(TAG, "cancel:" + callback);
MyEvent firstEvent = mEventQueue.first(); MyEvent firstEvent = mEventQueue.first();
for (Iterator<MyEvent> iter = mEventQueue.iterator(); for (Iterator<MyEvent> iter = mEventQueue.iterator();
@@ -1005,7 +1014,7 @@ public final class SipService extends ISipService.Stub {
MyEvent event = iter.next(); MyEvent event = iter.next();
if (event.mCallback == callback) { if (event.mCallback == callback) {
iter.remove(); iter.remove();
Log.d(TAG, " cancel found:" + event); if (DEBUG_TIMER) Log.d(TAG, " cancel found:" + event);
} }
} }
if (mEventQueue.isEmpty()) { if (mEventQueue.isEmpty()) {
@@ -1019,9 +1028,11 @@ public final class SipService extends ISipService.Stub {
recalculatePeriods(); recalculatePeriods();
scheduleNext(); scheduleNext();
} }
if (DEBUG_TIMER) {
Log.d(TAG, "after cancel:"); Log.d(TAG, "after cancel:");
printQueue(); printQueue();
} }
}
private void scheduleNext() { private void scheduleNext() {
if (stopped() || mEventQueue.isEmpty()) return; if (stopped() || mEventQueue.isEmpty()) return;
@@ -1069,13 +1080,13 @@ public final class SipService extends ISipService.Stub {
} }
private void execute(long triggerTime) { private void execute(long triggerTime) {
Log.d(TAG, "time's up, triggerTime = " + showTime(triggerTime) + ": " if (DEBUG_TIMER) Log.d(TAG, "time's up, triggerTime = "
+ mEventQueue.size()); + showTime(triggerTime) + ": " + mEventQueue.size());
if (stopped() || mEventQueue.isEmpty()) return; if (stopped() || mEventQueue.isEmpty()) return;
for (MyEvent event : mEventQueue) { for (MyEvent event : mEventQueue) {
if (event.mTriggerTime != triggerTime) break; if (event.mTriggerTime != triggerTime) break;
Log.d(TAG, "execute " + event); if (DEBUG_TIMER) Log.d(TAG, "execute " + event);
event.mLastTriggerTime = event.mTriggerTime; event.mLastTriggerTime = event.mTriggerTime;
event.mTriggerTime += event.mPeriod; event.mTriggerTime += event.mPeriod;
@@ -1083,8 +1094,10 @@ public final class SipService extends ISipService.Stub {
// run the callback in a new thread to prevent deadlock // run the callback in a new thread to prevent deadlock
new Thread(event.mCallback).start(); new Thread(event.mCallback).start();
} }
if (DEBUG_TIMER) {
Log.d(TAG, "after timeout execution"); Log.d(TAG, "after timeout execution");
printQueue(); printQueue();
}
scheduleNext(); scheduleNext();
} }

View File

@@ -80,6 +80,8 @@ import javax.sip.message.Response;
*/ */
class SipSessionGroup implements SipListener { class SipSessionGroup implements SipListener {
private static final String TAG = "SipSession"; private static final String TAG = "SipSession";
private static final boolean DEBUG = true;
private static final boolean DEBUG_PING = DEBUG && false;
private static final String ANONYMOUS = "anonymous"; private static final String ANONYMOUS = "anonymous";
private static final String SERVER_ERROR_PREFIX = "Response: "; private static final String SERVER_ERROR_PREFIX = "Response: ";
private static final int EXPIRY_TIME = 3600; private static final int EXPIRY_TIME = 3600;
@@ -218,22 +220,26 @@ class SipSessionGroup implements SipListener {
private synchronized SipSessionImpl getSipSession(EventObject event) { private synchronized SipSessionImpl getSipSession(EventObject event) {
String key = SipHelper.getCallId(event); String key = SipHelper.getCallId(event);
Log.d(TAG, "sesssion key from event: " + key); SipSessionImpl session = mSessionMap.get(key);
if ((session != null) && isLoggable(session)) {
Log.d(TAG, "session key from event: " + key);
Log.d(TAG, "active sessions:"); Log.d(TAG, "active sessions:");
for (String k : mSessionMap.keySet()) { for (String k : mSessionMap.keySet()) {
Log.d(TAG, " ..." + k + ": " + mSessionMap.get(k)); Log.d(TAG, " ..." + k + ": " + mSessionMap.get(k));
} }
SipSessionImpl session = mSessionMap.get(key); }
return ((session != null) ? session : mCallReceiverSession); return ((session != null) ? session : mCallReceiverSession);
} }
private synchronized void addSipSession(SipSessionImpl newSession) { private synchronized void addSipSession(SipSessionImpl newSession) {
removeSipSession(newSession); removeSipSession(newSession);
String key = newSession.getCallId(); String key = newSession.getCallId();
Log.d(TAG, "+++ add a session with key: '" + key + "'");
mSessionMap.put(key, newSession); mSessionMap.put(key, newSession);
if (isLoggable(newSession)) {
Log.d(TAG, "+++ add a session with key: '" + key + "'");
for (String k : mSessionMap.keySet()) { for (String k : mSessionMap.keySet()) {
Log.d(TAG, " ..... " + k + ": " + mSessionMap.get(k)); Log.d(TAG, " " + k + ": " + mSessionMap.get(k));
}
} }
} }
@@ -254,10 +260,12 @@ class SipSessionGroup implements SipListener {
} }
} }
} }
Log.d(TAG, " remove session " + session + " with key '" + key + "'");
if ((s != null) && isLoggable(s)) {
Log.d(TAG, "remove session " + session + " @key '" + key + "'");
for (String k : mSessionMap.keySet()) { for (String k : mSessionMap.keySet()) {
Log.d(TAG, " ..... " + k + ": " + mSessionMap.get(k)); Log.d(TAG, " " + k + ": " + mSessionMap.get(k));
}
} }
} }
@@ -288,10 +296,10 @@ class SipSessionGroup implements SipListener {
private synchronized void process(EventObject event) { private synchronized void process(EventObject event) {
SipSessionImpl session = getSipSession(event); SipSessionImpl session = getSipSession(event);
try { try {
if ((session != null) && session.process(event)) { boolean isLoggable = isLoggable(session, event);
Log.d(TAG, " ~~~~~ new state: " + session.mState); boolean processed = (session != null) && session.process(event);
} else { if (isLoggable && processed) {
Log.d(TAG, "event not processed: " + event); Log.d(TAG, "new state after: " + session.mState);
} }
} catch (Throwable e) { } catch (Throwable e) {
Log.w(TAG, "event process error: " + event, e); Log.w(TAG, "event process error: " + event, e);
@@ -321,8 +329,8 @@ class SipSessionGroup implements SipListener {
} }
public boolean process(EventObject evt) throws SipException { public boolean process(EventObject evt) throws SipException {
Log.d(TAG, " ~~~~~ " + this + ": " + mState + ": processing " if (isLoggable(this, evt)) Log.d(TAG, " ~~~~~ " + this + ": "
+ log(evt)); + mState + ": processing " + log(evt));
if (isRequestEvent(Request.INVITE, evt)) { if (isRequestEvent(Request.INVITE, evt)) {
RequestEvent event = (RequestEvent) evt; RequestEvent event = (RequestEvent) evt;
SipSessionImpl newSession = new SipSessionImpl(mProxy); SipSessionImpl newSession = new SipSessionImpl(mProxy);
@@ -503,8 +511,8 @@ class SipSessionGroup implements SipListener {
} }
public boolean process(EventObject evt) throws SipException { public boolean process(EventObject evt) throws SipException {
Log.d(TAG, " ~~~~~ " + this + ": " + mState + ": processing " if (isLoggable(this, evt)) Log.d(TAG, " ~~~~~ " + this + ": "
+ log(evt)); + mState + ": processing " + log(evt));
synchronized (SipSessionGroup.this) { synchronized (SipSessionGroup.this) {
if (isClosed()) return false; if (isClosed()) return false;
@@ -672,14 +680,14 @@ class SipSessionGroup implements SipListener {
if (mRPort == 0) mRPort = rPort; if (mRPort == 0) mRPort = rPort;
if (mRPort != rPort) { if (mRPort != rPort) {
mReRegisterFlag = true; mReRegisterFlag = true;
Log.w(TAG, String.format("rport is changed: %d <> %d", if (DEBUG) Log.w(TAG, String.format(
mRPort, rPort)); "rport is changed: %d <> %d", mRPort, rPort));
mRPort = rPort; mRPort = rPort;
} else { } else {
Log.w(TAG, "rport is the same: " + rPort); if (DEBUG_PING) Log.w(TAG, "rport is the same: " + rPort);
} }
} else { } else {
Log.w(TAG, "peer did not respect our rport request"); if (DEBUG) Log.w(TAG, "peer did not respond rport");
} }
reset(); reset();
return true; return true;
@@ -1188,6 +1196,34 @@ class SipSessionGroup implements SipListener {
} }
} }
private static boolean isLoggable(SipSessionImpl s) {
if (s != null) {
switch (s.mState) {
case PINGING:
return DEBUG_PING;
}
}
return DEBUG;
}
private static boolean isLoggable(SipSessionImpl s, EventObject evt) {
if (!isLoggable(s)) return false;
if (evt == null) return false;
if (evt instanceof OptionsCommand) {
return DEBUG_PING;
} else if (evt instanceof ResponseEvent) {
Response response = ((ResponseEvent) evt).getResponse();
if (Request.OPTIONS.equals(response.getHeader(CSeqHeader.NAME))) {
return DEBUG_PING;
}
return DEBUG;
} else if (evt instanceof RequestEvent) {
return DEBUG;
}
return false;
}
private static String log(EventObject evt) { private static String log(EventObject evt) {
if (evt instanceof RequestEvent) { if (evt instanceof RequestEvent) {
return ((RequestEvent) evt).getRequest().toString(); return ((RequestEvent) evt).getRequest().toString();