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

Commit c8476255 authored by Hyosun Kim's avatar Hyosun Kim Committed by Android (Google) Code Review
Browse files

Merge "Store the Satellite Entitlement Status and the Satellite Entitlement...

Merge "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" into main
parents 93727554 b8640650
Loading
Loading
Loading
Loading
+90 −4
Original line number 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_SATELLITE_ATTACH_SUPPORTED_BOOL;
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_ENTITLEMENT_STATUS;
import static android.telephony.SubscriptionManager.isValidSubscriptionId;
import static android.telephony.satellite.NtnSignalStrength.NTN_SIGNAL_STRENGTH_NONE;
import static android.telephony.satellite.SatelliteManager.EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS;
@@ -113,6 +115,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -2598,19 +2601,28 @@ public class SatelliteController extends Handler {
                }
            };
        }
        logd("onSatelliteEntitlementStatusUpdated subId=" + subId + " , entitlementEnabled="
                + entitlementEnabled + ", allowedPlmnList=" + (Objects.equals(null, allowedPlmnList)
                ? "" : allowedPlmnList + ""));

        synchronized (mSupportedSatelliteServicesLock) {
            if (mSatelliteEntitlementStatusPerCarrier.get(subId, false) != entitlementEnabled) {
                logd("update the carrier satellite enabled to " + 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);

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

            // TODO b/322143408 store entitlement status in telephony db.
            if (mSatelliteEntitlementStatusPerCarrier.get(subId, false)) {
                removeAttachRestrictionForCarrier(subId,
                        SATELLITE_COMMUNICATION_RESTRICTION_REASON_ENTITLEMENT, callback);
@@ -3230,7 +3242,8 @@ public class SatelliteController extends Handler {
        PersistableBundle config = mCarrierConfigManager.getConfigForSubId(subId,
                KEY_CARRIER_SUPPORTED_SATELLITE_SERVICES_PER_PROVIDER_BUNDLE,
                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()) {
            config = CarrierConfigManager.getDefaultConfig();
        }
@@ -3247,8 +3260,7 @@ public class SatelliteController extends Handler {
        }

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

@@ -3258,6 +3270,7 @@ public class SatelliteController extends Handler {
        }

        setSatelliteAttachEnabledForCarrierOnSimLoaded(subId);
        updateRestrictReasonForEntitlementPerCarrier(subId);
    }

    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
@@ -3267,6 +3280,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
     * associated with the SIM, and evaluate if satellite should be enabled for the carrier.
@@ -3371,6 +3409,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
     * {@code subId} to persistent storage.
+125 −0
Original line number 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_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_GREAT;
import static android.telephony.satellite.NtnSignalStrength.NTN_SIGNAL_STRENGTH_NONE;
@@ -2887,6 +2888,130 @@ public class SatelliteControllerTest extends TelephonyTest {
        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
    public void testHandleEventServiceStateChanged() throws Exception {
        when(mFeatureFlags.carrierEnabledSatelliteFlag()).thenReturn(true);