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.apdu; 18 19 import android.os.AsyncResult; 20 import android.os.Message; 21 22 import com.android.internal.telephony.CommandException; 23 import com.android.internal.telephony.CommandsInterface; 24 import com.android.internal.telephony.uicc.IccIoResult; 25 import com.android.internal.telephony.uicc.euicc.async.AsyncMessageInvocation; 26 import com.android.telephony.Rlog; 27 28 /** 29 * Invokes {@link CommandsInterface#iccTransmitApduLogicalChannel(int, int, int, int, int, int, 30 * String, Message)}. This takes an APDU command as the input and return the response. The status of 31 * returned response will be 0x6F00 if any error happens. No exception will be returned to the 32 * result callback. 33 * 34 * @hide 35 */ 36 public class TransmitApduLogicalChannelInvocation 37 extends AsyncMessageInvocation<ApduCommand, IccIoResult> { 38 private static final String LOG_TAG = "TransApdu"; 39 private static final int SW1_ERROR = 0x6F; 40 41 private final CommandsInterface mCi; 42 TransmitApduLogicalChannelInvocation(CommandsInterface ci)43 TransmitApduLogicalChannelInvocation(CommandsInterface ci) { 44 mCi = ci; 45 } 46 47 @Override sendRequestMessage(ApduCommand command, Message msg)48 protected void sendRequestMessage(ApduCommand command, Message msg) { 49 Rlog.v(LOG_TAG, "Send: " + command); 50 mCi.iccTransmitApduLogicalChannel(command.channel, command.cla | command.channel, 51 command.ins, command.p1, command.p2, command.p3, command.cmdHex, command.isEs10, 52 msg); 53 } 54 55 @Override parseResult(AsyncResult ar)56 protected IccIoResult parseResult(AsyncResult ar) { 57 IccIoResult response; 58 if (ar.exception == null && ar.result != null) { 59 response = (IccIoResult) ar.result; 60 } else { 61 if (ar.result == null) { 62 Rlog.e(LOG_TAG, "Empty response"); 63 } else if (ar.exception instanceof CommandException) { 64 Rlog.e(LOG_TAG, "CommandException", ar.exception); 65 } else { 66 Rlog.e(LOG_TAG, "CommandException", ar.exception); 67 } 68 response = new IccIoResult(SW1_ERROR, 0 /* sw2 */, (byte[]) null /* payload */); 69 } 70 71 Rlog.v(LOG_TAG, "Response: " + response); 72 return response; 73 } 74 } 75