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

Commit 1f85a3dd authored by Jordan Liu's avatar Jordan Liu
Browse files

Add UNINITIALIZED and rename INVALID

UNINITIALIZED_CARD_ID is for before the card ID is ready.
INVALID_CARD_ID is renamed to UNSUPPORTED_CARD_ID and it is used if the
card ID is known to be unsupported.

Bug: 122978614
Test: atest UiccControllerTest
Change-Id: Ia2315d9b38ef35b30d9b96b6436c08fa4404e4df
Merged-In: Ia2315d9b38ef35b30d9b96b6436c08fa4404e4df
parent 3d834a0e
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -43150,7 +43150,6 @@ package android.telephony {
    field public static final String EXTRA_STATE_RINGING;
    field public static final String EXTRA_SUBSCRIPTION_ID = "android.telephony.extra.SUBSCRIPTION_ID";
    field public static final String EXTRA_VOICEMAIL_NUMBER = "android.telephony.extra.VOICEMAIL_NUMBER";
    field public static final int INVALID_CARD_ID = -1; // 0xffffffff
    field public static final String METADATA_HIDE_VOICEMAIL_SETTINGS_MENU = "android.telephony.HIDE_VOICEMAIL_SETTINGS_MENU";
    field public static final int NETWORK_TYPE_1xRTT = 7; // 0x7
    field public static final int NETWORK_TYPE_CDMA = 4; // 0x4
@@ -43186,7 +43185,9 @@ package android.telephony {
    field public static final int SIM_STATE_PUK_REQUIRED = 3; // 0x3
    field public static final int SIM_STATE_READY = 5; // 0x5
    field public static final int SIM_STATE_UNKNOWN = 0; // 0x0
    field public static final int UNINITIALIZED_CARD_ID = -2; // 0xfffffffe
    field public static final int UNKNOWN_CARRIER_ID = -1; // 0xffffffff
    field public static final int UNSUPPORTED_CARD_ID = -1; // 0xffffffff
    field public static final int USSD_ERROR_SERVICE_UNAVAIL = -2; // 0xfffffffe
    field public static final int USSD_RETURN_FAILURE = -1; // 0xffffffff
    field public static final String VVM_TYPE_CVVM = "vvm_type_cvvm";
+6 −1
Original line number Diff line number Diff line
@@ -76,6 +76,11 @@ import java.util.concurrent.atomic.AtomicInteger;
 * filter with the appropriate action, the {@link #CATEGORY_EUICC_UI} category, and a non-zero
 * priority.
 *
 * <p>Old implementations of EuiccService may support passing in slot IDs equal to
 * {@link android.telephony.SubscriptionManager#INVALID_SIM_SLOT_INDEX}, which allows the LPA to
 * decide which eUICC to target when there are multiple eUICCs. This behavior is not supported in
 * Android Q or later.
 *
 * @hide
 */
@SystemApi
@@ -520,7 +525,7 @@ public abstract class EuiccService extends Service {
                        int resultCode = EuiccService.this.onDownloadSubscription(
                                slotId, subscription, switchAfterDownload, forceDeactivateSim);
                        result = new DownloadSubscriptionResult(resultCode,
                            0 /* resolvableErrors */, TelephonyManager.INVALID_CARD_ID);
                            0 /* resolvableErrors */, TelephonyManager.UNSUPPORTED_CARD_ID);
                    }
                    try {
                        callback.onComplete(result);
+18 −8
Original line number Diff line number Diff line
@@ -227,10 +227,19 @@ public class TelephonyManager {
    public static final int SRVCC_STATE_HANDOVER_CANCELED  = 3;

    /**
     * An invalid UICC card identifier. See {@link #getCardIdForDefaultEuicc()} and
     * {@link UiccCardInfo#getCardId()}.
     * A UICC card identifier used if the device does not support the operation.
     * For example, {@link #getCardIdForDefaultEuicc()} returns this value if the device has no
     * eUICC, or the eUICC cannot be read.
     */
    public static final int INVALID_CARD_ID = -1;
    public static final int UNSUPPORTED_CARD_ID = -1;

    /**
     * A UICC card identifier used before the UICC card is loaded. See
     * {@link #getCardIdForDefaultEuicc()} and {@link UiccCardInfo#getCardId()}.
     * <p>
     * Note that once the UICC card is loaded, the card ID may become {@link #UNSUPPORTED_CARD_ID}.
     */
    public static final int UNINITIALIZED_CARD_ID = -2;

    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
@@ -3099,24 +3108,25 @@ public class TelephonyManager {
    }

    /**
     * Get the card ID of the default eUICC card. If there is no eUICC, returns
     * {@link #INVALID_CARD_ID}.
     * Get the card ID of the default eUICC card. If the eUICCs have not yet been loaded, returns
     * {@link #UNINITIALIZED_CARD_ID}. If there is no eUICC or the device does not support card IDs
     * for eUICCs, returns {@link #UNSUPPORTED_CARD_ID}.
     *
     * <p>The card ID is a unique identifier associated with a UICC or eUICC card. Card IDs are
     * unique to a device, and always refer to the same UICC or eUICC card unless the device goes
     * through a factory reset.
     *
     * @return card ID of the default eUICC card.
     * @return card ID of the default eUICC card, if loaded.
     */
    public int getCardIdForDefaultEuicc() {
        try {
            ITelephony telephony = getITelephony();
            if (telephony == null) {
                return INVALID_CARD_ID;
                return UNINITIALIZED_CARD_ID;
            }
            return telephony.getCardIdForDefaultEuicc(mSubId, mContext.getOpPackageName());
        } catch (RemoteException e) {
            return INVALID_CARD_ID;
            return UNINITIALIZED_CARD_ID;
        }
    }

+26 −18
Original line number Diff line number Diff line
@@ -305,7 +305,7 @@ public class EuiccManager {
     */
    @Nullable
    public String getEid() {
        if (!refreshCardIdIfInvalid()) {
        if (!refreshCardIdIfUninitialized()) {
            return null;
        }
        try {
@@ -328,7 +328,7 @@ public class EuiccManager {
    @SystemApi
    @RequiresPermission(Manifest.permission.WRITE_EMBEDDED_SUBSCRIPTIONS)
    public int getOtaStatus() {
        if (!refreshCardIdIfInvalid()) {
        if (!refreshCardIdIfUninitialized()) {
            return EUICC_OTA_STATUS_UNAVAILABLE;
        }
        try {
@@ -363,7 +363,7 @@ public class EuiccManager {
    @RequiresPermission(Manifest.permission.WRITE_EMBEDDED_SUBSCRIPTIONS)
    public void downloadSubscription(DownloadableSubscription subscription,
            boolean switchAfterDownload, PendingIntent callbackIntent) {
        if (!refreshCardIdIfInvalid()) {
        if (!refreshCardIdIfUninitialized()) {
            sendUnavailableError(callbackIntent);
            return;
        }
@@ -425,7 +425,7 @@ public class EuiccManager {
    @SystemApi
    @RequiresPermission(Manifest.permission.WRITE_EMBEDDED_SUBSCRIPTIONS)
    public void continueOperation(Intent resolutionIntent, Bundle resolutionExtras) {
        if (!refreshCardIdIfInvalid()) {
        if (!refreshCardIdIfUninitialized()) {
            PendingIntent callbackIntent =
                    resolutionIntent.getParcelableExtra(
                            EuiccManager.EXTRA_EMBEDDED_SUBSCRIPTION_RESOLUTION_CALLBACK_INTENT);
@@ -462,7 +462,7 @@ public class EuiccManager {
    @RequiresPermission(Manifest.permission.WRITE_EMBEDDED_SUBSCRIPTIONS)
    public void getDownloadableSubscriptionMetadata(
            DownloadableSubscription subscription, PendingIntent callbackIntent) {
        if (!refreshCardIdIfInvalid()) {
        if (!refreshCardIdIfUninitialized()) {
            sendUnavailableError(callbackIntent);
            return;
        }
@@ -492,7 +492,7 @@ public class EuiccManager {
    @SystemApi
    @RequiresPermission(Manifest.permission.WRITE_EMBEDDED_SUBSCRIPTIONS)
    public void getDefaultDownloadableSubscriptionList(PendingIntent callbackIntent) {
        if (!refreshCardIdIfInvalid()) {
        if (!refreshCardIdIfUninitialized()) {
            sendUnavailableError(callbackIntent);
            return;
        }
@@ -511,7 +511,7 @@ public class EuiccManager {
     */
    @Nullable
    public EuiccInfo getEuiccInfo() {
        if (!refreshCardIdIfInvalid()) {
        if (!refreshCardIdIfUninitialized()) {
            return null;
        }
        try {
@@ -536,7 +536,7 @@ public class EuiccManager {
     */
    @RequiresPermission(Manifest.permission.WRITE_EMBEDDED_SUBSCRIPTIONS)
    public void deleteSubscription(int subscriptionId, PendingIntent callbackIntent) {
        if (!refreshCardIdIfInvalid()) {
        if (!refreshCardIdIfUninitialized()) {
            sendUnavailableError(callbackIntent);
            return;
        }
@@ -576,7 +576,7 @@ public class EuiccManager {
     */
    @RequiresPermission(Manifest.permission.WRITE_EMBEDDED_SUBSCRIPTIONS)
    public void switchToSubscription(int subscriptionId, PendingIntent callbackIntent) {
        if (!refreshCardIdIfInvalid()) {
        if (!refreshCardIdIfUninitialized()) {
            sendUnavailableError(callbackIntent);
            return;
        }
@@ -602,7 +602,7 @@ public class EuiccManager {
    @RequiresPermission(Manifest.permission.WRITE_EMBEDDED_SUBSCRIPTIONS)
    public void updateSubscriptionNickname(
            int subscriptionId, String nickname, PendingIntent callbackIntent) {
        if (!refreshCardIdIfInvalid()) {
        if (!refreshCardIdIfUninitialized()) {
            sendUnavailableError(callbackIntent);
            return;
        }
@@ -626,7 +626,7 @@ public class EuiccManager {
    @SystemApi
    @RequiresPermission(Manifest.permission.WRITE_EMBEDDED_SUBSCRIPTIONS)
    public void eraseSubscriptions(PendingIntent callbackIntent) {
        if (!refreshCardIdIfInvalid()) {
        if (!refreshCardIdIfUninitialized()) {
            sendUnavailableError(callbackIntent);
            return;
        }
@@ -656,7 +656,7 @@ public class EuiccManager {
     * @hide
     */
    public void retainSubscriptionsForFactoryReset(PendingIntent callbackIntent) {
        if (!refreshCardIdIfInvalid()) {
        if (!refreshCardIdIfUninitialized()) {
            sendUnavailableError(callbackIntent);
            return;
        }
@@ -667,16 +667,24 @@ public class EuiccManager {
        }
    }

    private boolean refreshCardIdIfInvalid() {
        if (!isEnabled()) {
            return false;
        }
        // Refresh mCardId if it's invalid.
        if (mCardId == TelephonyManager.INVALID_CARD_ID) {
    /**
     * Refreshes the cardId if its uninitialized, and returns whether we should continue the
     * operation.
     * <p>
     * Note that after a successful refresh, the mCardId may be TelephonyManager.UNSUPPORTED_CARD_ID
     * on older HALs. For backwards compatability, we continue to the LPA and let it decide which
     * card to use.
     */
    private boolean refreshCardIdIfUninitialized() {
        // Refresh mCardId if its UNINITIALIZED_CARD_ID
        if (mCardId == TelephonyManager.UNINITIALIZED_CARD_ID) {
            TelephonyManager tm = (TelephonyManager)
                    mContext.getSystemService(Context.TELEPHONY_SERVICE);
            mCardId = tm.getCardIdForDefaultEuicc();
        }
        if (mCardId == TelephonyManager.UNINITIALIZED_CARD_ID) {
            return false;
        }
        return true;
    }