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

Commit b8640650 authored by Hyosun Kim's avatar Hyosun Kim
Browse files

Store the Satellite Entitlement Status and the Satellite Entitlement plmn...

Store the Satellite Entitlement Status and  the Satellite Entitlement plmn list in db and added restrict reason for entitlement per carrier according to this value

If this carrier supports entitlement and the cache value or the Entitlement status value read from the db is disabled, add a restrict reason before the entitlement query.
If this carrier supports entitlement and the cache value or the Entitlement plmn list value read from the db is not empty, used it before the entitlement query.

Store the entitlement status and entitlement plmn list in the db after the query is completed.

Bug : 321876569
Test: atest SatelliteControllerTest
Test : manual test
1. If the entitlement status read from cache or db is disabled, verify adding a restriction reason before the entitlement query.
2. If the entitlement plmn list read from cache or db is not empty, verify for use it as plmn list before the entitlement query.
3. After the query is completed, verify storing the entitlement status and entitlement plmn list in the db.

Change-Id: If873463f560da3c188fa9e00b002d77edde0303d
parent 2dda955d
Loading
Loading
Loading
Loading
+90 −4
Original line number Original line Diff line number Diff line
@@ -20,7 +20,9 @@ import static android.provider.Settings.ACTION_SATELLITE_SETTING;
import static android.telephony.CarrierConfigManager.KEY_CARRIER_SUPPORTED_SATELLITE_SERVICES_PER_PROVIDER_BUNDLE;
import static android.telephony.CarrierConfigManager.KEY_CARRIER_SUPPORTED_SATELLITE_SERVICES_PER_PROVIDER_BUNDLE;
import static android.telephony.CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL;
import static android.telephony.CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL;
import static android.telephony.CarrierConfigManager.KEY_SATELLITE_CONNECTION_HYSTERESIS_SEC_INT;
import static android.telephony.CarrierConfigManager.KEY_SATELLITE_CONNECTION_HYSTERESIS_SEC_INT;
import static android.telephony.CarrierConfigManager.KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL;
import static android.telephony.SubscriptionManager.SATELLITE_ATTACH_ENABLED_FOR_CARRIER;
import static android.telephony.SubscriptionManager.SATELLITE_ATTACH_ENABLED_FOR_CARRIER;
import static android.telephony.SubscriptionManager.SATELLITE_ENTITLEMENT_STATUS;
import static android.telephony.SubscriptionManager.isValidSubscriptionId;
import static android.telephony.SubscriptionManager.isValidSubscriptionId;
import static android.telephony.satellite.NtnSignalStrength.NTN_SIGNAL_STRENGTH_NONE;
import static android.telephony.satellite.NtnSignalStrength.NTN_SIGNAL_STRENGTH_NONE;
import static android.telephony.satellite.SatelliteManager.EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS;
import static android.telephony.satellite.SatelliteManager.EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS;
@@ -112,6 +114,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.HashSet;
import java.util.List;
import java.util.List;
import java.util.Map;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -2530,19 +2533,28 @@ public class SatelliteController extends Handler {
                }
                }
            };
            };
        }
        }
        logd("onSatelliteEntitlementStatusUpdated subId=" + subId + " , entitlementEnabled="
                + entitlementEnabled + ", allowedPlmnList=" + (Objects.equals(null, allowedPlmnList)
                ? "" : allowedPlmnList + ""));


        synchronized (mSupportedSatelliteServicesLock) {
        synchronized (mSupportedSatelliteServicesLock) {
            if (mSatelliteEntitlementStatusPerCarrier.get(subId, false) != entitlementEnabled) {
            if (mSatelliteEntitlementStatusPerCarrier.get(subId, false) != entitlementEnabled) {
                logd("update the carrier satellite enabled to " + entitlementEnabled);
                logd("update the carrier satellite enabled to " + entitlementEnabled);
                mSatelliteEntitlementStatusPerCarrier.put(subId, entitlementEnabled);
                mSatelliteEntitlementStatusPerCarrier.put(subId, entitlementEnabled);
                try {
                    mSubscriptionManagerService.setSubscriptionProperty(subId,
                            SATELLITE_ENTITLEMENT_STATUS, entitlementEnabled ? "1" : "0");
                } catch (IllegalArgumentException | SecurityException e) {
                    loge("onSatelliteEntitlementStatusUpdated: setSubscriptionProperty, e=" + e);
                }
            }
            }
            mMergedPlmnListPerCarrier.remove(subId);
            mMergedPlmnListPerCarrier.remove(subId);


            mEntitlementPlmnListPerCarrier.put(subId, allowedPlmnList);
            mEntitlementPlmnListPerCarrier.put(subId, allowedPlmnList);
            updatePlmnListPerCarrier(subId);
            updatePlmnListPerCarrier(subId);
            configureSatellitePlmnForCarrier(subId);
            configureSatellitePlmnForCarrier(subId);
            mSubscriptionManagerService.setSatelliteEntitlementPlmnList(subId, allowedPlmnList);


            // TODO b/322143408 store entitlement status in telephony db.
            if (mSatelliteEntitlementStatusPerCarrier.get(subId, false)) {
            if (mSatelliteEntitlementStatusPerCarrier.get(subId, false)) {
                removeAttachRestrictionForCarrier(subId,
                removeAttachRestrictionForCarrier(subId,
                        SATELLITE_COMMUNICATION_RESTRICTION_REASON_ENTITLEMENT, callback);
                        SATELLITE_COMMUNICATION_RESTRICTION_REASON_ENTITLEMENT, callback);
@@ -3161,7 +3173,8 @@ public class SatelliteController extends Handler {
        PersistableBundle config = mCarrierConfigManager.getConfigForSubId(subId,
        PersistableBundle config = mCarrierConfigManager.getConfigForSubId(subId,
                KEY_CARRIER_SUPPORTED_SATELLITE_SERVICES_PER_PROVIDER_BUNDLE,
                KEY_CARRIER_SUPPORTED_SATELLITE_SERVICES_PER_PROVIDER_BUNDLE,
                KEY_SATELLITE_ATTACH_SUPPORTED_BOOL,
                KEY_SATELLITE_ATTACH_SUPPORTED_BOOL,
                KEY_SATELLITE_CONNECTION_HYSTERESIS_SEC_INT);
                KEY_SATELLITE_CONNECTION_HYSTERESIS_SEC_INT,
                KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL);
        if (config == null || config.isEmpty()) {
        if (config == null || config.isEmpty()) {
            config = CarrierConfigManager.getDefaultConfig();
            config = CarrierConfigManager.getDefaultConfig();
        }
        }
@@ -3178,8 +3191,7 @@ public class SatelliteController extends Handler {
        }
        }


        updateCarrierConfig(subId);
        updateCarrierConfig(subId);
        // TODO b/322143408 read the telephony db to get the entitlementStatus and update the
        updateEntitlementPlmnListPerCarrier(subId);
        //  restriction
        updateSupportedSatelliteServicesForActiveSubscriptions();
        updateSupportedSatelliteServicesForActiveSubscriptions();
        configureSatellitePlmnForCarrier(subId);
        configureSatellitePlmnForCarrier(subId);


@@ -3189,6 +3201,7 @@ public class SatelliteController extends Handler {
        }
        }


        setSatelliteAttachEnabledForCarrierOnSimLoaded(subId);
        setSatelliteAttachEnabledForCarrierOnSimLoaded(subId);
        updateRestrictReasonForEntitlementPerCarrier(subId);
    }
    }


    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
@@ -3198,6 +3211,31 @@ 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. */
    private void updateEntitlementPlmnListPerCarrier(int subId) {
        if (!getConfigForSubId(subId).getBoolean(KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL, false)) {
            logd("don't support entitlement");
            return;
        }

        synchronized (mSupportedSatelliteServicesLock) {
            if (mEntitlementPlmnListPerCarrier.indexOfKey(subId) < 0) {
                logd("updateEntitlementPlmnListPerCarrier: no correspondent cache, load from "
                        + "persist storage");
                List<String> entitlementPlmnList =
                        mSubscriptionManagerService.getSatelliteEntitlementPlmnList(subId);
                if (entitlementPlmnList.isEmpty()) {
                    loge("updateEntitlementPlmnListPerCarrier: no data for subId(" + subId + ")");
                    return;
                }
                logd("updateEntitlementPlmnListPerCarrier: entitlementPlmnList="
                        + entitlementPlmnList);
                mEntitlementPlmnListPerCarrier.put(subId, entitlementPlmnList);
            }
        }
    }

    /**
    /**
     * When a SIM is loaded, we need to check if users has enabled satellite attach for the carrier
     * When a SIM is loaded, we need to check if users has enabled satellite attach for the carrier
     * associated with the SIM, and evaluate if satellite should be enabled for the carrier.
     * associated with the SIM, and evaluate if satellite should be enabled for the carrier.
@@ -3302,6 +3340,54 @@ public class SatelliteController extends Handler {
        }
        }
    }
    }


    private void updateRestrictReasonForEntitlementPerCarrier(int subId) {
        if (!getConfigForSubId(subId).getBoolean(KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL, false)) {
            logd("don't support entitlement");
            return;
        }

        IIntegerConsumer callback = new IIntegerConsumer.Stub() {
            @Override
            public void accept(int result) {
                logd("updateRestrictReasonForEntitlementPerCarrier:" + result);
            }
        };
        synchronized (mSupportedSatelliteServicesLock) {
            if (mSatelliteEntitlementStatusPerCarrier.indexOfKey(subId) < 0) {
                logd("updateRestrictReasonForEntitlementPerCarrier: no correspondent cache, "
                        + "load from persist storage");
                String entitlementStatus = null;
                try {
                    entitlementStatus =
                            mSubscriptionManagerService.getSubscriptionProperty(subId,
                                    SATELLITE_ENTITLEMENT_STATUS, mContext.getOpPackageName(),
                                    mContext.getAttributionTag());
                } catch (IllegalArgumentException | SecurityException e) {
                    loge("updateRestrictReasonForEntitlementPerCarrier, e=" + e);
                }

                if (entitlementStatus == null) {
                    loge("updateRestrictReasonForEntitlementPerCarrier: invalid subId, subId="
                            + subId + " set to default value");
                    entitlementStatus = "0";
                }

                if (entitlementStatus.isEmpty()) {
                    loge("updateRestrictReasonForEntitlementPerCarrier: no data for subId(" + subId
                            + "). set to default value");
                    entitlementStatus = "0";
                }
                boolean result = entitlementStatus.equals("1");
                mSatelliteEntitlementStatusPerCarrier.put(subId, result);
            }

            if (!mSatelliteEntitlementStatusPerCarrier.get(subId, false)) {
                addAttachRestrictionForCarrier(subId,
                        SATELLITE_COMMUNICATION_RESTRICTION_REASON_ENTITLEMENT, callback);
            }
        }
    }

    /**
    /**
     * Save user setting for enabling satellite attach for the carrier associated with the
     * Save user setting for enabling satellite attach for the carrier associated with the
     * {@code subId} to persistent storage.
     * {@code subId} to persistent storage.
+125 −0
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.internal.telephony.satellite;


import static android.telephony.CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL;
import static android.telephony.CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL;
import static android.telephony.CarrierConfigManager.KEY_SATELLITE_CONNECTION_HYSTERESIS_SEC_INT;
import static android.telephony.CarrierConfigManager.KEY_SATELLITE_CONNECTION_HYSTERESIS_SEC_INT;
import static android.telephony.SubscriptionManager.SATELLITE_ENTITLEMENT_STATUS;
import static android.telephony.satellite.NtnSignalStrength.NTN_SIGNAL_STRENGTH_GOOD;
import static android.telephony.satellite.NtnSignalStrength.NTN_SIGNAL_STRENGTH_GOOD;
import static android.telephony.satellite.NtnSignalStrength.NTN_SIGNAL_STRENGTH_GREAT;
import static android.telephony.satellite.NtnSignalStrength.NTN_SIGNAL_STRENGTH_GREAT;
import static android.telephony.satellite.NtnSignalStrength.NTN_SIGNAL_STRENGTH_NONE;
import static android.telephony.satellite.NtnSignalStrength.NTN_SIGNAL_STRENGTH_NONE;
@@ -2881,6 +2882,130 @@ public class SatelliteControllerTest extends TelephonyTest {
        assertEquals(true, satelliteEnabledPerCarrier.get(SUB_ID1));
        assertEquals(true, satelliteEnabledPerCarrier.get(SUB_ID1));
    }
    }


    @Test
    public void testUpdateRestrictReasonForEntitlementPerCarrier() throws Exception {
        logd("testUpdateRestrictReasonForEntitlementPerCarrier");
        when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true);

        // Verify that the entitlement restriction reason is added before the entitlement query,
        // When the Satellite entitlement status value read from DB is disabled.
        doReturn("").when(mContext).getOpPackageName();
        doReturn("").when(mContext).getAttributionTag();
        doReturn("0").when(mMockSubscriptionManagerService).getSubscriptionProperty(anyInt(),
                eq(SATELLITE_ENTITLEMENT_STATUS), anyString(), anyString());
        doReturn(new ArrayList<>()).when(
                mMockSubscriptionManagerService).getSatelliteEntitlementPlmnList(anyInt());
        mCarrierConfigBundle.putBoolean(CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL,
                true);
        mCarrierConfigBundle.putBoolean(
                CarrierConfigManager.KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL, true);
        for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair
                : mCarrierConfigChangedListenerList) {
            pair.first.execute(() -> pair.second.onCarrierConfigChanged(
                    /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0)
            );
        }
        processAllMessages();
        Set<Integer> restrictionSet =
                mSatelliteControllerUT.getAttachRestrictionReasonsForCarrier(SUB_ID);
        assertEquals(1, restrictionSet.size());
        assertTrue(restrictionSet.contains(SATELLITE_COMMUNICATION_RESTRICTION_REASON_ENTITLEMENT));
    }

    @Test
    public void testUpdateEntitlementPlmnListPerCarrier() throws Exception {
        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
        // getSatellitePlmnsForCarrier before the entitlement query.
        doReturn(new ArrayList<>()).when(
                mMockSubscriptionManagerService).getSatelliteEntitlementPlmnList(anyInt());
        replaceInstance(SatelliteController.class, "mEntitlementPlmnListPerCarrier",
                mSatelliteControllerUT, new SparseArray<>());
        replaceInstance(SatelliteController.class, "mSatelliteServicesSupportedByCarriers",
                mSatelliteControllerUT, new HashMap<>());
        mCarrierConfigBundle.putBoolean(CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL,
                true);
        mCarrierConfigBundle.putBoolean(
                CarrierConfigManager.KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL, true);
        for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair
                : mCarrierConfigChangedListenerList) {
            pair.first.execute(() -> pair.second.onCarrierConfigChanged(
                    /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0)
            );
        }
        processAllMessages();

        assertEquals(new ArrayList<>(), mSatelliteControllerUT.getSatellitePlmnsForCarrier(SUB_ID));

        // If the Satellite entitlement plmn list read from the DB is valid and carrier config
        // plmn list is empty, check whether valid entitlement plmn list is returned
        // when calling getSatellitePlmnsForCarrier before the entitlement query.
        replaceInstance(SatelliteController.class, "mEntitlementPlmnListPerCarrier",
                mSatelliteControllerUT, new SparseArray<>());
        List<String> expectedSatelliteEntitlementPlmnList = Arrays.asList("123456,12560");
        doReturn(expectedSatelliteEntitlementPlmnList).when(
                mMockSubscriptionManagerService).getSatelliteEntitlementPlmnList(anyInt());
        for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair
                : mCarrierConfigChangedListenerList) {
            pair.first.execute(() -> pair.second.onCarrierConfigChanged(
                    /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0)
            );
        }
        processAllMessages();

        assertEquals(expectedSatelliteEntitlementPlmnList,
                mSatelliteControllerUT.getSatellitePlmnsForCarrier(SUB_ID));

        // If the Satellite entitlement plmn list read from the DB is valid and carrier config
        // plmn list is valid, check whether valid entitlement plmn list is returned when
        // calling getSatellitePlmnsForCarrier before the entitlement query.
        replaceInstance(SatelliteController.class, "mEntitlementPlmnListPerCarrier",
                mSatelliteControllerUT, new SparseArray<>());
        PersistableBundle carrierSupportedSatelliteServicesPerProvider = new PersistableBundle();
        List<String> carrierConfigPlmnList = Arrays.asList("00102", "00103", "00105");
        carrierSupportedSatelliteServicesPerProvider.putIntArray(
                carrierConfigPlmnList.get(0), new int[]{2});
        carrierSupportedSatelliteServicesPerProvider.putIntArray(
                carrierConfigPlmnList.get(1), new int[]{1, 3});
        carrierSupportedSatelliteServicesPerProvider.putIntArray(
                carrierConfigPlmnList.get(2), new int[]{2});
        mCarrierConfigBundle.putPersistableBundle(CarrierConfigManager
                        .KEY_CARRIER_SUPPORTED_SATELLITE_SERVICES_PER_PROVIDER_BUNDLE,
                carrierSupportedSatelliteServicesPerProvider);
        for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair
                : mCarrierConfigChangedListenerList) {
            pair.first.execute(() -> pair.second.onCarrierConfigChanged(
                    /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0)
            );
        }
        processAllMessages();

        assertEquals(expectedSatelliteEntitlementPlmnList,
                mSatelliteControllerUT.getSatellitePlmnsForCarrier(SUB_ID));

        // If the Satellite entitlement plmn list read from the DB is empty and carrier config
        // plmn list is valid, check whether valid carrier config plmn list is returned when
        // calling getSatellitePlmnsForCarrier before the entitlement query.
        replaceInstance(SatelliteController.class, "mEntitlementPlmnListPerCarrier",
                mSatelliteControllerUT, new SparseArray<>());
        doReturn(new ArrayList<>()).when(
                mMockSubscriptionManagerService).getSatelliteEntitlementPlmnList(anyInt());
        for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair
                : mCarrierConfigChangedListenerList) {
            pair.first.execute(() -> pair.second.onCarrierConfigChanged(
                    /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0)
            );
        }
        processAllMessages();

        assertEquals(carrierConfigPlmnList.stream().sorted().toList(),
                mSatelliteControllerUT.getSatellitePlmnsForCarrier(
                        SUB_ID).stream().sorted().toList());
    }

    @Test
    @Test
    public void testHandleEventServiceStateChanged() throws Exception {
    public void testHandleEventServiceStateChanged() throws Exception {
        when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true);
        when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true);