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

Commit 2e709f74 authored by Jack Yu's avatar Jack Yu Committed by Automerger Merge Worker
Browse files

Merge "Fixed IA APN was not set when SIM is re-inserted" am: 34d7b5dc

Original change: https://android-review.googlesource.com/c/platform/frameworks/opt/telephony/+/2032671

Change-Id: If8a4aa7205cbe7fa8ebdc9099ad696ae329d461e
parents 7652c4c3 34d7b5dc
Loading
Loading
Loading
Loading
+6 −9
Original line number Diff line number Diff line
@@ -445,20 +445,17 @@ public class DataProfileManager extends Handler {
                    .orElse(null);
        }

        if (initialAttachDataProfile == null) {
            loge("Cannot find initial attach data profile. APN database needs to be configured"
                    + " correctly.");
            // return here as we can't push a null data profile to the modem as initial attach APN.
            return;
        }

        if (!Objects.equals(mInitialAttachDataProfile, initialAttachDataProfile)) {
            mInitialAttachDataProfile = initialAttachDataProfile;
            logl("Initial attach data profile updated as " + mInitialAttachDataProfile);
            // TODO: Push the null data profile to modem on new AIDL HAL. Modem should clear the IA
            //  APN.
            if (mInitialAttachDataProfile != null) {
                mWwanDataServiceManager.setInitialAttachApn(mInitialAttachDataProfile,
                        mPhone.getServiceState().getDataRoamingFromRegistration(), null);
            }
        }
    }

    /**
     * Update the data profiles at modem.
+69 −6
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
@@ -51,6 +52,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;

import java.util.Arrays;
import java.util.List;
@@ -77,6 +79,8 @@ public class DataProfileManagerTest extends TelephonyTest {

    private DataNetworkControllerCallback mDataNetworkControllerCallback;

    private boolean mSimInserted = true;

    private class ApnSettingContentProvider extends MockContentProvider {
        public final String[] APN_COLUMNS = new String[]{
                Telephony.Carriers._ID, Telephony.Carriers.NUMERIC,
@@ -125,7 +129,7 @@ public class DataProfileManagerTest extends TelephonyTest {
                    "",                     // user
                    "",                     // password
                    -1,                     // authtype
                    "default,supl,mms",     // types
                    "default,supl,mms,ia",  // types
                    "IPV4V6",               // protocol
                    "IPV4V6",               // roaming_protocol
                    1,                      // carrier_enabled
@@ -281,11 +285,12 @@ public class DataProfileManagerTest extends TelephonyTest {

                    logd("Query '" + PLMN + "' APN settings");
                    MatrixCursor mc = new MatrixCursor(APN_COLUMNS);
                    if (mSimInserted) {
                        mc.addRow(getFakeApn1());
                        mc.addRow(getFakeApn2());
                        mc.addRow(getFakeApn3());
                        mc.addRow(getFakeApn4());

                    }
                    return mc;
                }
            } else if (isPathPrefixMatch(uri,
@@ -520,4 +525,62 @@ public class DataProfileManagerTest extends TelephonyTest {
        // The small timestamp profile should be returned.
        assertThat(mPreferredApnId).isEqualTo(dp2.getApnSetting().getId());
    }

    @Test
    public void testSetInitialAttachDataProfile() {
        verify(mMockedWwanDataServiceManager).setInitialAttachApn(any(DataProfile.class),
                eq(false), eq(null));

        List<DataProfile> dataProfiles = mDataProfileManagerUT
                .getDataProfilesForNetworkCapabilities(
                        new int[]{NetworkCapabilities.NET_CAPABILITY_IA});
        assertThat(dataProfiles).hasSize(1);
        assertThat(dataProfiles.get(0).getApnSetting().getApnName()).isEqualTo(GENERAL_PURPOSE_APN);
    }

    @Test
    public void testSimRemoval() throws Exception {
        testGetDataProfileForNetworkCapabilities();
        Mockito.clearInvocations(mDataProfileManagerCallback);
        mSimInserted = false;
        mDataProfileManagerUT.obtainMessage(2 /*EVENT_APN_DATABASE_CHANGED*/).sendToTarget();
        processAllMessages();

        verify(mDataProfileManagerCallback).onDataProfilesChanged();

        List<DataProfile> dataProfiles = mDataProfileManagerUT
                .getDataProfilesForNetworkCapabilities(
                        new int[]{NetworkCapabilities.NET_CAPABILITY_INTERNET});
        assertThat(dataProfiles).isEmpty();

        dataProfiles = mDataProfileManagerUT.getDataProfilesForNetworkCapabilities(
                        new int[]{NetworkCapabilities.NET_CAPABILITY_EIMS});
        assertThat(dataProfiles).hasSize(1);
        assertThat(dataProfiles.get(0).getApnSetting().getApnName()).isEqualTo("sos");

        dataProfiles = mDataProfileManagerUT.getDataProfilesForNetworkCapabilities(
                new int[]{NetworkCapabilities.NET_CAPABILITY_IMS});
        assertThat(dataProfiles).hasSize(1);
        assertThat(dataProfiles.get(0).getApnSetting().getApnName()).isEqualTo("ims");
    }

    @Test
    public void testSimInsertedAgain() throws Exception {
        testSimRemoval();
        Mockito.clearInvocations(mDataProfileManagerCallback);
        Mockito.clearInvocations(mMockedWwanDataServiceManager);
        mSimInserted = true;
        mDataProfileManagerUT.obtainMessage(2 /*EVENT_APN_DATABASE_CHANGED*/).sendToTarget();
        processAllMessages();

        verify(mDataProfileManagerCallback).onDataProfilesChanged();
        verify(mMockedWwanDataServiceManager).setInitialAttachApn(any(DataProfile.class),
                eq(false), eq(null));

        List<DataProfile> dataProfiles = mDataProfileManagerUT
                .getDataProfilesForNetworkCapabilities(
                        new int[]{NetworkCapabilities.NET_CAPABILITY_IMS});
        assertThat(dataProfiles).hasSize(1);
        assertThat(dataProfiles.get(0).getApnSetting().getApnName()).isEqualTo(IMS_APN);
    }
}