Merge "Migrate stringslint.py to AyeAye." am: 12b2d72b32

Original change: https://android-review.googlesource.com/c/platform/packages/services/AlternativeNetworkAccess/+/2173735

Change-Id: I1ad2ed470d026c74e086aaf16d9d88f0a06123be
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 24f7968..0141961 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -25,6 +25,7 @@
     <protected-broadcast android:name="com.android.ons.action.CONFIG" />
 
     <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
+    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
     <application
         android:process="com.android.phone"
         android:persistent="true">
@@ -55,6 +56,9 @@
             <intent-filter>
                 <action android:name="com.android.ons.action.ESIM_CONFIG"/>
             </intent-filter>
+            <intent-filter>
+                <action android:name="android.telephony.action.CARRIER_CONFIG_CHANGED"/>
+            </intent-filter>
         </receiver>
     </application>
 </manifest>
diff --git a/src/com/android/ons/ONSProfileActivator.java b/src/com/android/ons/ONSProfileActivator.java
index 0dc57b4..5325b8f 100644
--- a/src/com/android/ons/ONSProfileActivator.java
+++ b/src/com/android/ons/ONSProfileActivator.java
@@ -48,6 +48,8 @@
 public class ONSProfileActivator implements ONSProfileConfigurator.ONSProfConfigListener,
         ONSProfileDownloader.IONSProfileDownloaderListener {
 
+    public static final String ACTION_CARRIER_CONFIG_CHANGED =
+            "android.telephony.action.CARRIER_CONFIG_CHANGED";
     private static final String TAG = ONSProfileActivator.class.getName();
     private final Context mContext;
     private final SubscriptionManager mSubManager;
@@ -124,11 +126,11 @@
     /**
      * Called when SIM state changes. Triggers CBRS Auto provisioning.
      */
-    public Result handleSimStateChange() {
-        final int simState = mTelephonyManager.getSimState();
+    public Result handleCarrierConfigChange() {
+        /*final int simState = mTelephonyManager.getSimState();
         if (simState != TelephonyManager.SIM_STATE_READY) {
             return Result.ERR_SIM_NOT_READY;
-        }
+        }*/
 
         Result res = provisionCBRS();
         Log.d(TAG, res.toString());
diff --git a/src/com/android/ons/ONSProfileDownloader.java b/src/com/android/ons/ONSProfileDownloader.java
index 5b273d5..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;
+                }
             }
         }
     }
@@ -218,12 +218,14 @@
     protected void downloadProfile(int primarySubId) {
         Log.d(TAG, "downloadProfile");
 
-        //Get SMDP address from carrier configuration
-        String smdpAddr = getSMDPServerAddress(primarySubId);
-        if (smdpAddr == null || smdpAddr.length() <= 0) {
+        //Get SMDP address from carrier configuration.
+        String smdpAddress = getSMDPServerAddress(primarySubId);
+        if (smdpAddress == null || smdpAddress.length() <= 0) {
             return;
         }
 
+        //Generate Activation code 1${SM-DP+ FQDN}$
+        String activationCode = "1$" + smdpAddress + "$";
         Intent intent = new Intent(mContext, ONSProfileResultReceiver.class);
         intent.setAction(ACTION_ONS_ESIM_DOWNLOAD);
         intent.putExtra(PARAM_REQUEST_TYPE, REQUEST_CODE_DOWNLOAD_SUB);
@@ -232,8 +234,8 @@
                 REQUEST_CODE_DOWNLOAD_SUB, intent, PendingIntent.FLAG_MUTABLE);
 
         Log.d(TAG, "Download Request sent to EUICC Manager");
-        mEuiccManager.downloadSubscription(DownloadableSubscription.forActivationCode(smdpAddr),
-                true, callbackIntent);
+        mEuiccManager.downloadSubscription(DownloadableSubscription.forActivationCode(
+                activationCode), true, callbackIntent);
     }
 
     /**
diff --git a/src/com/android/ons/ONSProfileResultReceiver.java b/src/com/android/ons/ONSProfileResultReceiver.java
index c893751..2cc89b1 100644
--- a/src/com/android/ons/ONSProfileResultReceiver.java
+++ b/src/com/android/ons/ONSProfileResultReceiver.java
@@ -39,6 +39,10 @@
     @Override
     public void onReceive(Context context, Intent intent) {
         String action = intent.getAction();
+        if (action == null) {
+            return;
+        }
+
         if (action.equals(TelephonyManager.ACTION_MULTI_SIM_CONFIG_CHANGED)) {
             int simCount = intent.getIntExtra(TelephonyManager.EXTRA_ACTIVE_SIM_SUPPORTED_COUNT, 0);
             Log.d(TAG, "Mutli-SIM configed for " + simCount + "SIMs");
diff --git a/src/com/android/ons/ONSProfileSelector.java b/src/com/android/ons/ONSProfileSelector.java
index ac240c8..1b2c898 100644
--- a/src/com/android/ons/ONSProfileSelector.java
+++ b/src/com/android/ons/ONSProfileSelector.java
@@ -35,6 +35,9 @@
 import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
+import android.telephony.UiccCardInfo;
+import android.telephony.UiccPortInfo;
+import android.telephony.euicc.EuiccManager;
 import android.text.TextUtils;
 
 import com.android.internal.annotations.VisibleForTesting;
@@ -83,6 +86,8 @@
     protected TelephonyManager mTelephonyManager;
     @VisibleForTesting
     protected TelephonyManager mSubscriptionBoundTelephonyManager;
+    @VisibleForTesting
+    protected EuiccManager mEuiccManager;
 
     @VisibleForTesting
     protected ONSNetworkScanCtlr mNetworkScanCtlr;
@@ -352,7 +357,44 @@
         mSubId = subId;
         PendingIntent replyIntent = PendingIntent.getService(mContext,
                 1, callbackIntent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE);
-        mSubscriptionManager.switchToSubscription(subId, replyIntent);
+        int eSIMPortIndex = getAvailableESIMPortIndex();
+        if (eSIMPortIndex == TelephonyManager.INVALID_PORT_INDEX) {
+            sendUpdateNetworksCallbackHelper(mNetworkScanCallback,
+                    TelephonyManager.UPDATE_AVAILABLE_NETWORKS_SIM_PORT_NOT_AVAILABLE);
+            return;
+        }
+        mEuiccManager.switchToSubscription(subId, eSIMPortIndex, replyIntent);
+    }
+
+    private int getAvailableESIMPortIndex() {
+        //Check if an opportunistic subscription is already active. If yes then, use the same port.
+        //Check if an opportunistic subscription is already active. If yes then, use the same port.
+        List<SubscriptionInfo> subscriptionInfos = mSubscriptionManager
+                .getActiveSubscriptionInfoList();
+        if (subscriptionInfos != null) {
+            for (SubscriptionInfo subscriptionInfo : subscriptionInfos) {
+                if (subscriptionInfo.isEmbedded() && subscriptionInfo.isOpportunistic()) {
+                    return subscriptionInfo.getPortIndex();
+                }
+            }
+        }
+
+        //Look for available port.
+        for (UiccCardInfo uiccCardInfo : mTelephonyManager.getUiccCardsInfo()) {
+            if (!uiccCardInfo.isEuicc()) {
+                continue;
+            }
+
+            EuiccManager euiccManager = mEuiccManager.createForCardId(uiccCardInfo.getCardId());
+            for (UiccPortInfo uiccPortInfo : uiccCardInfo.getPorts()) {
+                //Port is available if no profiles enabled on it.
+                if (euiccManager.isSimPortAvailable(uiccPortInfo.getPortIndex())) {
+                    return uiccPortInfo.getPortIndex();
+                }
+            }
+        }
+
+        return TelephonyManager.INVALID_PORT_INDEX;
     }
 
     void onSubSwitchComplete(Intent intent) {
@@ -887,14 +929,13 @@
         mSequenceId = START_SEQUENCE_ID;
         mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
         mProfileSelectionCallback = profileSelectionCallback;
-        mTelephonyManager = (TelephonyManager)
-                mContext.getSystemService(Context.TELEPHONY_SERVICE);
+        mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
         mSubscriptionBoundTelephonyManager = mTelephonyManager.createForSubscriptionId(
                 SubscriptionManager.DEFAULT_SUBSCRIPTION_ID);
-        mSubscriptionManager = (SubscriptionManager)
-                mContext.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
+        mSubscriptionManager = mContext.getSystemService(SubscriptionManager.class);
         mNetworkScanCtlr = new ONSNetworkScanCtlr(mContext, mSubscriptionBoundTelephonyManager,
                 mNetworkAvailableCallBack);
+        mEuiccManager = c.getSystemService(EuiccManager.class);
         updateOpportunisticSubscriptions();
         mThread = new HandlerThread(LOG_TAG);
         mThread.start();
diff --git a/src/com/android/ons/OpportunisticNetworkService.java b/src/com/android/ons/OpportunisticNetworkService.java
index b869090..13e7034 100644
--- a/src/com/android/ons/OpportunisticNetworkService.java
+++ b/src/com/android/ons/OpportunisticNetworkService.java
@@ -163,7 +163,6 @@
     @VisibleForTesting
     protected void handleSimStateChange() {
         logDebug("SIM state changed");
-        mONSProfileActivator.handleSimStateChange();
 
         ONSConfigInput carrierAppConfigInput = mONSConfigInputHashMap.get(CARRIER_APP_CONFIG_NAME);
         if (carrierAppConfigInput == null) {
@@ -421,6 +420,10 @@
                         );
                     }
                     break;
+
+                    case ONSProfileActivator.ACTION_CARRIER_CONFIG_CHANGED:
+                        mONSProfileActivator.handleCarrierConfigChange();
+                        break;
                 }
             }
         }.setIntent(intent));
diff --git a/tests/src/com/android/ons/ONSProfileActivatorTest.java b/tests/src/com/android/ons/ONSProfileActivatorTest.java
index dae5f8d..c678d24 100644
--- a/tests/src/com/android/ons/ONSProfileActivatorTest.java
+++ b/tests/src/com/android/ons/ONSProfileActivatorTest.java
@@ -88,7 +88,7 @@
                 new ConnectivityManager.NetworkCallback());
     }
 
-    @Test
+    /*@Test
     public void testSIMNotReady() {
         doReturn(TelephonyManager.SIM_STATE_NOT_READY).when(mMockTeleManager).getSimState();
 
@@ -98,7 +98,7 @@
 
         assertEquals(ONSProfileActivator.Result.ERR_SIM_NOT_READY,
                 onsProfileActivator.handleSimStateChange());
-    }
+    }*/
 
     @Test
     public void testONSAutoProvisioningDisabled() {
@@ -110,7 +110,7 @@
                 mMockConnectivityManager, mMockONSProfileConfigurator, mMockONSProfileDownloader);
 
         assertEquals(ONSProfileActivator.Result.ERR_AUTO_PROVISIONING_DISABLED,
-                onsProfileActivator.handleSimStateChange());
+                onsProfileActivator.handleCarrierConfigChange());
     }
 
     @Test
@@ -124,7 +124,7 @@
                 mMockConnectivityManager, mMockONSProfileConfigurator, mMockONSProfileDownloader);
 
         assertEquals(ONSProfileActivator.Result.ERR_ESIM_NOT_SUPPORTED,
-                onsProfileActivator.handleSimStateChange());
+                onsProfileActivator.handleCarrierConfigChange());
     }
 
     @Test
@@ -141,7 +141,7 @@
                 mMockConnectivityManager, mMockONSProfileConfigurator, mMockONSProfileDownloader);
 
         assertEquals(ONSProfileActivator.Result.ERR_MULTISIM_NOT_SUPPORTED,
-                onsProfileActivator.handleSimStateChange());
+                onsProfileActivator.handleCarrierConfigChange());
     }
 
     @Test
@@ -168,7 +168,7 @@
                 mMockConnectivityManager, mMockONSProfileConfigurator, mMockONSProfileDownloader);
 
         assertEquals(ONSProfileActivator.Result.ERR_CANNOT_SWITCH_TO_DUAL_SIM_MODE,
-                onsProfileActivator.handleSimStateChange());
+                onsProfileActivator.handleCarrierConfigChange());
     }
 
     @Test
@@ -195,7 +195,7 @@
                 mMockConnectivityManager, mMockONSProfileConfigurator, mMockONSProfileDownloader);
 
         assertEquals(ONSProfileActivator.Result.ERR_SWITCHING_TO_DUAL_SIM_MODE,
-                onsProfileActivator.handleSimStateChange());
+                onsProfileActivator.handleCarrierConfigChange());
     }
 
     //@DisplayName("Dual SIM device with no SIM inserted")
@@ -213,7 +213,7 @@
                 mMockConnectivityManager, mMockONSProfileConfigurator, mMockONSProfileDownloader);
 
         assertEquals(ONSProfileActivator.Result.ERR_NO_SIM_INSERTED,
-                onsProfileActivator.handleSimStateChange());
+                onsProfileActivator.handleCarrierConfigChange());
     }
 
     @Test
@@ -241,7 +241,7 @@
                 mMockConnectivityManager, mMockONSProfileConfigurator, mMockONSProfileDownloader);
 
         assertEquals(ONSProfileActivator.Result.ERR_CARRIER_DOESNT_SUPPORT_CBRS,
-                onsProfileActivator.handleSimStateChange());
+                onsProfileActivator.handleCarrierConfigChange());
     }
 
     @Test
@@ -265,7 +265,7 @@
                 mMockConnectivityManager, mMockONSProfileConfigurator, mMockONSProfileDownloader);
 
         assertEquals(ONSProfileActivator.Result.ERR_DUAL_ACTIVE_SUBSCRIPTIONS,
-                onsProfileActivator.handleSimStateChange());
+                onsProfileActivator.handleCarrierConfigChange());
     }
 
     /*@Test
@@ -332,7 +332,7 @@
                 mMockConnectivityManager, mMockONSProfileConfigurator, mMockONSProfileDownloader);
 
         assertEquals(ONSProfileActivator.Result.ERR_SINGLE_ACTIVE_OPPORTUNISTIC_SIM,
-                onsProfileActivator.handleSimStateChange());
+                onsProfileActivator.handleCarrierConfigChange());
     }
 
     @Test
@@ -362,7 +362,7 @@
 
         onsProfileActivator.mIsInternetConnAvailable = true;
         assertEquals(ONSProfileActivator.Result.SUCCESS,
-                onsProfileActivator.handleSimStateChange());
+                onsProfileActivator.handleCarrierConfigChange());
     }
 
     @Test
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);
diff --git a/tests/src/com/android/ons/ONSProfileResultReceiverTest.java b/tests/src/com/android/ons/ONSProfileResultReceiverTest.java
new file mode 100644
index 0000000..b9eb4a6
--- /dev/null
+++ b/tests/src/com/android/ons/ONSProfileResultReceiverTest.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.ons;
+
+import android.content.Context;
+import android.content.Intent;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+
+public class ONSProfileResultReceiverTest extends ONSBaseTest {
+
+    @Mock
+    Context mMockContext;
+
+    @Before
+    public void setUp() throws Exception {
+        super.setUp("ONSTest");
+    }
+
+    @Test
+    public void testONSResultReceiverWithNoActionString() {
+        ONSProfileResultReceiver onsReceiver = new ONSProfileResultReceiver();
+
+        //Empty Intent with all null fields.
+        Intent intent = new Intent();
+
+        try {
+            onsReceiver.onReceive(mMockContext, intent);
+        } catch (Exception e) {
+            fail("Exception should not be thrown");
+        }
+
+    }
+
+    @Test
+    public void testONSResultReceiverWithActionStringNullExtras() {
+        ONSProfileResultReceiver onsReceiver = new ONSProfileResultReceiver();
+
+        //Intent with action String but all null extras.
+        Intent intent = new Intent();
+        intent.setAction("com.android.ons.TEST_ACTION");
+
+        try {
+            onsReceiver.onReceive(mContext, intent);
+        } catch (Exception e) {
+            fail("Exception should not be thrown");
+        }
+
+    }
+}