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.telephony;
18 
19 import android.annotation.FlaggedApi;
20 import android.annotation.NonNull;
21 import android.compat.annotation.UnsupportedAppUsage;
22 
23 import com.android.internal.telephony.flags.Flags;
24 
25 /**
26  * Describes the cause of a disconnected call. Those disconnect causes can be converted into a more
27  * generic {@link android.telecom.DisconnectCause} object.
28  *
29  * Used in {@link PhoneStateListener#onCallDisconnectCauseChanged}.
30  */
31 public final class DisconnectCause {
32 
33     /** The disconnect cause is not valid (Not received a disconnect cause) */
34     public static final int NOT_VALID                      = -1;
35     /** Has not yet disconnected */
36     public static final int NOT_DISCONNECTED               = 0;
37     /** An incoming call that was missed and never answered */
38     public static final int INCOMING_MISSED                = 1;
39     /** Normal; Remote hangup*/
40     public static final int NORMAL                         = 2;
41     /** Normal; Local hangup */
42     public static final int LOCAL                          = 3;
43     /** Outgoing call to busy line */
44     public static final int BUSY                           = 4;
45     /** Outgoing call to congested network */
46     public static final int CONGESTION                     = 5;
47     /** Not presently used */
48     public static final int MMI                            = 6;
49     /** Invalid dial string */
50     public static final int INVALID_NUMBER                 = 7;
51     /** Cannot reach the peer */
52     public static final int NUMBER_UNREACHABLE             = 8;
53     /** Cannot reach the server */
54     public static final int SERVER_UNREACHABLE             = 9;
55     /** Invalid credentials */
56     public static final int INVALID_CREDENTIALS            = 10;
57     /** Calling from out of network is not allowed */
58     public static final int OUT_OF_NETWORK                 = 11;
59     /** Server error */
60     public static final int SERVER_ERROR                   = 12;
61     /** Client timed out */
62     public static final int TIMED_OUT                      = 13;
63     /** Client went out of network range */
64     public static final int LOST_SIGNAL                    = 14;
65     /** GSM or CDMA ACM limit exceeded */
66     public static final int LIMIT_EXCEEDED                 = 15;
67     /** An incoming call that was rejected */
68     public static final int INCOMING_REJECTED              = 16;
69     /** Radio is turned off explicitly */
70     public static final int POWER_OFF                      = 17;
71     /** Out of service */
72     public static final int OUT_OF_SERVICE                 = 18;
73     /** No ICC, ICC locked, or other ICC error */
74     public static final int ICC_ERROR                      = 19;
75     /** Call was blocked by call barring */
76     public static final int CALL_BARRED                    = 20;
77     /** Call was blocked by fixed dial number */
78     public static final int FDN_BLOCKED                    = 21;
79     /** Call was blocked by restricted all voice access */
80     public static final int CS_RESTRICTED                  = 22;
81     /** Call was blocked by restricted normal voice access */
82     public static final int CS_RESTRICTED_NORMAL           = 23;
83     /** Call was blocked by restricted emergency voice access */
84     public static final int CS_RESTRICTED_EMERGENCY        = 24;
85     /** Unassigned number */
86     public static final int UNOBTAINABLE_NUMBER            = 25;
87     /** MS is locked until next power cycle */
88     public static final int CDMA_LOCKED_UNTIL_POWER_CYCLE  = 26;
89     /** Drop call*/
90     public static final int CDMA_DROP                      = 27;
91     /** INTERCEPT order received, MS state idle entered */
92     public static final int CDMA_INTERCEPT                 = 28;
93     /** MS has been redirected, call is cancelled */
94     public static final int CDMA_REORDER                   = 29;
95     /** Service option rejection */
96     public static final int CDMA_SO_REJECT                 = 30;
97     /** Requested service is rejected, retry delay is set */
98     public static final int CDMA_RETRY_ORDER               = 31;
99     /** Unable to obtain access to the CDMA system */
100     public static final int CDMA_ACCESS_FAILURE            = 32;
101     /** Not a preempted call */
102     public static final int CDMA_PREEMPTED                 = 33;
103     /** Not an emergency call */
104     public static final int CDMA_NOT_EMERGENCY             = 34;
105     /** Access Blocked by CDMA network */
106     public static final int CDMA_ACCESS_BLOCKED            = 35;
107     /** Unknown error or not specified */
108     public static final int ERROR_UNSPECIFIED              = 36;
109     /**
110      * Only emergency numbers are allowed, but we tried to dial a non-emergency number.
111      * @hide
112      */
113     // TODO: This should be the same as NOT_EMERGENCY
114     public static final int EMERGENCY_ONLY                 = 37;
115     /**
116      * The supplied CALL Intent didn't contain a valid phone number.
117      */
118     public static final int NO_PHONE_NUMBER_SUPPLIED       = 38;
119     /**
120      * Our initial phone number was actually an MMI sequence.
121      */
122     public static final int DIALED_MMI                     = 39;
123     /**
124      * We tried to call a voicemail: URI but the device has no voicemail number configured.
125      */
126     public static final int VOICEMAIL_NUMBER_MISSING       = 40;
127     /**
128      * This status indicates that InCallScreen should display the
129      * CDMA-specific "call lost" dialog.  (If an outgoing call fails,
130      * and the CDMA "auto-retry" feature is enabled, *and* the retried
131      * call fails too, we display this specific dialog.)
132      *
133      * TODO: this is currently unused, since the "call lost" dialog
134      * needs to be triggered by a *disconnect* event, rather than when
135      * the InCallScreen first comes to the foreground.  For now we use
136      * the needToShowCallLostDialog field for this (see below.)
137      *
138      * @hide
139      */
140     public static final int CDMA_CALL_LOST                 = 41;
141     /**
142      * This status indicates that the call was placed successfully,
143      * but additionally, the InCallScreen needs to display the
144      * "Exiting ECM" dialog.
145      *
146      * (Details: "Emergency callback mode" is a CDMA-specific concept
147      * where the phone disallows data connections over the cell
148      * network for some period of time after you make an emergency
149      * call.  If the phone is in ECM and you dial a non-emergency
150      * number, that automatically *cancels* ECM, but we additionally
151      * need to warn the user that ECM has been canceled (see bug
152      * 4207607.))
153      *
154      * TODO: Rethink where the best place to put this is. It is not a notification
155      * of a failure of the connection -- it is an additional message that accompanies
156      * a successful connection giving the user important information about what happened.
157      *
158      * {@hide}
159      */
160     public static final int EXITED_ECM                     = 42;
161 
162     /**
163      * The outgoing call failed with an unknown cause.
164      */
165     public static final int OUTGOING_FAILURE               = 43;
166 
167     /**
168      * The outgoing call was canceled by the {@link android.telecom.ConnectionService}.
169      */
170     public static final int OUTGOING_CANCELED              = 44;
171 
172     /**
173      * The call, which was an IMS call, disconnected because it merged with another call.
174      */
175     public static final int IMS_MERGED_SUCCESSFULLY        = 45;
176 
177     /**
178      * Stk Call Control modified DIAL request to USSD request.
179      */
180     public static final int DIAL_MODIFIED_TO_USSD          = 46;
181     /**
182      * Stk Call Control modified DIAL request to SS request.
183      */
184     public static final int DIAL_MODIFIED_TO_SS            = 47;
185     /**
186      * Stk Call Control modified DIAL request to DIAL with modified data.
187      */
188     public static final int DIAL_MODIFIED_TO_DIAL          = 48;
189 
190     /**
191      * The call was terminated because CDMA phone service and roaming have already been activated.
192      */
193     public static final int CDMA_ALREADY_ACTIVATED         = 49;
194 
195     /**
196      * The call was terminated because it is not possible to place a video call while TTY is
197      * enabled.
198      */
199     public static final int VIDEO_CALL_NOT_ALLOWED_WHILE_TTY_ENABLED = 50;
200 
201     /**
202      * The call was terminated because it was pulled to another device.
203      */
204     public static final int CALL_PULLED = 51;
205 
206     /**
207      * The call was terminated because it was answered on another device.
208      */
209     public static final int ANSWERED_ELSEWHERE = 52;
210 
211     /**
212      * The call was terminated because the maximum allowable number of calls has been reached.
213      */
214     public static final int MAXIMUM_NUMBER_OF_CALLS_REACHED = 53;
215 
216     /**
217      * The call was terminated because cellular data has been disabled.
218      * Used when in a video call and the user disables cellular data via the settings.
219      */
220     public static final int DATA_DISABLED = 54;
221 
222     /**
223      * The call was terminated because the data policy has disabled cellular data.
224      * Used when in a video call and the user has exceeded the device data limit.
225      */
226     public static final int DATA_LIMIT_REACHED = 55;
227 
228     /**
229      * The call being placed was detected as a call forwarding number and was being dialed while
230      * roaming on a carrier that does not allow this.
231      */
232     public static final int DIALED_CALL_FORWARDING_WHILE_ROAMING = 57;
233 
234     /**
235      * The network does not accept the emergency call request because IMEI was used as
236      * identification and this cability is not supported by the network.
237      */
238     public static final int IMEI_NOT_ACCEPTED = 58;
239 
240     /**
241      * A call over WIFI was disconnected because the WIFI signal was lost or became too degraded to
242      * continue the call.
243      */
244     public static final int WIFI_LOST = 59;
245 
246     /**
247      * The call has failed because of access class barring.
248      */
249     public static final int IMS_ACCESS_BLOCKED = 60;
250 
251     /**
252      * The call has ended (mid-call) because the device's battery is too low.
253      */
254     public static final int LOW_BATTERY = 61;
255 
256     /**
257      * A call was not dialed because the device's battery is too low.
258      */
259     public static final int DIAL_LOW_BATTERY = 62;
260 
261     /**
262      * Emergency call failed with a temporary fail cause and can be redialed on this slot.
263      */
264     public static final int EMERGENCY_TEMP_FAILURE = 63;
265 
266     /**
267      * Emergency call failed with a permanent fail cause and should not be redialed on this
268      * slot.
269      */
270     public static final int EMERGENCY_PERM_FAILURE = 64;
271 
272     /**
273      * This cause is used to report a normal event only when no other cause in the normal class
274      * applies.
275      */
276     public static final int NORMAL_UNSPECIFIED = 65;
277 
278     /**
279      * Stk Call Control modified DIAL request to video DIAL request.
280      */
281     public static final int DIAL_MODIFIED_TO_DIAL_VIDEO = 66;
282 
283     /**
284      * Stk Call Control modified Video DIAL request to SS request.
285      */
286     public static final int DIAL_VIDEO_MODIFIED_TO_SS = 67;
287 
288     /**
289      * Stk Call Control modified Video DIAL request to USSD request.
290      */
291     public static final int DIAL_VIDEO_MODIFIED_TO_USSD = 68;
292 
293     /**
294      * Stk Call Control modified Video DIAL request to DIAL request.
295      */
296     public static final int DIAL_VIDEO_MODIFIED_TO_DIAL = 69;
297 
298     /**
299      * Stk Call Control modified Video DIAL request to Video DIAL request.
300      */
301     public static final int DIAL_VIDEO_MODIFIED_TO_DIAL_VIDEO = 70;
302 
303     /**
304      * The network has reported that an alternative emergency number has been dialed, but the user
305      * must exit airplane mode to place the call.
306      */
307     public static final int IMS_SIP_ALTERNATE_EMERGENCY_CALL = 71;
308 
309     /**
310      * Indicates that a new outgoing call cannot be placed because there is already an outgoing
311      * call dialing out.
312      */
313     public static final int ALREADY_DIALING = 72;
314 
315     /**
316      * Indicates that a new outgoing call cannot be placed while there is a ringing call.
317      */
318     public static final int CANT_CALL_WHILE_RINGING = 73;
319 
320     /**
321      * Indicates that a new outgoing call cannot be placed because calling has been disabled using
322      * the ro.telephony.disable-call system property.
323      */
324     public static final int CALLING_DISABLED = 74;
325 
326     /**
327      * Indicates that a new outgoing call cannot be placed because there is currently an ongoing
328      * foreground and background call.
329      */
330     public static final int TOO_MANY_ONGOING_CALLS = 75;
331 
332     /**
333      * Indicates that a new outgoing call cannot be placed because OTASP provisioning is currently
334      * in process.
335      */
336     public static final int OTASP_PROVISIONING_IN_PROCESS = 76;
337 
338     /**
339      * Indicates that the call is dropped due to RTCP inactivity, primarily due to media path
340      * disruption.
341      */
342     public static final int MEDIA_TIMEOUT = 77;
343 
344     /**
345      * Indicates that an emergency call cannot be placed over WFC because the service is not
346      * available in the current location.
347      */
348     public static final int EMERGENCY_CALL_OVER_WFC_NOT_AVAILABLE = 78;
349 
350     /**
351      * Indicates that WiFi calling service is not available in the current location.
352      */
353     public static final int WFC_SERVICE_NOT_AVAILABLE_IN_THIS_LOCATION = 79;
354 
355     /**
356      * Indicates that an emergency call was placed, which caused the existing connection to be
357      * hung up.
358      */
359     public static final int OUTGOING_EMERGENCY_CALL_PLACED = 80;
360 
361     /**
362      * Indicates that incoming call was rejected by the modem before the call went in ringing
363      */
364     public static final int INCOMING_AUTO_REJECTED = 81;
365 
366     /**
367      * Indicates that the call was unable to be made because the satellite modem is enabled.
368      */
369     @FlaggedApi(Flags.FLAG_OEM_ENABLED_SATELLITE_FLAG)
370     public static final int SATELLITE_ENABLED = 82;
371 
372     //*********************************************************************************************
373     // When adding a disconnect type:
374     // 1) Update toString() with the newly added disconnect type.
375     // 2) Update android.telecom.DisconnectCauseUtil with any mappings to a telecom.DisconnectCause.
376     //*********************************************************************************************
377 
378     /** Private constructor to avoid class instantiation. */
DisconnectCause()379     private DisconnectCause() {
380         // Do nothing.
381     }
382 
383     /**
384      * Returns descriptive string for the specified disconnect cause.
385      * @hide
386      */
387     @UnsupportedAppUsage
toString(int cause)388     public static @NonNull String toString(int cause) {
389         switch (cause) {
390             case NOT_DISCONNECTED:
391                 return "NOT_DISCONNECTED";
392             case INCOMING_MISSED:
393                 return "INCOMING_MISSED";
394             case NORMAL:
395                 return "NORMAL";
396             case LOCAL:
397                 return "LOCAL";
398             case BUSY:
399                 return "BUSY";
400             case CONGESTION:
401                 return "CONGESTION";
402             case INVALID_NUMBER:
403                 return "INVALID_NUMBER";
404             case NUMBER_UNREACHABLE:
405                 return "NUMBER_UNREACHABLE";
406             case SERVER_UNREACHABLE:
407                 return "SERVER_UNREACHABLE";
408             case INVALID_CREDENTIALS:
409                 return "INVALID_CREDENTIALS";
410             case OUT_OF_NETWORK:
411                 return "OUT_OF_NETWORK";
412             case SERVER_ERROR:
413                 return "SERVER_ERROR";
414             case TIMED_OUT:
415                 return "TIMED_OUT";
416             case LOST_SIGNAL:
417                 return "LOST_SIGNAL";
418             case LIMIT_EXCEEDED:
419                 return "LIMIT_EXCEEDED";
420             case INCOMING_REJECTED:
421                 return "INCOMING_REJECTED";
422             case POWER_OFF:
423                 return "POWER_OFF";
424             case OUT_OF_SERVICE:
425                 return "OUT_OF_SERVICE";
426             case ICC_ERROR:
427                 return "ICC_ERROR";
428             case CALL_BARRED:
429                 return "CALL_BARRED";
430             case FDN_BLOCKED:
431                 return "FDN_BLOCKED";
432             case CS_RESTRICTED:
433                 return "CS_RESTRICTED";
434             case CS_RESTRICTED_NORMAL:
435                 return "CS_RESTRICTED_NORMAL";
436             case CS_RESTRICTED_EMERGENCY:
437                 return "CS_RESTRICTED_EMERGENCY";
438             case UNOBTAINABLE_NUMBER:
439                 return "UNOBTAINABLE_NUMBER";
440             case CDMA_LOCKED_UNTIL_POWER_CYCLE:
441                 return "CDMA_LOCKED_UNTIL_POWER_CYCLE";
442             case CDMA_DROP:
443                 return "CDMA_DROP";
444             case CDMA_INTERCEPT:
445                 return "CDMA_INTERCEPT";
446             case CDMA_REORDER:
447                 return "CDMA_REORDER";
448             case CDMA_SO_REJECT:
449                 return "CDMA_SO_REJECT";
450             case CDMA_RETRY_ORDER:
451                 return "CDMA_RETRY_ORDER";
452             case CDMA_ACCESS_FAILURE:
453                 return "CDMA_ACCESS_FAILURE";
454             case CDMA_PREEMPTED:
455                 return "CDMA_PREEMPTED";
456             case CDMA_NOT_EMERGENCY:
457                 return "CDMA_NOT_EMERGENCY";
458             case CDMA_ACCESS_BLOCKED:
459                 return "CDMA_ACCESS_BLOCKED";
460             case EMERGENCY_ONLY:
461                 return "EMERGENCY_ONLY";
462             case NO_PHONE_NUMBER_SUPPLIED:
463                 return "NO_PHONE_NUMBER_SUPPLIED";
464             case DIALED_MMI:
465                 return "DIALED_MMI";
466             case VOICEMAIL_NUMBER_MISSING:
467                 return "VOICEMAIL_NUMBER_MISSING";
468             case CDMA_CALL_LOST:
469                 return "CDMA_CALL_LOST";
470             case EXITED_ECM:
471                 return "EXITED_ECM";
472             case DIAL_MODIFIED_TO_USSD:
473                 return "DIAL_MODIFIED_TO_USSD";
474             case DIAL_MODIFIED_TO_SS:
475                 return "DIAL_MODIFIED_TO_SS";
476             case DIAL_MODIFIED_TO_DIAL:
477                 return "DIAL_MODIFIED_TO_DIAL";
478             case DIAL_MODIFIED_TO_DIAL_VIDEO:
479                 return "DIAL_MODIFIED_TO_DIAL_VIDEO";
480             case DIAL_VIDEO_MODIFIED_TO_SS:
481                 return "DIAL_VIDEO_MODIFIED_TO_SS";
482             case DIAL_VIDEO_MODIFIED_TO_USSD:
483                 return "DIAL_VIDEO_MODIFIED_TO_USSD";
484             case DIAL_VIDEO_MODIFIED_TO_DIAL:
485                 return "DIAL_VIDEO_MODIFIED_TO_DIAL";
486             case DIAL_VIDEO_MODIFIED_TO_DIAL_VIDEO:
487                 return "DIAL_VIDEO_MODIFIED_TO_DIAL_VIDEO";
488             case ERROR_UNSPECIFIED:
489                 return "ERROR_UNSPECIFIED";
490             case OUTGOING_FAILURE:
491                 return "OUTGOING_FAILURE";
492             case OUTGOING_CANCELED:
493                 return "OUTGOING_CANCELED";
494             case IMS_MERGED_SUCCESSFULLY:
495                 return "IMS_MERGED_SUCCESSFULLY";
496             case CDMA_ALREADY_ACTIVATED:
497                 return "CDMA_ALREADY_ACTIVATED";
498             case VIDEO_CALL_NOT_ALLOWED_WHILE_TTY_ENABLED:
499                 return "VIDEO_CALL_NOT_ALLOWED_WHILE_TTY_ENABLED";
500             case CALL_PULLED:
501                 return "CALL_PULLED";
502             case ANSWERED_ELSEWHERE:
503                 return "ANSWERED_ELSEWHERE";
504             case MAXIMUM_NUMBER_OF_CALLS_REACHED:
505                 return "MAXIMUM_NUMER_OF_CALLS_REACHED";
506             case DATA_DISABLED:
507                 return "DATA_DISABLED";
508             case DATA_LIMIT_REACHED:
509                 return "DATA_LIMIT_REACHED";
510             case DIALED_CALL_FORWARDING_WHILE_ROAMING:
511                 return "DIALED_CALL_FORWARDING_WHILE_ROAMING";
512             case IMEI_NOT_ACCEPTED:
513                 return "IMEI_NOT_ACCEPTED";
514             case WIFI_LOST:
515                 return "WIFI_LOST";
516             case IMS_ACCESS_BLOCKED:
517                 return "IMS_ACCESS_BLOCKED";
518             case LOW_BATTERY:
519                 return "LOW_BATTERY";
520             case DIAL_LOW_BATTERY:
521                 return "DIAL_LOW_BATTERY";
522             case EMERGENCY_TEMP_FAILURE:
523                 return "EMERGENCY_TEMP_FAILURE";
524             case EMERGENCY_PERM_FAILURE:
525                 return "EMERGENCY_PERM_FAILURE";
526             case NORMAL_UNSPECIFIED:
527                 return "NORMAL_UNSPECIFIED";
528             case IMS_SIP_ALTERNATE_EMERGENCY_CALL:
529                 return "IMS_SIP_ALTERNATE_EMERGENCY_CALL";
530             case ALREADY_DIALING:
531                 return "ALREADY_DIALING";
532             case CANT_CALL_WHILE_RINGING:
533                 return "CANT_CALL_WHILE_RINGING";
534             case CALLING_DISABLED:
535                 return "CALLING_DISABLED";
536             case TOO_MANY_ONGOING_CALLS:
537                 return "TOO_MANY_ONGOING_CALLS";
538             case OTASP_PROVISIONING_IN_PROCESS:
539                 return "OTASP_PROVISIONING_IN_PROCESS";
540             case MEDIA_TIMEOUT:
541                 return "MEDIA_TIMEOUT";
542             case EMERGENCY_CALL_OVER_WFC_NOT_AVAILABLE:
543                 return "EMERGENCY_CALL_OVER_WFC_NOT_AVAILABLE";
544             case WFC_SERVICE_NOT_AVAILABLE_IN_THIS_LOCATION:
545                 return "WFC_SERVICE_NOT_AVAILABLE_IN_THIS_LOCATION";
546             case OUTGOING_EMERGENCY_CALL_PLACED:
547                 return "OUTGOING_EMERGENCY_CALL_PLACED";
548             case INCOMING_AUTO_REJECTED:
549                 return "INCOMING_AUTO_REJECTED";
550             case SATELLITE_ENABLED:
551                 return "SATELLITE_ENABLED";
552             default:
553                 return "INVALID: " + cause;
554         }
555     }
556 }
557