Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4a267a91 authored by Hung-ying Tyan's avatar Hung-ying Tyan
Browse files

Move the keepalive process to SipSessionImpl and make it reusable.

Reuse the new component in the original keepalive process and the NAT port
mapping timeout measurement process.

This is the foundation for fixing the following bug.

Bug: 3464181

Change-Id: If7e951c000503fa64843942ad062c4d853e20c8d
parent ac320b22
Loading
Loading
Loading
Loading
+32 −19
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ import javax.sip.message.Response;
class SipHelper {
    private static final String TAG = SipHelper.class.getSimpleName();
    private static final boolean DEBUG = true;
    private static final boolean DEBUG_PING = false;

    private SipStack mSipStack;
    private SipProvider mSipProvider;
@@ -177,17 +178,19 @@ class SipHelper {
        return uri;
    }

    public ClientTransaction sendKeepAlive(SipProfile userProfile, String tag)
            throws SipException {
    public ClientTransaction sendOptions(SipProfile caller, SipProfile callee,
            String tag) throws SipException {
        try {
            Request request = createRequest(Request.OPTIONS, userProfile, tag);
            Request request = (caller == callee)
                    ? createRequest(Request.OPTIONS, caller, tag)
                    : createRequest(Request.OPTIONS, caller, callee, tag);

            ClientTransaction clientTransaction =
                    mSipProvider.getNewClientTransaction(request);
            clientTransaction.sendRequest();
            return clientTransaction;
        } catch (Exception e) {
            throw new SipException("sendKeepAlive()", e);
            throw new SipException("sendOptions()", e);
        }
    }

@@ -249,23 +252,29 @@ class SipHelper {
        return ct;
    }

    public ClientTransaction sendInvite(SipProfile caller, SipProfile callee,
            String sessionDescription, String tag)
            throws SipException {
        try {
    private Request createRequest(String requestType, SipProfile caller,
            SipProfile callee, String tag) throws ParseException, SipException {
        FromHeader fromHeader = createFromHeader(caller, tag);
        ToHeader toHeader = createToHeader(callee);
        SipURI requestURI = callee.getUri();
        List<ViaHeader> viaHeaders = createViaHeaders();
        CallIdHeader callIdHeader = createCallIdHeader();
            CSeqHeader cSeqHeader = createCSeqHeader(Request.INVITE);
        CSeqHeader cSeqHeader = createCSeqHeader(requestType);
        MaxForwardsHeader maxForwards = createMaxForwardsHeader();

        Request request = mMessageFactory.createRequest(requestURI,
                    Request.INVITE, callIdHeader, cSeqHeader, fromHeader,
                requestType, callIdHeader, cSeqHeader, fromHeader,
                toHeader, viaHeaders, maxForwards);

        request.addHeader(createContactHeader(caller));
        return request;
    }

    public ClientTransaction sendInvite(SipProfile caller, SipProfile callee,
            String sessionDescription, String tag)
            throws SipException {
        try {
            Request request = createRequest(Request.INVITE, caller, callee, tag);
            request.setContent(sessionDescription,
                    mHeaderFactory.createContentTypeHeader(
                            "application", "sdp"));
@@ -419,9 +428,13 @@ class SipHelper {
    public void sendResponse(RequestEvent event, int responseCode)
            throws SipException {
        try {
            Request request = event.getRequest();
            Response response = mMessageFactory.createResponse(
                    responseCode, event.getRequest());
            if (DEBUG) Log.d(TAG, "send response: " + response);
                    responseCode, request);
            if (DEBUG && (!Request.OPTIONS.equals(request.getMethod())
                    || DEBUG_PING)) {
                Log.d(TAG, "send response: " + response);
            }
            getServerTransaction(event).sendResponse(response);
        } catch (ParseException e) {
            throw new SipException("sendResponse()", e);
+173 −161

File changed.

Preview size limit exceeded, changes collapsed.

+241 −97

File changed.

Preview size limit exceeded, changes collapsed.