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

Commit fb1c7840 authored by Holly Jiuyu Sun's avatar Holly Jiuyu Sun
Browse files

Add APIs to EuiccCardManager and EuiccCardController.

Move CancelReason from EuiccCard to EuiccCardManager.
part 2.

Bug: 38206971
Test: test on phone
Change-Id: Iab61be59b7130a5336dffbc965eefefcfa3eccf6
parent fa618751
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -510,9 +510,21 @@ java_library {
        "telephony/java/com/android/internal/telephony/ITelephony.aidl",
        "telephony/java/com/android/internal/telephony/ITelephonyRegistry.aidl",
        "telephony/java/com/android/internal/telephony/IWapPushManager.aidl",
        "telephony/java/com/android/internal/telephony/euicc/IAuthenticateServerCallback.aidl",
        "telephony/java/com/android/internal/telephony/euicc/ICancelSessionCallback.aidl",
        "telephony/java/com/android/internal/telephony/euicc/IEuiccCardController.aidl",
        "telephony/java/com/android/internal/telephony/euicc/IEuiccController.aidl",
        "telephony/java/com/android/internal/telephony/euicc/IGetAllProfilesCallback.aidl",
        "telephony/java/com/android/internal/telephony/euicc/IGetEuiccChallengeCallback.aidl",
        "telephony/java/com/android/internal/telephony/euicc/IGetEuiccInfo1Callback.aidl",
        "telephony/java/com/android/internal/telephony/euicc/IGetEuiccInfo2Callback.aidl",
        "telephony/java/com/android/internal/telephony/euicc/IGetRulesAuthTableCallback.aidl",
        "telephony/java/com/android/internal/telephony/euicc/IListNotificationsCallback.aidl",
        "telephony/java/com/android/internal/telephony/euicc/ILoadBoundProfilePackageCallback.aidl",
        "telephony/java/com/android/internal/telephony/euicc/IPrepareDownloadCallback.aidl",
        "telephony/java/com/android/internal/telephony/euicc/IRemoveNotificationFromListCallback.aidl",
        "telephony/java/com/android/internal/telephony/euicc/IRetrieveNotificationCallback.aidl",
        "telephony/java/com/android/internal/telephony/euicc/IRetrieveNotificationListCallback.aidl",
        "wifi/java/android/net/wifi/IWifiManager.aidl",
        "wifi/java/android/net/wifi/aware/IWifiAwareEventCallback.aidl",
        "wifi/java/android/net/wifi/aware/IWifiAwareManager.aidl",
+340 −0
Original line number Diff line number Diff line
@@ -15,14 +15,31 @@
 */
package android.telephony.euicc;

import android.annotation.IntDef;
import android.annotation.Nullable;
import android.content.Context;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.service.euicc.EuiccProfileInfo;
import android.util.Log;

import com.android.internal.telephony.euicc.IAuthenticateServerCallback;
import com.android.internal.telephony.euicc.ICancelSessionCallback;
import com.android.internal.telephony.euicc.IEuiccCardController;
import com.android.internal.telephony.euicc.IGetAllProfilesCallback;
import com.android.internal.telephony.euicc.IGetEuiccChallengeCallback;
import com.android.internal.telephony.euicc.IGetEuiccInfo1Callback;
import com.android.internal.telephony.euicc.IGetEuiccInfo2Callback;
import com.android.internal.telephony.euicc.IGetRulesAuthTableCallback;
import com.android.internal.telephony.euicc.IListNotificationsCallback;
import com.android.internal.telephony.euicc.ILoadBoundProfilePackageCallback;
import com.android.internal.telephony.euicc.IPrepareDownloadCallback;
import com.android.internal.telephony.euicc.IRemoveNotificationFromListCallback;
import com.android.internal.telephony.euicc.IRetrieveNotificationCallback;
import com.android.internal.telephony.euicc.IRetrieveNotificationListCallback;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * EuiccCardManager is the application interface to an eSIM card.
@@ -34,6 +51,35 @@ import com.android.internal.telephony.euicc.IGetAllProfilesCallback;
public class EuiccCardManager {
    private static final String TAG = "EuiccCardManager";

    /** Reason for canceling a profile download session */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(prefix = { "CANCEL_REASON_" }, value = {
            CANCEL_REASON_END_USER_REJECTED,
            CANCEL_REASON_POSTPONED,
            CANCEL_REASON_TIMEOUT,
            CANCEL_REASON_PPR_NOT_ALLOWED
    })
    public @interface CancelReason {}

    /**
     * The end user has rejected the download. The profile will be put into the error state and
     * cannot be downloaded again without the operator's change.
     */
    public static final int CANCEL_REASON_END_USER_REJECTED = 0;

    /** The download has been postponed and can be restarted later. */
    public static final int CANCEL_REASON_POSTPONED = 1;

    /** The download has been timed out and can be restarted later. */
    public static final int CANCEL_REASON_TIMEOUT = 2;

    /**
     * The profile to be downloaded cannot be installed due to its policy rule is not allowed by
     * the RAT (Rules Authorisation Table) on the eUICC or by other installed profiles. The
     * download can be restarted later.
     */
    public static final int CANCEL_REASON_PPR_NOT_ALLOWED = 3;

    /** Result code of execution with no error. */
    public static final int RESULT_OK = 0;

@@ -85,4 +131,298 @@ public class EuiccCardManager {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Gets Rules Authorisation Table.
     *
     * @param callback the callback to get the result code and the rule authorisation table.
     */
    public void getRulesAuthTable(ResultCallback<EuiccRulesAuthTable> callback) {
        try {
            getIEuiccCardController().getRulesAuthTable(mContext.getOpPackageName(),
                    new IGetRulesAuthTableCallback.Stub() {
                        @Override
                        public void onComplete(int resultCode, EuiccRulesAuthTable rat) {
                            callback.onComplete(resultCode, rat);
                        }
                    });
        } catch (RemoteException e) {
            Log.e(TAG, "Error calling getRulesAuthTable", e);
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Gets the eUICC challenge for new profile downloading.
     *
     * @param callback the callback to get the result code and the challenge.
     */
    public void getEuiccChallenge(ResultCallback<byte[]> callback) {
        try {
            getIEuiccCardController().getEuiccChallenge(mContext.getOpPackageName(),
                    new IGetEuiccChallengeCallback.Stub() {
                        @Override
                        public void onComplete(int resultCode, byte[] challenge) {
                            callback.onComplete(resultCode, challenge);
                        }
                    });
        } catch (RemoteException e) {
            Log.e(TAG, "Error calling getEuiccChallenge", e);
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Gets the eUICC info1 defined in GSMA RSP v2.0+ for new profile downloading.
     *
     * @param callback the callback to get the result code and the info1.
     */
    public void getEuiccInfo1(ResultCallback<byte[]> callback) {
        try {
            getIEuiccCardController().getEuiccInfo1(mContext.getOpPackageName(),
                    new IGetEuiccInfo1Callback.Stub() {
                        @Override
                        public void onComplete(int resultCode, byte[] info) {
                            callback.onComplete(resultCode, info);
                        }
                    });
        } catch (RemoteException e) {
            Log.e(TAG, "Error calling getEuiccInfo1", e);
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Gets the eUICC info2 defined in GSMA RSP v2.0+ for new profile downloading.
     *
     * @param callback the callback to get the result code and the info2.
     */
    public void getEuiccInfo2(ResultCallback<byte[]> callback) {
        try {
            getIEuiccCardController().getEuiccInfo2(mContext.getOpPackageName(),
                    new IGetEuiccInfo2Callback.Stub() {
                        @Override
                        public void onComplete(int resultCode, byte[] info) {
                            callback.onComplete(resultCode, info);
                        }
                    });
        } catch (RemoteException e) {
            Log.e(TAG, "Error calling getEuiccInfo2", e);
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Authenticates the SM-DP+ server by the eUICC.
     *
     * @param matchingId the activation code token defined in GSMA RSP v2.0+ or empty when it is not
     *     required.
     * @param serverSigned1 ASN.1 data in byte array signed and returned by the SM-DP+ server.
     * @param serverSignature1 ASN.1 data in byte array indicating a SM-DP+ signature which is
     *     returned by SM-DP+ server.
     * @param euiccCiPkIdToBeUsed ASN.1 data in byte array indicating CI Public Key Identifier to be
     *     used by the eUICC for signature which is returned by SM-DP+ server. This is defined in
     *     GSMA RSP v2.0+.
     * @param serverCertificate ASN.1 data in byte array indicating SM-DP+ Certificate returned by
     *     SM-DP+ server.
     * @param callback the callback to get the result code and a byte array which represents a
     *     {@code AuthenticateServerResponse} defined in GSMA RSP v2.0+.
     */
    public void authenticateServer(String matchingId, byte[] serverSigned1,
            byte[] serverSignature1, byte[] euiccCiPkIdToBeUsed, byte[] serverCertificate,
            ResultCallback<byte[]> callback) {
        try {
            getIEuiccCardController().authenticateServer(
                    mContext.getOpPackageName(),
                    matchingId,
                    serverSigned1,
                    serverSignature1,
                    euiccCiPkIdToBeUsed,
                    serverCertificate,
                    new IAuthenticateServerCallback.Stub() {
                        @Override
                        public void onComplete(int resultCode, byte[] response) {
                            callback.onComplete(resultCode, response);
                        }
                    });
        } catch (RemoteException e) {
            Log.e(TAG, "Error calling authenticateServer", e);
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Prepares the profile download request sent to SM-DP+.
     *
     * @param hashCc the hash of confirmation code. It can be null if there is no confirmation code
     *     required.
     * @param smdpSigned2 ASN.1 data in byte array indicating the data to be signed by the SM-DP+
     *     returned by SM-DP+ server.
     * @param smdpSignature2 ASN.1 data in byte array indicating the SM-DP+ signature returned by
     *     SM-DP+ server.
     * @param smdpCertificate ASN.1 data in byte array indicating the SM-DP+ Certificate returned
     *     by SM-DP+ server.
     * @param callback the callback to get the result code and a byte array which represents a
     *     {@code PrepareDownloadResponse} defined in GSMA RSP v2.0+
     */
    public void prepareDownload(@Nullable byte[] hashCc, byte[] smdpSigned2,
            byte[] smdpSignature2, byte[] smdpCertificate, ResultCallback<byte[]> callback) {
        try {
            getIEuiccCardController().prepareDownload(
                    mContext.getOpPackageName(),
                    hashCc,
                    smdpSigned2,
                    smdpSignature2,
                    smdpCertificate,
                    new IPrepareDownloadCallback.Stub() {
                        @Override
                        public void onComplete(int resultCode, byte[] response) {
                            callback.onComplete(resultCode, response);
                        }
                    });
        } catch (RemoteException e) {
            Log.e(TAG, "Error calling prepareDownload", e);
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Loads a downloaded bound profile package onto the eUICC.
     *
     * @param boundProfilePackage the Bound Profile Package data returned by SM-DP+ server.
     * @param callback the callback to get the result code and a byte array which represents a
     *     {@code LoadBoundProfilePackageResponse} defined in GSMA RSP v2.0+.
     */
    public void loadBoundProfilePackage(byte[] boundProfilePackage,
            ResultCallback<byte[]> callback) {
        try {
            getIEuiccCardController().loadBoundProfilePackage(
                    mContext.getOpPackageName(),
                    boundProfilePackage,
                    new ILoadBoundProfilePackageCallback.Stub() {
                        @Override
                        public void onComplete(int resultCode, byte[] response) {
                            callback.onComplete(resultCode, response);
                        }
                    });
        } catch (RemoteException e) {
            Log.e(TAG, "Error calling loadBoundProfilePackage", e);
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Cancels the current profile download session.
     *
     * @param transactionId the transaction ID returned by SM-DP+ server.
     * @param reason the cancel reason.
     * @param callback the callback to get the result code and an byte[] which represents a
     *     {@code CancelSessionResponse} defined in GSMA RSP v2.0+.
     */
    public void cancelSession(byte[] transactionId, @CancelReason int reason,
            ResultCallback<byte[]> callback) {
        try {
            getIEuiccCardController().cancelSession(
                    mContext.getOpPackageName(),
                    transactionId,
                    reason,
                    new ICancelSessionCallback.Stub() {
                        @Override
                        public void onComplete(int resultCode, byte[] response) {
                            callback.onComplete(resultCode, response);
                        }
                    });
        } catch (RemoteException e) {
            Log.e(TAG, "Error calling cancelSession", e);
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Lists all notifications of the given {@code notificationEvents}.
     *
     * @param events bits of the event types ({@link EuiccNotification.Event}) to list.
     * @param callback the callback to get the result code and the list of notifications.
     */
    public void listNotifications(@EuiccNotification.Event int events,
            ResultCallback<EuiccNotification[]> callback) {
        try {
            getIEuiccCardController().listNotifications(mContext.getOpPackageName(), events,
                    new IListNotificationsCallback.Stub() {
                        @Override
                        public void onComplete(int resultCode, EuiccNotification[] notifications) {
                            callback.onComplete(resultCode, notifications);
                        }
                    });
        } catch (RemoteException e) {
            Log.e(TAG, "Error calling listNotifications", e);
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Retrieves contents of all notification of the given {@code events}.
     *
     * @param events bits of the event types ({@link EuiccNotification.Event}) to list.
     * @param callback the callback to get the result code and the list of notifications.
     */
    public void retrieveNotificationList(@EuiccNotification.Event int events,
            ResultCallback<EuiccNotification[]> callback) {
        try {
            getIEuiccCardController().retrieveNotificationList(mContext.getOpPackageName(), events,
                    new IRetrieveNotificationListCallback.Stub() {
                        @Override
                        public void onComplete(int resultCode, EuiccNotification[] notifications) {
                            callback.onComplete(resultCode, notifications);
                        }
                    });
        } catch (RemoteException e) {
            Log.e(TAG, "Error calling retrieveNotificationList", e);
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Retrieves the content of a notification of the given {@code seqNumber}.
     *
     * @param seqNumber the sequence number of the notification.
     * @param callback the callback to get the result code and the notification.
     */
    public void retrieveNotification(int seqNumber, ResultCallback<EuiccNotification> callback) {
        try {
            getIEuiccCardController().retrieveNotification(mContext.getOpPackageName(), seqNumber,
                    new IRetrieveNotificationCallback.Stub() {
                        @Override
                        public void onComplete(int resultCode, EuiccNotification notification) {
                            callback.onComplete(resultCode, notification);
                        }
                    });
        } catch (RemoteException e) {
            Log.e(TAG, "Error calling retrieveNotification", e);
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Removes a notification from eUICC.
     *
     * @param seqNumber the sequence number of the notification.
     * @param callback the callback to get the result code.
     */
    public void removeNotificationFromList(int seqNumber, ResultCallback<Void> callback) {
        try {
            getIEuiccCardController().removeNotificationFromList(
                    mContext.getOpPackageName(),
                    seqNumber,
                    new IRemoveNotificationFromListCallback.Stub() {
                        @Override
                        public void onComplete(int resultCode) {
                            callback.onComplete(resultCode, null);
                        }
                    });
        } catch (RemoteException e) {
            Log.e(TAG, "Error calling removeNotificationFromList", e);
            throw e.rethrowFromSystemServer();
        }
    }
}
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.telephony.euicc;

parcelable EuiccNotification;
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.telephony.euicc;

parcelable EuiccRulesAuthTable;
 No newline at end of file
+14 −13
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ import java.util.Arrays;
 *
 * TODO(b/35851809): Make this a @SystemApi.
 */
public final class EuiccRat implements Parcelable {
public final class EuiccRulesAuthTable implements Parcelable {
    /** Profile policy rule flags */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(flag = true, prefix = { "POLICY_RULE_FLAG_" }, value = {
@@ -50,7 +50,7 @@ public final class EuiccRat implements Parcelable {
    private final CarrierIdentifier[][] mCarrierIds;
    private final int[] mPolicyRuleFlags;

    /** This is used to build new {@link EuiccRat} instance. */
    /** This is used to build new {@link EuiccRulesAuthTable} instance. */
    public static final class Builder {
        private int[] mPolicyRules;
        private CarrierIdentifier[][] mCarrierIds;
@@ -72,7 +72,7 @@ public final class EuiccRat implements Parcelable {
         * Builds the RAT instance. This builder should not be used anymore after this method is
         * called, otherwise {@link NullPointerException} will be thrown.
         */
        public EuiccRat build() {
        public EuiccRulesAuthTable build() {
            if (mPosition != mPolicyRules.length) {
                throw new IllegalStateException(
                        "Not enough rules are added, expected: "
@@ -80,7 +80,7 @@ public final class EuiccRat implements Parcelable {
                                + ", added: "
                                + mPosition);
            }
            return new EuiccRat(mPolicyRules, mCarrierIds, mPolicyRuleFlags);
            return new EuiccRulesAuthTable(mPolicyRules, mCarrierIds, mPolicyRuleFlags);
        }

        /**
@@ -125,7 +125,8 @@ public final class EuiccRat implements Parcelable {
        return true;
    }

    private EuiccRat(int[] policyRules, CarrierIdentifier[][] carrierIds, int[] policyRuleFlags) {
    private EuiccRulesAuthTable(int[] policyRules, CarrierIdentifier[][] carrierIds,
            int[] policyRuleFlags) {
        mPolicyRules = policyRules;
        mCarrierIds = carrierIds;
        mPolicyRuleFlags = policyRuleFlags;
@@ -207,7 +208,7 @@ public final class EuiccRat implements Parcelable {
            return false;
        }

        EuiccRat that = (EuiccRat) obj;
        EuiccRulesAuthTable that = (EuiccRulesAuthTable) obj;
        if (mCarrierIds.length != that.mCarrierIds.length) {
            return false;
        }
@@ -234,7 +235,7 @@ public final class EuiccRat implements Parcelable {
                && Arrays.equals(mPolicyRuleFlags, that.mPolicyRuleFlags);
    }

    private EuiccRat(Parcel source) {
    private EuiccRulesAuthTable(Parcel source) {
        mPolicyRules = source.createIntArray();
        int len = mPolicyRules.length;
        mCarrierIds = new CarrierIdentifier[len][];
@@ -244,16 +245,16 @@ public final class EuiccRat implements Parcelable {
        mPolicyRuleFlags = source.createIntArray();
    }

    public static final Creator<EuiccRat> CREATOR =
            new Creator<EuiccRat>() {
    public static final Creator<EuiccRulesAuthTable> CREATOR =
            new Creator<EuiccRulesAuthTable>() {
                @Override
                public EuiccRat createFromParcel(Parcel source) {
                    return new EuiccRat(source);
                public EuiccRulesAuthTable createFromParcel(Parcel source) {
                    return new EuiccRulesAuthTable(source);
                }

                @Override
                public EuiccRat[] newArray(int size) {
                    return new EuiccRat[size];
                public EuiccRulesAuthTable[] newArray(int size) {
                    return new EuiccRulesAuthTable[size];
                }
            };
}
Loading