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

Commit 3a0be9e5 authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Support protocol override.

- Support override of protocol for D2D comms.
- Add extended logging so we can see what's up.

Test: Manual testing.
Bug: 163085177
Change-Id: I2cb838303d04fcff61d9079b36398581c33b5939
parent f82a6018
Loading
Loading
Loading
Loading
+26 −2
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.telecom.Log;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

/**
@@ -121,10 +122,11 @@ public class Communicator implements TransportProtocol.Callback {

    /**
     * Handles state changes for a call.
     * @param c The call in question.
     * @param id The call in question.
     * @param state The new state.
     */
    public void onStateChanged(Connection c, @Connection.ConnectionState int state) {
    public void onStateChanged(String id, @Connection.ConnectionState int state) {
        Log.i(this, "onStateChanged: id=%s, newState=%d", id, state);
        if (state == Connection.STATE_ACTIVE) {
            // Protocol negotiation can start as we are active
            if (mActiveTransport == null && !mIsNegotiationAttempted) {
@@ -291,4 +293,26 @@ public class Communicator implements TransportProtocol.Callback {
        }
        return "";
    }

    /**
     * Test method used to force a transport type to be the active transport.
     * @param transport The transport to activate.
     */
    public void setTransportActive(@NonNull String transport) {
        Optional<TransportProtocol> tp = mTransportProtocols.stream()
                .filter(t -> t.getClass().getSimpleName().equals(transport))
                .findFirst();
        if (!tp.isPresent()) {
            Log.w(this, "setTransportActive: %s is not a valid transport.");
            return;
        }

        mTransportProtocols.stream()
                .filter(p -> p != tp.get())
                .forEach(t -> t.forceNotNegotiated());
        tp.get().forceNegotiated();
        mActiveTransport = tp.get();
        mIsNegotiated = true;
        Log.i(this, "setTransportActive: %s has been forced active.", transport);
    }
}
+10 −0
Original line number Diff line number Diff line
@@ -611,4 +611,14 @@ public class DtmfTransport implements TransportProtocol {
            }
        }
    }

    @Override
    public void forceNegotiated() {

    }

    @Override
    public void forceNotNegotiated() {

    }
}
+28 −0
Original line number Diff line number Diff line
@@ -329,6 +329,11 @@ public class RtpTransport implements TransportProtocol, RtpAdapter.Callback {
                mRtpAdapter.getAcceptedRtpHeaderExtensions();
        mSupportedRtpHeaderExtensionTypes.addAll(acceptedExtensions);

        Log.i(this, "startNegotiation: supportedExtensions=%s", mSupportedRtpHeaderExtensionTypes
                .stream()
                .map(e -> e.toString())
                .collect(Collectors.joining(",")));

        boolean areExtensionsAvailable = acceptedExtensions.stream().anyMatch(
                e -> e.getUri().equals(DEVICE_STATE_RTP_HEADER_EXTENSION))
                && acceptedExtensions.stream().anyMatch(
@@ -358,9 +363,32 @@ public class RtpTransport implements TransportProtocol, RtpAdapter.Callback {
    public void sendMessages(Set<Communicator.Message> messages) {
        Set<RtpHeaderExtension> toSend = messages.stream().map(m -> generateRtpHeaderExtension(m))
                .collect(Collectors.toSet());
        Log.i(this, "sendMessages: sending=%s", messages);
        mRtpAdapter.sendRtpHeaderExtensions(toSend);
    }

    /**
     * Forces the protocol status to negotiated; for test purposes.
     */
    @Override
    public void forceNegotiated() {
        // If there is no supported RTP header extensions we need to fake it.
        if (mSupportedRtpHeaderExtensionTypes == null
                || mSupportedRtpHeaderExtensionTypes.isEmpty()) {
            mSupportedRtpHeaderExtensionTypes.add(DEVICE_STATE_RTP_HEADER_EXTENSION_TYPE);
            mSupportedRtpHeaderExtensionTypes.add(CALL_STATE_RTP_HEADER_EXTENSION_TYPE);
        }
        mProtocolStatus = PROTOCOL_STATUS_NEGOTIATION_COMPLETE;
    }

    /**
     * Forces the protocol status to un-negotiated; for test purposes.
     */
    @Override
    public void forceNotNegotiated() {
        mProtocolStatus = PROTOCOL_STATUS_NEGOTIATION_REQUIRED;
    }

    /**
     * Called by the platform when RTP header extensions are received and need to be translated to
     * concrete messages.
+1 −1
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ public final class Timeouts {
     * @return
     */
    public static long getDtmfNegotiationTimeoutMillis(ContentResolver cr) {
        return get(cr, "dtmf_negotiation_timeout_millis", 1000L);
        return get(cr, "dtmf_negotiation_timeout_millis", 3000L);
    }

    /**
+10 −0
Original line number Diff line number Diff line
@@ -70,4 +70,14 @@ public interface TransportProtocol {
     * @param messages the messages to send via the transport.
     */
    void sendMessages(Set<Communicator.Message> messages);

    /**
     * Forces this transport to be in a negotiated state.
     */
    void forceNegotiated();

    /**
     * Forces this transport to be in a non-negotiated state.
     */
    void forceNotNegotiated();
}
Loading