blob: ed7b79f62753149409dca8ccbcbbeface92510b0 [file] [log] [blame]
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.telecom;
18
Tyler Gunnbc9ecbc2021-03-09 15:06:30 -080019import android.annotation.Nullable;
Youming Yed6de26e2019-01-30 11:20:35 -080020import android.media.ToneGenerator;
Andrew Lee7f3d41f2014-09-11 17:33:16 -070021import android.os.Parcel;
22import android.os.Parcelable;
Tyler Gunnbc9ecbc2021-03-09 15:06:30 -080023import android.telephony.Annotation;
24import android.telephony.PreciseDisconnectCause;
25import android.telephony.ims.ImsReasonInfo;
Andrew Lee7f3d41f2014-09-11 17:33:16 -070026import android.text.TextUtils;
27
28import java.util.Objects;
29
30/**
31 * Describes the cause of a disconnected call. This always includes a code describing the generic
Santos Cordond9e614f2014-10-28 13:10:36 -070032 * cause of the disconnect. Optionally, it may include a label and/or description to display to the
33 * user. It is the responsibility of the {@link ConnectionService} to provide localized versions of
34 * the label and description. It also may contain a reason for the disconnect, which is intended for
35 * logging and not for display to the user.
Andrew Lee7f3d41f2014-09-11 17:33:16 -070036 */
37public final class DisconnectCause implements Parcelable {
38
39 /** Disconnected because of an unknown or unspecified reason. */
Tej Singhc477d9c2018-02-05 18:31:39 -080040 public static final int UNKNOWN = TelecomProtoEnums.UNKNOWN; // = 0
Andrew Lee7f3d41f2014-09-11 17:33:16 -070041 /** Disconnected because there was an error, such as a problem with the network. */
Tej Singhc477d9c2018-02-05 18:31:39 -080042 public static final int ERROR = TelecomProtoEnums.ERROR; // = 1
Andrew Lee7f3d41f2014-09-11 17:33:16 -070043 /** Disconnected because of a local user-initiated action, such as hanging up. */
Tej Singhc477d9c2018-02-05 18:31:39 -080044 public static final int LOCAL = TelecomProtoEnums.LOCAL; // = 2
Andrew Lee7f3d41f2014-09-11 17:33:16 -070045 /**
46 * Disconnected because of a remote user-initiated action, such as the other party hanging up
47 * up.
48 */
Tej Singhc477d9c2018-02-05 18:31:39 -080049 public static final int REMOTE = TelecomProtoEnums.REMOTE; // = 3
Andrew Lee7f3d41f2014-09-11 17:33:16 -070050 /** Disconnected because it has been canceled. */
Tej Singhc477d9c2018-02-05 18:31:39 -080051 public static final int CANCELED = TelecomProtoEnums.CANCELED; // = 4
Andrew Lee7f3d41f2014-09-11 17:33:16 -070052 /** Disconnected because there was no response to an incoming call. */
Tej Singhc477d9c2018-02-05 18:31:39 -080053 public static final int MISSED = TelecomProtoEnums.MISSED; // = 5
Andrew Lee7f3d41f2014-09-11 17:33:16 -070054 /** Disconnected because the user rejected an incoming call. */
Tej Singhc477d9c2018-02-05 18:31:39 -080055 public static final int REJECTED = TelecomProtoEnums.REJECTED; // = 6
Andrew Lee7f3d41f2014-09-11 17:33:16 -070056 /** Disconnected because the other party was busy. */
Tej Singhc477d9c2018-02-05 18:31:39 -080057 public static final int BUSY = TelecomProtoEnums.BUSY; // = 7
Andrew Lee7f3d41f2014-09-11 17:33:16 -070058 /**
59 * Disconnected because of a restriction on placing the call, such as dialing in airplane
60 * mode.
61 */
Tej Singhc477d9c2018-02-05 18:31:39 -080062 public static final int RESTRICTED = TelecomProtoEnums.RESTRICTED; // = 8
Andrew Lee7f3d41f2014-09-11 17:33:16 -070063 /** Disconnected for reason not described by other disconnect codes. */
Tej Singhc477d9c2018-02-05 18:31:39 -080064 public static final int OTHER = TelecomProtoEnums.OTHER; // = 9
Sailesh Nepal7a69c922014-11-05 18:37:53 -080065 /**
66 * Disconnected because the connection manager did not support the call. The call will be tried
67 * again without a connection manager. See {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
68 */
Tej Singhc477d9c2018-02-05 18:31:39 -080069 public static final int CONNECTION_MANAGER_NOT_SUPPORTED =
70 TelecomProtoEnums.CONNECTION_MANAGER_NOT_SUPPORTED; // = 10
Andrew Lee7f3d41f2014-09-11 17:33:16 -070071
Tyler Gunn876dbfb2016-03-14 15:18:07 -070072 /**
73 * Disconnected because the user did not locally answer the incoming call, but it was answered
74 * on another device where the call was ringing.
75 */
Tej Singhc477d9c2018-02-05 18:31:39 -080076 public static final int ANSWERED_ELSEWHERE = TelecomProtoEnums.ANSWERED_ELSEWHERE; // = 11
Tyler Gunn876dbfb2016-03-14 15:18:07 -070077
78 /**
79 * Disconnected because the call was pulled from the current device to another device.
80 */
Tej Singhc477d9c2018-02-05 18:31:39 -080081 public static final int CALL_PULLED = TelecomProtoEnums.CALL_PULLED; // = 12
Tyler Gunn876dbfb2016-03-14 15:18:07 -070082
Tyler Gunn6adbd2b2016-12-07 13:19:44 -080083 /**
84 * Reason code (returned via {@link #getReason()}) which indicates that a call could not be
85 * completed because the cellular radio is off or out of service, the device is connected to
86 * a wifi network, but the user has not enabled wifi calling.
Tyler Gunn6adbd2b2016-12-07 13:19:44 -080087 */
88 public static final String REASON_WIFI_ON_BUT_WFC_OFF = "REASON_WIFI_ON_BUT_WFC_OFF";
89
Brad Ebinger8818c6f2017-06-30 15:34:32 -070090 /**
91 * Reason code (returned via {@link #getReason()}), which indicates that the video telephony
92 * call was disconnected because IMS access is blocked.
Brad Ebinger8818c6f2017-06-30 15:34:32 -070093 */
94 public static final String REASON_IMS_ACCESS_BLOCKED = "REASON_IMS_ACCESS_BLOCKED";
95
Youming Yed6de26e2019-01-30 11:20:35 -080096 /**
Hall Liu2ef04112020-09-14 18:34:10 -070097 * Reason code (returned via {@link #getReason()}), which indicates that the connection service
98 * is setting the call's state to {@link Call#STATE_DISCONNECTED} because it is internally
99 * changing the representation of an IMS conference call to simulate a single-party call.
100 *
101 * This reason code is only used for communication between a {@link ConnectionService} and
102 * Telecom and should not be surfaced to the user.
Youming Yed6de26e2019-01-30 11:20:35 -0800103 */
104 public static final String REASON_EMULATING_SINGLE_CALL = "EMULATING_SINGLE_CALL";
105
Brad Ebinger62713872019-11-18 18:43:35 -0800106 /**
107 * This reason is set when a call is ended in order to place an emergency call when a
108 * {@link PhoneAccount} doesn't support holding an ongoing call to place an emergency call. This
109 * reason string should only be associated with the {@link #LOCAL} disconnect code returned from
110 * {@link #getCode()}.
111 */
112 public static final String REASON_EMERGENCY_CALL_PLACED = "REASON_EMERGENCY_CALL_PLACED";
113
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700114 private int mDisconnectCode;
115 private CharSequence mDisconnectLabel;
116 private CharSequence mDisconnectDescription;
117 private String mDisconnectReason;
118 private int mToneToPlay;
Tyler Gunnbc9ecbc2021-03-09 15:06:30 -0800119 private int mTelephonyDisconnectCause;
120 private int mTelephonyPreciseDisconnectCause;
121 private ImsReasonInfo mImsReasonInfo;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700122
123 /**
124 * Creates a new DisconnectCause.
125 *
126 * @param code The code for the disconnect cause.
127 */
128 public DisconnectCause(int code) {
129 this(code, null, null, null, ToneGenerator.TONE_UNKNOWN);
130 }
131
132 /**
133 * Creates a new DisconnectCause.
134 *
135 * @param code The code for the disconnect cause.
136 * @param reason The reason for the disconnect.
137 */
138 public DisconnectCause(int code, String reason) {
139 this(code, null, null, reason, ToneGenerator.TONE_UNKNOWN);
140 }
141
142 /**
143 * Creates a new DisconnectCause.
Santos Cordond9e614f2014-10-28 13:10:36 -0700144 *
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700145 * @param code The code for the disconnect cause.
Santos Cordona6018b92016-02-16 14:23:12 -0800146 * @param label The localized label to show to the user to explain the disconnect.
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700147 * @param description The localized description to show to the user to explain the disconnect.
148 * @param reason The reason for the disconnect.
149 */
150 public DisconnectCause(int code, CharSequence label, CharSequence description, String reason) {
151 this(code, label, description, reason, ToneGenerator.TONE_UNKNOWN);
152 }
153
154 /**
155 * Creates a new DisconnectCause.
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700156 *
157 * @param code The code for the disconnect cause.
158 * @param label The localized label to show to the user to explain the disconnect.
159 * @param description The localized description to show to the user to explain the disconnect.
160 * @param reason The reason for the disconnect.
161 * @param toneToPlay The tone to play on disconnect, as defined in {@link ToneGenerator}.
162 */
163 public DisconnectCause(int code, CharSequence label, CharSequence description, String reason,
164 int toneToPlay) {
Tyler Gunnbc9ecbc2021-03-09 15:06:30 -0800165 this(code, label, description, reason, toneToPlay,
166 android.telephony.DisconnectCause.ERROR_UNSPECIFIED,
167 PreciseDisconnectCause.ERROR_UNSPECIFIED,
168 null /* imsReasonInfo */);
169 }
170
171 /**
172 * Creates a new DisconnectCause instance.
173 * @param code The code for the disconnect cause.
174 * @param label The localized label to show to the user to explain the disconnect.
175 * @param description The localized description to show to the user to explain the disconnect.
176 * @param reason The reason for the disconnect.
177 * @param toneToPlay The tone to play on disconnect, as defined in {@link ToneGenerator}.
178 * @param telephonyDisconnectCause The Telephony disconnect cause.
179 * @param telephonyPreciseDisconnectCause The Telephony precise disconnect cause.
180 * @param imsReasonInfo The relevant {@link ImsReasonInfo}, or {@code null} if not available.
181 * @hide
182 */
183 public DisconnectCause(int code, CharSequence label, CharSequence description, String reason,
184 int toneToPlay, @Annotation.DisconnectCauses int telephonyDisconnectCause,
185 @Annotation.PreciseDisconnectCauses int telephonyPreciseDisconnectCause,
186 @Nullable ImsReasonInfo imsReasonInfo) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700187 mDisconnectCode = code;
188 mDisconnectLabel = label;
189 mDisconnectDescription = description;
190 mDisconnectReason = reason;
191 mToneToPlay = toneToPlay;
Tyler Gunnbc9ecbc2021-03-09 15:06:30 -0800192 mTelephonyDisconnectCause = telephonyDisconnectCause;
193 mTelephonyPreciseDisconnectCause = telephonyPreciseDisconnectCause;
194 mImsReasonInfo = imsReasonInfo;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700195 }
196
197 /**
198 * Returns the code for the reason for this disconnect.
199 *
200 * @return The disconnect code.
201 */
202 public int getCode() {
203 return mDisconnectCode;
204 }
205
206 /**
207 * Returns a short label which explains the reason for the disconnect cause and is for display
Santos Cordonc1ec9312015-04-24 11:26:01 -0700208 * in the user interface. If not null, it is expected that the In-Call UI should display this
209 * text where it would normally display the call state ("Dialing", "Disconnected") and is
210 * therefore expected to be relatively small. The {@link ConnectionService } is responsible for
211 * providing and localizing this label. If there is no string provided, returns null.
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700212 *
213 * @return The disconnect label.
214 */
215 public CharSequence getLabel() {
216 return mDisconnectLabel;
217 }
218
219 /**
220 * Returns a description which explains the reason for the disconnect cause and is for display
Santos Cordonc1ec9312015-04-24 11:26:01 -0700221 * in the user interface. This optional text is generally a longer and more descriptive version
222 * of {@link #getLabel}, however it can exist even if {@link #getLabel} is empty. The In-Call UI
223 * should display this relatively prominently; the traditional implementation displays this as
224 * an alert dialog. The {@link ConnectionService} is responsible for providing and localizing
225 * this message. If there is no string provided, returns null.
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700226 *
227 * @return The disconnect description.
228 */
229 public CharSequence getDescription() {
230 return mDisconnectDescription;
231 }
232
233 /**
234 * Returns an explanation of the reason for the disconnect. This is not intended for display to
235 * the user and is used mainly for logging.
236 *
237 * @return The disconnect reason.
238 */
239 public String getReason() {
240 return mDisconnectReason;
241 }
242
243 /**
Tyler Gunnbc9ecbc2021-03-09 15:06:30 -0800244 * Returns the telephony {@link android.telephony.DisconnectCause} for the call.
245 * @return The disconnect cause.
246 * @hide
247 */
248 public @Annotation.DisconnectCauses int getTelephonyDisconnectCause() {
249 return mTelephonyDisconnectCause;
250 }
251
252 /**
253 * Returns the telephony {@link android.telephony.PreciseDisconnectCause} for the call.
254 * @return The precise disconnect cause.
255 * @hide
256 */
257 public @Annotation.PreciseDisconnectCauses int getTelephonyPreciseDisconnectCause() {
258 return mTelephonyPreciseDisconnectCause;
259 }
260
261 /**
262 * Returns the telephony {@link ImsReasonInfo} associated with the call disconnection.
263 * @return The {@link ImsReasonInfo} or {@code null} if not known.
264 * @hide
265 */
266 public @Nullable ImsReasonInfo getImsReasonInfo() {
267 return mImsReasonInfo;
268 }
269
270 /**
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700271 * Returns the tone to play when disconnected.
272 *
273 * @return the tone as defined in {@link ToneGenerator} to play when disconnected.
274 */
275 public int getTone() {
276 return mToneToPlay;
277 }
278
Tyler Gunnbc9ecbc2021-03-09 15:06:30 -0800279 public static final @android.annotation.NonNull Creator<DisconnectCause> CREATOR
280 = new Creator<DisconnectCause>() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700281 @Override
282 public DisconnectCause createFromParcel(Parcel source) {
283 int code = source.readInt();
284 CharSequence label = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
285 CharSequence description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
286 String reason = source.readString();
287 int tone = source.readInt();
Tyler Gunnbc9ecbc2021-03-09 15:06:30 -0800288 int telephonyDisconnectCause = source.readInt();
289 int telephonyPreciseDisconnectCause = source.readInt();
290 ImsReasonInfo imsReasonInfo = source.readParcelable(null);
291 return new DisconnectCause(code, label, description, reason, tone,
292 telephonyDisconnectCause, telephonyPreciseDisconnectCause, imsReasonInfo);
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700293 }
294
295 @Override
296 public DisconnectCause[] newArray(int size) {
297 return new DisconnectCause[size];
298 }
299 };
300
301 @Override
302 public void writeToParcel(Parcel destination, int flags) {
303 destination.writeInt(mDisconnectCode);
304 TextUtils.writeToParcel(mDisconnectLabel, destination, flags);
305 TextUtils.writeToParcel(mDisconnectDescription, destination, flags);
306 destination.writeString(mDisconnectReason);
307 destination.writeInt(mToneToPlay);
Tyler Gunnbc9ecbc2021-03-09 15:06:30 -0800308 destination.writeInt(mTelephonyDisconnectCause);
309 destination.writeInt(mTelephonyPreciseDisconnectCause);
310 destination.writeParcelable(mImsReasonInfo, 0);
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700311 }
312
313 @Override
314 public int describeContents() {
315 return 0;
316 }
317
318 @Override
319 public int hashCode() {
320 return Objects.hashCode(mDisconnectCode)
321 + Objects.hashCode(mDisconnectLabel)
322 + Objects.hashCode(mDisconnectDescription)
323 + Objects.hashCode(mDisconnectReason)
Tyler Gunnbc9ecbc2021-03-09 15:06:30 -0800324 + Objects.hashCode(mToneToPlay)
325 + Objects.hashCode(mTelephonyDisconnectCause)
326 + Objects.hashCode(mTelephonyPreciseDisconnectCause)
327 + Objects.hashCode(mImsReasonInfo);
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700328 }
329
330 @Override
331 public boolean equals(Object o) {
332 if (o instanceof DisconnectCause) {
333 DisconnectCause d = (DisconnectCause) o;
334 return Objects.equals(mDisconnectCode, d.getCode())
335 && Objects.equals(mDisconnectLabel, d.getLabel())
336 && Objects.equals(mDisconnectDescription, d.getDescription())
337 && Objects.equals(mDisconnectReason, d.getReason())
Tyler Gunnbc9ecbc2021-03-09 15:06:30 -0800338 && Objects.equals(mToneToPlay, d.getTone())
339 && Objects.equals(mTelephonyDisconnectCause, d.getTelephonyDisconnectCause())
340 && Objects.equals(mTelephonyPreciseDisconnectCause,
341 d.getTelephonyPreciseDisconnectCause())
342 && Objects.equals(mImsReasonInfo, d.getImsReasonInfo());
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700343 }
344 return false;
345 }
346
347 @Override
348 public String toString() {
349 String code = "";
Sailesh Nepal7a69c922014-11-05 18:37:53 -0800350 switch (mDisconnectCode) {
351 case UNKNOWN:
352 code = "UNKNOWN";
353 break;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700354 case ERROR:
355 code = "ERROR";
356 break;
357 case LOCAL:
358 code = "LOCAL";
359 break;
360 case REMOTE:
361 code = "REMOTE";
362 break;
Sailesh Nepal7a69c922014-11-05 18:37:53 -0800363 case CANCELED:
364 code = "CANCELED";
365 break;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700366 case MISSED:
367 code = "MISSED";
368 break;
369 case REJECTED:
370 code = "REJECTED";
371 break;
372 case BUSY:
373 code = "BUSY";
374 break;
375 case RESTRICTED:
376 code = "RESTRICTED";
377 break;
378 case OTHER:
379 code = "OTHER";
380 break;
Sailesh Nepal7a69c922014-11-05 18:37:53 -0800381 case CONNECTION_MANAGER_NOT_SUPPORTED:
382 code = "CONNECTION_MANAGER_NOT_SUPPORTED";
383 break;
Tyler Gunn2a3f9972016-06-09 07:58:25 -0700384 case CALL_PULLED:
385 code = "CALL_PULLED";
386 break;
387 case ANSWERED_ELSEWHERE:
388 code = "ANSWERED_ELSEWHERE";
389 break;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700390 default:
Sailesh Nepal7a69c922014-11-05 18:37:53 -0800391 code = "invalid code: " + mDisconnectCode;
392 break;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700393 }
394 String label = mDisconnectLabel == null ? "" : mDisconnectLabel.toString();
395 String description = mDisconnectDescription == null
396 ? "" : mDisconnectDescription.toString();
397 String reason = mDisconnectReason == null ? "" : mDisconnectReason;
398 return "DisconnectCause [ Code: (" + code + ")"
399 + " Label: (" + label + ")"
400 + " Description: (" + description + ")"
401 + " Reason: (" + reason + ")"
Tyler Gunnbc9ecbc2021-03-09 15:06:30 -0800402 + " Tone: (" + mToneToPlay + ") "
403 + " TelephonyCause: " + mTelephonyDisconnectCause + "/"
404 + mTelephonyPreciseDisconnectCause
405 + " ImsReasonInfo: "
406 + mImsReasonInfo
407 + "]";
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700408 }
409}