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

Commit 65cbbaae authored by Steve Statia's avatar Steve Statia
Browse files

Added logic to use the Service Provider Name and an device overlay config to...

Added logic to use the Service Provider Name and an device overlay config to check if the network is non-terrestrial

Test: manual testing with adb device_config command, hardcoded overlay values, and atest SubscriptionManagerServiceTest

Bug: 318783678
Change-Id: If91039550d1ec8bc86348e48e82806c365439fff
parent 51a2da4b
Loading
Loading
Loading
Loading
+45 −8
Original line number Diff line number Diff line
@@ -1170,6 +1170,17 @@ public class SubscriptionManagerService extends ISub.Stub {
                        builder.setDisplayNameSource(SubscriptionManager.NAME_SOURCE_CARRIER);
                    }

                    boolean isSatelliteSpn = false;
                    if (mFeatureFlags.oemEnabledSatelliteFlag() ) {
                        if (isSatelliteSpn(embeddedProfile.getServiceProviderName())) {
                            isSatelliteSpn = true;
                            builder.setOnlyNonTerrestrialNetwork(1);
                        }
                    } else {
                        log("updateEmupdateEmbeddedSubscriptions: oemEnabledSatelliteFlag is "
                                + "disabled");
                    }

                    if (android.os.Build.isDebuggable() &&
                            SystemProperties.getInt("telephony.test.bootstrap_cid", -2)
                                == carrierId) {
@@ -1194,11 +1205,9 @@ public class SubscriptionManagerService extends ISub.Stub {
                        String mnc = cid.getMnc();
                        builder.setMcc(mcc);
                        builder.setMnc(mnc);
                        if (mFeatureFlags.oemEnabledSatelliteFlag()) {
                        if (mFeatureFlags.oemEnabledSatelliteFlag() && !isSatelliteSpn) {
                            builder.setOnlyNonTerrestrialNetwork(
                                    isSatellitePlmn(mcc + mnc) ? 1 : 0);
                        } else {
                            log("updateEmbeddedSubscriptions: oemEnabledSatelliteFlag is disabled");
                        }
                    }
                    // If cardId = unsupported or un-initialized, we have no reason to update DB.
@@ -1471,7 +1480,6 @@ public class SubscriptionManagerService extends ISub.Stub {
                            MccTable.updateMccMncConfiguration(mContext, mccMnc);
                        }
                        setMccMnc(subId, mccMnc);
                        setNtn(subId, isSatellitePlmn(mccMnc));
                    } else {
                        loge("updateSubscription: mcc/mnc is empty");
                    }
@@ -4340,7 +4348,7 @@ public class SubscriptionManagerService extends ISub.Stub {
    /**
     * @param mccMnc MccMnc value to check whether it supports non-terrestrial network or not.
     * @return {@code true} if MCC/MNC is matched with in the device overlay key
     * "config_satellite_sim_identifier", {@code false} otherwise.
     * "config_satellite_sim_plmn_identifier", {@code false} otherwise.
     */
    private boolean isSatellitePlmn(@NonNull String mccMnc) {
        if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
@@ -4348,7 +4356,7 @@ public class SubscriptionManagerService extends ISub.Stub {
            return false;
        }

        final int id = R.string.config_satellite_sim_identifier;
        final int id = R.string.config_satellite_sim_plmn_identifier;
        String overlayMccMnc = null;
        try {
            overlayMccMnc = mContext.getResources().getString(id);
@@ -4356,14 +4364,43 @@ public class SubscriptionManagerService extends ISub.Stub {
            loge("isSatellitePlmn: id= " + id + ", ex=" + ex);
        }
        if (TextUtils.isEmpty(overlayMccMnc) && isMockModemAllowed()) {
            log("isSatellitePlmn: Read config_satellite_sim_identifier from device config");
            log("isSatellitePlmn: Read config_satellite_sim_plmn_identifier from device config");
            overlayMccMnc = DeviceConfig.getString(DeviceConfig.NAMESPACE_TELEPHONY,
                    "config_satellite_sim_identifier", "");
                    "config_satellite_sim_plmn_identifier", "");
        }
        log("isSatellitePlmn: overlayMccMnc=" + overlayMccMnc + ", mccMnc=" + mccMnc);
        return TextUtils.equals(mccMnc, overlayMccMnc);
    }

    /**
     * Checks and matches the service provider name (spn) with the device overlay config to
     * determine whether non-terrestrial networks are supported.
     * @param spn service provider name of the profile.
     * @return {@code true} if the given spn is matched with the overlay key.
     * "config_satellite_sim_spn_identifier", {@code false} otherwise.
     */
    private boolean isSatelliteSpn(@NonNull String spn) {
        if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
            log("isSatelliteSpn: oemEnabledSatelliteFlag is disabled");
            return false;
        }

        final int id = R.string.config_satellite_sim_spn_identifier;
        String overlaySpn = null;
        try {
            overlaySpn = mContext.getResources().getString(id);
        } catch (Resources.NotFoundException ex) {
            loge("isSatelliteSpn: id= " + id + ", ex=" + ex);
        }
        if (TextUtils.isEmpty(overlaySpn) && isMockModemAllowed()) {
            log("isSatelliteSpn: Read config_satellite_sim_spn_identifier from device config");
            overlaySpn = DeviceConfig.getString(DeviceConfig.NAMESPACE_TELEPHONY,
                    "config_satellite_sim_spn_identifier", "");
        }
        log("isSatelliteSpn: overlaySpn=" + overlaySpn + ", spn=" + spn);
        return TextUtils.equals(spn, overlaySpn);
    }

    private boolean isMockModemAllowed() {
        boolean isAllowed = SystemProperties.getBoolean(ALLOW_MOCK_MODEM_PROPERTY, false);
        return (SystemProperties.getBoolean(ALLOW_MOCK_MODEM_PROPERTY, false)
+116 −0
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ 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 static org.mockito.Mockito.when;

import android.Manifest;
import android.annotation.NonNull;
@@ -78,6 +79,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.ParcelUuid;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.provider.Settings;
import android.provider.Telephony;
@@ -97,6 +99,7 @@ import android.testing.TestableLooper;
import android.util.ArraySet;
import android.util.Base64;

import com.android.internal.R;
import com.android.internal.telephony.ContextFixture;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneFactory;
@@ -2995,4 +2998,117 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
                .getSubscriptionInfoInternal(2);
        assertThat(subInfo.isGroupDisabled()).isFalse();
    }

    @Test
    public void testIsSatelliteSpn() {
        mContextFixture.putResource(R.string.config_satellite_sim_spn_identifier,
                FAKE_CARRIER_NAME1);
        System.setProperty("persist.radio.allow_mock_modem", "true");
        doReturn(true).when(mFlags).oemEnabledSatelliteFlag();

        EuiccProfileInfo profileInfo1 = new EuiccProfileInfo.Builder(FAKE_ICCID1)
                .setIccid(FAKE_ICCID1)
                .setNickname(FAKE_CARRIER_NAME1)
                .setServiceProviderName(FAKE_CARRIER_NAME1)
                .setProfileClass(SubscriptionManager.PROFILE_CLASS_OPERATIONAL)
                .setCarrierIdentifier(new CarrierIdentifier(FAKE_MCC1, FAKE_MNC1,
                        FAKE_CARRIER_NAME1, null, null, null, FAKE_CARRIER_ID1, FAKE_CARRIER_ID1))
                .setUiccAccessRule(Arrays.asList(UiccAccessRule.decodeRules(
                        FAKE_NATIVE_ACCESS_RULES1)))
                .build();

        GetEuiccProfileInfoListResult result = new GetEuiccProfileInfoListResult(
                EuiccService.RESULT_OK, new EuiccProfileInfo[]{profileInfo1}, false);
        doReturn(result).when(mEuiccController).blockingGetEuiccProfileInfoList(eq(1));
        doReturn(TelephonyManager.INVALID_PORT_INDEX).when(mUiccSlot)
                .getPortIndexFromIccId(anyString());
        doReturn(FAKE_ICCID1).when(mUiccController).convertToCardString(eq(1));

        mSubscriptionManagerServiceUT.updateEmbeddedSubscriptions(List.of(1), null);
        processAllMessages();

        SubscriptionInfoInternal subInfo = mSubscriptionManagerServiceUT
                .getSubscriptionInfoInternal(1);
        assertThat(subInfo.getOnlyNonTerrestrialNetwork()).isEqualTo(1);

        mContextFixture.putResource(R.string.config_satellite_sim_spn_identifier,
                FAKE_CARRIER_NAME1);
        System.setProperty("persist.radio.allow_mock_modem", "false");
        doReturn(false).when(mFlags).oemEnabledSatelliteFlag();
    }

    @Test
    public void testIsSatelliteSpnWithNullCarrierIdentifier() {
        mContextFixture.putResource(R.string.config_satellite_sim_spn_identifier,
                FAKE_CARRIER_NAME1);
        System.setProperty("persist.radio.allow_mock_modem", "true");
        doReturn(true).when(mFlags).oemEnabledSatelliteFlag();

        EuiccProfileInfo profileInfo1 = new EuiccProfileInfo.Builder(FAKE_ICCID1)
                .setIccid(FAKE_ICCID1)
                .setNickname(FAKE_CARRIER_NAME1)
                .setServiceProviderName(FAKE_CARRIER_NAME1)
                .setProfileClass(SubscriptionManager.PROFILE_CLASS_OPERATIONAL)
                .setCarrierIdentifier(null)
                .setUiccAccessRule(Arrays.asList(UiccAccessRule.decodeRules(
                        FAKE_NATIVE_ACCESS_RULES1)))
                .build();

        GetEuiccProfileInfoListResult result = new GetEuiccProfileInfoListResult(
                EuiccService.RESULT_OK, new EuiccProfileInfo[]{profileInfo1}, false);
        doReturn(result).when(mEuiccController).blockingGetEuiccProfileInfoList(eq(1));
        doReturn(TelephonyManager.INVALID_PORT_INDEX).when(mUiccSlot)
                .getPortIndexFromIccId(anyString());
        doReturn(FAKE_ICCID1).when(mUiccController).convertToCardString(eq(1));

        mSubscriptionManagerServiceUT.updateEmbeddedSubscriptions(List.of(1), null);
        processAllMessages();

        SubscriptionInfoInternal subInfo = mSubscriptionManagerServiceUT
                .getSubscriptionInfoInternal(1);
        assertThat(subInfo.getOnlyNonTerrestrialNetwork()).isEqualTo(1);

        mContextFixture.putResource(R.string.config_satellite_sim_spn_identifier,
                FAKE_CARRIER_NAME1);
        System.setProperty("persist.radio.allow_mock_modem", "false");
        doReturn(false).when(mFlags).oemEnabledSatelliteFlag();
    }

    @Test
    public void testIsSatelliteSpnWithWrongSpn() {
        mContextFixture.putResource(R.string.config_satellite_sim_spn_identifier,
                FAKE_CARRIER_NAME1);
        System.setProperty("persist.radio.allow_mock_modem", "true");
        doReturn(true).when(mFlags).oemEnabledSatelliteFlag();

        EuiccProfileInfo profileInfo1 = new EuiccProfileInfo.Builder(FAKE_ICCID1)
                .setIccid(FAKE_ICCID1)
                .setNickname(FAKE_CARRIER_NAME1)
                .setServiceProviderName(FAKE_CARRIER_NAME2)
                .setProfileClass(SubscriptionManager.PROFILE_CLASS_OPERATIONAL)
                .setCarrierIdentifier(new CarrierIdentifier(FAKE_MCC1, FAKE_MNC1,
                        FAKE_CARRIER_NAME1, null, null, null, FAKE_CARRIER_ID1, FAKE_CARRIER_ID1))
                .setUiccAccessRule(Arrays.asList(UiccAccessRule.decodeRules(
                        FAKE_NATIVE_ACCESS_RULES1)))
                .build();

        GetEuiccProfileInfoListResult result = new GetEuiccProfileInfoListResult(
                EuiccService.RESULT_OK, new EuiccProfileInfo[]{profileInfo1}, false);
        doReturn(result).when(mEuiccController).blockingGetEuiccProfileInfoList(eq(1));
        doReturn(TelephonyManager.INVALID_PORT_INDEX).when(mUiccSlot)
                .getPortIndexFromIccId(anyString());
        doReturn(FAKE_ICCID1).when(mUiccController).convertToCardString(eq(1));

        mSubscriptionManagerServiceUT.updateEmbeddedSubscriptions(List.of(1), null);
        processAllMessages();

        SubscriptionInfoInternal subInfo = mSubscriptionManagerServiceUT
                .getSubscriptionInfoInternal(1);
        assertThat(subInfo.getOnlyNonTerrestrialNetwork()).isEqualTo(0);

        mContextFixture.putResource(R.string.config_satellite_sim_spn_identifier,
                FAKE_CARRIER_NAME1);
        System.setProperty("persist.radio.allow_mock_modem", "false");
        doReturn(false).when(mFlags).oemEnabledSatelliteFlag();
    }
}