Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.telecom; |
| 18 | |
| 19 | import android.os.Parcel; |
| 20 | import android.os.Parcelable; |
| 21 | import android.media.ToneGenerator; |
| 22 | import android.text.TextUtils; |
| 23 | |
| 24 | import java.util.Objects; |
| 25 | |
| 26 | /** |
| 27 | * Describes the cause of a disconnected call. This always includes a code describing the generic |
Santos Cordon | d9e614f | 2014-10-28 13:10:36 -0700 | [diff] [blame] | 28 | * 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 Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 32 | */ |
| 33 | public 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 Nepal | 7a69c92 | 2014-11-05 18:37:53 -0800 | [diff] [blame] | 61 | /** |
| 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 Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 66 | |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 67 | /** |
| 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 | |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 78 | private int mDisconnectCode; |
| 79 | private CharSequence mDisconnectLabel; |
| 80 | private CharSequence mDisconnectDescription; |
| 81 | private String mDisconnectReason; |
| 82 | private int mToneToPlay; |
| 83 | |
| 84 | /** |
| 85 | * Creates a new DisconnectCause. |
| 86 | * |
| 87 | * @param code The code for the disconnect cause. |
| 88 | */ |
| 89 | public DisconnectCause(int code) { |
| 90 | this(code, null, null, null, ToneGenerator.TONE_UNKNOWN); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Creates a new DisconnectCause. |
| 95 | * |
| 96 | * @param code The code for the disconnect cause. |
| 97 | * @param reason The reason for the disconnect. |
| 98 | */ |
| 99 | public DisconnectCause(int code, String reason) { |
| 100 | this(code, null, null, reason, ToneGenerator.TONE_UNKNOWN); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Creates a new DisconnectCause. |
Santos Cordon | d9e614f | 2014-10-28 13:10:36 -0700 | [diff] [blame] | 105 | * |
Nancy Chen | f4cf77c | 2014-09-19 10:53:21 -0700 | [diff] [blame] | 106 | * @param code The code for the disconnect cause. |
Santos Cordon | a6018b9 | 2016-02-16 14:23:12 -0800 | [diff] [blame] | 107 | * @param label The localized label to show to the user to explain the disconnect. |
Nancy Chen | f4cf77c | 2014-09-19 10:53:21 -0700 | [diff] [blame] | 108 | * @param description The localized description to show to the user to explain the disconnect. |
| 109 | * @param reason The reason for the disconnect. |
| 110 | */ |
| 111 | public DisconnectCause(int code, CharSequence label, CharSequence description, String reason) { |
| 112 | this(code, label, description, reason, ToneGenerator.TONE_UNKNOWN); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Creates a new DisconnectCause. |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 117 | * |
| 118 | * @param code The code for the disconnect cause. |
| 119 | * @param label The localized label to show to the user to explain the disconnect. |
| 120 | * @param description The localized description to show to the user to explain the disconnect. |
| 121 | * @param reason The reason for the disconnect. |
| 122 | * @param toneToPlay The tone to play on disconnect, as defined in {@link ToneGenerator}. |
| 123 | */ |
| 124 | public DisconnectCause(int code, CharSequence label, CharSequence description, String reason, |
| 125 | int toneToPlay) { |
| 126 | mDisconnectCode = code; |
| 127 | mDisconnectLabel = label; |
| 128 | mDisconnectDescription = description; |
| 129 | mDisconnectReason = reason; |
| 130 | mToneToPlay = toneToPlay; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Returns the code for the reason for this disconnect. |
| 135 | * |
| 136 | * @return The disconnect code. |
| 137 | */ |
| 138 | public int getCode() { |
| 139 | return mDisconnectCode; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Returns a short label which explains the reason for the disconnect cause and is for display |
Santos Cordon | c1ec931 | 2015-04-24 11:26:01 -0700 | [diff] [blame] | 144 | * in the user interface. If not null, it is expected that the In-Call UI should display this |
| 145 | * text where it would normally display the call state ("Dialing", "Disconnected") and is |
| 146 | * therefore expected to be relatively small. The {@link ConnectionService } is responsible for |
| 147 | * providing and localizing this label. If there is no string provided, returns null. |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 148 | * |
| 149 | * @return The disconnect label. |
| 150 | */ |
| 151 | public CharSequence getLabel() { |
| 152 | return mDisconnectLabel; |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Returns a description which explains the reason for the disconnect cause and is for display |
Santos Cordon | c1ec931 | 2015-04-24 11:26:01 -0700 | [diff] [blame] | 157 | * in the user interface. This optional text is generally a longer and more descriptive version |
| 158 | * of {@link #getLabel}, however it can exist even if {@link #getLabel} is empty. The In-Call UI |
| 159 | * should display this relatively prominently; the traditional implementation displays this as |
| 160 | * an alert dialog. The {@link ConnectionService} is responsible for providing and localizing |
| 161 | * this message. If there is no string provided, returns null. |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 162 | * |
| 163 | * @return The disconnect description. |
| 164 | */ |
| 165 | public CharSequence getDescription() { |
| 166 | return mDisconnectDescription; |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * Returns an explanation of the reason for the disconnect. This is not intended for display to |
| 171 | * the user and is used mainly for logging. |
| 172 | * |
| 173 | * @return The disconnect reason. |
| 174 | */ |
| 175 | public String getReason() { |
| 176 | return mDisconnectReason; |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Returns the tone to play when disconnected. |
| 181 | * |
| 182 | * @return the tone as defined in {@link ToneGenerator} to play when disconnected. |
| 183 | */ |
| 184 | public int getTone() { |
| 185 | return mToneToPlay; |
| 186 | } |
| 187 | |
| 188 | public static final Creator<DisconnectCause> CREATOR = new Creator<DisconnectCause>() { |
| 189 | @Override |
| 190 | public DisconnectCause createFromParcel(Parcel source) { |
| 191 | int code = source.readInt(); |
| 192 | CharSequence label = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); |
| 193 | CharSequence description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); |
| 194 | String reason = source.readString(); |
| 195 | int tone = source.readInt(); |
| 196 | return new DisconnectCause(code, label, description, reason, tone); |
| 197 | } |
| 198 | |
| 199 | @Override |
| 200 | public DisconnectCause[] newArray(int size) { |
| 201 | return new DisconnectCause[size]; |
| 202 | } |
| 203 | }; |
| 204 | |
| 205 | @Override |
| 206 | public void writeToParcel(Parcel destination, int flags) { |
| 207 | destination.writeInt(mDisconnectCode); |
| 208 | TextUtils.writeToParcel(mDisconnectLabel, destination, flags); |
| 209 | TextUtils.writeToParcel(mDisconnectDescription, destination, flags); |
| 210 | destination.writeString(mDisconnectReason); |
| 211 | destination.writeInt(mToneToPlay); |
| 212 | } |
| 213 | |
| 214 | @Override |
| 215 | public int describeContents() { |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | @Override |
| 220 | public int hashCode() { |
| 221 | return Objects.hashCode(mDisconnectCode) |
| 222 | + Objects.hashCode(mDisconnectLabel) |
| 223 | + Objects.hashCode(mDisconnectDescription) |
| 224 | + Objects.hashCode(mDisconnectReason) |
| 225 | + Objects.hashCode(mToneToPlay); |
| 226 | } |
| 227 | |
| 228 | @Override |
| 229 | public boolean equals(Object o) { |
| 230 | if (o instanceof DisconnectCause) { |
| 231 | DisconnectCause d = (DisconnectCause) o; |
| 232 | return Objects.equals(mDisconnectCode, d.getCode()) |
| 233 | && Objects.equals(mDisconnectLabel, d.getLabel()) |
| 234 | && Objects.equals(mDisconnectDescription, d.getDescription()) |
| 235 | && Objects.equals(mDisconnectReason, d.getReason()) |
| 236 | && Objects.equals(mToneToPlay, d.getTone()); |
| 237 | } |
| 238 | return false; |
| 239 | } |
| 240 | |
| 241 | @Override |
| 242 | public String toString() { |
| 243 | String code = ""; |
Sailesh Nepal | 7a69c92 | 2014-11-05 18:37:53 -0800 | [diff] [blame] | 244 | switch (mDisconnectCode) { |
| 245 | case UNKNOWN: |
| 246 | code = "UNKNOWN"; |
| 247 | break; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 248 | case ERROR: |
| 249 | code = "ERROR"; |
| 250 | break; |
| 251 | case LOCAL: |
| 252 | code = "LOCAL"; |
| 253 | break; |
| 254 | case REMOTE: |
| 255 | code = "REMOTE"; |
| 256 | break; |
Sailesh Nepal | 7a69c92 | 2014-11-05 18:37:53 -0800 | [diff] [blame] | 257 | case CANCELED: |
| 258 | code = "CANCELED"; |
| 259 | break; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 260 | case MISSED: |
| 261 | code = "MISSED"; |
| 262 | break; |
| 263 | case REJECTED: |
| 264 | code = "REJECTED"; |
| 265 | break; |
| 266 | case BUSY: |
| 267 | code = "BUSY"; |
| 268 | break; |
| 269 | case RESTRICTED: |
| 270 | code = "RESTRICTED"; |
| 271 | break; |
| 272 | case OTHER: |
| 273 | code = "OTHER"; |
| 274 | break; |
Sailesh Nepal | 7a69c92 | 2014-11-05 18:37:53 -0800 | [diff] [blame] | 275 | case CONNECTION_MANAGER_NOT_SUPPORTED: |
| 276 | code = "CONNECTION_MANAGER_NOT_SUPPORTED"; |
| 277 | break; |
Tyler Gunn | 2a3f997 | 2016-06-09 07:58:25 -0700 | [diff] [blame] | 278 | case CALL_PULLED: |
| 279 | code = "CALL_PULLED"; |
| 280 | break; |
| 281 | case ANSWERED_ELSEWHERE: |
| 282 | code = "ANSWERED_ELSEWHERE"; |
| 283 | break; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 284 | default: |
Sailesh Nepal | 7a69c92 | 2014-11-05 18:37:53 -0800 | [diff] [blame] | 285 | code = "invalid code: " + mDisconnectCode; |
| 286 | break; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 287 | } |
| 288 | String label = mDisconnectLabel == null ? "" : mDisconnectLabel.toString(); |
| 289 | String description = mDisconnectDescription == null |
| 290 | ? "" : mDisconnectDescription.toString(); |
| 291 | String reason = mDisconnectReason == null ? "" : mDisconnectReason; |
| 292 | return "DisconnectCause [ Code: (" + code + ")" |
| 293 | + " Label: (" + label + ")" |
| 294 | + " Description: (" + description + ")" |
| 295 | + " Reason: (" + reason + ")" |
| 296 | + " Tone: (" + mToneToPlay + ") ]"; |
| 297 | } |
| 298 | } |