aboutsummaryrefslogtreecommitdiff
path: root/src/java/com/android/internal/telephony/RadioSimProxy.java
blob: 5265692167c4069f39f84841d6694cfb7618f54c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony;

import android.os.RemoteException;
import android.telephony.CarrierRestrictionRules;
import android.telephony.ImsiEncryptionInfo;
import android.telephony.Rlog;

import com.android.internal.telephony.uicc.IccCardApplicationStatus.PersoSubState;
import com.android.internal.telephony.uicc.SimPhonebookRecord;

/**
 * A holder for IRadioSim.
 * Use getAidl to get IRadioSim and call the AIDL implementations of the HAL APIs.
 */
public class RadioSimProxy extends RadioServiceProxy {
    private static final String TAG = "RadioSimProxy";
    private volatile android.hardware.radio.sim.IRadioSim mSimProxy = null;

    /**
     * Set IRadioSim as the AIDL implementation for RadioServiceProxy
     * @param halVersion Radio HAL version
     * @param sim IRadioSim implementation
     *
     * @return updated HAL version
     */
    public HalVersion setAidl(HalVersion halVersion, android.hardware.radio.sim.IRadioSim sim) {
        HalVersion version = halVersion;
        try {
            version = RIL.getServiceHalVersion(sim.getInterfaceVersion());
        } catch (RemoteException e) {
            Rlog.e(TAG, "setAidl: " + e);
        }
        mHalVersion = version;
        mSimProxy = sim;
        mIsAidl = true;

        Rlog.d(TAG, "AIDL initialized mHalVersion=" + mHalVersion);
        return mHalVersion;
    }

    /**
     * Get the AIDL implementation of RadioSimProxy
     * @return IRadioSim implementation
     */
    public android.hardware.radio.sim.IRadioSim getAidl() {
        return mSimProxy;
    }

    /**
     * Reset RadioSimProxy
     */
    @Override
    public void clear() {
        super.clear();
        mSimProxy = null;
    }

    /**
     * Check whether a RadioSim implementation exists
     * @return true if there is neither a HIDL nor AIDL implementation
     */
    @Override
    public boolean isEmpty() {
        return mRadioProxy == null && mSimProxy == null;
    }

    /**
     * Call IRadioSim#areUiccApplicationsEnabled
     * @param serial Serial number of request
     * @throws RemoteException
     */
    public void areUiccApplicationsEnabled(int serial) throws RemoteException {
        if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_5)) return;
        if (isAidl()) {
            mSimProxy.areUiccApplicationsEnabled(serial);
        } else {
            ((android.hardware.radio.V1_5.IRadio) mRadioProxy).areUiccApplicationsEnabled(serial);
        }
    }

    /**
     * Call IRadioSim#changeIccPin2ForApp
     * @param serial Serial number of request
     * @param oldPin2 Old PIN value
     * @param newPin2 New PIN value
     * @param aid Application ID
     * @throws RemoteException
     */
    public void changeIccPin2ForApp(int serial, String oldPin2, String newPin2, String aid)
            throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mSimProxy.changeIccPin2ForApp(serial, oldPin2, newPin2, aid);
        } else {
            mRadioProxy.changeIccPin2ForApp(serial, oldPin2, newPin2, aid);
        }
    }

    /**
     * Call IRadioSim#changeIccPinForApp
     * @param serial Serial number of request
     * @param oldPin Old PIN value
     * @param newPin New PIN value
     * @param aid Application ID
     * @throws RemoteException
     */
    public void changeIccPinForApp(int serial, String oldPin, String newPin, String aid)
            throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mSimProxy.changeIccPinForApp(serial, oldPin, newPin, aid);
        } else {
            mRadioProxy.changeIccPinForApp(serial, oldPin, newPin, aid);
        }
    }

    /**
     * Call IRadioSim#enableUiccApplications
     * @param serial Serial number of request
     * @param enable Whether or not to enable UiccApplications on the SIM
     * @throws RemoteException
     */
    public void enableUiccApplications(int serial, boolean enable) throws RemoteException {
        if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_5)) return;
        if (isAidl()) {
            mSimProxy.enableUiccApplications(serial, enable);
        } else {
            ((android.hardware.radio.V1_5.IRadio) mRadioProxy).enableUiccApplications(
                    serial, enable);
        }
    }

    /**
     * Call IRadioSim#getAllowedCarriers
     * @param serial Serial number of request
     * @throws RemoteException
     */
    public void getAllowedCarriers(int serial) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mSimProxy.getAllowedCarriers(serial);
        } else {
            mRadioProxy.getAllowedCarriers_1_4(serial);
        }
    }

    /**
     * Call IRadioSim#getCdmaSubscription
     * @param serial Serial number of request
     * @throws RemoteException
     */
    public void getCdmaSubscription(int serial) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mSimProxy.getCdmaSubscription(serial);
        } else {
            mRadioProxy.getCDMASubscription(serial);
        }
    }

    /**
     * Call IRadioSim#getCdmaSubscriptionSource
     * @param serial Serial number of request
     * @throws RemoteException
     */
    public void getCdmaSubscriptionSource(int serial) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mSimProxy.getCdmaSubscriptionSource(serial);
        } else {
            mRadioProxy.getCdmaSubscriptionSource(serial);
        }
    }

    /**
     * Call IRadioSim#getFacilityLockForApp
     * @param serial Serial number of request
     * @param facility One of CB_FACILTY_*
     * @param password Password or "" if not required
     * @param serviceClass Sum of SERVICE_CLASS_*
     * @param appId Application ID or null if none
     * @throws RemoteException
     */
    public void getFacilityLockForApp(int serial, String facility, String password,
            int serviceClass, String appId) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mSimProxy.getFacilityLockForApp(serial, facility, password, serviceClass, appId);
        } else {
            mRadioProxy.getFacilityLockForApp(serial, facility, password, serviceClass, appId);
        }
    }

    /**
     * Call IRadioSim#getIccCardStatus
     * @param serial Serial number of request
     * @throws RemoteException
     */
    public void getIccCardStatus(int serial) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mSimProxy.getIccCardStatus(serial);
        } else {
            mRadioProxy.getIccCardStatus(serial);
        }
    }

    /**
     * Call IRadioSim#getImsiForApp
     * @param serial Serial number of request
     * @param aid Application ID
     * @throws RemoteException
     */
    public void getImsiForApp(int serial, String aid) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mSimProxy.getImsiForApp(serial, aid);
        } else {
            mRadioProxy.getImsiForApp(serial, aid);
        }
    }

    /**
     * Call IRadioSim#getSimPhonebookCapacity
     * @param serial Serial number of request
     * @throws RemoteException
     */
    public void getSimPhonebookCapacity(int serial) throws RemoteException {
        if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_6)) return;
        if (isAidl()) {
            mSimProxy.getSimPhonebookCapacity(serial);
        } else {
            ((android.hardware.radio.V1_6.IRadio) mRadioProxy).getSimPhonebookCapacity(serial);
        }
    }

    /**
     * Call IRadioSim#getSimPhonebookRecords
     * @param serial Serial number of request
     * @throws RemoteException
     */
    public void getSimPhonebookRecords(int serial) throws RemoteException {
        if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_6)) return;
        if (isAidl()) {
            mSimProxy.getSimPhonebookRecords(serial);
        } else {
            ((android.hardware.radio.V1_6.IRadio) mRadioProxy).getSimPhonebookRecords(serial);
        }
    }

    /**
     * Call IRadioSim#iccCloseLogicalChannelWithSessionInfo
     * @param serial Serial number of request
     * @param channelId Channel ID of the channel to be closed
     * @param isEs10 Whether the logical channel is opened for performing ES10 operations.
     * @throws RemoteException
     */
    public void iccCloseLogicalChannel(int serial,
            int channelId, boolean isEs10) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_2_1)) {
                android.hardware.radio.sim.SessionInfo info =
                        new android.hardware.radio.sim.SessionInfo();
                info.sessionId = channelId;
                info.isEs10 = isEs10;
                mSimProxy.iccCloseLogicalChannelWithSessionInfo(serial, info);
                return;
            }
            mSimProxy.iccCloseLogicalChannel(serial, channelId);
        } else {
            mRadioProxy.iccCloseLogicalChannel(serial, channelId);
        }
    }

    /**
     * Call IRadioSim#iccIoForApp
     * @param serial Serial number of request
     * @param command Command
     * @param fileId File ID
     * @param path Path
     * @param p1 P1 value of the command
     * @param p2 P2 value of the command
     * @param p3 P3 value of the command
     * @param data Data to be sent
     * @param pin2 PIN 2 value
     * @param aid Application ID
     * @throws RemoteException
     */
    public void iccIoForApp(int serial, int command, int fileId, String path, int p1, int p2,
            int p3, String data, String pin2, String aid) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            android.hardware.radio.sim.IccIo iccIo = new android.hardware.radio.sim.IccIo();
            iccIo.command = command;
            iccIo.fileId = fileId;
            iccIo.path = path;
            iccIo.p1 = p1;
            iccIo.p2 = p2;
            iccIo.p3 = p3;
            iccIo.data = data;
            iccIo.pin2 = pin2;
            iccIo.aid = aid;
            mSimProxy.iccIoForApp(serial, iccIo);
        } else {
            android.hardware.radio.V1_0.IccIo iccIo = new android.hardware.radio.V1_0.IccIo();
            iccIo.command = command;
            iccIo.fileId = fileId;
            iccIo.path = path;
            iccIo.p1 = p1;
            iccIo.p2 = p2;
            iccIo.p3 = p3;
            iccIo.data = data;
            iccIo.pin2 = pin2;
            iccIo.aid = aid;
            mRadioProxy.iccIOForApp(serial, iccIo);
        }
    }

    /**
     * Call IRadioSim#iccOpenLogicalChannel
     * @param serial Serial number of request
     * @param aid Application ID
     * @param p2 P2 value of the command
     * @throws RemoteException
     */
    public void iccOpenLogicalChannel(int serial, String aid, int p2) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mSimProxy.iccOpenLogicalChannel(serial, aid, p2);
        } else {
            mRadioProxy.iccOpenLogicalChannel(serial, aid, p2);
        }
    }

    /**
     * Call IRadioSim#iccTransmitApduBasicChannel
     * @param serial Serial number of request
     * @param cla Class of the command
     * @param instruction Instruction of the command
     * @param p1 P1 value of the command
     * @param p2 P2 value of the command
     * @param p3 P3 value of the command
     * @param data Data to be sent
     * @throws RemoteException
     */
    public void iccTransmitApduBasicChannel(int serial, int cla, int instruction, int p1, int p2,
            int p3, String data) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mSimProxy.iccTransmitApduBasicChannel(serial,
                    RILUtils.convertToHalSimApduAidl(0, cla, instruction, p1, p2, p3, data,
                            false, mHalVersion));
        } else {
            mRadioProxy.iccTransmitApduBasicChannel(serial,
                    RILUtils.convertToHalSimApdu(0, cla, instruction, p1, p2, p3, data));
        }
    }

    /**
     * Call IRadioSim#iccTransmitApduLogicalChannel
     * @param serial Serial number of request
     * @param channel Channel ID of the channel to use for communication
     * @param cla Class of the command
     * @param instruction Instruction of the command
     * @param p1 P1 value of the command
     * @param p2 P2 value of the command
     * @param p3 P3 value of the command
     * @param data Data to be sent
     * @throws RemoteException
     */
    public void iccTransmitApduLogicalChannel(int serial, int channel, int cla, int instruction,
            int p1, int p2, int p3, String data) throws RemoteException {
        iccTransmitApduLogicalChannel(serial, channel, cla, instruction, p1, p2, p3, data, false);
    }

    /**
     * Call IRadioSim#iccTransmitApduLogicalChannel
     * @param serial Serial number of request
     * @param channel Channel ID of the channel to use for communication
     * @param cla Class of the command
     * @param instruction Instruction of the command
     * @param p1 P1 value of the command
     * @param p2 P2 value of the command
     * @param p3 P3 value of the command
     * @param data Data to be sent
     * @param isEs10Command APDU is an isEs10 command or not
     * @throws RemoteException
     */
    public void iccTransmitApduLogicalChannel(int serial, int channel, int cla, int instruction,
            int p1, int p2, int p3, String data, boolean isEs10Command) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mSimProxy.iccTransmitApduLogicalChannel(serial,
                    RILUtils.convertToHalSimApduAidl(channel, cla, instruction, p1, p2, p3, data,
                            isEs10Command, mHalVersion));
        } else {
            mRadioProxy.iccTransmitApduLogicalChannel(serial,
                    RILUtils.convertToHalSimApdu(channel, cla, instruction, p1, p2, p3, data));
        }
    }

    /**
     * Call IRadioSim#reportStkServiceIsRunning
     * @param serial Serial number of request
     * @throws RemoteException
     */
    public void reportStkServiceIsRunning(int serial) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mSimProxy.reportStkServiceIsRunning(serial);
        } else {
            mRadioProxy.reportStkServiceIsRunning(serial);
        }
    }

    /**
     * Call IRadioSim#requestIccSimAuthentication
     * @param serial Serial number of request
     * @param authContext P2 parameter that specifies the authentication context
     * @param authData Authentication challenge data
     * @param aid Application ID of the application/slot to send the auth command to
     * @throws RemoteException
     */
    public void requestIccSimAuthentication(int serial, int authContext, String authData,
            String aid) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mSimProxy.requestIccSimAuthentication(serial, authContext, authData, aid);
        } else {
            mRadioProxy.requestIccSimAuthentication(serial, authContext, authData, aid);
        }
    }

    /**
     * Call IRadioSim#responseAcknowledgement
     * @throws RemoteException
     */
    @Override
    public void responseAcknowledgement() throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mSimProxy.responseAcknowledgement();
        } else {
            mRadioProxy.responseAcknowledgement();
        }
    }

    /**
     * Call IRadioSim#sendEnvelope
     * @param serial Serial number of request
     * @param contents String containing SAT/USAT response in hexadecimal format starting with
     *                 command tag
     * @throws RemoteException
     */
    public void sendEnvelope(int serial, String contents) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mSimProxy.sendEnvelope(serial, contents);
        } else {
            mRadioProxy.sendEnvelope(serial, contents);
        }
    }

    /**
     * Call IRadioSim#sendEnvelopeWithStatus
     * @param serial Serial number of request
     * @param contents String containing SAT/USAT response in hexadecimal format starting with
     *                 command tag
     * @throws RemoteException
     */
    public void sendEnvelopeWithStatus(int serial, String contents) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mSimProxy.sendEnvelopeWithStatus(serial, contents);
        } else {
            mRadioProxy.sendEnvelopeWithStatus(serial, contents);
        }
    }

    /**
     * Call IRadioSim#sendTerminalResponseToSim
     * @param serial Serial number of request
     * @param contents String containing SAT/USAT response in hexadecimal format starting with
     *                 first byte of response data
     * @throws RemoteException
     */
    public void sendTerminalResponseToSim(int serial, String contents) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mSimProxy.sendTerminalResponseToSim(serial, contents);
        } else {
            mRadioProxy.sendTerminalResponseToSim(serial, contents);
        }
    }

    /**
     * Call IRadioSim#setAllowedCarriers
     * @param serial Serial number of request
     * @param carrierRestrictionRules Allowed carriers
     * @throws RemoteException
     */
    public void setAllowedCarriers(int serial, CarrierRestrictionRules carrierRestrictionRules)
            throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            // Prepare structure with allowed list, excluded list and priority
            android.hardware.radio.sim.CarrierRestrictions carrierRestrictions =
                    new android.hardware.radio.sim.CarrierRestrictions();
            carrierRestrictions.allowedCarriers = RILUtils.convertToHalCarrierRestrictionListAidl(
                    carrierRestrictionRules.getAllowedCarriers());
            carrierRestrictions.excludedCarriers = RILUtils.convertToHalCarrierRestrictionListAidl(
                    carrierRestrictionRules.getExcludedCarriers());
            carrierRestrictions.allowedCarriersPrioritized =
                    (carrierRestrictionRules.getDefaultCarrierRestriction()
                            == CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_NOT_ALLOWED);
            mSimProxy.setAllowedCarriers(serial, carrierRestrictions,
                    RILUtils.convertToHalSimLockMultiSimPolicyAidl(
                            carrierRestrictionRules.getMultiSimPolicy()));
        } else {
            // Prepare structure with allowed list, excluded list and priority
            android.hardware.radio.V1_4.CarrierRestrictionsWithPriority carrierRestrictions =
                    new android.hardware.radio.V1_4.CarrierRestrictionsWithPriority();
            carrierRestrictions.allowedCarriers = RILUtils.convertToHalCarrierRestrictionList(
                    carrierRestrictionRules.getAllowedCarriers());
            carrierRestrictions.excludedCarriers = RILUtils.convertToHalCarrierRestrictionList(
                    carrierRestrictionRules.getExcludedCarriers());
            carrierRestrictions.allowedCarriersPrioritized =
                    (carrierRestrictionRules.getDefaultCarrierRestriction()
                            == CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_NOT_ALLOWED);
            mRadioProxy.setAllowedCarriers_1_4(serial, carrierRestrictions,
                    RILUtils.convertToHalSimLockMultiSimPolicy(
                            carrierRestrictionRules.getMultiSimPolicy()));
        }
    }

    /**
     * Call IRadioSim#setCarrierInfoForImsiEncryption
     * @param serial Serial number of request
     * @param imsiEncryptionInfo ImsiEncryptionInfo
     * @throws RemoteException
     */
    public void setCarrierInfoForImsiEncryption(int serial, ImsiEncryptionInfo imsiEncryptionInfo)
            throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            android.hardware.radio.sim.ImsiEncryptionInfo halImsiInfo =
                    new android.hardware.radio.sim.ImsiEncryptionInfo();
            halImsiInfo.mnc = imsiEncryptionInfo.getMnc();
            halImsiInfo.mcc = imsiEncryptionInfo.getMcc();
            halImsiInfo.keyIdentifier = imsiEncryptionInfo.getKeyIdentifier();
            if (imsiEncryptionInfo.getExpirationTime() != null) {
                halImsiInfo.expirationTime = imsiEncryptionInfo.getExpirationTime().getTime();
            }
            halImsiInfo.carrierKey = imsiEncryptionInfo.getPublicKey().getEncoded();
            halImsiInfo.keyType = (byte) imsiEncryptionInfo.getKeyType();

            mSimProxy.setCarrierInfoForImsiEncryption(serial, halImsiInfo);
        } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) {
            android.hardware.radio.V1_6.ImsiEncryptionInfo halImsiInfo =
                    new android.hardware.radio.V1_6.ImsiEncryptionInfo();
            halImsiInfo.base.mnc = imsiEncryptionInfo.getMnc();
            halImsiInfo.base.mcc = imsiEncryptionInfo.getMcc();
            halImsiInfo.base.keyIdentifier = imsiEncryptionInfo.getKeyIdentifier();
            if (imsiEncryptionInfo.getExpirationTime() != null) {
                halImsiInfo.base.expirationTime = imsiEncryptionInfo.getExpirationTime().getTime();
            }
            for (byte b : imsiEncryptionInfo.getPublicKey().getEncoded()) {
                halImsiInfo.base.carrierKey.add(Byte.valueOf(b));
            }
            halImsiInfo.keyType = (byte) imsiEncryptionInfo.getKeyType();

            ((android.hardware.radio.V1_6.IRadio) mRadioProxy).setCarrierInfoForImsiEncryption_1_6(
                    serial, halImsiInfo);
        } else {
            android.hardware.radio.V1_1.ImsiEncryptionInfo halImsiInfo =
                    new android.hardware.radio.V1_1.ImsiEncryptionInfo();
            halImsiInfo.mnc = imsiEncryptionInfo.getMnc();
            halImsiInfo.mcc = imsiEncryptionInfo.getMcc();
            halImsiInfo.keyIdentifier = imsiEncryptionInfo.getKeyIdentifier();
            if (imsiEncryptionInfo.getExpirationTime() != null) {
                halImsiInfo.expirationTime = imsiEncryptionInfo.getExpirationTime().getTime();
            }
            for (byte b : imsiEncryptionInfo.getPublicKey().getEncoded()) {
                halImsiInfo.carrierKey.add(Byte.valueOf(b));
            }

            mRadioProxy.setCarrierInfoForImsiEncryption(serial, halImsiInfo);
        }
    }

    /**
     * Call IRadioSim#setCdmaSubscriptionSource
     * @param serial Serial number of request
     * @param cdmaSub One of  CDMA_SUBSCRIPTION_*
     * @throws RemoteException
     */
    public void setCdmaSubscriptionSource(int serial, int cdmaSub) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mSimProxy.setCdmaSubscriptionSource(serial, cdmaSub);
        } else {
            mRadioProxy.setCdmaSubscriptionSource(serial, cdmaSub);
        }
    }

    /**
     * Call IRadioSim#setFacilityLockForApp
     * @param serial Serial number of request
     * @param facility One of CB_FACILTY_*
     * @param lockState True means lock, false means unlock
     * @param password Password or "" if not required
     * @param serviceClass Sum of SERVICE_CLASS_*
     * @param appId Application ID or null if none
     * @throws RemoteException
     */
    public void setFacilityLockForApp(int serial, String facility, boolean lockState,
            String password, int serviceClass, String appId) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mSimProxy.setFacilityLockForApp(
                    serial, facility, lockState, password, serviceClass, appId);
        } else {
            mRadioProxy.setFacilityLockForApp(
                    serial, facility, lockState, password, serviceClass, appId);
        }
    }

    /**
     * Call IRadioSim#setSimCardPower
     * @param serial Serial number of request
     * @param state SIM state (power down, power up, pass through)
     * @throws RemoteException
     */
    public void setSimCardPower(int serial, int state) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mSimProxy.setSimCardPower(serial, state);
        } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) {
            ((android.hardware.radio.V1_6.IRadio) mRadioProxy).setSimCardPower_1_6(serial, state);
        } else {
            mRadioProxy.setSimCardPower_1_1(serial, state);
        }
    }

    /**
     * Call IRadioSim#setUiccSubscription
     * @param serial Serial number of request
     * @param slotId Slot ID
     * @param appIndex Application index in the card
     * @param subId Subscription ID
     * @param subStatus Activation status; 1 = activate and 0 = deactivate
     * @throws RemoteException
     */
    public void setUiccSubscription(int serial, int slotId, int appIndex, int subId, int subStatus)
            throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            android.hardware.radio.sim.SelectUiccSub info =
                    new android.hardware.radio.sim.SelectUiccSub();
            info.slot = slotId;
            info.appIndex = appIndex;
            info.subType = subId;
            info.actStatus = subStatus;
            mSimProxy.setUiccSubscription(serial, info);
        } else {
            android.hardware.radio.V1_0.SelectUiccSub info =
                    new android.hardware.radio.V1_0.SelectUiccSub();
            info.slot = slotId;
            info.appIndex = appIndex;
            info.subType = subId;
            info.actStatus = subStatus;
            mRadioProxy.setUiccSubscription(serial, info);
        }
    }

    /**
     * Call IRadioSim#supplyIccPin2ForApp
     * @param serial Serial number of request
     * @param pin2 PIN 2 value
     * @param aid Application ID
     * @throws RemoteException
     */
    public void supplyIccPin2ForApp(int serial, String pin2, String aid) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mSimProxy.supplyIccPin2ForApp(serial, pin2, aid);
        } else {
            mRadioProxy.supplyIccPin2ForApp(serial, pin2, aid);
        }
    }

    /**
     * Call IRadioSim#supplyIccPinForApp
     * @param serial Serial number of request
     * @param pin PIN value
     * @param aid Application ID
     * @throws RemoteException
     */
    public void supplyIccPinForApp(int serial, String pin, String aid) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mSimProxy.supplyIccPinForApp(serial, pin, aid);
        } else {
            mRadioProxy.supplyIccPinForApp(serial, pin, aid);
        }
    }

    /**
     * Call IRadioSim#supplyIccPuk2ForApp
     * @param serial Serial number of request
     * @param puk2 PUK 2 value
     * @param pin2 PIN 2 value
     * @param aid Application ID
     * @throws RemoteException
     */
    public void supplyIccPuk2ForApp(int serial, String puk2, String pin2, String aid)
            throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mSimProxy.supplyIccPuk2ForApp(serial, puk2, pin2, aid);
        } else {
            mRadioProxy.supplyIccPuk2ForApp(serial, puk2, pin2, aid);
        }
    }

    /**
     * Call IRadioSim#supplyIccPukForApp
     * @param serial Serial number of request
     * @param puk PUK value
     * @param pin PIN value
     * @param aid Application ID
     * @throws RemoteException
     */
    public void supplyIccPukForApp(int serial, String puk, String pin, String aid)
            throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mSimProxy.supplyIccPukForApp(serial, puk, pin, aid);
        } else {
            mRadioProxy.supplyIccPukForApp(serial, puk, pin, aid);
        }
    }

    /**
     * Call IRadioSim#supplySimDepersonalization
     * @param serial Serial number of request
     * @param persoType SIM personalization type
     * @param controlKey Unlock code for removing SIM personalization from this device
     * @throws RemoteException
     */
    public void supplySimDepersonalization(int serial, PersoSubState persoType, String controlKey)
            throws RemoteException {
        if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_5)) return;
        if (isAidl()) {
            mSimProxy.supplySimDepersonalization(serial,
                    RILUtils.convertToHalPersoTypeAidl(persoType), controlKey);
        } else {
            ((android.hardware.radio.V1_5.IRadio) mRadioProxy).supplySimDepersonalization(serial,
                    RILUtils.convertToHalPersoType(persoType), controlKey);
        }
    }

    /**
     * Call IRadioSim#updateSimPhonebookRecords
     * @param serial Serial number of request
     * @param recordInfo ADN record information to be updated
     * @throws RemoteException
     */
    public void updateSimPhonebookRecords(int serial, SimPhonebookRecord recordInfo)
            throws RemoteException {
        if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_6)) return;
        if (isAidl()) {
            mSimProxy.updateSimPhonebookRecords(serial,
                    RILUtils.convertToHalPhonebookRecordInfoAidl(recordInfo));
        } else {
            ((android.hardware.radio.V1_6.IRadio) mRadioProxy).updateSimPhonebookRecords(serial,
                    RILUtils.convertToHalPhonebookRecordInfo(recordInfo));
        }
    }
}