Attempt to fix bug that voicemail or emergency number is changed during a call.

This is caused by handling phone number change during a call.
This change will remember if it's a voicemail/emergency number after phone
number changes and continue to show it as voicemail/emergency number.

Bug: 64009408,63716219
Test: SimulatorConnectionService and real device.
PiperOrigin-RevId: 163276696
Change-Id: Ibcde9ab9b61dc683de3d77dddca789ade3e895ba
diff --git a/java/com/android/incallui/ContactInfoCache.java b/java/com/android/incallui/ContactInfoCache.java
index fdfba3b..d50a5c2 100644
--- a/java/com/android/incallui/ContactInfoCache.java
+++ b/java/com/android/incallui/ContactInfoCache.java
@@ -266,6 +266,8 @@
     cce.userType = info.userType;
     cce.originalPhoneNumber = info.phoneNumber;
     cce.shouldShowLocation = info.shouldShowGeoDescription;
+    cce.isEmergencyNumber = info.isEmergencyNumber();
+    cce.isVoicemailNumber = info.isVoiceMailNumber();
 
     if (info.contactExists) {
       cce.contactLookupResult = ContactLookupResult.Type.LOCAL_CONTACT;
@@ -428,6 +430,19 @@
             + "; didLocalLookup = "
             + didLocalLookup);
 
+    ContactCacheEntry existingCacheEntry = mInfoMap.get(callId);
+    Log.d(TAG, "Existing cacheEntry in hashMap " + existingCacheEntry);
+
+    // Mark it as emergency/voicemail if the cache exists and was emergency/voicemail before the
+    // number changed.
+    if (existingCacheEntry != null) {
+      if (existingCacheEntry.isEmergencyNumber) {
+        callerInfo.markAsEmergency(mContext);
+      } else if (existingCacheEntry.isVoicemailNumber) {
+        callerInfo.markAsVoiceMail(mContext);
+      }
+    }
+
     int presentationMode = numberPresentation;
     if (callerInfo.contactExists
         || callerInfo.isEmergencyNumber()
@@ -439,9 +454,6 @@
     ContactCacheEntry cacheEntry = buildEntry(mContext, callerInfo, presentationMode);
     cacheEntry.queryId = queryToken.mQueryId;
 
-    ContactCacheEntry existingCacheEntry = mInfoMap.get(callId);
-    Log.d(TAG, "Existing cacheEntry in hashMap " + existingCacheEntry);
-
     if (didLocalLookup) {
       if (cacheEntry.displayPhotoUri != null) {
         // When the difference between 2 numbers is only the prefix (e.g. + or IDD),
@@ -704,6 +716,8 @@
     boolean shouldShowLocation;
 
     boolean isBusiness;
+    boolean isEmergencyNumber;
+    boolean isVoicemailNumber;
 
     @Override
     public String toString() {
@@ -743,6 +757,10 @@
           + originalPhoneNumber
           + ", shouldShowLocation="
           + shouldShowLocation
+          + ", isEmergencyNumber="
+          + isEmergencyNumber
+          + ", isVoicemailNumber="
+          + isVoicemailNumber
           + '}';
     }
   }