Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 136a888e authored by linyuh's avatar linyuh Committed by Copybara-Service
Browse files

Reduce the number of parameters when building bottom sheet options for telecom/Duo calls.

Bug: 70988691
Test: ModulesTest, DuoCallModuleTest
PiperOrigin-RevId: 193431749
Change-Id: I2af9979504b99175513cb753a030244f735828be
parent 6ceb0dd5
Loading
Loading
Loading
Loading
+13 −11
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import com.android.dialer.blockreportspam.BlockReportSpamDialogInfo;
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 @@ final class Modules {
    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 @@ final class Modules {
    }

    // 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 @@ final class Modules {
    //
    // 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;
+2 −26
Original line number Diff line number Diff line
@@ -19,30 +19,22 @@ package com.android.dialer.historyitemactions;
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 @@ public class DuoCallModule implements HistoryItemActionModule {
  @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));
    }

    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);
  }
}
+13 −33
Original line number Diff line number Diff line
@@ -19,10 +19,7 @@ package com.android.dialer.historyitemactions;
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 @@ public class IntentModule implements HistoryItemActionModule {
    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;

    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;
    }

  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);
    return new IntentModule(context, PreCall.getIntent(context, callIntentBuilder), text, image);
  }
}