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

Commit 7d5884c9 authored by Ling Ma's avatar Ling Ma
Browse files

Add default IMS DP after sim loaded

Replace the check for adding default IMS DP to be the actual SIM state, so that even if user delete all DP from the SIM, we would still append a default IMS DP.

Fix: 282904697
Test: internet browsing + voice call
Change-Id: I7003732443ab0faeaaa5d8ffb0f929bff9646f90
Merged-In: I7003732443ab0faeaaa5d8ffb0f929bff9646f90
parent 65042c69
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -599,6 +599,13 @@ public class DataNetworkController extends Handler {
         * @param transport The transport of the data service.
         */
        public void onDataServiceBound(@TransportType int transport) {}

        /**
         * Called when SIM load state changed.
         *
         * @param simState The current SIM state
         */
        public void onSimStateChanged(@SimState int simState) {}
    }

    /**
@@ -2996,6 +3003,8 @@ public class DataNetworkController extends Handler {
                sendMessage(obtainMessage(EVENT_REEVALUATE_UNSATISFIED_NETWORK_REQUESTS,
                        DataEvaluationReason.SIM_LOADED));
            }
            mDataNetworkControllerCallbacks.forEach(callback -> callback.invokeFromExecutor(
                    () -> callback.onSimStateChanged(mSimState)));
        }
    }

+10 −1
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.telephony.AnomalyReporter;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager.SimState;
import android.telephony.data.ApnSetting;
import android.telephony.data.DataProfile;
import android.telephony.data.TrafficDescriptor;
@@ -116,6 +117,9 @@ public class DataProfileManager extends Handler {
    private final @NonNull Set<DataProfileManagerCallback> mDataProfileManagerCallbacks =
            new ArraySet<>();

    /** SIM state. */
    private @SimState int mSimState = TelephonyManager.SIM_STATE_UNKNOWN;

    /**
     * Data profile manager callback. This should be only used by {@link DataNetworkController}.
     */
@@ -170,6 +174,11 @@ public class DataProfileManager extends Handler {
                            @NonNull List<DataProfile> dataProfiles) {
                        DataProfileManager.this.onInternetDataNetworkConnected(dataProfiles);
                    }

                    @Override
                    public void onSimStateChanged(@SimState int simState) {
                        DataProfileManager.this.mSimState = simState;
                    }
                });
        mDataConfigManager.registerCallback(new DataConfigManagerCallback(this::post) {
            @Override
@@ -291,7 +300,7 @@ public class DataProfileManager extends Handler {

        DataProfile dataProfile;

        if (!profiles.isEmpty()) { // APN database has been read successfully after SIM loaded
        if (mSimState == TelephonyManager.SIM_STATE_LOADED) {
            // Check if any of the profile already supports IMS, if not, add the default one.
            dataProfile = profiles.stream()
                    .filter(dp -> dp.canSatisfy(NetworkCapabilities.NET_CAPABILITY_IMS))
+11 −6
Original line number Diff line number Diff line
@@ -838,7 +838,7 @@ public class DataProfileManagerTest extends TelephonyTest {
    @Test
    public void testSimRemoval() {
        Mockito.clearInvocations(mDataProfileManagerCallback);
        mSimInserted = false;
        changeSimStateTo(TelephonyManager.SIM_STATE_ABSENT);
        mDataProfileManagerUT.obtainMessage(2 /*EVENT_APN_DATABASE_CHANGED*/).sendToTarget();
        processAllMessages();

@@ -880,7 +880,7 @@ public class DataProfileManagerTest extends TelephonyTest {
        doReturn(List.of(ApnSetting.TYPE_IMS))
                .when(mDataConfigManager).getAllowedInitialAttachApnTypes();

        mSimInserted = true;
        changeSimStateTo(TelephonyManager.SIM_STATE_LOADED);
        mDataProfileManagerUT.obtainMessage(2 /*EVENT_APN_DATABASE_CHANGED*/).sendToTarget();
        processAllMessages();

@@ -1053,7 +1053,7 @@ public class DataProfileManagerTest extends TelephonyTest {

    @Test
    public void testResetApn() {
        mSimInserted = true;
        changeSimStateTo(TelephonyManager.SIM_STATE_LOADED);
        mDataProfileManagerUT.obtainMessage(2 /*EVENT_APN_DATABASE_CHANGED*/).sendToTarget();
        processAllMessages();

@@ -1125,7 +1125,7 @@ public class DataProfileManagerTest extends TelephonyTest {
                new NetworkRequest.Builder()
                        .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
                        .build(), mPhone);
        mSimInserted = true;
        changeSimStateTo(TelephonyManager.SIM_STATE_LOADED);
        mDataProfileManagerUT.obtainMessage(2 /*EVENT_APN_DATABASE_CHANGED*/).sendToTarget();
        processAllMessages();

@@ -1236,7 +1236,7 @@ public class DataProfileManagerTest extends TelephonyTest {
    @Test
    public void testDataProfileCompatibility_FilteringWithPreferredApnSetIdAsDefault() {
        mApnSettingContentProvider.setPreferredApn(GENERAL_PURPOSE_APN);
        mSimInserted = true;
        changeSimStateTo(TelephonyManager.SIM_STATE_LOADED);
        mDataProfileManagerUT.obtainMessage(2 /*EVENT_APN_DATABASE_CHANGED*/).sendToTarget();
        processAllMessages();

@@ -1327,7 +1327,7 @@ public class DataProfileManagerTest extends TelephonyTest {
    @Test
    public void testDataProfileCompatibility_FilteringWithPreferredApnSetIdAs1() {
        mApnSettingContentProvider.setPreferredApn(APN_SET_ID_1_APN);
        mSimInserted = true;
        changeSimStateTo(TelephonyManager.SIM_STATE_LOADED);
        mDataProfileManagerUT.obtainMessage(2 /*EVENT_APN_DATABASE_CHANGED*/).sendToTarget();
        processAllMessages();

@@ -1457,4 +1457,9 @@ public class DataProfileManagerTest extends TelephonyTest {
        assertThat(mDataProfileManagerUT.getDataProfileForNetworkRequest(tnr,
                TelephonyManager.NETWORK_TYPE_LTE, false)).isNull();
    }

    private void changeSimStateTo(@TelephonyManager.SimState int simState) {
        mSimInserted = simState == TelephonyManager.SIM_STATE_LOADED;
        mDataNetworkControllerCallback.onSimStateChanged(simState);
    }
}