1388fa40468c01b8959ae4bac688241b6d362820fJun Yin/* 2388fa40468c01b8959ae4bac688241b6d362820fJun Yin * Copyright (C) 2018 The Android Open Source Project 3388fa40468c01b8959ae4bac688241b6d362820fJun Yin * 4388fa40468c01b8959ae4bac688241b6d362820fJun Yin * Licensed under the Apache License, Version 2.0 (the "License"); 5388fa40468c01b8959ae4bac688241b6d362820fJun Yin * you may not use this file except in compliance with the License. 6388fa40468c01b8959ae4bac688241b6d362820fJun Yin * You may obtain a copy of the License at 7388fa40468c01b8959ae4bac688241b6d362820fJun Yin * 8388fa40468c01b8959ae4bac688241b6d362820fJun Yin * http://www.apache.org/licenses/LICENSE-2.0 9388fa40468c01b8959ae4bac688241b6d362820fJun Yin * 10388fa40468c01b8959ae4bac688241b6d362820fJun Yin * Unless required by applicable law or agreed to in writing, software 11388fa40468c01b8959ae4bac688241b6d362820fJun Yin * distributed under the License is distributed on an "AS IS" BASIS, 12388fa40468c01b8959ae4bac688241b6d362820fJun Yin * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13388fa40468c01b8959ae4bac688241b6d362820fJun Yin * See the License for the specific language governing permissions and 14388fa40468c01b8959ae4bac688241b6d362820fJun Yin * limitations under the License. 15388fa40468c01b8959ae4bac688241b6d362820fJun Yin */ 16388fa40468c01b8959ae4bac688241b6d362820fJun Yin 17388fa40468c01b8959ae4bac688241b6d362820fJun Yinpackage com.android.internal.telephony.uicc.euicc.apdu; 18388fa40468c01b8959ae4bac688241b6d362820fJun Yin 19388fa40468c01b8959ae4bac688241b6d362820fJun Yinimport android.telephony.IccOpenLogicalChannelResponse; 20388fa40468c01b8959ae4bac688241b6d362820fJun Yin 21388fa40468c01b8959ae4bac688241b6d362820fJun Yin/** 22388fa40468c01b8959ae4bac688241b6d362820fJun Yin * The exception of failing to execute an APDU command. It can be caused by an error happening on 23388fa40468c01b8959ae4bac688241b6d362820fJun Yin * opening the basic or logical channel, or the response of the APDU command is not success 24388fa40468c01b8959ae4bac688241b6d362820fJun Yin * ({@link ApduSender#STATUS_NO_ERROR}). 25388fa40468c01b8959ae4bac688241b6d362820fJun Yin * 26388fa40468c01b8959ae4bac688241b6d362820fJun Yin * @hide 27388fa40468c01b8959ae4bac688241b6d362820fJun Yin */ 28388fa40468c01b8959ae4bac688241b6d362820fJun Yinpublic class ApduException extends Exception { 29388fa40468c01b8959ae4bac688241b6d362820fJun Yin private final int mApduStatus; 30388fa40468c01b8959ae4bac688241b6d362820fJun Yin 31388fa40468c01b8959ae4bac688241b6d362820fJun Yin /** Creates an exception with the apduStatus code of the response of an APDU command. */ 32388fa40468c01b8959ae4bac688241b6d362820fJun Yin public ApduException(int apduStatus) { 33388fa40468c01b8959ae4bac688241b6d362820fJun Yin super(); 34388fa40468c01b8959ae4bac688241b6d362820fJun Yin mApduStatus = apduStatus; 35388fa40468c01b8959ae4bac688241b6d362820fJun Yin } 36388fa40468c01b8959ae4bac688241b6d362820fJun Yin 37388fa40468c01b8959ae4bac688241b6d362820fJun Yin public ApduException(String message) { 38388fa40468c01b8959ae4bac688241b6d362820fJun Yin super(message); 39388fa40468c01b8959ae4bac688241b6d362820fJun Yin mApduStatus = 0; 40388fa40468c01b8959ae4bac688241b6d362820fJun Yin } 41388fa40468c01b8959ae4bac688241b6d362820fJun Yin 42388fa40468c01b8959ae4bac688241b6d362820fJun Yin /** 43388fa40468c01b8959ae4bac688241b6d362820fJun Yin * @return The error status of the response of an APDU command. An error status can be any 44388fa40468c01b8959ae4bac688241b6d362820fJun Yin * positive 16-bit integer (i.e., SW1 & SW2) other than 45388fa40468c01b8959ae4bac688241b6d362820fJun Yin * {@link ApduSender#STATUS_NO_ERROR} which means no error. For an error encountered 46388fa40468c01b8959ae4bac688241b6d362820fJun Yin * when opening a logical channel before the APDU command gets sent, this is not the 47388fa40468c01b8959ae4bac688241b6d362820fJun Yin * status defined in {@link IccOpenLogicalChannelResponse}. In this caes, 0 will be 48388fa40468c01b8959ae4bac688241b6d362820fJun Yin * returned and the message of this exception will have the detailed error information. 49388fa40468c01b8959ae4bac688241b6d362820fJun Yin */ 50388fa40468c01b8959ae4bac688241b6d362820fJun Yin public int getApduStatus() { 51388fa40468c01b8959ae4bac688241b6d362820fJun Yin return mApduStatus; 52388fa40468c01b8959ae4bac688241b6d362820fJun Yin } 53388fa40468c01b8959ae4bac688241b6d362820fJun Yin 54388fa40468c01b8959ae4bac688241b6d362820fJun Yin /** @return The hex string of the error status. */ 55388fa40468c01b8959ae4bac688241b6d362820fJun Yin public String getStatusHex() { 56388fa40468c01b8959ae4bac688241b6d362820fJun Yin return Integer.toHexString(mApduStatus); 57388fa40468c01b8959ae4bac688241b6d362820fJun Yin } 58388fa40468c01b8959ae4bac688241b6d362820fJun Yin 59388fa40468c01b8959ae4bac688241b6d362820fJun Yin @Override 60388fa40468c01b8959ae4bac688241b6d362820fJun Yin public String getMessage() { 61388fa40468c01b8959ae4bac688241b6d362820fJun Yin return super.getMessage() + " (apduStatus=" + getStatusHex() + ")"; 62388fa40468c01b8959ae4bac688241b6d362820fJun Yin } 63388fa40468c01b8959ae4bac688241b6d362820fJun Yin} 64