diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2017-11-11 22:00:13 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-11-11 22:00:13 +0000 |
commit | 5e20ba7b1c6a9644da034b345000b37856d78125 (patch) | |
tree | a2cfecc9e0c1d1e920487a04f1e91acc8e7dfd8b /java/com/android/dialer/callintent | |
parent | 3d198bb28ae6b086f967619b25407f65a7f3ebe9 (diff) | |
parent | b0ed171b1c9d5b5d5e686b31be623c99ced15cf0 (diff) |
Merge changes Ide5ec431,Icf2f8fae
* changes:
Implement PreCallCoordinator
Make CallIntentBuilder parcelable
Diffstat (limited to 'java/com/android/dialer/callintent')
-rw-r--r-- | java/com/android/dialer/callintent/CallIntentBuilder.java | 129 |
1 files changed, 88 insertions, 41 deletions
diff --git a/java/com/android/dialer/callintent/CallIntentBuilder.java b/java/com/android/dialer/callintent/CallIntentBuilder.java index 25a5803dc..aabeabdc8 100644 --- a/java/com/android/dialer/callintent/CallIntentBuilder.java +++ b/java/com/android/dialer/callintent/CallIntentBuilder.java @@ -16,11 +16,11 @@ 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.Parcel; +import android.os.Parcelable; import android.os.SystemClock; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -30,23 +30,22 @@ 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.callintent.CallInitiationType.Type; 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; +import com.google.protobuf.InvalidProtocolBufferException; /** Creates an intent to start a new outgoing call. */ -public class CallIntentBuilder { - private final Uri uri; +public class CallIntentBuilder implements Parcelable { + private Uri uri; private final CallSpecificAppData callSpecificAppData; @Nullable private PhoneAccountHandle phoneAccountHandle; private boolean isVideoCall; private String callSubject; private boolean allowAssistedDial; - private AssistedDialingMediator assistedDialingMediator; + + private final Bundle outgoingCallExtras = new Bundle(); private static int lightbringerButtonAppearInExpandedCallLogItemCount = 0; private static int lightbringerButtonAppearInCollapsedCallLogItemCount = 0; @@ -96,6 +95,23 @@ public class CallIntentBuilder { this(CallUtil.getCallUri(Assert.isNotNull(number)), callInitiationType); } + public CallIntentBuilder(@NonNull Parcel parcel) { + ClassLoader classLoader = CallIntentBuilder.class.getClassLoader(); + uri = parcel.readParcelable(classLoader); + CallSpecificAppData data; + try { + data = CallSpecificAppData.parseFrom(parcel.createByteArray()); + } catch (InvalidProtocolBufferException e) { + data = createCallSpecificAppData(Type.UNKNOWN_INITIATION); + } + callSpecificAppData = data; + phoneAccountHandle = parcel.readParcelable(classLoader); + isVideoCall = parcel.readInt() != 0; + callSubject = parcel.readString(); + allowAssistedDial = parcel.readInt() != 0; + outgoingCallExtras.putAll(parcel.readBundle(classLoader)); + } + public static CallIntentBuilder forVoicemail( @Nullable PhoneAccountHandle phoneAccountHandle, CallInitiationType.Type callInitiationType) { return new CallIntentBuilder( @@ -103,6 +119,14 @@ public class CallIntentBuilder { .setPhoneAccountHandle(phoneAccountHandle); } + public void setUri(@NonNull Uri uri) { + this.uri = Assert.isNotNull(uri); + } + + public Uri getUri() { + return uri; + } + public CallSpecificAppData getCallSpecificAppData() { return callSpecificAppData; } @@ -112,40 +136,54 @@ public class CallIntentBuilder { return this; } + @Nullable + public PhoneAccountHandle getPhoneAccountHandle() { + return phoneAccountHandle; + } + public CallIntentBuilder setIsVideoCall(boolean isVideoCall) { this.isVideoCall = isVideoCall; return this; } - public CallIntentBuilder setAllowAssistedDial( - boolean allowAssistedDial, @NonNull AssistedDialingMediator assistedDialingMediator) { - this.assistedDialingMediator = Assert.isNotNull(assistedDialingMediator); + public boolean isVideoCall() { + return isVideoCall; + } + + public CallIntentBuilder setAllowAssistedDial(boolean allowAssistedDial) { this.allowAssistedDial = allowAssistedDial; return this; } + public boolean isAssistedDialAllowed() { + return allowAssistedDial; + } + public CallIntentBuilder setCallSubject(String callSubject) { this.callSubject = callSubject; return this; } + public String getCallSubject() { + return callSubject; + } + + public Bundle getOutgoingCallExtras() { + return outgoingCallExtras; + } + public Intent build() { Intent intent = new Intent(Intent.ACTION_CALL, uri); - Bundle extras = new Bundle(); - if (allowAssistedDial - && this.assistedDialingMediator != null - && this.assistedDialingMediator.isPlatformEligible()) { - intent = buildAssistedDialingParameters(intent, extras); - } intent.putExtra( TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, isVideoCall ? VideoProfile.STATE_BIDIRECTIONAL : VideoProfile.STATE_AUDIO_ONLY); - extras.putLong(Constants.EXTRA_CALL_CREATED_TIME_MILLIS, SystemClock.elapsedRealtime()); - CallIntentParser.putCallSpecificAppData(extras, callSpecificAppData); + outgoingCallExtras.putLong( + Constants.EXTRA_CALL_CREATED_TIME_MILLIS, SystemClock.elapsedRealtime()); + CallIntentParser.putCallSpecificAppData(outgoingCallExtras, callSpecificAppData); - intent.putExtra(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS, extras); + intent.putExtra(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS, outgoingCallExtras); if (phoneAccountHandle != null) { intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle); @@ -158,26 +196,6 @@ 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 = @@ -218,4 +236,33 @@ public class CallIntentBuilder { lightbringerButtonAppearInExpandedCallLogItemCount = 0; lightbringerButtonAppearInSearchCount = 0; } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeParcelable(uri, flags); + dest.writeByteArray(callSpecificAppData.toByteArray()); + dest.writeParcelable(phoneAccountHandle, flags); + dest.writeInt(isVideoCall ? 1 : 0); + dest.writeString(callSubject); + dest.writeInt(allowAssistedDial ? 1 : 0); + dest.writeBundle(outgoingCallExtras); + } + + public static final Creator<CallIntentBuilder> CREATOR = + new Creator<CallIntentBuilder>() { + @Override + public CallIntentBuilder createFromParcel(Parcel source) { + return new CallIntentBuilder(source); + } + + @Override + public CallIntentBuilder[] newArray(int size) { + return new CallIntentBuilder[0]; + } + }; } |