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