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

Commit 220fd520 authored by Ling Ma's avatar Ling Ma
Browse files

Send IA to modem when SIM switch or refresh

According to b 213517310#comment15, modem wants FWK to send IA again on
those 4 situations. Currently resend IA when SIM switch and refresh are not guaranteed
because in the current logic we only send IA if IA changes.

According to b 227579876, this change should be reverted for U, because
in U modem should only clear IA when FWK requests it to do so.

Test: atest + manual veirify
Fix: 235449106
Change-Id: Ie5c6b2aa8a220f656a70cba5a880cfe4dacf2721
parent 5d313954
Loading
Loading
Loading
Loading
+22 −10
Original line number Diff line number Diff line
@@ -75,6 +75,13 @@ public class DataProfileManager extends Handler {
    private final String mLogTag;
    private final LocalLog mLocalLog = new LocalLog(128);

    /**
     * Should only be used by update updateDataProfiles() to indicate whether resend IA to modem
     * regardless whether IA changed.
     **/
    private final boolean FORCED_UPDATE_IA = true;
    private final boolean ONLY_UPDATE_IA_IF_CHANGED = false;

    /** Data network controller. */
    private final @NonNull DataNetworkController mDataNetworkController;

@@ -176,11 +183,11 @@ public class DataProfileManager extends Handler {
        switch (msg.what) {
            case EVENT_SIM_REFRESH:
                log("Update data profiles due to SIM refresh.");
                updateDataProfiles();
                updateDataProfiles(FORCED_UPDATE_IA);
                break;
            case EVENT_APN_DATABASE_CHANGED:
                log("Update data profiles due to APN db updated.");
                updateDataProfiles();
                updateDataProfiles(ONLY_UPDATE_IA_IF_CHANGED);
                break;
            default:
                loge("Unexpected event " + msg);
@@ -193,7 +200,7 @@ public class DataProfileManager extends Handler {
     */
    private void onCarrierConfigUpdated() {
        log("Update data profiles due to carrier config updated.");
        updateDataProfiles();
        updateDataProfiles(FORCED_UPDATE_IA);

        //TODO: more works needed to be done here.
    }
@@ -231,8 +238,10 @@ public class DataProfileManager extends Handler {
    /**
     * Update all data profiles, including preferred data profile, and initial attach data profile.
     * Also send those profiles down to the modem if needed.
     *
     * @param forceUpdateIa If {@code true}, we should always send IA again to modem.
     */
    private void updateDataProfiles() {
    private void updateDataProfiles(boolean forceUpdateIa) {
        List<DataProfile> profiles = new ArrayList<>();
        if (mDataConfigManager.isConfigCarrierSpecific()) {
            Cursor cursor = mPhone.getContext().getContentResolver().query(
@@ -323,7 +332,7 @@ public class DataProfileManager extends Handler {
        }

        updateDataProfilesAtModem();
        updateInitialAttachDataProfileAtModem();
        updateInitialAttachDataProfileAtModem(forceUpdateIa);

        if (profilesChanged) {
            mDataProfileManagerCallbacks.forEach(callback -> callback.invokeFromExecutor(
@@ -381,7 +390,7 @@ public class DataProfileManager extends Handler {
                .orElse(null);
        // Save the preferred data profile into database.
        setPreferredDataProfile(dataProfile);
        updateDataProfiles();
        updateDataProfiles(ONLY_UPDATE_IA_IF_CHANGED);
    }

    /**
@@ -493,8 +502,10 @@ public class DataProfileManager extends Handler {
     * Some carriers might explicitly require that using "user-added" APN for initial
     * attach. In this case, exception can be configured through
     * {@link CarrierConfigManager#KEY_ALLOWED_INITIAL_ATTACH_APN_TYPES_STRING_ARRAY}.
     *
     * @param forceUpdateIa If {@code true}, we should always send IA again to modem.
     */
    private void updateInitialAttachDataProfileAtModem() {
    private void updateInitialAttachDataProfileAtModem(boolean forceUpdateIa) {
        DataProfile initialAttachDataProfile = null;

        // Sort the data profiles so the preferred data profile is at the beginning.
@@ -510,11 +521,12 @@ public class DataProfileManager extends Handler {
            if (initialAttachDataProfile != null) break;
        }

        if (!Objects.equals(mInitialAttachDataProfile, initialAttachDataProfile)) {
        if (forceUpdateIa || !Objects.equals(mInitialAttachDataProfile, initialAttachDataProfile)) {
            mInitialAttachDataProfile = initialAttachDataProfile;
            logl("Initial attach data profile updated as " + mInitialAttachDataProfile);
            logl("Initial attach data profile updated as " + mInitialAttachDataProfile
                    + " or forceUpdateIa= " + forceUpdateIa);
            // TODO: Push the null data profile to modem on new AIDL HAL. Modem should clear the IA
            //  APN.
            //  APN, tracking for U b/227579876, now using forceUpdateIa which always push to modem
            if (mInitialAttachDataProfile != null) {
                mWwanDataServiceManager.setInitialAttachApn(mInitialAttachDataProfile,
                        mPhone.getServiceState().getDataRoamingFromRegistration(), null);
+38 −0
Original line number Diff line number Diff line
@@ -639,6 +639,44 @@ public class DataProfileManagerTest extends TelephonyTest {
                .isEqualTo(GENERAL_PURPOSE_APN);
    }

    @Test
    public void testSetInitialAttachDataProfileMultipleRequests() throws Exception {
        // Test: Modem Cleared IA, should always send IA to modem
        // TODO(b/237444788): this case should be removed from U
        mDataProfileManagerUT.obtainMessage(3 /* EVENT_SIM_REFRESH */).sendToTarget();
        processAllMessages();

        Field IADPField = DataProfileManager.class.getDeclaredField("mInitialAttachDataProfile");
        IADPField.setAccessible(true);
        DataProfile dp = (DataProfile) IADPField.get(mDataProfileManagerUT);

        Mockito.clearInvocations(mMockedWwanDataServiceManager);
        mDataProfileManagerUT.obtainMessage(3 /* EVENT_SIM_REFRESH */).sendToTarget();
        processAllMessages();
        DataProfile dp2 = (DataProfile) IADPField.get(mDataProfileManagerUT);

        assertThat(Objects.equals(dp, dp2)).isTrue();
        verify(mMockedWwanDataServiceManager)
                .setInitialAttachApn(any(DataProfile.class), eq(false), eq(null));

        // Test: Modem did NOT clear IA, should not send IA to modem even if IA stays the same
        mDataProfileManagerUT.obtainMessage(2 /* EVENT_APN_DATABASE_CHANGED */).sendToTarget();
        processAllMessages();

        IADPField = DataProfileManager.class.getDeclaredField("mInitialAttachDataProfile");
        IADPField.setAccessible(true);
        dp = (DataProfile) IADPField.get(mDataProfileManagerUT);
        Mockito.clearInvocations(mMockedWwanDataServiceManager);

        mDataProfileManagerUT.obtainMessage(2 /* EVENT_APN_DATABASE_CHANGED */).sendToTarget();
        processAllMessages();
        dp2 = (DataProfile) IADPField.get(mDataProfileManagerUT);

        assertThat(Objects.equals(dp, dp2)).isTrue();
        verify(mMockedWwanDataServiceManager, Mockito.never())
                .setInitialAttachApn(any(DataProfile.class), eq(false), eq(null));
    }

    @Test
    public void testSimRemoval() {
        Mockito.clearInvocations(mDataProfileManagerCallback);