Merge "Reduce the number of parameters when building bottom sheet options for telecom/Duo calls."
diff --git a/java/com/android/dialer/calllog/ui/menu/Modules.java b/java/com/android/dialer/calllog/ui/menu/Modules.java
index e16de3a..70f1766 100644
--- a/java/com/android/dialer/calllog/ui/menu/Modules.java
+++ b/java/com/android/dialer/calllog/ui/menu/Modules.java
@@ -26,6 +26,7 @@
 import com.android.dialer.calldetails.CallDetailsActivity;
 import com.android.dialer.calldetails.CallDetailsHeaderInfo;
 import com.android.dialer.callintent.CallInitiationType;
+import com.android.dialer.callintent.CallIntentBuilder;
 import com.android.dialer.calllog.model.CoalescedRow;
 import com.android.dialer.calllogutils.CallLogEntryText;
 import com.android.dialer.calllogutils.NumberAttributesConverter;
@@ -145,9 +146,11 @@
     List<HistoryItemActionModule> modules = new ArrayList<>();
 
     // Add an audio call item
-    modules.add(
-        IntentModule.newCallModule(
-            context, normalizedNumber, phoneAccountHandle, CallInitiationType.Type.CALL_LOG));
+    // TODO(zachh): Support post-dial digits; consider using DialerPhoneNumber.
+    CallIntentBuilder callIntentBuilder =
+        new CallIntentBuilder(normalizedNumber, CallInitiationType.Type.CALL_LOG)
+            .setPhoneAccountHandle(phoneAccountHandle);
+    modules.add(IntentModule.newCallModule(context, callIntentBuilder));
 
     // If the call log entry is for a spam call, nothing more to be done.
     if (row.getNumberAttributes().getIsSpam()) {
@@ -155,12 +158,13 @@
     }
 
     // If the call log entry is for a video call, add the corresponding video call options.
+    // Note that if the entry is for a Duo video call but Duo is not available, we will fall back to
+    // a carrier video call.
     if ((row.getFeatures() & Calls.FEATURES_VIDEO) == Calls.FEATURES_VIDEO) {
       modules.add(
-          isDuoCall
-              ? new DuoCallModule(context, normalizedNumber, CallInitiationType.Type.CALL_LOG)
-              : IntentModule.newCarrierVideoCallModule(
-                  context, normalizedNumber, phoneAccountHandle, CallInitiationType.Type.CALL_LOG));
+          isDuoCall && canPlaceDuoCall(context, normalizedNumber)
+              ? new DuoCallModule(context, normalizedNumber)
+              : IntentModule.newCallModule(context, callIntentBuilder.setIsVideoCall(true)));
       return modules;
     }
 
@@ -169,11 +173,9 @@
     //
     // The carrier video call option takes precedence over Duo.
     if (canPlaceCarrierVideoCall(context, row)) {
-      modules.add(
-          IntentModule.newCarrierVideoCallModule(
-              context, normalizedNumber, phoneAccountHandle, CallInitiationType.Type.CALL_LOG));
+      modules.add(IntentModule.newCallModule(context, callIntentBuilder.setIsVideoCall(true)));
     } else if (canPlaceDuoCall(context, normalizedNumber)) {
-      modules.add(new DuoCallModule(context, normalizedNumber, CallInitiationType.Type.CALL_LOG));
+      modules.add(new DuoCallModule(context, normalizedNumber));
     }
 
     return modules;
diff --git a/java/com/android/dialer/historyitemactions/DuoCallModule.java b/java/com/android/dialer/historyitemactions/DuoCallModule.java
index b0d6a11..e6f31e2 100644
--- a/java/com/android/dialer/historyitemactions/DuoCallModule.java
+++ b/java/com/android/dialer/historyitemactions/DuoCallModule.java
@@ -19,30 +19,22 @@
 import android.Manifest.permission;
 import android.content.Context;
 import android.support.annotation.RequiresPermission;
-import com.android.dialer.callintent.CallInitiationType;
-import com.android.dialer.callintent.CallIntentBuilder;
-import com.android.dialer.duo.Duo;
-import com.android.dialer.duo.DuoComponent;
 import com.android.dialer.duo.PlaceDuoCallNotifier;
-import com.android.dialer.precall.PreCall;
 
 /** {@link HistoryItemActionModule} for making a Duo call. */
 public class DuoCallModule implements HistoryItemActionModule {
 
   private final Context context;
   private final String phoneNumber;
-  private final CallInitiationType.Type callInitiationType;
 
   /**
    * Creates a module for making a Duo call.
    *
    * @param phoneNumber The number to start a Duo call. It can be of any format.
    */
-  public DuoCallModule(
-      Context context, String phoneNumber, CallInitiationType.Type callInitiationType) {
+  public DuoCallModule(Context context, String phoneNumber) {
     this.context = context;
     this.phoneNumber = phoneNumber;
-    this.callInitiationType = callInitiationType;
   }
 
   @Override
@@ -58,23 +50,7 @@
   @Override
   @RequiresPermission(permission.READ_PHONE_STATE)
   public boolean onClick() {
-    if (canPlaceDuoCall(context, phoneNumber)) {
-      PlaceDuoCallNotifier.notify(context, phoneNumber);
-    } else {
-      // If a Duo call can't be placed, fall back to an IMS video call.
-      PreCall.start(
-          context, new CallIntentBuilder(phoneNumber, callInitiationType).setIsVideoCall(true));
-    }
-
+    PlaceDuoCallNotifier.notify(context, phoneNumber);
     return true; // Close the bottom sheet.
   }
-
-  private boolean canPlaceDuoCall(Context context, String phoneNumber) {
-    Duo duo = DuoComponent.get(context).getDuo();
-
-    return duo.isInstalled(context)
-        && duo.isEnabled(context)
-        && duo.isActivated(context)
-        && duo.isReachable(context, phoneNumber);
-  }
 }
diff --git a/java/com/android/dialer/historyitemactions/IntentModule.java b/java/com/android/dialer/historyitemactions/IntentModule.java
index a5236c5..f73d4c9 100644
--- a/java/com/android/dialer/historyitemactions/IntentModule.java
+++ b/java/com/android/dialer/historyitemactions/IntentModule.java
@@ -19,10 +19,7 @@
 import android.content.Context;
 import android.content.Intent;
 import android.support.annotation.DrawableRes;
-import android.support.annotation.Nullable;
 import android.support.annotation.StringRes;
-import android.telecom.PhoneAccountHandle;
-import com.android.dialer.callintent.CallInitiationType.Type;
 import com.android.dialer.callintent.CallIntentBuilder;
 import com.android.dialer.precall.PreCall;
 import com.android.dialer.util.DialerUtils;
@@ -61,36 +58,19 @@
     return true;
   }
 
-  public static IntentModule newCallModule(
-      Context context,
-      String number,
-      @Nullable PhoneAccountHandle phoneAccountHandle,
-      Type initiationType) {
-    // TODO(zachh): Support post-dial digits; consider using DialerPhoneNumber.
-    return new IntentModule(
-        context,
-        PreCall.getIntent(
-            context,
-            new CallIntentBuilder(number, initiationType)
-                .setPhoneAccountHandle(phoneAccountHandle)),
-        R.string.voice_call,
-        R.drawable.quantum_ic_call_white_24);
-  }
+  /** Creates a module for starting an outgoing call with a {@link CallIntentBuilder}. */
+  public static IntentModule newCallModule(Context context, CallIntentBuilder callIntentBuilder) {
+    @StringRes int text;
+    @DrawableRes int image;
 
-  public static IntentModule newCarrierVideoCallModule(
-      Context context,
-      String number,
-      @Nullable PhoneAccountHandle phoneAccountHandle,
-      Type initiationType) {
-    // TODO(zachh): Support post-dial digits; consider using DialerPhoneNumber.
-    return new IntentModule(
-        context,
-        PreCall.getIntent(
-            context,
-            new CallIntentBuilder(number, initiationType)
-                .setPhoneAccountHandle(phoneAccountHandle)
-                .setIsVideoCall(true)),
-        R.string.video_call,
-        R.drawable.quantum_ic_videocam_vd_white_24);
+    if (callIntentBuilder.isVideoCall()) {
+      text = R.string.video_call;
+      image = R.drawable.quantum_ic_videocam_vd_white_24;
+    } else {
+      text = R.string.voice_call;
+      image = R.drawable.quantum_ic_call_white_24;
+    }
+
+    return new IntentModule(context, PreCall.getIntent(context, callIntentBuilder), text, image);
   }
 }