Add impressions for Duo related events (install, activate and invite)

Bug: 70034799
Test: GoogleCallLogAdapterTest
PiperOrigin-RevId: 179085188
Change-Id: I7546cf7e35bbdd3788b03d19627d9a04f612335f
diff --git a/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java b/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java
index a6489cd..922a086 100644
--- a/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java
+++ b/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java
@@ -922,7 +922,10 @@
       Logger.get(mContext).logImpression(DialerImpression.Type.VOICEMAIL_PLAY_AUDIO_DIRECTLY);
       mVoicemailPrimaryActionButtonClicked = true;
       mExpandCollapseListener.onClick(primaryActionView);
-    } else if (view.getId() == R.id.call_with_note_action) {
+      return;
+    }
+
+    if (view.getId() == R.id.call_with_note_action) {
       CallSubjectDialog.start(
           (Activity) mContext,
           info.photoId,
@@ -935,7 +938,10 @@
           numberType, /* phone number type (e.g. mobile) in second line of contact view */
           getContactType(),
           accountHandle);
-    } else if (view.getId() == R.id.block_report_action) {
+      return;
+    }
+
+    if (view.getId() == R.id.block_report_action) {
       Logger.get(mContext).logImpression(DialerImpression.Type.CALL_LOG_BLOCK_REPORT_SPAM);
       maybeShowBlockNumberMigrationDialog(
           new BlockedNumbersMigrator.Listener() {
@@ -945,7 +951,10 @@
                   displayNumber, number, countryIso, callType, info.sourceType);
             }
           });
-    } else if (view.getId() == R.id.block_action) {
+      return;
+    }
+
+    if (view.getId() == R.id.block_action) {
       Logger.get(mContext).logImpression(DialerImpression.Type.CALL_LOG_BLOCK_NUMBER);
       maybeShowBlockNumberMigrationDialog(
           new BlockedNumbersMigrator.Listener() {
@@ -955,63 +964,72 @@
                   displayNumber, number, countryIso, callType, info.sourceType);
             }
           });
-    } else if (view.getId() == R.id.unblock_action) {
+      return;
+    }
+
+    if (view.getId() == R.id.unblock_action) {
       Logger.get(mContext).logImpression(DialerImpression.Type.CALL_LOG_UNBLOCK_NUMBER);
       mBlockReportListener.onUnblock(
           displayNumber, number, countryIso, callType, info.sourceType, isSpam, blockId);
-    } else if (view.getId() == R.id.report_not_spam_action) {
+      return;
+    }
+
+    if (view.getId() == R.id.report_not_spam_action) {
       Logger.get(mContext).logImpression(DialerImpression.Type.CALL_LOG_REPORT_AS_NOT_SPAM);
       mBlockReportListener.onReportNotSpam(
           displayNumber, number, countryIso, callType, info.sourceType);
-    } else if (view.getId() == R.id.call_compose_action) {
+      return;
+    }
+
+    if (view.getId() == R.id.call_compose_action) {
       LogUtil.i("CallLogListItemViewHolder.onClick", "share and call pressed");
       Logger.get(mContext).logImpression(DialerImpression.Type.CALL_LOG_SHARE_AND_CALL);
       Activity activity = (Activity) mContext;
       activity.startActivityForResult(
           CallComposerActivity.newIntent(activity, buildContact()),
           ActivityRequestCodes.DIALTACTS_CALL_COMPOSER);
-    } else if (view.getId() == R.id.share_voicemail) {
+      return;
+    }
+
+    if (view.getId() == R.id.share_voicemail) {
       Logger.get(mContext).logImpression(DialerImpression.Type.VVM_SHARE_PRESSED);
       mVoicemailPlaybackPresenter.shareVoicemail();
+      return;
+    }
+
+    logCallLogAction(view.getId());
+
+    final IntentProvider intentProvider = (IntentProvider) view.getTag();
+    if (intentProvider == null) {
+      return;
+    }
+
+    final Intent intent = intentProvider.getIntent(mContext);
+    // See IntentProvider.getCallDetailIntentProvider() for why this may be null.
+    if (intent == null) {
+      return;
+    }
+
+    // We check to see if we are starting a Duo intent. The reason is Duo
+    // intents need to be started using startActivityForResult instead of the usual startActivity
+    String packageName = intent.getPackage();
+    if (DuoConstants.PACKAGE_NAME.equals(packageName)) {
+      startDuoActivity(intent);
+    } else if (CallDetailsActivity.isLaunchIntent(intent)) {
+      PerformanceReport.recordClick(UiAction.Type.OPEN_CALL_DETAIL);
+      ((Activity) mContext)
+          .startActivityForResult(intent, ActivityRequestCodes.DIALTACTS_CALL_DETAILS);
     } else {
-      logCallLogAction(view.getId());
-
-      final IntentProvider intentProvider = (IntentProvider) view.getTag();
-      if (intentProvider == null) {
-        return;
+      if (Intent.ACTION_CALL.equals(intent.getAction())
+          && intent.getIntExtra(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, -1)
+              == VideoProfile.STATE_BIDIRECTIONAL) {
+        Logger.get(mContext).logImpression(DialerImpression.Type.IMS_VIDEO_REQUESTED_FROM_CALL_LOG);
+      }
+      if (intent.getDataString().contains(DuoConstants.PACKAGE_NAME)) {
+        Logger.get(mContext).logImpression(DialerImpression.Type.DUO_CALL_LOG_SET_UP_INSTALL);
       }
 
-      final Intent intent = intentProvider.getIntent(mContext);
-      // See IntentProvider.getCallDetailIntentProvider() for why this may be null.
-      if (intent == null) {
-        return;
-      }
-
-      // We check to see if we are starting a Duo intent. The reason is Duo
-      // intents need to be started using startActivityForResult instead of the usual startActivity
-      String packageName = intent.getPackage();
-      if (DuoConstants.PACKAGE_NAME.equals(packageName)) {
-        Logger.get(mContext)
-            .logImpression(DialerImpression.Type.LIGHTBRINGER_VIDEO_REQUESTED_FROM_CALL_LOG);
-        if (isNonContactEntry(info)) {
-          Logger.get(mContext)
-              .logImpression(
-                  DialerImpression.Type.LIGHTBRINGER_NON_CONTACT_VIDEO_REQUESTED_FROM_CALL_LOG);
-        }
-        startDuoActivity(intent);
-      } else if (CallDetailsActivity.isLaunchIntent(intent)) {
-        PerformanceReport.recordClick(UiAction.Type.OPEN_CALL_DETAIL);
-        ((Activity) mContext)
-            .startActivityForResult(intent, ActivityRequestCodes.DIALTACTS_CALL_DETAILS);
-      } else {
-        if (Intent.ACTION_CALL.equals(intent.getAction())
-            && intent.getIntExtra(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, -1)
-                == VideoProfile.STATE_BIDIRECTIONAL) {
-          Logger.get(mContext)
-              .logImpression(DialerImpression.Type.IMS_VIDEO_REQUESTED_FROM_CALL_LOG);
-        }
-        DialerUtils.startActivityWithErrorToast(mContext, intent);
-      }
+      DialerUtils.startActivityWithErrorToast(mContext, intent);
     }
   }
 
@@ -1023,6 +1041,23 @@
   }
 
   private void startDuoActivity(Intent intent) {
+    if (DuoConstants.DUO_ACTIVATE_ACTION.equals(intent.getAction())) {
+      Logger.get(mContext).logImpression(DialerImpression.Type.DUO_CALL_LOG_SET_UP_ACTIVATE);
+    } else if (DuoConstants.DUO_INVITE_ACTION.equals(intent.getAction())) {
+      Logger.get(mContext).logImpression(DialerImpression.Type.DUO_CALL_LOG_INVITE);
+    } else if (DuoConstants.DUO_CALL_ACTION.equals(intent.getAction())) {
+      Logger.get(mContext)
+          .logImpression(DialerImpression.Type.LIGHTBRINGER_VIDEO_REQUESTED_FROM_CALL_LOG);
+      if (isNonContactEntry(info)) {
+        Logger.get(mContext)
+            .logImpression(
+                DialerImpression.Type.LIGHTBRINGER_NON_CONTACT_VIDEO_REQUESTED_FROM_CALL_LOG);
+      }
+    } else {
+      throw Assert.createIllegalStateFailException(
+          "Duo intent with invalid action" + intent.getAction());
+    }
+
     try {
       Activity activity = (Activity) mContext;
       activity.startActivityForResult(intent, ActivityRequestCodes.DIALTACTS_DUO);
diff --git a/java/com/android/dialer/app/calllog/IntentProvider.java b/java/com/android/dialer/app/calllog/IntentProvider.java
index c86a260..3a07a6f 100644
--- a/java/com/android/dialer/app/calllog/IntentProvider.java
+++ b/java/com/android/dialer/app/calllog/IntentProvider.java
@@ -114,7 +114,7 @@
                 .scheme("https")
                 .authority("play.google.com")
                 .appendEncodedPath("store/apps/details")
-                .appendQueryParameter("id", "com.google.android.apps.tachyon")
+                .appendQueryParameter("id", DuoConstants.PACKAGE_NAME)
                 .appendQueryParameter(
                     "referrer",
                     "utm_source=dialer&utm_medium=text&utm_campaign=product") // This string is from
@@ -128,8 +128,7 @@
     return new IntentProvider() {
       @Override
       public Intent getIntent(Context context) {
-        return new Intent("com.google.android.apps.tachyon.action.REGISTER")
-            .setPackage(DuoConstants.PACKAGE_NAME);
+        return new Intent(DuoConstants.DUO_ACTIVATE_ACTION).setPackage(DuoConstants.PACKAGE_NAME);
       }
     };
   }
@@ -139,7 +138,7 @@
       @Override
       public Intent getIntent(Context context) {
         Intent intent =
-            new Intent("com.google.android.apps.tachyon.action.INVITE")
+            new Intent(DuoConstants.DUO_INVITE_ACTION)
                 .setPackage(DuoConstants.PACKAGE_NAME)
                 .setData(Uri.fromParts(PhoneAccount.SCHEME_TEL, number, null /* fragment */));
         return intent;
diff --git a/java/com/android/dialer/duo/DuoConstants.java b/java/com/android/dialer/duo/DuoConstants.java
index 50254ee..6eb660d 100644
--- a/java/com/android/dialer/duo/DuoConstants.java
+++ b/java/com/android/dialer/duo/DuoConstants.java
@@ -34,5 +34,12 @@
   public static final PhoneAccountHandle PHONE_ACCOUNT_HANDLE =
       new PhoneAccountHandle(PHONE_ACCOUNT_COMPONENT_NAME, PHONE_ACCOUNT_ID);
 
+  public static final String DUO_ACTIVATE_ACTION =
+      "com.google.android.apps.tachyon.action.REGISTER";
+
+  public static final String DUO_INVITE_ACTION = "com.google.android.apps.tachyon.action.INVITE";
+
+  public static final String DUO_CALL_ACTION = "com.google.android.apps.tachyon.action.CALL";
+
   private DuoConstants() {}
 }
diff --git a/java/com/android/dialer/logging/dialer_impression.proto b/java/com/android/dialer/logging/dialer_impression.proto
index 2bbce0d..aed6625 100644
--- a/java/com/android/dialer/logging/dialer_impression.proto
+++ b/java/com/android/dialer/logging/dialer_impression.proto
@@ -12,7 +12,7 @@
   // Event enums to be used for Impression Logging in Dialer.
   // It's perfectly acceptable for this enum to be large
   // Values should be from 1000 to 100000.
-  // Next Tag: 1308
+  // Next Tag: 1311
   enum Type {
     UNKNOWN_AOSP_EVENT_TYPE = 1000;
 
@@ -621,5 +621,9 @@
     DUAL_SIM_SELECTION_PREFERRED_SET = 1305;
     DUAL_SIM_SELECTION_PREFERRED_USED = 1306;
     DUAL_SIM_SELECTION_GLOBAL_USED = 1307;
+
+    DUO_CALL_LOG_SET_UP_INSTALL = 1308;
+    DUO_CALL_LOG_SET_UP_ACTIVATE = 1309;
+    DUO_CALL_LOG_INVITE = 1310;
   }
 }