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