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

Commit 172dbcd1 authored by James.cf Lin's avatar James.cf Lin
Browse files

Fix the subscribe request failed even the network response is 202 Accepted

When the framework receives the network response callback with the sip code 202 Accepted, it should treat it as success.

Bug: 179943973
Test: atest ImsServiceTest RcsUceAdapterTest
Change-Id: Iefee7533d188dcc9b8c642cc6baf056af320ebca
parent fb403b00
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -172,13 +172,15 @@ public class CapabilityRequestResponse {
    }

    /**
     * Check if the network response is OK.
     * @return true if the network response code is OK and the Reason header cause
     * Check if the network response is success.
     * @return true if the network response code is OK or Accepted and the Reason header cause
     * is either not present or OK.
     */
    public boolean isNetworkResponseOK() {
        final int sipCodeOk = NetworkSipCode.SIP_CODE_OK;
        if (getNetworkRespSipCode().filter(c -> c == sipCodeOk).isPresent() &&
        final int sipCodeAccepted = NetworkSipCode.SIP_CODE_ACCEPTED;
        Optional<Integer> respSipCode = getNetworkRespSipCode();
        if (respSipCode.filter(c -> (c == sipCodeOk || c == sipCodeAccepted)).isPresent() &&
                (!getReasonHeaderCause().isPresent()
                        || getReasonHeaderCause().filter(c -> c == sipCodeOk).isPresent())) {
            return true;
+2 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ package com.android.ims.rcs.uce.util;
 */
public class NetworkSipCode {
    public static final int SIP_CODE_OK = 200;
    public static final int SIP_CODE_ACCEPTED = 202;
    public static final int SIP_CODE_BAD_REQUEST = 400;
    public static final int SIP_CODE_FORBIDDEN = 403;
    public static final int SIP_CODE_NOT_FOUND = 404;
@@ -36,6 +37,7 @@ public class NetworkSipCode {
    public static final int SIP_CODE_DOES_NOT_EXIST_ANYWHERE = 604;

    public static final String SIP_OK = "OK";
    public static final String SIP_ACCEPTED = "Accepted";
    public static final String SIP_BAD_REQUEST = "Bad Request";
    public static final String SIP_SERVICE_UNAVAILABLE = "Service Unavailable";
    public static final String SIP_INTERNAL_SERVER_ERROR = "Internal Server Error";
+12 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import android.net.Uri;
@@ -142,6 +143,7 @@ public class OptionsRequestTest extends ImsTestBase {
        doReturn(true).when(mRequestResponse).isNetworkResponseOK();
        IOptionsResponseCallback callback = request.getResponseCallback();

        // Respond the SIP CODE 200 OK
        callback.onNetworkResponse(NetworkSipCode.SIP_CODE_OK, NetworkSipCode.SIP_OK, mFeatureTags);

        verify(mRequestResponse).setNetworkResponseCode(NetworkSipCode.SIP_CODE_OK,
@@ -149,6 +151,16 @@ public class OptionsRequestTest extends ImsTestBase {
        verify(mRequestResponse).setRemoteCapabilities(any(), eq(mFeatureTags));
        verify(mRequestResponse, never()).setErrorCode(RcsUceAdapter.ERROR_FORBIDDEN);
        verify(mRequestManagerCallback, never()).onRequestFailed(anyLong());

        // Respond the SIP CODE 202 ACCEPTED
        callback.onNetworkResponse(NetworkSipCode.SIP_CODE_ACCEPTED, NetworkSipCode.SIP_ACCEPTED,
                mFeatureTags);

        verify(mRequestResponse).setNetworkResponseCode(NetworkSipCode.SIP_CODE_ACCEPTED,
                NetworkSipCode.SIP_ACCEPTED);
        verify(mRequestResponse, times(2)).setRemoteCapabilities(any(), eq(mFeatureTags));
        verify(mRequestResponse, never()).setErrorCode(RcsUceAdapter.ERROR_FORBIDDEN);
        verify(mRequestManagerCallback, never()).onRequestFailed(anyLong());
    }

    @Test
+17 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import android.net.Uri;
@@ -111,12 +112,21 @@ public class SubscribeRequestTest extends ImsTestBase {
        doReturn(true).when(mRequestResponse).isNetworkResponseOK();
        ISubscribeResponseCallback callback = subscribeRequest.getResponseCallback();

        // Respond the SIP CODE 200 OK
        callback.onNetworkResponse(NetworkSipCode.SIP_CODE_OK, NetworkSipCode.SIP_OK);

        verify(mRequestResponse).setNetworkResponseCode(NetworkSipCode.SIP_CODE_OK,
                NetworkSipCode.SIP_OK);
        verify(mRequestResponse, never()).setErrorCode(RcsUceAdapter.ERROR_FORBIDDEN);
        verify(mRequestManagerCallback, never()).onRequestFailed(anyLong());

        // Respond the SIP CODE 202 ACCEPTED
        callback.onNetworkResponse(NetworkSipCode.SIP_CODE_ACCEPTED, NetworkSipCode.SIP_ACCEPTED);

        verify(mRequestResponse).setNetworkResponseCode(NetworkSipCode.SIP_CODE_ACCEPTED,
                NetworkSipCode.SIP_ACCEPTED);
        verify(mRequestResponse, never()).setErrorCode(RcsUceAdapter.ERROR_FORBIDDEN);
        verify(mRequestManagerCallback, never()).onRequestFailed(anyLong());
    }

    @Test
@@ -170,10 +180,17 @@ public class SubscribeRequestTest extends ImsTestBase {
        doReturn(true).when(mRequestResponse).isNetworkResponseOK();
        ISubscribeResponseCallback callback = subscribeRequest.getResponseCallback();

        // Respond SIP CODE 200 OK
        callback.onNetworkResponse(NetworkSipCode.SIP_CODE_OK, NetworkSipCode.SIP_OK);
        callback.onTerminated(null, 0L);

        verify(mRequestManagerCallback).onRequestSuccess(anyLong());

        // Respond SIP CODE 202 ACCEPTED
        callback.onNetworkResponse(NetworkSipCode.SIP_CODE_ACCEPTED, NetworkSipCode.SIP_ACCEPTED);
        callback.onTerminated(null, 0L);

        verify(mRequestManagerCallback, times(2)).onRequestSuccess(anyLong());
    }

    @Test