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

Commit 9715d77a authored by Hyosun Kim's avatar Hyosun Kim Committed by Android (Google) Code Review
Browse files

Merge "Ensure IMS configs are sent properly after IMS service crash" into tm-dev

parents 05e87420 df191ad1
Loading
Loading
Loading
Loading
+9 −10
Original line number Diff line number Diff line
@@ -193,9 +193,9 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
    // True if there is a carrier config loaded for a specific subscription (and not the default
    // configuration).
    private boolean mCarrierConfigLoadedForSubscription = false;
    // Cache a carrier config for a subscription that is still pending a connection to the
    // ImsService.
    private Pair<Integer, PersistableBundle> mPendingCarrierConfigForSubId = null;
    // Cache the latest carrier config received for a subscription. The configuration will be
    // applied to the ImsService when startListeningForCalls is called.
    private Pair<Integer, PersistableBundle> mCarrierConfigForSubId = null;
    // The subId of the last ImsService attached to this tracker or empty if there has not been
    // an attached ImsService yet.
    private Optional<Integer> mCurrentlyConnectedSubId = Optional.empty();
@@ -377,16 +377,14 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
                    return;
                }
                PersistableBundle carrierConfig = getCarrierConfigBundle(subId);
                mCarrierConfigForSubId = new Pair<>(subId, carrierConfig);
                if (!mCurrentlyConnectedSubId.isEmpty()
                        && subId == mCurrentlyConnectedSubId.get()) {
                    log("onReceive: Applying carrier config for subId: " + subId);
                    // Reset pending config state
                    mPendingCarrierConfigForSubId = null;
                    updateCarrierConfiguration(subId, carrierConfig);
                } else {
                    // cache the latest config update until ImsService connects for this subId.
                    // Once it has connected, startListeningForCalls will apply the pending config.
                    mPendingCarrierConfigForSubId = new Pair<>(subId, carrierConfig);
                    // Once it has connected, startListeningForCalls will apply the config.
                    log("onReceive: caching carrier config until ImsService connects for subId: "
                            + subId);
                }
@@ -1107,10 +1105,11 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
                    null);
        }

        if (mPendingCarrierConfigForSubId != null && mPendingCarrierConfigForSubId.first == subId) {
        if (mCarrierConfigForSubId != null && mCarrierConfigForSubId.first == subId) {
            // The carrier configuration was received by CarrierConfigManager before the indication
            // that the ImsService was connected.
            updateCarrierConfiguration(subId, mPendingCarrierConfigForSubId.second);
            // that the ImsService was connected or ImsService has restarted and we need to re-apply
            // the configuration.
            updateCarrierConfiguration(subId, mCarrierConfigForSubId.second);
        } else {
            log("startListeningForCalls - waiting for the first carrier config indication for this "
                    + "subscription");
+47 −0
Original line number Diff line number Diff line
@@ -431,6 +431,53 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest {
        verify(mImsManager).updateImsServiceConfig();
    }

    @Test
    @SmallTest
    public void testCarrierConfigSentAfterReadyAndCrash() throws Exception {
        verify(mImsManager, never()).updateImsServiceConfig();

        // Receive a subscription loaded and IMS connection ready indication.
        doReturn(true).when(mSubscriptionController).isActiveSubId(anyInt());
        mContextFixture.getCarrierConfigBundle().putBoolean(
                CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL, true);
        // CarrierConfigLoader has signalled that the carrier config has been applied for a specific
        // subscription. This will trigger unavailable -> ready indications.
        mConnectorListener.connectionUnavailable(FeatureConnector.UNAVAILABLE_REASON_DISCONNECTED);
        mConnectorListener.connectionReady(mImsManager, SUB_0);
        processAllMessages();
        // Did not receive carrier config changed yet
        verify(mImsManager, never()).updateImsServiceConfig();
        sendCarrierConfigChanged();
        processAllMessages();
        // ImsService crashes and reconnects
        mConnectorListener.connectionUnavailable(FeatureConnector.UNAVAILABLE_REASON_DISCONNECTED);
        mConnectorListener.connectionReady(mImsManager, SUB_0);
        processAllMessages();
        verify(mImsManager, times(2)).updateImsServiceConfig();
    }

    @Test
    @SmallTest
    public void testCarrierConfigSentBeforeReadyAndCrash() throws Exception {
        // move to ImsService unavailable state.
        mConnectorListener.connectionUnavailable(FeatureConnector.UNAVAILABLE_REASON_DISCONNECTED);
        doReturn(true).when(mSubscriptionController).isActiveSubId(anyInt());
        mContextFixture.getCarrierConfigBundle().putBoolean(
                CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL, true);

        sendCarrierConfigChanged();
        // No ImsService connected, so this will cache the config.
        verify(mImsManager, never()).updateImsServiceConfig();

        // Connect to ImsService and then simulate a crash recovery. We should make sure that the
        // configs are sent again after recovery.
        mConnectorListener.connectionReady(mImsManager, SUB_0);
        mConnectorListener.connectionUnavailable(FeatureConnector.UNAVAILABLE_REASON_DISCONNECTED);
        mConnectorListener.connectionReady(mImsManager, SUB_0);
        processAllMessages();
        verify(mImsManager, times(2)).updateImsServiceConfig();
    }

    @Test
    @SmallTest
    public void testImsMTCall() {