Snap for 8609386 from c78a27102d45963646a3c7b122fac576951baebd to tm-release

Change-Id: I54cbef0ff2698894603e629eeaaf06b3eab43e08
diff --git a/src/com/android/ons/ONSProfileDownloader.java b/src/com/android/ons/ONSProfileDownloader.java
index 76ec92d..f83aab9 100644
--- a/src/com/android/ons/ONSProfileDownloader.java
+++ b/src/com/android/ons/ONSProfileDownloader.java
@@ -129,37 +129,11 @@
                                                                     int operationCode,
                                                                     int errorCode) {
 
-            if (operationCode == EuiccManager.OPERATION_DOWNLOAD) {
-
-                //Success Cases
-                if (resultCode == EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_OK) {
-                    return DownloadRetryOperationCode.DOWNLOAD_SUCCESSFUL;
-                }
-
-                //Low eUICC memory cases
-                if (errorCode == EuiccManager.ERROR_EUICC_INSUFFICIENT_MEMORY) {
-                    Log.d(TAG, "Download ERR: EUICC_INSUFFICIENT_MEMORY");
-                    return DownloadRetryOperationCode.ERR_MEMORY_FULL;
-                }
-
-                //Temporary download error cases
-                if (errorCode == EuiccManager.ERROR_TIME_OUT
-                        || errorCode == EuiccManager.ERROR_CONNECTION_ERROR
-                        || errorCode == EuiccManager.ERROR_OPERATION_BUSY) {
-                    return DownloadRetryOperationCode.ERR_RETRY_DOWNLOAD;
-                }
-
-                //Profile installation failure cases
-                if (errorCode == EuiccManager.ERROR_INSTALL_PROFILE) {
-                    return DownloadRetryOperationCode.ERR_INSTALL_ESIM_PROFILE_FAILED;
-                }
-
-                //UnResolvable error cases
-                return DownloadRetryOperationCode.ERR_UNRESOLVABLE;
-
-            } else if (operationCode == EuiccManager.OPERATION_SMDX_SUBJECT_REASON_CODE) {
+            if (operationCode == EuiccManager.OPERATION_SMDX_SUBJECT_REASON_CODE) {
                 //SMDP Error codes handling
                 Pair<String, String> errCode = decodeSmdxSubjectAndReasonCode(detailedErrCode);
+                Log.e(TAG, " Subject Code: " + errCode.first + " Reason Code: "
+                        + errCode.second);
 
                 //8.1 - eUICC, 4.8 - Insufficient Memory
                 // eUICC does not have sufficient space for this Profile.
@@ -176,10 +150,36 @@
                 //All other errors are unresolvable or retry after SIM State Change
                 return DownloadRetryOperationCode.ERR_UNRESOLVABLE;
 
-            } else {
-                //Ignore if Operation code is not DOWNLOAD or SMDX_SUBJECT_REASON_CODE.
-                //Callback is registered only for download requests.
-                return DownloadRetryOperationCode.ERR_UNRESOLVABLE;
+            }
+
+            switch (errorCode) {
+
+                //Success Cases
+                case EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_OK: {
+                    return DownloadRetryOperationCode.DOWNLOAD_SUCCESSFUL;
+                }
+
+                //Low eUICC memory cases
+                case EuiccManager.ERROR_EUICC_INSUFFICIENT_MEMORY: {
+                    Log.d(TAG, "Download ERR: EUICC_INSUFFICIENT_MEMORY");
+                    return DownloadRetryOperationCode.ERR_MEMORY_FULL;
+                }
+
+                //Temporary download error cases
+                case EuiccManager.ERROR_TIME_OUT:
+                case EuiccManager.ERROR_CONNECTION_ERROR:
+                case EuiccManager.ERROR_OPERATION_BUSY: {
+                    return DownloadRetryOperationCode.ERR_RETRY_DOWNLOAD;
+                }
+
+                //Profile installation failure cases
+                case EuiccManager.ERROR_INSTALL_PROFILE: {
+                    return DownloadRetryOperationCode.ERR_INSTALL_ESIM_PROFILE_FAILED;
+                }
+
+                default: {
+                    return DownloadRetryOperationCode.ERR_UNRESOLVABLE;
+                }
             }
         }
     }
diff --git a/tests/src/com/android/ons/ONSProfileDownloaderTest.java b/tests/src/com/android/ons/ONSProfileDownloaderTest.java
index f89d9bb..f37ef1e 100644
--- a/tests/src/com/android/ons/ONSProfileDownloaderTest.java
+++ b/tests/src/com/android/ons/ONSProfileDownloaderTest.java
@@ -136,8 +136,7 @@
                 intent.putExtra(ONSProfileDownloader.PARAM_PRIMARY_SUBID, TEST_SUB_ID);
                 intent.putExtra(ONSProfileDownloader.PARAM_REQUEST_TYPE,
                         ONSProfileDownloader.REQUEST_CODE_DOWNLOAD_SUB);
-                intent.putExtra(EuiccManager.EXTRA_EMBEDDED_SUBSCRIPTION_OPERATION_CODE,
-                        EuiccManager.OPERATION_DOWNLOAD);
+                intent.putExtra(EuiccManager.EXTRA_EMBEDDED_SUBSCRIPTION_OPERATION_CODE, 0);
 
                 onsProfileDownloader.onCallbackIntentReceived(intent,
                         EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_OK);
@@ -215,7 +214,7 @@
                 intent.putExtra(ONSProfileDownloader.PARAM_REQUEST_TYPE,
                         ONSProfileDownloader.REQUEST_CODE_DOWNLOAD_SUB);
                 intent.putExtra(EuiccManager.EXTRA_EMBEDDED_SUBSCRIPTION_OPERATION_CODE,
-                        EuiccManager.OPERATION_DOWNLOAD);
+                        EuiccManager.OPERATION_EUICC_GSMA);
                 intent.putExtra(EuiccManager.EXTRA_EMBEDDED_SUBSCRIPTION_ERROR_CODE,
                         EuiccManager.ERROR_EUICC_INSUFFICIENT_MEMORY);
 
@@ -266,7 +265,7 @@
                 intent.putExtra(EuiccManager.EXTRA_EMBEDDED_SUBSCRIPTION_ERROR_CODE,
                         EuiccManager.ERROR_CONNECTION_ERROR);
                 intent.putExtra(EuiccManager.EXTRA_EMBEDDED_SUBSCRIPTION_OPERATION_CODE,
-                        EuiccManager.OPERATION_DOWNLOAD);
+                        EuiccManager.OPERATION_SMDX);
 
                 onsProfileDownloader.onCallbackIntentReceived(intent,
                         EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR);
@@ -320,7 +319,7 @@
                 intent.putExtra(ONSProfileDownloader.PARAM_REQUEST_TYPE,
                         ONSProfileDownloader.REQUEST_CODE_DOWNLOAD_SUB);
                 intent.putExtra(EuiccManager.EXTRA_EMBEDDED_SUBSCRIPTION_OPERATION_CODE,
-                        EuiccManager.OPERATION_DOWNLOAD);
+                        EuiccManager.OPERATION_SIM_SLOT);
                 intent.putExtra(EuiccManager.EXTRA_EMBEDDED_SUBSCRIPTION_ERROR_CODE,
                         EuiccManager.ERROR_TIME_OUT);
 
@@ -432,7 +431,7 @@
                 intent.putExtra(ONSProfileDownloader.PARAM_REQUEST_TYPE,
                         ONSProfileDownloader.REQUEST_CODE_DOWNLOAD_SUB);
                 intent.putExtra(EuiccManager.EXTRA_EMBEDDED_SUBSCRIPTION_OPERATION_CODE,
-                        EuiccManager.OPERATION_DOWNLOAD);
+                        EuiccManager.OPERATION_SMDX);
                 intent.putExtra(EuiccManager.EXTRA_EMBEDDED_SUBSCRIPTION_ERROR_CODE,
                         EuiccManager.ERROR_INVALID_RESPONSE);
 
@@ -472,42 +471,41 @@
 
                 ONSProfileDownloader.DownloadRetryOperationCode res =
                         downloadHandler.mapDownloaderErrorCode(
-                        EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_OK, 0,
-                        EuiccManager.OPERATION_DOWNLOAD, 0);
+                        EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_OK, 0, 0, 0);
                 assertEquals(
                         ONSProfileDownloader.DownloadRetryOperationCode.DOWNLOAD_SUCCESSFUL, res);
 
                 res = downloadHandler.mapDownloaderErrorCode(
                         EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR, 0,
-                        EuiccManager.OPERATION_DOWNLOAD,
+                        EuiccManager.OPERATION_EUICC_GSMA,
                         EuiccManager.ERROR_EUICC_INSUFFICIENT_MEMORY);
                 assertEquals(ONSProfileDownloader.DownloadRetryOperationCode
                         .ERR_MEMORY_FULL, res);
 
                 res = downloadHandler.mapDownloaderErrorCode(
                         EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR, 0,
-                        EuiccManager.OPERATION_DOWNLOAD,
+                        EuiccManager.OPERATION_SIM_SLOT,
                         EuiccManager.ERROR_TIME_OUT);
                 assertEquals(ONSProfileDownloader.DownloadRetryOperationCode
                         .ERR_RETRY_DOWNLOAD, res);
 
                 res = downloadHandler.mapDownloaderErrorCode(
                         EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR, 0,
-                        EuiccManager.OPERATION_DOWNLOAD,
+                        EuiccManager.OPERATION_SMDX,
                         EuiccManager.ERROR_CONNECTION_ERROR);
                 assertEquals(ONSProfileDownloader.DownloadRetryOperationCode
                         .ERR_RETRY_DOWNLOAD, res);
 
                 res = downloadHandler.mapDownloaderErrorCode(
                         EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR, 0,
-                        EuiccManager.OPERATION_DOWNLOAD,
+                        EuiccManager.OPERATION_SMDX,
                         EuiccManager.ERROR_INVALID_RESPONSE);
                 assertEquals(ONSProfileDownloader.DownloadRetryOperationCode
                         .ERR_UNRESOLVABLE, res);
 
                 res = downloadHandler.mapDownloaderErrorCode(
                         EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_ERROR, 0,
-                        EuiccManager.OPERATION_DOWNLOAD,
+                        EuiccManager.OPERATION_SMDX,
                         EuiccManager.ERROR_INVALID_RESPONSE);
                 assertEquals(ONSProfileDownloader.DownloadRetryOperationCode
                         .ERR_UNRESOLVABLE, res);