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

Commit 79637da5 authored by James.cf Lin's avatar James.cf Lin Committed by Automerger Merge Worker
Browse files

[UCE] Do not block indefinitely if the framework never receive a final result...

[UCE] Do not block indefinitely if the framework never receive a final result for capabilities request am: 8892764c

Original change: https://android-review.googlesource.com/c/platform/frameworks/opt/net/ims/+/1719882

Change-Id: I779b2cae9e6359bb334bfd96a1969ee338d0d114
parents 50ea930a 8892764c
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -731,6 +731,16 @@ public class UceController {
        mDeviceState.resetDeviceState();
    }

    /**
     * Set the milliseconds of capabilities request timeout.
     * <p>
     * Used for testing ONLY.
     */
    public void setCapabilitiesRequestTimeout(long timeoutAfterMs) {
        logd("setCapabilitiesRequestTimeout: " + timeoutAfterMs);
        UceUtils.setCapRequestTimeoutAfterMillis(timeoutAfterMs);
    }

    /**
     * Get the subscription ID.
     */
+14 −4
Original line number Diff line number Diff line
@@ -89,6 +89,8 @@ public abstract class CapabilityRequest implements UceRequest {
    @Override
    public void onFinish() {
        mIsFinished = true;
        // Remove the timeout timer of this request
        mRequestManagerCallback.removeRequestTimeoutTimer(mTaskId);
    }

    @Override
@@ -215,16 +217,24 @@ public abstract class CapabilityRequest implements UceRequest {

    /**
     * Get the contact uris which cannot retrieve capabilities from the cache.
     * @param cachedCapabilityList The capabilities which are already stored in the cache.
     * @param cachedCapList The capabilities which are already stored in the cache.
     */
    private List<Uri> getRequestingFromNetworkUris(
            List<RcsContactUceCapability> cachedCapabilityList) {
    private List<Uri> getRequestingFromNetworkUris(List<RcsContactUceCapability> cachedCapList) {
        return mUriList.stream()
                .filter(uri -> cachedCapabilityList.stream()
                .filter(uri -> cachedCapList.stream()
                        .noneMatch(cap -> cap.getContactUri().equals(uri)))
                        .collect(Collectors.toList());
    }

    /**
     * Set the timeout timer of this request.
     */
    protected void setupRequestTimeoutTimer() {
        long timeoutAfterMs = UceUtils.getCapRequestTimeoutAfterMillis();
        logd("setupRequestTimeoutTimer(ms): " + timeoutAfterMs);
        mRequestManagerCallback.setRequestTimeoutTimer(mCoordinatorId, mTaskId, timeoutAfterMs);
    }

    /*
     * Requests capabilities from IMS. The inherited request is required to override this method
     * to define the behavior of requesting capabilities.
+5 −0
Original line number Diff line number Diff line
@@ -105,7 +105,10 @@ public class OptionsRequest extends CapabilityRequest {

        logi("requestCapabilities: featureTag size=" + featureTags.size());
        try {
            // Send the capabilities request.
            optionsController.sendCapabilitiesRequest(mContactUri, featureTags, mResponseCallback);
            // Setup the timeout timer.
            setupRequestTimeoutTimer();
        } catch (RemoteException e) {
            logw("requestCapabilities exception: " + e);
            mRequestResponse.setRequestInternalError(RcsUceAdapter.ERROR_GENERIC_FAILURE);
@@ -117,6 +120,7 @@ public class OptionsRequest extends CapabilityRequest {
    private void onCommandError(@CommandCode int cmdError) {
        logd("onCommandError: error code=" + cmdError);
        if (mIsFinished) {
            logw("onCommandError: The request is already finished");
            return;
        }
        mRequestResponse.setCommandError(cmdError);
@@ -128,6 +132,7 @@ public class OptionsRequest extends CapabilityRequest {
        logd("onNetworkResponse: sipCode=" + sipCode + ", reason=" + reason
                + ", remoteCap size=" + ((remoteCaps == null) ? "null" : remoteCaps.size()));
        if (mIsFinished) {
            logw("onNetworkResponse: The request is already finished");
            return;
        }

+27 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.telephony.ims.stub.RcsCapabilityExchangeImplBase.COMMAND_C

import android.os.RemoteException;
import android.telephony.ims.RcsContactUceCapability;
import android.telephony.ims.RcsUceAdapter;
import android.telephony.ims.aidl.IRcsUceControllerCallback;

import com.android.ims.rcs.uce.request.UceRequestManager.RequestManagerCallback;
@@ -96,6 +97,11 @@ public class OptionsRequestCoordinator extends UceRequestCoordinator {
    private static final RequestResultCreator sNotNeedRequestFromNetworkCreator =
            (taskId, response) -> RequestResult.createSuccessResult(taskId);

    // The RequestResult creator of the request timeout.
    private static final RequestResultCreator sRequestTimeoutCreator =
            (taskId, response) -> RequestResult.createFailedResult(taskId,
                    RcsUceAdapter.ERROR_REQUEST_TIMEOUT, 0L);

    // The callback to notify the result of the capabilities request.
    private IRcsUceControllerCallback mCapabilitiesCallback;

@@ -144,6 +150,9 @@ public class OptionsRequestCoordinator extends UceRequestCoordinator {
            case REQUEST_UPDATE_NO_NEED_REQUEST_FROM_NETWORK:
                handleNoNeedRequestFromNetwork(request);
                break;
            case REQUEST_UPDATE_TIMEOUT:
                handleRequestTimeout(request);
                break;
            default:
                logw("onRequestUpdated(OptionsRequest): invalid event " + event);
                break;
@@ -247,6 +256,24 @@ public class OptionsRequestCoordinator extends UceRequestCoordinator {
        moveRequestToFinishedCollection(taskId, requestResult);
    }

    /**
     * This method is called when the framework does not receive receive the result for
     * capabilities request.
     */
    private void handleRequestTimeout(OptionsRequest request) {
        CapabilityRequestResponse response = request.getRequestResponse();
        logd("handleRequestTimeout: " + response.toString());

        // Finish this request.
        request.onFinish();

        // Remove this request from the activated collection and notify RequestManager.
        long taskId = request.getTaskId();
        RequestResult requestResult = sRequestTimeoutCreator.createRequestResult(taskId,
                response);
        moveRequestToFinishedCollection(taskId, requestResult);
    }

    /**
     * Trigger the capabilities updated callback.
     */
+6 −0
Original line number Diff line number Diff line
@@ -143,17 +143,23 @@ public class RemoteOptionsCoordinator extends UceRequestCoordinator {
    private void triggerOptionsReqCallback(RcsContactUceCapability deviceCaps,
            boolean isRemoteNumberBlocked) {
        try {
            logd("triggerOptionsReqCallback: start");
            mOptionsReqCallback.respondToCapabilityRequest(deviceCaps, isRemoteNumberBlocked);
        } catch (RemoteException e) {
            logw("triggerOptionsReqCallback exception: " + e);
        } finally {
            logd("triggerOptionsReqCallback: done");
        }
    }

    private void triggerOptionsReqWithErrorCallback(int errorCode, String reason) {
        try {
            logd("triggerOptionsReqWithErrorCallback: start");
            mOptionsReqCallback.respondToCapabilityRequestWithError(errorCode, reason);
        } catch (RemoteException e) {
            logw("triggerOptionsReqWithErrorCallback exception: " + e);
        } finally {
            logd("triggerOptionsReqWithErrorCallback: done");
        }
    }

Loading