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

Commit 2f6858bb authored by Tyler Gunn's avatar Tyler Gunn Committed by Radhika Agrawal
Browse files

Modify D2D comms to make use of carrier configs.

- ImsPhoneCallTracker now selectively performs SDP negotiation based on
the availability of RTP / SDP for the carrier.
- RtpTransport will count itself negotiated if SDP is not in use (we will
change that in the future to do a probe/response, but for now in testing
it is sufficient).

Test: Added unit tests for carrier config cases.
Bug: 163085177
Change-Id: I6bffea3e83961afe07523a6276470ace75a7c908
parent ba25db62
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * Responsible for facilitating device-to-device communication between both ends of a call.
@@ -107,6 +108,9 @@ public class Communicator implements TransportProtocol.Callback {

    public Communicator(@NonNull List<TransportProtocol> transportProtocols,
            @NonNull Callback callback) {
        Log.i(this, "Initializing communicator with transports: %s",
                transportProtocols.stream().map(p -> p.getClass().getSimpleName()).collect(
                        Collectors.joining(",")));
        mTransportProtocols.addAll(transportProtocols);
        mTransportProtocols.forEach(p -> p.setCallback(this));
        mCallback = callback;
@@ -315,4 +319,11 @@ public class Communicator implements TransportProtocol.Callback {
        mIsNegotiated = true;
        Log.i(this, "setTransportActive: %s has been forced active.", transport);
    }

    /**
     * @return the list of {@link TransportProtocol} which are configured at the current time.
     */
    public @NonNull List<TransportProtocol> getTransportProtocols() {
        return mTransportProtocols;
    }
}
+36 −15
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.NonNull;
import android.net.Uri;
import android.os.Handler;
import android.telecom.Log;
import android.telephony.ims.ImsCallProfile;
import android.telephony.ims.RtpHeaderExtension;
import android.telephony.ims.RtpHeaderExtensionType;
import android.util.ArraySet;
@@ -282,6 +283,15 @@ public class RtpTransport implements TransportProtocol, RtpAdapter.Callback {
     */
    private final Handler mHandler;

    /**
     * {@code true} if the carrier supports negotiating the RTP header extensions using SDP.
     * If {@code true}, we can expected the
     * {@link ImsCallProfile#getAcceptedRtpHeaderExtensionTypes()} to contain the SDP negotiated RTP
     * header extensions.  If {@code false} we will assume the protocol is negotiated only after
     * receiving an RTP header extension of the expected type.
     */
    private final boolean mIsSdpNegotiationSupported;

    /**
     * Protocol status.
     */
@@ -297,11 +307,14 @@ public class RtpTransport implements TransportProtocol, RtpAdapter.Callback {
     * @param rtpAdapter Adapter for abstract send/receive of RTP header extension data.
     * @param timeoutsAdapter Timeouts adapter for dealing with time based configurations.
     * @param handler Handler for posting future events.
     * @param isSdpNegotiationSupported Indicates whether SDP negotiation
     */
    public RtpTransport(RtpAdapter rtpAdapter, Timeouts.Adapter timeoutsAdapter, Handler handler) {
    public RtpTransport(RtpAdapter rtpAdapter, Timeouts.Adapter timeoutsAdapter, Handler handler,
            boolean isSdpNegotiationSupported) {
        mRtpAdapter = rtpAdapter;
        mTimeoutsAdapter = timeoutsAdapter;
        mHandler = handler;
        mIsSdpNegotiationSupported = isSdpNegotiationSupported;
    }

    /**
@@ -334,6 +347,7 @@ public class RtpTransport implements TransportProtocol, RtpAdapter.Callback {
                .map(e -> e.toString())
                .collect(Collectors.joining(",")));

        if (mIsSdpNegotiationSupported) {
            boolean areExtensionsAvailable = acceptedExtensions.stream().anyMatch(
                    e -> e.getUri().equals(DEVICE_STATE_RTP_HEADER_EXTENSION))
                    && acceptedExtensions.stream().anyMatch(
@@ -349,9 +363,16 @@ public class RtpTransport implements TransportProtocol, RtpAdapter.Callback {
                // Headers failed to be negotiated during SDP.   Assume protocol is not available.
                // TODO: Implement fallback logic where we still try an SDP probe/response.
                mProtocolStatus = PROTOCOL_STATUS_NEGOTIATION_FAILED;
            Log.i(this, "startNegotiation: header extensions not available; negotiation failed");
                Log.i(this,
                        "startNegotiation: header extensions not available; negotiation failed");
                notifyProtocolUnavailable();
            }
        } else {
            Log.i(this, "startNegotiation: SDP negotiation not supported; negotiation complete");
            // TODO: This is temporary; we will need to implement a probe/response in this scenario
            // if SDP is not supported.  For now we will just assume the protocol is ready.
            notifyProtocolReady();
        }
    }

    /**
+41 −10
Original line number Diff line number Diff line
@@ -535,6 +535,8 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
    private boolean mAlwaysPlayRemoteHoldTone = false;
    private boolean mAutoRetryFailedWifiEmergencyCall = false;
    private boolean mSupportCepOnPeer = true;
    private boolean mSupportD2DUsingRtp = false;
    private boolean mSupportSdpForRtpHeaderExtensions = false;
    // Tracks the state of our background/foreground calls while a call hold/swap operation is
    // in progress. Values listed above.
    private HoldSwapState mHoldSwitchingState = HoldSwapState.INACTIVE;
@@ -1026,22 +1028,39 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
                    null);
        }

        maybeConfigureRtpHeaderExtensions();

        if (mCarrierConfigLoaded) {
            mImsManager.updateImsServiceConfig();
        }
        // For compatibility with apps that still use deprecated intent
        sendImsServiceStateIntent(ImsManager.ACTION_IMS_SERVICE_UP);
    }

    /**
     * Configures RTP header extension types used during SDP negotiation.
     */
    private void maybeConfigureRtpHeaderExtensions() {
        // Where device to device communication is available, ensure that the
        // supported RTP header extension types defined in {@link RtpTransport} are
        // set as the offered RTP header extensions for this device.
        if (mConfig != null && mConfig.isD2DCommunicationSupported) {
        if (mConfig != null && mConfig.isD2DCommunicationSupported && mSupportD2DUsingRtp) {
            ArraySet<RtpHeaderExtensionType> types = new ArraySet<>();
            if (mSupportSdpForRtpHeaderExtensions) {
                types.add(RtpTransport.CALL_STATE_RTP_HEADER_EXTENSION_TYPE);
                types.add(RtpTransport.DEVICE_STATE_RTP_HEADER_EXTENSION_TYPE);
            logi("connectionReady: set offered RTP header extension types");
                logi("maybeConfigureRtpHeaderExtensions: set offered RTP header extension types");

            } else {
                logi("maybeConfigureRtpHeaderExtensions: SDP negotiation not supported; not "
                        + "setting offered RTP header extension types");
            }
            try {
                mImsManager.setOfferedRtpHeaderExtensionTypes(types);
            } catch (ImsException e) {
                loge("maybeConfigureRtpHeaderExtensions: failed to set extensions; " + e);
            }

        if (mCarrierConfigLoaded) {
            mImsManager.updateImsServiceConfig();
        }
        // For compatibility with apps that still use deprecated intent
        sendImsServiceStateIntent(ImsManager.ACTION_IMS_SERVICE_UP);
    }

    private void stopListeningForCalls() {
@@ -1436,6 +1455,8 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
        if (mImsManager != null) {
            mImsManager.updateImsServiceConfig();
        }
        // Check for changes due to carrier config.
        maybeConfigureRtpHeaderExtensions();
    }

    /**
@@ -1479,6 +1500,11 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
                CarrierConfigManager.KEY_AUTO_RETRY_FAILED_WIFI_EMERGENCY_CALL);
        mSupportCepOnPeer = carrierConfig.getBoolean(
                CarrierConfigManager.KEY_SUPPORT_IMS_CONFERENCE_EVENT_PACKAGE_ON_PEER_BOOL);
        mSupportD2DUsingRtp = carrierConfig.getBoolean(
                CarrierConfigManager.KEY_SUPPORTS_DEVICE_TO_DEVICE_COMMUNICATION_USING_RTP_BOOL);
        mSupportSdpForRtpHeaderExtensions = carrierConfig.getBoolean(
                CarrierConfigManager
                        .KEY_SUPPORTS_SDP_NEGOTIATION_OF_D2D_RTP_HEADER_EXTENSIONS_BOOL);

        if (mPhone.getContext().getResources().getBoolean(
                com.android.internal.R.bool.config_allow_ussd_over_ims)) {
@@ -4377,6 +4403,11 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
        pw.println(" mSupportCepOnPeer=" + mSupportCepOnPeer);
        if (mConfig != null) {
            pw.println(" isDeviceToDeviceCommsSupported= " + mConfig.isD2DCommunicationSupported);
            if (mConfig.isD2DCommunicationSupported) {
                pw.println(" mSupportD2DUsingRtp= " + mSupportD2DUsingRtp);
                pw.println(" mSupportSdpForRtpHeaderExtensions= "
                        + mSupportSdpForRtpHeaderExtensions);
            }
        }
        pw.println(" Event Log:");
        pw.increaseIndent();
+1 −2
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import static org.mockito.Mockito.when;

import android.os.Handler;
import android.telephony.ims.RtpHeaderExtension;
import android.telephony.ims.RtpHeaderExtensionType;
import android.test.suitebuilder.annotation.SmallTest;
import android.util.ArraySet;

@@ -84,7 +83,7 @@ public class RtpTransportConversionTest {
    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
        mRtpTransport = new RtpTransport(mRtpAdapter, mTimeoutsAdapter, mHandler);
        mRtpTransport = new RtpTransport(mRtpAdapter, mTimeoutsAdapter, mHandler, true /* sdp */);
        mRtpTransport.setCallback(mCallback);

        when(mRtpAdapter.getAcceptedRtpHeaderExtensions()).thenReturn(
+1 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ public class RtpTransportTest {
    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
        mRtpTransport = new RtpTransport(mRtpAdapter, mTimeoutsAdapter, mHandler);
        mRtpTransport = new RtpTransport(mRtpAdapter, mTimeoutsAdapter, mHandler, true /* sdp */);
        mRtpTransport.setCallback(mCallback);
    }

Loading