• 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.annotation.NonNull;
22 import android.os.AsyncResult;
23 import android.os.Message;
24 import android.os.RemoteException;
25 import android.telephony.AccessNetworkConstants;
26 import android.telephony.NetworkScanRequest;
27 import android.telephony.RadioAccessSpecifier;
28 import android.telephony.Rlog;
29 import android.telephony.SignalThresholdInfo;
30 
31 import com.android.internal.telephony.flags.Flags;
32 
33 import java.util.ArrayList;
34 import java.util.List;
35 import java.util.stream.Collectors;
36 
37 /**
38  * A holder for IRadioNetwork.
39  * Use getAidl to get IRadioNetwork and call the AIDL implementations of the HAL APIs.
40  */
41 public class RadioNetworkProxy extends RadioServiceProxy {
42     private static final String TAG = "RadioNetworkProxy";
43     private volatile android.hardware.radio.network.IRadioNetwork mNetworkProxy = null;
44 
45     private static final int INDICATION_FILTERS_ALL_V1_2 =
46             android.hardware.radio.V1_5.IndicationFilter.SIGNAL_STRENGTH
47                     | android.hardware.radio.V1_5.IndicationFilter.FULL_NETWORK_STATE
48                     | android.hardware.radio.V1_5.IndicationFilter.DATA_CALL_DORMANCY_CHANGED
49                     | android.hardware.radio.V1_5.IndicationFilter.LINK_CAPACITY_ESTIMATE
50                     | android.hardware.radio.V1_5.IndicationFilter.PHYSICAL_CHANNEL_CONFIG;
51     private static final int INDICATION_FILTERS_ALL_V1_5 =
52             INDICATION_FILTERS_ALL_V1_2
53                     | android.hardware.radio.V1_5.IndicationFilter.REGISTRATION_FAILURE
54                     | android.hardware.radio.V1_5.IndicationFilter.BARRING_INFO;
55     private static final int INDICATION_FILTERS_ALL_AIDL =
56             android.hardware.radio.network.IndicationFilter.SIGNAL_STRENGTH
57                     | android.hardware.radio.network.IndicationFilter.FULL_NETWORK_STATE
58                     | android.hardware.radio.network.IndicationFilter.DATA_CALL_DORMANCY_CHANGED
59                     | android.hardware.radio.network.IndicationFilter.LINK_CAPACITY_ESTIMATE
60                     | android.hardware.radio.network.IndicationFilter.PHYSICAL_CHANNEL_CONFIG
61                     | android.hardware.radio.network.IndicationFilter.REGISTRATION_FAILURE
62                     | android.hardware.radio.network.IndicationFilter.BARRING_INFO;
63 
64     /**
65      * Set IRadioNetwork as the AIDL implementation for RadioServiceProxy
66      * @param halVersion Radio HAL version
67      * @param network IRadioNetwork implementation
68      *
69      * @return updated HAL version
70      */
setAidl(HalVersion halVersion, android.hardware.radio.network.IRadioNetwork network)71     public HalVersion setAidl(HalVersion halVersion,
72             android.hardware.radio.network.IRadioNetwork network) {
73         HalVersion version = halVersion;
74         try {
75             version = RIL.getServiceHalVersion(network.getInterfaceVersion());
76         } catch (RemoteException e) {
77             Rlog.e(TAG, "setAidl: " + e);
78         }
79         mHalVersion = version;
80         mNetworkProxy = network;
81         mIsAidl = true;
82 
83         Rlog.d(TAG, "AIDL initialized mHalVersion=" + mHalVersion);
84         return mHalVersion;
85     }
86 
87     /**
88      * Get the AIDL implementation of RadioNetworkProxy
89      * @return IRadioNetwork implementation
90      */
getAidl()91     public android.hardware.radio.network.IRadioNetwork getAidl() {
92         return mNetworkProxy;
93     }
94 
95     /**
96      * Reset RadioNetworkProxy
97      */
98     @Override
clear()99     public void clear() {
100         super.clear();
101         mNetworkProxy = null;
102     }
103 
104     /**
105      * Check whether a RadioNetwork implementation exists
106      * @return true if there is neither a HIDL nor AIDL implementation
107      */
108     @Override
isEmpty()109     public boolean isEmpty() {
110         return mRadioProxy == null && mNetworkProxy == null;
111     }
112 
113     /**
114      * Call IRadioNetwork#getAllowedNetworkTypesBitmap
115      * @param serial Serial number of request
116      * @throws RemoteException
117      */
getAllowedNetworkTypesBitmap(int serial)118     public void getAllowedNetworkTypesBitmap(int serial) throws RemoteException {
119         if (isEmpty()) return;
120         if (isAidl()) {
121             mNetworkProxy.getAllowedNetworkTypesBitmap(serial);
122         } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) {
123             ((android.hardware.radio.V1_6.IRadio) mRadioProxy).getAllowedNetworkTypesBitmap(serial);
124         } else {
125             mRadioProxy.getPreferredNetworkTypeBitmap(serial);
126         }
127     }
128 
129     /**
130      * Call IRadioNetwork#getAvailableBandModes
131      * @param serial Serial number of request
132      * @throws RemoteException
133      */
getAvailableBandModes(int serial)134     public void getAvailableBandModes(int serial) throws RemoteException {
135         if (Flags.cleanupCdma()) return;
136         if (isEmpty()) return;
137         if (isAidl()) {
138             mNetworkProxy.getAvailableBandModes(serial);
139         } else {
140             mRadioProxy.getAvailableBandModes(serial);
141         }
142     }
143 
144     /**
145      * Call IRadioNetwork#getAvailableNetworks
146      * @param serial Serial number of request
147      * @throws RemoteException
148      */
getAvailableNetworks(int serial)149     public void getAvailableNetworks(int serial) throws RemoteException {
150         if (isEmpty()) return;
151         if (isAidl()) {
152             mNetworkProxy.getAvailableNetworks(serial);
153         } else {
154             mRadioProxy.getAvailableNetworks(serial);
155         }
156     }
157 
158     /**
159      * Call IRadioNetwork#getBarringInfo
160      * @param serial Serial number of request
161      * @throws RemoteException
162      */
getBarringInfo(int serial)163     public void getBarringInfo(int serial) throws RemoteException {
164         if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_5)) return;
165         if (isAidl()) {
166             mNetworkProxy.getBarringInfo(serial);
167         } else {
168             ((android.hardware.radio.V1_5.IRadio) mRadioProxy).getBarringInfo(serial);
169         }
170     }
171 
172     /**
173      * Call IRadioNetwork#getCdmaRoamingPreference
174      * @param serial Serial number of request
175      * @throws RemoteException
176      */
getCdmaRoamingPreference(int serial)177     public void getCdmaRoamingPreference(int serial) throws RemoteException {
178         if (Flags.cleanupCdma()) return;
179         if (isEmpty()) return;
180         if (isAidl()) {
181             mNetworkProxy.getCdmaRoamingPreference(serial);
182         } else {
183             mRadioProxy.getCdmaRoamingPreference(serial);
184         }
185     }
186 
187     /**
188      * Call IRadioNetwork#getCellInfoList
189      * @param serial Serial number of request
190      * @throws RemoteException
191      */
getCellInfoList(int serial)192     public void getCellInfoList(int serial) throws RemoteException {
193         if (isEmpty()) return;
194         if (isAidl()) {
195             mNetworkProxy.getCellInfoList(serial);
196         } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) {
197             ((android.hardware.radio.V1_6.IRadio) mRadioProxy).getCellInfoList_1_6(serial);
198         } else {
199             mRadioProxy.getCellInfoList(serial);
200         }
201     }
202 
203     /**
204      * Call IRadioNetwork#getDataRegistrationState
205      * @param serial Serial number of request
206      * @param overrideHalVersion Radio HAL fallback compatibility override
207      * @throws RemoteException
208      */
getDataRegistrationState(int serial, HalVersion overrideHalVersion)209     public void getDataRegistrationState(int serial, HalVersion overrideHalVersion)
210             throws RemoteException {
211         if (isEmpty()) return;
212         if (isAidl()) {
213             mNetworkProxy.getDataRegistrationState(serial);
214         } else if ((overrideHalVersion == null
215                 || overrideHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6))
216                 && mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) {
217             ((android.hardware.radio.V1_6.IRadio) mRadioProxy).getDataRegistrationState_1_6(serial);
218         } else if ((overrideHalVersion == null
219                 || overrideHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5))
220                 && mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) {
221             ((android.hardware.radio.V1_5.IRadio) mRadioProxy).getDataRegistrationState_1_5(serial);
222         } else {
223             mRadioProxy.getDataRegistrationState(serial);
224         }
225     }
226 
227     /**
228      * Call IRadioNetwork#getImsRegistrationState
229      * @param serial Serial number of request
230      * @throws RemoteException
231      */
getImsRegistrationState(int serial)232     public void getImsRegistrationState(int serial) throws RemoteException {
233         if (isEmpty()) return;
234         if (isAidl()) {
235             mNetworkProxy.getImsRegistrationState(serial);
236         } else {
237             mRadioProxy.getImsRegistrationState(serial);
238         }
239     }
240 
241     /**
242      * Call IRadioNetwork#getNetworkSelectionMode
243      * @param serial Serial number of request
244      * @throws RemoteException
245      */
getNetworkSelectionMode(int serial)246     public void getNetworkSelectionMode(int serial) throws RemoteException {
247         if (isEmpty()) return;
248         if (isAidl()) {
249             mNetworkProxy.getNetworkSelectionMode(serial);
250         } else {
251             mRadioProxy.getNetworkSelectionMode(serial);
252         }
253     }
254 
255     /**
256      * Call IRadioNetwork#getOperator
257      * @param serial Serial number of request
258      * @throws RemoteException
259      */
getOperator(int serial)260     public void getOperator(int serial) throws RemoteException {
261         if (isEmpty()) return;
262         if (isAidl()) {
263             mNetworkProxy.getOperator(serial);
264         } else {
265             mRadioProxy.getOperator(serial);
266         }
267     }
268 
269     /**
270      * Call IRadioNetwork#getSignalStrength
271      * @param serial Serial number of request
272      * @throws RemoteException
273      */
getSignalStrength(int serial)274     public void getSignalStrength(int serial) throws RemoteException {
275         if (isEmpty()) return;
276         if (isAidl()) {
277             mNetworkProxy.getSignalStrength(serial);
278         } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) {
279             ((android.hardware.radio.V1_6.IRadio) mRadioProxy).getSignalStrength_1_6(serial);
280         } else {
281             mRadioProxy.getSignalStrength_1_4(serial);
282         }
283     }
284 
285     /**
286      * Call IRadioNetwork#getSystemSelectionChannels
287      * @param serial Serial number of request
288      * @throws RemoteException
289      */
getSystemSelectionChannels(int serial)290     public void getSystemSelectionChannels(int serial) throws RemoteException {
291         if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_6)) return;
292         if (isAidl()) {
293             mNetworkProxy.getSystemSelectionChannels(serial);
294         } else {
295             ((android.hardware.radio.V1_6.IRadio) mRadioProxy).getSystemSelectionChannels(serial);
296         }
297     }
298 
299     /**
300      * Call IRadioNetwork#getVoiceRadioTechnology
301      * @param serial Serial number of request
302      * @throws RemoteException
303      */
getVoiceRadioTechnology(int serial)304     public void getVoiceRadioTechnology(int serial) throws RemoteException {
305         if (isEmpty()) return;
306         if (isAidl()) {
307             mNetworkProxy.getVoiceRadioTechnology(serial);
308         } else {
309             mRadioProxy.getVoiceRadioTechnology(serial);
310         }
311     }
312 
313     /**
314      * Call IRadioNetwork#getVoiceRegistrationState
315      * @param serial Serial number of request
316      * @param overrideHalVersion Radio HAL fallback compatibility override
317      * @throws RemoteException
318      */
getVoiceRegistrationState(int serial, HalVersion overrideHalVersion)319     public void getVoiceRegistrationState(int serial, HalVersion overrideHalVersion)
320             throws RemoteException {
321         if (isEmpty()) return;
322         if (isAidl()) {
323             mNetworkProxy.getVoiceRegistrationState(serial);
324         } else if ((overrideHalVersion == null
325                 || overrideHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6))
326                 && mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) {
327             ((android.hardware.radio.V1_6.IRadio) mRadioProxy)
328                     .getVoiceRegistrationState_1_6(serial);
329         } else if ((overrideHalVersion == null
330                 || overrideHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5))
331                 && mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) {
332             ((android.hardware.radio.V1_5.IRadio) mRadioProxy)
333                     .getVoiceRegistrationState_1_5(serial);
334         } else {
335             mRadioProxy.getVoiceRegistrationState(serial);
336         }
337     }
338 
339     /**
340      * Call IRadioNetwork#isNrDualConnectivityEnabled
341      * @param serial Serial number of request
342      * @throws RemoteException
343      */
isNrDualConnectivityEnabled(int serial)344     public void isNrDualConnectivityEnabled(int serial) throws RemoteException {
345         if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_6)) return;
346         if (isAidl()) {
347             mNetworkProxy.isNrDualConnectivityEnabled(serial);
348         } else {
349             ((android.hardware.radio.V1_6.IRadio) mRadioProxy).isNrDualConnectivityEnabled(serial);
350         }
351     }
352 
353     /**
354      * Call IRadioNetwork#responseAcknowledgement
355      * @throws RemoteException
356      */
357     @Override
responseAcknowledgement()358     public void responseAcknowledgement() throws RemoteException {
359         if (isEmpty()) return;
360         if (isAidl()) {
361             mNetworkProxy.responseAcknowledgement();
362         } else {
363             mRadioProxy.responseAcknowledgement();
364         }
365     }
366 
367     /**
368      * Call IRadioNetwork#setAllowedNetworkTypesBitmap
369      * @param serial Serial number of request
370      * @param networkTypeBitmask Network type bitmask to set
371      * @throws RemoteException
372      */
setAllowedNetworkTypesBitmap(int serial, int networkTypeBitmask)373     public void setAllowedNetworkTypesBitmap(int serial, int networkTypeBitmask)
374             throws RemoteException {
375         if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_6)) return;
376         if (isAidl()) {
377             mNetworkProxy.setAllowedNetworkTypesBitmap(serial,
378                     RILUtils.convertToHalRadioAccessFamilyAidl(networkTypeBitmask));
379         } else {
380             ((android.hardware.radio.V1_6.IRadio) mRadioProxy).setAllowedNetworkTypesBitmap(
381                     serial, RILUtils.convertToHalRadioAccessFamily(networkTypeBitmask));
382         }
383     }
384 
385     /**
386      * Call IRadioNetwork#setPreferredNetworkTypeBitmap
387      * @param serial Serial number of request
388      * @param networkTypesBitmask Preferred network types bitmask to set
389      * @throws RemoteException
390      */
setPreferredNetworkTypeBitmap(int serial, int networkTypesBitmask)391     public void setPreferredNetworkTypeBitmap(int serial, int networkTypesBitmask)
392             throws RemoteException {
393         if (isEmpty() || mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) return;
394         mRadioProxy.setPreferredNetworkTypeBitmap(serial,
395                 RILUtils.convertToHalRadioAccessFamily(networkTypesBitmask));
396     }
397 
398     /**
399      * Call IRadioNetwork#setBandMode
400      * @param serial Serial number of request
401      * @param bandMode One of BM_*_BAND
402      * @throws RemoteException
403      */
setBandMode(int serial, int bandMode)404     public void setBandMode(int serial, int bandMode) throws RemoteException {
405         if (Flags.cleanupCdma()) return;
406         if (isEmpty()) return;
407         if (isAidl()) {
408             mNetworkProxy.setBandMode(serial, bandMode);
409         } else {
410             mRadioProxy.setBandMode(serial, bandMode);
411         }
412     }
413 
414     /**
415      * Call IRadioNetwork#setBarringPassword
416      * @param serial Serial number of request
417      * @param facility Facility string code
418      * @param oldPassword Old password
419      * @param newPassword New password
420      * @throws RemoteException
421      */
setBarringPassword(int serial, String facility, String oldPassword, String newPassword)422     public void setBarringPassword(int serial, String facility, String oldPassword,
423             String newPassword) throws RemoteException {
424         if (isEmpty()) return;
425         if (isAidl()) {
426             mNetworkProxy.setBarringPassword(serial, facility, oldPassword, newPassword);
427         } else {
428             mRadioProxy.setBarringPassword(serial, facility, oldPassword, newPassword);
429         }
430     }
431 
432     /**
433      * Call IRadioNetwork#setCdmaRoamingPreference
434      * @param serial Serial number of request
435      * @param cdmaRoamingType One of CDMA_RM_*
436      * @throws RemoteException
437      */
setCdmaRoamingPreference(int serial, int cdmaRoamingType)438     public void setCdmaRoamingPreference(int serial, int cdmaRoamingType) throws RemoteException {
439         if (Flags.cleanupCdma()) return;
440         if (isEmpty()) return;
441         if (isAidl()) {
442             mNetworkProxy.setCdmaRoamingPreference(serial, cdmaRoamingType);
443         } else {
444             mRadioProxy.setCdmaRoamingPreference(serial, cdmaRoamingType);
445         }
446     }
447 
448     /**
449      * Call IRadioNetwork#setCellInfoListRate
450      * @param serial Serial number of request
451      * @param rate Minimum time in milliseconds to indicate time between unsolicited cellInfoList()
452      * @throws RemoteException
453      */
setCellInfoListRate(int serial, int rate)454     public void setCellInfoListRate(int serial, int rate) throws RemoteException {
455         if (isEmpty()) return;
456         if (isAidl()) {
457             mNetworkProxy.setCellInfoListRate(serial, rate);
458         } else {
459             mRadioProxy.setCellInfoListRate(serial, rate);
460         }
461     }
462 
463     /**
464      * Call IRadioNetwork#setIndicationFilter
465      * @param serial Serial number of request
466      * @param filter Unsolicited response filter
467      * @throws RemoteException
468      */
setIndicationFilter(int serial, int filter)469     public void setIndicationFilter(int serial, int filter) throws RemoteException {
470         if (isEmpty()) return;
471         if (isAidl()) {
472             mNetworkProxy.setIndicationFilter(serial, filter & INDICATION_FILTERS_ALL_AIDL);
473         } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) {
474             ((android.hardware.radio.V1_5.IRadio) mRadioProxy).setIndicationFilter_1_5(serial,
475                     filter & INDICATION_FILTERS_ALL_V1_5);
476         } else {
477             mRadioProxy.setIndicationFilter_1_2(serial, filter & INDICATION_FILTERS_ALL_V1_2);
478         }
479     }
480 
481     /**
482      * Call IRadioNetwork#setLinkCapacityReportingCriteria
483      * @param serial Serial number of request
484      * @param hysteresisMs A hysteresis time in milliseconds. A value of 0 disables hysteresis.
485      * @param hysteresisDlKbps An interval in kbps defining the required magnitude change between DL
486      *                         reports. A value of 0 disables hysteresis
487      * @param hysteresisUlKbps An interval in kbps defining the required magnitude change between UL
488      *                         reports. A value of 0 disables hysteresis
489      * @param thresholdsDlKbps An array of trigger thresholds in kbps for DL reports. A size of 0
490      *                         disables thresholds
491      * @param thresholdsUlKbps An array of trigger thresholds in kbps for UL reports. A size of 0
492      *                         disables thresholds
493      * @param ran RadioAccessNetwork for which to apply criteria
494      * @throws RemoteException
495      */
setLinkCapacityReportingCriteria(int serial, int hysteresisMs, int hysteresisDlKbps, int hysteresisUlKbps, int[] thresholdsDlKbps, int[] thresholdsUlKbps, int ran)496     public void setLinkCapacityReportingCriteria(int serial, int hysteresisMs, int hysteresisDlKbps,
497             int hysteresisUlKbps, int[] thresholdsDlKbps, int[] thresholdsUlKbps, int ran)
498             throws RemoteException {
499         if (isEmpty()) return;
500         if (isAidl()) {
501             mNetworkProxy.setLinkCapacityReportingCriteria(serial, hysteresisMs, hysteresisDlKbps,
502                     hysteresisUlKbps, thresholdsDlKbps, thresholdsUlKbps,
503                     RILUtils.convertToHalAccessNetworkAidl(ran));
504         } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) {
505             ((android.hardware.radio.V1_5.IRadio) mRadioProxy).setLinkCapacityReportingCriteria_1_5(
506                     serial, hysteresisMs, hysteresisDlKbps, hysteresisUlKbps,
507                     RILUtils.primitiveArrayToArrayList(thresholdsDlKbps),
508                     RILUtils.primitiveArrayToArrayList(thresholdsUlKbps),
509                     RILUtils.convertToHalAccessNetwork(ran));
510         } else {
511             if (ran == AccessNetworkConstants.AccessNetworkType.NGRAN) {
512                 throw new RuntimeException("NGRAN unsupported on IRadio version: " + mHalVersion);
513             }
514             mRadioProxy.setLinkCapacityReportingCriteria(
515                     serial, hysteresisMs, hysteresisDlKbps, hysteresisUlKbps,
516                     RILUtils.primitiveArrayToArrayList(thresholdsDlKbps),
517                     RILUtils.primitiveArrayToArrayList(thresholdsUlKbps),
518                     RILUtils.convertToHalAccessNetwork(ran));
519         }
520     }
521 
522     /**
523      * Call IRadioNetwork#setLocationUpdates
524      * @param serial Serial number of request
525      * @param enable Whether to enable or disable network state change notifications when location
526      *               information (lac and/or cid) has changed
527      * @throws RemoteException
528      */
setLocationUpdates(int serial, boolean enable)529     public void setLocationUpdates(int serial, boolean enable) throws RemoteException {
530         if (Flags.cleanupCdma()) return;
531         if (isEmpty()) return;
532         if (isAidl()) {
533             mNetworkProxy.setLocationUpdates(serial, enable);
534         } else {
535             mRadioProxy.setLocationUpdates(serial, enable);
536         }
537     }
538 
539     /**
540      * Call IRadioNetwork#setNetworkSelectionModeAutomatic
541      * @param serial Serial number of request
542      * @throws RemoteException
543      */
setNetworkSelectionModeAutomatic(int serial)544     public void setNetworkSelectionModeAutomatic(int serial) throws RemoteException {
545         if (isEmpty()) return;
546         if (isAidl()) {
547             mNetworkProxy.setNetworkSelectionModeAutomatic(serial);
548         } else {
549             mRadioProxy.setNetworkSelectionModeAutomatic(serial);
550         }
551     }
552 
553     /**
554      * Call IRadioNetwork#setNetworkSelectionModeManual
555      * @param serial Serial number of request
556      * @param operatorNumeric PLMN ID of the network to select
557      * @param ran Radio access network type
558      * @throws RemoteException
559      */
setNetworkSelectionModeManual(int serial, String operatorNumeric, int ran)560     public void setNetworkSelectionModeManual(int serial, String operatorNumeric, int ran)
561             throws RemoteException {
562         if (isEmpty()) return;
563         if (isAidl()) {
564             mNetworkProxy.setNetworkSelectionModeManual(serial, operatorNumeric,
565                     RILUtils.convertToHalAccessNetworkAidl(ran));
566         } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) {
567             ((android.hardware.radio.V1_5.IRadio) mRadioProxy).setNetworkSelectionModeManual_1_5(
568                     serial, operatorNumeric, RILUtils.convertToHalRadioAccessNetworks(ran));
569         } else {
570             mRadioProxy.setNetworkSelectionModeManual(serial, operatorNumeric);
571         }
572     }
573 
574     /**
575      * Call IRadioNetwork#setNrDualConnectivityState
576      * @param serial Serial number of request
577      * @param nrDualConnectivityState Expected NR dual connectivity state
578      * @throws RemoteException
579      */
setNrDualConnectivityState(int serial, byte nrDualConnectivityState)580     public void setNrDualConnectivityState(int serial, byte nrDualConnectivityState)
581             throws RemoteException {
582         if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_6)) return;
583         if (isAidl()) {
584             mNetworkProxy.setNrDualConnectivityState(serial, nrDualConnectivityState);
585         } else {
586             ((android.hardware.radio.V1_6.IRadio) mRadioProxy).setNrDualConnectivityState(
587                     serial, nrDualConnectivityState);
588         }
589     }
590 
591     /**
592      * Call IRadioNetwork#setSignalStrengthReportingCriteria
593      * @param serial Serial number of request
594      * @param signalThresholdInfos a list of {@link SignalThresholdInfo} to set with.
595      * @throws RemoteException
596      */
setSignalStrengthReportingCriteria(int serial, @NonNull List<SignalThresholdInfo> signalThresholdInfos)597     public void setSignalStrengthReportingCriteria(int serial,
598             @NonNull List<SignalThresholdInfo> signalThresholdInfos) throws RemoteException {
599         if (isEmpty()) return;
600         if (isAidl()) {
601             android.hardware.radio.network.SignalThresholdInfo[] halSignalThresholdsInfos =
602             new android.hardware.radio.network.SignalThresholdInfo[signalThresholdInfos.size()];
603             for (int i = 0; i < signalThresholdInfos.size(); i++) {
604                 halSignalThresholdsInfos[i] = RILUtils.convertToHalSignalThresholdInfoAidl(
605                         signalThresholdInfos.get(i));
606             }
607             mNetworkProxy.setSignalStrengthReportingCriteria(serial, halSignalThresholdsInfos);
608         } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) {
609             for (SignalThresholdInfo signalThresholdInfo : signalThresholdInfos) {
610                 ((android.hardware.radio.V1_5.IRadio) mRadioProxy)
611                         .setSignalStrengthReportingCriteria_1_5(serial,
612                                 RILUtils.convertToHalSignalThresholdInfo(signalThresholdInfo),
613                                 RILUtils.convertToHalAccessNetwork(
614                                         signalThresholdInfo.getRadioAccessNetworkType()));
615             }
616         } else {
617             for (SignalThresholdInfo signalThresholdInfo : signalThresholdInfos) {
618                 mRadioProxy.setSignalStrengthReportingCriteria(serial,
619                         signalThresholdInfo.getHysteresisMs(),
620                         signalThresholdInfo.getHysteresisDb(),
621                         RILUtils.primitiveArrayToArrayList(signalThresholdInfo.getThresholds()),
622                         RILUtils.convertToHalAccessNetwork(
623                                 signalThresholdInfo.getRadioAccessNetworkType()));
624             }
625         }
626     }
627 
628     /**
629      * Call IRadioNetwork#setSuppServiceNotifications
630      * @param serial Serial number of request
631      * @param enable True to enable notifications, false to disable
632      * @throws RemoteException
633      */
setSuppServiceNotifications(int serial, boolean enable)634     public void setSuppServiceNotifications(int serial, boolean enable) throws RemoteException {
635         if (Flags.cleanupCdma()) return;
636         if (isEmpty()) return;
637         if (isAidl()) {
638             mNetworkProxy.setSuppServiceNotifications(serial, enable);
639         } else {
640             mRadioProxy.setSuppServiceNotifications(serial, enable);
641         }
642     }
643 
644     /**
645      * Call IRadioNetwork#setSystemSelectionChannels
646      * @param serial Serial number of request
647      * @param specifiers Which bands to scan
648      * @throws RemoteException
649      */
setSystemSelectionChannels(int serial, List<RadioAccessSpecifier> specifiers)650     public void setSystemSelectionChannels(int serial, List<RadioAccessSpecifier> specifiers)
651             throws RemoteException {
652         if (isEmpty()) return;
653         if (isAidl()) {
654             mNetworkProxy.setSystemSelectionChannels(serial, !specifiers.isEmpty(),
655                     specifiers.stream().map(RILUtils::convertToHalRadioAccessSpecifierAidl)
656                             .toArray(android.hardware.radio.network.RadioAccessSpecifier[]::new));
657         } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) {
658             ((android.hardware.radio.V1_5.IRadio) mRadioProxy).setSystemSelectionChannels_1_5(
659                     serial, !specifiers.isEmpty(), specifiers.stream()
660                             .map(RILUtils::convertToHalRadioAccessSpecifier15)
661                             .collect(Collectors.toCollection(ArrayList::new)));
662         } else {
663             mRadioProxy.setSystemSelectionChannels(serial, !specifiers.isEmpty(),
664                     specifiers.stream()
665                             .map(RILUtils::convertToHalRadioAccessSpecifier11)
666                             .collect(Collectors.toCollection(ArrayList::new)));
667         }
668     }
669 
670     /**
671      * Call IRadioNetwork#startNetworkScan
672      * @param serial Serial number of request
673      * @param request Defines the radio networks/bands/channels which need to be scanned
674      * @param overrideHalVersion Radio HAL fallback compatibility override
675      * @throws RemoteException
676      */
startNetworkScan(int serial, NetworkScanRequest request, HalVersion overrideHalVersion, Message result)677     public void startNetworkScan(int serial, NetworkScanRequest request,
678             HalVersion overrideHalVersion, Message result) throws RemoteException {
679         if (isEmpty()) return;
680         if (isAidl()) {
681             android.hardware.radio.network.NetworkScanRequest halRequest =
682                     new android.hardware.radio.network.NetworkScanRequest();
683             halRequest.type = request.getScanType();
684             halRequest.interval = request.getSearchPeriodicity();
685             halRequest.maxSearchTime = request.getMaxSearchTime();
686             halRequest.incrementalResultsPeriodicity = request.getIncrementalResultsPeriodicity();
687             halRequest.incrementalResults = request.getIncrementalResults();
688             halRequest.mccMncs = request.getPlmns().stream().toArray(String[]::new);
689             ArrayList<android.hardware.radio.network.RadioAccessSpecifier> specifiers =
690                     new ArrayList<>();
691             for (RadioAccessSpecifier ras : request.getSpecifiers()) {
692                 android.hardware.radio.network.RadioAccessSpecifier rasInHalFormat =
693                         RILUtils.convertToHalRadioAccessSpecifierAidl(ras);
694                 if (rasInHalFormat == null) {
695                     AsyncResult.forMessage(result, null,
696                             CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
697                     result.sendToTarget();
698                     return;
699                 }
700                 specifiers.add(rasInHalFormat);
701             }
702             halRequest.specifiers = specifiers.stream().toArray(
703                     android.hardware.radio.network.RadioAccessSpecifier[]::new);
704             mNetworkProxy.startNetworkScan(serial, halRequest);
705         } else if ((overrideHalVersion == null
706                 || overrideHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5))
707                 && mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) {
708             android.hardware.radio.V1_5.NetworkScanRequest halRequest =
709                     new android.hardware.radio.V1_5.NetworkScanRequest();
710             halRequest.type = request.getScanType();
711             halRequest.interval = request.getSearchPeriodicity();
712             halRequest.maxSearchTime = request.getMaxSearchTime();
713             halRequest.incrementalResultsPeriodicity = request.getIncrementalResultsPeriodicity();
714             halRequest.incrementalResults = request.getIncrementalResults();
715             halRequest.mccMncs.addAll(request.getPlmns());
716             for (RadioAccessSpecifier ras : request.getSpecifiers()) {
717                 android.hardware.radio.V1_5.RadioAccessSpecifier rasInHalFormat =
718                         RILUtils.convertToHalRadioAccessSpecifier15(ras);
719                 if (rasInHalFormat == null) {
720                     AsyncResult.forMessage(result, null,
721                             CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
722                     result.sendToTarget();
723                     return;
724                 }
725                 halRequest.specifiers.add(rasInHalFormat);
726             }
727             ((android.hardware.radio.V1_5.IRadio) mRadioProxy).startNetworkScan_1_5(
728                     serial, halRequest);
729         } else {
730             android.hardware.radio.V1_2.NetworkScanRequest halRequest =
731                     new android.hardware.radio.V1_2.NetworkScanRequest();
732             halRequest.type = request.getScanType();
733             halRequest.interval = request.getSearchPeriodicity();
734             halRequest.maxSearchTime = request.getMaxSearchTime();
735             halRequest.incrementalResultsPeriodicity = request.getIncrementalResultsPeriodicity();
736             halRequest.incrementalResults = request.getIncrementalResults();
737             halRequest.mccMncs.addAll(request.getPlmns());
738 
739             for (RadioAccessSpecifier ras : request.getSpecifiers()) {
740                 android.hardware.radio.V1_1.RadioAccessSpecifier rasInHalFormat =
741                         RILUtils.convertToHalRadioAccessSpecifier11(ras);
742                 if (rasInHalFormat == null) {
743                     AsyncResult.forMessage(result, null,
744                             CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
745                     result.sendToTarget();
746                     return;
747                 }
748                 halRequest.specifiers.add(rasInHalFormat);
749             }
750             mRadioProxy.startNetworkScan_1_4(serial, halRequest);
751         }
752     }
753 
754     /**
755      * Call IRadioNetwork#stopNetworkScan
756      * @param serial Serial number of request
757      * @throws RemoteException
758      */
stopNetworkScan(int serial)759     public void stopNetworkScan(int serial) throws RemoteException {
760         if (isEmpty()) return;
761         if (isAidl()) {
762             mNetworkProxy.stopNetworkScan(serial);
763         } else {
764             mRadioProxy.stopNetworkScan(serial);
765         }
766     }
767 
768     /**
769      * Call IRadioNetwork#supplyNetworkDepersonalization
770      * @param serial Serial number of request
771      * @param netPin Network depersonalization code
772      * @throws RemoteException
773      */
supplyNetworkDepersonalization(int serial, String netPin)774     public void supplyNetworkDepersonalization(int serial, String netPin) throws RemoteException {
775         if (isEmpty()) return;
776         if (isAidl()) {
777             mNetworkProxy.supplyNetworkDepersonalization(serial, netPin);
778         } else {
779             mRadioProxy.supplyNetworkDepersonalization(serial, netPin);
780         }
781     }
782 
783     /**
784      * Call IRadioNetwork#getUsageSetting()
785      * @param serial Serial number of request
786      * @throws RemoteException
787      */
getUsageSetting(int serial)788     public void getUsageSetting(int serial) throws RemoteException {
789         if (isEmpty()) return;
790         if (isAidl()) {
791             mNetworkProxy.getUsageSetting(serial);
792         }
793         // Only supported on AIDL.
794     }
795 
796     /**
797      * Call IRadioNetwork#setUsageSetting()
798      * @param serial Serial number of request
799      * @throws RemoteException
800      */
setUsageSetting(int serial, int usageSetting)801     public void setUsageSetting(int serial,
802             /* TelephonyManager.UsageSetting */ int usageSetting) throws RemoteException {
803         if (isEmpty()) return;
804         if (isAidl()) {
805             mNetworkProxy.setUsageSetting(serial, usageSetting);
806         }
807         // Only supported on AIDL.
808     }
809 
810     /**
811      * Set the Emergency Mode
812      *
813      * @param serial Serial number of the request.
814      * @param emcModeType Defines the radio emergency mode type.
815      * @throws RemoteException
816      */
setEmergencyMode(int serial, int emcModeType)817     public void setEmergencyMode(int serial, int emcModeType) throws RemoteException {
818         if (isEmpty()) return;
819         if (isAidl()) {
820             mNetworkProxy.setEmergencyMode(serial, emcModeType);
821         }
822         // Only supported on AIDL.
823     }
824 
825     /**
826      * Triggers an Emergency network scan.
827      *
828      * @param serial Serial number of the request.
829      * @param scanRequest Contains the preferred networks and type of service to be scanned.
830      * @throws RemoteException
831      */
triggerEmergencyNetworkScan(int serial, android.hardware.radio.network.EmergencyNetworkScanTrigger scanRequest)832     public void triggerEmergencyNetworkScan(int serial,
833             android.hardware.radio.network.EmergencyNetworkScanTrigger scanRequest)
834             throws RemoteException {
835         if (isEmpty()) return;
836         if (isAidl()) {
837             mNetworkProxy.triggerEmergencyNetworkScan(serial, scanRequest);
838         }
839         // Only supported on AIDL.
840     }
841 
842     /**
843      * Cancels ongoing Emergency network scan
844      *
845      * @param serial Serial number of the request.
846      * @param resetScan Indicates how the next {@link #triggerEmergencyNetworkScan} should work.
847      *        If {@code true}, then the modem shall start the new scan from the beginning,
848      *        otherwise the modem shall resume from the last search.
849      *
850      * @throws RemoteException
851      */
cancelEmergencyNetworkScan(int serial, boolean resetScan)852     public void cancelEmergencyNetworkScan(int serial, boolean resetScan) throws RemoteException {
853         if (isEmpty()) return;
854         if (isAidl()) {
855             mNetworkProxy.cancelEmergencyNetworkScan(serial, resetScan);
856         }
857         // Only supported on AIDL.
858     }
859 
860     /**
861      * Exits ongoing Emergency Mode
862      *
863      * @param serial Serial number of the request.
864      * @throws RemoteException
865      */
exitEmergencyMode(int serial)866     public void exitEmergencyMode(int serial) throws RemoteException {
867         if (isEmpty()) return;
868         if (isAidl()) {
869             mNetworkProxy.exitEmergencyMode(serial);
870         }
871         // Only supported on AIDL.
872     }
873 
874     /**
875      * Set if null ciphering / null integrity is permitted.
876      *
877      * @param serial Serial number of the request.
878      * @param enabled true if null modes are allowed, false otherwise
879      * @throws RemoteException
880      */
setNullCipherAndIntegrityEnabled(int serial, boolean enabled)881     public void setNullCipherAndIntegrityEnabled(int serial,
882             boolean enabled) throws RemoteException {
883         if (isEmpty()) return;
884         if (isAidl()) {
885             mNetworkProxy.setNullCipherAndIntegrityEnabled(serial, enabled);
886         }
887         // Only supported on AIDL.
888     }
889 
890     /**
891      * Get if null ciphering / null integrity is permitted.
892      * @param serial Serial number of the request.
893      * @throws RemoteException
894      *
895      */
isNullCipherAndIntegrityEnabled(int serial)896     public void isNullCipherAndIntegrityEnabled(int serial) throws RemoteException {
897         if (isEmpty()) return;
898         if (isAidl()) {
899             mNetworkProxy.isNullCipherAndIntegrityEnabled(serial);
900         }
901         // Only supported on AIDL.
902     }
903 
904     /**
905      * Checks whether N1 mode is enabled.
906      *
907      * @param serial Serial number of the request.
908      * @throws RemoteException
909      */
isN1ModeEnabled(int serial)910     public void isN1ModeEnabled(int serial) throws RemoteException {
911         if (isEmpty()) return;
912         if (isAidl()) {
913             mNetworkProxy.isN1ModeEnabled(serial);
914         }
915         // Only supported on AIDL.
916     }
917 
918     /**
919      * Enables or disables N1 mode.
920      *
921      * @param serial Serial number of request.
922      * @param enable Indicates whether to enable N1 mode or not.
923      * @throws RemoteException
924      */
setN1ModeEnabled(int serial, boolean enable)925     public void setN1ModeEnabled(int serial, boolean enable) throws RemoteException {
926         if (isEmpty()) return;
927         if (isAidl()) {
928             mNetworkProxy.setN1ModeEnabled(serial, enable);
929         }
930         // Only supported on AIDL.
931     }
932 
933     /**
934      * Enables or disables cellular identifier disclosure transparency.
935      *
936      * @param serial Serial number of request.
937      * @param enable Indicates whether to enable disclosure transparency or not.
938      */
setCellularIdentifierTransparencyEnabled(int serial, boolean enable)939     public void setCellularIdentifierTransparencyEnabled(int serial, boolean enable)
940             throws RemoteException {
941         if (isEmpty()) return;
942         if (isAidl()) {
943             mNetworkProxy.setCellularIdentifierTransparencyEnabled(serial, enable);
944         }
945         // Only supported on AIDL.
946     }
947 
948     /**
949      * Checks whether cellular identifier transparency disclosure is enabled.
950      *
951      * @param serial Serial number of request.
952      */
isCellularIdentifierTransparencyEnabled(int serial)953     public void isCellularIdentifierTransparencyEnabled(int serial) throws RemoteException {
954         if (isEmpty()) return;
955         if (isAidl()) {
956             mNetworkProxy.isCellularIdentifierTransparencyEnabled(serial);
957         }
958         // Only supported on AIDL.
959     }
960 
961     /**
962      * Checks security algorithm update reports are enabled.
963      *
964      * @param serial Serial number of the request.
965      * @throws RemoteException
966      */
isSecurityAlgorithmsUpdatedEnabled(int serial)967     public void isSecurityAlgorithmsUpdatedEnabled(int serial) throws RemoteException {
968         if (isEmpty()) return;
969         if (isAidl()) {
970             mNetworkProxy.isSecurityAlgorithmsUpdatedEnabled(serial);
971         }
972         // Only supported on AIDL.
973     }
974 
975     /**
976      * Enables or disables security algorithm update reports.
977      *
978      * @param serial Serial number of request.
979      * @param enable Indicates whether to enable or disable security algorithm update reports.
980      * @throws RemoteException
981      */
setSecurityAlgorithmsUpdatedEnabled(int serial, boolean enable)982     public void setSecurityAlgorithmsUpdatedEnabled(int serial,
983             boolean enable) throws RemoteException {
984         if (isEmpty()) return;
985         if (isAidl()) {
986             mNetworkProxy.setSecurityAlgorithmsUpdatedEnabled(serial, enable);
987         }
988         // Only supported on AIDL.
989     }
990 
991    /**
992      * Set the non-terrestrial PLMN with lower priority than terrestrial networks.
993      *
994      * @param serial Serial number of request.
995      * @param carrierPlmnList The list of roaming PLMN used for connecting to satellite networks
996      *                        supported by user subscription.
997      * @param allSatellitePlmnList Modem should use the allSatellitePlmnList to identify satellite
998      *                             PLMNs that are not supported by the carrier and make sure not to
999      *                             attach to them.
1000      */
setSatellitePlmn(int serial, List<String> carrierPlmnList, List<String> allSatellitePlmnList)1001     public void setSatellitePlmn(int serial, List<String> carrierPlmnList,
1002             List<String> allSatellitePlmnList) throws RemoteException {
1003         if (isEmpty()) return;
1004         if (isAidl()) {
1005             String[] carrierPlmnArray = carrierPlmnList.toArray(new String[0]);
1006             String[] allSatellitePlmnArray = allSatellitePlmnList.toArray(new String[0]);
1007             mNetworkProxy.setSatellitePlmn(serial, carrierPlmnArray, allSatellitePlmnArray);
1008         }
1009         // Only supported on AIDL.
1010     }
1011 
1012     /**
1013      * Enable or disable satellite in the cellular modem associated with a carrier.
1014      *
1015      * @param serial Serial number of request.
1016      * @param satelliteEnabled {@code true} to enable satellite, {@code false} to disable satellite.
1017      */
setSatelliteEnabledForCarrier( int serial, boolean satelliteEnabled)1018     public void setSatelliteEnabledForCarrier(
1019             int serial, boolean satelliteEnabled) throws RemoteException {
1020         if (isEmpty()) return;
1021         if (isAidl()) {
1022             mNetworkProxy.setSatelliteEnabledForCarrier(serial, satelliteEnabled);
1023         }
1024         // Only supported on AIDL.
1025     }
1026 
1027     /**
1028      * Check whether satellite is enabled in the cellular modem associated with a carrier.
1029      *
1030      * @param serial Serial number of request.
1031      */
isSatelliteEnabledForCarrier(int serial)1032     public void isSatelliteEnabledForCarrier(int serial)
1033             throws RemoteException {
1034         if (isEmpty()) return;
1035         if (isAidl()) {
1036             mNetworkProxy.isSatelliteEnabledForCarrier(serial);
1037         }
1038         // Only supported on AIDL.
1039     }
1040 }
1041