summaryrefslogtreecommitdiff
path: root/telecomm/java/android/telecom/DisconnectCause.java
blob: ed7b79f62753149409dca8ccbcbbeface92510b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.telecom;

import android.annotation.Nullable;
import android.media.ToneGenerator;
import android.os.Parcel;
import android.os.Parcelable;
import android.telephony.Annotation;
import android.telephony.PreciseDisconnectCause;
import android.telephony.ims.ImsReasonInfo;
import android.text.TextUtils;

import java.util.Objects;

/**
 * Describes the cause of a disconnected call. This always includes a code describing the generic
 * cause of the disconnect. Optionally, it may include a label and/or description to display to the
 * user. It is the responsibility of the {@link ConnectionService} to provide localized versions of
 * the label and description. It also may contain a reason for the disconnect, which is intended for
 * logging and not for display to the user.
 */
public final class DisconnectCause implements Parcelable {

    /** Disconnected because of an unknown or unspecified reason. */
    public static final int UNKNOWN = TelecomProtoEnums.UNKNOWN; // = 0
    /** Disconnected because there was an error, such as a problem with the network. */
    public static final int ERROR = TelecomProtoEnums.ERROR; // = 1
    /** Disconnected because of a local user-initiated action, such as hanging up. */
    public static final int LOCAL = TelecomProtoEnums.LOCAL; // = 2
    /**
     * Disconnected because of a remote user-initiated action, such as the other party hanging up
     * up.
     */
    public static final int REMOTE = TelecomProtoEnums.REMOTE; // = 3
    /** Disconnected because it has been canceled. */
    public static final int CANCELED = TelecomProtoEnums.CANCELED; // = 4
    /** Disconnected because there was no response to an incoming call. */
    public static final int MISSED = TelecomProtoEnums.MISSED; // = 5
    /** Disconnected because the user rejected an incoming call. */
    public static final int REJECTED = TelecomProtoEnums.REJECTED; // = 6
    /** Disconnected because the other party was busy. */
    public static final int BUSY = TelecomProtoEnums.BUSY; // = 7
    /**
     * Disconnected because of a restriction on placing the call, such as dialing in airplane
     * mode.
     */
    public static final int RESTRICTED = TelecomProtoEnums.RESTRICTED; // = 8
    /** Disconnected for reason not described by other disconnect codes. */
    public static final int OTHER = TelecomProtoEnums.OTHER; // = 9
    /**
     * Disconnected because the connection manager did not support the call. The call will be tried
     * again without a connection manager. See {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
     */
    public static final int CONNECTION_MANAGER_NOT_SUPPORTED =
            TelecomProtoEnums.CONNECTION_MANAGER_NOT_SUPPORTED; // = 10

    /**
     * Disconnected because the user did not locally answer the incoming call, but it was answered
     * on another device where the call was ringing.
     */
    public static final int ANSWERED_ELSEWHERE = TelecomProtoEnums.ANSWERED_ELSEWHERE; // = 11

    /**
     * Disconnected because the call was pulled from the current device to another device.
     */
    public static final int CALL_PULLED = TelecomProtoEnums.CALL_PULLED; // = 12

    /**
     * Reason code (returned via {@link #getReason()}) which indicates that a call could not be
     * completed because the cellular radio is off or out of service, the device is connected to
     * a wifi network, but the user has not enabled wifi calling.
     */
    public static final String REASON_WIFI_ON_BUT_WFC_OFF = "REASON_WIFI_ON_BUT_WFC_OFF";

    /**
     * Reason code (returned via {@link #getReason()}), which indicates that the video telephony
     * call was disconnected because IMS access is blocked.
     */
    public static final String REASON_IMS_ACCESS_BLOCKED = "REASON_IMS_ACCESS_BLOCKED";

    /**
     * Reason code (returned via {@link #getReason()}), which indicates that the connection service
     * is setting the call's state to {@link Call#STATE_DISCONNECTED} because it is internally
     * changing the representation of an IMS conference call to simulate a single-party call.
     *
     * This reason code is only used for communication between a {@link ConnectionService} and
     * Telecom and should not be surfaced to the user.
     */
    public static final String REASON_EMULATING_SINGLE_CALL = "EMULATING_SINGLE_CALL";

    /**
     * This reason is set when a call is ended in order to place an emergency call when a
     * {@link PhoneAccount} doesn't support holding an ongoing call to place an emergency call. This
     * reason string should only be associated with the {@link #LOCAL} disconnect code returned from
     * {@link #getCode()}.
     */
    public static final String REASON_EMERGENCY_CALL_PLACED = "REASON_EMERGENCY_CALL_PLACED";

    private int mDisconnectCode;
    private CharSequence mDisconnectLabel;
    private CharSequence mDisconnectDescription;
    private String mDisconnectReason;
    private int mToneToPlay;
    private int mTelephonyDisconnectCause;
    private int mTelephonyPreciseDisconnectCause;
    private ImsReasonInfo mImsReasonInfo;

    /**
     * Creates a new DisconnectCause.
     *
     * @param code The code for the disconnect cause.
     */
    public DisconnectCause(int code) {
        this(code, null, null, null, ToneGenerator.TONE_UNKNOWN);
    }

    /**
     * Creates a new DisconnectCause.
     *
     * @param code The code for the disconnect cause.
     * @param reason The reason for the disconnect.
     */
    public DisconnectCause(int code, String reason) {
        this(code, null, null, reason, ToneGenerator.TONE_UNKNOWN);
    }

    /**
     * Creates a new DisconnectCause.
     *
     * @param code The code for the disconnect cause.
     * @param label The localized label to show to the user to explain the disconnect.
     * @param description The localized description to show to the user to explain the disconnect.
     * @param reason The reason for the disconnect.
     */
    public DisconnectCause(int code, CharSequence label, CharSequence description, String reason) {
        this(code, label, description, reason, ToneGenerator.TONE_UNKNOWN);
    }

    /**
     * Creates a new DisconnectCause.
     *
     * @param code The code for the disconnect cause.
     * @param label The localized label to show to the user to explain the disconnect.
     * @param description The localized description to show to the user to explain the disconnect.
     * @param reason The reason for the disconnect.
     * @param toneToPlay The tone to play on disconnect, as defined in {@link ToneGenerator}.
     */
    public DisconnectCause(int code, CharSequence label, CharSequence description, String reason,
            int toneToPlay) {
        this(code, label, description, reason, toneToPlay,
                android.telephony.DisconnectCause.ERROR_UNSPECIFIED,
                PreciseDisconnectCause.ERROR_UNSPECIFIED,
                null /* imsReasonInfo */);
    }

    /**
     * Creates a new DisconnectCause instance.
     * @param code The code for the disconnect cause.
     * @param label The localized label to show to the user to explain the disconnect.
     * @param description The localized description to show to the user to explain the disconnect.
     * @param reason The reason for the disconnect.
     * @param toneToPlay The tone to play on disconnect, as defined in {@link ToneGenerator}.
     * @param telephonyDisconnectCause The Telephony disconnect cause.
     * @param telephonyPreciseDisconnectCause The Telephony precise disconnect cause.
     * @param imsReasonInfo The relevant {@link ImsReasonInfo}, or {@code null} if not available.
     * @hide
     */
    public DisconnectCause(int code, CharSequence label, CharSequence description, String reason,
            int toneToPlay, @Annotation.DisconnectCauses int telephonyDisconnectCause,
            @Annotation.PreciseDisconnectCauses int telephonyPreciseDisconnectCause,
            @Nullable ImsReasonInfo imsReasonInfo) {
        mDisconnectCode = code;
        mDisconnectLabel = label;
        mDisconnectDescription = description;
        mDisconnectReason = reason;
        mToneToPlay = toneToPlay;
        mTelephonyDisconnectCause = telephonyDisconnectCause;
        mTelephonyPreciseDisconnectCause = telephonyPreciseDisconnectCause;
        mImsReasonInfo = imsReasonInfo;
    }

    /**
     * Returns the code for the reason for this disconnect.
     *
     * @return The disconnect code.
     */
    public int getCode() {
        return mDisconnectCode;
    }

    /**
     * Returns a short label which explains the reason for the disconnect cause and is for display
     * in the user interface. If not null, it is expected that the In-Call UI should display this
     * text where it would normally display the call state ("Dialing", "Disconnected") and is
     * therefore expected to be relatively small. The {@link ConnectionService } is responsible for
     * providing and localizing this label. If there is no string provided, returns null.
     *
     * @return The disconnect label.
     */
    public CharSequence getLabel() {
        return mDisconnectLabel;
    }

    /**
     * Returns a description which explains the reason for the disconnect cause and is for display
     * in the user interface. This optional text is generally a longer and more descriptive version
     * of {@link #getLabel}, however it can exist even if {@link #getLabel} is empty. The In-Call UI
     * should display this relatively prominently; the traditional implementation displays this as
     * an alert dialog. The {@link ConnectionService} is responsible for providing and localizing
     * this message. If there is no string provided, returns null.
     *
     * @return The disconnect description.
     */
    public CharSequence getDescription() {
        return mDisconnectDescription;
    }

    /**
     * Returns an explanation of the reason for the disconnect. This is not intended for display to
     * the user and is used mainly for logging.
     *
     * @return The disconnect reason.
     */
    public String getReason() {
        return mDisconnectReason;
    }

    /**
     * Returns the telephony {@link android.telephony.DisconnectCause} for the call.
     * @return The disconnect cause.
     * @hide
     */
    public @Annotation.DisconnectCauses int getTelephonyDisconnectCause() {
        return mTelephonyDisconnectCause;
    }

    /**
     * Returns the telephony {@link android.telephony.PreciseDisconnectCause} for the call.
     * @return The precise disconnect cause.
     * @hide
     */
    public @Annotation.PreciseDisconnectCauses int getTelephonyPreciseDisconnectCause() {
        return mTelephonyPreciseDisconnectCause;
    }

    /**
     * Returns the telephony {@link ImsReasonInfo} associated with the call disconnection.
     * @return The {@link ImsReasonInfo} or {@code null} if not known.
     * @hide
     */
    public @Nullable ImsReasonInfo getImsReasonInfo() {
        return mImsReasonInfo;
    }

    /**
     * Returns the tone to play when disconnected.
     *
     * @return the tone as defined in {@link ToneGenerator} to play when disconnected.
     */
    public int getTone() {
        return mToneToPlay;
    }

    public static final @android.annotation.NonNull Creator<DisconnectCause> CREATOR
            = new Creator<DisconnectCause>() {
        @Override
        public DisconnectCause createFromParcel(Parcel source) {
            int code = source.readInt();
            CharSequence label = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
            CharSequence description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
            String reason = source.readString();
            int tone = source.readInt();
            int telephonyDisconnectCause = source.readInt();
            int telephonyPreciseDisconnectCause = source.readInt();
            ImsReasonInfo imsReasonInfo = source.readParcelable(null);
            return new DisconnectCause(code, label, description, reason, tone,
                    telephonyDisconnectCause, telephonyPreciseDisconnectCause, imsReasonInfo);
        }

        @Override
        public DisconnectCause[] newArray(int size) {
            return new DisconnectCause[size];
        }
    };

    @Override
    public void writeToParcel(Parcel destination, int flags) {
        destination.writeInt(mDisconnectCode);
        TextUtils.writeToParcel(mDisconnectLabel, destination, flags);
        TextUtils.writeToParcel(mDisconnectDescription, destination, flags);
        destination.writeString(mDisconnectReason);
        destination.writeInt(mToneToPlay);
        destination.writeInt(mTelephonyDisconnectCause);
        destination.writeInt(mTelephonyPreciseDisconnectCause);
        destination.writeParcelable(mImsReasonInfo, 0);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(mDisconnectCode)
                + Objects.hashCode(mDisconnectLabel)
                + Objects.hashCode(mDisconnectDescription)
                + Objects.hashCode(mDisconnectReason)
                + Objects.hashCode(mToneToPlay)
                + Objects.hashCode(mTelephonyDisconnectCause)
                + Objects.hashCode(mTelephonyPreciseDisconnectCause)
                + Objects.hashCode(mImsReasonInfo);
    }

    @Override
    public boolean equals(Object o) {
        if (o instanceof DisconnectCause) {
            DisconnectCause d = (DisconnectCause) o;
            return Objects.equals(mDisconnectCode, d.getCode())
                    && Objects.equals(mDisconnectLabel, d.getLabel())
                    && Objects.equals(mDisconnectDescription, d.getDescription())
                    && Objects.equals(mDisconnectReason, d.getReason())
                    && Objects.equals(mToneToPlay, d.getTone())
                    && Objects.equals(mTelephonyDisconnectCause, d.getTelephonyDisconnectCause())
                    && Objects.equals(mTelephonyPreciseDisconnectCause,
                    d.getTelephonyPreciseDisconnectCause())
                    && Objects.equals(mImsReasonInfo, d.getImsReasonInfo());
        }
        return false;
    }

    @Override
    public String toString() {
        String code = "";
        switch (mDisconnectCode) {
            case UNKNOWN:
                code = "UNKNOWN";
                break;
            case ERROR:
                code = "ERROR";
                break;
            case LOCAL:
                code = "LOCAL";
                break;
            case REMOTE:
                code = "REMOTE";
                break;
            case CANCELED:
                code = "CANCELED";
                break;
            case MISSED:
                code = "MISSED";
                break;
            case REJECTED:
                code = "REJECTED";
                break;
            case BUSY:
                code = "BUSY";
                break;
            case RESTRICTED:
                code = "RESTRICTED";
                break;
            case OTHER:
                code = "OTHER";
                break;
            case CONNECTION_MANAGER_NOT_SUPPORTED:
                code = "CONNECTION_MANAGER_NOT_SUPPORTED";
                break;
            case CALL_PULLED:
                code = "CALL_PULLED";
                break;
            case ANSWERED_ELSEWHERE:
                code = "ANSWERED_ELSEWHERE";
                break;
            default:
                code = "invalid code: " + mDisconnectCode;
                break;
        }
        String label = mDisconnectLabel == null ? "" : mDisconnectLabel.toString();
        String description = mDisconnectDescription == null
                ? "" : mDisconnectDescription.toString();
        String reason = mDisconnectReason == null ? "" : mDisconnectReason;
        return "DisconnectCause [ Code: (" + code + ")"
                + " Label: (" + label + ")"
                + " Description: (" + description + ")"
                + " Reason: (" + reason + ")"
                + " Tone: (" + mToneToPlay + ") "
                + " TelephonyCause: " + mTelephonyDisconnectCause + "/"
                + mTelephonyPreciseDisconnectCause
                + " ImsReasonInfo: "
                + mImsReasonInfo
                + "]";
    }
}