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

Commit b65208a4 authored by Hakjun Choi's avatar Hakjun Choi
Browse files

Add new apis for satellite service

Added an api to find whether the subscription ID supports NTN network

Bug: 299232193
Test: atest SubscriptionInfoTest, SubscriptionInfoInternalTest,
SubscriptionDatabaseManagerTest

Change-Id: I21d219203e92fe6242da55306768418c3dddae94
parent 81d07851
Loading
Loading
Loading
Loading
+38 −4
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import android.util.LocalLog;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.flags.FeatureFlags;
import com.android.internal.telephony.uicc.UiccController;
import com.android.internal.util.function.TriConsumer;
import com.android.telephony.Rlog;
@@ -277,8 +278,10 @@ public class SubscriptionDatabaseManager extends Handler {
                    SubscriptionInfoInternal::getSatelliteEnabled),
            new AbstractMap.SimpleImmutableEntry<>(
                    SimInfo.COLUMN_SATELLITE_ATTACH_ENABLED_FOR_CARRIER,
                    SubscriptionInfoInternal::getSatelliteAttachEnabledForCarrier)

                    SubscriptionInfoInternal::getSatelliteAttachEnabledForCarrier),
            new AbstractMap.SimpleImmutableEntry<>(
                    SimInfo.COLUMN_IS_NTN,
                    SubscriptionInfoInternal::getNtn)
    );

    /**
@@ -406,7 +409,10 @@ public class SubscriptionDatabaseManager extends Handler {
                    SubscriptionDatabaseManager::setSatelliteEnabled),
            new AbstractMap.SimpleImmutableEntry<>(
                    SimInfo.COLUMN_SATELLITE_ATTACH_ENABLED_FOR_CARRIER,
                    SubscriptionDatabaseManager::setSatelliteAttachEnabledForCarrier)
                    SubscriptionDatabaseManager::setSatelliteAttachEnabledForCarrier),
            new AbstractMap.SimpleImmutableEntry<>(
                    SimInfo.COLUMN_IS_NTN,
                    SubscriptionDatabaseManager::setNtn)
    );

    /**
@@ -538,6 +544,10 @@ public class SubscriptionDatabaseManager extends Handler {
    @NonNull
    private final Context mContext;

    /** The feature flags */
    @NonNull
    private final FeatureFlags mFeatureFlags;

    /** The callback used for passing events back to {@link SubscriptionManagerService}. */
    @NonNull
    private final SubscriptionDatabaseManagerCallback mCallback;
@@ -628,9 +638,11 @@ public class SubscriptionDatabaseManager extends Handler {
     *
     * @param context The context.
     * @param looper Looper for the handler.
     * @param featureFlags The feature flags.
     * @param callback Subscription database callback.
     */
    public SubscriptionDatabaseManager(@NonNull Context context, @NonNull Looper looper,
            @NonNull FeatureFlags featureFlags,
            @NonNull SubscriptionDatabaseManagerCallback callback) {
        super(looper);
        log("Created SubscriptionDatabaseManager.");
@@ -639,6 +651,7 @@ public class SubscriptionDatabaseManager extends Handler {
        mUiccController = UiccController.getInstance();
        mAsyncMode = mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_subscription_database_async_update);
        mFeatureFlags = featureFlags;
        initializeDatabase();
    }

@@ -2013,6 +2026,23 @@ public class SubscriptionDatabaseManager extends Handler {
                SubscriptionInfoInternal.Builder::setSatelliteAttachEnabledForCarrier);
    }

    /**
     * Set whether the subscription is exclusively used for non-terrestrial networks or not.
     *
     * @param subId Subscription ID.
     * @param isNtn {@code 1} if it is a non-terrestrial network subscription.
     * {@code 0} otherwise.
     *
     * @throws IllegalArgumentException if the subscription does not exist.
     */
    public void setNtn(int subId, int isNtn) {
        if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
            return;
        }
        writeDatabaseAndCacheHelper(subId, SimInfo.COLUMN_IS_NTN, isNtn,
                SubscriptionInfoInternal.Builder::setNtn);
    }

    /**
     * Set whether group of the subscription is disabled. This is only useful if it's a grouped
     * opportunistic subscription. In this case, if all primary (non-opportunistic)
@@ -2273,6 +2303,10 @@ public class SubscriptionDatabaseManager extends Handler {
                .setSatelliteAttachEnabledForCarrier(cursor.getInt(
                        cursor.getColumnIndexOrThrow(
                                SimInfo.COLUMN_SATELLITE_ATTACH_ENABLED_FOR_CARRIER)));
        if (mFeatureFlags.oemEnabledSatelliteFlag()) {
            builder.setNtn(cursor.getInt(cursor.getColumnIndexOrThrow(
                    SimInfo.COLUMN_IS_NTN)));
        }
        return builder.build();
    }

+41 −4
Original line number Diff line number Diff line
@@ -448,6 +448,12 @@ public class SubscriptionInfoInternal {
     */
    private final int mIsSatelliteAttachEnabledForCarrier;

    /**
     * Whether this subscription is used for communicating with non-terrestrial networks.
     * By default, its disabled. It is intended to use integer to fit the database format.
     */
    private final int mIsNtn;

    // Below are the fields that do not exist in the SimInfo table.
    /**
     * The card ID of the SIM card. This maps uniquely to {@link #mCardString}.
@@ -532,6 +538,7 @@ public class SubscriptionInfoInternal {
        this.mIsSatelliteEnabled = builder.mIsSatelliteEnabled;
        this.mIsSatelliteAttachEnabledForCarrier =
                builder.mIsSatelliteAttachEnabledForCarrier;
        this.mIsNtn = builder.mIsNtn;

        // Below are the fields that do not exist in the SimInfo table.
        this.mCardId = builder.mCardId;
@@ -1143,6 +1150,15 @@ public class SubscriptionInfoInternal {
        return mIsSatelliteAttachEnabledForCarrier;
    }

    /**
     * An NTN subscription connects to non-terrestrial networks.
     *
     * @return {@code 1} if the subscription is for non-terrestrial networks. {@code 0} otherwise.
     */
    public int getNtn() {
        return mIsNtn;
    }

    // Below are the fields that do not exist in SimInfo table.
    /**
     * @return The card ID of the SIM card which contains the subscription.
@@ -1212,6 +1228,7 @@ public class SubscriptionInfoInternal {
                .setUiccApplicationsEnabled(mAreUiccApplicationsEnabled != 0)
                .setPortIndex(mPortIndex)
                .setUsageSetting(mUsageSetting)
                .setNtn(mIsNtn == 1)
                .build();
    }

@@ -1269,6 +1286,7 @@ public class SubscriptionInfoInternal {
                + " userId=" + mUserId
                + " isSatelliteEnabled=" + mIsSatelliteEnabled
                + " satellite_attach_enabled_for_carrier=" + mIsSatelliteAttachEnabledForCarrier
                + " getNtn=" + mIsNtn
                + " isGroupDisabled=" + mIsGroupDisabled
                + "]";
    }
@@ -1325,7 +1343,8 @@ public class SubscriptionInfoInternal {
                that.mAllowedNetworkTypesForReasons) && mDeviceToDeviceStatusSharingContacts.equals(
                that.mDeviceToDeviceStatusSharingContacts) && mNumberFromCarrier.equals(
                that.mNumberFromCarrier) && mNumberFromIms.equals(that.mNumberFromIms)
                && mIsSatelliteAttachEnabledForCarrier == that.mIsSatelliteAttachEnabledForCarrier;
                && mIsSatelliteAttachEnabledForCarrier == that.mIsSatelliteAttachEnabledForCarrier
                && mIsNtn == that.mIsNtn;
    }

    @Override
@@ -1347,7 +1366,7 @@ public class SubscriptionInfoInternal {
                mNumberFromCarrier,
                mNumberFromIms, mPortIndex, mUsageSetting, mLastUsedTPMessageReference, mUserId,
                mIsSatelliteEnabled, mCardId, mIsGroupDisabled,
                mIsSatelliteAttachEnabledForCarrier);
                mIsSatelliteAttachEnabledForCarrier, mIsNtn);
        result = 31 * result + Arrays.hashCode(mNativeAccessRules);
        result = 31 * result + Arrays.hashCode(mCarrierConfigAccessRules);
        result = 31 * result + Arrays.hashCode(mRcsConfig);
@@ -1708,12 +1727,17 @@ public class SubscriptionInfoInternal {
        /**
         * Whether satellite is enabled or not.
         */
        private int mIsSatelliteEnabled = -1;
        private int mIsSatelliteEnabled = 0;

        /**
         * Whether satellite attach for carrier is enabled by user.
         */
        private int mIsSatelliteAttachEnabledForCarrier = -1;
        private int mIsSatelliteAttachEnabledForCarrier = 0;

        /**
         * Whether this subscription is used for communicating with non-terrestrial network or not.
         */
        private int mIsNtn = 0;

        // The following fields do not exist in the SimInfo table.
        /**
@@ -1803,6 +1827,7 @@ public class SubscriptionInfoInternal {
            mUserId = info.mUserId;
            mIsSatelliteEnabled = info.mIsSatelliteEnabled;
            mIsSatelliteAttachEnabledForCarrier = info.mIsSatelliteAttachEnabledForCarrier;
            mIsNtn = info.mIsNtn;
            // Below are the fields that do not exist in the SimInfo table.
            mCardId = info.mCardId;
            mIsGroupDisabled = info.mIsGroupDisabled;
@@ -2686,6 +2711,18 @@ public class SubscriptionInfoInternal {
            return this;
        }

        /**
         * Set whether the subscription is for NTN or not.
         *
         * @param isNtn {@code 1} if the subscription is for NTN, {@code 0} otherwise.
         * @return The builder.
         */
        @NonNull
        public Builder setNtn(int isNtn) {
            mIsNtn = isNtn;
            return this;
        }

        // Below are the fields that do not exist in the SimInfo table.
        /**
         * Set the card ID of the SIM card which contains the subscription.
+52 −2
Original line number Diff line number Diff line
@@ -175,7 +175,8 @@ public class SubscriptionManagerService extends ISub.Stub {
            SimInfo.COLUMN_D2D_STATUS_SHARING_SELECTED_CONTACTS,
            SimInfo.COLUMN_NR_ADVANCED_CALLING_ENABLED,
            SimInfo.COLUMN_SATELLITE_ENABLED,
            SimInfo.COLUMN_SATELLITE_ATTACH_ENABLED_FOR_CARRIER
            SimInfo.COLUMN_SATELLITE_ATTACH_ENABLED_FOR_CARRIER,
            SimInfo.COLUMN_IS_NTN
    );

    /**
@@ -488,7 +489,8 @@ public class SubscriptionManagerService extends ISub.Stub {
        HandlerThread handlerThread = new HandlerThread(LOG_TAG);
        handlerThread.start();
        mSubscriptionDatabaseManager = new SubscriptionDatabaseManager(context,
                handlerThread.getLooper(), new SubscriptionDatabaseManagerCallback(mHandler::post) {
                handlerThread.getLooper(), mFeatureFlags,
                new SubscriptionDatabaseManagerCallback(mHandler::post) {
                    /**
                     * Called when database has been loaded into the cache.
                     */
@@ -825,6 +827,26 @@ public class SubscriptionManagerService extends ISub.Stub {
        }
    }

    /**
     * Set whether the subscription ID supports oem satellite or not.
     *
     * @param subId The subscription ID.
     * @param isNtn {@code true} Requested subscription ID supports oem satellite service,
     * {@code false} otherwise.
     */
    public void setNtn(int subId, boolean isNtn) {
        if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
            return;
        }

        // This can throw IllegalArgumentException if the subscription does not exist.
        try {
            mSubscriptionDatabaseManager.setNtn(subId, (isNtn ? 1 : 0));
        } catch (IllegalArgumentException e) {
            loge("setNtn: invalid subId=" + subId);
        }
    }

    /**
     * Set ISO country code by subscription id.
     *
@@ -1120,6 +1142,9 @@ public class SubscriptionManagerService extends ISub.Stub {
                        String mnc = cid.getMnc();
                        builder.setMcc(mcc);
                        builder.setMnc(mnc);
                        if (mFeatureFlags.oemEnabledSatelliteFlag()) {
                            builder.setNtn(isSatellitePlmn(mcc + mnc) ? 1 : 0);
                        }
                    }
                    // If cardId = unsupported or un-initialized, we have no reason to update DB.
                    // Additionally, if the device does not support cardId for default eUICC, the
@@ -1391,6 +1416,7 @@ public class SubscriptionManagerService extends ISub.Stub {
                            MccTable.updateMccMncConfiguration(mContext, mccMnc);
                        }
                        setMccMnc(subId, mccMnc);
                        setNtn(subId, isSatellitePlmn(mccMnc));
                    } else {
                        loge("updateSubscription: mcc/mnc is empty");
                    }
@@ -3958,6 +3984,30 @@ public class SubscriptionManagerService extends ISub.Stub {
                .collect(Collectors.joining(", ")) + "]";
    }

    /**
     * @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_esim_identifier", {@code false} otherwise.
     */
    private boolean isSatellitePlmn(@NonNull String mccMnc) {
        if (!mFeatureFlags.oemEnabledSatelliteFlag()) {
            return false;
        }

        final int id = R.string.config_satellite_esim_identifier;
        String overlayMccMnc = null;
        try {
            overlayMccMnc = mContext.getResources().getString(id);
        } catch (Resources.NotFoundException ex) {
            loge("isSatellitePlmn: id= " + id + ", ex=" + ex);
        }
        if (overlayMccMnc == null) {
            return false;
        } else {
            return mccMnc.equals(overlayMccMnc);
        }
    }

    /**
     * Log debug messages.
     *
+3 −2
Original line number Diff line number Diff line
@@ -128,9 +128,10 @@ public class FakeTelephonyProvider extends MockContentProvider {
                    + "  INTEGER DEFAULT -1,"
                    + Telephony.SimInfo.COLUMN_USER_HANDLE + " INTEGER DEFAULT "
                    + UserHandle.USER_NULL + ","
                    + Telephony.SimInfo.COLUMN_SATELLITE_ENABLED + " INTEGER DEFAULT -1,"
                    + Telephony.SimInfo.COLUMN_SATELLITE_ENABLED + " INTEGER DEFAULT 0,"
                    + Telephony.SimInfo.COLUMN_SATELLITE_ATTACH_ENABLED_FOR_CARRIER
                    + " INTEGER DEFAULT -1"
                    + " INTEGER DEFAULT 0, "
                    + Telephony.SimInfo.COLUMN_IS_NTN + " INTEGER DEFAULT 0"
                    + ");";
        }

+6 −0
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import android.os.Parcel;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;

import com.android.internal.telephony.flags.Flags;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -52,6 +54,7 @@ public class SubscriptionInfoTest {
                .setEhplmns(EHPLMNS)
                .setHplmns(HPLMNS)
                .setCountryIso("us")
                .setNtn(true)
                .build();
    }

@@ -71,6 +74,9 @@ public class SubscriptionInfoTest {
        assertThat(mSubscriptionInfoUT.getSubscriptionId()).isEqualTo(1);
        assertThat(mSubscriptionInfoUT.getSimSlotIndex()).isEqualTo(0);
        assertThat(mSubscriptionInfoUT.getIccId()).isEqualTo("890126042XXXXXXXXXXX");
        if (Flags.oemEnabledSatelliteFlag()) {
            assertThat(mSubscriptionInfoUT.isNtn()).isTrue();
        }
    }

    @Test
Loading