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