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

Commit 2d88b6cc authored by Thomas Nguyen's avatar Thomas Nguyen Committed by Hakjun Choi
Browse files

Configure earfcns to modem

Change-Id: I709006bf002168e5b7b5ae855bdd6cbc9acc86b6
Flag: com.android.internal.telephony.flags.carrier_roaming_nb_iot_ntn
Bug: 373872272
Test: SatelliteManagerTestOnMockService SatelliteAccessControllerTest
parent 35168cf0
Loading
Loading
Loading
Loading
+112 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import static android.telephony.CarrierConfigManager.KEY_CARRIER_SUPPORTED_SATEL
import static android.telephony.CarrierConfigManager.KEY_CARRIER_SUPPORTED_SATELLITE_SERVICES_PER_PROVIDER_BUNDLE;
import static android.telephony.CarrierConfigManager.KEY_EMERGENCY_CALL_TO_SATELLITE_T911_HANDOVER_TIMEOUT_MILLIS_INT;
import static android.telephony.CarrierConfigManager.KEY_EMERGENCY_MESSAGING_SUPPORTED_BOOL;
import static android.telephony.CarrierConfigManager.KEY_REGIONAL_SATELLITE_EARFCN_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;
@@ -141,6 +142,7 @@ import android.telephony.satellite.SatelliteModemEnableRequestAttributes;
import android.telephony.satellite.SatelliteSubscriberInfo;
import android.telephony.satellite.SatelliteSubscriberProvisionStatus;
import android.telephony.satellite.SatelliteSubscriptionInfo;
import android.telephony.satellite.SystemSelectionSpecifier;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
@@ -299,6 +301,8 @@ public class SatelliteController extends Handler {
    private static final int EVENT_TERRESTRIAL_NETWORK_AVAILABLE_CHANGED = 55;
    private static final int EVENT_SET_NETWORK_SELECTION_AUTO_DONE = 56;
    private static final int EVENT_SIGNAL_STRENGTH_CHANGED = 57;
    private static final int CMD_UPDATE_SYSTEM_SELECTION_CHANNELS = 58;
    private static final int EVENT_UPDATE_SYSTEM_SELECTION_CHANNELS_DONE = 59;

    @NonNull private static SatelliteController sInstance;
    @NonNull private final Context mContext;
@@ -481,6 +485,13 @@ public class SatelliteController extends Handler {
     * {@code true} for enabled and {@code false} for disabled. */
    @NonNull private final Map<Integer, Boolean> mIsSatelliteAttachEnabledForCarrierArrayPerSub =
            new HashMap<>();
    /** Key: subId, value: (key: Regional satellite config Id string, value: Integer
     * arrays of earfcns in the corresponding regions.)
     */
    @GuardedBy("mRegionalSatelliteEarfcnsLock")
    @NonNull private final Map<Integer, Map<String, Set<Integer>>>
            mRegionalSatelliteEarfcns = new HashMap<>();
    @NonNull private final Object mRegionalSatelliteEarfcnsLock = new Object();
    @NonNull private final FeatureFlags mFeatureFlags;
    @NonNull private final Object mSatelliteConnectedLock = new Object();
    /** Key: Subscription ID; Value: Last satellite connected time */
@@ -1223,6 +1234,17 @@ public class SatelliteController extends Handler {
        }
    }

    private static final class UpdateSystemSelectionChannelsArgument {
        @NonNull SystemSelectionSpecifier mSelectionSpecifier;
        @NonNull ResultReceiver mResult;

        UpdateSystemSelectionChannelsArgument(@NonNull SystemSelectionSpecifier selectionSpecifier,
                @NonNull ResultReceiver result) {
            this.mSelectionSpecifier = selectionSpecifier;
            this.mResult = result;
        }
    }

    /**
     * Arguments to send to SatelliteTransmissionUpdate registrants
     */
@@ -2040,6 +2062,29 @@ public class SatelliteController extends Handler {
                int phoneId = (int) ar.userObj;
                updateLastNotifiedCarrierRoamingNtnSignalStrengthAndNotify(
                        PhoneFactory.getPhone(phoneId));
                break;
            }

            case CMD_UPDATE_SYSTEM_SELECTION_CHANNELS: {
                plogd("CMD_UPDATE_SYSTEM_SELECTION_CHANNELS");
                request = (SatelliteControllerHandlerRequest) msg.obj;
                onCompleted = obtainMessage(EVENT_UPDATE_SYSTEM_SELECTION_CHANNELS_DONE, request);
                mSatelliteModemInterface.updateSystemSelectionChannels(
                        ((UpdateSystemSelectionChannelsArgument) (request.argument))
                                .mSelectionSpecifier,
                        onCompleted);
                break;
            }

            case EVENT_UPDATE_SYSTEM_SELECTION_CHANNELS_DONE: {
                ar = (AsyncResult) msg.obj;
                request = (SatelliteControllerHandlerRequest) ar.userObj;
                int error =  SatelliteServiceUtils.getSatelliteError(
                        ar, "updateSystemSelectionChannel");
                plogd("EVENT_UPDATE_SYSTEM_SELECTION_CHANNELS_DONE = " + error);
                ((UpdateSystemSelectionChannelsArgument) (request.argument)).mResult.send(error,
                        null);
                break;
            }

            default:
@@ -5200,6 +5245,13 @@ public class SatelliteController extends Handler {
                        KEY_CARRIER_SUPPORTED_SATELLITE_SERVICES_PER_PROVIDER_BUNDLE));
    }

    @NonNull
    private Map<String, Set<Integer>> readRegionalSatelliteEarfcnsFromCarrierConfig(int subId) {
        PersistableBundle config = getPersistableBundle(subId);
        return SatelliteServiceUtils.parseRegionalSatelliteEarfcns(
                config.getPersistableBundle(KEY_REGIONAL_SATELLITE_EARFCN_BUNDLE));
    }

    @NonNull private PersistableBundle getConfigForSubId(int subId) {
        PersistableBundle config = null;
        if (mCarrierConfigManager != null) {
@@ -5223,7 +5275,8 @@ public class SatelliteController extends Handler {
                        KEY_SATELLITE_ROAMING_P2P_SMS_INACTIVITY_TIMEOUT_SEC_INT,
                        KEY_SATELLITE_ROAMING_ESOS_INACTIVITY_TIMEOUT_SEC_INT,
                        KEY_SATELLITE_SOS_MAX_DATAGRAM_SIZE,
                        KEY_SATELLITE_SUPPORTED_MSG_APPS_STRING_ARRAY
                        KEY_SATELLITE_SUPPORTED_MSG_APPS_STRING_ARRAY,
                        KEY_REGIONAL_SATELLITE_EARFCN_BUNDLE
                );
            } catch (Exception e) {
                logw("getConfigForSubId: " + e);
@@ -5254,6 +5307,7 @@ public class SatelliteController extends Handler {
        evaluateCarrierRoamingNtnEligibilityChange();
        sendMessageDelayed(obtainMessage(CMD_EVALUATE_ESOS_PROFILES_PRIORITIZATION),
                mEvaluateEsosProfilesPrioritizationDurationMillis);
        updateRegionalSatelliteEarfcns(subId);
    }

    // imsi, msisdn, default sms subId change
@@ -7191,6 +7245,63 @@ public class SatelliteController extends Handler {
        incrementResultReceiverCount("SC:provisionSatellite");
    }

    /**
     * Request to update system selection channels.
     *
     * @param result The result receiver that returns if the request is successful or
     *               an error code if the request failed.
     */
    public void updateSystemSelectionChannels(@NonNull SystemSelectionSpecifier selectionSpecifier,
            @NonNull ResultReceiver result) {
        if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
            plogd("updateSystemSelectionChannels: "
                    + "carrierRoamingNbIotNtn flag is disabled");
            result.send(SATELLITE_RESULT_REQUEST_NOT_SUPPORTED, null);
            return;
        }

        sendRequestAsync(CMD_UPDATE_SYSTEM_SELECTION_CHANNELS,
                new UpdateSystemSelectionChannelsArgument(selectionSpecifier, result), null);
    }

    /**
     * @param subId Subscription ID.
     * @return The The map of earfcns with key: regional satellite config Id,
     * value: set of earfcns in the corresponding regions associated with the {@code subId}.
     */
    @NonNull
    public Map<String, Set<Integer>> getRegionalSatelliteEarfcns(int subId) {
        if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
            logd("getRegionalSatelliteEarfcns: carrierRoamingNbIotNtnFlag is disabled");
            return new HashMap<>();
        }
        synchronized (mRegionalSatelliteEarfcnsLock) {
            if (mRegionalSatelliteEarfcns.containsKey(subId)) {
                return mRegionalSatelliteEarfcns.get(subId);
            } else {
                logd("getRegionalSatelliteEarfcns: Earfcns for subId: " + subId + " not found");
                return new HashMap<>();
            }
        }
    }

    /**
     * Update regional satellite earfcn information from carrier config.
     */
    public void updateRegionalSatelliteEarfcns(int subId) {
        plogd("updateRegionalSatelliteEarfcns with subId " + subId);
        if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
            plogd("updateRegionalSatelliteEarfcns: "
                    + "carrierRoamingNbIotNtn flag is disabled");
            return;
        }

        synchronized (mRegionalSatelliteEarfcnsLock) {
            mRegionalSatelliteEarfcns.put(subId,
                    readRegionalSatelliteEarfcnsFromCarrierConfig(subId));
        }
    }

    /**
     * Deliver the list of deprovisioned satellite subscriber ids.
     *
+37 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.telephony.satellite.SatelliteDatagram;
import android.telephony.satellite.SatelliteManager;
import android.telephony.satellite.SatelliteManager.SatelliteException;
import android.telephony.satellite.SatelliteModemEnableRequestAttributes;
import android.telephony.satellite.SystemSelectionSpecifier;
import android.telephony.satellite.stub.INtnSignalStrengthConsumer;
import android.telephony.satellite.stub.ISatellite;
import android.telephony.satellite.stub.ISatelliteCapabilitiesConsumer;
@@ -1383,6 +1384,42 @@ public class SatelliteModemInterface {
        mExponentialBackoff.start();
    }

    /**
     * Request to update system selection channels
     *
     * @param systemSelectionSpecifier system selection specifiers
     * @param message The Message to send to result of the operation to.
     */
    public void updateSystemSelectionChannels(
            @NonNull SystemSelectionSpecifier systemSelectionSpecifier,
            @Nullable Message message) {
        plogd("updateSystemSelectionChannels: SystemSelectionSpecifier: "
                + systemSelectionSpecifier.toString());
        if (mSatelliteService != null) {
            try {
                mSatelliteService.updateSystemSelectionChannels(SatelliteServiceUtils
                                .toSystemSelectionSpecifier(systemSelectionSpecifier),
                        new IIntegerConsumer.Stub() {
                            @Override
                            public void accept(int result) {
                                int error = SatelliteServiceUtils.fromSatelliteError(result);
                                plogd("updateSystemSelectionChannels: " + error);
                                Binder.withCleanCallingIdentity(() ->
                                        sendMessageWithResult(message, null, error));
                            }
                        });
            } catch (RemoteException e) {
                ploge("updateSystemSelectionChannels: RemoteException " + e);
                sendMessageWithResult(message, null,
                        SatelliteManager.SATELLITE_RESULT_SERVICE_ERROR);
            }
        } else {
            ploge("updateSystemSelectionChannels: Satellite service is unavailable.");
            sendMessageWithResult(message, null,
                    SatelliteManager.SATELLITE_RESULT_RADIO_NOT_AVAILABLE);
        }
    }

    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected static void sendMessageWithResult(@NonNull Message message, @Nullable Object result,
            @SatelliteManager.SatelliteResult int error) {
+52 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.telephony.satellite.SatelliteDatagram;
import android.telephony.satellite.SatelliteManager;
import android.telephony.satellite.SatelliteModemEnableRequestAttributes;
import android.telephony.satellite.SatelliteSubscriptionInfo;
import android.telephony.satellite.SystemSelectionSpecifier;
import android.telephony.satellite.stub.NTRadioTechnology;
import android.telephony.satellite.stub.SatelliteModemState;
import android.telephony.satellite.stub.SatelliteResult;
@@ -53,6 +54,7 @@ import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.subscription.SubscriptionManagerService;
import com.android.internal.telephony.util.TelephonyUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
@@ -542,6 +544,56 @@ public class SatelliteServiceUtils {
        return mcc + mnc;
    }

    /**
     * Convert SystemSelectionSpecifier from framework definition to service definition
     * @param systemSelectionSpecifier The SystemSelectionSpecifier from the framework.
     * @return The converted SystemSelectionSpecifier for the satellite service.
     */
    @NonNull public static List<android.telephony.satellite.stub
            .SystemSelectionSpecifier> toSystemSelectionSpecifier(
            @NonNull SystemSelectionSpecifier systemSelectionSpecifier) {
        List<android.telephony.satellite.stub.SystemSelectionSpecifier> converted =
                new ArrayList<>();
        android.telephony.satellite.stub.SystemSelectionSpecifier convertedSpecifier =
                new android.telephony.satellite.stub.SystemSelectionSpecifier();

        convertedSpecifier.mMccMnc = systemSelectionSpecifier.getMccMnc();
        convertedSpecifier.mBands = systemSelectionSpecifier.getBands().toArray();
        convertedSpecifier.mEarfcs = systemSelectionSpecifier.getEarfcs().toArray();
        converted.add(convertedSpecifier);
        return converted;
    }

    /**
     * Expected format of the input dictionary bundle is:
     * <ul>
     *     <li>Key: Regional satellite config Id string.</li>
     *     <li>Value: Integer arrays of earfcns in the corresponding regions."</li>
     * </ul>
     * @return The map of earfcns with key: regional satellite config Id,
     * value: set of earfcns in the corresponding regions.
     */
    @NonNull
    public static Map<String, Set<Integer>> parseRegionalSatelliteEarfcns(
            @Nullable PersistableBundle earfcnsBundle) {
        Map<String, Set<Integer>> earfcnsMap = new HashMap<>();
        if (earfcnsBundle == null || earfcnsBundle.isEmpty()) {
            logd("parseRegionalSatelliteEarfcns: earfcnsBundle is null or empty");
            return earfcnsMap;
        }

        for (String configId : earfcnsBundle.keySet()) {
            Set<Integer> earfcnsSet = new HashSet<>();
            for (int earfcn : earfcnsBundle.getIntArray(configId)) {
                earfcnsSet.add(earfcn);
            }
            logd("parseRegionalSatelliteEarfcns: configId = " + configId + ", earfcns ="
                    + earfcnsSet.stream().map(String::valueOf).collect(joining(",")));
            earfcnsMap.put(configId, earfcnsSet);
        }
        return earfcnsMap;
    }

    private static void logd(@NonNull String log) {
        Rlog.d(TAG, log);
    }