1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.internal.telephony.uicc.euicc; 18 19 import android.annotation.IntDef; 20 import android.annotation.Nullable; 21 22 import com.android.internal.telephony.uicc.asn1.Asn1Node; 23 import com.android.internal.telephony.uicc.euicc.apdu.ApduSender; 24 25 import java.lang.annotation.Retention; 26 import java.lang.annotation.RetentionPolicy; 27 28 /** 29 * The exception which is thrown when an error is returned in a successfully executed APDU command 30 * sent to eUICC. This exception means the response status is no-error 31 * ({@link ApduSender#STATUS_NO_ERROR}), but the action is failed due to eUICC specific logic. 32 */ 33 public class EuiccCardErrorException extends EuiccCardException { 34 /** Operations */ 35 @Retention(RetentionPolicy.SOURCE) 36 @IntDef(prefix = "OPERATION_", value = { 37 OPERATION_UNKNOWN, 38 OPERATION_GET_PROFILE, 39 OPERATION_PREPARE_DOWNLOAD, 40 OPERATION_AUTHENTICATE_SERVER, 41 OPERATION_CANCEL_SESSION, 42 OPERATION_LOAD_BOUND_PROFILE_PACKAGE, 43 OPERATION_LIST_NOTIFICATIONS, 44 OPERATION_SET_NICKNAME, 45 OPERATION_RETRIEVE_NOTIFICATION, 46 OPERATION_REMOVE_NOTIFICATION_FROM_LIST, 47 OPERATION_SWITCH_TO_PROFILE, 48 OPERATION_DISABLE_PROFILE, 49 OPERATION_DELETE_PROFILE, 50 OPERATION_RESET_MEMORY, 51 OPERATION_SET_DEFAULT_SMDP_ADDRESS, 52 }) 53 public @interface OperationCode {} 54 55 public static final int OPERATION_UNKNOWN = 0; 56 public static final int OPERATION_GET_PROFILE = 1; 57 public static final int OPERATION_PREPARE_DOWNLOAD = 2; 58 public static final int OPERATION_AUTHENTICATE_SERVER = 3; 59 public static final int OPERATION_CANCEL_SESSION = 4; 60 public static final int OPERATION_LOAD_BOUND_PROFILE_PACKAGE = 5; 61 public static final int OPERATION_LIST_NOTIFICATIONS = 6; 62 public static final int OPERATION_SET_NICKNAME = 7; 63 public static final int OPERATION_RETRIEVE_NOTIFICATION = 8; 64 public static final int OPERATION_REMOVE_NOTIFICATION_FROM_LIST = 9; 65 public static final int OPERATION_SWITCH_TO_PROFILE = 10; 66 public static final int OPERATION_DISABLE_PROFILE = 11; 67 public static final int OPERATION_DELETE_PROFILE = 12; 68 public static final int OPERATION_RESET_MEMORY = 13; 69 public static final int OPERATION_SET_DEFAULT_SMDP_ADDRESS = 14; 70 71 private final @OperationCode int mOperationCode; 72 private final int mErrorCode; 73 private final @Nullable Asn1Node mErrorDetails; 74 75 /** 76 * Creates an exception with an error code in the response of an APDU command. 77 * 78 * @param errorCode The meaning of the code depends on each APDU command. It should always be 79 * non-negative. 80 */ EuiccCardErrorException(@perationCode int operationCode, int errorCode)81 public EuiccCardErrorException(@OperationCode int operationCode, int errorCode) { 82 mOperationCode = operationCode; 83 mErrorCode = errorCode; 84 mErrorDetails = null; 85 } 86 87 /** 88 * Creates an exception with an error code and the error details in the response of an APDU 89 * command. 90 * 91 * @param errorCode The meaning of the code depends on each APDU command. It should always be 92 * non-negative. 93 * @param errorDetails The content of the details depends on each APDU command. 94 */ EuiccCardErrorException(@perationCode int operationCode, int errorCode, @Nullable Asn1Node errorDetails)95 public EuiccCardErrorException(@OperationCode int operationCode, int errorCode, 96 @Nullable Asn1Node errorDetails) { 97 mOperationCode = operationCode; 98 mErrorCode = errorCode; 99 mErrorDetails = errorDetails; 100 } 101 102 /** @return The error code. The meaning of the code depends on each APDU command. */ getErrorCode()103 public int getErrorCode() { 104 return mErrorCode; 105 } 106 107 /** @return The operation code. */ getOperationCode()108 public int getOperationCode() { 109 return mOperationCode; 110 } 111 112 /** @return The error details. The meaning of the details depends on each APDU command. */ 113 @Nullable getErrorDetails()114 public Asn1Node getErrorDetails() { 115 return mErrorDetails; 116 } 117 118 @Override getMessage()119 public String getMessage() { 120 return "EuiccCardError: mOperatorCode=" + mOperationCode + ", mErrorCode=" + mErrorCode 121 + ", errorDetails=" + (mErrorDetails == null ? "null" : mErrorDetails.toHex()); 122 } 123 } 124