PS preferred scan after VoLTE failure only when SIM ready

Keeping PS preferred scan after VoLTE failure is to recover
the exceptional case: ePDN setup fails since it is requested
while initial registration is on going and the registration
is rejected.

This case happens only when there is an active SIM.
So if there is no active SIM, do the RAT preference switching
as usually.

Bug: 335752472
Test: atest EmergencyCallDomainSelectorTest
Change-Id: Id72283ec4fd42022e6321868e8812ebe4678b9a2
diff --git a/src/com/android/services/telephony/domainselection/EmergencyCallDomainSelector.java b/src/com/android/services/telephony/domainselection/EmergencyCallDomainSelector.java
index 29ad29e..6001a43 100644
--- a/src/com/android/services/telephony/domainselection/EmergencyCallDomainSelector.java
+++ b/src/com/android/services/telephony/domainselection/EmergencyCallDomainSelector.java
@@ -452,7 +452,8 @@
             int reasonCode = mSelectionAttributes.getPsDisconnectCause().getCode();
             if (reasonCode == ImsReasonInfo.CODE_LOCAL_NOT_REGISTERED
                     && regState != REGISTRATION_STATE_HOME
-                    && regState != REGISTRATION_STATE_ROAMING) {
+                    && regState != REGISTRATION_STATE_ROAMING
+                    && isSimReady()) {
                 // b/326292100, ePDN setup failed in limited state, request PS preferred scan.
                 mLastNetworkType = UNKNOWN;
                 mSwitchRatPreferenceWithLocalNotRegistered = true;
diff --git a/tests/src/com/android/services/telephony/domainselection/EmergencyCallDomainSelectorTest.java b/tests/src/com/android/services/telephony/domainselection/EmergencyCallDomainSelectorTest.java
index 53f3b8a..adf342c 100644
--- a/tests/src/com/android/services/telephony/domainselection/EmergencyCallDomainSelectorTest.java
+++ b/tests/src/com/android/services/telephony/domainselection/EmergencyCallDomainSelectorTest.java
@@ -2928,6 +2928,34 @@
     }
 
     @Test
+    public void testDefaultLimitedServiceEutranFailPinLocked() throws Exception {
+        doReturn(TelephonyManager.SIM_STATE_PIN_REQUIRED)
+                .when(mTelephonyManager).getSimState(anyInt());
+
+        createSelector(SLOT_0_SUB_ID);
+        unsolBarringInfoChanged(false);
+
+        EmergencyRegistrationResult regResult = getEmergencyRegResult(EUTRAN,
+                REGISTRATION_STATE_UNKNOWN,
+                0, false, true, 0, 0, "", "");
+        SelectionAttributes attr = getSelectionAttributes(SLOT_0, SLOT_0_SUB_ID, regResult);
+        mDomainSelector.selectDomain(attr, mTransportSelectorCallback);
+        processAllMessages();
+
+        bindImsServiceUnregistered();
+
+        processAllMessages();
+        verify(mWwanSelectorCallback, times(1)).onDomainSelected(eq(DOMAIN_PS), eq(true));
+
+        attr = getSelectionAttributes(SLOT_0, SLOT_0_SUB_ID, false, regResult,
+                new ImsReasonInfo(ImsReasonInfo.CODE_LOCAL_NOT_REGISTERED, 0, null));
+        mDomainSelector.reselectDomain(attr);
+        processAllMessages();
+
+        verifyScanCsPreferred();
+    }
+
+    @Test
     public void testDefaultLimitedServiceScanTypeFullService() throws Exception {
         PersistableBundle bundle = getDefaultPersistableBundle();
         bundle.putInt(KEY_EMERGENCY_NETWORK_SCAN_TYPE_INT, SCAN_TYPE_FULL_SERVICE);