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 | |
Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
| 22 | import android.media.ToneGenerator; |
| 23 | import android.text.TextUtils; |
| 24 | |
| 25 | import java.util.Objects; |
| 26 | |
| 27 | /** |
| 28 | * 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] | 29 | * 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. |
Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame] | 33 | * @hide |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 34 | */ |
Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame] | 35 | @SystemApi |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 36 | public 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; |
Sailesh Nepal | 7a69c92 | 2014-11-05 18:37:53 -0800 | [diff] [blame] | 64 | /** |
| 65 | * Disconnected because the connection manager did not support the call. The call will be tried |
| 66 | * again without a connection manager. See {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. |
| 67 | */ |
| 68 | public static final int CONNECTION_MANAGER_NOT_SUPPORTED = 10; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 69 | |
| 70 | private int mDisconnectCode; |
| 71 | private CharSequence mDisconnectLabel; |
| 72 | private CharSequence mDisconnectDescription; |
| 73 | private String mDisconnectReason; |
| 74 | private int mToneToPlay; |
| 75 | |
| 76 | /** |
| 77 | * Creates a new DisconnectCause. |
| 78 | * |
| 79 | * @param code The code for the disconnect cause. |
| 80 | */ |
| 81 | public DisconnectCause(int code) { |
| 82 | this(code, null, null, null, ToneGenerator.TONE_UNKNOWN); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Creates a new DisconnectCause. |
| 87 | * |
| 88 | * @param code The code for the disconnect cause. |
| 89 | * @param reason The reason for the disconnect. |
| 90 | */ |
| 91 | public DisconnectCause(int code, String reason) { |
| 92 | this(code, null, null, reason, ToneGenerator.TONE_UNKNOWN); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Creates a new DisconnectCause. |
Santos Cordon | d9e614f | 2014-10-28 13:10:36 -0700 | [diff] [blame] | 97 | * |
Nancy Chen | f4cf77c | 2014-09-19 10:53:21 -0700 | [diff] [blame] | 98 | * @param label The localized label to show to the user to explain the disconnect. |
| 99 | * @param code The code for the disconnect cause. |
| 100 | * @param description The localized description to show to the user to explain the disconnect. |
| 101 | * @param reason The reason for the disconnect. |
| 102 | */ |
| 103 | public DisconnectCause(int code, CharSequence label, CharSequence description, String reason) { |
| 104 | this(code, label, description, reason, ToneGenerator.TONE_UNKNOWN); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Creates a new DisconnectCause. |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 109 | * |
| 110 | * @param code The code for the disconnect cause. |
| 111 | * @param label The localized label to show to the user to explain the disconnect. |
| 112 | * @param description The localized description to show to the user to explain the disconnect. |
| 113 | * @param reason The reason for the disconnect. |
| 114 | * @param toneToPlay The tone to play on disconnect, as defined in {@link ToneGenerator}. |
| 115 | */ |
| 116 | public DisconnectCause(int code, CharSequence label, CharSequence description, String reason, |
| 117 | int toneToPlay) { |
| 118 | mDisconnectCode = code; |
| 119 | mDisconnectLabel = label; |
| 120 | mDisconnectDescription = description; |
| 121 | mDisconnectReason = reason; |
| 122 | mToneToPlay = toneToPlay; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Returns the code for the reason for this disconnect. |
| 127 | * |
| 128 | * @return The disconnect code. |
| 129 | */ |
| 130 | public int getCode() { |
| 131 | return mDisconnectCode; |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Returns a short label which explains the reason for the disconnect cause and is for display |
| 136 | * in the user interface. The {@link ConnectionService } is responsible for providing and |
| 137 | * localizing this label. If there is no string provided, returns null. |
| 138 | * |
| 139 | * @return The disconnect label. |
| 140 | */ |
| 141 | public CharSequence getLabel() { |
| 142 | return mDisconnectLabel; |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Returns a description which explains the reason for the disconnect cause and is for display |
| 147 | * in the user interface. The {@link ConnectionService } is responsible for providing and |
| 148 | * localizing this message. If there is no string provided, returns null. |
| 149 | * |
| 150 | * @return The disconnect description. |
| 151 | */ |
| 152 | public CharSequence getDescription() { |
| 153 | return mDisconnectDescription; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Returns an explanation of the reason for the disconnect. This is not intended for display to |
| 158 | * the user and is used mainly for logging. |
| 159 | * |
| 160 | * @return The disconnect reason. |
| 161 | */ |
| 162 | public String getReason() { |
| 163 | return mDisconnectReason; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Returns the tone to play when disconnected. |
| 168 | * |
| 169 | * @return the tone as defined in {@link ToneGenerator} to play when disconnected. |
| 170 | */ |
| 171 | public int getTone() { |
| 172 | return mToneToPlay; |
| 173 | } |
| 174 | |
| 175 | public static final Creator<DisconnectCause> CREATOR = new Creator<DisconnectCause>() { |
| 176 | @Override |
| 177 | public DisconnectCause createFromParcel(Parcel source) { |
| 178 | int code = source.readInt(); |
| 179 | CharSequence label = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); |
| 180 | CharSequence description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); |
| 181 | String reason = source.readString(); |
| 182 | int tone = source.readInt(); |
| 183 | return new DisconnectCause(code, label, description, reason, tone); |
| 184 | } |
| 185 | |
| 186 | @Override |
| 187 | public DisconnectCause[] newArray(int size) { |
| 188 | return new DisconnectCause[size]; |
| 189 | } |
| 190 | }; |
| 191 | |
| 192 | @Override |
| 193 | public void writeToParcel(Parcel destination, int flags) { |
| 194 | destination.writeInt(mDisconnectCode); |
| 195 | TextUtils.writeToParcel(mDisconnectLabel, destination, flags); |
| 196 | TextUtils.writeToParcel(mDisconnectDescription, destination, flags); |
| 197 | destination.writeString(mDisconnectReason); |
| 198 | destination.writeInt(mToneToPlay); |
| 199 | } |
| 200 | |
| 201 | @Override |
| 202 | public int describeContents() { |
| 203 | return 0; |
| 204 | } |
| 205 | |
| 206 | @Override |
| 207 | public int hashCode() { |
| 208 | return Objects.hashCode(mDisconnectCode) |
| 209 | + Objects.hashCode(mDisconnectLabel) |
| 210 | + Objects.hashCode(mDisconnectDescription) |
| 211 | + Objects.hashCode(mDisconnectReason) |
| 212 | + Objects.hashCode(mToneToPlay); |
| 213 | } |
| 214 | |
| 215 | @Override |
| 216 | public boolean equals(Object o) { |
| 217 | if (o instanceof DisconnectCause) { |
| 218 | DisconnectCause d = (DisconnectCause) o; |
| 219 | return Objects.equals(mDisconnectCode, d.getCode()) |
| 220 | && Objects.equals(mDisconnectLabel, d.getLabel()) |
| 221 | && Objects.equals(mDisconnectDescription, d.getDescription()) |
| 222 | && Objects.equals(mDisconnectReason, d.getReason()) |
| 223 | && Objects.equals(mToneToPlay, d.getTone()); |
| 224 | } |
| 225 | return false; |
| 226 | } |
| 227 | |
| 228 | @Override |
| 229 | public String toString() { |
| 230 | String code = ""; |
Sailesh Nepal | 7a69c92 | 2014-11-05 18:37:53 -0800 | [diff] [blame] | 231 | switch (mDisconnectCode) { |
| 232 | case UNKNOWN: |
| 233 | code = "UNKNOWN"; |
| 234 | break; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 235 | case ERROR: |
| 236 | code = "ERROR"; |
| 237 | break; |
| 238 | case LOCAL: |
| 239 | code = "LOCAL"; |
| 240 | break; |
| 241 | case REMOTE: |
| 242 | code = "REMOTE"; |
| 243 | break; |
Sailesh Nepal | 7a69c92 | 2014-11-05 18:37:53 -0800 | [diff] [blame] | 244 | case CANCELED: |
| 245 | code = "CANCELED"; |
| 246 | break; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 247 | case MISSED: |
| 248 | code = "MISSED"; |
| 249 | break; |
| 250 | case REJECTED: |
| 251 | code = "REJECTED"; |
| 252 | break; |
| 253 | case BUSY: |
| 254 | code = "BUSY"; |
| 255 | break; |
| 256 | case RESTRICTED: |
| 257 | code = "RESTRICTED"; |
| 258 | break; |
| 259 | case OTHER: |
| 260 | code = "OTHER"; |
| 261 | break; |
Sailesh Nepal | 7a69c92 | 2014-11-05 18:37:53 -0800 | [diff] [blame] | 262 | case CONNECTION_MANAGER_NOT_SUPPORTED: |
| 263 | code = "CONNECTION_MANAGER_NOT_SUPPORTED"; |
| 264 | break; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 265 | default: |
Sailesh Nepal | 7a69c92 | 2014-11-05 18:37:53 -0800 | [diff] [blame] | 266 | code = "invalid code: " + mDisconnectCode; |
| 267 | break; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 268 | } |
| 269 | String label = mDisconnectLabel == null ? "" : mDisconnectLabel.toString(); |
| 270 | String description = mDisconnectDescription == null |
| 271 | ? "" : mDisconnectDescription.toString(); |
| 272 | String reason = mDisconnectReason == null ? "" : mDisconnectReason; |
| 273 | return "DisconnectCause [ Code: (" + code + ")" |
| 274 | + " Label: (" + label + ")" |
| 275 | + " Description: (" + description + ")" |
| 276 | + " Reason: (" + reason + ")" |
| 277 | + " Tone: (" + mToneToPlay + ") ]"; |
| 278 | } |
| 279 | } |