Adds CNAP name filtering based on CarrierConfig

The CNAP name is now filtered based on a String array that is defined in
the CarrierConfig. This filtering helps remove caller id information
that is not useful, such as "WIRELESS CALLER" and "UNKOWN NAME".

Bug: 30142293
Change-Id: Ic59dc984b61277fad53d88db5b4cce6f67989c8c
diff --git a/src/com/android/services/telephony/TelephonyConnection.java b/src/com/android/services/telephony/TelephonyConnection.java
index ec7a33c..81f1099 100644
--- a/src/com/android/services/telephony/TelephonyConnection.java
+++ b/src/com/android/services/telephony/TelephonyConnection.java
@@ -767,7 +767,7 @@
                 setAddress(address, presentation);
             }
 
-            String name = mOriginalConnection.getCnapName();
+            String name = filterCnapName(mOriginalConnection.getCnapName());
             int namePresentation = mOriginalConnection.getCnapNamePresentation();
             if (!Objects.equals(name, getCallerDisplayName()) ||
                     namePresentation != getCallerDisplayNamePresentation()) {
@@ -860,6 +860,33 @@
     }
 
     /**
+     * Filters the CNAP name to not include a list of names that are unhelpful to the user for
+     * Caller ID purposes.
+     */
+    private String filterCnapName(final String cnapName) {
+        if (cnapName == null) {
+            return null;
+        }
+        PersistableBundle carrierConfig = getCarrierConfig();
+        String[] filteredCnapNames = null;
+        if (carrierConfig != null) {
+            filteredCnapNames = carrierConfig.getStringArray(
+                    CarrierConfigManager.FILTERED_CNAP_NAMES_STRING_ARRAY);
+        }
+        if (filteredCnapNames != null) {
+            long cnapNameMatches = Arrays.asList(filteredCnapNames)
+                    .stream()
+                    .filter(filteredCnapName -> filteredCnapName.equals(cnapName.toUpperCase()))
+                    .count();
+            if (cnapNameMatches > 0) {
+                Log.i(this, "filterCnapName: Filtered CNAP Name: " + cnapName);
+                return "";
+            }
+        }
+        return cnapName;
+    }
+
+    /**
      * Sets the EXTRA_CALL_TECHNOLOGY_TYPE extra on the connection to report back to Telecom.
      */
     private void setTechnologyTypeExtra() {