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

Commit 9195feb3 authored by Chen Xu's avatar Chen Xu Committed by Gerrit Code Review
Browse files

Merge "Use portIndex when switching subscription"

parents 8d8f7ee8 e0cf8a77
Loading
Loading
Loading
Loading
+5 −4
Original line number Original line Diff line number Diff line
@@ -493,13 +493,13 @@ public class EuiccConnector extends StateMachine implements ServiceConnection {


    /** Asynchronously switch to the given subscription. */
    /** Asynchronously switch to the given subscription. */
    @VisibleForTesting(visibility = PACKAGE)
    @VisibleForTesting(visibility = PACKAGE)
    public void switchToSubscription(int cardId, @Nullable String iccid, boolean forceDeactivateSim,
    public void switchToSubscription(int cardId, int portIndex, @Nullable String iccid,
            SwitchCommandCallback callback) {
            boolean forceDeactivateSim, SwitchCommandCallback callback) {
        SwitchRequest request = new SwitchRequest();
        SwitchRequest request = new SwitchRequest();
        request.mIccid = iccid;
        request.mIccid = iccid;
        request.mForceDeactivateSim = forceDeactivateSim;
        request.mForceDeactivateSim = forceDeactivateSim;
        request.mCallback = callback;
        request.mCallback = callback;
        sendMessage(CMD_SWITCH_TO_SUBSCRIPTION, cardId, 0 /* arg2 */, request);
        sendMessage(CMD_SWITCH_TO_SUBSCRIPTION, cardId, portIndex, request);
    }
    }


    /** Asynchronously update the nickname of the given subscription. */
    /** Asynchronously update the nickname of the given subscription. */
@@ -838,7 +838,8 @@ public class EuiccConnector extends StateMachine implements ServiceConnection {
                        }
                        }
                        case CMD_SWITCH_TO_SUBSCRIPTION: {
                        case CMD_SWITCH_TO_SUBSCRIPTION: {
                            SwitchRequest request = (SwitchRequest) message.obj;
                            SwitchRequest request = (SwitchRequest) message.obj;
                            mEuiccService.switchToSubscription(slotId, request.mIccid,
                            final int portIndex = message.arg2;
                            mEuiccService.switchToSubscription(slotId, portIndex, request.mIccid,
                                    request.mForceDeactivateSim,
                                    request.mForceDeactivateSim,
                                    new ISwitchToSubscriptionCallback.Stub() {
                                    new ISwitchToSubscriptionCallback.Stub() {
                                        @Override
                                        @Override
+87 −31
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.os.Binder;
import android.os.Binder;
import android.os.Bundle;
import android.os.Bundle;
import android.os.RemoteException;
import android.provider.Settings;
import android.provider.Settings;
import android.service.euicc.DownloadSubscriptionResult;
import android.service.euicc.DownloadSubscriptionResult;
import android.service.euicc.EuiccService;
import android.service.euicc.EuiccService;
@@ -180,6 +181,9 @@ public class EuiccController extends IEuiccController.Stub {
            PendingIntent callbackIntent =
            PendingIntent callbackIntent =
                    resolutionIntent.getParcelableExtra(
                    resolutionIntent.getParcelableExtra(
                            EuiccManager.EXTRA_EMBEDDED_SUBSCRIPTION_RESOLUTION_CALLBACK_INTENT);
                            EuiccManager.EXTRA_EMBEDDED_SUBSCRIPTION_RESOLUTION_CALLBACK_INTENT);
            int portIndex = resolutionIntent.getIntExtra(
                    EuiccService.EXTRA_RESOLUTION_PORT_INDEX, 0);
            resolutionExtras.putInt(EuiccService.EXTRA_RESOLUTION_PORT_INDEX, portIndex);
            op.continueOperation(cardId, resolutionExtras, callbackIntent);
            op.continueOperation(cardId, resolutionExtras, callbackIntent);
        } finally {
        } finally {
            Binder.restoreCallingIdentity(token);
            Binder.restoreCallingIdentity(token);
@@ -417,7 +421,7 @@ public class EuiccController extends IEuiccController.Stub {
                    break;
                    break;
                case EuiccService.RESULT_MUST_DEACTIVATE_SIM:
                case EuiccService.RESULT_MUST_DEACTIVATE_SIM:
                    resultCode = RESOLVABLE_ERROR;
                    resultCode = RESOLVABLE_ERROR;
                    addResolutionIntent(extrasIntent,
                    addResolutionIntentForDefaultPort(extrasIntent,
                            EuiccService.ACTION_RESOLVE_DEACTIVATE_SIM,
                            EuiccService.ACTION_RESOLVE_DEACTIVATE_SIM,
                            mCallingPackage,
                            mCallingPackage,
                            0 /* resolvableErrors */,
                            0 /* resolvableErrors */,
@@ -568,7 +572,8 @@ public class EuiccController extends IEuiccController.Stub {
                Log.i(TAG, "Caller can't manage subscription on target SIM. "
                Log.i(TAG, "Caller can't manage subscription on target SIM. "
                        + "Ask user's consent first");
                        + "Ask user's consent first");
                Intent extrasIntent = new Intent();
                Intent extrasIntent = new Intent();
                addResolutionIntent(extrasIntent, EuiccService.ACTION_RESOLVE_NO_PRIVILEGES,
                addResolutionIntentForDefaultPort(extrasIntent,
                        EuiccService.ACTION_RESOLVE_NO_PRIVILEGES,
                        callingPackage,
                        callingPackage,
                        0 /* resolvableErrors */,
                        0 /* resolvableErrors */,
                        false /* confirmationCodeRetried */,
                        false /* confirmationCodeRetried */,
@@ -624,7 +629,8 @@ public class EuiccController extends IEuiccController.Stub {
                    // The caller can manage the target SIM. Ask the user's consent to deactivate
                    // The caller can manage the target SIM. Ask the user's consent to deactivate
                    // the current SIM.
                    // the current SIM.
                    Intent extrasIntent = new Intent();
                    Intent extrasIntent = new Intent();
                    addResolutionIntent(extrasIntent, EuiccService.ACTION_RESOLVE_DEACTIVATE_SIM,
                    addResolutionIntentForDefaultPort(extrasIntent,
                            EuiccService.ACTION_RESOLVE_DEACTIVATE_SIM,
                            mCallingPackage,
                            mCallingPackage,
                            0 /* resolvableErrors */,
                            0 /* resolvableErrors */,
                            false /* confirmationCodeRetried */,
                            false /* confirmationCodeRetried */,
@@ -706,7 +712,7 @@ public class EuiccController extends IEuiccController.Stub {
                                break;
                                break;
                            case EuiccService.RESULT_MUST_DEACTIVATE_SIM:
                            case EuiccService.RESULT_MUST_DEACTIVATE_SIM:
                                resultCode = RESOLVABLE_ERROR;
                                resultCode = RESOLVABLE_ERROR;
                                addResolutionIntent(extrasIntent,
                                addResolutionIntentForDefaultPort(extrasIntent,
                                        EuiccService.ACTION_RESOLVE_DEACTIVATE_SIM,
                                        EuiccService.ACTION_RESOLVE_DEACTIVATE_SIM,
                                        callingPackage,
                                        callingPackage,
                                        0 /* resolvableErrors */,
                                        0 /* resolvableErrors */,
@@ -727,7 +733,7 @@ public class EuiccController extends IEuiccController.Stub {
                                    retried = true;
                                    retried = true;
                                }
                                }
                                if (result.getResolvableErrors() != 0) {
                                if (result.getResolvableErrors() != 0) {
                                    addResolutionIntent(extrasIntent,
                                    addResolutionIntentForDefaultPort(extrasIntent,
                                            EuiccService.ACTION_RESOLVE_RESOLVABLE_ERRORS,
                                            EuiccService.ACTION_RESOLVE_RESOLVABLE_ERRORS,
                                            callingPackage,
                                            callingPackage,
                                            result.getResolvableErrors(),
                                            result.getResolvableErrors(),
@@ -737,7 +743,7 @@ public class EuiccController extends IEuiccController.Stub {
                                                callingPackage, result.getResolvableErrors()),
                                                callingPackage, result.getResolvableErrors()),
                                            cardId);
                                            cardId);
                                }  else { // Deprecated case
                                }  else { // Deprecated case
                                    addResolutionIntent(extrasIntent,
                                    addResolutionIntentForDefaultPort(extrasIntent,
                                            EuiccService.ACTION_RESOLVE_CONFIRMATION_CODE,
                                            EuiccService.ACTION_RESOLVE_CONFIRMATION_CODE,
                                            callingPackage,
                                            callingPackage,
                                            0 /* resolvableErrors */,
                                            0 /* resolvableErrors */,
@@ -851,7 +857,7 @@ public class EuiccController extends IEuiccController.Stub {
                    break;
                    break;
                case EuiccService.RESULT_MUST_DEACTIVATE_SIM:
                case EuiccService.RESULT_MUST_DEACTIVATE_SIM:
                    resultCode = RESOLVABLE_ERROR;
                    resultCode = RESOLVABLE_ERROR;
                    addResolutionIntent(extrasIntent,
                    addResolutionIntentForDefaultPort(extrasIntent,
                            EuiccService.ACTION_RESOLVE_DEACTIVATE_SIM,
                            EuiccService.ACTION_RESOLVE_DEACTIVATE_SIM,
                            mCallingPackage,
                            mCallingPackage,
                            0 /* resolvableErrors */,
                            0 /* resolvableErrors */,
@@ -959,12 +965,21 @@ public class EuiccController extends IEuiccController.Stub {
    @Override
    @Override
    public void switchToSubscription(int cardId, int subscriptionId, String callingPackage,
    public void switchToSubscription(int cardId, int subscriptionId, String callingPackage,
            PendingIntent callbackIntent) {
            PendingIntent callbackIntent) {
        switchToSubscription(cardId,
        // convert PendingIntent to callback if no callback provided
                subscriptionId, false /* forceDeactivateSim */, callingPackage, callbackIntent);
        IResultCallback callback = getCallbackFromPendingIntent(callbackIntent);
        switchToSubscription(cardId, 0,
                subscriptionId, false /* forceDeactivateSim */, callingPackage, callback);
    }
    }


    void switchToSubscription(int cardId, int subscriptionId, boolean forceDeactivateSim,
    @Override
            String callingPackage, PendingIntent callbackIntent) {
    public void switchToSubscriptionWithPort(int cardId, int portIndex, int subscriptionId,
            String callingPackage, IResultCallback callback) {
        switchToSubscription(cardId, portIndex,
                subscriptionId, false /* forceDeactivateSim */, callingPackage, callback);
    }

    void switchToSubscription(int cardId, int portIndex, int subscriptionId,
            boolean forceDeactivateSim, String callingPackage, IResultCallback callback) {
        boolean callerCanWriteEmbeddedSubscriptions = callerCanWriteEmbeddedSubscriptions();
        boolean callerCanWriteEmbeddedSubscriptions = callerCanWriteEmbeddedSubscriptions();
        mAppOpsManager.checkPackage(Binder.getCallingUid(), callingPackage);
        mAppOpsManager.checkPackage(Binder.getCallingUid(), callingPackage);


@@ -985,7 +1000,7 @@ public class EuiccController extends IEuiccController.Stub {
                    passConsent = true;
                    passConsent = true;
                } else {
                } else {
                    Log.e(TAG, "Not permitted to switch to empty subscription");
                    Log.e(TAG, "Not permitted to switch to empty subscription");
                    sendResult(callbackIntent, ERROR, null /* extrasIntent */);
                    callback.onComplete(ERROR, null);
                    return;
                    return;
                }
                }
                iccid = null;
                iccid = null;
@@ -993,7 +1008,7 @@ public class EuiccController extends IEuiccController.Stub {
                SubscriptionInfo sub = getSubscriptionForSubscriptionId(subscriptionId);
                SubscriptionInfo sub = getSubscriptionForSubscriptionId(subscriptionId);
                if (sub == null) {
                if (sub == null) {
                    Log.e(TAG, "Cannot switch to nonexistent sub: " + subscriptionId);
                    Log.e(TAG, "Cannot switch to nonexistent sub: " + subscriptionId);
                    sendResult(callbackIntent, ERROR, null /* extrasIntent */);
                    callback.onComplete(ERROR, null);
                    return;
                    return;
                }
                }
                if (callerCanWriteEmbeddedSubscriptions) {
                if (callerCanWriteEmbeddedSubscriptions) {
@@ -1001,7 +1016,7 @@ public class EuiccController extends IEuiccController.Stub {
                } else {
                } else {
                    if (!mSubscriptionManager.canManageSubscription(sub, callingPackage)) {
                    if (!mSubscriptionManager.canManageSubscription(sub, callingPackage)) {
                        Log.e(TAG, "Not permitted to switch to sub: " + subscriptionId);
                        Log.e(TAG, "Not permitted to switch to sub: " + subscriptionId);
                        sendResult(callbackIntent, ERROR, null /* extrasIntent */);
                        callback.onComplete(ERROR, null);
                        return;
                        return;
                    }
                    }


@@ -1022,35 +1037,55 @@ public class EuiccController extends IEuiccController.Stub {
                        false /* confirmationCodeRetried */,
                        false /* confirmationCodeRetried */,
                        EuiccOperation.forSwitchNoPrivileges(
                        EuiccOperation.forSwitchNoPrivileges(
                                token, subscriptionId, callingPackage),
                                token, subscriptionId, callingPackage),
                        cardId);
                        cardId, portIndex);
                sendResult(callbackIntent, RESOLVABLE_ERROR, extrasIntent);
                callback.onComplete(RESOLVABLE_ERROR, extrasIntent);
                return;
                return;
            }
            }


            switchToSubscriptionPrivileged(cardId, token, subscriptionId, iccid, forceDeactivateSim,
            switchToSubscriptionPrivileged(cardId, portIndex, token, subscriptionId, iccid,
                    callingPackage, callbackIntent);
                    forceDeactivateSim, callingPackage, callback);
        } catch (RemoteException e) {
            Log.e(TAG, "Cannot run callback.onComplete due to RemoteException e=" + e);
        } finally {
        } finally {
            Binder.restoreCallingIdentity(token);
            Binder.restoreCallingIdentity(token);
        }
        }
    }
    }


    void switchToSubscriptionPrivileged(int cardId, final long callingToken, int subscriptionId,
    /**
            boolean forceDeactivateSim, final String callingPackage,
     *
            final PendingIntent callbackIntent) {
     * Create callback object which sends a given PendingIntent in the onComplete method.
     * This is used for compatibility between the old API which uses PendingIntents, and the new
     * API which uses Executors and Callbacks.
     * @param pi the PendingIntent to send
     * @return the callback
     */
    public IResultCallback getCallbackFromPendingIntent(PendingIntent pi) {
        return new IResultCallback.Stub() {
            @Override
            public void onComplete(int result, Intent resultIntent) {
                sendResult(pi, result, resultIntent);
            }
        };
    }

    void switchToSubscriptionPrivileged(int cardId, int portIndex, final long callingToken,
            int subscriptionId, boolean forceDeactivateSim, final String callingPackage,
            final IResultCallback callback) {
        String iccid = null;
        String iccid = null;
        SubscriptionInfo sub = getSubscriptionForSubscriptionId(subscriptionId);
        SubscriptionInfo sub = getSubscriptionForSubscriptionId(subscriptionId);
        if (sub != null) {
        if (sub != null) {
            iccid = sub.getIccId();
            iccid = sub.getIccId();
        }
        }
        switchToSubscriptionPrivileged(cardId, callingToken, subscriptionId, iccid,
        switchToSubscriptionPrivileged(cardId, portIndex, callingToken, subscriptionId, iccid,
                forceDeactivateSim, callingPackage, callbackIntent);
                forceDeactivateSim, callingPackage, callback);
    }
    }


    void switchToSubscriptionPrivileged(int cardId, final long callingToken, int subscriptionId,
    void switchToSubscriptionPrivileged(int cardId, int portIndex, final long callingToken,
            @Nullable String iccid, boolean forceDeactivateSim, final String callingPackage,
            int subscriptionId, @Nullable String iccid, boolean forceDeactivateSim,
            final PendingIntent callbackIntent) {
            final String callingPackage, final IResultCallback callback) {
        mConnector.switchToSubscription(
        mConnector.switchToSubscription(
                cardId,
                cardId,
                portIndex,
                iccid,
                iccid,
                forceDeactivateSim,
                forceDeactivateSim,
                new EuiccConnector.SwitchCommandCallback() {
                new EuiccConnector.SwitchCommandCallback() {
@@ -1071,20 +1106,31 @@ public class EuiccController extends IEuiccController.Stub {
                                        false /* confirmationCodeRetried */,
                                        false /* confirmationCodeRetried */,
                                        EuiccOperation.forSwitchDeactivateSim(
                                        EuiccOperation.forSwitchDeactivateSim(
                                                callingToken, subscriptionId, callingPackage),
                                                callingToken, subscriptionId, callingPackage),
                                        cardId);
                                        cardId, portIndex);
                                break;
                                break;
                            default:
                            default:
                                resultCode = ERROR;
                                resultCode = ERROR;
                                addExtrasToResultIntent(extrasIntent, result);
                                addExtrasToResultIntent(extrasIntent, result);
                                break;
                                break;
                        }
                        }

                        try {
                        sendResult(callbackIntent, resultCode, extrasIntent);
                            callback.onComplete(resultCode, extrasIntent);
                        } catch (RemoteException e) {
                            Log.e(TAG, "onSwitchComplete: "
                                    + "Cannot run callback.onComplete due to RemoteException e="
                                    + e);
                        }
                    }
                    }


                    @Override
                    @Override
                    public void onEuiccServiceUnavailable() {
                    public void onEuiccServiceUnavailable() {
                        sendResult(callbackIntent, ERROR, null /* extrasIntent */);
                        try {
                            callback.onComplete(ERROR, null);
                        } catch (RemoteException e) {
                            Log.e(TAG, "EuiccService is unavailable. "
                                    + "Cannot run callback.onComplete due to RemoteException e="
                                    + e);
                        }
                    }
                    }
                });
                });
    }
    }
@@ -1279,11 +1325,20 @@ public class EuiccController extends IEuiccController.Stub {
        }
        }
    }
    }


    /** Add a resolution intent to the given extras intent with the default port index 0 */
    public void addResolutionIntentForDefaultPort(Intent extrasIntent, String resolutionAction,
            String callingPackage, int resolvableErrors, boolean confirmationCodeRetried,
            EuiccOperation op, int cardId) {
        // use the default port 0 when not specified
        addResolutionIntent(extrasIntent, resolutionAction, callingPackage, resolvableErrors,
                confirmationCodeRetried, op, cardId, TelephonyManager.DEFAULT_PORT_INDEX);
    }

    /** Add a resolution intent to the given extras intent. */
    /** Add a resolution intent to the given extras intent. */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    public void addResolutionIntent(Intent extrasIntent, String resolutionAction,
    public void addResolutionIntent(Intent extrasIntent, String resolutionAction,
            String callingPackage, int resolvableErrors, boolean confirmationCodeRetried,
            String callingPackage, int resolvableErrors, boolean confirmationCodeRetried,
            EuiccOperation op, int cardId) {
            EuiccOperation op, int cardId, int portIndex) {
        Intent intent = new Intent(EuiccManager.ACTION_RESOLVE_ERROR);
        Intent intent = new Intent(EuiccManager.ACTION_RESOLVE_ERROR);
        intent.setPackage(RESOLUTION_ACTIVITY_PACKAGE_NAME);
        intent.setPackage(RESOLUTION_ACTIVITY_PACKAGE_NAME);
        intent.setComponent(new ComponentName(
        intent.setComponent(new ComponentName(
@@ -1293,6 +1348,7 @@ public class EuiccController extends IEuiccController.Stub {
        intent.putExtra(EuiccService.EXTRA_RESOLUTION_CALLING_PACKAGE, callingPackage);
        intent.putExtra(EuiccService.EXTRA_RESOLUTION_CALLING_PACKAGE, callingPackage);
        intent.putExtra(EuiccService.EXTRA_RESOLVABLE_ERRORS, resolvableErrors);
        intent.putExtra(EuiccService.EXTRA_RESOLVABLE_ERRORS, resolvableErrors);
        intent.putExtra(EuiccService.EXTRA_RESOLUTION_CARD_ID, cardId);
        intent.putExtra(EuiccService.EXTRA_RESOLUTION_CARD_ID, cardId);
        intent.putExtra(EuiccService.EXTRA_RESOLUTION_PORT_INDEX, portIndex);
        intent.putExtra(EuiccService.EXTRA_RESOLUTION_CONFIRMATION_CODE_RETRIED,
        intent.putExtra(EuiccService.EXTRA_RESOLUTION_CONFIRMATION_CODE_RETRIED,
                confirmationCodeRetried);
                confirmationCodeRetried);
        intent.putExtra(EXTRA_OPERATION, op);
        intent.putExtra(EXTRA_OPERATION, op);
+24 −10
Original line number Original line Diff line number Diff line
@@ -302,16 +302,26 @@ public class EuiccOperation implements Parcelable {
                        resolutionExtras.getBoolean(EuiccService.EXTRA_RESOLUTION_CONSENT),
                        resolutionExtras.getBoolean(EuiccService.EXTRA_RESOLUTION_CONSENT),
                        callbackIntent);
                        callbackIntent);
                break;
                break;
            case ACTION_SWITCH_DEACTIVATE_SIM:
            case ACTION_SWITCH_DEACTIVATE_SIM: {
                resolvedSwitchDeactivateSim(cardId,
                // get portIndex from original operation
                final int portIndex = resolutionExtras.getInt(
                        EuiccService.EXTRA_RESOLUTION_PORT_INDEX,
                        0);
                resolvedSwitchDeactivateSim(cardId, portIndex,
                        resolutionExtras.getBoolean(EuiccService.EXTRA_RESOLUTION_CONSENT),
                        resolutionExtras.getBoolean(EuiccService.EXTRA_RESOLUTION_CONSENT),
                        callbackIntent);
                        callbackIntent);
                break;
                break;
            case ACTION_SWITCH_NO_PRIVILEGES:
            }
                resolvedSwitchNoPrivileges(cardId,
            case ACTION_SWITCH_NO_PRIVILEGES: {
                // get portIndex from original operation
                final int portIndex = resolutionExtras.getInt(
                        EuiccService.EXTRA_RESOLUTION_PORT_INDEX,
                        0);
                resolvedSwitchNoPrivileges(cardId, portIndex,
                        resolutionExtras.getBoolean(EuiccService.EXTRA_RESOLUTION_CONSENT),
                        resolutionExtras.getBoolean(EuiccService.EXTRA_RESOLUTION_CONSENT),
                        callbackIntent);
                        callbackIntent);
                break;
                break;
            }
            default:
            default:
                Log.wtf(TAG, "Unknown action: " + mAction);
                Log.wtf(TAG, "Unknown action: " + mAction);
                break;
                break;
@@ -482,24 +492,26 @@ public class EuiccOperation implements Parcelable {
        }
        }
    }
    }


    private void resolvedSwitchDeactivateSim(int cardId, boolean consent,
    private void resolvedSwitchDeactivateSim(int cardId, int portIndex, boolean consent,
            PendingIntent callbackIntent) {
            PendingIntent callbackIntent) {
        if (consent) {
        if (consent) {
            // User has consented; perform the switch, but this time, tell the LPA to deactivate any
            // User has consented; perform the switch, but this time, tell the LPA to deactivate any
            // required active SIMs.
            // required active SIMs.
            EuiccController.get().switchToSubscription(
            EuiccController euiccController = EuiccController.get();
            euiccController.switchToSubscription(
                    cardId,
                    cardId,
                    portIndex,
                    mSubscriptionId,
                    mSubscriptionId,
                    true /* forceDeactivateSim */,
                    true /* forceDeactivateSim */,
                    mCallingPackage,
                    mCallingPackage,
                    callbackIntent);
                    euiccController.getCallbackFromPendingIntent(callbackIntent));
        } else {
        } else {
            // User has not consented; fail the operation.
            // User has not consented; fail the operation.
            fail(callbackIntent);
            fail(callbackIntent);
        }
        }
    }
    }


    private void resolvedSwitchNoPrivileges(int cardId, boolean consent,
    private void resolvedSwitchNoPrivileges(int cardId, int portIndex, boolean consent,
            PendingIntent callbackIntent) {
            PendingIntent callbackIntent) {
        if (consent) {
        if (consent) {
            // User has consented; perform the switch with full privileges.
            // User has consented; perform the switch with full privileges.
@@ -511,13 +523,15 @@ public class EuiccOperation implements Parcelable {
                // carrier. Also note that in practice, we'd need to deactivate the active SIM to
                // carrier. Also note that in practice, we'd need to deactivate the active SIM to
                // even reach this point, because we cannot fetch the metadata needed to check the
                // even reach this point, because we cannot fetch the metadata needed to check the
                // privileges without doing so.
                // privileges without doing so.
                EuiccController.get().switchToSubscriptionPrivileged(
                EuiccController euiccController = EuiccController.get();
                euiccController.switchToSubscriptionPrivileged(
                        cardId,
                        cardId,
                        portIndex,
                        token,
                        token,
                        mSubscriptionId,
                        mSubscriptionId,
                        true /* forceDeactivateSim */,
                        true /* forceDeactivateSim */,
                        mCallingPackage,
                        mCallingPackage,
                        callbackIntent);
                        euiccController.getCallbackFromPendingIntent(callbackIntent));
            } finally {
            } finally {
                Binder.restoreCallingIdentity(token);
                Binder.restoreCallingIdentity(token);
            }
            }
+2 −1
Original line number Original line Diff line number Diff line
@@ -68,6 +68,7 @@ public class EuiccConnectorTest extends TelephonyTest {
    @Mock private IEuiccService.Stub mEuiccService;
    @Mock private IEuiccService.Stub mEuiccService;


    private static final int CARD_ID = 15;
    private static final int CARD_ID = 15;
    private static final int PORT_INDEX = 0;


    @Before
    @Before
    public void setUp() throws Exception {
    public void setUp() throws Exception {
@@ -137,7 +138,7 @@ public class EuiccConnectorTest extends TelephonyTest {
                false /* hasPriority */);
                false /* hasPriority */);
        mConnector = new EuiccConnector(mContext, mLooper.getLooper());
        mConnector = new EuiccConnector(mContext, mLooper.getLooper());
        final AtomicBoolean called = new AtomicBoolean(false);
        final AtomicBoolean called = new AtomicBoolean(false);
        mConnector.switchToSubscription(CARD_ID, "12345", true, new
        mConnector.switchToSubscription(CARD_ID, PORT_INDEX, "12345", true, new
                EuiccConnector.SwitchCommandCallback() {
                EuiccConnector.SwitchCommandCallback() {
            @Override
            @Override
            public void onSwitchComplete(int result) {
            public void onSwitchComplete(int result) {
+21 −17
Original line number Original line Diff line number Diff line
@@ -118,6 +118,7 @@ public class EuiccControllerTest extends TelephonyTest {
    private static final int SUBSCRIPTION_ID = 12345;
    private static final int SUBSCRIPTION_ID = 12345;
    private static final String ICC_ID = "54321";
    private static final String ICC_ID = "54321";
    private static final int CARD_ID = 25;
    private static final int CARD_ID = 25;
    private static final int PORT_INDEX = 0;


    @Mock private EuiccConnector mMockConnector;
    @Mock private EuiccConnector mMockConnector;
    private TestEuiccController mController;
    private TestEuiccController mController;
@@ -148,7 +149,7 @@ public class EuiccControllerTest extends TelephonyTest {
        public void addResolutionIntent(
        public void addResolutionIntent(
                Intent extrasIntent, String resolutionAction, String callingPackage,
                Intent extrasIntent, String resolutionAction, String callingPackage,
                int resolvableErrors, boolean confirmationCodeRetried, EuiccOperation op,
                int resolvableErrors, boolean confirmationCodeRetried, EuiccOperation op,
                int cardId) {
                int cardId, int portIndex) {
            mResolutionAction = resolutionAction;
            mResolutionAction = resolutionAction;
            mOp = op;
            mOp = op;
        }
        }
@@ -765,8 +766,8 @@ public class EuiccControllerTest extends TelephonyTest {
                "whatever" /* callingPackage */);
                "whatever" /* callingPackage */);
        verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_ERROR,
        verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_ERROR,
                0 /* detailedCode */);
                0 /* detailedCode */);
        verify(mMockConnector, never()).switchToSubscription(anyInt(), anyString(), anyBoolean(),
        verify(mMockConnector, never()).switchToSubscription(anyInt(), anyInt(), anyString(),
                any());
                anyBoolean(), any());
    }
    }


    @Test
    @Test
@@ -777,8 +778,8 @@ public class EuiccControllerTest extends TelephonyTest {
                0 /* result */, "whatever" /* callingPackage */);
                0 /* result */, "whatever" /* callingPackage */);
        verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_ERROR,
        verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_ERROR,
                0 /* detailedCode */);
                0 /* detailedCode */);
        verify(mMockConnector, never()).switchToSubscription(anyInt(), anyString(), anyBoolean(),
        verify(mMockConnector, never()).switchToSubscription(anyInt(), anyInt(), anyString(),
                any());
                anyBoolean(), any());
    }
    }


    @Test
    @Test
@@ -790,7 +791,8 @@ public class EuiccControllerTest extends TelephonyTest {
                "whatever" /* callingPackage */);
                "whatever" /* callingPackage */);
        verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_ERROR,
        verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_ERROR,
                0 /* detailedCode */);
                0 /* detailedCode */);
        verify(mMockConnector).switchToSubscription(anyInt(), anyString(), anyBoolean(), any());
        verify(mMockConnector).switchToSubscription(anyInt(), anyInt(), anyString(), anyBoolean(),
                any());
    }
    }


    @Test
    @Test
@@ -832,8 +834,8 @@ public class EuiccControllerTest extends TelephonyTest {
                "whatever" /* callingPackage */);
                "whatever" /* callingPackage */);
        verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_ERROR,
        verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_ERROR,
                0 /* detailedCode */);
                0 /* detailedCode */);
        verify(mMockConnector, never()).switchToSubscription(anyInt(), anyString(), anyBoolean(),
        verify(mMockConnector, never()).switchToSubscription(anyInt(), anyInt(), anyString(),
                any());
                anyBoolean(), any());
    }
    }


    @Test
    @Test
@@ -868,8 +870,8 @@ public class EuiccControllerTest extends TelephonyTest {
                SUBSCRIPTION_ID, ICC_ID, false /* complete */, 0 /* result */, PACKAGE_NAME);
                SUBSCRIPTION_ID, ICC_ID, false /* complete */, 0 /* result */, PACKAGE_NAME);
        verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR,
        verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR,
                0 /* detailedCode */);
                0 /* detailedCode */);
        verify(mMockConnector, never()).switchToSubscription(anyInt(), anyString(), anyBoolean(),
        verify(mMockConnector, never()).switchToSubscription(anyInt(), anyInt(), anyString(),
                any());
                anyBoolean(), any());
        verifyResolutionIntent(EuiccService.ACTION_RESOLVE_NO_PRIVILEGES,
        verifyResolutionIntent(EuiccService.ACTION_RESOLVE_NO_PRIVILEGES,
                EuiccOperation.ACTION_SWITCH_NO_PRIVILEGES);
                EuiccOperation.ACTION_SWITCH_NO_PRIVILEGES);
    }
    }
@@ -885,8 +887,8 @@ public class EuiccControllerTest extends TelephonyTest {
                SUBSCRIPTION_ID, ICC_ID, false /* complete */, 0 /* result */, PACKAGE_NAME);
                SUBSCRIPTION_ID, ICC_ID, false /* complete */, 0 /* result */, PACKAGE_NAME);
        verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR,
        verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR,
                0 /* detailedCode */);
                0 /* detailedCode */);
        verify(mMockConnector, never()).switchToSubscription(anyInt(), anyString(), anyBoolean(),
        verify(mMockConnector, never()).switchToSubscription(anyInt(), anyInt(), anyString(),
                any());
                anyBoolean(), any());
        verifyResolutionIntent(EuiccService.ACTION_RESOLVE_NO_PRIVILEGES,
        verifyResolutionIntent(EuiccService.ACTION_RESOLVE_NO_PRIVILEGES,
                EuiccOperation.ACTION_SWITCH_NO_PRIVILEGES);
                EuiccOperation.ACTION_SWITCH_NO_PRIVILEGES);
    }
    }
@@ -902,8 +904,8 @@ public class EuiccControllerTest extends TelephonyTest {
                SUBSCRIPTION_ID, ICC_ID, false /* complete */, 0 /* result */, PACKAGE_NAME);
                SUBSCRIPTION_ID, ICC_ID, false /* complete */, 0 /* result */, PACKAGE_NAME);
        verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR,
        verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR,
                0 /* detailedCode */);
                0 /* detailedCode */);
        verify(mMockConnector, never()).switchToSubscription(anyInt(), anyString(), anyBoolean(),
        verify(mMockConnector, never()).switchToSubscription(anyInt(), anyInt(), anyString(),
                any());
                anyBoolean(), any());
        verifyResolutionIntent(EuiccService.ACTION_RESOLVE_NO_PRIVILEGES,
        verifyResolutionIntent(EuiccService.ACTION_RESOLVE_NO_PRIVILEGES,
                EuiccOperation.ACTION_SWITCH_NO_PRIVILEGES);
                EuiccOperation.ACTION_SWITCH_NO_PRIVILEGES);
    }
    }
@@ -1383,7 +1385,7 @@ public class EuiccControllerTest extends TelephonyTest {
            @Override
            @Override
            public Void answer(InvocationOnMock invocation) throws Exception {
            public Void answer(InvocationOnMock invocation) throws Exception {
                EuiccConnector.SwitchCommandCallback cb = invocation
                EuiccConnector.SwitchCommandCallback cb = invocation
                        .getArgument(3 /* resultCallback */);
                        .getArgument(4 /* resultCallback */);
                if (complete) {
                if (complete) {
                    cb.onSwitchComplete(result);
                    cb.onSwitchComplete(result);
                } else {
                } else {
@@ -1391,8 +1393,10 @@ public class EuiccControllerTest extends TelephonyTest {
                }
                }
                return null;
                return null;
            }
            }
        }).when(mMockConnector).switchToSubscription(anyInt(), eq(iccid), anyBoolean(), any());
        }).when(mMockConnector).switchToSubscription(anyInt(), anyInt(), eq(iccid), anyBoolean(),
        mController.switchToSubscription(CARD_ID, subscriptionId, callingPackage, resultCallback);
                any());
        mController.switchToSubscription(CARD_ID, subscriptionId, callingPackage,
                resultCallback);
    }
    }


    private void callUpdateSubscriptionNickname(int subscriptionId, String iccid, String nickname,
    private void callUpdateSubscriptionNickname(int subscriptionId, String iccid, String nickname,