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

Commit 2886ef41 authored by James.cf Lin's avatar James.cf Lin
Browse files

Fix the Framework should wait the publish request until the first publish...

Fix the Framework should wait the publish request until the first publish request is trigered by the Service

Bug: 179828995
Test: atest -c CtsTelephonyTestCases:android.telephony.ims.cts.ImsServiceTest
Change-Id: Ibb475f55a15731563a12fbaa695516d6cea85ca3
parent 172dbcd1
Loading
Loading
Loading
Loading
+33 −5
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ public class PublishControllerImpl implements PublishController {
    private PublishHandler mPublishHandler;
    private volatile boolean mIsDestroyedFlag;
    private volatile boolean mCapabilityPresenceEnabled;
    private volatile boolean mReceivePublishFromService;
    private volatile RcsFeatureManager mRcsFeatureManager;
    private final UceControllerCallback mUceCtrlCallback;

@@ -233,7 +234,7 @@ public class PublishControllerImpl implements PublishController {
        }
    }

    // Clear the publish state callback since the publish controller instance is destroyed.
    // Clear all the publish state callbacks since the publish controller instance is destroyed.
    private void clearPublishStateCallbacks() {
        synchronized (mPublishStateLock) {
            logd("clearPublishStateCallbacks");
@@ -262,6 +263,10 @@ public class PublishControllerImpl implements PublishController {
        return mDeviceCapabilityInfo.getDeviceCapabilities(mechanism, mContext);
    }

    /*
     * Register the availability callback to receive the RCS capabilities change. This method is
     * called when the RCS is connected.
     */
    private void registerRcsAvailabilityChanged(RcsFeatureManager manager) {
        try {
            manager.registerRcsAvailabilityCallback(mSubId, mRcsCapabilitiesCallback);
@@ -270,6 +275,10 @@ public class PublishControllerImpl implements PublishController {
        }
    }

    /*
     * Unregister the availability callback. This method is called when the PublishController
     * instance is destroyed.
     */
    private void unregisterRcsAvailabilityChanged() {
        RcsFeatureManager manager = mRcsFeatureManager;
        if (manager == null) return;
@@ -329,6 +338,7 @@ public class PublishControllerImpl implements PublishController {
    @Override
    public void requestPublishCapabilitiesFromService(int triggerType) {
        logi("Receive the publish request from service: service trigger type=" + triggerType);
        mReceivePublishFromService = true;
        mPublishHandler.requestPublish(PublishController.PUBLISH_TRIGGER_SERVICE);
    }

@@ -431,15 +441,16 @@ public class PublishControllerImpl implements PublishController {
                return;
            }
            if (publishCtrl.mIsDestroyedFlag) return;
            publishCtrl.logd("requestPublish: " + type + ", delay=" + delay);

            // Return if the RCS capabilities presence uce is not enabled.
            if (!publishCtrl.mCapabilityPresenceEnabled) {
                publishCtrl.logd("requestPublish: Skip. capability presence uce is not enabled.");
            // Check if the PUBLISH request is allowed.
            if (!publishCtrl.isPublishRequestAllowed()) {
                publishCtrl.logd("requestPublish: SKIP. The publish request is not allowed.");
                publishCtrl.mPublishProcessor.setPendingRequest(true);
                return;
            }

            publishCtrl.logd("requestPublish: " + type + ", delay=" + delay);

            // If the trigger type is not RETRY, it means that the device capabilities have been
            // changed. To make sure that the publish request can be processed immediately, remove
            // the existing one and send a new publish request without delayed.
@@ -523,6 +534,23 @@ public class PublishControllerImpl implements PublishController {
        }
    }

    /**
     * Check if the PUBLISH request is allowed.
     */
    private boolean isPublishRequestAllowed() {
        // The PUBLISH request requires that the RCS PRESENCE is capable.
        if (!mCapabilityPresenceEnabled) {
            logd("isPublishRequestAllowed: capability presence uce is not enabled.");
            return false;
        }
        // The first PUBLISH request is required to be triggered from the service.
        if (!mReceivePublishFromService) {
            logd("requestPublish: Have not received the first PUBLISH request from the service.");
            return false;
        }
        return true;
    }

    /**
     * Update the publish state and notify the publish state callback if the new state is different
     * from original state.
+66 −4
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static org.mockito.ArgumentMatchers.anyInt;
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.os.Handler;
@@ -157,9 +158,10 @@ public class PublishControllerImplTest extends ImsTestBase {

    @Test
    @SmallTest
    public void testRequestPublishFromService() throws Exception {
    public void testRequestPublishFromServiceWithoutRcsPresenceCapability() throws Exception {
        PublishControllerImpl publishController = createPublishController();

        // Trigger the PUBLISH request from the service
        publishController.requestPublishCapabilitiesFromService(
                RcsUceAdapter.CAPABILITY_UPDATE_TRIGGER_MOVE_TO_IWLAN);

@@ -172,6 +174,58 @@ public class PublishControllerImplTest extends ImsTestBase {
        verify(mPublishProcessor).checkAndSendPendingRequest();
    }

    @Test
    @SmallTest
    public void testRequestPublishFromServiceWithRcsCapability() throws Exception {
        PublishControllerImpl publishController = createPublishController();

        // Set the PRESENCE is capable
        IImsCapabilityCallback RcsCapCallback = publishController.getRcsCapabilitiesCallback();
        RcsCapCallback.onCapabilitiesStatusChanged(RcsUceAdapter.CAPABILITY_TYPE_PRESENCE_UCE);

        // Trigger the PUBLISH request from the service.
        publishController.requestPublishCapabilitiesFromService(
                RcsUceAdapter.CAPABILITY_UPDATE_TRIGGER_MOVE_TO_IWLAN);

        Handler handler = publishController.getPublishHandler();
        waitForHandlerAction(handler, 1000);
        verify(mPublishProcessor).doPublish(PublishController.PUBLISH_TRIGGER_SERVICE);
    }

    @Test
    @SmallTest
    public void testFirstRequestPublishIsTriggeredFromService() throws Exception {
        PublishControllerImpl publishController = createPublishController();

        // Set the PRESENCE is capable
        IImsCapabilityCallback RcsCapCallback = publishController.getRcsCapabilitiesCallback();
        RcsCapCallback.onCapabilitiesStatusChanged(RcsUceAdapter.CAPABILITY_TYPE_PRESENCE_UCE);

        // Trigger a publish request (VT changes)
        PublishControllerCallback callback = publishController.getPublishControllerCallback();
        callback.requestPublishFromInternal(PUBLISH_TRIGGER_VT_SETTING_CHANGE, 0);
        Handler handler = publishController.getPublishHandler();
        waitForHandlerAction(handler, 1000);

        // Verify it cannot be processed because the first request should triggred from service.
        verify(mPublishProcessor, never()).doPublish(PUBLISH_TRIGGER_VT_SETTING_CHANGE);

        // Trigger the PUBLISH request from the service.
        publishController.requestPublishCapabilitiesFromService(
                RcsUceAdapter.CAPABILITY_UPDATE_TRIGGER_MOVE_TO_IWLAN);
        waitForHandlerAction(handler, 1000);

        // Verify the request which is from the service can be processed
        verify(mPublishProcessor).doPublish(PublishController.PUBLISH_TRIGGER_SERVICE);

        // Trigger the third publish request (VT changes)
        callback.requestPublishFromInternal(PUBLISH_TRIGGER_VT_SETTING_CHANGE, 0);
        waitForHandlerAction(handler, 1000);

        // Verify the publish request can be processed this time.
        verify(mPublishProcessor).doPublish(PublishController.PUBLISH_TRIGGER_VT_SETTING_CHANGE);
    }

    @Test
    @SmallTest
    public void testRequestPublishWhenDeviceCapabilitiesChange() throws Exception {
@@ -181,13 +235,21 @@ public class PublishControllerImplTest extends ImsTestBase {
        IImsCapabilityCallback RcsCapCallback = publishController.getRcsCapabilitiesCallback();
        RcsCapCallback.onCapabilitiesStatusChanged(RcsUceAdapter.CAPABILITY_TYPE_PRESENCE_UCE);

        // Trigger the first publish (RETRY)
        // Trigger the PUBLISH request from the service.
        publishController.requestPublishCapabilitiesFromService(
                RcsUceAdapter.CAPABILITY_UPDATE_TRIGGER_MOVE_TO_IWLAN);
        Handler handler = publishController.getPublishHandler();
        waitForHandlerAction(handler, 1000);

        // Verify the request which is from the service can be processed
        verify(mPublishProcessor).doPublish(PublishController.PUBLISH_TRIGGER_SERVICE);

        // Trigger the sedond publish (RETRY), it should be processed after 10 seconds.
        PublishControllerCallback callback = publishController.getPublishControllerCallback();
        callback.requestPublishFromInternal(PUBLISH_TRIGGER_RETRY, 60000);
        callback.requestPublishFromInternal(PUBLISH_TRIGGER_RETRY, 10000);

        // Trigger another publish request (VT changes)
        callback.requestPublishFromInternal(PUBLISH_TRIGGER_VT_SETTING_CHANGE, 0);
        Handler handler = publishController.getPublishHandler();
        waitForHandlerAction(handler, 1000);

        // Verify the publish request can be processed immediately