Include DisconnectCause Builder
As part of telecom mainline prep, the previously hidden DisconnectCause
constructor (which includes the Telephony debug info) was promoted to a
system API. From API feedback, a request was put forward to add a
Builder to consolidate the construction of the DisconnectCause instance.
This CL adds the Builder and reverts the previous changes to make the
constructor an API. Instead, the Telephony reference has been resolved
to use the builder pattern instead. The other constructors have been
untouched sincce there are many references within Telecom, which would
make the changes unnecessarily noisy. Those can be cleaned up for a
separate refactor but they shouldn't block mainline prep work.
Bug: 324414185
Bug: 311773409
Test: atest TelecomUnitTests, atest DataObjectUnitTests
Change-Id: I784915cac286322c50f9e605ef457969f5a8cda4
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index 934b193..ab9cefb 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -13603,12 +13603,24 @@
}
public final class DisconnectCause implements android.os.Parcelable {
- ctor @FlaggedApi("com.android.server.telecom.flags.telecom_resolve_hidden_dependencies") public DisconnectCause(int, @NonNull CharSequence, @NonNull CharSequence, @NonNull String, int, int, int, @Nullable android.telephony.ims.ImsReasonInfo);
method @FlaggedApi("com.android.server.telecom.flags.telecom_resolve_hidden_dependencies") @Nullable public android.telephony.ims.ImsReasonInfo getImsReasonInfo();
method @FlaggedApi("com.android.server.telecom.flags.telecom_resolve_hidden_dependencies") public int getTelephonyDisconnectCause();
method @FlaggedApi("com.android.server.telecom.flags.telecom_resolve_hidden_dependencies") public int getTelephonyPreciseDisconnectCause();
}
+ @FlaggedApi("com.android.server.telecom.flags.telecom_resolve_hidden_dependencies") public static final class DisconnectCause.Builder {
+ ctor public DisconnectCause.Builder();
+ method @NonNull public android.telecom.DisconnectCause build();
+ method @NonNull public android.telecom.DisconnectCause.Builder setCode(int);
+ method @NonNull public android.telecom.DisconnectCause.Builder setDescription(@Nullable CharSequence);
+ method @NonNull public android.telecom.DisconnectCause.Builder setImsReasonInfo(@Nullable android.telephony.ims.ImsReasonInfo);
+ method @NonNull public android.telecom.DisconnectCause.Builder setLabel(@Nullable CharSequence);
+ method @NonNull public android.telecom.DisconnectCause.Builder setReason(@NonNull String);
+ method @NonNull public android.telecom.DisconnectCause.Builder setTelephonyDisconnectCause(int);
+ method @NonNull public android.telecom.DisconnectCause.Builder setTelephonyPreciseDisconnectCause(int);
+ method @NonNull public android.telecom.DisconnectCause.Builder setTone(int);
+ }
+
public abstract class InCallService extends android.app.Service {
method @Deprecated public android.telecom.Phone getPhone();
method @Deprecated public void onPhoneCreated(android.telecom.Phone);
diff --git a/telecomm/java/android/telecom/DisconnectCause.java b/telecomm/java/android/telecom/DisconnectCause.java
index 7ad26c9..5ba5ee883 100644
--- a/telecomm/java/android/telecom/DisconnectCause.java
+++ b/telecomm/java/android/telecom/DisconnectCause.java
@@ -169,8 +169,7 @@
int toneToPlay) {
this(code, label, description, reason, toneToPlay,
android.telephony.DisconnectCause.ERROR_UNSPECIFIED,
- PreciseDisconnectCause.ERROR_UNSPECIFIED,
- null /* imsReasonInfo */);
+ PreciseDisconnectCause.ERROR_UNSPECIFIED, null /* imsReasonInfo */);
}
/**
@@ -187,8 +186,6 @@
* @param imsReasonInfo The relevant {@link ImsReasonInfo}, or {@code null} if not available.
* @hide
*/
- @SystemApi
- @FlaggedApi(Flags.FLAG_TELECOM_RESOLVE_HIDDEN_DEPENDENCIES)
public DisconnectCause(int code, @NonNull CharSequence label,
@NonNull CharSequence description, @NonNull String reason,
int toneToPlay, @Annotation.DisconnectCauses int telephonyDisconnectCause,
@@ -298,6 +295,117 @@
return mToneToPlay;
}
+ /**
+ * @hide
+ */
+ @SystemApi
+ @FlaggedApi(Flags.FLAG_TELECOM_RESOLVE_HIDDEN_DEPENDENCIES)
+ public static final class Builder {
+ private int mDisconnectCode;
+ private CharSequence mDisconnectLabel;
+ private CharSequence mDisconnectDescription;
+ private String mDisconnectReason;
+ private int mToneToPlay;
+ private int mTelephonyDisconnectCause;
+ private int mTelephonyPreciseDisconnectCause;
+ private ImsReasonInfo mImsReasonInfo;
+
+ /**
+ * Sets the code for the reason for this disconnect.
+ * @param code The code denoting the type of disconnect.
+ */
+ public @NonNull DisconnectCause.Builder setCode(int code) {
+ mDisconnectCode = code;
+ return this;
+ }
+
+ /**
+ * Sets a label which explains the reason for the disconnect cause, used for display in the
+ * user interface.
+ * @param label The label to associate with the disconnect cause.
+ */
+ public @NonNull DisconnectCause.Builder setLabel(@Nullable CharSequence label) {
+ mDisconnectLabel = label;
+ return this;
+ }
+
+ /**
+ * Sets a description which provides the reason for the disconnect cause, used for display
+ * in the user interface.
+ * @param description The description to associate with the disconnect cause.
+ */
+ public @NonNull DisconnectCause.Builder setDescription(
+ @Nullable CharSequence description) {
+ mDisconnectDescription = description;
+ return this;
+ }
+
+ /**
+ * Sets a reason providing explanation for the disconnect (intended for logging and not for
+ * displaying in the user interface).
+ * @param reason The reason for the disconnect.
+ */
+ public @NonNull DisconnectCause.Builder setReason(@NonNull String reason) {
+ mDisconnectReason = reason;
+ return this;
+ }
+
+ /**
+ * Sets the tone to play when disconnected.
+ * @param toneToPlay The tone as defined in {@link ToneGenerator} to play when disconnected.
+ */
+ public @NonNull DisconnectCause.Builder setTone(int toneToPlay) {
+ mToneToPlay = toneToPlay;
+ return this;
+ }
+
+ /**
+ * Sets the telephony {@link android.telephony.DisconnectCause} for the call (used
+ * internally by Telecom for providing extra debug information from Telephony).
+ * @param telephonyDisconnectCause The disconnect cause as provided by Telephony.
+ */
+ public @NonNull DisconnectCause.Builder setTelephonyDisconnectCause(
+ @Annotation.DisconnectCauses int telephonyDisconnectCause) {
+ mTelephonyDisconnectCause = telephonyDisconnectCause;
+ return this;
+ }
+
+ /**
+ * Sets the telephony {@link android.telephony.PreciseDisconnectCause} for the call (used
+ * internally by Telecom for providing extra debug information from Telephony).
+ * @param telephonyPreciseDisconnectCause The precise disconnect cause as provided by
+ * Telephony.
+ */
+
+ public @NonNull DisconnectCause.Builder setTelephonyPreciseDisconnectCause(
+ @Annotation.PreciseDisconnectCauses int telephonyPreciseDisconnectCause) {
+ mTelephonyPreciseDisconnectCause = telephonyPreciseDisconnectCause;
+ return this;
+ }
+
+ /**
+ * Returns the telephony {@link ImsReasonInfo} associated with the call disconnection. This
+ * is only used internally by Telecom for providing extra debug information from Telephony.
+ *
+ * @param imsReasonInfo The {@link ImsReasonInfo} or {@code null} if not known.
+ */
+ public @NonNull DisconnectCause.Builder setImsReasonInfo(
+ @Nullable ImsReasonInfo imsReasonInfo) {
+ mImsReasonInfo = imsReasonInfo;
+ return this;
+ }
+
+ /**
+ * Build the {@link DisconnectCause} from the provided Builder config.
+ * @return The {@link DisconnectCause} instance from provided builder.
+ */
+ public @NonNull DisconnectCause build() {
+ return new DisconnectCause(mDisconnectCode, mDisconnectLabel, mDisconnectDescription,
+ mDisconnectReason, mToneToPlay, mTelephonyDisconnectCause,
+ mTelephonyPreciseDisconnectCause, mImsReasonInfo);
+ }
+ }
+
public static final @android.annotation.NonNull Creator<DisconnectCause> CREATOR
= new Creator<DisconnectCause>() {
@Override