Home | History | Annotate | Download | only in apdu
      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 import android.telephony.Rlog;
     22 
     23 import com.android.internal.telephony.CommandException;
     24 import com.android.internal.telephony.CommandsInterface;
     25 import com.android.internal.telephony.uicc.IccIoResult;
     26 import com.android.internal.telephony.uicc.euicc.async.AsyncMessageInvocation;
     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 
     43     TransmitApduLogicalChannelInvocation(CommandsInterface ci) {
     44         mCi = ci;
     45     }
     46 
     47     @Override
     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, msg);
     52     }
     53 
     54     @Override
     55     protected IccIoResult parseResult(AsyncResult ar) {
     56         IccIoResult response;
     57         if (ar.exception == null && ar.result != null) {
     58             response  = (IccIoResult) ar.result;
     59         } else {
     60             if (ar.result == null) {
     61                 Rlog.e(LOG_TAG, "Empty response");
     62             } else if (ar.exception instanceof CommandException) {
     63                 Rlog.e(LOG_TAG,  "CommandException", ar.exception);
     64             } else {
     65                 Rlog.e(LOG_TAG,  "CommandException", ar.exception);
     66             }
     67             response = new IccIoResult(SW1_ERROR, 0 /* sw2 */, (byte[]) null /* payload */);
     68         }
     69 
     70         Rlog.v(LOG_TAG, "Response: " + response);
     71         return response;
     72     }
     73 }
     74