• 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 com.android.internal.telephony;
18 
19 import android.os.RemoteException;
20 import android.telephony.CarrierRestrictionRules;
21 import android.telephony.ImsiEncryptionInfo;
22 import android.telephony.Rlog;
23 
24 import com.android.internal.telephony.flags.Flags;
25 import com.android.internal.telephony.uicc.IccCardApplicationStatus.PersoSubState;
26 import com.android.internal.telephony.uicc.SimPhonebookRecord;
27 
28 import java.util.Collections;
29 
30 /**
31  * A holder for IRadioSim.
32  * Use getAidl to get IRadioSim and call the AIDL implementations of the HAL APIs.
33  */
34 public class RadioSimProxy extends RadioServiceProxy {
35     private static final String TAG = "RadioSimProxy";
36     private volatile android.hardware.radio.sim.IRadioSim mSimProxy = null;
37 
38     /**
39      * Set IRadioSim as the AIDL implementation for RadioServiceProxy
40      * @param halVersion Radio HAL version
41      * @param sim IRadioSim implementation
42      *
43      * @return updated HAL version
44      */
setAidl(HalVersion halVersion, android.hardware.radio.sim.IRadioSim sim)45     public HalVersion setAidl(HalVersion halVersion, android.hardware.radio.sim.IRadioSim sim) {
46         HalVersion version = halVersion;
47         try {
48             version = RIL.getServiceHalVersion(sim.getInterfaceVersion());
49         } catch (RemoteException e) {
50             Rlog.e(TAG, "setAidl: " + e);
51         }
52         mHalVersion = version;
53         mSimProxy = sim;
54         mIsAidl = true;
55 
56         Rlog.d(TAG, "AIDL initialized mHalVersion=" + mHalVersion);
57         return mHalVersion;
58     }
59 
60     /**
61      * Get the AIDL implementation of RadioSimProxy
62      * @return IRadioSim implementation
63      */
getAidl()64     public android.hardware.radio.sim.IRadioSim getAidl() {
65         return mSimProxy;
66     }
67 
68     /**
69      * Reset RadioSimProxy
70      */
71     @Override
clear()72     public void clear() {
73         super.clear();
74         mSimProxy = null;
75     }
76 
77     /**
78      * Check whether a RadioSim implementation exists
79      * @return true if there is neither a HIDL nor AIDL implementation
80      */
81     @Override
isEmpty()82     public boolean isEmpty() {
83         return mRadioProxy == null && mSimProxy == null;
84     }
85 
86     /**
87      * Call IRadioSim#areUiccApplicationsEnabled
88      * @param serial Serial number of request
89      * @throws RemoteException
90      */
areUiccApplicationsEnabled(int serial)91     public void areUiccApplicationsEnabled(int serial) throws RemoteException {
92         if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_5)) return;
93         if (isAidl()) {
94             mSimProxy.areUiccApplicationsEnabled(serial);
95         } else {
96             ((android.hardware.radio.V1_5.IRadio) mRadioProxy).areUiccApplicationsEnabled(serial);
97         }
98     }
99 
100     /**
101      * Call IRadioSim#changeIccPin2ForApp
102      * @param serial Serial number of request
103      * @param oldPin2 Old PIN value
104      * @param newPin2 New PIN value
105      * @param aid Application ID
106      * @throws RemoteException
107      */
changeIccPin2ForApp(int serial, String oldPin2, String newPin2, String aid)108     public void changeIccPin2ForApp(int serial, String oldPin2, String newPin2, String aid)
109             throws RemoteException {
110         if (isEmpty()) return;
111         if (isAidl()) {
112             mSimProxy.changeIccPin2ForApp(serial, oldPin2, newPin2, aid);
113         } else {
114             mRadioProxy.changeIccPin2ForApp(serial, oldPin2, newPin2, aid);
115         }
116     }
117 
118     /**
119      * Call IRadioSim#changeIccPinForApp
120      * @param serial Serial number of request
121      * @param oldPin Old PIN value
122      * @param newPin New PIN value
123      * @param aid Application ID
124      * @throws RemoteException
125      */
changeIccPinForApp(int serial, String oldPin, String newPin, String aid)126     public void changeIccPinForApp(int serial, String oldPin, String newPin, String aid)
127             throws RemoteException {
128         if (isEmpty()) return;
129         if (isAidl()) {
130             mSimProxy.changeIccPinForApp(serial, oldPin, newPin, aid);
131         } else {
132             mRadioProxy.changeIccPinForApp(serial, oldPin, newPin, aid);
133         }
134     }
135 
136     /**
137      * Call IRadioSim#enableUiccApplications
138      * @param serial Serial number of request
139      * @param enable Whether or not to enable UiccApplications on the SIM
140      * @throws RemoteException
141      */
enableUiccApplications(int serial, boolean enable)142     public void enableUiccApplications(int serial, boolean enable) throws RemoteException {
143         if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_5)) return;
144         if (isAidl()) {
145             mSimProxy.enableUiccApplications(serial, enable);
146         } else {
147             ((android.hardware.radio.V1_5.IRadio) mRadioProxy).enableUiccApplications(
148                     serial, enable);
149         }
150     }
151 
152     /**
153      * Call IRadioSim#getAllowedCarriers
154      * @param serial Serial number of request
155      * @throws RemoteException
156      */
getAllowedCarriers(int serial)157     public void getAllowedCarriers(int serial) throws RemoteException {
158         if (isEmpty()) return;
159         if (isAidl()) {
160             mSimProxy.getAllowedCarriers(serial);
161         } else {
162             mRadioProxy.getAllowedCarriers_1_4(serial);
163         }
164     }
165 
166     /**
167      * Call IRadioSim#getCdmaSubscription
168      * @param serial Serial number of request
169      * @throws RemoteException
170      */
getCdmaSubscription(int serial)171     public void getCdmaSubscription(int serial) throws RemoteException {
172         if (Flags.cleanupCdma()) return;
173         if (isEmpty()) return;
174         if (isAidl()) {
175             mSimProxy.getCdmaSubscription(serial);
176         } else {
177             mRadioProxy.getCDMASubscription(serial);
178         }
179     }
180 
181     /**
182      * Call IRadioSim#getCdmaSubscriptionSource
183      * @param serial Serial number of request
184      * @throws RemoteException
185      */
getCdmaSubscriptionSource(int serial)186     public void getCdmaSubscriptionSource(int serial) throws RemoteException {
187         if (Flags.cleanupCdma()) return;
188         if (isEmpty()) return;
189         if (isAidl()) {
190             mSimProxy.getCdmaSubscriptionSource(serial);
191         } else {
192             mRadioProxy.getCdmaSubscriptionSource(serial);
193         }
194     }
195 
196     /**
197      * Call IRadioSim#getFacilityLockForApp
198      * @param serial Serial number of request
199      * @param facility One of CB_FACILTY_*
200      * @param password Password or "" if not required
201      * @param serviceClass Sum of SERVICE_CLASS_*
202      * @param appId Application ID or null if none
203      * @throws RemoteException
204      */
getFacilityLockForApp(int serial, String facility, String password, int serviceClass, String appId)205     public void getFacilityLockForApp(int serial, String facility, String password,
206             int serviceClass, String appId) throws RemoteException {
207         if (isEmpty()) return;
208         if (isAidl()) {
209             mSimProxy.getFacilityLockForApp(serial, facility, password, serviceClass, appId);
210         } else {
211             mRadioProxy.getFacilityLockForApp(serial, facility, password, serviceClass, appId);
212         }
213     }
214 
215     /**
216      * Call IRadioSim#getIccCardStatus
217      * @param serial Serial number of request
218      * @throws RemoteException
219      */
getIccCardStatus(int serial)220     public void getIccCardStatus(int serial) throws RemoteException {
221         if (isEmpty()) return;
222         if (isAidl()) {
223             mSimProxy.getIccCardStatus(serial);
224         } else {
225             mRadioProxy.getIccCardStatus(serial);
226         }
227     }
228 
229     /**
230      * Call IRadioSim#getImsiForApp
231      * @param serial Serial number of request
232      * @param aid Application ID
233      * @throws RemoteException
234      */
getImsiForApp(int serial, String aid)235     public void getImsiForApp(int serial, String aid) throws RemoteException {
236         if (isEmpty()) return;
237         if (isAidl()) {
238             mSimProxy.getImsiForApp(serial, aid);
239         } else {
240             mRadioProxy.getImsiForApp(serial, aid);
241         }
242     }
243 
244     /**
245      * Call IRadioSim#getSimPhonebookCapacity
246      * @param serial Serial number of request
247      * @throws RemoteException
248      */
getSimPhonebookCapacity(int serial)249     public void getSimPhonebookCapacity(int serial) throws RemoteException {
250         if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_6)) return;
251         if (isAidl()) {
252             mSimProxy.getSimPhonebookCapacity(serial);
253         } else {
254             ((android.hardware.radio.V1_6.IRadio) mRadioProxy).getSimPhonebookCapacity(serial);
255         }
256     }
257 
258     /**
259      * Call IRadioSim#getSimPhonebookRecords
260      * @param serial Serial number of request
261      * @throws RemoteException
262      */
getSimPhonebookRecords(int serial)263     public void getSimPhonebookRecords(int serial) throws RemoteException {
264         if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_6)) return;
265         if (isAidl()) {
266             mSimProxy.getSimPhonebookRecords(serial);
267         } else {
268             ((android.hardware.radio.V1_6.IRadio) mRadioProxy).getSimPhonebookRecords(serial);
269         }
270     }
271 
272     /**
273      * Call IRadioSim#iccCloseLogicalChannelWithSessionInfo
274      * @param serial Serial number of request
275      * @param channelId Channel ID of the channel to be closed
276      * @param isEs10 Whether the logical channel is opened for performing ES10 operations.
277      * @throws RemoteException
278      */
iccCloseLogicalChannel(int serial, int channelId, boolean isEs10)279     public void iccCloseLogicalChannel(int serial,
280             int channelId, boolean isEs10) throws RemoteException {
281         if (isEmpty()) return;
282         if (isAidl()) {
283             if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_2_1)) {
284                 android.hardware.radio.sim.SessionInfo info =
285                         new android.hardware.radio.sim.SessionInfo();
286                 info.sessionId = channelId;
287                 info.isEs10 = isEs10;
288                 mSimProxy.iccCloseLogicalChannelWithSessionInfo(serial, info);
289                 return;
290             }
291             mSimProxy.iccCloseLogicalChannel(serial, channelId);
292         } else {
293             mRadioProxy.iccCloseLogicalChannel(serial, channelId);
294         }
295     }
296 
297     /**
298      * Call IRadioSim#iccIoForApp
299      * @param serial Serial number of request
300      * @param command Command
301      * @param fileId File ID
302      * @param path Path
303      * @param p1 P1 value of the command
304      * @param p2 P2 value of the command
305      * @param p3 P3 value of the command
306      * @param data Data to be sent
307      * @param pin2 PIN 2 value
308      * @param aid Application ID
309      * @throws RemoteException
310      */
iccIoForApp(int serial, int command, int fileId, String path, int p1, int p2, int p3, String data, String pin2, String aid)311     public void iccIoForApp(int serial, int command, int fileId, String path, int p1, int p2,
312             int p3, String data, String pin2, String aid) throws RemoteException {
313         if (isEmpty()) return;
314         if (isAidl()) {
315             android.hardware.radio.sim.IccIo iccIo = new android.hardware.radio.sim.IccIo();
316             iccIo.command = command;
317             iccIo.fileId = fileId;
318             iccIo.path = path;
319             iccIo.p1 = p1;
320             iccIo.p2 = p2;
321             iccIo.p3 = p3;
322             iccIo.data = data;
323             iccIo.pin2 = pin2;
324             iccIo.aid = aid;
325             mSimProxy.iccIoForApp(serial, iccIo);
326         } else {
327             android.hardware.radio.V1_0.IccIo iccIo = new android.hardware.radio.V1_0.IccIo();
328             iccIo.command = command;
329             iccIo.fileId = fileId;
330             iccIo.path = path;
331             iccIo.p1 = p1;
332             iccIo.p2 = p2;
333             iccIo.p3 = p3;
334             iccIo.data = data;
335             iccIo.pin2 = pin2;
336             iccIo.aid = aid;
337             mRadioProxy.iccIOForApp(serial, iccIo);
338         }
339     }
340 
341     /**
342      * Call IRadioSim#iccOpenLogicalChannel
343      * @param serial Serial number of request
344      * @param aid Application ID
345      * @param p2 P2 value of the command
346      * @throws RemoteException
347      */
iccOpenLogicalChannel(int serial, String aid, int p2)348     public void iccOpenLogicalChannel(int serial, String aid, int p2) throws RemoteException {
349         if (isEmpty()) return;
350         if (isAidl()) {
351             mSimProxy.iccOpenLogicalChannel(serial, aid, p2);
352         } else {
353             mRadioProxy.iccOpenLogicalChannel(serial, aid, p2);
354         }
355     }
356 
357     /**
358      * Call IRadioSim#iccTransmitApduBasicChannel
359      * @param serial Serial number of request
360      * @param cla Class of the command
361      * @param instruction Instruction of the command
362      * @param p1 P1 value of the command
363      * @param p2 P2 value of the command
364      * @param p3 P3 value of the command
365      * @param data Data to be sent
366      * @throws RemoteException
367      */
iccTransmitApduBasicChannel(int serial, int cla, int instruction, int p1, int p2, int p3, String data)368     public void iccTransmitApduBasicChannel(int serial, int cla, int instruction, int p1, int p2,
369             int p3, String data) throws RemoteException {
370         if (isEmpty()) return;
371         if (isAidl()) {
372             mSimProxy.iccTransmitApduBasicChannel(serial,
373                     RILUtils.convertToHalSimApduAidl(0, cla, instruction, p1, p2, p3, data,
374                             false, mHalVersion));
375         } else {
376             mRadioProxy.iccTransmitApduBasicChannel(serial,
377                     RILUtils.convertToHalSimApdu(0, cla, instruction, p1, p2, p3, data));
378         }
379     }
380 
381     /**
382      * Call IRadioSim#iccTransmitApduLogicalChannel
383      * @param serial Serial number of request
384      * @param channel Channel ID of the channel to use for communication
385      * @param cla Class of the command
386      * @param instruction Instruction of the command
387      * @param p1 P1 value of the command
388      * @param p2 P2 value of the command
389      * @param p3 P3 value of the command
390      * @param data Data to be sent
391      * @throws RemoteException
392      */
iccTransmitApduLogicalChannel(int serial, int channel, int cla, int instruction, int p1, int p2, int p3, String data)393     public void iccTransmitApduLogicalChannel(int serial, int channel, int cla, int instruction,
394             int p1, int p2, int p3, String data) throws RemoteException {
395         iccTransmitApduLogicalChannel(serial, channel, cla, instruction, p1, p2, p3, data, false);
396     }
397 
398     /**
399      * Call IRadioSim#iccTransmitApduLogicalChannel
400      * @param serial Serial number of request
401      * @param channel Channel ID of the channel to use for communication
402      * @param cla Class of the command
403      * @param instruction Instruction of the command
404      * @param p1 P1 value of the command
405      * @param p2 P2 value of the command
406      * @param p3 P3 value of the command
407      * @param data Data to be sent
408      * @param isEs10Command APDU is an isEs10 command or not
409      * @throws RemoteException
410      */
iccTransmitApduLogicalChannel(int serial, int channel, int cla, int instruction, int p1, int p2, int p3, String data, boolean isEs10Command)411     public void iccTransmitApduLogicalChannel(int serial, int channel, int cla, int instruction,
412             int p1, int p2, int p3, String data, boolean isEs10Command) throws RemoteException {
413         if (isEmpty()) return;
414         if (isAidl()) {
415             mSimProxy.iccTransmitApduLogicalChannel(serial,
416                     RILUtils.convertToHalSimApduAidl(channel, cla, instruction, p1, p2, p3, data,
417                             isEs10Command, mHalVersion));
418         } else {
419             mRadioProxy.iccTransmitApduLogicalChannel(serial,
420                     RILUtils.convertToHalSimApdu(channel, cla, instruction, p1, p2, p3, data));
421         }
422     }
423 
424     /**
425      * Call IRadioSim#reportStkServiceIsRunning
426      * @param serial Serial number of request
427      * @throws RemoteException
428      */
reportStkServiceIsRunning(int serial)429     public void reportStkServiceIsRunning(int serial) throws RemoteException {
430         if (isEmpty()) return;
431         if (isAidl()) {
432             mSimProxy.reportStkServiceIsRunning(serial);
433         } else {
434             mRadioProxy.reportStkServiceIsRunning(serial);
435         }
436     }
437 
438     /**
439      * Call IRadioSim#requestIccSimAuthentication
440      * @param serial Serial number of request
441      * @param authContext P2 parameter that specifies the authentication context
442      * @param authData Authentication challenge data
443      * @param aid Application ID of the application/slot to send the auth command to
444      * @throws RemoteException
445      */
requestIccSimAuthentication(int serial, int authContext, String authData, String aid)446     public void requestIccSimAuthentication(int serial, int authContext, String authData,
447             String aid) throws RemoteException {
448         if (isEmpty()) return;
449         if (isAidl()) {
450             mSimProxy.requestIccSimAuthentication(serial, authContext, authData, aid);
451         } else {
452             mRadioProxy.requestIccSimAuthentication(serial, authContext, authData, aid);
453         }
454     }
455 
456     /**
457      * Call IRadioSim#responseAcknowledgement
458      * @throws RemoteException
459      */
460     @Override
responseAcknowledgement()461     public void responseAcknowledgement() throws RemoteException {
462         if (isEmpty()) return;
463         if (isAidl()) {
464             mSimProxy.responseAcknowledgement();
465         } else {
466             mRadioProxy.responseAcknowledgement();
467         }
468     }
469 
470     /**
471      * Call IRadioSim#sendEnvelope
472      * @param serial Serial number of request
473      * @param contents String containing SAT/USAT response in hexadecimal format starting with
474      *                 command tag
475      * @throws RemoteException
476      */
sendEnvelope(int serial, String contents)477     public void sendEnvelope(int serial, String contents) throws RemoteException {
478         if (isEmpty()) return;
479         if (isAidl()) {
480             mSimProxy.sendEnvelope(serial, contents);
481         } else {
482             mRadioProxy.sendEnvelope(serial, contents);
483         }
484     }
485 
486     /**
487      * Call IRadioSim#sendEnvelopeWithStatus
488      * @param serial Serial number of request
489      * @param contents String containing SAT/USAT response in hexadecimal format starting with
490      *                 command tag
491      * @throws RemoteException
492      */
sendEnvelopeWithStatus(int serial, String contents)493     public void sendEnvelopeWithStatus(int serial, String contents) throws RemoteException {
494         if (isEmpty()) return;
495         if (isAidl()) {
496             mSimProxy.sendEnvelopeWithStatus(serial, contents);
497         } else {
498             mRadioProxy.sendEnvelopeWithStatus(serial, contents);
499         }
500     }
501 
502     /**
503      * Call IRadioSim#sendTerminalResponseToSim
504      * @param serial Serial number of request
505      * @param contents String containing SAT/USAT response in hexadecimal format starting with
506      *                 first byte of response data
507      * @throws RemoteException
508      */
sendTerminalResponseToSim(int serial, String contents)509     public void sendTerminalResponseToSim(int serial, String contents) throws RemoteException {
510         if (isEmpty()) return;
511         if (isAidl()) {
512             mSimProxy.sendTerminalResponseToSim(serial, contents);
513         } else {
514             mRadioProxy.sendTerminalResponseToSim(serial, contents);
515         }
516     }
517 
518     /**
519      * Call IRadioSim#setAllowedCarriers
520      *
521      * @param serial                  Serial number of request
522      * @param carrierRestrictionRules Allowed carriers
523      */
setAllowedCarriers(int serial, CarrierRestrictionRules carrierRestrictionRules, HalVersion halversion)524     public void setAllowedCarriers(int serial, CarrierRestrictionRules carrierRestrictionRules,
525             HalVersion halversion) throws RemoteException {
526         if (isEmpty()) return;
527         if (isAidl()) {
528             android.hardware.radio.sim.CarrierRestrictions carrierRestrictions =
529                     new android.hardware.radio.sim.CarrierRestrictions();
530             if (halversion.greaterOrEqual(RIL.RADIO_HAL_VERSION_2_2)) {
531                 carrierRestrictions.allowedCarrierInfoList =
532                         RILUtils.convertToHalCarrierInfoListAidl(
533                                 carrierRestrictionRules.getAllowedCarriers());
534                 carrierRestrictions.excludedCarrierInfoList =
535                         RILUtils.convertToHalCarrierInfoListAidl(
536                                 carrierRestrictionRules.getExcludedCarriers());
537                 carrierRestrictions.allowedCarriers =
538                         RILUtils.convertToHalCarrierRestrictionListAidl(Collections.EMPTY_LIST);
539                 carrierRestrictions.excludedCarriers =
540                         RILUtils.convertToHalCarrierRestrictionListAidl(Collections.EMPTY_LIST);
541             } else {
542                 // Prepare structure with allowed list, excluded list and priority
543                 carrierRestrictions.allowedCarriers =
544                         RILUtils.convertToHalCarrierRestrictionListAidl(
545                                 carrierRestrictionRules.getAllowedCarriers());
546                 carrierRestrictions.excludedCarriers =
547                         RILUtils.convertToHalCarrierRestrictionListAidl(
548                                 carrierRestrictionRules.getExcludedCarriers());
549             }
550             carrierRestrictions.allowedCarriersPrioritized =
551                     (carrierRestrictionRules.getDefaultCarrierRestriction()
552                             == CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_NOT_ALLOWED);
553             carrierRestrictions.status = carrierRestrictionRules.getCarrierRestrictionStatus();
554             mSimProxy.setAllowedCarriers(serial, carrierRestrictions,
555                     RILUtils.convertToHalSimLockMultiSimPolicyAidl(
556                             carrierRestrictionRules.getMultiSimPolicy()));
557             Rlog.d(TAG, "RadioSimProxy setAllowedCarriers params = " + carrierRestrictions);
558         } else {
559             // Prepare structure with allowed list, excluded list and priority
560             android.hardware.radio.V1_4.CarrierRestrictionsWithPriority carrierRestrictions =
561                     new android.hardware.radio.V1_4.CarrierRestrictionsWithPriority();
562             carrierRestrictions.allowedCarriers = RILUtils.convertToHalCarrierRestrictionList(
563                     carrierRestrictionRules.getAllowedCarriers());
564             carrierRestrictions.excludedCarriers = RILUtils.convertToHalCarrierRestrictionList(
565                     carrierRestrictionRules.getExcludedCarriers());
566             carrierRestrictions.allowedCarriersPrioritized =
567                     (carrierRestrictionRules.getDefaultCarrierRestriction()
568                             == CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_NOT_ALLOWED);
569             mRadioProxy.setAllowedCarriers_1_4(serial, carrierRestrictions,
570                     RILUtils.convertToHalSimLockMultiSimPolicy(
571                             carrierRestrictionRules.getMultiSimPolicy()));
572         }
573     }
574 
575     /**
576      * Call IRadioSim#setCarrierInfoForImsiEncryption
577      * @param serial Serial number of request
578      * @param imsiEncryptionInfo ImsiEncryptionInfo
579      * @throws RemoteException
580      */
setCarrierInfoForImsiEncryption(int serial, ImsiEncryptionInfo imsiEncryptionInfo)581     public void setCarrierInfoForImsiEncryption(int serial, ImsiEncryptionInfo imsiEncryptionInfo)
582             throws RemoteException {
583         if (isEmpty()) return;
584         if (isAidl()) {
585             android.hardware.radio.sim.ImsiEncryptionInfo halImsiInfo =
586                     new android.hardware.radio.sim.ImsiEncryptionInfo();
587             halImsiInfo.mnc = imsiEncryptionInfo.getMnc();
588             halImsiInfo.mcc = imsiEncryptionInfo.getMcc();
589             halImsiInfo.keyIdentifier = imsiEncryptionInfo.getKeyIdentifier();
590             if (imsiEncryptionInfo.getExpirationTime() != null) {
591                 halImsiInfo.expirationTime = imsiEncryptionInfo.getExpirationTime().getTime();
592             }
593             halImsiInfo.carrierKey = imsiEncryptionInfo.getPublicKey().getEncoded();
594             halImsiInfo.keyType = (byte) imsiEncryptionInfo.getKeyType();
595 
596             mSimProxy.setCarrierInfoForImsiEncryption(serial, halImsiInfo);
597         } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) {
598             android.hardware.radio.V1_6.ImsiEncryptionInfo halImsiInfo =
599                     new android.hardware.radio.V1_6.ImsiEncryptionInfo();
600             halImsiInfo.base.mnc = imsiEncryptionInfo.getMnc();
601             halImsiInfo.base.mcc = imsiEncryptionInfo.getMcc();
602             halImsiInfo.base.keyIdentifier = imsiEncryptionInfo.getKeyIdentifier();
603             if (imsiEncryptionInfo.getExpirationTime() != null) {
604                 halImsiInfo.base.expirationTime = imsiEncryptionInfo.getExpirationTime().getTime();
605             }
606             for (byte b : imsiEncryptionInfo.getPublicKey().getEncoded()) {
607                 halImsiInfo.base.carrierKey.add(Byte.valueOf(b));
608             }
609             halImsiInfo.keyType = (byte) imsiEncryptionInfo.getKeyType();
610 
611             ((android.hardware.radio.V1_6.IRadio) mRadioProxy).setCarrierInfoForImsiEncryption_1_6(
612                     serial, halImsiInfo);
613         } else {
614             android.hardware.radio.V1_1.ImsiEncryptionInfo halImsiInfo =
615                     new android.hardware.radio.V1_1.ImsiEncryptionInfo();
616             halImsiInfo.mnc = imsiEncryptionInfo.getMnc();
617             halImsiInfo.mcc = imsiEncryptionInfo.getMcc();
618             halImsiInfo.keyIdentifier = imsiEncryptionInfo.getKeyIdentifier();
619             if (imsiEncryptionInfo.getExpirationTime() != null) {
620                 halImsiInfo.expirationTime = imsiEncryptionInfo.getExpirationTime().getTime();
621             }
622             for (byte b : imsiEncryptionInfo.getPublicKey().getEncoded()) {
623                 halImsiInfo.carrierKey.add(Byte.valueOf(b));
624             }
625 
626             mRadioProxy.setCarrierInfoForImsiEncryption(serial, halImsiInfo);
627         }
628     }
629 
630     /**
631      * Call IRadioSim#setCdmaSubscriptionSource
632      * @param serial Serial number of request
633      * @param cdmaSub One of  CDMA_SUBSCRIPTION_*
634      * @throws RemoteException
635      */
setCdmaSubscriptionSource(int serial, int cdmaSub)636     public void setCdmaSubscriptionSource(int serial, int cdmaSub) throws RemoteException {
637         if (Flags.cleanupCdma()) return;
638         if (isEmpty()) return;
639         if (isAidl()) {
640             mSimProxy.setCdmaSubscriptionSource(serial, cdmaSub);
641         } else {
642             mRadioProxy.setCdmaSubscriptionSource(serial, cdmaSub);
643         }
644     }
645 
646     /**
647      * Call IRadioSim#setFacilityLockForApp
648      * @param serial Serial number of request
649      * @param facility One of CB_FACILTY_*
650      * @param lockState True means lock, false means unlock
651      * @param password Password or "" if not required
652      * @param serviceClass Sum of SERVICE_CLASS_*
653      * @param appId Application ID or null if none
654      * @throws RemoteException
655      */
setFacilityLockForApp(int serial, String facility, boolean lockState, String password, int serviceClass, String appId)656     public void setFacilityLockForApp(int serial, String facility, boolean lockState,
657             String password, int serviceClass, String appId) throws RemoteException {
658         if (isEmpty()) return;
659         if (isAidl()) {
660             mSimProxy.setFacilityLockForApp(
661                     serial, facility, lockState, password, serviceClass, appId);
662         } else {
663             mRadioProxy.setFacilityLockForApp(
664                     serial, facility, lockState, password, serviceClass, appId);
665         }
666     }
667 
668     /**
669      * Call IRadioSim#setSimCardPower
670      * @param serial Serial number of request
671      * @param state SIM state (power down, power up, pass through)
672      * @throws RemoteException
673      */
setSimCardPower(int serial, int state)674     public void setSimCardPower(int serial, int state) throws RemoteException {
675         if (isEmpty()) return;
676         if (isAidl()) {
677             mSimProxy.setSimCardPower(serial, state);
678         } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) {
679             ((android.hardware.radio.V1_6.IRadio) mRadioProxy).setSimCardPower_1_6(serial, state);
680         } else {
681             mRadioProxy.setSimCardPower_1_1(serial, state);
682         }
683     }
684 
685     /**
686      * Call IRadioSim#setUiccSubscription
687      * @param serial Serial number of request
688      * @param slotId Slot ID
689      * @param appIndex Application index in the card
690      * @param subId Subscription ID
691      * @param subStatus Activation status; 1 = activate and 0 = deactivate
692      * @throws RemoteException
693      */
setUiccSubscription(int serial, int slotId, int appIndex, int subId, int subStatus)694     public void setUiccSubscription(int serial, int slotId, int appIndex, int subId, int subStatus)
695             throws RemoteException {
696         if (Flags.cleanupCdma()) return;
697         if (isEmpty()) return;
698         if (isAidl()) {
699             android.hardware.radio.sim.SelectUiccSub info =
700                     new android.hardware.radio.sim.SelectUiccSub();
701             info.slot = slotId;
702             info.appIndex = appIndex;
703             info.subType = subId;
704             info.actStatus = subStatus;
705             mSimProxy.setUiccSubscription(serial, info);
706         } else {
707             android.hardware.radio.V1_0.SelectUiccSub info =
708                     new android.hardware.radio.V1_0.SelectUiccSub();
709             info.slot = slotId;
710             info.appIndex = appIndex;
711             info.subType = subId;
712             info.actStatus = subStatus;
713             mRadioProxy.setUiccSubscription(serial, info);
714         }
715     }
716 
717     /**
718      * Call IRadioSim#supplyIccPin2ForApp
719      * @param serial Serial number of request
720      * @param pin2 PIN 2 value
721      * @param aid Application ID
722      * @throws RemoteException
723      */
supplyIccPin2ForApp(int serial, String pin2, String aid)724     public void supplyIccPin2ForApp(int serial, String pin2, String aid) throws RemoteException {
725         if (isEmpty()) return;
726         if (isAidl()) {
727             mSimProxy.supplyIccPin2ForApp(serial, pin2, aid);
728         } else {
729             mRadioProxy.supplyIccPin2ForApp(serial, pin2, aid);
730         }
731     }
732 
733     /**
734      * Call IRadioSim#supplyIccPinForApp
735      * @param serial Serial number of request
736      * @param pin PIN value
737      * @param aid Application ID
738      * @throws RemoteException
739      */
supplyIccPinForApp(int serial, String pin, String aid)740     public void supplyIccPinForApp(int serial, String pin, String aid) throws RemoteException {
741         if (isEmpty()) return;
742         if (isAidl()) {
743             mSimProxy.supplyIccPinForApp(serial, pin, aid);
744         } else {
745             mRadioProxy.supplyIccPinForApp(serial, pin, aid);
746         }
747     }
748 
749     /**
750      * Call IRadioSim#supplyIccPuk2ForApp
751      * @param serial Serial number of request
752      * @param puk2 PUK 2 value
753      * @param pin2 PIN 2 value
754      * @param aid Application ID
755      * @throws RemoteException
756      */
supplyIccPuk2ForApp(int serial, String puk2, String pin2, String aid)757     public void supplyIccPuk2ForApp(int serial, String puk2, String pin2, String aid)
758             throws RemoteException {
759         if (isEmpty()) return;
760         if (isAidl()) {
761             mSimProxy.supplyIccPuk2ForApp(serial, puk2, pin2, aid);
762         } else {
763             mRadioProxy.supplyIccPuk2ForApp(serial, puk2, pin2, aid);
764         }
765     }
766 
767     /**
768      * Call IRadioSim#supplyIccPukForApp
769      * @param serial Serial number of request
770      * @param puk PUK value
771      * @param pin PIN value
772      * @param aid Application ID
773      * @throws RemoteException
774      */
supplyIccPukForApp(int serial, String puk, String pin, String aid)775     public void supplyIccPukForApp(int serial, String puk, String pin, String aid)
776             throws RemoteException {
777         if (isEmpty()) return;
778         if (isAidl()) {
779             mSimProxy.supplyIccPukForApp(serial, puk, pin, aid);
780         } else {
781             mRadioProxy.supplyIccPukForApp(serial, puk, pin, aid);
782         }
783     }
784 
785     /**
786      * Call IRadioSim#supplySimDepersonalization
787      * @param serial Serial number of request
788      * @param persoType SIM personalization type
789      * @param controlKey Unlock code for removing SIM personalization from this device
790      * @throws RemoteException
791      */
supplySimDepersonalization(int serial, PersoSubState persoType, String controlKey)792     public void supplySimDepersonalization(int serial, PersoSubState persoType, String controlKey)
793             throws RemoteException {
794         if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_5)) return;
795         if (isAidl()) {
796             mSimProxy.supplySimDepersonalization(serial,
797                     RILUtils.convertToHalPersoTypeAidl(persoType), controlKey);
798         } else {
799             ((android.hardware.radio.V1_5.IRadio) mRadioProxy).supplySimDepersonalization(serial,
800                     RILUtils.convertToHalPersoType(persoType), controlKey);
801         }
802     }
803 
804     /**
805      * Call IRadioSim#updateSimPhonebookRecords
806      * @param serial Serial number of request
807      * @param recordInfo ADN record information to be updated
808      * @throws RemoteException
809      */
updateSimPhonebookRecords(int serial, SimPhonebookRecord recordInfo)810     public void updateSimPhonebookRecords(int serial, SimPhonebookRecord recordInfo)
811             throws RemoteException {
812         if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_6)) return;
813         if (isAidl()) {
814             mSimProxy.updateSimPhonebookRecords(serial,
815                     RILUtils.convertToHalPhonebookRecordInfoAidl(recordInfo));
816         } else {
817             ((android.hardware.radio.V1_6.IRadio) mRadioProxy).updateSimPhonebookRecords(serial,
818                     RILUtils.convertToHalPhonebookRecordInfo(recordInfo));
819         }
820     }
821 }
822