1 /* 2 * Copyright (C) 2018 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 package android.telephony.euicc; 17 18 import android.annotation.CallbackExecutor; 19 import android.annotation.IntDef; 20 import android.annotation.Nullable; 21 import android.annotation.SystemApi; 22 import android.content.Context; 23 import android.os.RemoteException; 24 import android.os.ServiceManager; 25 import android.service.euicc.EuiccProfileInfo; 26 import android.util.Log; 27 28 import com.android.internal.telephony.euicc.IAuthenticateServerCallback; 29 import com.android.internal.telephony.euicc.ICancelSessionCallback; 30 import com.android.internal.telephony.euicc.IDeleteProfileCallback; 31 import com.android.internal.telephony.euicc.IDisableProfileCallback; 32 import com.android.internal.telephony.euicc.IEuiccCardController; 33 import com.android.internal.telephony.euicc.IGetAllProfilesCallback; 34 import com.android.internal.telephony.euicc.IGetDefaultSmdpAddressCallback; 35 import com.android.internal.telephony.euicc.IGetEuiccChallengeCallback; 36 import com.android.internal.telephony.euicc.IGetEuiccInfo1Callback; 37 import com.android.internal.telephony.euicc.IGetEuiccInfo2Callback; 38 import com.android.internal.telephony.euicc.IGetProfileCallback; 39 import com.android.internal.telephony.euicc.IGetRulesAuthTableCallback; 40 import com.android.internal.telephony.euicc.IGetSmdsAddressCallback; 41 import com.android.internal.telephony.euicc.IListNotificationsCallback; 42 import com.android.internal.telephony.euicc.ILoadBoundProfilePackageCallback; 43 import com.android.internal.telephony.euicc.IPrepareDownloadCallback; 44 import com.android.internal.telephony.euicc.IRemoveNotificationFromListCallback; 45 import com.android.internal.telephony.euicc.IResetMemoryCallback; 46 import com.android.internal.telephony.euicc.IRetrieveNotificationCallback; 47 import com.android.internal.telephony.euicc.IRetrieveNotificationListCallback; 48 import com.android.internal.telephony.euicc.ISetDefaultSmdpAddressCallback; 49 import com.android.internal.telephony.euicc.ISetNicknameCallback; 50 import com.android.internal.telephony.euicc.ISwitchToProfileCallback; 51 52 import java.lang.annotation.Retention; 53 import java.lang.annotation.RetentionPolicy; 54 import java.util.concurrent.Executor; 55 56 /** 57 * EuiccCardManager is the application interface to an eSIM card. 58 * @hide 59 */ 60 @SystemApi 61 public class EuiccCardManager { 62 private static final String TAG = "EuiccCardManager"; 63 64 /** Reason for canceling a profile download session */ 65 @Retention(RetentionPolicy.SOURCE) 66 @IntDef(prefix = { "CANCEL_REASON_" }, value = { 67 CANCEL_REASON_END_USER_REJECTED, 68 CANCEL_REASON_POSTPONED, 69 CANCEL_REASON_TIMEOUT, 70 CANCEL_REASON_PPR_NOT_ALLOWED 71 }) 72 /** @hide */ 73 public @interface CancelReason {} 74 75 /** 76 * The end user has rejected the download. The profile will be put into the error state and 77 * cannot be downloaded again without the operator's change. 78 */ 79 public static final int CANCEL_REASON_END_USER_REJECTED = 0; 80 81 /** The download has been postponed and can be restarted later. */ 82 public static final int CANCEL_REASON_POSTPONED = 1; 83 84 /** The download has been timed out and can be restarted later. */ 85 public static final int CANCEL_REASON_TIMEOUT = 2; 86 87 /** 88 * The profile to be downloaded cannot be installed due to its policy rule is not allowed by 89 * the RAT (Rules Authorisation Table) on the eUICC or by other installed profiles. The 90 * download can be restarted later. 91 */ 92 public static final int CANCEL_REASON_PPR_NOT_ALLOWED = 3; 93 94 /** Options for resetting eUICC memory */ 95 @Retention(RetentionPolicy.SOURCE) 96 @IntDef(flag = true, prefix = { "RESET_OPTION_" }, value = { 97 RESET_OPTION_DELETE_OPERATIONAL_PROFILES, 98 RESET_OPTION_DELETE_FIELD_LOADED_TEST_PROFILES, 99 RESET_OPTION_RESET_DEFAULT_SMDP_ADDRESS 100 }) 101 /** @hide */ 102 public @interface ResetOption {} 103 104 /** Deletes all operational profiles. */ 105 public static final int RESET_OPTION_DELETE_OPERATIONAL_PROFILES = 1; 106 107 /** Deletes all field-loaded testing profiles. */ 108 public static final int RESET_OPTION_DELETE_FIELD_LOADED_TEST_PROFILES = 1 << 1; 109 110 /** Resets the default SM-DP+ address. */ 111 public static final int RESET_OPTION_RESET_DEFAULT_SMDP_ADDRESS = 1 << 2; 112 113 /** Result code of execution with no error. */ 114 public static final int RESULT_OK = 0; 115 116 /** Result code of an unknown error. */ 117 public static final int RESULT_UNKNOWN_ERROR = -1; 118 119 /** Result code when the eUICC card with the given card Id is not found. */ 120 public static final int RESULT_EUICC_NOT_FOUND = -2; 121 122 /** Result code indicating the caller is not the active LPA. */ 123 public static final int RESULT_CALLER_NOT_ALLOWED = -3; 124 125 /** 126 * Callback to receive the result of an eUICC card API. 127 * 128 * @param <T> Type of the result. 129 */ 130 public interface ResultCallback<T> { 131 /** 132 * This method will be called when an eUICC card API call is completed. 133 * 134 * @param resultCode This can be {@link #RESULT_OK} or other positive values returned by the 135 * eUICC. 136 * @param result The result object. It can be null if the {@code resultCode} is not 137 * {@link #RESULT_OK}. 138 */ onComplete(int resultCode, T result)139 void onComplete(int resultCode, T result); 140 } 141 142 private final Context mContext; 143 144 /** @hide */ EuiccCardManager(Context context)145 public EuiccCardManager(Context context) { 146 mContext = context; 147 } 148 getIEuiccCardController()149 private IEuiccCardController getIEuiccCardController() { 150 return IEuiccCardController.Stub.asInterface( 151 ServiceManager.getService("euicc_card_controller")); 152 } 153 154 /** 155 * Requests all the profiles on eUicc. 156 * 157 * @param cardId The Id of the eUICC. 158 * @param executor The executor through which the callback should be invoked. 159 * @param callback The callback to get the result code and all the profiles. 160 */ requestAllProfiles(String cardId, @CallbackExecutor Executor executor, ResultCallback<EuiccProfileInfo[]> callback)161 public void requestAllProfiles(String cardId, @CallbackExecutor Executor executor, 162 ResultCallback<EuiccProfileInfo[]> callback) { 163 try { 164 getIEuiccCardController().getAllProfiles(mContext.getOpPackageName(), cardId, 165 new IGetAllProfilesCallback.Stub() { 166 @Override 167 public void onComplete(int resultCode, EuiccProfileInfo[] profiles) { 168 executor.execute(() -> callback.onComplete(resultCode, profiles)); 169 } 170 }); 171 } catch (RemoteException e) { 172 Log.e(TAG, "Error calling getAllProfiles", e); 173 throw e.rethrowFromSystemServer(); 174 } 175 } 176 177 /** 178 * Requests the profile of the given iccid. 179 * 180 * @param cardId The Id of the eUICC. 181 * @param iccid The iccid of the profile. 182 * @param executor The executor through which the callback should be invoked. 183 * @param callback The callback to get the result code and profile. 184 */ requestProfile(String cardId, String iccid, @CallbackExecutor Executor executor, ResultCallback<EuiccProfileInfo> callback)185 public void requestProfile(String cardId, String iccid, @CallbackExecutor Executor executor, 186 ResultCallback<EuiccProfileInfo> callback) { 187 try { 188 getIEuiccCardController().getProfile(mContext.getOpPackageName(), cardId, iccid, 189 new IGetProfileCallback.Stub() { 190 @Override 191 public void onComplete(int resultCode, EuiccProfileInfo profile) { 192 executor.execute(() -> callback.onComplete(resultCode, profile)); 193 } 194 }); 195 } catch (RemoteException e) { 196 Log.e(TAG, "Error calling getProfile", e); 197 throw e.rethrowFromSystemServer(); 198 } 199 } 200 201 /** 202 * Disables the profile of the given iccid. 203 * 204 * @param cardId The Id of the eUICC. 205 * @param iccid The iccid of the profile. 206 * @param refresh Whether sending the REFRESH command to modem. 207 * @param executor The executor through which the callback should be invoked. 208 * @param callback The callback to get the result code. 209 */ disableProfile(String cardId, String iccid, boolean refresh, @CallbackExecutor Executor executor, ResultCallback<Void> callback)210 public void disableProfile(String cardId, String iccid, boolean refresh, 211 @CallbackExecutor Executor executor, ResultCallback<Void> callback) { 212 try { 213 getIEuiccCardController().disableProfile(mContext.getOpPackageName(), cardId, iccid, 214 refresh, new IDisableProfileCallback.Stub() { 215 @Override 216 public void onComplete(int resultCode) { 217 executor.execute(() -> callback.onComplete(resultCode, null)); 218 } 219 }); 220 } catch (RemoteException e) { 221 Log.e(TAG, "Error calling disableProfile", e); 222 throw e.rethrowFromSystemServer(); 223 } 224 } 225 226 /** 227 * Switches from the current profile to another profile. The current profile will be disabled 228 * and the specified profile will be enabled. 229 * 230 * @param cardId The Id of the eUICC. 231 * @param iccid The iccid of the profile to switch to. 232 * @param refresh Whether sending the REFRESH command to modem. 233 * @param executor The executor through which the callback should be invoked. 234 * @param callback The callback to get the result code and the EuiccProfileInfo enabled. 235 */ switchToProfile(String cardId, String iccid, boolean refresh, @CallbackExecutor Executor executor, ResultCallback<EuiccProfileInfo> callback)236 public void switchToProfile(String cardId, String iccid, boolean refresh, 237 @CallbackExecutor Executor executor, ResultCallback<EuiccProfileInfo> callback) { 238 try { 239 getIEuiccCardController().switchToProfile(mContext.getOpPackageName(), cardId, iccid, 240 refresh, new ISwitchToProfileCallback.Stub() { 241 @Override 242 public void onComplete(int resultCode, EuiccProfileInfo profile) { 243 executor.execute(() -> callback.onComplete(resultCode, profile)); 244 } 245 }); 246 } catch (RemoteException e) { 247 Log.e(TAG, "Error calling switchToProfile", e); 248 throw e.rethrowFromSystemServer(); 249 } 250 } 251 252 /** 253 * Sets the nickname of the profile of the given iccid. 254 * 255 * @param cardId The Id of the eUICC. 256 * @param iccid The iccid of the profile. 257 * @param nickname The nickname of the profile. 258 * @param executor The executor through which the callback should be invoked. 259 * @param callback The callback to get the result code. 260 */ setNickname(String cardId, String iccid, String nickname, @CallbackExecutor Executor executor, ResultCallback<Void> callback)261 public void setNickname(String cardId, String iccid, String nickname, 262 @CallbackExecutor Executor executor, ResultCallback<Void> callback) { 263 try { 264 getIEuiccCardController().setNickname(mContext.getOpPackageName(), cardId, iccid, 265 nickname, new ISetNicknameCallback.Stub() { 266 @Override 267 public void onComplete(int resultCode) { 268 executor.execute(() -> callback.onComplete(resultCode, null)); 269 } 270 }); 271 } catch (RemoteException e) { 272 Log.e(TAG, "Error calling setNickname", e); 273 throw e.rethrowFromSystemServer(); 274 } 275 } 276 277 /** 278 * Deletes the profile of the given iccid from eUICC. 279 * 280 * @param cardId The Id of the eUICC. 281 * @param iccid The iccid of the profile. 282 * @param executor The executor through which the callback should be invoked. 283 * @param callback The callback to get the result code. 284 */ deleteProfile(String cardId, String iccid, @CallbackExecutor Executor executor, ResultCallback<Void> callback)285 public void deleteProfile(String cardId, String iccid, @CallbackExecutor Executor executor, 286 ResultCallback<Void> callback) { 287 try { 288 getIEuiccCardController().deleteProfile(mContext.getOpPackageName(), cardId, iccid, 289 new IDeleteProfileCallback.Stub() { 290 @Override 291 public void onComplete(int resultCode) { 292 executor.execute(() -> callback.onComplete(resultCode, null)); 293 } 294 }); 295 } catch (RemoteException e) { 296 Log.e(TAG, "Error calling deleteProfile", e); 297 throw e.rethrowFromSystemServer(); 298 } 299 } 300 301 /** 302 * Resets the eUICC memory. 303 * 304 * @param cardId The Id of the eUICC. 305 * @param options Bits of the options of resetting which parts of the eUICC memory. See 306 * EuiccCard for details. 307 * @param executor The executor through which the callback should be invoked. 308 * @param callback The callback to get the result code. 309 */ resetMemory(String cardId, @ResetOption int options, @CallbackExecutor Executor executor, ResultCallback<Void> callback)310 public void resetMemory(String cardId, @ResetOption int options, 311 @CallbackExecutor Executor executor, ResultCallback<Void> callback) { 312 try { 313 getIEuiccCardController().resetMemory(mContext.getOpPackageName(), cardId, options, 314 new IResetMemoryCallback.Stub() { 315 @Override 316 public void onComplete(int resultCode) { 317 executor.execute(() -> callback.onComplete(resultCode, null)); 318 } 319 }); 320 } catch (RemoteException e) { 321 Log.e(TAG, "Error calling resetMemory", e); 322 throw e.rethrowFromSystemServer(); 323 } 324 } 325 326 /** 327 * Requests the default SM-DP+ address from eUICC. 328 * 329 * @param cardId The Id of the eUICC. 330 * @param executor The executor through which the callback should be invoked. 331 * @param callback The callback to get the result code and the default SM-DP+ address. 332 */ requestDefaultSmdpAddress(String cardId, @CallbackExecutor Executor executor, ResultCallback<String> callback)333 public void requestDefaultSmdpAddress(String cardId, @CallbackExecutor Executor executor, 334 ResultCallback<String> callback) { 335 try { 336 getIEuiccCardController().getDefaultSmdpAddress(mContext.getOpPackageName(), cardId, 337 new IGetDefaultSmdpAddressCallback.Stub() { 338 @Override 339 public void onComplete(int resultCode, String address) { 340 executor.execute(() -> callback.onComplete(resultCode, address)); 341 } 342 }); 343 } catch (RemoteException e) { 344 Log.e(TAG, "Error calling getDefaultSmdpAddress", e); 345 throw e.rethrowFromSystemServer(); 346 } 347 } 348 349 /** 350 * Requests the SM-DS address from eUICC. 351 * 352 * @param cardId The Id of the eUICC. 353 * @param executor The executor through which the callback should be invoked. 354 * @param callback The callback to get the result code and the SM-DS address. 355 */ requestSmdsAddress(String cardId, @CallbackExecutor Executor executor, ResultCallback<String> callback)356 public void requestSmdsAddress(String cardId, @CallbackExecutor Executor executor, 357 ResultCallback<String> callback) { 358 try { 359 getIEuiccCardController().getSmdsAddress(mContext.getOpPackageName(), cardId, 360 new IGetSmdsAddressCallback.Stub() { 361 @Override 362 public void onComplete(int resultCode, String address) { 363 executor.execute(() -> callback.onComplete(resultCode, address)); 364 } 365 }); 366 } catch (RemoteException e) { 367 Log.e(TAG, "Error calling getSmdsAddress", e); 368 throw e.rethrowFromSystemServer(); 369 } 370 } 371 372 /** 373 * Sets the default SM-DP+ address of eUICC. 374 * 375 * @param cardId The Id of the eUICC. 376 * @param defaultSmdpAddress The default SM-DP+ address to set. 377 * @param executor The executor through which the callback should be invoked. 378 * @param callback The callback to get the result code. 379 */ setDefaultSmdpAddress(String cardId, String defaultSmdpAddress, @CallbackExecutor Executor executor, ResultCallback<Void> callback)380 public void setDefaultSmdpAddress(String cardId, String defaultSmdpAddress, 381 @CallbackExecutor Executor executor, ResultCallback<Void> callback) { 382 try { 383 getIEuiccCardController().setDefaultSmdpAddress(mContext.getOpPackageName(), cardId, 384 defaultSmdpAddress, 385 new ISetDefaultSmdpAddressCallback.Stub() { 386 @Override 387 public void onComplete(int resultCode) { 388 executor.execute(() -> callback.onComplete(resultCode, null)); 389 } 390 }); 391 } catch (RemoteException e) { 392 Log.e(TAG, "Error calling setDefaultSmdpAddress", e); 393 throw e.rethrowFromSystemServer(); 394 } 395 } 396 397 /** 398 * Requests Rules Authorisation Table. 399 * 400 * @param cardId The Id of the eUICC. 401 * @param executor The executor through which the callback should be invoked. 402 * @param callback the callback to get the result code and the rule authorisation table. 403 */ requestRulesAuthTable(String cardId, @CallbackExecutor Executor executor, ResultCallback<EuiccRulesAuthTable> callback)404 public void requestRulesAuthTable(String cardId, @CallbackExecutor Executor executor, 405 ResultCallback<EuiccRulesAuthTable> callback) { 406 try { 407 getIEuiccCardController().getRulesAuthTable(mContext.getOpPackageName(), cardId, 408 new IGetRulesAuthTableCallback.Stub() { 409 @Override 410 public void onComplete(int resultCode, EuiccRulesAuthTable rat) { 411 executor.execute(() -> callback.onComplete(resultCode, rat)); 412 } 413 }); 414 } catch (RemoteException e) { 415 Log.e(TAG, "Error calling getRulesAuthTable", e); 416 throw e.rethrowFromSystemServer(); 417 } 418 } 419 420 /** 421 * Requests the eUICC challenge for new profile downloading. 422 * 423 * @param cardId The Id of the eUICC. 424 * @param executor The executor through which the callback should be invoked. 425 * @param callback the callback to get the result code and the challenge. 426 */ requestEuiccChallenge(String cardId, @CallbackExecutor Executor executor, ResultCallback<byte[]> callback)427 public void requestEuiccChallenge(String cardId, @CallbackExecutor Executor executor, 428 ResultCallback<byte[]> callback) { 429 try { 430 getIEuiccCardController().getEuiccChallenge(mContext.getOpPackageName(), cardId, 431 new IGetEuiccChallengeCallback.Stub() { 432 @Override 433 public void onComplete(int resultCode, byte[] challenge) { 434 executor.execute(() -> callback.onComplete(resultCode, challenge)); 435 } 436 }); 437 } catch (RemoteException e) { 438 Log.e(TAG, "Error calling getEuiccChallenge", e); 439 throw e.rethrowFromSystemServer(); 440 } 441 } 442 443 /** 444 * Requests the eUICC info1 defined in GSMA RSP v2.0+ for new profile downloading. 445 * 446 * @param cardId The Id of the eUICC. 447 * @param executor The executor through which the callback should be invoked. 448 * @param callback the callback to get the result code and the info1. 449 */ requestEuiccInfo1(String cardId, @CallbackExecutor Executor executor, ResultCallback<byte[]> callback)450 public void requestEuiccInfo1(String cardId, @CallbackExecutor Executor executor, 451 ResultCallback<byte[]> callback) { 452 try { 453 getIEuiccCardController().getEuiccInfo1(mContext.getOpPackageName(), cardId, 454 new IGetEuiccInfo1Callback.Stub() { 455 @Override 456 public void onComplete(int resultCode, byte[] info) { 457 executor.execute(() -> callback.onComplete(resultCode, info)); 458 } 459 }); 460 } catch (RemoteException e) { 461 Log.e(TAG, "Error calling getEuiccInfo1", e); 462 throw e.rethrowFromSystemServer(); 463 } 464 } 465 466 /** 467 * Gets the eUICC info2 defined in GSMA RSP v2.0+ for new profile downloading. 468 * 469 * @param cardId The Id of the eUICC. 470 * @param executor The executor through which the callback should be invoked. 471 * @param callback the callback to get the result code and the info2. 472 */ requestEuiccInfo2(String cardId, @CallbackExecutor Executor executor, ResultCallback<byte[]> callback)473 public void requestEuiccInfo2(String cardId, @CallbackExecutor Executor executor, 474 ResultCallback<byte[]> callback) { 475 try { 476 getIEuiccCardController().getEuiccInfo2(mContext.getOpPackageName(), cardId, 477 new IGetEuiccInfo2Callback.Stub() { 478 @Override 479 public void onComplete(int resultCode, byte[] info) { 480 executor.execute(() -> callback.onComplete(resultCode, info)); 481 } 482 }); 483 } catch (RemoteException e) { 484 Log.e(TAG, "Error calling getEuiccInfo2", e); 485 throw e.rethrowFromSystemServer(); 486 } 487 } 488 489 /** 490 * Authenticates the SM-DP+ server by the eUICC. 491 * 492 * @param cardId The Id of the eUICC. 493 * @param matchingId the activation code token defined in GSMA RSP v2.0+ or empty when it is not 494 * required. 495 * @param serverSigned1 ASN.1 data in byte array signed and returned by the SM-DP+ server. 496 * @param serverSignature1 ASN.1 data in byte array indicating a SM-DP+ signature which is 497 * returned by SM-DP+ server. 498 * @param euiccCiPkIdToBeUsed ASN.1 data in byte array indicating CI Public Key Identifier to be 499 * used by the eUICC for signature which is returned by SM-DP+ server. This is defined in 500 * GSMA RSP v2.0+. 501 * @param serverCertificate ASN.1 data in byte array indicating SM-DP+ Certificate returned by 502 * SM-DP+ server. 503 * @param executor The executor through which the callback should be invoked. 504 * @param callback the callback to get the result code and a byte array which represents a 505 * {@code AuthenticateServerResponse} defined in GSMA RSP v2.0+. 506 */ authenticateServer(String cardId, String matchingId, byte[] serverSigned1, byte[] serverSignature1, byte[] euiccCiPkIdToBeUsed, byte[] serverCertificate, @CallbackExecutor Executor executor, ResultCallback<byte[]> callback)507 public void authenticateServer(String cardId, String matchingId, byte[] serverSigned1, 508 byte[] serverSignature1, byte[] euiccCiPkIdToBeUsed, byte[] serverCertificate, 509 @CallbackExecutor Executor executor, ResultCallback<byte[]> callback) { 510 try { 511 getIEuiccCardController().authenticateServer( 512 mContext.getOpPackageName(), 513 cardId, 514 matchingId, 515 serverSigned1, 516 serverSignature1, 517 euiccCiPkIdToBeUsed, 518 serverCertificate, 519 new IAuthenticateServerCallback.Stub() { 520 @Override 521 public void onComplete(int resultCode, byte[] response) { 522 executor.execute(() -> callback.onComplete(resultCode, response)); 523 } 524 }); 525 } catch (RemoteException e) { 526 Log.e(TAG, "Error calling authenticateServer", e); 527 throw e.rethrowFromSystemServer(); 528 } 529 } 530 531 /** 532 * Prepares the profile download request sent to SM-DP+. 533 * 534 * @param cardId The Id of the eUICC. 535 * @param hashCc the hash of confirmation code. It can be null if there is no confirmation code 536 * required. 537 * @param smdpSigned2 ASN.1 data in byte array indicating the data to be signed by the SM-DP+ 538 * returned by SM-DP+ server. 539 * @param smdpSignature2 ASN.1 data in byte array indicating the SM-DP+ signature returned by 540 * SM-DP+ server. 541 * @param smdpCertificate ASN.1 data in byte array indicating the SM-DP+ Certificate returned 542 * by SM-DP+ server. 543 * @param executor The executor through which the callback should be invoked. 544 * @param callback the callback to get the result code and a byte array which represents a 545 * {@code PrepareDownloadResponse} defined in GSMA RSP v2.0+ 546 */ prepareDownload(String cardId, @Nullable byte[] hashCc, byte[] smdpSigned2, byte[] smdpSignature2, byte[] smdpCertificate, @CallbackExecutor Executor executor, ResultCallback<byte[]> callback)547 public void prepareDownload(String cardId, @Nullable byte[] hashCc, byte[] smdpSigned2, 548 byte[] smdpSignature2, byte[] smdpCertificate, @CallbackExecutor Executor executor, 549 ResultCallback<byte[]> callback) { 550 try { 551 getIEuiccCardController().prepareDownload( 552 mContext.getOpPackageName(), 553 cardId, 554 hashCc, 555 smdpSigned2, 556 smdpSignature2, 557 smdpCertificate, 558 new IPrepareDownloadCallback.Stub() { 559 @Override 560 public void onComplete(int resultCode, byte[] response) { 561 executor.execute(() -> callback.onComplete(resultCode, response)); 562 } 563 }); 564 } catch (RemoteException e) { 565 Log.e(TAG, "Error calling prepareDownload", e); 566 throw e.rethrowFromSystemServer(); 567 } 568 } 569 570 /** 571 * Loads a downloaded bound profile package onto the eUICC. 572 * 573 * @param cardId The Id of the eUICC. 574 * @param boundProfilePackage the Bound Profile Package data returned by SM-DP+ server. 575 * @param executor The executor through which the callback should be invoked. 576 * @param callback the callback to get the result code and a byte array which represents a 577 * {@code LoadBoundProfilePackageResponse} defined in GSMA RSP v2.0+. 578 */ loadBoundProfilePackage(String cardId, byte[] boundProfilePackage, @CallbackExecutor Executor executor, ResultCallback<byte[]> callback)579 public void loadBoundProfilePackage(String cardId, byte[] boundProfilePackage, 580 @CallbackExecutor Executor executor, ResultCallback<byte[]> callback) { 581 try { 582 getIEuiccCardController().loadBoundProfilePackage( 583 mContext.getOpPackageName(), 584 cardId, 585 boundProfilePackage, 586 new ILoadBoundProfilePackageCallback.Stub() { 587 @Override 588 public void onComplete(int resultCode, byte[] response) { 589 executor.execute(() -> callback.onComplete(resultCode, response)); 590 } 591 }); 592 } catch (RemoteException e) { 593 Log.e(TAG, "Error calling loadBoundProfilePackage", e); 594 throw e.rethrowFromSystemServer(); 595 } 596 } 597 598 /** 599 * Cancels the current profile download session. 600 * 601 * @param cardId The Id of the eUICC. 602 * @param transactionId the transaction ID returned by SM-DP+ server. 603 * @param reason the cancel reason. 604 * @param executor The executor through which the callback should be invoked. 605 * @param callback the callback to get the result code and an byte[] which represents a 606 * {@code CancelSessionResponse} defined in GSMA RSP v2.0+. 607 */ cancelSession(String cardId, byte[] transactionId, @CancelReason int reason, @CallbackExecutor Executor executor, ResultCallback<byte[]> callback)608 public void cancelSession(String cardId, byte[] transactionId, @CancelReason int reason, 609 @CallbackExecutor Executor executor, ResultCallback<byte[]> callback) { 610 try { 611 getIEuiccCardController().cancelSession( 612 mContext.getOpPackageName(), 613 cardId, 614 transactionId, 615 reason, 616 new ICancelSessionCallback.Stub() { 617 @Override 618 public void onComplete(int resultCode, byte[] response) { 619 executor.execute(() -> callback.onComplete(resultCode, response)); 620 } 621 }); 622 } catch (RemoteException e) { 623 Log.e(TAG, "Error calling cancelSession", e); 624 throw e.rethrowFromSystemServer(); 625 } 626 } 627 628 /** 629 * Lists all notifications of the given {@code events}. 630 * 631 * @param cardId The Id of the eUICC. 632 * @param events bits of the event types ({@link EuiccNotification.Event}) to list. 633 * @param executor The executor through which the callback should be invoked. 634 * @param callback the callback to get the result code and the list of notifications. 635 */ listNotifications(String cardId, @EuiccNotification.Event int events, @CallbackExecutor Executor executor, ResultCallback<EuiccNotification[]> callback)636 public void listNotifications(String cardId, @EuiccNotification.Event int events, 637 @CallbackExecutor Executor executor, ResultCallback<EuiccNotification[]> callback) { 638 try { 639 getIEuiccCardController().listNotifications(mContext.getOpPackageName(), cardId, events, 640 new IListNotificationsCallback.Stub() { 641 @Override 642 public void onComplete(int resultCode, EuiccNotification[] notifications) { 643 executor.execute(() -> callback.onComplete(resultCode, notifications)); 644 } 645 }); 646 } catch (RemoteException e) { 647 Log.e(TAG, "Error calling listNotifications", e); 648 throw e.rethrowFromSystemServer(); 649 } 650 } 651 652 /** 653 * Retrieves contents of all notification of the given {@code events}. 654 * 655 * @param cardId The Id of the eUICC. 656 * @param events bits of the event types ({@link EuiccNotification.Event}) to list. 657 * @param executor The executor through which the callback should be invoked. 658 * @param callback the callback to get the result code and the list of notifications. 659 */ retrieveNotificationList(String cardId, @EuiccNotification.Event int events, @CallbackExecutor Executor executor, ResultCallback<EuiccNotification[]> callback)660 public void retrieveNotificationList(String cardId, @EuiccNotification.Event int events, 661 @CallbackExecutor Executor executor, ResultCallback<EuiccNotification[]> callback) { 662 try { 663 getIEuiccCardController().retrieveNotificationList(mContext.getOpPackageName(), cardId, 664 events, new IRetrieveNotificationListCallback.Stub() { 665 @Override 666 public void onComplete(int resultCode, EuiccNotification[] notifications) { 667 executor.execute(() -> callback.onComplete(resultCode, notifications)); 668 } 669 }); 670 } catch (RemoteException e) { 671 Log.e(TAG, "Error calling retrieveNotificationList", e); 672 throw e.rethrowFromSystemServer(); 673 } 674 } 675 676 /** 677 * Retrieves the content of a notification of the given {@code seqNumber}. 678 * 679 * @param cardId The Id of the eUICC. 680 * @param seqNumber the sequence number of the notification. 681 * @param executor The executor through which the callback should be invoked. 682 * @param callback the callback to get the result code and the notification. 683 */ retrieveNotification(String cardId, int seqNumber, @CallbackExecutor Executor executor, ResultCallback<EuiccNotification> callback)684 public void retrieveNotification(String cardId, int seqNumber, 685 @CallbackExecutor Executor executor, ResultCallback<EuiccNotification> callback) { 686 try { 687 getIEuiccCardController().retrieveNotification(mContext.getOpPackageName(), cardId, 688 seqNumber, new IRetrieveNotificationCallback.Stub() { 689 @Override 690 public void onComplete(int resultCode, EuiccNotification notification) { 691 executor.execute(() -> callback.onComplete(resultCode, notification)); 692 } 693 }); 694 } catch (RemoteException e) { 695 Log.e(TAG, "Error calling retrieveNotification", e); 696 throw e.rethrowFromSystemServer(); 697 } 698 } 699 700 /** 701 * Removes a notification from eUICC. 702 * 703 * @param cardId The Id of the eUICC. 704 * @param seqNumber the sequence number of the notification. 705 * @param executor The executor through which the callback should be invoked. 706 * @param callback the callback to get the result code. 707 */ removeNotificationFromList(String cardId, int seqNumber, @CallbackExecutor Executor executor, ResultCallback<Void> callback)708 public void removeNotificationFromList(String cardId, int seqNumber, 709 @CallbackExecutor Executor executor, ResultCallback<Void> callback) { 710 try { 711 getIEuiccCardController().removeNotificationFromList( 712 mContext.getOpPackageName(), 713 cardId, 714 seqNumber, 715 new IRemoveNotificationFromListCallback.Stub() { 716 @Override 717 public void onComplete(int resultCode) { 718 executor.execute(() -> callback.onComplete(resultCode, null)); 719 } 720 }); 721 } catch (RemoteException e) { 722 Log.e(TAG, "Error calling removeNotificationFromList", e); 723 throw e.rethrowFromSystemServer(); 724 } 725 } 726 } 727