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 | |
Youming Ye | d6de26e | 2019-01-30 11:20:35 -0800 | [diff] [blame] | 19 | import android.media.ToneGenerator; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 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. */ |
Tej Singh | c477d9c | 2018-02-05 18:31:39 -0800 | [diff] [blame] | 36 | public static final int UNKNOWN = TelecomProtoEnums.UNKNOWN; // = 0 |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 37 | /** Disconnected because there was an error, such as a problem with the network. */ |
Tej Singh | c477d9c | 2018-02-05 18:31:39 -0800 | [diff] [blame] | 38 | public static final int ERROR = TelecomProtoEnums.ERROR; // = 1 |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 39 | /** Disconnected because of a local user-initiated action, such as hanging up. */ |
Tej Singh | c477d9c | 2018-02-05 18:31:39 -0800 | [diff] [blame] | 40 | public static final int LOCAL = TelecomProtoEnums.LOCAL; // = 2 |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 41 | /** |
| 42 | * Disconnected because of a remote user-initiated action, such as the other party hanging up |
| 43 | * up. |
| 44 | */ |
Tej Singh | c477d9c | 2018-02-05 18:31:39 -0800 | [diff] [blame] | 45 | public static final int REMOTE = TelecomProtoEnums.REMOTE; // = 3 |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 46 | /** Disconnected because it has been canceled. */ |
Tej Singh | c477d9c | 2018-02-05 18:31:39 -0800 | [diff] [blame] | 47 | public static final int CANCELED = TelecomProtoEnums.CANCELED; // = 4 |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 48 | /** Disconnected because there was no response to an incoming call. */ |
Tej Singh | c477d9c | 2018-02-05 18:31:39 -0800 | [diff] [blame] | 49 | public static final int MISSED = TelecomProtoEnums.MISSED; // = 5 |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 50 | /** Disconnected because the user rejected an incoming call. */ |
Tej Singh | c477d9c | 2018-02-05 18:31:39 -0800 | [diff] [blame] | 51 | public static final int REJECTED = TelecomProtoEnums.REJECTED; // = 6 |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 52 | /** Disconnected because the other party was busy. */ |
Tej Singh | c477d9c | 2018-02-05 18:31:39 -0800 | [diff] [blame] | 53 | public static final int BUSY = TelecomProtoEnums.BUSY; // = 7 |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 54 | /** |
| 55 | * Disconnected because of a restriction on placing the call, such as dialing in airplane |
| 56 | * mode. |
| 57 | */ |
Tej Singh | c477d9c | 2018-02-05 18:31:39 -0800 | [diff] [blame] | 58 | public static final int RESTRICTED = TelecomProtoEnums.RESTRICTED; // = 8 |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 59 | /** Disconnected for reason not described by other disconnect codes. */ |
Tej Singh | c477d9c | 2018-02-05 18:31:39 -0800 | [diff] [blame] | 60 | public static final int OTHER = TelecomProtoEnums.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 | */ |
Tej Singh | c477d9c | 2018-02-05 18:31:39 -0800 | [diff] [blame] | 65 | public static final int CONNECTION_MANAGER_NOT_SUPPORTED = |
| 66 | TelecomProtoEnums.CONNECTION_MANAGER_NOT_SUPPORTED; // = 10 |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 67 | |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 68 | /** |
| 69 | * Disconnected because the user did not locally answer the incoming call, but it was answered |
| 70 | * on another device where the call was ringing. |
| 71 | */ |
Tej Singh | c477d9c | 2018-02-05 18:31:39 -0800 | [diff] [blame] | 72 | public static final int ANSWERED_ELSEWHERE = TelecomProtoEnums.ANSWERED_ELSEWHERE; // = 11 |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 73 | |
| 74 | /** |
| 75 | * Disconnected because the call was pulled from the current device to another device. |
| 76 | */ |
Tej Singh | c477d9c | 2018-02-05 18:31:39 -0800 | [diff] [blame] | 77 | public static final int CALL_PULLED = TelecomProtoEnums.CALL_PULLED; // = 12 |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 78 | |
Tyler Gunn | 6adbd2b | 2016-12-07 13:19:44 -0800 | [diff] [blame] | 79 | /** |
| 80 | * Reason code (returned via {@link #getReason()}) which indicates that a call could not be |
| 81 | * completed because the cellular radio is off or out of service, the device is connected to |
| 82 | * a wifi network, but the user has not enabled wifi calling. |
| 83 | * @hide |
| 84 | */ |
| 85 | public static final String REASON_WIFI_ON_BUT_WFC_OFF = "REASON_WIFI_ON_BUT_WFC_OFF"; |
| 86 | |
Brad Ebinger | 8818c6f | 2017-06-30 15:34:32 -0700 | [diff] [blame] | 87 | /** |
| 88 | * Reason code (returned via {@link #getReason()}), which indicates that the video telephony |
| 89 | * call was disconnected because IMS access is blocked. |
| 90 | * @hide |
| 91 | */ |
| 92 | public static final String REASON_IMS_ACCESS_BLOCKED = "REASON_IMS_ACCESS_BLOCKED"; |
| 93 | |
Youming Ye | d6de26e | 2019-01-30 11:20:35 -0800 | [diff] [blame] | 94 | /** |
| 95 | * Reason code, which indicates that the conference call is simulating single party conference. |
| 96 | * @hide |
| 97 | */ |
| 98 | public static final String REASON_EMULATING_SINGLE_CALL = "EMULATING_SINGLE_CALL"; |
| 99 | |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 100 | private int mDisconnectCode; |
| 101 | private CharSequence mDisconnectLabel; |
| 102 | private CharSequence mDisconnectDescription; |
| 103 | private String mDisconnectReason; |
| 104 | private int mToneToPlay; |
| 105 | |
| 106 | /** |
| 107 | * Creates a new DisconnectCause. |
| 108 | * |
| 109 | * @param code The code for the disconnect cause. |
| 110 | */ |
| 111 | public DisconnectCause(int code) { |
| 112 | this(code, null, null, null, ToneGenerator.TONE_UNKNOWN); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Creates a new DisconnectCause. |
| 117 | * |
| 118 | * @param code The code for the disconnect cause. |
| 119 | * @param reason The reason for the disconnect. |
| 120 | */ |
| 121 | public DisconnectCause(int code, String reason) { |
| 122 | this(code, null, null, reason, ToneGenerator.TONE_UNKNOWN); |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Creates a new DisconnectCause. |
Santos Cordon | d9e614f | 2014-10-28 13:10:36 -0700 | [diff] [blame] | 127 | * |
Nancy Chen | f4cf77c | 2014-09-19 10:53:21 -0700 | [diff] [blame] | 128 | * @param code The code for the disconnect cause. |
Santos Cordon | a6018b9 | 2016-02-16 14:23:12 -0800 | [diff] [blame] | 129 | * @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] | 130 | * @param description The localized description to show to the user to explain the disconnect. |
| 131 | * @param reason The reason for the disconnect. |
| 132 | */ |
| 133 | public DisconnectCause(int code, CharSequence label, CharSequence description, String reason) { |
| 134 | this(code, label, description, reason, ToneGenerator.TONE_UNKNOWN); |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Creates a new DisconnectCause. |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 139 | * |
| 140 | * @param code The code for the disconnect cause. |
| 141 | * @param label The localized label to show to the user to explain the disconnect. |
| 142 | * @param description The localized description to show to the user to explain the disconnect. |
| 143 | * @param reason The reason for the disconnect. |
| 144 | * @param toneToPlay The tone to play on disconnect, as defined in {@link ToneGenerator}. |
| 145 | */ |
| 146 | public DisconnectCause(int code, CharSequence label, CharSequence description, String reason, |
| 147 | int toneToPlay) { |
| 148 | mDisconnectCode = code; |
| 149 | mDisconnectLabel = label; |
| 150 | mDisconnectDescription = description; |
| 151 | mDisconnectReason = reason; |
| 152 | mToneToPlay = toneToPlay; |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Returns the code for the reason for this disconnect. |
| 157 | * |
| 158 | * @return The disconnect code. |
| 159 | */ |
| 160 | public int getCode() { |
| 161 | return mDisconnectCode; |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * 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] | 166 | * in the user interface. If not null, it is expected that the In-Call UI should display this |
| 167 | * text where it would normally display the call state ("Dialing", "Disconnected") and is |
| 168 | * therefore expected to be relatively small. The {@link ConnectionService } is responsible for |
| 169 | * 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] | 170 | * |
| 171 | * @return The disconnect label. |
| 172 | */ |
| 173 | public CharSequence getLabel() { |
| 174 | return mDisconnectLabel; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * 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] | 179 | * in the user interface. This optional text is generally a longer and more descriptive version |
| 180 | * of {@link #getLabel}, however it can exist even if {@link #getLabel} is empty. The In-Call UI |
| 181 | * should display this relatively prominently; the traditional implementation displays this as |
| 182 | * an alert dialog. The {@link ConnectionService} is responsible for providing and localizing |
| 183 | * this message. If there is no string provided, returns null. |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 184 | * |
| 185 | * @return The disconnect description. |
| 186 | */ |
| 187 | public CharSequence getDescription() { |
| 188 | return mDisconnectDescription; |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Returns an explanation of the reason for the disconnect. This is not intended for display to |
| 193 | * the user and is used mainly for logging. |
| 194 | * |
| 195 | * @return The disconnect reason. |
| 196 | */ |
| 197 | public String getReason() { |
| 198 | return mDisconnectReason; |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Returns the tone to play when disconnected. |
| 203 | * |
| 204 | * @return the tone as defined in {@link ToneGenerator} to play when disconnected. |
| 205 | */ |
| 206 | public int getTone() { |
| 207 | return mToneToPlay; |
| 208 | } |
| 209 | |
| 210 | public static final Creator<DisconnectCause> CREATOR = new Creator<DisconnectCause>() { |
| 211 | @Override |
| 212 | public DisconnectCause createFromParcel(Parcel source) { |
| 213 | int code = source.readInt(); |
| 214 | CharSequence label = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); |
| 215 | CharSequence description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); |
| 216 | String reason = source.readString(); |
| 217 | int tone = source.readInt(); |
| 218 | return new DisconnectCause(code, label, description, reason, tone); |
| 219 | } |
| 220 | |
| 221 | @Override |
| 222 | public DisconnectCause[] newArray(int size) { |
| 223 | return new DisconnectCause[size]; |
| 224 | } |
| 225 | }; |
| 226 | |
| 227 | @Override |
| 228 | public void writeToParcel(Parcel destination, int flags) { |
| 229 | destination.writeInt(mDisconnectCode); |
| 230 | TextUtils.writeToParcel(mDisconnectLabel, destination, flags); |
| 231 | TextUtils.writeToParcel(mDisconnectDescription, destination, flags); |
| 232 | destination.writeString(mDisconnectReason); |
| 233 | destination.writeInt(mToneToPlay); |
| 234 | } |
| 235 | |
| 236 | @Override |
| 237 | public int describeContents() { |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | @Override |
| 242 | public int hashCode() { |
| 243 | return Objects.hashCode(mDisconnectCode) |
| 244 | + Objects.hashCode(mDisconnectLabel) |
| 245 | + Objects.hashCode(mDisconnectDescription) |
| 246 | + Objects.hashCode(mDisconnectReason) |
| 247 | + Objects.hashCode(mToneToPlay); |
| 248 | } |
| 249 | |
| 250 | @Override |
| 251 | public boolean equals(Object o) { |
| 252 | if (o instanceof DisconnectCause) { |
| 253 | DisconnectCause d = (DisconnectCause) o; |
| 254 | return Objects.equals(mDisconnectCode, d.getCode()) |
| 255 | && Objects.equals(mDisconnectLabel, d.getLabel()) |
| 256 | && Objects.equals(mDisconnectDescription, d.getDescription()) |
| 257 | && Objects.equals(mDisconnectReason, d.getReason()) |
| 258 | && Objects.equals(mToneToPlay, d.getTone()); |
| 259 | } |
| 260 | return false; |
| 261 | } |
| 262 | |
| 263 | @Override |
| 264 | public String toString() { |
| 265 | String code = ""; |
Sailesh Nepal | 7a69c92 | 2014-11-05 18:37:53 -0800 | [diff] [blame] | 266 | switch (mDisconnectCode) { |
| 267 | case UNKNOWN: |
| 268 | code = "UNKNOWN"; |
| 269 | break; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 270 | case ERROR: |
| 271 | code = "ERROR"; |
| 272 | break; |
| 273 | case LOCAL: |
| 274 | code = "LOCAL"; |
| 275 | break; |
| 276 | case REMOTE: |
| 277 | code = "REMOTE"; |
| 278 | break; |
Sailesh Nepal | 7a69c92 | 2014-11-05 18:37:53 -0800 | [diff] [blame] | 279 | case CANCELED: |
| 280 | code = "CANCELED"; |
| 281 | break; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 282 | case MISSED: |
| 283 | code = "MISSED"; |
| 284 | break; |
| 285 | case REJECTED: |
| 286 | code = "REJECTED"; |
| 287 | break; |
| 288 | case BUSY: |
| 289 | code = "BUSY"; |
| 290 | break; |
| 291 | case RESTRICTED: |
| 292 | code = "RESTRICTED"; |
| 293 | break; |
| 294 | case OTHER: |
| 295 | code = "OTHER"; |
| 296 | break; |
Sailesh Nepal | 7a69c92 | 2014-11-05 18:37:53 -0800 | [diff] [blame] | 297 | case CONNECTION_MANAGER_NOT_SUPPORTED: |
| 298 | code = "CONNECTION_MANAGER_NOT_SUPPORTED"; |
| 299 | break; |
Tyler Gunn | 2a3f997 | 2016-06-09 07:58:25 -0700 | [diff] [blame] | 300 | case CALL_PULLED: |
| 301 | code = "CALL_PULLED"; |
| 302 | break; |
| 303 | case ANSWERED_ELSEWHERE: |
| 304 | code = "ANSWERED_ELSEWHERE"; |
| 305 | break; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 306 | default: |
Sailesh Nepal | 7a69c92 | 2014-11-05 18:37:53 -0800 | [diff] [blame] | 307 | code = "invalid code: " + mDisconnectCode; |
| 308 | break; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 309 | } |
| 310 | String label = mDisconnectLabel == null ? "" : mDisconnectLabel.toString(); |
| 311 | String description = mDisconnectDescription == null |
| 312 | ? "" : mDisconnectDescription.toString(); |
| 313 | String reason = mDisconnectReason == null ? "" : mDisconnectReason; |
| 314 | return "DisconnectCause [ Code: (" + code + ")" |
| 315 | + " Label: (" + label + ")" |
| 316 | + " Description: (" + description + ")" |
| 317 | + " Reason: (" + reason + ")" |
| 318 | + " Tone: (" + mToneToPlay + ") ]"; |
| 319 | } |
| 320 | } |