Esempio n. 1
0
    public void setListener(ISipSessionListener listener) {
      synchronized (SipService.this) {
        mProxy.setListener(listener);

        try {
          int state = (mSession == null) ? SipSession.State.READY_TO_CALL : mSession.getState();
          if ((state == SipSession.State.REGISTERING)
              || (state == SipSession.State.DEREGISTERING)) {
            mProxy.onRegistering(mSession);
          } else if (mRegistered) {
            int duration = (int) (mExpiryTime - SystemClock.elapsedRealtime());
            mProxy.onRegistrationDone(mSession, duration);
          } else if (mErrorCode != SipErrorCode.NO_ERROR) {
            if (mErrorCode == SipErrorCode.TIME_OUT) {
              mProxy.onRegistrationTimeout(mSession);
            } else {
              mProxy.onRegistrationFailed(mSession, mErrorCode, mErrorMessage);
            }
          } else if (!mConnected) {
            mProxy.onRegistrationFailed(
                mSession, SipErrorCode.DATA_CONNECTION_LOST, "no data connection");
          } else if (!mRunning) {
            mProxy.onRegistrationFailed(
                mSession, SipErrorCode.CLIENT_ERROR, "registration not running");
          } else {
            mProxy.onRegistrationFailed(mSession, SipErrorCode.IN_PROGRESS, String.valueOf(state));
          }
        } catch (Throwable t) {
          Log.w(TAG, "setListener(): " + t);
        }
      }
    }
Esempio n. 2
0
    @Override
    public void onRegistrationFailed(ISipSession session, int errorCode, String message) {
      if (DEBUG)
        Log.d(
            TAG,
            "onRegistrationFailed(): "
                + session
                + ": "
                + SipErrorCode.toString(errorCode)
                + ": "
                + message);
      synchronized (SipService.this) {
        if (notCurrentSession(session)) return;

        switch (errorCode) {
          case SipErrorCode.INVALID_CREDENTIALS:
          case SipErrorCode.SERVER_UNREACHABLE:
            if (DEBUG) Log.d(TAG, "   pause auto-registration");
            stop();
            break;
          default:
            restartLater();
        }

        mErrorCode = errorCode;
        mErrorMessage = message;
        mProxy.onRegistrationFailed(session, errorCode, message);
        mMyWakeLock.release(session);
      }
    }
Esempio n. 3
0
    @Override
    public void onRegistrationDone(ISipSession session, int duration) {
      if (DEBUG) Log.d(TAG, "onRegistrationDone(): " + session);
      synchronized (SipService.this) {
        if (notCurrentSession(session)) return;

        mProxy.onRegistrationDone(session, duration);

        if (duration > 0) {
          mExpiryTime = SystemClock.elapsedRealtime() + (duration * 1000);

          if (!mRegistered) {
            mRegistered = true;
            // allow some overlap to avoid call drop during renew
            duration -= MIN_EXPIRY_TIME;
            if (duration < MIN_EXPIRY_TIME) {
              duration = MIN_EXPIRY_TIME;
            }
            restart(duration);

            SipProfile localProfile = mSession.getLocalProfile();
            if ((mKeepAliveSession == null)
                && (isBehindNAT(mLocalIp) || localProfile.getSendKeepAlive())) {
              startKeepAliveProcess(getKeepAliveInterval());
            }
          }
          mMyWakeLock.release(session);
        } else {
          mRegistered = false;
          mExpiryTime = -1L;
          if (DEBUG) Log.d(TAG, "Refresh registration immediately");
          run();
        }
      }
    }
Esempio n. 4
0
    @Override
    public void onRegistering(ISipSession session) {
      if (DEBUG) Log.d(TAG, "onRegistering(): " + session);
      synchronized (SipService.this) {
        if (notCurrentSession(session)) return;

        mRegistered = false;
        mProxy.onRegistering(session);
      }
    }
Esempio n. 5
0
    @Override
    public void onRegistrationTimeout(ISipSession session) {
      if (DEBUG) Log.d(TAG, "onRegistrationTimeout(): " + session);
      synchronized (SipService.this) {
        if (notCurrentSession(session)) return;

        mErrorCode = SipErrorCode.TIME_OUT;
        mProxy.onRegistrationTimeout(session);
        restartLater();
        mMyWakeLock.release(session);
      }
    }
Esempio n. 6
0
    public void stop() {
      if (!mRunning) return;
      mRunning = false;
      mMyWakeLock.release(mSession);
      if (mSession != null) {
        mSession.setListener(null);
        if (mConnected && mRegistered) mSession.unregister();
      }

      mTimer.cancel(this);
      stopKeepAliveProcess();

      mRegistered = false;
      setListener(mProxy.getListener());
    }