blob: cab4d39d88337c0a531058a991a2ce76d1321ecb [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 Gunn711d876fd2014-09-19 11:17:02 -070019import android.annotation.SystemApi;
Andrew Lee7f3d41f2014-09-11 17:33:16 -070020import android.os.Parcel;
21import android.os.Parcelable;
22import android.media.ToneGenerator;
23import 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 Cordond3a0b162014-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.
Tyler Gunn711d876fd2014-09-19 11:17:02 -070033 * @hide
Andrew Lee7f3d41f2014-09-11 17:33:16 -070034 */
Tyler Gunn711d876fd2014-09-19 11:17:02 -070035@SystemApi
Andrew Lee7f3d41f2014-09-11 17:33:16 -070036public final class DisconnectCause implements Parcelable {
37
38 /** Disconnected because of an unknown or unspecified reason. */
39 public static final int UNKNOWN = 0;
40 /** Disconnected because there was an error, such as a problem with the network. */
41 public static final int ERROR = 1;
42 /** Disconnected because of a local user-initiated action, such as hanging up. */
43 public static final int LOCAL = 2;
44 /**
45 * Disconnected because of a remote user-initiated action, such as the other party hanging up
46 * up.
47 */
48 public static final int REMOTE = 3;
49 /** Disconnected because it has been canceled. */
50 public static final int CANCELED = 4;
51 /** Disconnected because there was no response to an incoming call. */
52 public static final int MISSED = 5;
53 /** Disconnected because the user rejected an incoming call. */
54 public static final int REJECTED = 6;
55 /** Disconnected because the other party was busy. */
56 public static final int BUSY = 7;
57 /**
58 * Disconnected because of a restriction on placing the call, such as dialing in airplane
59 * mode.
60 */
61 public static final int RESTRICTED = 8;
62 /** Disconnected for reason not described by other disconnect codes. */
63 public static final int OTHER = 9;
64
Divya Sharma1cb8f692015-02-24 16:25:55 -080065 public static final int CONNECTION_MANAGER_NOT_SUPPORTED = 10;
66
Andrew Lee7f3d41f2014-09-11 17:33:16 -070067 private int mDisconnectCode;
68 private CharSequence mDisconnectLabel;
69 private CharSequence mDisconnectDescription;
70 private String mDisconnectReason;
71 private int mToneToPlay;
72
73 /**
74 * Creates a new DisconnectCause.
75 *
76 * @param code The code for the disconnect cause.
77 */
78 public DisconnectCause(int code) {
79 this(code, null, null, null, ToneGenerator.TONE_UNKNOWN);
80 }
81
82 /**
83 * Creates a new DisconnectCause.
84 *
85 * @param code The code for the disconnect cause.
86 * @param reason The reason for the disconnect.
87 */
88 public DisconnectCause(int code, String reason) {
89 this(code, null, null, reason, ToneGenerator.TONE_UNKNOWN);
90 }
91
92 /**
93 * Creates a new DisconnectCause.
Santos Cordond3a0b162014-10-28 13:10:36 -070094 *
Nancy Chenf4cf77c2014-09-19 10:53:21 -070095 * @param label The localized label to show to the user to explain the disconnect.
96 * @param code The code for the disconnect cause.
97 * @param description The localized description to show to the user to explain the disconnect.
98 * @param reason The reason for the disconnect.
99 */
100 public DisconnectCause(int code, CharSequence label, CharSequence description, String reason) {
101 this(code, label, description, reason, ToneGenerator.TONE_UNKNOWN);
102 }
103
104 /**
105 * Creates a new DisconnectCause.
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700106 *
107 * @param code The code for the disconnect cause.
108 * @param label The localized label to show to the user to explain the disconnect.
109 * @param description The localized description to show to the user to explain the disconnect.
110 * @param reason The reason for the disconnect.
111 * @param toneToPlay The tone to play on disconnect, as defined in {@link ToneGenerator}.
112 */
113 public DisconnectCause(int code, CharSequence label, CharSequence description, String reason,
114 int toneToPlay) {
115 mDisconnectCode = code;
116 mDisconnectLabel = label;
117 mDisconnectDescription = description;
118 mDisconnectReason = reason;
119 mToneToPlay = toneToPlay;
120 }
121
122 /**
123 * Returns the code for the reason for this disconnect.
124 *
125 * @return The disconnect code.
126 */
127 public int getCode() {
128 return mDisconnectCode;
129 }
130
131 /**
132 * Returns a short label which explains the reason for the disconnect cause and is for display
133 * in the user interface. The {@link ConnectionService } is responsible for providing and
134 * localizing this label. If there is no string provided, returns null.
135 *
136 * @return The disconnect label.
137 */
138 public CharSequence getLabel() {
139 return mDisconnectLabel;
140 }
141
142 /**
143 * Returns a description which explains the reason for the disconnect cause and is for display
144 * in the user interface. The {@link ConnectionService } is responsible for providing and
145 * localizing this message. If there is no string provided, returns null.
146 *
147 * @return The disconnect description.
148 */
149 public CharSequence getDescription() {
150 return mDisconnectDescription;
151 }
152
153 /**
154 * Returns an explanation of the reason for the disconnect. This is not intended for display to
155 * the user and is used mainly for logging.
156 *
157 * @return The disconnect reason.
158 */
159 public String getReason() {
160 return mDisconnectReason;
161 }
162
163 /**
164 * Returns the tone to play when disconnected.
165 *
166 * @return the tone as defined in {@link ToneGenerator} to play when disconnected.
167 */
168 public int getTone() {
169 return mToneToPlay;
170 }
171
172 public static final Creator<DisconnectCause> CREATOR = new Creator<DisconnectCause>() {
173 @Override
174 public DisconnectCause createFromParcel(Parcel source) {
175 int code = source.readInt();
176 CharSequence label = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
177 CharSequence description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
178 String reason = source.readString();
179 int tone = source.readInt();
180 return new DisconnectCause(code, label, description, reason, tone);
181 }
182
183 @Override
184 public DisconnectCause[] newArray(int size) {
185 return new DisconnectCause[size];
186 }
187 };
188
189 @Override
190 public void writeToParcel(Parcel destination, int flags) {
191 destination.writeInt(mDisconnectCode);
192 TextUtils.writeToParcel(mDisconnectLabel, destination, flags);
193 TextUtils.writeToParcel(mDisconnectDescription, destination, flags);
194 destination.writeString(mDisconnectReason);
195 destination.writeInt(mToneToPlay);
196 }
197
198 @Override
199 public int describeContents() {
200 return 0;
201 }
202
203 @Override
204 public int hashCode() {
205 return Objects.hashCode(mDisconnectCode)
206 + Objects.hashCode(mDisconnectLabel)
207 + Objects.hashCode(mDisconnectDescription)
208 + Objects.hashCode(mDisconnectReason)
209 + Objects.hashCode(mToneToPlay);
210 }
211
212 @Override
213 public boolean equals(Object o) {
214 if (o instanceof DisconnectCause) {
215 DisconnectCause d = (DisconnectCause) o;
216 return Objects.equals(mDisconnectCode, d.getCode())
217 && Objects.equals(mDisconnectLabel, d.getLabel())
218 && Objects.equals(mDisconnectDescription, d.getDescription())
219 && Objects.equals(mDisconnectReason, d.getReason())
220 && Objects.equals(mToneToPlay, d.getTone());
221 }
222 return false;
223 }
224
225 @Override
226 public String toString() {
227 String code = "";
228 switch (getCode()) {
229 case ERROR:
230 code = "ERROR";
231 break;
232 case LOCAL:
233 code = "LOCAL";
234 break;
235 case REMOTE:
236 code = "REMOTE";
237 break;
238 case MISSED:
239 code = "MISSED";
240 break;
241 case REJECTED:
242 code = "REJECTED";
243 break;
244 case BUSY:
245 code = "BUSY";
246 break;
247 case RESTRICTED:
248 code = "RESTRICTED";
249 break;
250 case OTHER:
251 code = "OTHER";
252 break;
253 case UNKNOWN:
254 default:
255 code = "UNKNOWN";
256 }
257 String label = mDisconnectLabel == null ? "" : mDisconnectLabel.toString();
258 String description = mDisconnectDescription == null
259 ? "" : mDisconnectDescription.toString();
260 String reason = mDisconnectReason == null ? "" : mDisconnectReason;
261 return "DisconnectCause [ Code: (" + code + ")"
262 + " Label: (" + label + ")"
263 + " Description: (" + description + ")"
264 + " Reason: (" + reason + ")"
265 + " Tone: (" + mToneToPlay + ") ]";
266 }
267}