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.os.AsyncResult; 22 import android.os.Message; 23 import android.os.RemoteException; 24 import android.telephony.CarrierRestrictionRules; 25 import android.telephony.ImsiEncryptionInfo; 26 import android.telephony.Rlog; 27 import android.telephony.TelephonyManager; 28 29 import com.android.internal.telephony.uicc.IccCardApplicationStatus.PersoSubState; 30 import com.android.internal.telephony.uicc.SimPhonebookRecord; 31 32 /** 33 * A holder for IRadioSim. Use getHidl to get IRadio 1.0 and call the HIDL implementations or 34 * getAidl to get IRadioSim and call the AIDL implementations of the HAL APIs. 35 */ 36 public class RadioSimProxy extends RadioServiceProxy { 37 private static final String TAG = "RadioSimProxy"; 38 private volatile android.hardware.radio.sim.IRadioSim mSimProxy = null; 39 40 /** 41 * Set IRadioSim as the AIDL implementation for RadioServiceProxy 42 * @param halVersion Radio HAL version 43 * @param sim IRadioSim implementation 44 * 45 * @return updated HAL version 46 */ setAidl(HalVersion halVersion, android.hardware.radio.sim.IRadioSim sim)47 public HalVersion setAidl(HalVersion halVersion, android.hardware.radio.sim.IRadioSim sim) { 48 HalVersion version = halVersion; 49 try { 50 version = RIL.getServiceHalVersion(sim.getInterfaceVersion()); 51 } catch (RemoteException e) { 52 Rlog.e(TAG, "setAidl: " + e); 53 } 54 mHalVersion = version; 55 mSimProxy = sim; 56 mIsAidl = true; 57 58 Rlog.d(TAG, "AIDL initialized mHalVersion=" + mHalVersion); 59 return mHalVersion; 60 } 61 62 /** 63 * Get the AIDL implementation of RadioSimProxy 64 * @return IRadioSim implementation 65 */ getAidl()66 public android.hardware.radio.sim.IRadioSim getAidl() { 67 return mSimProxy; 68 } 69 70 /** 71 * Reset RadioSimProxy 72 */ 73 @Override clear()74 public void clear() { 75 super.clear(); 76 mSimProxy = null; 77 } 78 79 /** 80 * Check whether a RadioSim implementation exists 81 * @return true if there is neither a HIDL nor AIDL implementation 82 */ 83 @Override isEmpty()84 public boolean isEmpty() { 85 return mRadioProxy == null && mSimProxy == null; 86 } 87 88 /** 89 * Call IRadioSim#areUiccApplicationsEnabled 90 * @param serial Serial number of request 91 * @throws RemoteException 92 */ areUiccApplicationsEnabled(int serial)93 public void areUiccApplicationsEnabled(int serial) throws RemoteException { 94 if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_5)) return; 95 if (isAidl()) { 96 mSimProxy.areUiccApplicationsEnabled(serial); 97 } else { 98 ((android.hardware.radio.V1_5.IRadio) mRadioProxy).areUiccApplicationsEnabled(serial); 99 } 100 } 101 102 /** 103 * Call IRadioSim#changeIccPin2ForApp 104 * @param serial Serial number of request 105 * @param oldPin2 Old PIN value 106 * @param newPin2 New PIN value 107 * @param aid Application ID 108 * @throws RemoteException 109 */ changeIccPin2ForApp(int serial, String oldPin2, String newPin2, String aid)110 public void changeIccPin2ForApp(int serial, String oldPin2, String newPin2, String aid) 111 throws RemoteException { 112 if (isEmpty()) return; 113 if (isAidl()) { 114 mSimProxy.changeIccPin2ForApp(serial, oldPin2, newPin2, aid); 115 } else { 116 mRadioProxy.changeIccPin2ForApp(serial, oldPin2, newPin2, aid); 117 } 118 } 119 120 /** 121 * Call IRadioSim#changeIccPinForApp 122 * @param serial Serial number of request 123 * @param oldPin Old PIN value 124 * @param newPin New PIN value 125 * @param aid Application ID 126 * @throws RemoteException 127 */ changeIccPinForApp(int serial, String oldPin, String newPin, String aid)128 public void changeIccPinForApp(int serial, String oldPin, String newPin, String aid) 129 throws RemoteException { 130 if (isEmpty()) return; 131 if (isAidl()) { 132 mSimProxy.changeIccPinForApp(serial, oldPin, newPin, aid); 133 } else { 134 mRadioProxy.changeIccPinForApp(serial, oldPin, newPin, aid); 135 } 136 } 137 138 /** 139 * Call IRadioSim#enableUiccApplications 140 * @param serial Serial number of request 141 * @param enable Whether or not to enable UiccApplications on the SIM 142 * @throws RemoteException 143 */ enableUiccApplications(int serial, boolean enable)144 public void enableUiccApplications(int serial, boolean enable) throws RemoteException { 145 if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_5)) return; 146 if (isAidl()) { 147 mSimProxy.enableUiccApplications(serial, enable); 148 } else { 149 ((android.hardware.radio.V1_5.IRadio) mRadioProxy).enableUiccApplications( 150 serial, enable); 151 } 152 } 153 154 /** 155 * Call IRadioSim#getAllowedCarriers 156 * @param serial Serial number of request 157 * @throws RemoteException 158 */ getAllowedCarriers(int serial)159 public void getAllowedCarriers(int serial) throws RemoteException { 160 if (isEmpty()) return; 161 if (isAidl()) { 162 mSimProxy.getAllowedCarriers(serial); 163 } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_4)) { 164 ((android.hardware.radio.V1_4.IRadio) mRadioProxy).getAllowedCarriers_1_4(serial); 165 } else { 166 mRadioProxy.getAllowedCarriers(serial); 167 } 168 } 169 170 /** 171 * Call IRadioSim#getCdmaSubscription 172 * @param serial Serial number of request 173 * @throws RemoteException 174 */ getCdmaSubscription(int serial)175 public void getCdmaSubscription(int serial) throws RemoteException { 176 if (isEmpty()) return; 177 if (isAidl()) { 178 mSimProxy.getCdmaSubscription(serial); 179 } else { 180 mRadioProxy.getCDMASubscription(serial); 181 } 182 } 183 184 /** 185 * Call IRadioSim#getCdmaSubscriptionSource 186 * @param serial Serial number of request 187 * @throws RemoteException 188 */ getCdmaSubscriptionSource(int serial)189 public void getCdmaSubscriptionSource(int serial) throws RemoteException { 190 if (isEmpty()) return; 191 if (isAidl()) { 192 mSimProxy.getCdmaSubscriptionSource(serial); 193 } else { 194 mRadioProxy.getCdmaSubscriptionSource(serial); 195 } 196 } 197 198 /** 199 * Call IRadioSim#getFacilityLockForApp 200 * @param serial Serial number of request 201 * @param facility One of CB_FACILTY_* 202 * @param password Password or "" if not required 203 * @param serviceClass Sum of SERVICE_CLASS_* 204 * @param appId Application ID or null if none 205 * @throws RemoteException 206 */ getFacilityLockForApp(int serial, String facility, String password, int serviceClass, String appId)207 public void getFacilityLockForApp(int serial, String facility, String password, 208 int serviceClass, String appId) throws RemoteException { 209 if (isEmpty()) return; 210 if (isAidl()) { 211 mSimProxy.getFacilityLockForApp(serial, facility, password, serviceClass, appId); 212 } else { 213 mRadioProxy.getFacilityLockForApp(serial, facility, password, serviceClass, appId); 214 } 215 } 216 217 /** 218 * Call IRadioSim#getIccCardStatus 219 * @param serial Serial number of request 220 * @throws RemoteException 221 */ getIccCardStatus(int serial)222 public void getIccCardStatus(int serial) throws RemoteException { 223 if (isEmpty()) return; 224 if (isAidl()) { 225 mSimProxy.getIccCardStatus(serial); 226 } else { 227 mRadioProxy.getIccCardStatus(serial); 228 } 229 } 230 231 /** 232 * Call IRadioSim#getImsiForApp 233 * @param serial Serial number of request 234 * @param aid Application ID 235 * @throws RemoteException 236 */ getImsiForApp(int serial, String aid)237 public void getImsiForApp(int serial, String aid) throws RemoteException { 238 if (isEmpty()) return; 239 if (isAidl()) { 240 mSimProxy.getImsiForApp(serial, aid); 241 } else { 242 mRadioProxy.getImsiForApp(serial, aid); 243 } 244 } 245 246 /** 247 * Call IRadioSim#getSimPhonebookCapacity 248 * @param serial Serial number of request 249 * @throws RemoteException 250 */ getSimPhonebookCapacity(int serial)251 public void getSimPhonebookCapacity(int serial) throws RemoteException { 252 if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_6)) return; 253 if (isAidl()) { 254 mSimProxy.getSimPhonebookCapacity(serial); 255 } else { 256 ((android.hardware.radio.V1_6.IRadio) mRadioProxy).getSimPhonebookCapacity(serial); 257 } 258 } 259 260 /** 261 * Call IRadioSim#getSimPhonebookRecords 262 * @param serial Serial number of request 263 * @throws RemoteException 264 */ getSimPhonebookRecords(int serial)265 public void getSimPhonebookRecords(int serial) throws RemoteException { 266 if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_6)) return; 267 if (isAidl()) { 268 mSimProxy.getSimPhonebookRecords(serial); 269 } else { 270 ((android.hardware.radio.V1_6.IRadio) mRadioProxy).getSimPhonebookRecords(serial); 271 } 272 } 273 274 /** 275 * Call IRadioSim#iccCloseLogicalChannelWithSessionInfo 276 * @param serial Serial number of request 277 * @param channelId Channel ID of the channel to be closed 278 * @param isEs10 Whether the logical channel is opened for performing ES10 operations. 279 * @throws RemoteException 280 */ iccCloseLogicalChannel(int serial, int channelId, boolean isEs10)281 public void iccCloseLogicalChannel(int serial, 282 int channelId, boolean isEs10) throws RemoteException { 283 if (isEmpty()) return; 284 if (isAidl()) { 285 if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_2_1)) { 286 android.hardware.radio.sim.SessionInfo info = 287 new android.hardware.radio.sim.SessionInfo(); 288 info.sessionId = channelId; 289 info.isEs10 = isEs10; 290 mSimProxy.iccCloseLogicalChannelWithSessionInfo(serial, info); 291 return; 292 } 293 mSimProxy.iccCloseLogicalChannel(serial, channelId); 294 } else { 295 mRadioProxy.iccCloseLogicalChannel(serial, channelId); 296 } 297 } 298 299 /** 300 * Call IRadioSim#iccIoForApp 301 * @param serial Serial number of request 302 * @param command Command 303 * @param fileId File ID 304 * @param path Path 305 * @param p1 P1 value of the command 306 * @param p2 P2 value of the command 307 * @param p3 P3 value of the command 308 * @param data Data to be sent 309 * @param pin2 PIN 2 value 310 * @param aid Application ID 311 * @throws RemoteException 312 */ iccIoForApp(int serial, int command, int fileId, String path, int p1, int p2, int p3, String data, String pin2, String aid)313 public void iccIoForApp(int serial, int command, int fileId, String path, int p1, int p2, 314 int p3, String data, String pin2, String aid) throws RemoteException { 315 if (isEmpty()) return; 316 if (isAidl()) { 317 android.hardware.radio.sim.IccIo iccIo = new android.hardware.radio.sim.IccIo(); 318 iccIo.command = command; 319 iccIo.fileId = fileId; 320 iccIo.path = path; 321 iccIo.p1 = p1; 322 iccIo.p2 = p2; 323 iccIo.p3 = p3; 324 iccIo.data = data; 325 iccIo.pin2 = pin2; 326 iccIo.aid = aid; 327 mSimProxy.iccIoForApp(serial, iccIo); 328 } else { 329 android.hardware.radio.V1_0.IccIo iccIo = new android.hardware.radio.V1_0.IccIo(); 330 iccIo.command = command; 331 iccIo.fileId = fileId; 332 iccIo.path = path; 333 iccIo.p1 = p1; 334 iccIo.p2 = p2; 335 iccIo.p3 = p3; 336 iccIo.data = data; 337 iccIo.pin2 = pin2; 338 iccIo.aid = aid; 339 mRadioProxy.iccIOForApp(serial, iccIo); 340 } 341 } 342 343 /** 344 * Call IRadioSim#iccOpenLogicalChannel 345 * @param serial Serial number of request 346 * @param aid Application ID 347 * @param p2 P2 value of the command 348 * @throws RemoteException 349 */ iccOpenLogicalChannel(int serial, String aid, int p2)350 public void iccOpenLogicalChannel(int serial, String aid, int p2) throws RemoteException { 351 if (isEmpty()) return; 352 if (isAidl()) { 353 mSimProxy.iccOpenLogicalChannel(serial, aid, p2); 354 } else { 355 mRadioProxy.iccOpenLogicalChannel(serial, aid, p2); 356 } 357 } 358 359 /** 360 * Call IRadioSim#iccTransmitApduBasicChannel 361 * @param serial Serial number of request 362 * @param cla Class of the command 363 * @param instruction Instruction of the command 364 * @param p1 P1 value of the command 365 * @param p2 P2 value of the command 366 * @param p3 P3 value of the command 367 * @param data Data to be sent 368 * @throws RemoteException 369 */ iccTransmitApduBasicChannel(int serial, int cla, int instruction, int p1, int p2, int p3, String data)370 public void iccTransmitApduBasicChannel(int serial, int cla, int instruction, int p1, int p2, 371 int p3, String data) throws RemoteException { 372 if (isEmpty()) return; 373 if (isAidl()) { 374 mSimProxy.iccTransmitApduBasicChannel(serial, 375 RILUtils.convertToHalSimApduAidl(0, cla, instruction, p1, p2, p3, data, 376 false, mHalVersion)); 377 } else { 378 mRadioProxy.iccTransmitApduBasicChannel(serial, 379 RILUtils.convertToHalSimApdu(0, cla, instruction, p1, p2, p3, data)); 380 } 381 } 382 383 /** 384 * Call IRadioSim#iccTransmitApduLogicalChannel 385 * @param serial Serial number of request 386 * @param channel Channel ID of the channel to use for communication 387 * @param cla Class of the command 388 * @param instruction Instruction of the command 389 * @param p1 P1 value of the command 390 * @param p2 P2 value of the command 391 * @param p3 P3 value of the command 392 * @param data Data to be sent 393 * @throws RemoteException 394 */ iccTransmitApduLogicalChannel(int serial, int channel, int cla, int instruction, int p1, int p2, int p3, String data)395 public void iccTransmitApduLogicalChannel(int serial, int channel, int cla, int instruction, 396 int p1, int p2, int p3, String data) throws RemoteException { 397 iccTransmitApduLogicalChannel(serial, channel, cla, instruction, p1, p2, p3, data, false); 398 } 399 400 /** 401 * Call IRadioSim#iccTransmitApduLogicalChannel 402 * @param serial Serial number of request 403 * @param channel Channel ID of the channel to use for communication 404 * @param cla Class of the command 405 * @param instruction Instruction of the command 406 * @param p1 P1 value of the command 407 * @param p2 P2 value of the command 408 * @param p3 P3 value of the command 409 * @param data Data to be sent 410 * @param isEs10Command APDU is an isEs10 command or not 411 * @throws RemoteException 412 */ iccTransmitApduLogicalChannel(int serial, int channel, int cla, int instruction, int p1, int p2, int p3, String data, boolean isEs10Command)413 public void iccTransmitApduLogicalChannel(int serial, int channel, int cla, int instruction, 414 int p1, int p2, int p3, String data, boolean isEs10Command) throws RemoteException { 415 if (isEmpty()) return; 416 if (isAidl()) { 417 mSimProxy.iccTransmitApduLogicalChannel(serial, 418 RILUtils.convertToHalSimApduAidl(channel, cla, instruction, p1, p2, p3, data, 419 isEs10Command, mHalVersion)); 420 } else { 421 mRadioProxy.iccTransmitApduLogicalChannel(serial, 422 RILUtils.convertToHalSimApdu(channel, cla, instruction, p1, p2, p3, data)); 423 } 424 } 425 426 /** 427 * Call IRadioSim#reportStkServiceIsRunning 428 * @param serial Serial number of request 429 * @throws RemoteException 430 */ reportStkServiceIsRunning(int serial)431 public void reportStkServiceIsRunning(int serial) throws RemoteException { 432 if (isEmpty()) return; 433 if (isAidl()) { 434 mSimProxy.reportStkServiceIsRunning(serial); 435 } else { 436 mRadioProxy.reportStkServiceIsRunning(serial); 437 } 438 } 439 440 /** 441 * Call IRadioSim#requestIccSimAuthentication 442 * @param serial Serial number of request 443 * @param authContext P2 parameter that specifies the authentication context 444 * @param authData Authentication challenge data 445 * @param aid Application ID of the application/slot to send the auth command to 446 * @throws RemoteException 447 */ requestIccSimAuthentication(int serial, int authContext, String authData, String aid)448 public void requestIccSimAuthentication(int serial, int authContext, String authData, 449 String aid) throws RemoteException { 450 if (isEmpty()) return; 451 if (isAidl()) { 452 mSimProxy.requestIccSimAuthentication(serial, authContext, authData, aid); 453 } else { 454 mRadioProxy.requestIccSimAuthentication(serial, authContext, authData, aid); 455 } 456 } 457 458 /** 459 * Call IRadioSim#responseAcknowledgement 460 * @throws RemoteException 461 */ 462 @Override responseAcknowledgement()463 public void responseAcknowledgement() throws RemoteException { 464 if (isEmpty()) return; 465 if (isAidl()) { 466 mSimProxy.responseAcknowledgement(); 467 } else { 468 mRadioProxy.responseAcknowledgement(); 469 } 470 } 471 472 /** 473 * Call IRadioSim#sendEnvelope 474 * @param serial Serial number of request 475 * @param contents String containing SAT/USAT response in hexadecimal format starting with 476 * command tag 477 * @throws RemoteException 478 */ sendEnvelope(int serial, String contents)479 public void sendEnvelope(int serial, String contents) throws RemoteException { 480 if (isEmpty()) return; 481 if (isAidl()) { 482 mSimProxy.sendEnvelope(serial, contents); 483 } else { 484 mRadioProxy.sendEnvelope(serial, contents); 485 } 486 } 487 488 /** 489 * Call IRadioSim#sendEnvelopeWithStatus 490 * @param serial Serial number of request 491 * @param contents String containing SAT/USAT response in hexadecimal format starting with 492 * command tag 493 * @throws RemoteException 494 */ sendEnvelopeWithStatus(int serial, String contents)495 public void sendEnvelopeWithStatus(int serial, String contents) throws RemoteException { 496 if (isEmpty()) return; 497 if (isAidl()) { 498 mSimProxy.sendEnvelopeWithStatus(serial, contents); 499 } else { 500 mRadioProxy.sendEnvelopeWithStatus(serial, contents); 501 } 502 } 503 504 /** 505 * Call IRadioSim#sendTerminalResponseToSim 506 * @param serial Serial number of request 507 * @param contents String containing SAT/USAT response in hexadecimal format starting with 508 * first byte of response data 509 * @throws RemoteException 510 */ sendTerminalResponseToSim(int serial, String contents)511 public void sendTerminalResponseToSim(int serial, String contents) throws RemoteException { 512 if (isEmpty()) return; 513 if (isAidl()) { 514 mSimProxy.sendTerminalResponseToSim(serial, contents); 515 } else { 516 mRadioProxy.sendTerminalResponseToSim(serial, contents); 517 } 518 } 519 520 /** 521 * Call IRadioSim#setAllowedCarriers 522 * @param serial Serial number of request 523 * @param carrierRestrictionRules Allowed carriers 524 * @param result Result to return in case of error 525 * @throws RemoteException 526 */ setAllowedCarriers(int serial, CarrierRestrictionRules carrierRestrictionRules, Message result)527 public void setAllowedCarriers(int serial, CarrierRestrictionRules carrierRestrictionRules, 528 Message result) throws RemoteException { 529 if (isEmpty()) return; 530 if (isAidl()) { 531 // Prepare structure with allowed list, excluded list and priority 532 android.hardware.radio.sim.CarrierRestrictions carrierRestrictions = 533 new android.hardware.radio.sim.CarrierRestrictions(); 534 carrierRestrictions.allowedCarriers = RILUtils.convertToHalCarrierRestrictionListAidl( 535 carrierRestrictionRules.getAllowedCarriers()); 536 carrierRestrictions.excludedCarriers = RILUtils.convertToHalCarrierRestrictionListAidl( 537 carrierRestrictionRules.getExcludedCarriers()); 538 carrierRestrictions.allowedCarriersPrioritized = 539 (carrierRestrictionRules.getDefaultCarrierRestriction() 540 == CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_NOT_ALLOWED); 541 mSimProxy.setAllowedCarriers(serial, carrierRestrictions, 542 RILUtils.convertToHalSimLockMultiSimPolicyAidl( 543 carrierRestrictionRules.getMultiSimPolicy())); 544 } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_4)) { 545 // Prepare structure with allowed list, excluded list and priority 546 android.hardware.radio.V1_4.CarrierRestrictionsWithPriority carrierRestrictions = 547 new android.hardware.radio.V1_4.CarrierRestrictionsWithPriority(); 548 carrierRestrictions.allowedCarriers = RILUtils.convertToHalCarrierRestrictionList( 549 carrierRestrictionRules.getAllowedCarriers()); 550 carrierRestrictions.excludedCarriers = RILUtils.convertToHalCarrierRestrictionList( 551 carrierRestrictionRules.getExcludedCarriers()); 552 carrierRestrictions.allowedCarriersPrioritized = 553 (carrierRestrictionRules.getDefaultCarrierRestriction() 554 == CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_NOT_ALLOWED); 555 ((android.hardware.radio.V1_4.IRadio) mRadioProxy).setAllowedCarriers_1_4( 556 serial, carrierRestrictions, RILUtils.convertToHalSimLockMultiSimPolicy( 557 carrierRestrictionRules.getMultiSimPolicy())); 558 } else { 559 boolean isAllCarriersAllowed = carrierRestrictionRules.isAllCarriersAllowed(); 560 boolean supported = (isAllCarriersAllowed 561 || (carrierRestrictionRules.getExcludedCarriers().isEmpty() 562 && (carrierRestrictionRules.getDefaultCarrierRestriction() 563 == CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_NOT_ALLOWED))) 564 && (RILUtils.convertToHalSimLockMultiSimPolicy( 565 carrierRestrictionRules.getMultiSimPolicy()) 566 == android.hardware.radio.V1_4.SimLockMultiSimPolicy.NO_MULTISIM_POLICY); 567 568 if (!supported) { 569 // Feature is not supported by IRadio interface 570 if (result != null) { 571 AsyncResult.forMessage(result, null, 572 CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED)); 573 result.sendToTarget(); 574 } 575 return; 576 } 577 578 // Prepare structure with allowed list 579 android.hardware.radio.V1_0.CarrierRestrictions carrierRestrictions = 580 new android.hardware.radio.V1_0.CarrierRestrictions(); 581 carrierRestrictions.allowedCarriers = RILUtils.convertToHalCarrierRestrictionList( 582 carrierRestrictionRules.getAllowedCarriers()); 583 mRadioProxy.setAllowedCarriers(serial, isAllCarriersAllowed, carrierRestrictions); 584 } 585 } 586 587 /** 588 * Call IRadioSim#setCarrierInfoForImsiEncryption 589 * @param serial Serial number of request 590 * @param imsiEncryptionInfo ImsiEncryptionInfo 591 * @throws RemoteException 592 */ setCarrierInfoForImsiEncryption(int serial, ImsiEncryptionInfo imsiEncryptionInfo)593 public void setCarrierInfoForImsiEncryption(int serial, ImsiEncryptionInfo imsiEncryptionInfo) 594 throws RemoteException { 595 if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_1)) return; 596 if (isAidl()) { 597 android.hardware.radio.sim.ImsiEncryptionInfo halImsiInfo = 598 new android.hardware.radio.sim.ImsiEncryptionInfo(); 599 halImsiInfo.mnc = imsiEncryptionInfo.getMnc(); 600 halImsiInfo.mcc = imsiEncryptionInfo.getMcc(); 601 halImsiInfo.keyIdentifier = imsiEncryptionInfo.getKeyIdentifier(); 602 if (imsiEncryptionInfo.getExpirationTime() != null) { 603 halImsiInfo.expirationTime = imsiEncryptionInfo.getExpirationTime().getTime(); 604 } 605 halImsiInfo.carrierKey = imsiEncryptionInfo.getPublicKey().getEncoded(); 606 halImsiInfo.keyType = (byte) imsiEncryptionInfo.getKeyType(); 607 608 mSimProxy.setCarrierInfoForImsiEncryption(serial, halImsiInfo); 609 } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) { 610 android.hardware.radio.V1_6.ImsiEncryptionInfo halImsiInfo = 611 new android.hardware.radio.V1_6.ImsiEncryptionInfo(); 612 halImsiInfo.base.mnc = imsiEncryptionInfo.getMnc(); 613 halImsiInfo.base.mcc = imsiEncryptionInfo.getMcc(); 614 halImsiInfo.base.keyIdentifier = imsiEncryptionInfo.getKeyIdentifier(); 615 if (imsiEncryptionInfo.getExpirationTime() != null) { 616 halImsiInfo.base.expirationTime = imsiEncryptionInfo.getExpirationTime().getTime(); 617 } 618 for (byte b : imsiEncryptionInfo.getPublicKey().getEncoded()) { 619 halImsiInfo.base.carrierKey.add(Byte.valueOf(b)); 620 } 621 halImsiInfo.keyType = (byte) imsiEncryptionInfo.getKeyType(); 622 623 ((android.hardware.radio.V1_6.IRadio) mRadioProxy).setCarrierInfoForImsiEncryption_1_6( 624 serial, halImsiInfo); 625 } else { 626 android.hardware.radio.V1_1.ImsiEncryptionInfo halImsiInfo = 627 new android.hardware.radio.V1_1.ImsiEncryptionInfo(); 628 halImsiInfo.mnc = imsiEncryptionInfo.getMnc(); 629 halImsiInfo.mcc = imsiEncryptionInfo.getMcc(); 630 halImsiInfo.keyIdentifier = imsiEncryptionInfo.getKeyIdentifier(); 631 if (imsiEncryptionInfo.getExpirationTime() != null) { 632 halImsiInfo.expirationTime = imsiEncryptionInfo.getExpirationTime().getTime(); 633 } 634 for (byte b : imsiEncryptionInfo.getPublicKey().getEncoded()) { 635 halImsiInfo.carrierKey.add(Byte.valueOf(b)); 636 } 637 638 ((android.hardware.radio.V1_1.IRadio) mRadioProxy).setCarrierInfoForImsiEncryption( 639 serial, halImsiInfo); 640 } 641 } 642 643 /** 644 * Call IRadioSim#setCdmaSubscriptionSource 645 * @param serial Serial number of request 646 * @param cdmaSub One of CDMA_SUBSCRIPTION_* 647 * @throws RemoteException 648 */ setCdmaSubscriptionSource(int serial, int cdmaSub)649 public void setCdmaSubscriptionSource(int serial, int cdmaSub) throws RemoteException { 650 if (isEmpty()) return; 651 if (isAidl()) { 652 mSimProxy.setCdmaSubscriptionSource(serial, cdmaSub); 653 } else { 654 mRadioProxy.setCdmaSubscriptionSource(serial, cdmaSub); 655 } 656 } 657 658 /** 659 * Call IRadioSim#setFacilityLockForApp 660 * @param serial Serial number of request 661 * @param facility One of CB_FACILTY_* 662 * @param lockState True means lock, false means unlock 663 * @param password Password or "" if not required 664 * @param serviceClass Sum of SERVICE_CLASS_* 665 * @param appId Application ID or null if none 666 * @throws RemoteException 667 */ setFacilityLockForApp(int serial, String facility, boolean lockState, String password, int serviceClass, String appId)668 public void setFacilityLockForApp(int serial, String facility, boolean lockState, 669 String password, int serviceClass, String appId) throws RemoteException { 670 if (isEmpty()) return; 671 if (isAidl()) { 672 mSimProxy.setFacilityLockForApp( 673 serial, facility, lockState, password, serviceClass, appId); 674 } else { 675 mRadioProxy.setFacilityLockForApp( 676 serial, facility, lockState, password, serviceClass, appId); 677 } 678 } 679 680 /** 681 * Call IRadioSim#setSimCardPower 682 * @param serial Serial number of request 683 * @param state SIM state (power down, power up, pass through) 684 * @param result Result to return in case of error 685 * @throws RemoteException 686 */ setSimCardPower(int serial, int state, Message result)687 public void setSimCardPower(int serial, int state, Message result) throws RemoteException { 688 if (isEmpty()) return; 689 if (isAidl()) { 690 mSimProxy.setSimCardPower(serial, state); 691 } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_6)) { 692 ((android.hardware.radio.V1_6.IRadio) mRadioProxy).setSimCardPower_1_6(serial, state); 693 } else if (mHalVersion.greaterOrEqual(RIL.RADIO_HAL_VERSION_1_1)) { 694 ((android.hardware.radio.V1_1.IRadio) mRadioProxy).setSimCardPower_1_1(serial, state); 695 } else { 696 switch (state) { 697 case TelephonyManager.CARD_POWER_DOWN: { 698 mRadioProxy.setSimCardPower(serial, false); 699 break; 700 } 701 case TelephonyManager.CARD_POWER_UP: { 702 mRadioProxy.setSimCardPower(serial, true); 703 break; 704 } 705 default: { 706 if (result != null) { 707 AsyncResult.forMessage(result, null, 708 CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED)); 709 result.sendToTarget(); 710 } 711 } 712 } 713 } 714 } 715 716 /** 717 * Call IRadioSim#setUiccSubscription 718 * @param serial Serial number of request 719 * @param slotId Slot ID 720 * @param appIndex Application index in the card 721 * @param subId Subscription ID 722 * @param subStatus Activation status; 1 = activate and 0 = deactivate 723 * @throws RemoteException 724 */ setUiccSubscription(int serial, int slotId, int appIndex, int subId, int subStatus)725 public void setUiccSubscription(int serial, int slotId, int appIndex, int subId, int subStatus) 726 throws RemoteException { 727 if (isEmpty()) return; 728 if (isAidl()) { 729 android.hardware.radio.sim.SelectUiccSub info = 730 new android.hardware.radio.sim.SelectUiccSub(); 731 info.slot = slotId; 732 info.appIndex = appIndex; 733 info.subType = subId; 734 info.actStatus = subStatus; 735 mSimProxy.setUiccSubscription(serial, info); 736 } else { 737 android.hardware.radio.V1_0.SelectUiccSub info = 738 new android.hardware.radio.V1_0.SelectUiccSub(); 739 info.slot = slotId; 740 info.appIndex = appIndex; 741 info.subType = subId; 742 info.actStatus = subStatus; 743 mRadioProxy.setUiccSubscription(serial, info); 744 } 745 } 746 747 /** 748 * Call IRadioSim#supplyIccPin2ForApp 749 * @param serial Serial number of request 750 * @param pin2 PIN 2 value 751 * @param aid Application ID 752 * @throws RemoteException 753 */ supplyIccPin2ForApp(int serial, String pin2, String aid)754 public void supplyIccPin2ForApp(int serial, String pin2, String aid) throws RemoteException { 755 if (isEmpty()) return; 756 if (isAidl()) { 757 mSimProxy.supplyIccPin2ForApp(serial, pin2, aid); 758 } else { 759 mRadioProxy.supplyIccPin2ForApp(serial, pin2, aid); 760 } 761 } 762 763 /** 764 * Call IRadioSim#supplyIccPinForApp 765 * @param serial Serial number of request 766 * @param pin PIN value 767 * @param aid Application ID 768 * @throws RemoteException 769 */ supplyIccPinForApp(int serial, String pin, String aid)770 public void supplyIccPinForApp(int serial, String pin, String aid) throws RemoteException { 771 if (isEmpty()) return; 772 if (isAidl()) { 773 mSimProxy.supplyIccPinForApp(serial, pin, aid); 774 } else { 775 mRadioProxy.supplyIccPinForApp(serial, pin, aid); 776 } 777 } 778 779 /** 780 * Call IRadioSim#supplyIccPuk2ForApp 781 * @param serial Serial number of request 782 * @param puk2 PUK 2 value 783 * @param pin2 PIN 2 value 784 * @param aid Application ID 785 * @throws RemoteException 786 */ supplyIccPuk2ForApp(int serial, String puk2, String pin2, String aid)787 public void supplyIccPuk2ForApp(int serial, String puk2, String pin2, String aid) 788 throws RemoteException { 789 if (isEmpty()) return; 790 if (isAidl()) { 791 mSimProxy.supplyIccPuk2ForApp(serial, puk2, pin2, aid); 792 } else { 793 mRadioProxy.supplyIccPuk2ForApp(serial, puk2, pin2, aid); 794 } 795 } 796 797 /** 798 * Call IRadioSim#supplyIccPukForApp 799 * @param serial Serial number of request 800 * @param puk PUK value 801 * @param pin PIN value 802 * @param aid Application ID 803 * @throws RemoteException 804 */ supplyIccPukForApp(int serial, String puk, String pin, String aid)805 public void supplyIccPukForApp(int serial, String puk, String pin, String aid) 806 throws RemoteException { 807 if (isEmpty()) return; 808 if (isAidl()) { 809 mSimProxy.supplyIccPukForApp(serial, puk, pin, aid); 810 } else { 811 mRadioProxy.supplyIccPukForApp(serial, puk, pin, aid); 812 } 813 } 814 815 /** 816 * Call IRadioSim#supplySimDepersonalization 817 * @param serial Serial number of request 818 * @param persoType SIM personalization type 819 * @param controlKey Unlock code for removing SIM personalization from this device 820 * @throws RemoteException 821 */ supplySimDepersonalization(int serial, PersoSubState persoType, String controlKey)822 public void supplySimDepersonalization(int serial, PersoSubState persoType, String controlKey) 823 throws RemoteException { 824 if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_5)) return; 825 if (isAidl()) { 826 mSimProxy.supplySimDepersonalization(serial, 827 RILUtils.convertToHalPersoTypeAidl(persoType), controlKey); 828 } else { 829 ((android.hardware.radio.V1_5.IRadio) mRadioProxy).supplySimDepersonalization(serial, 830 RILUtils.convertToHalPersoType(persoType), controlKey); 831 } 832 } 833 834 /** 835 * Call IRadioSim#updateSimPhonebookRecords 836 * @param serial Serial number of request 837 * @param recordInfo ADN record information to be updated 838 * @throws RemoteException 839 */ updateSimPhonebookRecords(int serial, SimPhonebookRecord recordInfo)840 public void updateSimPhonebookRecords(int serial, SimPhonebookRecord recordInfo) 841 throws RemoteException { 842 if (isEmpty() || mHalVersion.less(RIL.RADIO_HAL_VERSION_1_6)) return; 843 if (isAidl()) { 844 mSimProxy.updateSimPhonebookRecords(serial, 845 RILUtils.convertToHalPhonebookRecordInfoAidl(recordInfo)); 846 } else { 847 ((android.hardware.radio.V1_6.IRadio) mRadioProxy).updateSimPhonebookRecords(serial, 848 RILUtils.convertToHalPhonebookRecordInfo(recordInfo)); 849 } 850 } 851 } 852