blob: f7fe1ba1f998b3b37f5bae783e326dd1d9007154 [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
Hall Liu2ef04112020-09-14 18:34:10 -070019import android.annotation.SystemApi;
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;
Andrew Lee7f3d41f2014-09-11 17:33:16 -070023import android.text.TextUtils;
24
25import java.util.Objects;
26
27/**
28 * Describes the cause of a disconnected call. This always includes a code describing the generic
Santos Cordond9e614f2014-10-28 13:10:36 -070029 * cause of the disconnect. Optionally, it may include a label and/or description to display to the
30 * user. It is the responsibility of the {@link ConnectionService} to provide localized versions of
31 * the label and description. It also may contain a reason for the disconnect, which is intended for
32 * logging and not for display to the user.
Andrew Lee7f3d41f2014-09-11 17:33:16 -070033 */
34public final class DisconnectCause implements Parcelable {
35
36 /** Disconnected because of an unknown or unspecified reason. */
Tej Singhc477d9c2018-02-05 18:31:39 -080037 public static final int UNKNOWN = TelecomProtoEnums.UNKNOWN; // = 0
Andrew Lee7f3d41f2014-09-11 17:33:16 -070038 /** Disconnected because there was an error, such as a problem with the network. */
Tej Singhc477d9c2018-02-05 18:31:39 -080039 public static final int ERROR = TelecomProtoEnums.ERROR; // = 1
Andrew Lee7f3d41f2014-09-11 17:33:16 -070040 /** Disconnected because of a local user-initiated action, such as hanging up. */
Tej Singhc477d9c2018-02-05 18:31:39 -080041 public static final int LOCAL = TelecomProtoEnums.LOCAL; // = 2
Andrew Lee7f3d41f2014-09-11 17:33:16 -070042 /**
43 * Disconnected because of a remote user-initiated action, such as the other party hanging up
44 * up.
45 */
Tej Singhc477d9c2018-02-05 18:31:39 -080046 public static final int REMOTE = TelecomProtoEnums.REMOTE; // = 3
Andrew Lee7f3d41f2014-09-11 17:33:16 -070047 /** Disconnected because it has been canceled. */
Tej Singhc477d9c2018-02-05 18:31:39 -080048 public static final int CANCELED = TelecomProtoEnums.CANCELED; // = 4
Andrew Lee7f3d41f2014-09-11 17:33:16 -070049 /** Disconnected because there was no response to an incoming call. */
Tej Singhc477d9c2018-02-05 18:31:39 -080050 public static final int MISSED = TelecomProtoEnums.MISSED; // = 5
Andrew Lee7f3d41f2014-09-11 17:33:16 -070051 /** Disconnected because the user rejected an incoming call. */
Tej Singhc477d9c2018-02-05 18:31:39 -080052 public static final int REJECTED = TelecomProtoEnums.REJECTED; // = 6
Andrew Lee7f3d41f2014-09-11 17:33:16 -070053 /** Disconnected because the other party was busy. */
Tej Singhc477d9c2018-02-05 18:31:39 -080054 public static final int BUSY = TelecomProtoEnums.BUSY; // = 7
Andrew Lee7f3d41f2014-09-11 17:33:16 -070055 /**
56 * Disconnected because of a restriction on placing the call, such as dialing in airplane
57 * mode.
58 */
Tej Singhc477d9c2018-02-05 18:31:39 -080059 public static final int RESTRICTED = TelecomProtoEnums.RESTRICTED; // = 8
Andrew Lee7f3d41f2014-09-11 17:33:16 -070060 /** Disconnected for reason not described by other disconnect codes. */
Tej Singhc477d9c2018-02-05 18:31:39 -080061 public static final int OTHER = TelecomProtoEnums.OTHER; // = 9
Sailesh Nepal7a69c922014-11-05 18:37:53 -080062 /**
63 * Disconnected because the connection manager did not support the call. The call will be tried
64 * again without a connection manager. See {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
65 */
Tej Singhc477d9c2018-02-05 18:31:39 -080066 public static final int CONNECTION_MANAGER_NOT_SUPPORTED =
67 TelecomProtoEnums.CONNECTION_MANAGER_NOT_SUPPORTED; // = 10
Andrew Lee7f3d41f2014-09-11 17:33:16 -070068
Tyler Gunn876dbfb2016-03-14 15:18:07 -070069 /**
70 * Disconnected because the user did not locally answer the incoming call, but it was answered
71 * on another device where the call was ringing.
72 */
Tej Singhc477d9c2018-02-05 18:31:39 -080073 public static final int ANSWERED_ELSEWHERE = TelecomProtoEnums.ANSWERED_ELSEWHERE; // = 11
Tyler Gunn876dbfb2016-03-14 15:18:07 -070074
75 /**
76 * Disconnected because the call was pulled from the current device to another device.
77 */
Tej Singhc477d9c2018-02-05 18:31:39 -080078 public static final int CALL_PULLED = TelecomProtoEnums.CALL_PULLED; // = 12
Tyler Gunn876dbfb2016-03-14 15:18:07 -070079
Tyler Gunn6adbd2b2016-12-07 13:19:44 -080080 /**
81 * Reason code (returned via {@link #getReason()}) which indicates that a call could not be
82 * completed because the cellular radio is off or out of service, the device is connected to
83 * a wifi network, but the user has not enabled wifi calling.
Tyler Gunn6adbd2b2016-12-07 13:19:44 -080084 */
85 public static final String REASON_WIFI_ON_BUT_WFC_OFF = "REASON_WIFI_ON_BUT_WFC_OFF";
86
Brad Ebinger8818c6f2017-06-30 15:34:32 -070087 /**
88 * Reason code (returned via {@link #getReason()}), which indicates that the video telephony
89 * call was disconnected because IMS access is blocked.
Brad Ebinger8818c6f2017-06-30 15:34:32 -070090 */
91 public static final String REASON_IMS_ACCESS_BLOCKED = "REASON_IMS_ACCESS_BLOCKED";
92
Youming Yed6de26e2019-01-30 11:20:35 -080093 /**
Hall Liu2ef04112020-09-14 18:34:10 -070094 * Reason code (returned via {@link #getReason()}), which indicates that the connection service
95 * is setting the call's state to {@link Call#STATE_DISCONNECTED} because it is internally
96 * changing the representation of an IMS conference call to simulate a single-party call.
97 *
98 * This reason code is only used for communication between a {@link ConnectionService} and
99 * Telecom and should not be surfaced to the user.
100 *
Youming Yed6de26e2019-01-30 11:20:35 -0800101 * @hide
102 */
Hall Liu2ef04112020-09-14 18:34:10 -0700103 @SystemApi
Youming Yed6de26e2019-01-30 11:20:35 -0800104 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;
119
120 /**
121 * Creates a new DisconnectCause.
122 *
123 * @param code The code for the disconnect cause.
124 */
125 public DisconnectCause(int code) {
126 this(code, null, null, null, ToneGenerator.TONE_UNKNOWN);
127 }
128
129 /**
130 * Creates a new DisconnectCause.
131 *
132 * @param code The code for the disconnect cause.
133 * @param reason The reason for the disconnect.
134 */
135 public DisconnectCause(int code, String reason) {
136 this(code, null, null, reason, ToneGenerator.TONE_UNKNOWN);
137 }
138
139 /**
140 * Creates a new DisconnectCause.
Santos Cordond9e614f2014-10-28 13:10:36 -0700141 *
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700142 * @param code The code for the disconnect cause.
Santos Cordona6018b92016-02-16 14:23:12 -0800143 * @param label The localized label to show to the user to explain the disconnect.
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700144 * @param description The localized description to show to the user to explain the disconnect.
145 * @param reason The reason for the disconnect.
146 */
147 public DisconnectCause(int code, CharSequence label, CharSequence description, String reason) {
148 this(code, label, description, reason, ToneGenerator.TONE_UNKNOWN);
149 }
150
151 /**
152 * Creates a new DisconnectCause.
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700153 *
154 * @param code The code for the disconnect cause.
155 * @param label The localized label to show to the user to explain the disconnect.
156 * @param description The localized description to show to the user to explain the disconnect.
157 * @param reason The reason for the disconnect.
158 * @param toneToPlay The tone to play on disconnect, as defined in {@link ToneGenerator}.
159 */
160 public DisconnectCause(int code, CharSequence label, CharSequence description, String reason,
161 int toneToPlay) {
162 mDisconnectCode = code;
163 mDisconnectLabel = label;
164 mDisconnectDescription = description;
165 mDisconnectReason = reason;
166 mToneToPlay = toneToPlay;
167 }
168
169 /**
170 * Returns the code for the reason for this disconnect.
171 *
172 * @return The disconnect code.
173 */
174 public int getCode() {
175 return mDisconnectCode;
176 }
177
178 /**
179 * Returns a short label which explains the reason for the disconnect cause and is for display
Santos Cordonc1ec9312015-04-24 11:26:01 -0700180 * in the user interface. If not null, it is expected that the In-Call UI should display this
181 * text where it would normally display the call state ("Dialing", "Disconnected") and is
182 * therefore expected to be relatively small. The {@link ConnectionService } is responsible for
183 * providing and localizing this label. If there is no string provided, returns null.
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700184 *
185 * @return The disconnect label.
186 */
187 public CharSequence getLabel() {
188 return mDisconnectLabel;
189 }
190
191 /**
192 * Returns a description which explains the reason for the disconnect cause and is for display
Santos Cordonc1ec9312015-04-24 11:26:01 -0700193 * in the user interface. This optional text is generally a longer and more descriptive version
194 * of {@link #getLabel}, however it can exist even if {@link #getLabel} is empty. The In-Call UI
195 * should display this relatively prominently; the traditional implementation displays this as
196 * an alert dialog. The {@link ConnectionService} is responsible for providing and localizing
197 * this message. If there is no string provided, returns null.
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700198 *
199 * @return The disconnect description.
200 */
201 public CharSequence getDescription() {
202 return mDisconnectDescription;
203 }
204
205 /**
206 * Returns an explanation of the reason for the disconnect. This is not intended for display to
207 * the user and is used mainly for logging.
208 *
209 * @return The disconnect reason.
210 */
211 public String getReason() {
212 return mDisconnectReason;
213 }
214
215 /**
216 * Returns the tone to play when disconnected.
217 *
218 * @return the tone as defined in {@link ToneGenerator} to play when disconnected.
219 */
220 public int getTone() {
221 return mToneToPlay;
222 }
223
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700224 public static final @android.annotation.NonNull Creator<DisconnectCause> CREATOR = new Creator<DisconnectCause>() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700225 @Override
226 public DisconnectCause createFromParcel(Parcel source) {
227 int code = source.readInt();
228 CharSequence label = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
229 CharSequence description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
230 String reason = source.readString();
231 int tone = source.readInt();
232 return new DisconnectCause(code, label, description, reason, tone);
233 }
234
235 @Override
236 public DisconnectCause[] newArray(int size) {
237 return new DisconnectCause[size];
238 }
239 };
240
241 @Override
242 public void writeToParcel(Parcel destination, int flags) {
243 destination.writeInt(mDisconnectCode);
244 TextUtils.writeToParcel(mDisconnectLabel, destination, flags);
245 TextUtils.writeToParcel(mDisconnectDescription, destination, flags);
246 destination.writeString(mDisconnectReason);
247 destination.writeInt(mToneToPlay);
248 }
249
250 @Override
251 public int describeContents() {
252 return 0;
253 }
254
255 @Override
256 public int hashCode() {
257 return Objects.hashCode(mDisconnectCode)
258 + Objects.hashCode(mDisconnectLabel)
259 + Objects.hashCode(mDisconnectDescription)
260 + Objects.hashCode(mDisconnectReason)
261 + Objects.hashCode(mToneToPlay);
262 }
263
264 @Override
265 public boolean equals(Object o) {
266 if (o instanceof DisconnectCause) {
267 DisconnectCause d = (DisconnectCause) o;
268 return Objects.equals(mDisconnectCode, d.getCode())
269 && Objects.equals(mDisconnectLabel, d.getLabel())
270 && Objects.equals(mDisconnectDescription, d.getDescription())
271 && Objects.equals(mDisconnectReason, d.getReason())
272 && Objects.equals(mToneToPlay, d.getTone());
273 }
274 return false;
275 }
276
277 @Override
278 public String toString() {
279 String code = "";
Sailesh Nepal7a69c922014-11-05 18:37:53 -0800280 switch (mDisconnectCode) {
281 case UNKNOWN:
282 code = "UNKNOWN";
283 break;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700284 case ERROR:
285 code = "ERROR";
286 break;
287 case LOCAL:
288 code = "LOCAL";
289 break;
290 case REMOTE:
291 code = "REMOTE";
292 break;
Sailesh Nepal7a69c922014-11-05 18:37:53 -0800293 case CANCELED:
294 code = "CANCELED";
295 break;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700296 case MISSED:
297 code = "MISSED";
298 break;
299 case REJECTED:
300 code = "REJECTED";
301 break;
302 case BUSY:
303 code = "BUSY";
304 break;
305 case RESTRICTED:
306 code = "RESTRICTED";
307 break;
308 case OTHER:
309 code = "OTHER";
310 break;
Sailesh Nepal7a69c922014-11-05 18:37:53 -0800311 case CONNECTION_MANAGER_NOT_SUPPORTED:
312 code = "CONNECTION_MANAGER_NOT_SUPPORTED";
313 break;
Tyler Gunn2a3f9972016-06-09 07:58:25 -0700314 case CALL_PULLED:
315 code = "CALL_PULLED";
316 break;
317 case ANSWERED_ELSEWHERE:
318 code = "ANSWERED_ELSEWHERE";
319 break;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700320 default:
Sailesh Nepal7a69c922014-11-05 18:37:53 -0800321 code = "invalid code: " + mDisconnectCode;
322 break;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700323 }
324 String label = mDisconnectLabel == null ? "" : mDisconnectLabel.toString();
325 String description = mDisconnectDescription == null
326 ? "" : mDisconnectDescription.toString();
327 String reason = mDisconnectReason == null ? "" : mDisconnectReason;
328 return "DisconnectCause [ Code: (" + code + ")"
329 + " Label: (" + label + ")"
330 + " Description: (" + description + ")"
331 + " Reason: (" + reason + ")"
332 + " Tone: (" + mToneToPlay + ") ]";
333 }
334}