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

Commit e59c2cf3 authored by Holly Jiuyu Sun's avatar Holly Jiuyu Sun Committed by Gerrit Code Review
Browse files

Merge "Carrier confirmation code."

parents 67c73499 f203ed03
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -411,6 +411,15 @@ public class EuiccController extends IEuiccController.Stub {
                                                callingToken, subscription, switchAfterDownload,
                                                callingPackage));
                                break;
                            case EuiccService.RESULT_NEED_CONFIRMATION_CODE:
                                resultCode = RESOLVABLE_ERROR;
                                addResolutionIntent(extrasIntent,
                                        EuiccService.ACTION_RESOLVE_CONFIRMATION_CODE,
                                        callingPackage,
                                        EuiccOperation.forDownloadConfirmationCode(
                                                callingToken, subscription, switchAfterDownload,
                                                callingPackage));
                                break;
                            default:
                                resultCode = ERROR;
                                extrasIntent.putExtra(
+36 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.os.Parcelable;
import android.service.euicc.EuiccService;
import android.telephony.euicc.DownloadableSubscription;
import android.telephony.euicc.EuiccManager;
import android.text.TextUtils;
import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;
@@ -60,6 +61,7 @@ public class EuiccOperation implements Parcelable {
            ACTION_GET_METADATA_DEACTIVATE_SIM,
            ACTION_DOWNLOAD_DEACTIVATE_SIM,
            ACTION_DOWNLOAD_NO_PRIVILEGES,
            ACTION_DOWNLOAD_CONFIRMATION_CODE,
    })
    @interface Action {}

@@ -75,6 +77,8 @@ public class EuiccOperation implements Parcelable {
    static final int ACTION_SWITCH_DEACTIVATE_SIM = 5;
    @VisibleForTesting
    static final int ACTION_SWITCH_NO_PRIVILEGES = 6;
    @VisibleForTesting
    static final int ACTION_DOWNLOAD_CONFIRMATION_CODE = 7;

    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
    public final @Action int mAction;
@@ -123,6 +127,17 @@ public class EuiccOperation implements Parcelable {
                subscription,  0 /* subscriptionId */, switchAfterDownload, callingPackage);
    }

    /**
     * {@link EuiccManager#downloadSubscription} failed with
     * {@link EuiccService#RESULT_NEED_CONFIRMATION_CODE} error.
     */
    public static EuiccOperation forDownloadConfirmationCode(long callingToken,
            DownloadableSubscription subscription, boolean switchAfterDownload,
            String callingPackage) {
        return new EuiccOperation(ACTION_DOWNLOAD_CONFIRMATION_CODE, callingToken,
                subscription, 0 /* subscriptionId */, switchAfterDownload, callingPackage);
    }

    static EuiccOperation forGetDefaultListDeactivateSim(long callingToken, String callingPackage) {
        return new EuiccOperation(ACTION_GET_DEFAULT_LIST_DEACTIVATE_SIM, callingToken,
                null /* downloadableSubscription */, 0 /* subscriptionId */,
@@ -205,6 +220,11 @@ public class EuiccOperation implements Parcelable {
                        resolutionExtras.getBoolean(EuiccService.RESOLUTION_EXTRA_CONSENT),
                        callbackIntent);
                break;
            case ACTION_DOWNLOAD_CONFIRMATION_CODE:
                resolvedDownloadConfirmationCode(
                        resolutionExtras.getString(EuiccService.RESOLUTION_EXTRA_CONFIRMATION_CODE),
                        callbackIntent);
                break;
            case ACTION_GET_DEFAULT_LIST_DEACTIVATE_SIM:
                resolvedGetDefaultListDeactivateSim(
                        resolutionExtras.getBoolean(EuiccService.RESOLUTION_EXTRA_CONSENT),
@@ -284,6 +304,22 @@ public class EuiccOperation implements Parcelable {
        }
    }

    private void resolvedDownloadConfirmationCode(String confirmationCode,
            PendingIntent callbackIntent) {
        if (TextUtils.isEmpty(confirmationCode)) {
            fail(callbackIntent);
        } else {
            mDownloadableSubscription.setConfirmationCode(confirmationCode);
            EuiccController.get()
                    .downloadSubscription(
                            mDownloadableSubscription,
                            mSwitchAfterDownload,
                            mCallingPackage,
                            true /* forceDeactivateSim */,
                            callbackIntent);
        }
    }

    private void resolvedGetDefaultListDeactivateSim(
            boolean consent, PendingIntent callbackIntent) {
        if (consent) {
+11 −0
Original line number Diff line number Diff line
@@ -349,6 +349,17 @@ public class EuiccControllerTest extends TelephonyTest {
                EuiccOperation.ACTION_DOWNLOAD_DEACTIVATE_SIM);
    }

    @Test
    public void testDownloadSubscription_needConfirmationCode() throws Exception {
        setHasWriteEmbeddedPermission(true);
        callDownloadSubscription(SUBSCRIPTION, false /* switchAfterDownload */, true /* complete */,
                EuiccService.RESULT_NEED_CONFIRMATION_CODE, "whatever" /* callingPackage */);
        verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR,
                0 /* detailedCode */);
        verifyResolutionIntent(EuiccService.ACTION_RESOLVE_CONFIRMATION_CODE,
                EuiccOperation.ACTION_DOWNLOAD_CONFIRMATION_CODE);
    }

    @Test
    public void testDownloadSubscription_success() throws Exception {
        setHasWriteEmbeddedPermission(true);