Log contact source when reporting spam from the new UI.

Bug: 73780748
Test: PhoneLookupInfoConsolidatorTest
PiperOrigin-RevId: 187404074
Change-Id: I1db81304909fbf63aba00088c12e18922042c3b1
diff --git a/java/com/android/dialer/blockreportspam/ShowBlockReportSpamDialogReceiver.java b/java/com/android/dialer/blockreportspam/ShowBlockReportSpamDialogReceiver.java
index 364736e..f24bb1c 100644
--- a/java/com/android/dialer/blockreportspam/ShowBlockReportSpamDialogReceiver.java
+++ b/java/com/android/dialer/blockreportspam/ShowBlockReportSpamDialogReceiver.java
@@ -26,7 +26,6 @@
 import com.android.dialer.blockreportspam.BlockReportSpamDialogs.OnSpamDialogClickListener;
 import com.android.dialer.common.Assert;
 import com.android.dialer.common.LogUtil;
-import com.android.dialer.logging.ContactSource;
 import com.android.dialer.logging.DialerImpression;
 import com.android.dialer.logging.Logger;
 import com.android.dialer.protos.ProtoParsers;
@@ -109,7 +108,7 @@
                 dialogInfo.getCountryIso(),
                 dialogInfo.getCallType(),
                 dialogInfo.getReportingLocation(),
-                ContactSource.Type.UNKNOWN_SOURCE_TYPE /* TODO(a bug): Fix. */);
+                dialogInfo.getContactSource());
           }
 
           // TODO(a bug): Block the number.
@@ -154,7 +153,7 @@
                 dialogInfo.getCountryIso(),
                 dialogInfo.getCallType(),
                 dialogInfo.getReportingLocation(),
-                ContactSource.Type.UNKNOWN_SOURCE_TYPE /* TODO(a bug): Fix. */);
+                dialogInfo.getContactSource());
           }
         };
 
diff --git a/java/com/android/dialer/blockreportspam/block_report_spam_dialog_info.proto b/java/com/android/dialer/blockreportspam/block_report_spam_dialog_info.proto
index 3c5a616..70872c7 100644
--- a/java/com/android/dialer/blockreportspam/block_report_spam_dialog_info.proto
+++ b/java/com/android/dialer/blockreportspam/block_report_spam_dialog_info.proto
@@ -7,11 +7,12 @@
 
 package com.android.dialer.blockreportspam;
 
+import "java/com/android/dialer/logging/contact_source.proto";
 import "java/com/android/dialer/logging/reporting_location.proto";
 
 // Contains information needed in dialogs that allow a user to block a number
 // and/or report it as spam/not spam.
-// Next ID: 5
+// Next ID: 6
 message BlockReportSpamDialogInfo {
   // A dialer-normalized version of the number used in the dialogs.
   // See DialerPhoneNumber#normalized_number.
@@ -27,4 +28,7 @@
   // The location where the number is reported.
   optional com.android.dialer.logging.ReportingLocation.Type
       reporting_location = 4;
+
+  // The source where contact info is associated with the number.
+  optional com.android.dialer.logging.ContactSource.Type contact_source = 5;
 }
\ No newline at end of file
diff --git a/java/com/android/dialer/calllog/database/contract/number_attributes.proto b/java/com/android/dialer/calllog/database/contract/number_attributes.proto
index 594e676..e24f393 100644
--- a/java/com/android/dialer/calllog/database/contract/number_attributes.proto
+++ b/java/com/android/dialer/calllog/database/contract/number_attributes.proto
@@ -21,8 +21,10 @@
 
 package com.android.dialer;
 
+import "java/com/android/dialer/logging/contact_source.proto";
+
 // Information related to the phone number of the call.
-// Next ID: 12
+// Next ID: 13
 message NumberAttributes {
   // The name (which may be a person's name or business name, but not a number)
   // formatted exactly as it should appear to the user. If the user's locale or
@@ -65,4 +67,7 @@
 
   // Whether the number is spam.
   optional bool is_spam = 11;
+
+  // Source of the contact associated with the number.
+  optional com.android.dialer.logging.ContactSource.Type contact_source = 12;
 }
\ No newline at end of file
diff --git a/java/com/android/dialer/calllog/ui/menu/Modules.java b/java/com/android/dialer/calllog/ui/menu/Modules.java
index 9df1223..184f7ab 100644
--- a/java/com/android/dialer/calllog/ui/menu/Modules.java
+++ b/java/com/android/dialer/calllog/ui/menu/Modules.java
@@ -90,6 +90,7 @@
               .setCountryIso(row.number().getCountryIso())
               .setCallType(row.callType())
               .setReportingLocation(ReportingLocation.Type.CALL_LOG_HISTORY)
+              .setContactSource(row.numberAttributes().getContactSource())
               .build();
       modules.addAll(
           SharedModules.createModulesHandlingBlockedOrSpamNumber(
diff --git a/java/com/android/dialer/calllogutils/NumberAttributesConverter.java b/java/com/android/dialer/calllogutils/NumberAttributesConverter.java
index ceb8d57..a9376bb 100644
--- a/java/com/android/dialer/calllogutils/NumberAttributesConverter.java
+++ b/java/com/android/dialer/calllogutils/NumberAttributesConverter.java
@@ -56,6 +56,7 @@
         .setIsBlocked(phoneLookupInfoConsolidator.isBlocked())
         .setIsSpam(phoneLookupInfoConsolidator.isSpam())
         .setCanReportAsInvalidNumber(phoneLookupInfoConsolidator.canReportAsInvalidNumber())
-        .setIsCp2InfoIncomplete(phoneLookupInfoConsolidator.isDefaultCp2InfoIncomplete());
+        .setIsCp2InfoIncomplete(phoneLookupInfoConsolidator.isDefaultCp2InfoIncomplete())
+        .setContactSource(phoneLookupInfoConsolidator.getContactSource());
   }
 }
diff --git a/java/com/android/dialer/phonelookup/consolidator/PhoneLookupInfoConsolidator.java b/java/com/android/dialer/phonelookup/consolidator/PhoneLookupInfoConsolidator.java
index 3a48fd5..6e86756 100644
--- a/java/com/android/dialer/phonelookup/consolidator/PhoneLookupInfoConsolidator.java
+++ b/java/com/android/dialer/phonelookup/consolidator/PhoneLookupInfoConsolidator.java
@@ -18,6 +18,7 @@
 import android.support.annotation.IntDef;
 import android.support.annotation.Nullable;
 import com.android.dialer.common.Assert;
+import com.android.dialer.logging.ContactSource;
 import com.android.dialer.phonelookup.PhoneLookup;
 import com.android.dialer.phonelookup.PhoneLookupInfo;
 import com.android.dialer.phonelookup.PhoneLookupInfo.BlockedState;
@@ -91,6 +92,39 @@
   }
 
   /**
+   * Returns a {@link com.android.dialer.logging.ContactSource.Type} representing the source from
+   * which info is used to display contact info in the UI.
+   */
+  public ContactSource.Type getContactSource() {
+    switch (nameSource) {
+      case NameSource.CP2_DEFAULT_DIRECTORY:
+        return ContactSource.Type.SOURCE_TYPE_DIRECTORY;
+      case NameSource.CP2_EXTENDED_DIRECTORY:
+        return ContactSource.Type.SOURCE_TYPE_EXTENDED;
+      case NameSource.PEOPLE_API:
+        return getRefinedPeopleApiSource();
+      case NameSource.NONE:
+        return ContactSource.Type.UNKNOWN_SOURCE_TYPE;
+      default:
+        throw Assert.createUnsupportedOperationFailException(
+            String.format("Unsupported name source: %s", nameSource));
+    }
+  }
+
+  private ContactSource.Type getRefinedPeopleApiSource() {
+    Assert.checkState(nameSource == NameSource.PEOPLE_API);
+
+    switch (phoneLookupInfo.getPeopleApiInfo().getInfoType()) {
+      case CONTACT:
+        return ContactSource.Type.SOURCE_TYPE_PROFILE;
+      case NEARBY_BUSINESS:
+        return ContactSource.Type.SOURCE_TYPE_PLACES;
+      default:
+        return ContactSource.Type.SOURCE_TYPE_REMOTE_OTHER;
+    }
+  }
+
+  /**
    * The {@link PhoneLookupInfo} passed to the constructor is associated with a number. This method
    * returns the name associated with that number.
    *
diff --git a/java/com/android/dialer/voicemail/listui/menu/Modules.java b/java/com/android/dialer/voicemail/listui/menu/Modules.java
index cc7bcbe..c3c883c 100644
--- a/java/com/android/dialer/voicemail/listui/menu/Modules.java
+++ b/java/com/android/dialer/voicemail/listui/menu/Modules.java
@@ -71,6 +71,7 @@
             .setCountryIso(voicemailEntry.number().getCountryIso())
             .setCallType(voicemailEntry.callType())
             .setReportingLocation(ReportingLocation.Type.VOICEMAIL_HISTORY)
+            .setContactSource(voicemailEntry.numberAttributes().getContactSource())
             .build();
     modules.addAll(
         SharedModules.createModulesHandlingBlockedOrSpamNumber(