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 java.util.ArrayList; 32 import java.util.List; 33 import java.util.stream.Collectors; 34 35 /** 36 * A holder for IRadioNetwork. Use getHidl to get IRadio 1.0 and call the HIDL implementations or 37 * getAidl to get IRadioNetwork and call the AIDL implementations of the HAL APIs. 38 */ 39 public class RadioNetworkProxy extends RadioServiceProxy { 40 private static final String TAG = "RadioNetworkProxy"; 41 private volatile android.hardware.radio.network.IRadioNetwork mNetworkProxy = null; 42 43 private static final int INDICATION_FILTERS_ALL_V1_0 = 44 android.hardware.radio.V1_5.IndicationFilter.SIGNAL_STRENGTH 45 | android.hardware.radio.V1_5.IndicationFilter.FULL_NETWORK_STATE 46 | android.hardware.radio.V1_5.IndicationFilter.DATA_CALL_DORMANCY_CHANGED; 47 private static final int INDICATION_FILTERS_ALL_V1_2 = 48 INDICATION_FILTERS_ALL_V1_0 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 */ setAidl(HalVersion halVersion, android.hardware.radio.network.IRadioNetwork network)69 public void setAidl(HalVersion halVersion, 70 android.hardware.radio.network.IRadioNetwork network) { 71 mHalVersion = halVersion; 72 mNetworkProxy = network; 73 mIsAidl = true; 74 Rlog.d(TAG, "AIDL initialized"); 75 } 76 77 /** 78 * Get the AIDL implementation of RadioNetworkProxy 79 * @return IRadioNetwork implementation 80 */ getAidl()81 public android.hardware.radio.network.IRadioNetwork getAidl() { 82 return mNetworkProxy; 83 } 84 85 /** 86 * Reset RadioNetworkProxy 87 */ 88 @Override clear()89 public void clear() { 90 super.clear(); 91 mNetworkProxy = null; 92 } 93 94 /** 95 * Check whether a RadioNetwork implementation exists 96 * @return true if there is neither a HIDL nor AIDL implementation 97 */ 98 @Override isEmpty()99 public boolean isEmpty() { 100 return mRadioProxy == null && mNetworkProxy == null; 101 } 102 103 /** 104 * Call IRadioNetwork#getAllowedNetworkTypesBitmap 105 * @param serial Serial number of request 106 * @throws RemoteException 107 */ getAllowedNetworkTypesBitmap(int serial)108 public void getAllowedNetworkTypesBitmap(int serial) throws RemoteException { 109 if (isEmpty()) return; 110 if (isAidl()) { 111 mNetworkProxy.getAllowedNetworkTypesBitmap(serial); 112 } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) { 113 ((android.hardware.radio.V1_6.IRadio) mRadioProxy).getAllowedNetworkTypesBitmap(serial); 114 } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_4)) { 115 ((android.hardware.radio.V1_4.IRadio) mRadioProxy) 116 .getPreferredNetworkTypeBitmap(serial); 117 } else { 118 mRadioProxy.getPreferredNetworkType(serial); 119 } 120 } 121 122 /** 123 * Call IRadioNetwork#getAvailableBandModes 124 * @param serial Serial number of request 125 * @throws RemoteException 126 */ getAvailableBandModes(int serial)127 public void getAvailableBandModes(int serial) throws RemoteException { 128 if (isEmpty()) return; 129 if (isAidl()) { 130 mNetworkProxy.getAvailableBandModes(serial); 131 } else { 132 mRadioProxy.getAvailableBandModes(serial); 133 } 134 } 135 136 /** 137 * Call IRadioNetwork#getAvailableNetworks 138 * @param serial Serial number of request 139 * @throws RemoteException 140 */ getAvailableNetworks(int serial)141 public void getAvailableNetworks(int serial) throws RemoteException { 142 if (isEmpty()) return; 143 if (isAidl()) { 144 mNetworkProxy.getAvailableNetworks(serial); 145 } else { 146 mRadioProxy.getAvailableNetworks(serial); 147 } 148 } 149 150 /** 151 * Call IRadioNetwork#getBarringInfo 152 * @param serial Serial number of request 153 * @throws RemoteException 154 */ getBarringInfo(int serial)155 public void getBarringInfo(int serial) throws RemoteException { 156 if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_5)) return; 157 if (isAidl()) { 158 mNetworkProxy.getBarringInfo(serial); 159 } else { 160 ((android.hardware.radio.V1_5.IRadio) mRadioProxy).getBarringInfo(serial); 161 } 162 } 163 164 /** 165 * Call IRadioNetwork#getCdmaRoamingPreference 166 * @param serial Serial number of request 167 * @throws RemoteException 168 */ getCdmaRoamingPreference(int serial)169 public void getCdmaRoamingPreference(int serial) throws RemoteException { 170 if (isEmpty()) return; 171 if (isAidl()) { 172 mNetworkProxy.getCdmaRoamingPreference(serial); 173 } else { 174 mRadioProxy.getCdmaRoamingPreference(serial); 175 } 176 } 177 178 /** 179 * Call IRadioNetwork#getCellInfoList 180 * @param serial Serial number of request 181 * @throws RemoteException 182 */ getCellInfoList(int serial)183 public void getCellInfoList(int serial) throws RemoteException { 184 if (isEmpty()) return; 185 if (isAidl()) { 186 mNetworkProxy.getCellInfoList(serial); 187 } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) { 188 ((android.hardware.radio.V1_6.IRadio) mRadioProxy).getCellInfoList_1_6(serial); 189 } else { 190 mRadioProxy.getCellInfoList(serial); 191 } 192 } 193 194 /** 195 * Call IRadioNetwork#getDataRegistrationState 196 * @param serial Serial number of request 197 * @param overrideHalVersion Radio HAL fallback compatibility override 198 * @throws RemoteException 199 */ getDataRegistrationState(int serial, HalVersion overrideHalVersion)200 public void getDataRegistrationState(int serial, HalVersion overrideHalVersion) 201 throws RemoteException { 202 if (isEmpty()) return; 203 if (isAidl()) { 204 mNetworkProxy.getDataRegistrationState(serial); 205 } else if ((overrideHalVersion == null 206 || overrideHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) 207 && mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) { 208 ((android.hardware.radio.V1_6.IRadio) mRadioProxy).getDataRegistrationState_1_6(serial); 209 } else if ((overrideHalVersion == null 210 || overrideHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) 211 && mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) { 212 ((android.hardware.radio.V1_5.IRadio) mRadioProxy).getDataRegistrationState_1_5(serial); 213 } else { 214 mRadioProxy.getDataRegistrationState(serial); 215 } 216 } 217 218 /** 219 * Call IRadioNetwork#getImsRegistrationState 220 * @param serial Serial number of request 221 * @throws RemoteException 222 */ getImsRegistrationState(int serial)223 public void getImsRegistrationState(int serial) throws RemoteException { 224 if (isEmpty()) return; 225 if (isAidl()) { 226 mNetworkProxy.getImsRegistrationState(serial); 227 } else { 228 mRadioProxy.getImsRegistrationState(serial); 229 } 230 } 231 232 /** 233 * Call IRadioNetwork#getNetworkSelectionMode 234 * @param serial Serial number of request 235 * @throws RemoteException 236 */ getNetworkSelectionMode(int serial)237 public void getNetworkSelectionMode(int serial) throws RemoteException { 238 if (isEmpty()) return; 239 if (isAidl()) { 240 mNetworkProxy.getNetworkSelectionMode(serial); 241 } else { 242 mRadioProxy.getNetworkSelectionMode(serial); 243 } 244 } 245 246 /** 247 * Call IRadioNetwork#getOperator 248 * @param serial Serial number of request 249 * @throws RemoteException 250 */ getOperator(int serial)251 public void getOperator(int serial) throws RemoteException { 252 if (isEmpty()) return; 253 if (isAidl()) { 254 mNetworkProxy.getOperator(serial); 255 } else { 256 mRadioProxy.getOperator(serial); 257 } 258 } 259 260 /** 261 * Call IRadioNetwork#getSignalStrength 262 * @param serial Serial number of request 263 * @throws RemoteException 264 */ getSignalStrength(int serial)265 public void getSignalStrength(int serial) throws RemoteException { 266 if (isEmpty()) return; 267 if (isAidl()) { 268 mNetworkProxy.getSignalStrength(serial); 269 } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) { 270 ((android.hardware.radio.V1_6.IRadio) mRadioProxy).getSignalStrength_1_6(serial); 271 } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_4)) { 272 ((android.hardware.radio.V1_4.IRadio) mRadioProxy).getSignalStrength_1_4(serial); 273 } else { 274 mRadioProxy.getSignalStrength(serial); 275 } 276 } 277 278 /** 279 * Call IRadioNetwork#getSystemSelectionChannels 280 * @param serial Serial number of request 281 * @throws RemoteException 282 */ getSystemSelectionChannels(int serial)283 public void getSystemSelectionChannels(int serial) throws RemoteException { 284 if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_6)) return; 285 if (isAidl()) { 286 mNetworkProxy.getSystemSelectionChannels(serial); 287 } else { 288 ((android.hardware.radio.V1_6.IRadio) mRadioProxy).getSystemSelectionChannels(serial); 289 } 290 } 291 292 /** 293 * Call IRadioNetwork#getVoiceRadioTechnology 294 * @param serial Serial number of request 295 * @throws RemoteException 296 */ getVoiceRadioTechnology(int serial)297 public void getVoiceRadioTechnology(int serial) throws RemoteException { 298 if (isEmpty()) return; 299 if (isAidl()) { 300 mNetworkProxy.getVoiceRadioTechnology(serial); 301 } else { 302 mRadioProxy.getVoiceRadioTechnology(serial); 303 } 304 } 305 306 /** 307 * Call IRadioNetwork#getVoiceRegistrationState 308 * @param serial Serial number of request 309 * @param overrideHalVersion Radio HAL fallback compatibility override 310 * @throws RemoteException 311 */ getVoiceRegistrationState(int serial, HalVersion overrideHalVersion)312 public void getVoiceRegistrationState(int serial, HalVersion overrideHalVersion) 313 throws RemoteException { 314 if (isEmpty()) return; 315 if (isAidl()) { 316 mNetworkProxy.getVoiceRegistrationState(serial); 317 } else if ((overrideHalVersion == null 318 || overrideHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) 319 && mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) { 320 ((android.hardware.radio.V1_6.IRadio) mRadioProxy) 321 .getVoiceRegistrationState_1_6(serial); 322 } else if ((overrideHalVersion == null 323 || overrideHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) 324 && mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) { 325 ((android.hardware.radio.V1_5.IRadio) mRadioProxy) 326 .getVoiceRegistrationState_1_5(serial); 327 } else { 328 mRadioProxy.getVoiceRegistrationState(serial); 329 } 330 } 331 332 /** 333 * Call IRadioNetwork#isNrDualConnectivityEnabled 334 * @param serial Serial number of request 335 * @throws RemoteException 336 */ isNrDualConnectivityEnabled(int serial)337 public void isNrDualConnectivityEnabled(int serial) throws RemoteException { 338 if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_6)) return; 339 if (isAidl()) { 340 mNetworkProxy.isNrDualConnectivityEnabled(serial); 341 } else { 342 ((android.hardware.radio.V1_6.IRadio) mRadioProxy).isNrDualConnectivityEnabled(serial); 343 } 344 } 345 346 /** 347 * Call IRadioNetwork#responseAcknowledgement 348 * @throws RemoteException 349 */ 350 @Override responseAcknowledgement()351 public void responseAcknowledgement() throws RemoteException { 352 if (isEmpty()) return; 353 if (isAidl()) { 354 mNetworkProxy.responseAcknowledgement(); 355 } else { 356 mRadioProxy.responseAcknowledgement(); 357 } 358 } 359 360 /** 361 * Call IRadioNetwork#setAllowedNetworkTypesBitmap 362 * @param serial Serial number of request 363 * @param networkTypeBitmask Network type bitmask to set 364 * @throws RemoteException 365 */ setAllowedNetworkTypesBitmap(int serial, int networkTypeBitmask)366 public void setAllowedNetworkTypesBitmap(int serial, int networkTypeBitmask) 367 throws RemoteException { 368 if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_6)) return; 369 if (isAidl()) { 370 mNetworkProxy.setAllowedNetworkTypesBitmap(serial, 371 RILUtils.convertToHalRadioAccessFamilyAidl(networkTypeBitmask)); 372 } else { 373 ((android.hardware.radio.V1_6.IRadio) mRadioProxy).setAllowedNetworkTypesBitmap( 374 serial, RILUtils.convertToHalRadioAccessFamily(networkTypeBitmask)); 375 } 376 } 377 378 /** 379 * Call IRadioNetwork#setPreferredNetworkTypeBitmap 380 * @param serial Serial number of request 381 * @param networkTypesBitmask Preferred network types bitmask to set 382 * @throws RemoteException 383 */ setPreferredNetworkTypeBitmap(int serial, int networkTypesBitmask)384 public void setPreferredNetworkTypeBitmap(int serial, int networkTypesBitmask) 385 throws RemoteException { 386 if (isEmpty() || mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) return; 387 if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_4)) { 388 ((android.hardware.radio.V1_4.IRadio) mRadioProxy).setPreferredNetworkTypeBitmap(serial, 389 RILUtils.convertToHalRadioAccessFamily(networkTypesBitmask)); 390 } else { 391 mRadioProxy.setPreferredNetworkType(serial, networkTypesBitmask); 392 } 393 } 394 395 /** 396 * Call IRadioNetwork#setBandMode 397 * @param serial Serial number of request 398 * @param bandMode One of BM_*_BAND 399 * @throws RemoteException 400 */ setBandMode(int serial, int bandMode)401 public void setBandMode(int serial, int bandMode) throws RemoteException { 402 if (isEmpty()) return; 403 if (isAidl()) { 404 mNetworkProxy.setBandMode(serial, bandMode); 405 } else { 406 mRadioProxy.setBandMode(serial, bandMode); 407 } 408 } 409 410 /** 411 * Call IRadioNetwork#setBarringPassword 412 * @param serial Serial number of request 413 * @param facility Facility string code 414 * @param oldPassword Old password 415 * @param newPassword New password 416 * @throws RemoteException 417 */ setBarringPassword(int serial, String facility, String oldPassword, String newPassword)418 public void setBarringPassword(int serial, String facility, String oldPassword, 419 String newPassword) throws RemoteException { 420 if (isEmpty()) return; 421 if (isAidl()) { 422 mNetworkProxy.setBarringPassword(serial, facility, oldPassword, newPassword); 423 } else { 424 mRadioProxy.setBarringPassword(serial, facility, oldPassword, newPassword); 425 } 426 } 427 428 /** 429 * Call IRadioNetwork#setCdmaRoamingPreference 430 * @param serial Serial number of request 431 * @param cdmaRoamingType One of CDMA_RM_* 432 * @throws RemoteException 433 */ setCdmaRoamingPreference(int serial, int cdmaRoamingType)434 public void setCdmaRoamingPreference(int serial, int cdmaRoamingType) throws RemoteException { 435 if (isEmpty()) return; 436 if (isAidl()) { 437 mNetworkProxy.setCdmaRoamingPreference(serial, cdmaRoamingType); 438 } else { 439 mRadioProxy.setCdmaRoamingPreference(serial, cdmaRoamingType); 440 } 441 } 442 443 /** 444 * Call IRadioNetwork#setCellInfoListRate 445 * @param serial Serial number of request 446 * @param rate Minimum time in milliseconds to indicate time between unsolicited cellInfoList() 447 * @throws RemoteException 448 */ setCellInfoListRate(int serial, int rate)449 public void setCellInfoListRate(int serial, int rate) throws RemoteException { 450 if (isEmpty()) return; 451 if (isAidl()) { 452 mNetworkProxy.setCellInfoListRate(serial, rate); 453 } else { 454 mRadioProxy.setCellInfoListRate(serial, rate); 455 } 456 } 457 458 /** 459 * Call IRadioNetwork#setIndicationFilter 460 * @param serial Serial number of request 461 * @param filter Unsolicited response filter 462 * @throws RemoteException 463 */ setIndicationFilter(int serial, int filter)464 public void setIndicationFilter(int serial, int filter) throws RemoteException { 465 if (isEmpty()) return; 466 if (isAidl()) { 467 mNetworkProxy.setIndicationFilter(serial, filter & INDICATION_FILTERS_ALL_AIDL); 468 } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) { 469 ((android.hardware.radio.V1_5.IRadio) mRadioProxy).setIndicationFilter_1_5(serial, 470 filter & INDICATION_FILTERS_ALL_V1_5); 471 } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_2)) { 472 ((android.hardware.radio.V1_2.IRadio) mRadioProxy).setIndicationFilter_1_2(serial, 473 filter & INDICATION_FILTERS_ALL_V1_2); 474 } else { 475 mRadioProxy.setIndicationFilter(serial, filter & INDICATION_FILTERS_ALL_V1_0); 476 } 477 } 478 479 /** 480 * Call IRadioNetwork#setLinkCapacityReportingCriteria 481 * @param serial Serial number of request 482 * @param hysteresisMs A hysteresis time in milliseconds. A value of 0 disables hysteresis. 483 * @param hysteresisDlKbps An interval in kbps defining the required magnitude change between DL 484 * reports. A value of 0 disables hysteresis 485 * @param hysteresisUlKbps An interval in kbps defining the required magnitude change between UL 486 * reports. A value of 0 disables hysteresis 487 * @param thresholdsDlKbps An array of trigger thresholds in kbps for DL reports. A size of 0 488 * disables thresholds 489 * @param thresholdsUlKbps An array of trigger thresholds in kbps for UL reports. A size of 0 490 * disables thresholds 491 * @param ran RadioAccessNetwork for which to apply criteria 492 * @throws RemoteException 493 */ setLinkCapacityReportingCriteria(int serial, int hysteresisMs, int hysteresisDlKbps, int hysteresisUlKbps, int[] thresholdsDlKbps, int[] thresholdsUlKbps, int ran)494 public void setLinkCapacityReportingCriteria(int serial, int hysteresisMs, int hysteresisDlKbps, 495 int hysteresisUlKbps, int[] thresholdsDlKbps, int[] thresholdsUlKbps, int ran) 496 throws RemoteException { 497 if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_2)) return; 498 if (isAidl()) { 499 mNetworkProxy.setLinkCapacityReportingCriteria(serial, hysteresisMs, hysteresisDlKbps, 500 hysteresisUlKbps, thresholdsDlKbps, thresholdsUlKbps, 501 RILUtils.convertToHalAccessNetworkAidl(ran)); 502 } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) { 503 ((android.hardware.radio.V1_5.IRadio) mRadioProxy).setLinkCapacityReportingCriteria_1_5( 504 serial, hysteresisMs, hysteresisDlKbps, hysteresisUlKbps, 505 RILUtils.primitiveArrayToArrayList(thresholdsDlKbps), 506 RILUtils.primitiveArrayToArrayList(thresholdsUlKbps), 507 RILUtils.convertToHalAccessNetwork(ran)); 508 } else { 509 if (ran == AccessNetworkConstants.AccessNetworkType.NGRAN) { 510 throw new RuntimeException("NGRAN unsupported on IRadio version: " + mHalVersion); 511 } 512 ((android.hardware.radio.V1_2.IRadio) mRadioProxy).setLinkCapacityReportingCriteria( 513 serial, hysteresisMs, hysteresisDlKbps, hysteresisUlKbps, 514 RILUtils.primitiveArrayToArrayList(thresholdsDlKbps), 515 RILUtils.primitiveArrayToArrayList(thresholdsUlKbps), 516 RILUtils.convertToHalAccessNetwork(ran)); 517 } 518 } 519 520 /** 521 * Call IRadioNetwork#setLocationUpdates 522 * @param serial Serial number of request 523 * @param enable Whether to enable or disable network state change notifications when location 524 * information (lac and/or cid) has changed 525 * @throws RemoteException 526 */ setLocationUpdates(int serial, boolean enable)527 public void setLocationUpdates(int serial, boolean enable) throws RemoteException { 528 if (isEmpty()) return; 529 if (isAidl()) { 530 mNetworkProxy.setLocationUpdates(serial, enable); 531 } else { 532 mRadioProxy.setLocationUpdates(serial, enable); 533 } 534 } 535 536 /** 537 * Call IRadioNetwork#setNetworkSelectionModeAutomatic 538 * @param serial Serial number of request 539 * @throws RemoteException 540 */ setNetworkSelectionModeAutomatic(int serial)541 public void setNetworkSelectionModeAutomatic(int serial) throws RemoteException { 542 if (isEmpty()) return; 543 if (isAidl()) { 544 mNetworkProxy.setNetworkSelectionModeAutomatic(serial); 545 } else { 546 mRadioProxy.setNetworkSelectionModeAutomatic(serial); 547 } 548 } 549 550 /** 551 * Call IRadioNetwork#setNetworkSelectionModeManual 552 * @param serial Serial number of request 553 * @param operatorNumeric PLMN ID of the network to select 554 * @param ran Radio access network type 555 * @throws RemoteException 556 */ setNetworkSelectionModeManual(int serial, String operatorNumeric, int ran)557 public void setNetworkSelectionModeManual(int serial, String operatorNumeric, int ran) 558 throws RemoteException { 559 if (isEmpty()) return; 560 if (isAidl()) { 561 mNetworkProxy.setNetworkSelectionModeManual(serial, operatorNumeric, 562 RILUtils.convertToHalAccessNetworkAidl(ran)); 563 } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) { 564 ((android.hardware.radio.V1_5.IRadio) mRadioProxy).setNetworkSelectionModeManual_1_5( 565 serial, operatorNumeric, RILUtils.convertToHalRadioAccessNetworks(ran)); 566 } else { 567 mRadioProxy.setNetworkSelectionModeManual(serial, operatorNumeric); 568 } 569 } 570 571 /** 572 * Call IRadioNetwork#setNrDualConnectivityState 573 * @param serial Serial number of request 574 * @param nrDualConnectivityState Expected NR dual connectivity state 575 * @throws RemoteException 576 */ setNrDualConnectivityState(int serial, byte nrDualConnectivityState)577 public void setNrDualConnectivityState(int serial, byte nrDualConnectivityState) 578 throws RemoteException { 579 if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_6)) return; 580 if (isAidl()) { 581 mNetworkProxy.setNrDualConnectivityState(serial, nrDualConnectivityState); 582 } else { 583 ((android.hardware.radio.V1_6.IRadio) mRadioProxy).setNrDualConnectivityState( 584 serial, nrDualConnectivityState); 585 } 586 } 587 588 /** 589 * Call IRadioNetwork#setSignalStrengthReportingCriteria 590 * @param serial Serial number of request 591 * @param signalThresholdInfos a list of {@link SignalThresholdInfo} to set with. 592 * @throws RemoteException 593 */ setSignalStrengthReportingCriteria(int serial, @NonNull List<SignalThresholdInfo> signalThresholdInfos)594 public void setSignalStrengthReportingCriteria(int serial, 595 @NonNull List<SignalThresholdInfo> signalThresholdInfos) throws RemoteException { 596 if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_2)) return; 597 if (isAidl()) { 598 android.hardware.radio.network.SignalThresholdInfo[] halSignalThresholdsInfos = 599 new android.hardware.radio.network.SignalThresholdInfo[signalThresholdInfos.size()]; 600 for (int i = 0; i < signalThresholdInfos.size(); i++) { 601 halSignalThresholdsInfos[i] = RILUtils.convertToHalSignalThresholdInfoAidl( 602 signalThresholdInfos.get(i)); 603 } 604 mNetworkProxy.setSignalStrengthReportingCriteria(serial, halSignalThresholdsInfos); 605 } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) { 606 for (SignalThresholdInfo signalThresholdInfo : signalThresholdInfos) { 607 ((android.hardware.radio.V1_5.IRadio) mRadioProxy) 608 .setSignalStrengthReportingCriteria_1_5(serial, 609 RILUtils.convertToHalSignalThresholdInfo(signalThresholdInfo), 610 RILUtils.convertToHalAccessNetwork( 611 signalThresholdInfo.getRadioAccessNetworkType())); 612 } 613 } else { 614 for (SignalThresholdInfo signalThresholdInfo : signalThresholdInfos) { 615 ((android.hardware.radio.V1_2.IRadio) mRadioProxy) 616 .setSignalStrengthReportingCriteria(serial, 617 signalThresholdInfo.getHysteresisMs(), 618 signalThresholdInfo.getHysteresisDb(), 619 RILUtils.primitiveArrayToArrayList( 620 signalThresholdInfo.getThresholds()), 621 RILUtils.convertToHalAccessNetwork( 622 signalThresholdInfo.getRadioAccessNetworkType())); 623 } 624 } 625 } 626 627 /** 628 * Call IRadioNetwork#setSuppServiceNotifications 629 * @param serial Serial number of request 630 * @param enable True to enable notifications, false to disable 631 * @throws RemoteException 632 */ setSuppServiceNotifications(int serial, boolean enable)633 public void setSuppServiceNotifications(int serial, boolean enable) throws RemoteException { 634 if (isEmpty()) return; 635 if (isAidl()) { 636 mNetworkProxy.setSuppServiceNotifications(serial, enable); 637 } else { 638 mRadioProxy.setSuppServiceNotifications(serial, enable); 639 } 640 } 641 642 /** 643 * Call IRadioNetwork#setSystemSelectionChannels 644 * @param serial Serial number of request 645 * @param specifiers Which bands to scan 646 * @throws RemoteException 647 */ setSystemSelectionChannels(int serial, List<RadioAccessSpecifier> specifiers)648 public void setSystemSelectionChannels(int serial, List<RadioAccessSpecifier> specifiers) 649 throws RemoteException { 650 if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_3)) return; 651 if (isAidl()) { 652 mNetworkProxy.setSystemSelectionChannels(serial, !specifiers.isEmpty(), 653 specifiers.stream().map(RILUtils::convertToHalRadioAccessSpecifierAidl) 654 .toArray(android.hardware.radio.network.RadioAccessSpecifier[]::new)); 655 } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) { 656 ((android.hardware.radio.V1_5.IRadio) mRadioProxy).setSystemSelectionChannels_1_5( 657 serial, !specifiers.isEmpty(), specifiers.stream() 658 .map(RILUtils::convertToHalRadioAccessSpecifier15) 659 .collect(Collectors.toCollection(ArrayList::new))); 660 } else { 661 ((android.hardware.radio.V1_3.IRadio) mRadioProxy).setSystemSelectionChannels( 662 serial, !specifiers.isEmpty(), specifiers.stream() 663 .map(RILUtils::convertToHalRadioAccessSpecifier11) 664 .collect(Collectors.toCollection(ArrayList::new))); 665 } 666 } 667 668 /** 669 * Call IRadioNetwork#startNetworkScan 670 * @param serial Serial number of request 671 * @param request Defines the radio networks/bands/channels which need to be scanned 672 * @param overrideHalVersion Radio HAL fallback compatibility override 673 * @throws RemoteException 674 */ startNetworkScan(int serial, NetworkScanRequest request, HalVersion overrideHalVersion, Message result)675 public void startNetworkScan(int serial, NetworkScanRequest request, 676 HalVersion overrideHalVersion, Message result) throws RemoteException { 677 if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_1)) return; 678 if (isAidl()) { 679 android.hardware.radio.network.NetworkScanRequest halRequest = 680 new android.hardware.radio.network.NetworkScanRequest(); 681 halRequest.type = request.getScanType(); 682 halRequest.interval = request.getSearchPeriodicity(); 683 halRequest.maxSearchTime = request.getMaxSearchTime(); 684 halRequest.incrementalResultsPeriodicity = request.getIncrementalResultsPeriodicity(); 685 halRequest.incrementalResults = request.getIncrementalResults(); 686 halRequest.mccMncs = request.getPlmns().stream().toArray(String[]::new); 687 ArrayList<android.hardware.radio.network.RadioAccessSpecifier> specifiers = 688 new ArrayList<>(); 689 for (RadioAccessSpecifier ras : request.getSpecifiers()) { 690 android.hardware.radio.network.RadioAccessSpecifier rasInHalFormat = 691 RILUtils.convertToHalRadioAccessSpecifierAidl(ras); 692 if (rasInHalFormat == null) { 693 AsyncResult.forMessage(result, null, 694 CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED)); 695 result.sendToTarget(); 696 return; 697 } 698 specifiers.add(rasInHalFormat); 699 } 700 halRequest.specifiers = specifiers.stream().toArray( 701 android.hardware.radio.network.RadioAccessSpecifier[]::new); 702 mNetworkProxy.startNetworkScan(serial, halRequest); 703 } else if ((overrideHalVersion == null 704 || overrideHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) 705 && mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_5)) { 706 android.hardware.radio.V1_5.NetworkScanRequest halRequest = 707 new android.hardware.radio.V1_5.NetworkScanRequest(); 708 halRequest.type = request.getScanType(); 709 halRequest.interval = request.getSearchPeriodicity(); 710 halRequest.maxSearchTime = request.getMaxSearchTime(); 711 halRequest.incrementalResultsPeriodicity = request.getIncrementalResultsPeriodicity(); 712 halRequest.incrementalResults = request.getIncrementalResults(); 713 halRequest.mccMncs.addAll(request.getPlmns()); 714 for (RadioAccessSpecifier ras : request.getSpecifiers()) { 715 android.hardware.radio.V1_5.RadioAccessSpecifier rasInHalFormat = 716 RILUtils.convertToHalRadioAccessSpecifier15(ras); 717 if (rasInHalFormat == null) { 718 AsyncResult.forMessage(result, null, 719 CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED)); 720 result.sendToTarget(); 721 return; 722 } 723 halRequest.specifiers.add(rasInHalFormat); 724 } 725 ((android.hardware.radio.V1_5.IRadio) mRadioProxy).startNetworkScan_1_5( 726 serial, halRequest); 727 } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_2)) { 728 android.hardware.radio.V1_2.NetworkScanRequest halRequest = 729 new android.hardware.radio.V1_2.NetworkScanRequest(); 730 halRequest.type = request.getScanType(); 731 halRequest.interval = request.getSearchPeriodicity(); 732 halRequest.maxSearchTime = request.getMaxSearchTime(); 733 halRequest.incrementalResultsPeriodicity = request.getIncrementalResultsPeriodicity(); 734 halRequest.incrementalResults = request.getIncrementalResults(); 735 halRequest.mccMncs.addAll(request.getPlmns()); 736 737 for (RadioAccessSpecifier ras : request.getSpecifiers()) { 738 android.hardware.radio.V1_1.RadioAccessSpecifier rasInHalFormat = 739 RILUtils.convertToHalRadioAccessSpecifier11(ras); 740 if (rasInHalFormat == null) { 741 AsyncResult.forMessage(result, null, 742 CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED)); 743 result.sendToTarget(); 744 return; 745 } 746 halRequest.specifiers.add(rasInHalFormat); 747 } 748 749 if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_4)) { 750 ((android.hardware.radio.V1_4.IRadio) mRadioProxy).startNetworkScan_1_4( 751 serial, halRequest); 752 } else { 753 ((android.hardware.radio.V1_2.IRadio) mRadioProxy).startNetworkScan_1_2( 754 serial, halRequest); 755 } 756 } else { 757 android.hardware.radio.V1_1.NetworkScanRequest halRequest = 758 new android.hardware.radio.V1_1.NetworkScanRequest(); 759 halRequest.type = request.getScanType(); 760 halRequest.interval = request.getSearchPeriodicity(); 761 for (RadioAccessSpecifier ras : request.getSpecifiers()) { 762 android.hardware.radio.V1_1.RadioAccessSpecifier rasInHalFormat = 763 RILUtils.convertToHalRadioAccessSpecifier11(ras); 764 if (rasInHalFormat == null) { 765 AsyncResult.forMessage(result, null, 766 CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED)); 767 result.sendToTarget(); 768 return; 769 } 770 halRequest.specifiers.add(rasInHalFormat); 771 } 772 ((android.hardware.radio.V1_1.IRadio) mRadioProxy).startNetworkScan(serial, halRequest); 773 } 774 } 775 776 /** 777 * Call IRadioNetwork#stopNetworkScan 778 * @param serial Serial number of request 779 * @throws RemoteException 780 */ stopNetworkScan(int serial)781 public void stopNetworkScan(int serial) throws RemoteException { 782 if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_1)) return; 783 if (isAidl()) { 784 mNetworkProxy.stopNetworkScan(serial); 785 } else { 786 ((android.hardware.radio.V1_1.IRadio) mRadioProxy).stopNetworkScan(serial); 787 } 788 } 789 790 /** 791 * Call IRadioNetwork#supplyNetworkDepersonalization 792 * @param serial Serial number of request 793 * @param netPin Network depersonalization code 794 * @throws RemoteException 795 */ supplyNetworkDepersonalization(int serial, String netPin)796 public void supplyNetworkDepersonalization(int serial, String netPin) throws RemoteException { 797 if (isEmpty()) return; 798 if (isAidl()) { 799 mNetworkProxy.supplyNetworkDepersonalization(serial, netPin); 800 } else { 801 mRadioProxy.supplyNetworkDepersonalization(serial, netPin); 802 } 803 } 804 805 /** 806 * Call IRadioNetwork#getUsageSetting() 807 * @param serial Serial number of request 808 * @throws RemoteException 809 */ getUsageSetting(int serial)810 public void getUsageSetting(int serial) throws RemoteException { 811 if (isEmpty()) return; 812 if (isAidl()) { 813 mNetworkProxy.getUsageSetting(serial); 814 } 815 // Only supported on AIDL. 816 } 817 818 /** 819 * Call IRadioNetwork#setUsageSetting() 820 * @param serial Serial number of request 821 * @throws RemoteException 822 */ setUsageSetting(int serial, int usageSetting)823 public void setUsageSetting(int serial, 824 /* TelephonyManager.UsageSetting */ int usageSetting) throws RemoteException { 825 if (isEmpty()) return; 826 if (isAidl()) { 827 mNetworkProxy.setUsageSetting(serial, usageSetting); 828 } 829 // Only supported on AIDL. 830 } 831 } 832