summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/callintent
diff options
context:
space:
mode:
authorerfanian <erfanian@google.com>2017-10-09 15:12:22 -0700
committerEric Erfanian <erfanian@google.com>2017-10-10 07:12:05 -0700
commit04ac93d3c9d2f3f4c157bfa1d23d225aa34db9df (patch)
treef6e7fc8b5c3c67eecc096996d10ccd8abe145812 /java/com/android/dialer/callintent
parent45e4573bb6ab234d57a921a73095fd18e453e261 (diff)
Add assisted dialing to outbound calls that qualify.
* Add missing assisted dialing to calls from contacts in the call log. * Add missing assisted dialing to calls from dialpad and normal search. Bug: 63995025,63995261 Test: unit test PiperOrigin-RevId: 171593967 Change-Id: I4e63ef1dcd7ee1b2b5cbb8ecb4d8da744d90bd66
Diffstat (limited to 'java/com/android/dialer/callintent')
-rw-r--r--java/com/android/dialer/callintent/CallIntentBuilder.java41
1 files changed, 35 insertions, 6 deletions
diff --git a/java/com/android/dialer/callintent/CallIntentBuilder.java b/java/com/android/dialer/callintent/CallIntentBuilder.java
index b5b680e48..dc239dc6b 100644
--- a/java/com/android/dialer/callintent/CallIntentBuilder.java
+++ b/java/com/android/dialer/callintent/CallIntentBuilder.java
@@ -16,21 +16,27 @@
package com.android.dialer.callintent;
+import android.annotation.TargetApi;
import android.content.Intent;
import android.net.Uri;
+import android.os.Build;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
+import android.telecom.PhoneAccount;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.telecom.VideoProfile;
import android.text.TextUtils;
+import com.android.dialer.assisteddialing.AssistedDialingMediator;
+import com.android.dialer.assisteddialing.TransformationInfo;
import com.android.dialer.common.Assert;
import com.android.dialer.compat.telephony.TelephonyManagerCompat;
import com.android.dialer.performancereport.PerformanceReport;
import com.android.dialer.util.CallUtil;
+import java.util.Optional;
/** Creates an intent to start a new outgoing call. */
public class CallIntentBuilder {
@@ -40,6 +46,7 @@ public class CallIntentBuilder {
private boolean isVideoCall;
private String callSubject;
private boolean allowAssistedDial;
+ private AssistedDialingMediator assistedDialingMediator;
private static int lightbringerButtonAppearInExpandedCallLogItemCount = 0;
private static int lightbringerButtonAppearInCollapsedCallLogItemCount = 0;
@@ -103,7 +110,9 @@ public class CallIntentBuilder {
return this;
}
- public CallIntentBuilder setAllowAssistedDial(boolean allowAssistedDial) {
+ public CallIntentBuilder setAllowAssistedDial(
+ boolean allowAssistedDial, @NonNull AssistedDialingMediator assistedDialingMediator) {
+ this.assistedDialingMediator = Assert.isNotNull(assistedDialingMediator);
this.allowAssistedDial = allowAssistedDial;
return this;
}
@@ -115,18 +124,18 @@ public class CallIntentBuilder {
public Intent build() {
Intent intent = new Intent(Intent.ACTION_CALL, uri);
+ Bundle extras = new Bundle();
+
+ if (allowAssistedDial && this.assistedDialingMediator != null) {
+ intent = buildAssistedDialingParameters(intent, extras);
+ }
intent.putExtra(
TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE,
isVideoCall ? VideoProfile.STATE_BIDIRECTIONAL : VideoProfile.STATE_AUDIO_ONLY);
- Bundle extras = new Bundle();
extras.putLong(Constants.EXTRA_CALL_CREATED_TIME_MILLIS, SystemClock.elapsedRealtime());
CallIntentParser.putCallSpecificAppData(extras, callSpecificAppData);
- if (allowAssistedDial) {
- extras.putBoolean(TelephonyManagerCompat.ALLOW_ASSISTED_DIAL, true);
- }
-
intent.putExtra(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS, extras);
if (phoneAccountHandle != null) {
@@ -140,6 +149,26 @@ public class CallIntentBuilder {
return intent;
}
+ @SuppressWarnings("AndroidApiChecker") // Use of optional
+ @TargetApi(Build.VERSION_CODES.N)
+ private Intent buildAssistedDialingParameters(Intent intent, Bundle extras) {
+ extras.putBoolean(TelephonyManagerCompat.ALLOW_ASSISTED_DIAL, true);
+ String phoneNumber =
+ uri.getScheme().equals(PhoneAccount.SCHEME_TEL) ? uri.getSchemeSpecificPart() : "";
+ Optional<TransformationInfo> transformedNumber =
+ assistedDialingMediator.attemptAssistedDial(phoneNumber);
+ if (transformedNumber.isPresent()) {
+ Bundle assistedDialingExtras = transformedNumber.get().toBundle();
+ extras.putBoolean(TelephonyManagerCompat.IS_ASSISTED_DIALED, true);
+ extras.putBundle(TelephonyManagerCompat.ASSISTED_DIALING_EXTRAS, assistedDialingExtras);
+ intent =
+ new Intent(
+ Intent.ACTION_CALL,
+ CallUtil.getCallUri(Assert.isNotNull(transformedNumber.get().transformedNumber())));
+ }
+ return intent;
+ }
+
private static @NonNull CallSpecificAppData createCallSpecificAppData(
CallInitiationType.Type callInitiationType) {
CallSpecificAppData callSpecificAppData =