@@ -442,6 +442,7 @@ private synchronized void onConnectivityChanged(
442442
443443 if (wasConnected ) {
444444 mLocalIp = null ;
445+ stopPortMappingMeasurement ();
445446 for (SipSessionGroupExt group : mSipGroups .values ()) {
446447 group .onConnectivityChanged (false );
447448 }
@@ -457,7 +458,6 @@ private synchronized void onConnectivityChanged(
457458 if (isWifi && (mWifiLock != null )) stopWifiScanner ();
458459 } else {
459460 mMyWakeLock .reset (); // in case there's a leak
460- stopPortMappingMeasurement ();
461461 if (isWifi && (mWifiLock != null )) startWifiScanner ();
462462 }
463463 } catch (SipException e ) {
@@ -784,52 +784,50 @@ private class IntervalMeasurementProcess implements Runnable,
784784 private static final int PASS_THRESHOLD = 10 ;
785785 private static final int MAX_RETRY_COUNT = 5 ;
786786 private static final int NAT_MEASUREMENT_RETRY_INTERVAL = 120 ; // in seconds
787+ private SipProfile mLocalProfile ;
787788 private SipSessionGroupExt mGroup ;
788789 private SipSessionGroup .SipSessionImpl mSession ;
789790 private int mMinInterval ;
790791 private int mMaxInterval ;
791792 private int mInterval ;
792- private int mPassCount = 0 ;
793+ private int mPassCount ;
793794
794795 public IntervalMeasurementProcess (SipProfile localProfile ,
795796 int minInterval , int maxInterval ) {
796797 mMaxInterval = maxInterval ;
797798 mMinInterval = minInterval ;
798- mInterval = (maxInterval + minInterval ) / 2 ;
799-
800- // Don't start measurement if the interval is too small
801- if (mInterval < DEFAULT_KEEPALIVE_INTERVAL ) {
802- Log .w (TAG , "interval is too small; measurement aborted; "
803- + "maxInterval=" + mMaxInterval );
804- return ;
805- } else if (checkTermination ()) {
806- Log .w (TAG , "interval is too small; measurement aborted; "
807- + "interval=[" + mMinInterval + "," + mMaxInterval
808- + "]" );
809- return ;
810- }
811-
812- try {
813- mGroup = new SipSessionGroupExt (localProfile , null , null );
814- // TODO: remove this line once SipWakeupTimer can better handle
815- // variety of timeout values
816- mGroup .setWakeupTimer (new SipWakeupTimer (mContext , mExecutor ));
817- } catch (Exception e ) {
818- Log .w (TAG , "start interval measurement error: " + e );
819- }
799+ mLocalProfile = localProfile ;
820800 }
821801
822802 public void start () {
823803 synchronized (SipService .this ) {
824- Log .d (TAG , "start measurement w interval=" + mInterval );
825- if (mSession == null ) {
826- mSession = (SipSessionGroup .SipSessionImpl )
827- mGroup .createSession (null );
804+ if (mSession != null ) {
805+ return ;
828806 }
807+
808+ mInterval = (mMaxInterval + mMinInterval ) / 2 ;
809+ mPassCount = 0 ;
810+
811+ // Don't start measurement if the interval is too small
812+ if (mInterval < DEFAULT_KEEPALIVE_INTERVAL || checkTermination ()) {
813+ Log .w (TAG , "measurement aborted; interval=[" +
814+ mMinInterval + "," + mMaxInterval + "]" );
815+ return ;
816+ }
817+
829818 try {
819+ Log .d (TAG , "start measurement w interval=" + mInterval );
820+
821+ mGroup = new SipSessionGroupExt (mLocalProfile , null , null );
822+ // TODO: remove this line once SipWakeupTimer can better handle
823+ // variety of timeout values
824+ mGroup .setWakeupTimer (new SipWakeupTimer (mContext , mExecutor ));
825+
826+ mSession = (SipSessionGroup .SipSessionImpl )
827+ mGroup .createSession (null );
830828 mSession .startKeepAliveProcess (mInterval , this );
831- } catch (SipException e ) {
832- Log . e ( TAG , "start()" , e );
829+ } catch (Throwable t ) {
830+ onError ( SipErrorCode . CLIENT_ERROR , t . toString () );
833831 }
834832 }
835833 }
@@ -840,6 +838,10 @@ public void stop() {
840838 mSession .stopKeepAliveProcess ();
841839 mSession = null ;
842840 }
841+ if (mGroup != null ) {
842+ mGroup .close ();
843+ mGroup = null ;
844+ }
843845 mTimer .cancel (this );
844846 }
845847 }
0 commit comments