From 136a888ef24d7168ca9cf5a2a512429f5f9408f6 Mon Sep 17 00:00:00 2001 From: linyuh Date: Wed, 18 Apr 2018 15:57:00 -0700 Subject: 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 --- .../android/dialer/calllog/ui/menu/Modules.java | 24 +++++------ .../dialer/historyitemactions/DuoCallModule.java | 28 +------------ .../dialer/historyitemactions/IntentModule.java | 46 ++++++---------------- 3 files changed, 28 insertions(+), 70 deletions(-) diff --git a/java/com/android/dialer/calllog/ui/menu/Modules.java b/java/com/android/dialer/calllog/ui/menu/Modules.java index e16de3af1..70f17662e 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.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 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; diff --git a/java/com/android/dialer/historyitemactions/DuoCallModule.java b/java/com/android/dialer/historyitemactions/DuoCallModule.java index b0d6a11fc..e6f31e293 100644 --- a/java/com/android/dialer/historyitemactions/DuoCallModule.java +++ b/java/com/android/dialer/historyitemactions/DuoCallModule.java @@ -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)); - } - + 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 a5236c57a..f73d4c951 100644 --- a/java/com/android/dialer/historyitemactions/IntentModule.java +++ b/java/com/android/dialer/historyitemactions/IntentModule.java @@ -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); } } -- cgit v1.2.3