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

Commit 1f608eb0 authored by Hyosun Kim's avatar Hyosun Kim Committed by Automerger Merge Worker
Browse files

Prevents empty string entitlement plmn case. am: 01b5c451

parents 003a014f 01b5c451
Loading
Loading
Loading
Loading
+16 −9
Original line number Diff line number Diff line
@@ -3224,13 +3224,18 @@ public class SatelliteController extends Handler {
    private void updatePlmnListPerCarrier(int subId) {
        synchronized (mSupportedSatelliteServicesLock) {
            List<String> carrierPlmnList, entitlementPlmnList;
            if (getConfigForSubId(subId).getBoolean(KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL,
                    false)) {
                entitlementPlmnList = mEntitlementPlmnListPerCarrier.get(subId,
                        new ArrayList<>()).stream().toList();
                logd("updatePlmnListPerCarrier: entitlementPlmnList=" + entitlementPlmnList
                        + " size=" + entitlementPlmnList.size());
                if (!entitlementPlmnList.isEmpty()) {
                    mMergedPlmnListPerCarrier.put(subId, entitlementPlmnList);
                    logd("update it using entitlementPlmnList=" + entitlementPlmnList);
                    return;
                }
            }

            SatelliteConfig satelliteConfig = getSatelliteConfig();
            if (satelliteConfig != null) {
@@ -3356,8 +3361,10 @@ public class SatelliteController extends Handler {
        }
    }

    /** If there is no cached entitlement plmn list, read it from the db and use it if it is not an
     * empty list. */
    /**
     * If there is no cached entitlement plmn list, read it from the db and use it if it is not an
     * empty list.
     */
    private void updateEntitlementPlmnListPerCarrier(int subId) {
        if (!getConfigForSubId(subId).getBoolean(KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL, false)) {
            logd("don't support entitlement");
@@ -3371,7 +3378,7 @@ public class SatelliteController extends Handler {
                List<String> entitlementPlmnList =
                        mSubscriptionManagerService.getSatelliteEntitlementPlmnList(subId);
                if (entitlementPlmnList.isEmpty()) {
                    loge("updateEntitlementPlmnListPerCarrier: no data for subId(" + subId + ")");
                    logd("updateEntitlementPlmnListPerCarrier: read empty list");
                    return;
                }
                logd("updateEntitlementPlmnListPerCarrier: entitlementPlmnList="
+6 −6
Original line number Diff line number Diff line
@@ -124,6 +124,7 @@ import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
@@ -4412,13 +4413,12 @@ public class SubscriptionManagerService extends ISub.Stub {
    public List<String> getSatelliteEntitlementPlmnList(int subId) {
        SubscriptionInfoInternal subInfo = mSubscriptionDatabaseManager.getSubscriptionInfoInternal(
                subId);
        if (subInfo == null) {
            loge("getSatelliteEntitlementPlmnList: invalid subId=" + subId);
            return new ArrayList<>();
        }

        return Arrays.stream(subInfo.getSatelliteEntitlementPlmns().split(",")).collect(
                Collectors.toList());
        return Optional.ofNullable(subInfo)
                .map(SubscriptionInfoInternal::getSatelliteEntitlementPlmns)
                .filter(s -> !s.isEmpty())
                .map(s -> Arrays.stream(s.split(",")).collect(Collectors.toList()))
                .orElse(new ArrayList<>());
    }

    /**
+44 −54
Original line number Diff line number Diff line
@@ -2669,67 +2669,41 @@ public class SatelliteControllerTest extends TelephonyTest {
            throws Exception {
        logd("testPassSatellitePlmnToModemAfterUpdateSatelliteEntitlementStatus");
        when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true);

        replaceInstance(SatelliteController.class, "mMergedPlmnListPerCarrier",
                mSatelliteControllerUT, new SparseArray<>());
        List<String> overlayConfigPlmnList = new ArrayList<>();
        replaceInstance(SatelliteController.class, "mSatellitePlmnListFromOverlayConfig",
                mSatelliteControllerUT, overlayConfigPlmnList);
        mCarrierConfigBundle.putBoolean(
                CarrierConfigManager.KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL, true);
        mCarrierConfigBundle.putBoolean(CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL,
                true);

        // If the PlmnListPerCarrier and the overlay config plmn list are empty verify passing to
        // the modem.
        // If the entitlement plmn list, the carrier plmn list and the overlay config plmn list
        // are empty verify not passing to the modem.
        reset(mMockSatelliteModemInterface);
        List<String> entitlementPlmnList = new ArrayList<>();
        mSatelliteControllerUT.onSatelliteEntitlementStatusUpdated(SUB_ID, false,
                entitlementPlmnList, mIIntegerConsumer);
        verify(mMockSatelliteModemInterface, never()).requestSatelliteEnabled(anyBoolean(),
                anyBoolean(), any(Message.class));

        List<String> plmnListPerCarrier = mSatelliteControllerUT.getSatellitePlmnsForCarrier(
                SUB_ID);
        List<String> allSatellitePlmnList = SatelliteServiceUtils.mergeStrLists(
                plmnListPerCarrier, overlayConfigPlmnList);

        assertEquals(new ArrayList<>(), plmnListPerCarrier);
        assertEquals(new ArrayList<>(), allSatellitePlmnList);
        verify(mMockSatelliteModemInterface, times(1)).setSatellitePlmn(anyInt(),
                eq(plmnListPerCarrier), eq(allSatellitePlmnList), any(Message.class));

        // If the PlmnListPerCarrier and the overlay config plmn list are exist but
        // KEY_SATELLITE_ATTACH_SUPPORTED_BOOL is false, verify passing to the modem.
        // If the entitlement plmn list and the overlay config plmn list are available and the
        // carrier plmn list is empty verify passing to the modem.
        reset(mMockSatelliteModemInterface);
        entitlementPlmnList = Arrays.stream(new String[]{"00101", "00102", "00103"}).toList();
        List<String> mergedPlmnList = entitlementPlmnList;
        overlayConfigPlmnList =
                Arrays.stream(new String[]{"00101", "00102", "00104"}).toList();
        replaceInstance(SatelliteController.class, "mSatellitePlmnListFromOverlayConfig",
                mSatelliteControllerUT, overlayConfigPlmnList);
        verifyPassingToModemAfterQueryCompleted(entitlementPlmnList, mergedPlmnList,
                overlayConfigPlmnList);

        mSatelliteControllerUT.onSatelliteEntitlementStatusUpdated(SUB_ID, true,
                entitlementPlmnList, mIIntegerConsumer);

        plmnListPerCarrier = mSatelliteControllerUT.getSatellitePlmnsForCarrier(SUB_ID);
        assertEquals(new ArrayList<>(), plmnListPerCarrier);
        allSatellitePlmnList = SatelliteServiceUtils.mergeStrLists(
                entitlementPlmnList, overlayConfigPlmnList);
        verify(mMockSatelliteModemInterface, times(1)).setSatellitePlmn(anyInt(),
                eq(entitlementPlmnList), eq(allSatellitePlmnList), any(Message.class));

        // If the PlmnListPerCarrier and the overlay config plmn list are exist and
        // KEY_SATELLITE_ATTACH_SUPPORTED_BOOL is true verify passing the modem.
        // If the entitlement plmn list, the overlay config plmn list and the carrier plmn list
        // are available, verify passing to the modem.
        reset(mMockSatelliteModemInterface);
        mCarrierConfigBundle.putBoolean(CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL,
                true);

        mSatelliteControllerUT.onSatelliteEntitlementStatusUpdated(SUB_ID, true,
                entitlementPlmnList, mIIntegerConsumer);

        plmnListPerCarrier = mSatelliteControllerUT.getSatellitePlmnsForCarrier(SUB_ID);
        allSatellitePlmnList = SatelliteServiceUtils.mergeStrLists(
                plmnListPerCarrier, overlayConfigPlmnList);

        assertEquals(entitlementPlmnList, plmnListPerCarrier);
        verify(mMockSatelliteModemInterface, times(1)).setSatellitePlmn(anyInt(),
                eq(plmnListPerCarrier), eq(allSatellitePlmnList), any(Message.class));

        // If the PlmnListPerCarrier and the overlay config plmn list are exist verify passing
        // the modem.
        reset(mMockSatelliteModemInterface);
        entitlementPlmnList = Arrays.stream(new String[]{"00101", "00102", "00103"}).toList();
        Map<Integer, Map<String, Set<Integer>>>
                satelliteServicesSupportedByCarriers = new HashMap<>();
        List<String> carrierConfigPlmnList = Arrays.stream(new String[]{"00105", "00106"}).toList();
@@ -2739,19 +2713,32 @@ public class SatelliteControllerTest extends TelephonyTest {
        satelliteServicesSupportedByCarriers.put(SUB_ID, plmnAndService);
        replaceInstance(SatelliteController.class, "mSatelliteServicesSupportedByCarriers",
                mSatelliteControllerUT, satelliteServicesSupportedByCarriers);
        overlayConfigPlmnList = Arrays.stream(new String[]{"00101", "00102", "00104"}).toList();
        replaceInstance(SatelliteController.class, "mSatellitePlmnListFromOverlayConfig",
                mSatelliteControllerUT, overlayConfigPlmnList);
        List<String> mergedPlmnList = entitlementPlmnList;
        verifyPassingToModemAfterQueryCompleted(entitlementPlmnList, mergedPlmnList,
                overlayConfigPlmnList);

        mSatelliteControllerUT.onSatelliteEntitlementStatusUpdated(SUB_ID, true,
        // If the entitlement plmn list is empty and the overlay config plmn list and the carrier
        // plmn list are available, verify not passing to the modem.
        reset(mMockSatelliteModemInterface);
        entitlementPlmnList = new ArrayList<>();
        mergedPlmnList = carrierConfigPlmnList;
        verifyPassingToModemAfterQueryCompleted(entitlementPlmnList, mergedPlmnList,
                overlayConfigPlmnList);
    }

    private void verifyPassingToModemAfterQueryCompleted(List<String> entitlementPlmnList,
            List<String> mergedPlmnList, List<String> overlayConfigPlmnList) {
        mSatelliteControllerUT.onSatelliteEntitlementStatusUpdated(SUB_ID, false,
                entitlementPlmnList, mIIntegerConsumer);

        plmnListPerCarrier = mSatelliteControllerUT.getSatellitePlmnsForCarrier(SUB_ID);
        allSatellitePlmnList = SatelliteServiceUtils.mergeStrLists(
        List<String> plmnListPerCarrier = mSatelliteControllerUT.getSatellitePlmnsForCarrier(
                SUB_ID);
        List<String> allSatellitePlmnList = SatelliteServiceUtils.mergeStrLists(
                plmnListPerCarrier, overlayConfigPlmnList);

        assertEquals(mergedPlmnList, plmnListPerCarrier);
        if (overlayConfigPlmnList.isEmpty()) {
            assertEquals(plmnListPerCarrier, allSatellitePlmnList);
        }
        verify(mMockSatelliteModemInterface, times(1)).setSatellitePlmn(anyInt(),
                eq(plmnListPerCarrier), eq(allSatellitePlmnList), any(Message.class));
    }
@@ -2879,8 +2866,11 @@ public class SatelliteControllerTest extends TelephonyTest {
    public void testUpdatePlmnListPerCarrier() throws Exception {
        logd("testUpdatePlmnListPerCarrier");
        when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true);

        replaceInstance(SatelliteController.class, "mMergedPlmnListPerCarrier",
                mSatelliteControllerUT, new SparseArray<>());
        mCarrierConfigBundle.putBoolean(
                CarrierConfigManager.KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL, true);
        List<String> plmnListPerCarrier;

        // verify whether an empty list is returned with conditions below
@@ -2996,8 +2986,8 @@ public class SatelliteControllerTest extends TelephonyTest {
        logd("testUpdateEntitlementPlmnListPerCarrier");
        when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true);

        // If the Satellite entitlement plmn list read from the DB is empty and carrier config
        // plmn list also is empty , check whether an empty list is returned when calling
        // If the Satellite entitlement plmn list read from the DB is empty list and carrier
        // config plmn list also is empty , check whether an empty list is returned when calling
        // getSatellitePlmnsForCarrier before the entitlement query.
        doReturn(new ArrayList<>()).when(
                mMockSubscriptionManagerService).getSatelliteEntitlementPlmnList(anyInt());
+61 −0
Original line number Diff line number Diff line
@@ -43,13 +43,16 @@ import static com.android.internal.telephony.subscription.SubscriptionDatabaseMa
import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_PHONE_NUMBER2;
import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_RCS_CONFIG1;
import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_RCS_CONFIG2;
import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_SATELLITE_ENTITLEMENT_PLMNS1;
import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_SUBSCRIPTION_INFO1;
import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_SUBSCRIPTION_INFO2;
import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_UUID1;

import static com.google.common.truth.Truth.assertThat;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -131,11 +134,13 @@ import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;

@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
@@ -3202,4 +3207,60 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
        System.setProperty("persist.radio.allow_mock_modem", "false");
        doReturn(false).when(mFlags).oemEnabledSatelliteFlag();
    }

    @Test
    public void testGetSatelliteEntitlementPlmnList() throws Exception {
        mContextFixture.addCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE);

        // When the empty list is stored, verify whether SubscriptionInfoInternal returns an
        // empty string and SubscriptionManagerService returns an empty List.
        insertSubscription(FAKE_SUBSCRIPTION_INFO1);
        List<String> expectedPlmnList = new ArrayList<>();
        int subId = 1;

        SubscriptionInfoInternal subInfo = mSubscriptionManagerServiceUT
                .getSubscriptionInfoInternal(subId);
        assertTrue(subInfo.getSatelliteEntitlementPlmns().isEmpty());
        assertEquals(expectedPlmnList,
                mSubscriptionManagerServiceUT.getSatelliteEntitlementPlmnList(subId));

        // When the list is stored as [123123,12310], verify whether SubscriptionInfoInternal
        // returns the string as "123123,12310" and SubscriptionManagerService returns the List as
        // [123123,12310].
        insertSubscription(FAKE_SUBSCRIPTION_INFO2);
        String expectedPlmn = FAKE_SATELLITE_ENTITLEMENT_PLMNS1;
        expectedPlmnList = Arrays.stream(expectedPlmn.split(",")).collect(Collectors.toList());
        subId = 2;

        subInfo = mSubscriptionManagerServiceUT.getSubscriptionInfoInternal(subId);
        assertEquals(expectedPlmn, subInfo.getSatelliteEntitlementPlmns());
        assertEquals(expectedPlmnList,
                mSubscriptionManagerServiceUT.getSatelliteEntitlementPlmnList(subId));

        // When calling SubscriptionDatabaseManager#getSubscriptionInfoInternalreturns returns a
        // null, then verify the SubscriptionManagerService returns an empty List.
        SubscriptionDatabaseManager mockSubscriptionDatabaseManager = Mockito.mock(
                SubscriptionDatabaseManager.class);
        Field field = SubscriptionManagerService.class.getDeclaredField(
                "mSubscriptionDatabaseManager");
        field.setAccessible(true);
        field.set(mSubscriptionManagerServiceUT, mockSubscriptionDatabaseManager);

        doReturn(null).when(mockSubscriptionDatabaseManager).getSubscriptionInfoInternal(anyInt());
        expectedPlmnList = new ArrayList<>();
        assertEquals(expectedPlmnList,
                mSubscriptionManagerServiceUT.getSatelliteEntitlementPlmnList(subId));

        // When calling SubscriptionDatabaseManager#getSubscriptionInfoInternalreturns returns a
        // non null. And when calling SubscriptionInfoInternal#getSatelliteEntitlementPlmns
        // returns a null, then verify the SubscriptionManagerService returns an empty List.
        SubscriptionInfoInternal mockSubscriptionInfoInternal = Mockito.mock(
                SubscriptionInfoInternal.class);
        doReturn(mockSubscriptionInfoInternal).when(
                mockSubscriptionDatabaseManager).getSubscriptionInfoInternal(anyInt());
        doReturn(null).when(mockSubscriptionInfoInternal).getSatelliteEntitlementPlmns();

        assertEquals(expectedPlmnList,
                mSubscriptionManagerServiceUT.getSatelliteEntitlementPlmnList(subId));
    }
}