blob: dcf5c271d0ebff4384a51c85c97054c10605c2a4 [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
19import android.os.Parcel;
20import android.os.Parcelable;
21import android.media.ToneGenerator;
22import android.text.TextUtils;
23
24import java.util.Objects;
25
26/**
27 * Describes the cause of a disconnected call. This always includes a code describing the generic
Santos Cordond9e614f2014-10-28 13:10:36 -070028 * cause of the disconnect. Optionally, it may include a label and/or description to display to the
29 * user. It is the responsibility of the {@link ConnectionService} to provide localized versions of
30 * the label and description. It also may contain a reason for the disconnect, which is intended for
31 * logging and not for display to the user.
Andrew Lee7f3d41f2014-09-11 17:33:16 -070032 */
33public final class DisconnectCause implements Parcelable {
34
35 /** Disconnected because of an unknown or unspecified reason. */
36 public static final int UNKNOWN = 0;
37 /** Disconnected because there was an error, such as a problem with the network. */
38 public static final int ERROR = 1;
39 /** Disconnected because of a local user-initiated action, such as hanging up. */
40 public static final int LOCAL = 2;
41 /**
42 * Disconnected because of a remote user-initiated action, such as the other party hanging up
43 * up.
44 */
45 public static final int REMOTE = 3;
46 /** Disconnected because it has been canceled. */
47 public static final int CANCELED = 4;
48 /** Disconnected because there was no response to an incoming call. */
49 public static final int MISSED = 5;
50 /** Disconnected because the user rejected an incoming call. */
51 public static final int REJECTED = 6;
52 /** Disconnected because the other party was busy. */
53 public static final int BUSY = 7;
54 /**
55 * Disconnected because of a restriction on placing the call, such as dialing in airplane
56 * mode.
57 */
58 public static final int RESTRICTED = 8;
59 /** Disconnected for reason not described by other disconnect codes. */
60 public static final int OTHER = 9;
Sailesh Nepal7a69c922014-11-05 18:37:53 -080061 /**
62 * Disconnected because the connection manager did not support the call. The call will be tried
63 * again without a connection manager. See {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
64 */
65 public static final int CONNECTION_MANAGER_NOT_SUPPORTED = 10;
Andrew Lee7f3d41f2014-09-11 17:33:16 -070066
Tyler Gunn876dbfb2016-03-14 15:18:07 -070067 /**
68 * Disconnected because the user did not locally answer the incoming call, but it was answered
69 * on another device where the call was ringing.
70 */
71 public static final int ANSWERED_ELSEWHERE = 11;
72
73 /**
74 * Disconnected because the call was pulled from the current device to another device.
75 */
76 public static final int CALL_PULLED = 12;
77
Tyler Gunn6adbd2b2016-12-07 13:19:44 -080078 /**
79 * Reason code (returned via {@link #getReason()}) which indicates that a call could not be
80 * completed because the cellular radio is off or out of service, the device is connected to
81 * a wifi network, but the user has not enabled wifi calling.
82 * @hide
83 */
84 public static final String REASON_WIFI_ON_BUT_WFC_OFF = "REASON_WIFI_ON_BUT_WFC_OFF";
85
Brad Ebinger8818c6f2017-06-30 15:34:32 -070086 /**
87 * Reason code (returned via {@link #getReason()}), which indicates that the video telephony
88 * call was disconnected because IMS access is blocked.
89 * @hide
90 */
91 public static final String REASON_IMS_ACCESS_BLOCKED = "REASON_IMS_ACCESS_BLOCKED";
92
Andrew Lee7f3d41f2014-09-11 17:33:16 -070093 private int mDisconnectCode;
94 private CharSequence mDisconnectLabel;
95 private CharSequence mDisconnectDescription;
96 private String mDisconnectReason;
97 private int mToneToPlay;
98
99 /**
100 * Creates a new DisconnectCause.
101 *
102 * @param code The code for the disconnect cause.
103 */
104 public DisconnectCause(int code) {
105 this(code, null, null, null, ToneGenerator.TONE_UNKNOWN);
106 }
107
108 /**
109 * Creates a new DisconnectCause.
110 *
111 * @param code The code for the disconnect cause.
112 * @param reason The reason for the disconnect.
113 */
114 public DisconnectCause(int code, String reason) {
115 this(code, null, null, reason, ToneGenerator.TONE_UNKNOWN);
116 }
117
118 /**
119 * Creates a new DisconnectCause.
Santos Cordond9e614f2014-10-28 13:10:36 -0700120 *
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700121 * @param code The code for the disconnect cause.
Santos Cordona6018b92016-02-16 14:23:12 -0800122 * @param label The localized label to show to the user to explain the disconnect.
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700123 * @param description The localized description to show to the user to explain the disconnect.
124 * @param reason The reason for the disconnect.
125 */
126 public DisconnectCause(int code, CharSequence label, CharSequence description, String reason) {
127 this(code, label, description, reason, ToneGenerator.TONE_UNKNOWN);
128 }
129
130 /**
131 * Creates a new DisconnectCause.
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700132 *
133 * @param code The code for the disconnect cause.
134 * @param label The localized label to show to the user to explain the disconnect.
135 * @param description The localized description to show to the user to explain the disconnect.
136 * @param reason The reason for the disconnect.
137 * @param toneToPlay The tone to play on disconnect, as defined in {@link ToneGenerator}.
138 */
139 public DisconnectCause(int code, CharSequence label, CharSequence description, String reason,
140 int toneToPlay) {
141 mDisconnectCode = code;
142 mDisconnectLabel = label;
143 mDisconnectDescription = description;
144 mDisconnectReason = reason;
145 mToneToPlay = toneToPlay;
146 }
147
148 /**
149 * Returns the code for the reason for this disconnect.
150 *
151 * @return The disconnect code.
152 */
153 public int getCode() {
154 return mDisconnectCode;
155 }
156
157 /**
158 * Returns a short label which explains the reason for the disconnect cause and is for display
Santos Cordonc1ec9312015-04-24 11:26:01 -0700159 * in the user interface. If not null, it is expected that the In-Call UI should display this
160 * text where it would normally display the call state ("Dialing", "Disconnected") and is
161 * therefore expected to be relatively small. The {@link ConnectionService } is responsible for
162 * providing and localizing this label. If there is no string provided, returns null.
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700163 *
164 * @return The disconnect label.
165 */
166 public CharSequence getLabel() {
167 return mDisconnectLabel;
168 }
169
170 /**
171 * Returns a description which explains the reason for the disconnect cause and is for display
Santos Cordonc1ec9312015-04-24 11:26:01 -0700172 * in the user interface. This optional text is generally a longer and more descriptive version
173 * of {@link #getLabel}, however it can exist even if {@link #getLabel} is empty. The In-Call UI
174 * should display this relatively prominently; the traditional implementation displays this as
175 * an alert dialog. The {@link ConnectionService} is responsible for providing and localizing
176 * this message. If there is no string provided, returns null.
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700177 *
178 * @return The disconnect description.
179 */
180 public CharSequence getDescription() {
181 return mDisconnectDescription;
182 }
183
184 /**
185 * Returns an explanation of the reason for the disconnect. This is not intended for display to
186 * the user and is used mainly for logging.
187 *
188 * @return The disconnect reason.
189 */
190 public String getReason() {
191 return mDisconnectReason;
192 }
193
194 /**
195 * Returns the tone to play when disconnected.
196 *
197 * @return the tone as defined in {@link ToneGenerator} to play when disconnected.
198 */
199 public int getTone() {
200 return mToneToPlay;
201 }
202
203 public static final Creator<DisconnectCause> CREATOR = new Creator<DisconnectCause>() {
204 @Override
205 public DisconnectCause createFromParcel(Parcel source) {
206 int code = source.readInt();
207 CharSequence label = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
208 CharSequence description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
209 String reason = source.readString();
210 int tone = source.readInt();
211 return new DisconnectCause(code, label, description, reason, tone);
212 }
213
214 @Override
215 public DisconnectCause[] newArray(int size) {
216 return new DisconnectCause[size];
217 }
218 };
219
220 @Override
221 public void writeToParcel(Parcel destination, int flags) {
222 destination.writeInt(mDisconnectCode);
223 TextUtils.writeToParcel(mDisconnectLabel, destination, flags);
224 TextUtils.writeToParcel(mDisconnectDescription, destination, flags);
225 destination.writeString(mDisconnectReason);
226 destination.writeInt(mToneToPlay);
227 }
228
229 @Override
230 public int describeContents() {
231 return 0;
232 }
233
234 @Override
235 public int hashCode() {
236 return Objects.hashCode(mDisconnectCode)
237 + Objects.hashCode(mDisconnectLabel)
238 + Objects.hashCode(mDisconnectDescription)
239 + Objects.hashCode(mDisconnectReason)
240 + Objects.hashCode(mToneToPlay);
241 }
242
243 @Override
244 public boolean equals(Object o) {
245 if (o instanceof DisconnectCause) {
246 DisconnectCause d = (DisconnectCause) o;
247 return Objects.equals(mDisconnectCode, d.getCode())
248 && Objects.equals(mDisconnectLabel, d.getLabel())
249 && Objects.equals(mDisconnectDescription, d.getDescription())
250 && Objects.equals(mDisconnectReason, d.getReason())
251 && Objects.equals(mToneToPlay, d.getTone());
252 }
253 return false;
254 }
255
256 @Override
257 public String toString() {
258 String code = "";
Sailesh Nepal7a69c922014-11-05 18:37:53 -0800259 switch (mDisconnectCode) {
260 case UNKNOWN:
261 code = "UNKNOWN";
262 break;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700263 case ERROR:
264 code = "ERROR";
265 break;
266 case LOCAL:
267 code = "LOCAL";
268 break;
269 case REMOTE:
270 code = "REMOTE";
271 break;
Sailesh Nepal7a69c922014-11-05 18:37:53 -0800272 case CANCELED:
273 code = "CANCELED";
274 break;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700275 case MISSED:
276 code = "MISSED";
277 break;
278 case REJECTED:
279 code = "REJECTED";
280 break;
281 case BUSY:
282 code = "BUSY";
283 break;
284 case RESTRICTED:
285 code = "RESTRICTED";
286 break;
287 case OTHER:
288 code = "OTHER";
289 break;
Sailesh Nepal7a69c922014-11-05 18:37:53 -0800290 case CONNECTION_MANAGER_NOT_SUPPORTED:
291 code = "CONNECTION_MANAGER_NOT_SUPPORTED";
292 break;
Tyler Gunn2a3f9972016-06-09 07:58:25 -0700293 case CALL_PULLED:
294 code = "CALL_PULLED";
295 break;
296 case ANSWERED_ELSEWHERE:
297 code = "ANSWERED_ELSEWHERE";
298 break;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700299 default:
Sailesh Nepal7a69c922014-11-05 18:37:53 -0800300 code = "invalid code: " + mDisconnectCode;
301 break;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700302 }
303 String label = mDisconnectLabel == null ? "" : mDisconnectLabel.toString();
304 String description = mDisconnectDescription == null
305 ? "" : mDisconnectDescription.toString();
306 String reason = mDisconnectReason == null ? "" : mDisconnectReason;
307 return "DisconnectCause [ Code: (" + code + ")"
308 + " Label: (" + label + ")"
309 + " Description: (" + description + ")"
310 + " Reason: (" + reason + ")"
311 + " Tone: (" + mToneToPlay + ") ]";
312 }
313}