aboutsummaryrefslogtreecommitdiff
path: root/src/java/com/android/internal/telephony/RadioNetworkProxy.java
blob: 246c2e02045be4b8a86364c4bd9c2e436c9e154a (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
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
/*
 * 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 static com.android.internal.telephony.RILConstants.REQUEST_NOT_SUPPORTED;

import android.annotation.NonNull;
import android.os.AsyncResult;
import android.os.Message;
import android.os.RemoteException;
import android.telephony.AccessNetworkConstants;
import android.telephony.NetworkScanRequest;
import android.telephony.RadioAccessSpecifier;
import android.telephony.Rlog;
import android.telephony.SignalThresholdInfo;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * A holder for IRadioNetwork. Use getHidl to get IRadio 1.0 and call the HIDL implementations or
 * getAidl to get IRadioNetwork and call the AIDL implementations of the HAL APIs.
 */
public class RadioNetworkProxy extends RadioServiceProxy {
    private static final String TAG = "RadioNetworkProxy";
    private volatile android.hardware.radio.network.IRadioNetwork mNetworkProxy = null;

    private static final int INDICATION_FILTERS_ALL_V1_0 =
            android.hardware.radio.V1_5.IndicationFilter.SIGNAL_STRENGTH
                    | android.hardware.radio.V1_5.IndicationFilter.FULL_NETWORK_STATE
                    | android.hardware.radio.V1_5.IndicationFilter.DATA_CALL_DORMANCY_CHANGED;
    private static final int INDICATION_FILTERS_ALL_V1_2 =
            INDICATION_FILTERS_ALL_V1_0
                    | android.hardware.radio.V1_5.IndicationFilter.LINK_CAPACITY_ESTIMATE
                    | android.hardware.radio.V1_5.IndicationFilter.PHYSICAL_CHANNEL_CONFIG;
    private static final int INDICATION_FILTERS_ALL_V1_5 =
            INDICATION_FILTERS_ALL_V1_2
                    | android.hardware.radio.V1_5.IndicationFilter.REGISTRATION_FAILURE
                    | android.hardware.radio.V1_5.IndicationFilter.BARRING_INFO;
    private static final int INDICATION_FILTERS_ALL_AIDL =
            android.hardware.radio.network.IndicationFilter.SIGNAL_STRENGTH
                    | android.hardware.radio.network.IndicationFilter.FULL_NETWORK_STATE
                    | android.hardware.radio.network.IndicationFilter.DATA_CALL_DORMANCY_CHANGED
                    | android.hardware.radio.network.IndicationFilter.LINK_CAPACITY_ESTIMATE
                    | android.hardware.radio.network.IndicationFilter.PHYSICAL_CHANNEL_CONFIG
                    | android.hardware.radio.network.IndicationFilter.REGISTRATION_FAILURE
                    | android.hardware.radio.network.IndicationFilter.BARRING_INFO;

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

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

    /**
     * Get the AIDL implementation of RadioNetworkProxy
     * @return IRadioNetwork implementation
     */
    public android.hardware.radio.network.IRadioNetwork getAidl() {
        return mNetworkProxy;
    }

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

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

    /**
     * Call IRadioNetwork#getAllowedNetworkTypesBitmap
     * @param serial Serial number of request
     * @throws RemoteException
     */
    public void getAllowedNetworkTypesBitmap(int serial) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mNetworkProxy.getAllowedNetworkTypesBitmap(serial);
        } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) {
            ((android.hardware.radio.V1_6.IRadio) mRadioProxy).getAllowedNetworkTypesBitmap(serial);
        } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_4)) {
            ((android.hardware.radio.V1_4.IRadio) mRadioProxy)
                    .getPreferredNetworkTypeBitmap(serial);
        } else {
            mRadioProxy.getPreferredNetworkType(serial);
        }
    }

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

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

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

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

    /**
     * Call IRadioNetwork#getCellInfoList
     * @param serial Serial number of request
     * @throws RemoteException
     */
    public void getCellInfoList(int serial) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mNetworkProxy.getCellInfoList(serial);
        } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) {
            ((android.hardware.radio.V1_6.IRadio) mRadioProxy).getCellInfoList_1_6(serial);
        } else {
            mRadioProxy.getCellInfoList(serial);
        }
    }

    /**
     * Call IRadioNetwork#getDataRegistrationState
     * @param serial Serial number of request
     * @param overrideHalVersion Radio HAL fallback compatibility override
     * @throws RemoteException
     */
    public void getDataRegistrationState(int serial, HalVersion overrideHalVersion)
            throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mNetworkProxy.getDataRegistrationState(serial);
        } else if ((overrideHalVersion == null
                || overrideHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6))
                && mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) {
            ((android.hardware.radio.V1_6.IRadio) mRadioProxy).getDataRegistrationState_1_6(serial);
        } else if ((overrideHalVersion == null
                || overrideHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5))
                && mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) {
            ((android.hardware.radio.V1_5.IRadio) mRadioProxy).getDataRegistrationState_1_5(serial);
        } else {
            mRadioProxy.getDataRegistrationState(serial);
        }
    }

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

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

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

    /**
     * Call IRadioNetwork#getSignalStrength
     * @param serial Serial number of request
     * @throws RemoteException
     */
    public void getSignalStrength(int serial) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mNetworkProxy.getSignalStrength(serial);
        } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) {
            ((android.hardware.radio.V1_6.IRadio) mRadioProxy).getSignalStrength_1_6(serial);
        } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_4)) {
            ((android.hardware.radio.V1_4.IRadio) mRadioProxy).getSignalStrength_1_4(serial);
        } else {
            mRadioProxy.getSignalStrength(serial);
        }
    }

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

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

    /**
     * Call IRadioNetwork#getVoiceRegistrationState
     * @param serial Serial number of request
     * @param overrideHalVersion Radio HAL fallback compatibility override
     * @throws RemoteException
     */
    public void getVoiceRegistrationState(int serial, HalVersion overrideHalVersion)
            throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mNetworkProxy.getVoiceRegistrationState(serial);
        } else if ((overrideHalVersion == null
                || overrideHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6))
                && mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) {
            ((android.hardware.radio.V1_6.IRadio) mRadioProxy)
                    .getVoiceRegistrationState_1_6(serial);
        } else if ((overrideHalVersion == null
                || overrideHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5))
                && mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) {
            ((android.hardware.radio.V1_5.IRadio) mRadioProxy)
                    .getVoiceRegistrationState_1_5(serial);
        } else {
            mRadioProxy.getVoiceRegistrationState(serial);
        }
    }

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

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

    /**
     * Call IRadioNetwork#setAllowedNetworkTypesBitmap
     * @param serial Serial number of request
     * @param networkTypeBitmask Network type bitmask to set
     * @throws RemoteException
     */
    public void setAllowedNetworkTypesBitmap(int serial, int networkTypeBitmask)
            throws RemoteException {
        if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_6)) return;
        if (isAidl()) {
            mNetworkProxy.setAllowedNetworkTypesBitmap(serial,
                    RILUtils.convertToHalRadioAccessFamilyAidl(networkTypeBitmask));
        } else {
            ((android.hardware.radio.V1_6.IRadio) mRadioProxy).setAllowedNetworkTypesBitmap(
                    serial, RILUtils.convertToHalRadioAccessFamily(networkTypeBitmask));
        }
    }

    /**
     * Call IRadioNetwork#setPreferredNetworkTypeBitmap
     * @param serial Serial number of request
     * @param networkTypesBitmask Preferred network types bitmask to set
     * @throws RemoteException
     */
    public void setPreferredNetworkTypeBitmap(int serial, int networkTypesBitmask)
            throws RemoteException {
        if (isEmpty() || mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) return;
        if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_4)) {
            ((android.hardware.radio.V1_4.IRadio) mRadioProxy).setPreferredNetworkTypeBitmap(serial,
                    RILUtils.convertToHalRadioAccessFamily(networkTypesBitmask));
        } else {
            mRadioProxy.setPreferredNetworkType(serial, networkTypesBitmask);
        }
    }

    /**
     * Call IRadioNetwork#setBandMode
     * @param serial Serial number of request
     * @param bandMode One of BM_*_BAND
     * @throws RemoteException
     */
    public void setBandMode(int serial, int bandMode) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mNetworkProxy.setBandMode(serial, bandMode);
        } else {
            mRadioProxy.setBandMode(serial, bandMode);
        }
    }

    /**
     * Call IRadioNetwork#setBarringPassword
     * @param serial Serial number of request
     * @param facility Facility string code
     * @param oldPassword Old password
     * @param newPassword New password
     * @throws RemoteException
     */
    public void setBarringPassword(int serial, String facility, String oldPassword,
            String newPassword) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mNetworkProxy.setBarringPassword(serial, facility, oldPassword, newPassword);
        } else {
            mRadioProxy.setBarringPassword(serial, facility, oldPassword, newPassword);
        }
    }

    /**
     * Call IRadioNetwork#setCdmaRoamingPreference
     * @param serial Serial number of request
     * @param cdmaRoamingType One of CDMA_RM_*
     * @throws RemoteException
     */
    public void setCdmaRoamingPreference(int serial, int cdmaRoamingType) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mNetworkProxy.setCdmaRoamingPreference(serial, cdmaRoamingType);
        } else {
            mRadioProxy.setCdmaRoamingPreference(serial, cdmaRoamingType);
        }
    }

    /**
     * Call IRadioNetwork#setCellInfoListRate
     * @param serial Serial number of request
     * @param rate Minimum time in milliseconds to indicate time between unsolicited cellInfoList()
     * @throws RemoteException
     */
    public void setCellInfoListRate(int serial, int rate) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mNetworkProxy.setCellInfoListRate(serial, rate);
        } else {
            mRadioProxy.setCellInfoListRate(serial, rate);
        }
    }

    /**
     * Call IRadioNetwork#setIndicationFilter
     * @param serial Serial number of request
     * @param filter Unsolicited response filter
     * @throws RemoteException
     */
    public void setIndicationFilter(int serial, int filter) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mNetworkProxy.setIndicationFilter(serial, filter & INDICATION_FILTERS_ALL_AIDL);
        } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) {
            ((android.hardware.radio.V1_5.IRadio) mRadioProxy).setIndicationFilter_1_5(serial,
                    filter & INDICATION_FILTERS_ALL_V1_5);
        } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_2)) {
            ((android.hardware.radio.V1_2.IRadio) mRadioProxy).setIndicationFilter_1_2(serial,
                    filter & INDICATION_FILTERS_ALL_V1_2);
        } else {
            mRadioProxy.setIndicationFilter(serial, filter & INDICATION_FILTERS_ALL_V1_0);
        }
    }

    /**
     * Call IRadioNetwork#setLinkCapacityReportingCriteria
     * @param serial Serial number of request
     * @param hysteresisMs A hysteresis time in milliseconds. A value of 0 disables hysteresis.
     * @param hysteresisDlKbps An interval in kbps defining the required magnitude change between DL
     *                         reports. A value of 0 disables hysteresis
     * @param hysteresisUlKbps An interval in kbps defining the required magnitude change between UL
     *                         reports. A value of 0 disables hysteresis
     * @param thresholdsDlKbps An array of trigger thresholds in kbps for DL reports. A size of 0
     *                         disables thresholds
     * @param thresholdsUlKbps An array of trigger thresholds in kbps for UL reports. A size of 0
     *                         disables thresholds
     * @param ran RadioAccessNetwork for which to apply criteria
     * @throws RemoteException
     */
    public void setLinkCapacityReportingCriteria(int serial, int hysteresisMs, int hysteresisDlKbps,
            int hysteresisUlKbps, int[] thresholdsDlKbps, int[] thresholdsUlKbps, int ran)
            throws RemoteException {
        if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_2)) return;
        if (isAidl()) {
            mNetworkProxy.setLinkCapacityReportingCriteria(serial, hysteresisMs, hysteresisDlKbps,
                    hysteresisUlKbps, thresholdsDlKbps, thresholdsUlKbps,
                    RILUtils.convertToHalAccessNetworkAidl(ran));
        } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) {
            ((android.hardware.radio.V1_5.IRadio) mRadioProxy).setLinkCapacityReportingCriteria_1_5(
                    serial, hysteresisMs, hysteresisDlKbps, hysteresisUlKbps,
                    RILUtils.primitiveArrayToArrayList(thresholdsDlKbps),
                    RILUtils.primitiveArrayToArrayList(thresholdsUlKbps),
                    RILUtils.convertToHalAccessNetwork(ran));
        } else {
            if (ran == AccessNetworkConstants.AccessNetworkType.NGRAN) {
                throw new RuntimeException("NGRAN unsupported on IRadio version: " + mHalVersion);
            }
            ((android.hardware.radio.V1_2.IRadio) mRadioProxy).setLinkCapacityReportingCriteria(
                    serial, hysteresisMs, hysteresisDlKbps, hysteresisUlKbps,
                    RILUtils.primitiveArrayToArrayList(thresholdsDlKbps),
                    RILUtils.primitiveArrayToArrayList(thresholdsUlKbps),
                    RILUtils.convertToHalAccessNetwork(ran));
        }
    }

    /**
     * Call IRadioNetwork#setLocationUpdates
     * @param serial Serial number of request
     * @param enable Whether to enable or disable network state change notifications when location
     *               information (lac and/or cid) has changed
     * @throws RemoteException
     */
    public void setLocationUpdates(int serial, boolean enable) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mNetworkProxy.setLocationUpdates(serial, enable);
        } else {
            mRadioProxy.setLocationUpdates(serial, enable);
        }
    }

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

    /**
     * Call IRadioNetwork#setNetworkSelectionModeManual
     * @param serial Serial number of request
     * @param operatorNumeric PLMN ID of the network to select
     * @param ran Radio access network type
     * @throws RemoteException
     */
    public void setNetworkSelectionModeManual(int serial, String operatorNumeric, int ran)
            throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mNetworkProxy.setNetworkSelectionModeManual(serial, operatorNumeric,
                    RILUtils.convertToHalAccessNetworkAidl(ran));
        } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) {
            ((android.hardware.radio.V1_5.IRadio) mRadioProxy).setNetworkSelectionModeManual_1_5(
                    serial, operatorNumeric, RILUtils.convertToHalRadioAccessNetworks(ran));
        } else {
            mRadioProxy.setNetworkSelectionModeManual(serial, operatorNumeric);
        }
    }

    /**
     * Call IRadioNetwork#setNrDualConnectivityState
     * @param serial Serial number of request
     * @param nrDualConnectivityState Expected NR dual connectivity state
     * @throws RemoteException
     */
    public void setNrDualConnectivityState(int serial, byte nrDualConnectivityState)
            throws RemoteException {
        if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_6)) return;
        if (isAidl()) {
            mNetworkProxy.setNrDualConnectivityState(serial, nrDualConnectivityState);
        } else {
            ((android.hardware.radio.V1_6.IRadio) mRadioProxy).setNrDualConnectivityState(
                    serial, nrDualConnectivityState);
        }
    }

    /**
     * Call IRadioNetwork#setSignalStrengthReportingCriteria
     * @param serial Serial number of request
     * @param signalThresholdInfos a list of {@link SignalThresholdInfo} to set with.
     * @throws RemoteException
     */
    public void setSignalStrengthReportingCriteria(int serial,
            @NonNull List<SignalThresholdInfo> signalThresholdInfos) throws RemoteException {
        if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_2)) return;
        if (isAidl()) {
            android.hardware.radio.network.SignalThresholdInfo[] halSignalThresholdsInfos =
            new android.hardware.radio.network.SignalThresholdInfo[signalThresholdInfos.size()];
            for (int i = 0; i < signalThresholdInfos.size(); i++) {
                halSignalThresholdsInfos[i] = RILUtils.convertToHalSignalThresholdInfoAidl(
                        signalThresholdInfos.get(i));
            }
            mNetworkProxy.setSignalStrengthReportingCriteria(serial, halSignalThresholdsInfos);
        } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) {
            for (SignalThresholdInfo signalThresholdInfo : signalThresholdInfos) {
                ((android.hardware.radio.V1_5.IRadio) mRadioProxy)
                        .setSignalStrengthReportingCriteria_1_5(serial,
                                RILUtils.convertToHalSignalThresholdInfo(signalThresholdInfo),
                                RILUtils.convertToHalAccessNetwork(
                                        signalThresholdInfo.getRadioAccessNetworkType()));
            }
        } else {
            for (SignalThresholdInfo signalThresholdInfo : signalThresholdInfos) {
                ((android.hardware.radio.V1_2.IRadio) mRadioProxy)
                        .setSignalStrengthReportingCriteria(serial,
                                signalThresholdInfo.getHysteresisMs(),
                                signalThresholdInfo.getHysteresisDb(),
                                RILUtils.primitiveArrayToArrayList(
                                        signalThresholdInfo.getThresholds()),
                                RILUtils.convertToHalAccessNetwork(
                                        signalThresholdInfo.getRadioAccessNetworkType()));
            }
        }
    }

    /**
     * Call IRadioNetwork#setSuppServiceNotifications
     * @param serial Serial number of request
     * @param enable True to enable notifications, false to disable
     * @throws RemoteException
     */
    public void setSuppServiceNotifications(int serial, boolean enable) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mNetworkProxy.setSuppServiceNotifications(serial, enable);
        } else {
            mRadioProxy.setSuppServiceNotifications(serial, enable);
        }
    }

    /**
     * Call IRadioNetwork#setSystemSelectionChannels
     * @param serial Serial number of request
     * @param specifiers Which bands to scan
     * @throws RemoteException
     */
    public void setSystemSelectionChannels(int serial, List<RadioAccessSpecifier> specifiers)
            throws RemoteException {
        if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_3)) return;
        if (isAidl()) {
            mNetworkProxy.setSystemSelectionChannels(serial, !specifiers.isEmpty(),
                    specifiers.stream().map(RILUtils::convertToHalRadioAccessSpecifierAidl)
                            .toArray(android.hardware.radio.network.RadioAccessSpecifier[]::new));
        } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) {
            ((android.hardware.radio.V1_5.IRadio) mRadioProxy).setSystemSelectionChannels_1_5(
                    serial, !specifiers.isEmpty(), specifiers.stream()
                            .map(RILUtils::convertToHalRadioAccessSpecifier15)
                            .collect(Collectors.toCollection(ArrayList::new)));
        } else {
            ((android.hardware.radio.V1_3.IRadio) mRadioProxy).setSystemSelectionChannels(
                    serial, !specifiers.isEmpty(), specifiers.stream()
                            .map(RILUtils::convertToHalRadioAccessSpecifier11)
                            .collect(Collectors.toCollection(ArrayList::new)));
        }
    }

    /**
     * Call IRadioNetwork#startNetworkScan
     * @param serial Serial number of request
     * @param request Defines the radio networks/bands/channels which need to be scanned
     * @param overrideHalVersion Radio HAL fallback compatibility override
     * @throws RemoteException
     */
    public void startNetworkScan(int serial, NetworkScanRequest request,
            HalVersion overrideHalVersion, Message result) throws RemoteException {
        if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_1)) return;
        if (isAidl()) {
            android.hardware.radio.network.NetworkScanRequest halRequest =
                    new android.hardware.radio.network.NetworkScanRequest();
            halRequest.type = request.getScanType();
            halRequest.interval = request.getSearchPeriodicity();
            halRequest.maxSearchTime = request.getMaxSearchTime();
            halRequest.incrementalResultsPeriodicity = request.getIncrementalResultsPeriodicity();
            halRequest.incrementalResults = request.getIncrementalResults();
            halRequest.mccMncs = request.getPlmns().stream().toArray(String[]::new);
            ArrayList<android.hardware.radio.network.RadioAccessSpecifier> specifiers =
                    new ArrayList<>();
            for (RadioAccessSpecifier ras : request.getSpecifiers()) {
                android.hardware.radio.network.RadioAccessSpecifier rasInHalFormat =
                        RILUtils.convertToHalRadioAccessSpecifierAidl(ras);
                if (rasInHalFormat == null) {
                    AsyncResult.forMessage(result, null,
                            CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
                    result.sendToTarget();
                    return;
                }
                specifiers.add(rasInHalFormat);
            }
            halRequest.specifiers = specifiers.stream().toArray(
                    android.hardware.radio.network.RadioAccessSpecifier[]::new);
            mNetworkProxy.startNetworkScan(serial, halRequest);
        } else if ((overrideHalVersion == null
                || overrideHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5))
                && mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) {
            android.hardware.radio.V1_5.NetworkScanRequest halRequest =
                    new android.hardware.radio.V1_5.NetworkScanRequest();
            halRequest.type = request.getScanType();
            halRequest.interval = request.getSearchPeriodicity();
            halRequest.maxSearchTime = request.getMaxSearchTime();
            halRequest.incrementalResultsPeriodicity = request.getIncrementalResultsPeriodicity();
            halRequest.incrementalResults = request.getIncrementalResults();
            halRequest.mccMncs.addAll(request.getPlmns());
            for (RadioAccessSpecifier ras : request.getSpecifiers()) {
                android.hardware.radio.V1_5.RadioAccessSpecifier rasInHalFormat =
                        RILUtils.convertToHalRadioAccessSpecifier15(ras);
                if (rasInHalFormat == null) {
                    AsyncResult.forMessage(result, null,
                            CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
                    result.sendToTarget();
                    return;
                }
                halRequest.specifiers.add(rasInHalFormat);
            }
            ((android.hardware.radio.V1_5.IRadio) mRadioProxy).startNetworkScan_1_5(
                    serial, halRequest);
        } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_2)) {
            android.hardware.radio.V1_2.NetworkScanRequest halRequest =
                    new android.hardware.radio.V1_2.NetworkScanRequest();
            halRequest.type = request.getScanType();
            halRequest.interval = request.getSearchPeriodicity();
            halRequest.maxSearchTime = request.getMaxSearchTime();
            halRequest.incrementalResultsPeriodicity = request.getIncrementalResultsPeriodicity();
            halRequest.incrementalResults = request.getIncrementalResults();
            halRequest.mccMncs.addAll(request.getPlmns());

            for (RadioAccessSpecifier ras : request.getSpecifiers()) {
                android.hardware.radio.V1_1.RadioAccessSpecifier rasInHalFormat =
                        RILUtils.convertToHalRadioAccessSpecifier11(ras);
                if (rasInHalFormat == null) {
                    AsyncResult.forMessage(result, null,
                            CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
                    result.sendToTarget();
                    return;
                }
                halRequest.specifiers.add(rasInHalFormat);
            }

            if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_4)) {
                ((android.hardware.radio.V1_4.IRadio) mRadioProxy).startNetworkScan_1_4(
                        serial, halRequest);
            } else {
                ((android.hardware.radio.V1_2.IRadio) mRadioProxy).startNetworkScan_1_2(
                        serial, halRequest);
            }
        } else {
            android.hardware.radio.V1_1.NetworkScanRequest halRequest =
                    new android.hardware.radio.V1_1.NetworkScanRequest();
            halRequest.type = request.getScanType();
            halRequest.interval = request.getSearchPeriodicity();
            for (RadioAccessSpecifier ras : request.getSpecifiers()) {
                android.hardware.radio.V1_1.RadioAccessSpecifier rasInHalFormat =
                        RILUtils.convertToHalRadioAccessSpecifier11(ras);
                if (rasInHalFormat == null) {
                    AsyncResult.forMessage(result, null,
                            CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
                    result.sendToTarget();
                    return;
                }
                halRequest.specifiers.add(rasInHalFormat);
            }
            ((android.hardware.radio.V1_1.IRadio) mRadioProxy).startNetworkScan(serial, halRequest);
        }
    }

    /**
     * Call IRadioNetwork#stopNetworkScan
     * @param serial Serial number of request
     * @throws RemoteException
     */
    public void stopNetworkScan(int serial) throws RemoteException {
        if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_1)) return;
        if (isAidl()) {
            mNetworkProxy.stopNetworkScan(serial);
        } else {
            ((android.hardware.radio.V1_1.IRadio) mRadioProxy).stopNetworkScan(serial);
        }
    }

    /**
     * Call IRadioNetwork#supplyNetworkDepersonalization
     * @param serial Serial number of request
     * @param netPin Network depersonalization code
     * @throws RemoteException
     */
    public void supplyNetworkDepersonalization(int serial, String netPin) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mNetworkProxy.supplyNetworkDepersonalization(serial, netPin);
        } else {
            mRadioProxy.supplyNetworkDepersonalization(serial, netPin);
        }
    }

    /**
     * Call IRadioNetwork#getUsageSetting()
     * @param serial Serial number of request
     * @throws RemoteException
     */
    public void getUsageSetting(int serial) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mNetworkProxy.getUsageSetting(serial);
        }
        // Only supported on AIDL.
    }

    /**
     * Call IRadioNetwork#setUsageSetting()
     * @param serial Serial number of request
     * @throws RemoteException
     */
    public void setUsageSetting(int serial,
            /* TelephonyManager.UsageSetting */ int usageSetting) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mNetworkProxy.setUsageSetting(serial, usageSetting);
        }
        // Only supported on AIDL.
    }

    /**
     * Set the Emergency Mode
     *
     * @param serial Serial number of the request.
     * @param emcModeType Defines the radio emergency mode type.
     * @throws RemoteException
     */
    public void setEmergencyMode(int serial, int emcModeType) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mNetworkProxy.setEmergencyMode(serial, emcModeType);
        }
        // Only supported on AIDL.
    }

    /**
     * Triggers an Emergency network scan.
     *
     * @param serial Serial number of the request.
     * @param scanRequest Contains the preferred networks and type of service to be scanned.
     * @throws RemoteException
     */
    public void triggerEmergencyNetworkScan(int serial,
            android.hardware.radio.network.EmergencyNetworkScanTrigger scanRequest)
            throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mNetworkProxy.triggerEmergencyNetworkScan(serial, scanRequest);
        }
        // Only supported on AIDL.
    }

    /**
     * Cancels ongoing Emergency network scan
     *
     * @param serial Serial number of the request.
     * @param resetScan Indicates how the next {@link #triggerEmergencyNetworkScan} should work.
     *        If {@code true}, then the modem shall start the new scan from the beginning,
     *        otherwise the modem shall resume from the last search.
     *
     * @throws RemoteException
     */
    public void cancelEmergencyNetworkScan(int serial, boolean resetScan) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mNetworkProxy.cancelEmergencyNetworkScan(serial, resetScan);
        }
        // Only supported on AIDL.
    }

    /**
     * Exits ongoing Emergency Mode
     *
     * @param serial Serial number of the request.
     * @throws RemoteException
     */
    public void exitEmergencyMode(int serial) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mNetworkProxy.exitEmergencyMode(serial);
        }
        // Only supported on AIDL.
    }

    /**
     * Set if null ciphering / null integrity is permitted.
     *
     * @param serial Serial number of the request.
     * @param enabled true if null modes are allowed, false otherwise
     * @throws RemoteException
     */
    public void setNullCipherAndIntegrityEnabled(int serial,
            boolean enabled) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mNetworkProxy.setNullCipherAndIntegrityEnabled(serial, enabled);
        }
        // Only supported on AIDL.
    }

    /**
     * Get if null ciphering / null integrity is permitted.
     * @param serial Serial number of the request.
     * @throws RemoteException
     *
     */
    public void isNullCipherAndIntegrityEnabled(int serial) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mNetworkProxy.isNullCipherAndIntegrityEnabled(serial);
        }
        // Only supported on AIDL.
    }

    /**
     * Checks whether N1 mode is enabled.
     *
     * @param serial Serial number of the request.
     * @throws RemoteException
     */
    public void isN1ModeEnabled(int serial) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mNetworkProxy.isN1ModeEnabled(serial);
        }
        // Only supported on AIDL.
    }

    /**
     * Enables or disables N1 mode.
     *
     * @param serial Serial number of request.
     * @param enable Indicates whether to enable N1 mode or not.
     * @throws RemoteException
     */
    public void setN1ModeEnabled(int serial, boolean enable) throws RemoteException {
        if (isEmpty()) return;
        if (isAidl()) {
            mNetworkProxy.setN1ModeEnabled(serial, enable);
        }
        // Only supported on AIDL.
    }
}