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.euicc.async.AsyncMessageInvocation;
25 import com.android.telephony.Rlog;
26 
27 /**
28  * Invokes {@link CommandsInterface#iccCloseLogicalChannel(int, Message)}. This takes a channel id
29  * (Integer) as the input and return a boolean to indicate if closing the logical channel is
30  * succeeded. No exception will be returned to the result callback.
31  *
32  * @hide
33  */
34 class CloseLogicalChannelInvocation extends AsyncMessageInvocation<Integer, Boolean> {
35     private static final String LOG_TAG = "CloseChan";
36 
37     private final CommandsInterface mCi;
38 
CloseLogicalChannelInvocation(CommandsInterface ci)39     CloseLogicalChannelInvocation(CommandsInterface ci) {
40         mCi = ci;
41     }
42 
43     @Override
sendRequestMessage(Integer channel, Message msg)44     protected void sendRequestMessage(Integer channel, Message msg) {
45         Rlog.v(LOG_TAG, "Channel: " + channel);
46         mCi.iccCloseLogicalChannel(channel, msg);
47     }
48 
49     @Override
parseResult(AsyncResult ar)50     protected Boolean parseResult(AsyncResult ar) {
51         if (ar.exception == null) {
52             return true;
53         }
54         if (ar.exception instanceof CommandException) {
55             Rlog.e(LOG_TAG, "CommandException", ar.exception);
56         } else {
57             Rlog.e(LOG_TAG, "Unknown exception", ar.exception);
58         }
59         return false;
60     }
61 }
62