• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 android.telephony.mockmodem;
18 
19 import static android.telephony.mockmodem.MockSimService.COMMAND_GET_RESPONSE;
20 import static android.telephony.mockmodem.MockSimService.COMMAND_READ_BINARY;
21 import static android.telephony.mockmodem.MockSimService.EF_ICCID;
22 
23 import android.hardware.radio.RadioError;
24 import android.hardware.radio.RadioIndicationType;
25 import android.hardware.radio.RadioResponseInfo;
26 import android.hardware.radio.sim.CardStatus;
27 import android.hardware.radio.sim.IRadioSim;
28 import android.hardware.radio.sim.IRadioSimIndication;
29 import android.hardware.radio.sim.IRadioSimResponse;
30 import android.hardware.radio.sim.SimRefreshResult;
31 import android.os.AsyncResult;
32 import android.os.Handler;
33 import android.os.Message;
34 import android.os.RemoteException;
35 import android.telephony.mockmodem.MockModemConfigBase.SimInfoChangedResult;
36 import android.telephony.mockmodem.MockSimService.SimAppData;
37 import android.util.Log;
38 
39 import java.util.ArrayList;
40 
41 public class IRadioSimImpl extends IRadioSim.Stub {
42     private static final String TAG = "MRSIM";
43     private final MockModemService mService;
44     private IRadioSimResponse mRadioSimResponse;
45     private IRadioSimIndication mRadioSimIndication;
46     private static MockModemConfigInterface[] sMockModemConfigInterfaces;
47     private Object mCacheUpdateMutex;
48     private final Handler mHandler;
49     private int mSubId;
50 
51     // ***** Events
52     static final int EVENT_SIM_CARD_STATUS_CHANGED = 1;
53     static final int EVENT_SIM_APP_DATA_CHANGED = 2;
54     static final int EVENT_SIM_INFO_CHANGED = 3;
55 
56     // ***** Cache of modem attributes/status
57     private int mNumOfLogicalSim;
58     private CardStatus mCardStatus;
59     private ArrayList<SimAppData> mSimAppList;
60 
IRadioSimImpl( MockModemService service, MockModemConfigInterface[] interfaces, int instanceId)61     public IRadioSimImpl(
62             MockModemService service, MockModemConfigInterface[] interfaces, int instanceId) {
63         Log.d(TAG, "Instantiated");
64 
65         this.mService = service;
66         sMockModemConfigInterfaces = interfaces;
67         mSubId = instanceId;
68         mCardStatus = new CardStatus();
69         mCacheUpdateMutex = new Object();
70         mHandler = new IRadioSimHandler();
71         mNumOfLogicalSim = sMockModemConfigInterfaces.length;
72 
73         // Register events
74         sMockModemConfigInterfaces[mSubId].registerForCardStatusChanged(
75                 mHandler, EVENT_SIM_CARD_STATUS_CHANGED, null);
76 
77         // Register events
78         sMockModemConfigInterfaces[mSubId].registerForSimAppDataChanged(
79                 mHandler, EVENT_SIM_APP_DATA_CHANGED, null);
80 
81         // Register events
82         sMockModemConfigInterfaces[mSubId].registerForSimInfoChanged(
83                 mHandler, EVENT_SIM_INFO_CHANGED, null);
84     }
85 
86     /** Handler class to handle callbacks */
87     private final class IRadioSimHandler extends Handler {
88         @Override
handleMessage(Message msg)89         public void handleMessage(Message msg) {
90             AsyncResult ar;
91             synchronized (mCacheUpdateMutex) {
92                 switch (msg.what) {
93                     case EVENT_SIM_CARD_STATUS_CHANGED:
94                         Log.d(TAG, "Received EVENT_SIM_CARD_STATUS_CHANGED");
95                         ar = (AsyncResult) msg.obj;
96                         if (ar != null && ar.exception == null) {
97                             mCardStatus = (CardStatus) ar.result;
98                             Log.i(TAG, "Sim card status: " + mCardStatus);
99                             simStatusChanged();
100                         } else {
101                             Log.e(TAG, msg.what + " failure. Exception: " + ar.exception);
102                         }
103                         break;
104 
105                     case EVENT_SIM_APP_DATA_CHANGED:
106                         Log.d(TAG, "Received EVENT_SIM_APP_DATA_CHANGED");
107                         ar = (AsyncResult) msg.obj;
108                         if (ar != null && ar.exception == null) {
109                             mSimAppList = (ArrayList<SimAppData>) ar.result;
110                             if (mSimAppList != null) {
111                                 Log.i(TAG, "number of SIM app data: " + mSimAppList.size());
112                             } else {
113                                 Log.e(TAG, "mSimAppList = null");
114                             }
115                         } else {
116                             Log.e(TAG, msg.what + " failure. Exception: " + ar.exception);
117                         }
118                         break;
119 
120                     case EVENT_SIM_INFO_CHANGED:
121                         ar = (AsyncResult) msg.obj;
122                         if (ar != null && ar.exception == null) {
123                             SimInfoChangedResult simInfoChangeResult =
124                                     (SimInfoChangedResult) ar.result;
125                             Log.d(TAG, "Received EVENT_SIM_INFO_CHANGED: " + simInfoChangeResult);
126                             SimRefreshResult simRefreshResult = new SimRefreshResult();
127                             switch (simInfoChangeResult.mSimInfoType) {
128                                 case SimInfoChangedResult.SIM_INFO_TYPE_MCC_MNC:
129                                 case SimInfoChangedResult.SIM_INFO_TYPE_IMSI:
130                                     if (simRefreshResult != null) {
131                                         simRefreshResult.type =
132                                                 SimRefreshResult.TYPE_SIM_FILE_UPDATE;
133                                         simRefreshResult.efId = simInfoChangeResult.mEfId;
134                                         simRefreshResult.aid = simInfoChangeResult.mAid;
135                                         simRefresh(simRefreshResult);
136                                     }
137                                     break;
138                             }
139                         } else {
140                             Log.e(TAG, msg.what + " failure. Exception: " + ar.exception);
141                         }
142                         break;
143                 }
144             }
145         }
146     }
147 
148     // Implementation of IRadioSim functions
149     @Override
setResponseFunctions( IRadioSimResponse radioSimResponse, IRadioSimIndication radioSimIndication)150     public void setResponseFunctions(
151             IRadioSimResponse radioSimResponse, IRadioSimIndication radioSimIndication) {
152         Log.d(TAG, "setResponseFunctions");
153         mRadioSimResponse = radioSimResponse;
154         mRadioSimIndication = radioSimIndication;
155         mService.countDownLatch(MockModemService.LATCH_RADIO_INTERFACES_READY);
156     }
157 
158     @Override
responseAcknowledgement()159     public void responseAcknowledgement() {
160         Log.d(TAG, "responseAcknowledgement");
161         // TODO
162         // acknowledgeRequest(in int serial);
163     }
164 
165     @Override
areUiccApplicationsEnabled(int serial)166     public void areUiccApplicationsEnabled(int serial) {
167         Log.d(TAG, "areUiccApplicationsEnabled");
168 
169         boolean enabled = true;
170 
171         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
172         try {
173             mRadioSimResponse.areUiccApplicationsEnabledResponse(rsp, enabled);
174         } catch (RemoteException ex) {
175             Log.e(TAG, "Failed to areUiccApplicationsEnabled from AIDL. Exception" + ex);
176         }
177     }
178 
179     @Override
changeIccPin2ForApp(int serial, String oldPin2, String newPin2, String aid)180     public void changeIccPin2ForApp(int serial, String oldPin2, String newPin2, String aid) {
181         Log.d(TAG, "changeIccPin2ForApp");
182         // TODO: cache value
183 
184         int remainingRetries = 3;
185 
186         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
187         try {
188             mRadioSimResponse.changeIccPin2ForAppResponse(rsp, remainingRetries);
189         } catch (RemoteException ex) {
190             Log.e(TAG, "Failed to changeIccPin2ForApp from AIDL. Exception" + ex);
191         }
192     }
193 
194     @Override
changeIccPinForApp(int serial, String oldPin, String newPin, String aid)195     public void changeIccPinForApp(int serial, String oldPin, String newPin, String aid) {
196         Log.d(TAG, "changeIccPinForApp");
197         // TODO: cache value
198 
199         int remainingRetries = 3;
200 
201         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
202         try {
203             mRadioSimResponse.changeIccPinForAppResponse(rsp, remainingRetries);
204         } catch (RemoteException ex) {
205             Log.e(TAG, "Failed to changeIccPinForApp from AIDL. Exception" + ex);
206         }
207     }
208 
209     @Override
enableUiccApplications(int serial, boolean enable)210     public void enableUiccApplications(int serial, boolean enable) {
211         Log.d(TAG, "enableUiccApplications");
212         // TODO: cache value
213 
214         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
215         try {
216             mRadioSimResponse.enableUiccApplicationsResponse(rsp);
217         } catch (RemoteException ex) {
218             Log.e(TAG, "Failed to enableUiccApplications from AIDL. Exception" + ex);
219         }
220     }
221 
222     @Override
getAllowedCarriers(int serial)223     public void getAllowedCarriers(int serial) {
224         Log.d(TAG, "getAllowedCarriers");
225 
226         android.hardware.radio.sim.CarrierRestrictions carriers =
227                 new android.hardware.radio.sim.CarrierRestrictions();
228         int multiSimPolicy = android.hardware.radio.sim.SimLockMultiSimPolicy.NO_MULTISIM_POLICY;
229 
230         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
231         try {
232             mRadioSimResponse.getAllowedCarriersResponse(rsp, carriers, multiSimPolicy);
233         } catch (RemoteException ex) {
234             Log.e(TAG, "Failed to getAllowedCarriers from AIDL. Exception" + ex);
235         }
236     }
237 
238     @Override
getCdmaSubscription(int serial)239     public void getCdmaSubscription(int serial) {
240         Log.d(TAG, "getCdmaSubscription");
241 
242         String mdn = "";
243         String hSid = "";
244         String hNid = "";
245         String min = "";
246         String prl = "";
247 
248         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
249         try {
250             mRadioSimResponse.getCdmaSubscriptionResponse(rsp, mdn, hSid, hNid, min, prl);
251         } catch (RemoteException ex) {
252             Log.e(TAG, "Failed to getCdmaSubscription from AIDL. Exception" + ex);
253         }
254     }
255 
256     @Override
getCdmaSubscriptionSource(int serial)257     public void getCdmaSubscriptionSource(int serial) {
258         Log.d(TAG, "getCdmaSubscriptionSource");
259 
260         int source = 0; // CdmaSubscriptionSource.RUIM_SIM
261 
262         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
263         try {
264             mRadioSimResponse.getCdmaSubscriptionSourceResponse(rsp, source);
265         } catch (RemoteException ex) {
266             Log.e(TAG, "Failed to getCdmaSubscriptionSource from AIDL. Exception" + ex);
267         }
268     }
269 
270     @Override
getFacilityLockForApp( int serial, String facility, String password, int serviceClass, String appId)271     public void getFacilityLockForApp(
272             int serial, String facility, String password, int serviceClass, String appId) {
273         Log.d(TAG, "getFacilityLockForApp");
274         int numOfSimApp = mSimAppList.size();
275         int responseError = RadioError.NONE;
276         int simAppIdx;
277         boolean isHandled = false;
278         boolean isFacilitySupport = true;
279         int responseData = -1;
280 
281         synchronized (mCacheUpdateMutex) {
282             // TODO: check service class
283             for (simAppIdx = 0;
284                     simAppIdx < numOfSimApp && isFacilitySupport && !isHandled;
285                     simAppIdx++) {
286                 switch (facility) {
287                     case "FD": // FDN status query
288                         if (appId.equals(mSimAppList.get(simAppIdx).getAid())) {
289                             responseData = mSimAppList.get(simAppIdx).getFdnStatus();
290                             isHandled = true;
291                         }
292                         break;
293                     case "SC": // PIN1 status query
294                         if (appId.equals(mSimAppList.get(simAppIdx).getAid())) {
295                             responseData = mSimAppList.get(simAppIdx).getPin1State();
296                             isHandled = true;
297                         }
298                         break;
299                     default:
300                         isFacilitySupport = false;
301                         break;
302                 }
303             }
304         }
305 
306         if (!isHandled) {
307             Log.e(TAG, "Not support sim application aid = " + appId);
308             responseError = RadioError.NO_SUCH_ELEMENT;
309         } else if (!isFacilitySupport) {
310             Log.e(TAG, "Not support facility = " + facility);
311             responseError = RadioError.REQUEST_NOT_SUPPORTED;
312         } else if (responseData == -1) {
313             responseError = RadioError.INTERNAL_ERR;
314         }
315 
316         RadioResponseInfo rsp = mService.makeSolRsp(serial, responseError);
317         try {
318             mRadioSimResponse.getFacilityLockForAppResponse(rsp, responseData);
319         } catch (RemoteException ex) {
320             Log.e(TAG, "Failed to getFacilityLockForApp from AIDL. Exception" + ex);
321         }
322     }
323 
324     @Override
getIccCardStatus(int serial)325     public void getIccCardStatus(int serial) {
326         Log.d(TAG, "getIccCardStatus");
327         CardStatus cardStatus;
328 
329         synchronized (mCacheUpdateMutex) {
330             cardStatus = mCardStatus;
331         }
332 
333         RadioResponseInfo rsp = mService.makeSolRsp(serial);
334         try {
335             mRadioSimResponse.getIccCardStatusResponse(rsp, cardStatus);
336         } catch (RemoteException ex) {
337             Log.e(TAG, "Failed to getIccCardStatus from AIDL. Exception" + ex);
338         }
339     }
340 
341     @Override
getImsiForApp(int serial, String aid)342     public void getImsiForApp(int serial, String aid) {
343         Log.d(TAG, "getImsiForApp");
344         String imsi = "";
345         int numOfSimApp = mSimAppList.size();
346         int responseError = RadioError.NONE;
347         int simAppIdx;
348         boolean isHandled;
349 
350         synchronized (mCacheUpdateMutex) {
351             for (simAppIdx = 0, isHandled = false;
352                     simAppIdx < numOfSimApp && !isHandled;
353                     simAppIdx++) {
354                 if (aid.equals(mSimAppList.get(simAppIdx).getAid())) {
355                     imsi = mSimAppList.get(simAppIdx).getImsi();
356                     isHandled = true;
357                 }
358             }
359         }
360 
361         if (!isHandled) {
362             Log.e(TAG, "Not support sim application aid = " + aid);
363             responseError = RadioError.NO_SUCH_ELEMENT;
364         }
365 
366         RadioResponseInfo rsp = mService.makeSolRsp(serial, responseError);
367         try {
368             mRadioSimResponse.getImsiForAppResponse(rsp, imsi);
369         } catch (RemoteException ex) {
370             Log.e(TAG, "Failed to getImsiForApp from AIDL. Exception" + ex);
371         }
372     }
373 
374     @Override
getSimPhonebookCapacity(int serial)375     public void getSimPhonebookCapacity(int serial) {
376         Log.d(TAG, "getSimPhonebookCapacity");
377 
378         android.hardware.radio.sim.PhonebookCapacity capacity =
379                 new android.hardware.radio.sim.PhonebookCapacity();
380 
381         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
382         try {
383             mRadioSimResponse.getSimPhonebookCapacityResponse(rsp, capacity);
384         } catch (RemoteException ex) {
385             Log.e(TAG, "Failed to getSimPhonebookCapacity from AIDL. Exception" + ex);
386         }
387     }
388 
389     @Override
getSimPhonebookRecords(int serial)390     public void getSimPhonebookRecords(int serial) {
391         Log.d(TAG, "getSimPhonebookRecords");
392 
393         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
394         try {
395             mRadioSimResponse.getSimPhonebookRecordsResponse(rsp);
396         } catch (RemoteException ex) {
397             Log.e(TAG, "Failed to getSimPhonebookRecords from AIDL. Exception" + ex);
398         }
399     }
400 
401     @Override
iccCloseLogicalChannel(int serial, int channelId)402     public void iccCloseLogicalChannel(int serial, int channelId) {
403         Log.d(TAG, "iccCloseLogicalChannel");
404         // TODO: cache value
405 
406         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
407         try {
408             mRadioSimResponse.iccCloseLogicalChannelResponse(rsp);
409         } catch (RemoteException ex) {
410             Log.e(TAG, "Failed to iccCloseLogicalChannel from AIDL. Exception" + ex);
411         }
412     }
413 
encodeBcdString(String str)414     private String encodeBcdString(String str) {
415         StringBuffer bcdString = new StringBuffer();
416 
417         if (str.length() % 2 != 0) {
418             Log.d(TAG, "Invalid string(" + str + ") for Bcd format");
419             return "";
420         }
421 
422         for (int i = 0; i < str.length(); i += 2) {
423             bcdString.append(str.substring(i + 1, i + 2));
424             bcdString.append(str.substring(i, i + 1));
425         }
426 
427         return bcdString.toString();
428     }
429 
getIccIoResult( android.hardware.radio.sim.IccIoResult iccIoResult, int command, int fileId, String path, int p1, int p2, int p3, String aid)430     private int getIccIoResult(
431             android.hardware.radio.sim.IccIoResult iccIoResult,
432             int command,
433             int fileId,
434             String path,
435             int p1,
436             int p2,
437             int p3,
438             String aid) {
439         int numOfSimApp = mSimAppList.size();
440         int simAppIdx;
441         boolean foundAid;
442         int responseError = RadioError.GENERIC_FAILURE;
443 
444         if (iccIoResult == null) {
445             return responseError;
446         }
447 
448         synchronized (mCacheUpdateMutex) {
449             for (simAppIdx = 0, foundAid = false; simAppIdx < numOfSimApp; simAppIdx++) {
450                 if (aid.equals(mSimAppList.get(simAppIdx).getAid())) {
451                     foundAid = true;
452                     break;
453                 }
454             }
455 
456             if (!foundAid) {
457                 Log.e(TAG, "Not support sim application aid = " + aid);
458                 iccIoResult.sw1 = 0x6A;
459                 iccIoResult.sw2 = 0x82;
460             } else {
461                 switch (fileId) {
462                     case EF_ICCID:
463                         if (command == COMMAND_READ_BINARY) {
464                             String bcdIccid =
465                                     encodeBcdString(mSimAppList.get(simAppIdx).getIccid());
466                             iccIoResult.simResponse = bcdIccid;
467                             Log.d(TAG, "Get IccIo result: ICCID = " + iccIoResult.simResponse);
468                             iccIoResult.sw1 = 0x90;
469                             responseError = RadioError.NONE;
470                         } else if (command == COMMAND_GET_RESPONSE) {
471                             iccIoResult.simResponse = mSimAppList.get(simAppIdx).getIccidInfo();
472                             Log.d(TAG, "Get IccIo result: ICCID = " + iccIoResult.simResponse);
473                             iccIoResult.sw1 = 0x90;
474                             responseError = RadioError.NONE;
475                         } else {
476                             Log.d(
477                                     TAG,
478                                     "Command("
479                                             + command
480                                             + ") not support for file id = 0x"
481                                             + Integer.toHexString(fileId));
482                             iccIoResult.sw1 = 0x6A;
483                             iccIoResult.sw2 = 0x82;
484                         }
485                         break;
486                     default:
487                         Log.d(TAG, "Not find EF file id = 0x" + Integer.toHexString(fileId));
488                         iccIoResult.sw1 = 0x6A;
489                         iccIoResult.sw2 = 0x82;
490                         break;
491                 }
492             }
493         }
494 
495         return responseError;
496     }
497 
498     @Override
iccIoForApp(int serial, android.hardware.radio.sim.IccIo iccIo)499     public void iccIoForApp(int serial, android.hardware.radio.sim.IccIo iccIo) {
500         Log.d(TAG, "iccIoForApp");
501         int responseError = RadioError.NONE;
502         android.hardware.radio.sim.IccIoResult iccIoResult =
503                 new android.hardware.radio.sim.IccIoResult();
504 
505         switch (iccIo.command) {
506             case COMMAND_READ_BINARY:
507             case COMMAND_GET_RESPONSE:
508                 responseError =
509                         getIccIoResult(
510                                 iccIoResult,
511                                 iccIo.command,
512                                 iccIo.fileId,
513                                 iccIo.path,
514                                 iccIo.p1,
515                                 iccIo.p2,
516                                 iccIo.p3,
517                                 iccIo.aid);
518                 break;
519             default:
520                 responseError = RadioError.REQUEST_NOT_SUPPORTED;
521                 break;
522         }
523 
524         RadioResponseInfo rsp = mService.makeSolRsp(serial, responseError);
525         try {
526             mRadioSimResponse.iccIoForAppResponse(rsp, iccIoResult);
527         } catch (RemoteException ex) {
528             Log.e(TAG, "Failed to iccIoForApp from AIDL. Exception" + ex);
529         }
530     }
531 
532     @Override
iccOpenLogicalChannel(int serial, String aid, int p2)533     public void iccOpenLogicalChannel(int serial, String aid, int p2) {
534         Log.d(TAG, "iccOpenLogicalChannel");
535         // TODO: cache value
536         int channelId = 0;
537         byte[] selectResponse = new byte[0];
538 
539         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
540         try {
541             mRadioSimResponse.iccOpenLogicalChannelResponse(rsp, channelId, selectResponse);
542         } catch (RemoteException ex) {
543             Log.e(TAG, "Failed to iccOpenLogicalChannel from AIDL. Exception" + ex);
544         }
545     }
546 
547     @Override
iccTransmitApduBasicChannel( int serial, android.hardware.radio.sim.SimApdu message)548     public void iccTransmitApduBasicChannel(
549             int serial, android.hardware.radio.sim.SimApdu message) {
550         Log.d(TAG, "iccTransmitApduBasicChannel");
551         // TODO: cache value
552         android.hardware.radio.sim.IccIoResult iccIoResult =
553                 new android.hardware.radio.sim.IccIoResult();
554 
555         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
556         try {
557             mRadioSimResponse.iccTransmitApduBasicChannelResponse(rsp, iccIoResult);
558         } catch (RemoteException ex) {
559             Log.e(TAG, "Failed to iccTransmitApduBasicChannel from AIDL. Exception" + ex);
560         }
561     }
562 
563     @Override
iccTransmitApduLogicalChannel( int serial, android.hardware.radio.sim.SimApdu message)564     public void iccTransmitApduLogicalChannel(
565             int serial, android.hardware.radio.sim.SimApdu message) {
566         Log.d(TAG, "iccTransmitApduLogicalChannel");
567         // TODO: cache value
568         android.hardware.radio.sim.IccIoResult iccIoResult =
569                 new android.hardware.radio.sim.IccIoResult();
570 
571         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
572         try {
573             mRadioSimResponse.iccTransmitApduBasicChannelResponse(rsp, iccIoResult);
574         } catch (RemoteException ex) {
575             Log.e(TAG, "Failed to iccTransmitApduLogicalChannel from AIDL. Exception" + ex);
576         }
577     }
578 
579     @Override
reportStkServiceIsRunning(int serial)580     public void reportStkServiceIsRunning(int serial) {
581         Log.d(TAG, "reportStkServiceIsRunning");
582 
583         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
584         try {
585             mRadioSimResponse.reportStkServiceIsRunningResponse(rsp);
586         } catch (RemoteException ex) {
587             Log.e(TAG, "Failed to reportStkServiceIsRunning from AIDL. Exception" + ex);
588         }
589     }
590 
591     @Override
requestIccSimAuthentication( int serial, int authContext, String authData, String aid)592     public void requestIccSimAuthentication(
593             int serial, int authContext, String authData, String aid) {
594         Log.d(TAG, "requestIccSimAuthentication");
595         // TODO: cache value
596         android.hardware.radio.sim.IccIoResult iccIoResult =
597                 new android.hardware.radio.sim.IccIoResult();
598 
599         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
600         try {
601             mRadioSimResponse.requestIccSimAuthenticationResponse(rsp, iccIoResult);
602         } catch (RemoteException ex) {
603             Log.e(TAG, "Failed to requestIccSimAuthentication from AIDL. Exception" + ex);
604         }
605     }
606 
607     @Override
sendEnvelope(int serial, String contents)608     public void sendEnvelope(int serial, String contents) {
609         Log.d(TAG, "sendEnvelope");
610         // TODO: cache value
611         String commandResponse = "";
612 
613         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
614         try {
615             mRadioSimResponse.sendEnvelopeResponse(rsp, commandResponse);
616         } catch (RemoteException ex) {
617             Log.e(TAG, "Failed to sendEnvelope from AIDL. Exception" + ex);
618         }
619     }
620 
621     @Override
sendEnvelopeWithStatus(int serial, String contents)622     public void sendEnvelopeWithStatus(int serial, String contents) {
623         Log.d(TAG, "sendEnvelopeWithStatus");
624         // TODO: cache value
625         android.hardware.radio.sim.IccIoResult iccIoResult =
626                 new android.hardware.radio.sim.IccIoResult();
627 
628         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
629         try {
630             mRadioSimResponse.sendEnvelopeWithStatusResponse(rsp, iccIoResult);
631         } catch (RemoteException ex) {
632             Log.e(TAG, "Failed to sendEnvelopeWithStatus from AIDL. Exception" + ex);
633         }
634     }
635 
636     @Override
sendTerminalResponseToSim(int serial, String contents)637     public void sendTerminalResponseToSim(int serial, String contents) {
638         Log.d(TAG, "sendTerminalResponseToSim");
639         // TODO: cache value
640 
641         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
642         try {
643             mRadioSimResponse.sendTerminalResponseToSimResponse(rsp);
644         } catch (RemoteException ex) {
645             Log.e(TAG, "Failed to sendTerminalResponseToSim from AIDL. Exception" + ex);
646         }
647     }
648 
649     @Override
setAllowedCarriers( int serial, android.hardware.radio.sim.CarrierRestrictions carriers, int multiSimPolicy)650     public void setAllowedCarriers(
651             int serial,
652             android.hardware.radio.sim.CarrierRestrictions carriers,
653             int multiSimPolicy) {
654         Log.d(TAG, "sendTerminalResponseToSim");
655         // TODO: cache value
656 
657         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
658         try {
659             mRadioSimResponse.setAllowedCarriersResponse(rsp);
660         } catch (RemoteException ex) {
661             Log.e(TAG, "Failed to setAllowedCarriers from AIDL. Exception" + ex);
662         }
663     }
664 
665     @Override
setCarrierInfoForImsiEncryption( int serial, android.hardware.radio.sim.ImsiEncryptionInfo imsiEncryptionInfo)666     public void setCarrierInfoForImsiEncryption(
667             int serial, android.hardware.radio.sim.ImsiEncryptionInfo imsiEncryptionInfo) {
668         Log.d(TAG, "setCarrierInfoForImsiEncryption");
669         // TODO: cache value
670 
671         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
672         try {
673             mRadioSimResponse.setCarrierInfoForImsiEncryptionResponse(rsp);
674         } catch (RemoteException ex) {
675             Log.e(TAG, "Failed to setCarrierInfoForImsiEncryption from AIDL. Exception" + ex);
676         }
677     }
678 
679     @Override
setCdmaSubscriptionSource(int serial, int cdmaSub)680     public void setCdmaSubscriptionSource(int serial, int cdmaSub) {
681         Log.d(TAG, "setCdmaSubscriptionSource");
682         // TODO: cache value
683 
684         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
685         try {
686             mRadioSimResponse.setCdmaSubscriptionSourceResponse(rsp);
687         } catch (RemoteException ex) {
688             Log.e(TAG, "Failed to setCdmaSubscriptionSource from AIDL. Exception" + ex);
689         }
690     }
691 
692     @Override
setFacilityLockForApp( int serial, String facility, boolean lockState, String password, int serviceClass, String appId)693     public void setFacilityLockForApp(
694             int serial,
695             String facility,
696             boolean lockState,
697             String password,
698             int serviceClass,
699             String appId) {
700         Log.d(TAG, "setFacilityLockForApp");
701         // TODO: cache value
702         int retry = 10;
703 
704         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
705         try {
706             mRadioSimResponse.setFacilityLockForAppResponse(rsp, retry);
707         } catch (RemoteException ex) {
708             Log.e(TAG, "Failed to setFacilityLockForApp from AIDL. Exception" + ex);
709         }
710     }
711 
712     @Override
setSimCardPower(int serial, int powerUp)713     public void setSimCardPower(int serial, int powerUp) {
714         Log.d(TAG, "setSimCardPower");
715         // TODO: cache value
716         int retry = 10;
717 
718         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
719         try {
720             mRadioSimResponse.setSimCardPowerResponse(rsp);
721         } catch (RemoteException ex) {
722             Log.e(TAG, "Failed to setSimCardPower from AIDL. Exception" + ex);
723         }
724     }
725 
726     @Override
setUiccSubscription(int serial, android.hardware.radio.sim.SelectUiccSub uiccSub)727     public void setUiccSubscription(int serial, android.hardware.radio.sim.SelectUiccSub uiccSub) {
728         Log.d(TAG, "setUiccSubscription");
729         // TODO: cache value
730 
731         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
732         try {
733             mRadioSimResponse.setUiccSubscriptionResponse(rsp);
734         } catch (RemoteException ex) {
735             Log.e(TAG, "Failed to setUiccSubscription from AIDL. Exception" + ex);
736         }
737     }
738 
739     @Override
supplyIccPin2ForApp(int serial, String pin2, String aid)740     public void supplyIccPin2ForApp(int serial, String pin2, String aid) {
741         Log.d(TAG, "supplyIccPin2ForApp");
742         // TODO: cache value
743         int setFacilityLockForApp = 10;
744 
745         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
746         try {
747             mRadioSimResponse.supplyIccPin2ForAppResponse(rsp, setFacilityLockForApp);
748         } catch (RemoteException ex) {
749             Log.e(TAG, "Failed to supplyIccPin2ForApp from AIDL. Exception" + ex);
750         }
751     }
752 
753     @Override
supplyIccPinForApp(int serial, String pin, String aid)754     public void supplyIccPinForApp(int serial, String pin, String aid) {
755         Log.d(TAG, "supplyIccPinForApp");
756         // TODO: cache value
757         int setFacilityLockForApp = 10;
758 
759         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
760         try {
761             mRadioSimResponse.supplyIccPinForAppResponse(rsp, setFacilityLockForApp);
762         } catch (RemoteException ex) {
763             Log.e(TAG, "Failed to supplyIccPinForApp from AIDL. Exception" + ex);
764         }
765     }
766 
767     @Override
supplyIccPuk2ForApp(int serial, String puk2, String pin2, String aid)768     public void supplyIccPuk2ForApp(int serial, String puk2, String pin2, String aid) {
769         Log.d(TAG, "supplyIccPuk2ForApp");
770         // TODO: cache value
771         int setFacilityLockForApp = 10;
772 
773         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
774         try {
775             mRadioSimResponse.supplyIccPuk2ForAppResponse(rsp, setFacilityLockForApp);
776         } catch (RemoteException ex) {
777             Log.e(TAG, "Failed to supplyIccPuk2ForApp from AIDL. Exception" + ex);
778         }
779     }
780 
781     @Override
supplyIccPukForApp(int serial, String puk, String pin, String aid)782     public void supplyIccPukForApp(int serial, String puk, String pin, String aid) {
783         Log.d(TAG, "supplyIccPukForApp");
784         // TODO: cache value
785         int setFacilityLockForApp = 10;
786 
787         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
788         try {
789             mRadioSimResponse.supplyIccPukForAppResponse(rsp, setFacilityLockForApp);
790         } catch (RemoteException ex) {
791             Log.e(TAG, "Failed to supplyIccPukForApp from AIDL. Exception" + ex);
792         }
793     }
794 
795     @Override
supplySimDepersonalization(int serial, int persoType, String controlKey)796     public void supplySimDepersonalization(int serial, int persoType, String controlKey) {
797         Log.d(TAG, "supplySimDepersonalization");
798         // TODO: cache value
799         int retPersoType = persoType;
800         int setFacilityLockForApp = 10;
801 
802         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
803         try {
804             mRadioSimResponse.supplySimDepersonalizationResponse(
805                     rsp, retPersoType, setFacilityLockForApp);
806         } catch (RemoteException ex) {
807             Log.e(TAG, "Failed to supplySimDepersonalization from AIDL. Exception" + ex);
808         }
809     }
810 
811     @Override
updateSimPhonebookRecords( int serial, android.hardware.radio.sim.PhonebookRecordInfo recordInfo)812     public void updateSimPhonebookRecords(
813             int serial, android.hardware.radio.sim.PhonebookRecordInfo recordInfo) {
814         Log.d(TAG, "updateSimPhonebookRecords");
815         // TODO: cache value
816         int updatedRecordIndex = 0;
817 
818         RadioResponseInfo rsp = mService.makeSolRsp(serial, RadioError.REQUEST_NOT_SUPPORTED);
819         try {
820             mRadioSimResponse.updateSimPhonebookRecordsResponse(rsp, updatedRecordIndex);
821         } catch (RemoteException ex) {
822             Log.e(TAG, "Failed to updateSimPhonebookRecords from AIDL. Exception" + ex);
823         }
824     }
825 
carrierInfoForImsiEncryption()826     public void carrierInfoForImsiEncryption() {
827         Log.d(TAG, "carrierInfoForImsiEncryption");
828 
829         if (mRadioSimIndication != null) {
830             try {
831                 mRadioSimIndication.carrierInfoForImsiEncryption(RadioIndicationType.UNSOLICITED);
832             } catch (RemoteException ex) {
833                 Log.e(TAG, "Failed to carrierInfoForImsiEncryption from AIDL. Exception" + ex);
834             }
835         } else {
836             Log.e(TAG, "null mRadioSimIndication");
837         }
838     }
839 
cdmaSubscriptionSourceChanged(int cdmaSource)840     public void cdmaSubscriptionSourceChanged(int cdmaSource) {
841         Log.d(TAG, "carrierInfoForImsiEncryption");
842 
843         if (mRadioSimIndication != null) {
844             try {
845                 mRadioSimIndication.cdmaSubscriptionSourceChanged(
846                         RadioIndicationType.UNSOLICITED, cdmaSource);
847             } catch (RemoteException ex) {
848                 Log.e(TAG, "Failed to cdmaSubscriptionSourceChanged from AIDL. Exception" + ex);
849             }
850         } else {
851             Log.e(TAG, "null mRadioSimIndication");
852         }
853     }
854 
simPhonebookChanged()855     public void simPhonebookChanged() {
856         Log.d(TAG, "simPhonebookChanged");
857 
858         if (mRadioSimIndication != null) {
859             try {
860                 mRadioSimIndication.simPhonebookChanged(RadioIndicationType.UNSOLICITED);
861             } catch (RemoteException ex) {
862                 Log.e(TAG, "Failed to simPhonebookChanged from AIDL. Exception" + ex);
863             }
864         } else {
865             Log.e(TAG, "null mRadioSimIndication");
866         }
867     }
868 
simPhonebookRecordsReceived( byte status, android.hardware.radio.sim.PhonebookRecordInfo[] records)869     public void simPhonebookRecordsReceived(
870             byte status, android.hardware.radio.sim.PhonebookRecordInfo[] records) {
871         Log.d(TAG, "simPhonebookRecordsReceived");
872 
873         if (mRadioSimIndication != null) {
874             try {
875                 mRadioSimIndication.simPhonebookRecordsReceived(
876                         RadioIndicationType.UNSOLICITED, status, records);
877             } catch (RemoteException ex) {
878                 Log.e(TAG, "Failed to simPhonebookRecordsReceived from AIDL. Exception" + ex);
879             }
880         } else {
881             Log.e(TAG, "null mRadioSimIndication");
882         }
883     }
884 
simRefresh(SimRefreshResult refreshResult)885     public void simRefresh(SimRefreshResult refreshResult) {
886         Log.d(TAG, "simRefresh");
887 
888         if (mRadioSimIndication != null) {
889             try {
890                 mRadioSimIndication.simRefresh(RadioIndicationType.UNSOLICITED, refreshResult);
891             } catch (RemoteException ex) {
892                 Log.e(TAG, "Failed to simRefresh from AIDL. Exception" + ex);
893             }
894         } else {
895             Log.e(TAG, "null mRadioSimIndication");
896         }
897     }
898 
simStatusChanged()899     public void simStatusChanged() {
900         Log.d(TAG, "simStatusChanged");
901 
902         if (mRadioSimIndication != null) {
903             try {
904                 mRadioSimIndication.simStatusChanged(RadioIndicationType.UNSOLICITED);
905             } catch (RemoteException ex) {
906                 Log.e(TAG, "Failed to simStatusChanged from AIDL. Exception" + ex);
907             }
908         } else {
909             Log.e(TAG, "null mRadioSimIndication");
910         }
911     }
912 
stkEventNotify(String cmd)913     public void stkEventNotify(String cmd) {
914         Log.d(TAG, "stkEventNotify");
915 
916         if (mRadioSimIndication != null) {
917             try {
918                 mRadioSimIndication.stkEventNotify(RadioIndicationType.UNSOLICITED, cmd);
919             } catch (RemoteException ex) {
920                 Log.e(TAG, "Failed to stkEventNotify from AIDL. Exception" + ex);
921             }
922         } else {
923             Log.e(TAG, "null mRadioSimIndication");
924         }
925     }
926 
stkProactiveCommand(String cmd)927     public void stkProactiveCommand(String cmd) {
928         Log.d(TAG, "stkProactiveCommand");
929 
930         if (mRadioSimIndication != null) {
931             try {
932                 mRadioSimIndication.stkProactiveCommand(RadioIndicationType.UNSOLICITED, cmd);
933             } catch (RemoteException ex) {
934                 Log.e(TAG, "Failed to stkProactiveCommand from AIDL. Exception" + ex);
935             }
936         } else {
937             Log.e(TAG, "null mRadioSimIndication");
938         }
939     }
940 
stkSessionEnd()941     public void stkSessionEnd() {
942         Log.d(TAG, "stkSessionEnd");
943 
944         if (mRadioSimIndication != null) {
945             try {
946                 mRadioSimIndication.stkSessionEnd(RadioIndicationType.UNSOLICITED);
947             } catch (RemoteException ex) {
948                 Log.e(TAG, "Failed to stkSessionEnd from AIDL. Exception" + ex);
949             }
950         } else {
951             Log.e(TAG, "null mRadioSimIndication");
952         }
953     }
954 
subscriptionStatusChanged(boolean activate)955     public void subscriptionStatusChanged(boolean activate) {
956         Log.d(TAG, "subscriptionStatusChanged");
957 
958         if (mRadioSimIndication != null) {
959             try {
960                 mRadioSimIndication.subscriptionStatusChanged(
961                         RadioIndicationType.UNSOLICITED, activate);
962             } catch (RemoteException ex) {
963                 Log.e(TAG, "Failed to subscriptionStatusChanged from AIDL. Exception" + ex);
964             }
965         } else {
966             Log.e(TAG, "null mRadioSimIndication");
967         }
968     }
969 
uiccApplicationsEnablementChanged(boolean enabled)970     public void uiccApplicationsEnablementChanged(boolean enabled) {
971         Log.d(TAG, "uiccApplicationsEnablementChanged");
972 
973         if (mRadioSimIndication != null) {
974             try {
975                 mRadioSimIndication.uiccApplicationsEnablementChanged(
976                         RadioIndicationType.UNSOLICITED, enabled);
977             } catch (RemoteException ex) {
978                 Log.e(TAG, "Failed to uiccApplicationsEnablementChanged from AIDL. Exception" + ex);
979             }
980         } else {
981             Log.e(TAG, "null mRadioSimIndication");
982         }
983     }
984 
985     @Override
getInterfaceHash()986     public String getInterfaceHash() {
987         return IRadioSim.HASH;
988     }
989 
990     @Override
getInterfaceVersion()991     public int getInterfaceVersion() {
992         return IRadioSim.VERSION;
993     }
994 }
995