• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.IntDef;
20 import android.annotation.SystemApi;
21 import android.annotation.UnsupportedAppUsage;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 import android.telephony.DisconnectCause;
25 import android.telephony.PreciseDisconnectCause;
26 
27 import java.lang.annotation.Retention;
28 import java.lang.annotation.RetentionPolicy;
29 import java.util.Objects;
30 
31 /**
32  * Contains precise call states.
33  *
34  * The following call information is included in returned PreciseCallState:
35  *
36  * <ul>
37  *   <li>Precise ringing call state.
38  *   <li>Precise foreground call state.
39  *   <li>Precise background call state.
40  * </ul>
41  *
42  * @see android.telephony.TelephonyManager.CallState which contains generic call states.
43  *
44  * @hide
45  */
46 @SystemApi
47 public final class PreciseCallState implements Parcelable {
48 
49     /** @hide */
50     @Retention(RetentionPolicy.SOURCE)
51     @IntDef(prefix = {"PRECISE_CALL_STATE_"},
52             value = {
53                     PRECISE_CALL_STATE_NOT_VALID,
54                     PRECISE_CALL_STATE_IDLE,
55                     PRECISE_CALL_STATE_ACTIVE,
56                     PRECISE_CALL_STATE_HOLDING,
57                     PRECISE_CALL_STATE_DIALING,
58                     PRECISE_CALL_STATE_ALERTING,
59                     PRECISE_CALL_STATE_INCOMING,
60                     PRECISE_CALL_STATE_WAITING,
61                     PRECISE_CALL_STATE_DISCONNECTED,
62                     PRECISE_CALL_STATE_DISCONNECTING})
63     public @interface State {}
64 
65     /** Call state is not valid (Not received a call state). */
66     public static final int PRECISE_CALL_STATE_NOT_VALID =      -1;
67     /** Call state: No activity. */
68     public static final int PRECISE_CALL_STATE_IDLE =           0;
69     /** Call state: Active. */
70     public static final int PRECISE_CALL_STATE_ACTIVE =         1;
71     /** Call state: On hold. */
72     public static final int PRECISE_CALL_STATE_HOLDING =        2;
73     /** Call state: Dialing. */
74     public static final int PRECISE_CALL_STATE_DIALING =        3;
75     /** Call state: Alerting. */
76     public static final int PRECISE_CALL_STATE_ALERTING =       4;
77     /** Call state: Incoming. */
78     public static final int PRECISE_CALL_STATE_INCOMING =       5;
79     /** Call state: Waiting. */
80     public static final int PRECISE_CALL_STATE_WAITING =        6;
81     /** Call state: Disconnected. */
82     public static final int PRECISE_CALL_STATE_DISCONNECTED =   7;
83     /** Call state: Disconnecting. */
84     public static final int PRECISE_CALL_STATE_DISCONNECTING =  8;
85 
86     private @State int mRingingCallState = PRECISE_CALL_STATE_NOT_VALID;
87     private @State int mForegroundCallState = PRECISE_CALL_STATE_NOT_VALID;
88     private @State int mBackgroundCallState = PRECISE_CALL_STATE_NOT_VALID;
89     private int mDisconnectCause = DisconnectCause.NOT_VALID;
90     private int mPreciseDisconnectCause = PreciseDisconnectCause.NOT_VALID;
91 
92     /**
93      * Constructor
94      *
95      * @hide
96      */
97     @UnsupportedAppUsage
PreciseCallState(@tate int ringingCall, @State int foregroundCall, @State int backgroundCall, int disconnectCause, int preciseDisconnectCause)98     public PreciseCallState(@State int ringingCall, @State int foregroundCall,
99                             @State int backgroundCall, int disconnectCause,
100                             int preciseDisconnectCause) {
101         mRingingCallState = ringingCall;
102         mForegroundCallState = foregroundCall;
103         mBackgroundCallState = backgroundCall;
104         mDisconnectCause = disconnectCause;
105         mPreciseDisconnectCause = preciseDisconnectCause;
106     }
107 
108     /**
109      * Empty Constructor
110      *
111      * @hide
112      */
PreciseCallState()113     public PreciseCallState() {
114     }
115 
116     /**
117      * Construct a PreciseCallState object from the given parcel.
118      *
119      * @hide
120      */
PreciseCallState(Parcel in)121     private PreciseCallState(Parcel in) {
122         mRingingCallState = in.readInt();
123         mForegroundCallState = in.readInt();
124         mBackgroundCallState = in.readInt();
125         mDisconnectCause = in.readInt();
126         mPreciseDisconnectCause = in.readInt();
127     }
128 
129     /**
130      * Returns the precise ringing call state.
131      */
getRingingCallState()132     public @State int getRingingCallState() {
133         return mRingingCallState;
134     }
135 
136     /**
137      * Returns the precise foreground call state.
138      */
getForegroundCallState()139     public @State int getForegroundCallState() {
140         return mForegroundCallState;
141     }
142 
143     /**
144      * Returns the precise background call state.
145      */
getBackgroundCallState()146     public @State int getBackgroundCallState() {
147         return mBackgroundCallState;
148     }
149 
150     /**
151      * Get disconnect cause generated by the framework
152      *
153      * @see DisconnectCause#NOT_VALID
154      * @see DisconnectCause#NOT_DISCONNECTED
155      * @see DisconnectCause#INCOMING_MISSED
156      * @see DisconnectCause#NORMAL
157      * @see DisconnectCause#LOCAL
158      * @see DisconnectCause#BUSY
159      * @see DisconnectCause#CONGESTION
160      * @see DisconnectCause#MMI
161      * @see DisconnectCause#INVALID_NUMBER
162      * @see DisconnectCause#NUMBER_UNREACHABLE
163      * @see DisconnectCause#SERVER_UNREACHABLE
164      * @see DisconnectCause#INVALID_CREDENTIALS
165      * @see DisconnectCause#OUT_OF_NETWORK
166      * @see DisconnectCause#SERVER_ERROR
167      * @see DisconnectCause#TIMED_OUT
168      * @see DisconnectCause#LOST_SIGNAL
169      * @see DisconnectCause#LIMIT_EXCEEDED
170      * @see DisconnectCause#INCOMING_REJECTED
171      * @see DisconnectCause#POWER_OFF
172      * @see DisconnectCause#OUT_OF_SERVICE
173      * @see DisconnectCause#ICC_ERROR
174      * @see DisconnectCause#CALL_BARRED
175      * @see DisconnectCause#FDN_BLOCKED
176      * @see DisconnectCause#CS_RESTRICTED
177      * @see DisconnectCause#CS_RESTRICTED_NORMAL
178      * @see DisconnectCause#CS_RESTRICTED_EMERGENCY
179      * @see DisconnectCause#UNOBTAINABLE_NUMBER
180      * @see DisconnectCause#CDMA_LOCKED_UNTIL_POWER_CYCLE
181      * @see DisconnectCause#CDMA_DROP
182      * @see DisconnectCause#CDMA_INTERCEPT
183      * @see DisconnectCause#CDMA_REORDER
184      * @see DisconnectCause#CDMA_SO_REJECT
185      * @see DisconnectCause#CDMA_RETRY_ORDER
186      * @see DisconnectCause#CDMA_ACCESS_FAILURE
187      * @see DisconnectCause#CDMA_PREEMPTED
188      * @see DisconnectCause#CDMA_NOT_EMERGENCY
189      * @see DisconnectCause#CDMA_ACCESS_BLOCKED
190      * @see DisconnectCause#ERROR_UNSPECIFIED
191      *
192      * TODO: remove disconnect cause from preciseCallState as there is no link between random
193      * connection disconnect cause with foreground, background or ringing call.
194      *
195      * @hide
196      */
197     @UnsupportedAppUsage
getDisconnectCause()198     public int getDisconnectCause() {
199         return mDisconnectCause;
200     }
201 
202     /**
203      * Get disconnect cause generated by the RIL
204      *
205      * @see PreciseDisconnectCause#NOT_VALID
206      * @see PreciseDisconnectCause#NO_DISCONNECT_CAUSE_AVAILABLE
207      * @see PreciseDisconnectCause#UNOBTAINABLE_NUMBER
208      * @see PreciseDisconnectCause#NORMAL
209      * @see PreciseDisconnectCause#BUSY
210      * @see PreciseDisconnectCause#NUMBER_CHANGED
211      * @see PreciseDisconnectCause#STATUS_ENQUIRY
212      * @see PreciseDisconnectCause#NORMAL_UNSPECIFIED
213      * @see PreciseDisconnectCause#NO_CIRCUIT_AVAIL
214      * @see PreciseDisconnectCause#TEMPORARY_FAILURE
215      * @see PreciseDisconnectCause#SWITCHING_CONGESTION
216      * @see PreciseDisconnectCause#CHANNEL_NOT_AVAIL
217      * @see PreciseDisconnectCause#QOS_NOT_AVAIL
218      * @see PreciseDisconnectCause#BEARER_NOT_AVAIL
219      * @see PreciseDisconnectCause#ACM_LIMIT_EXCEEDED
220      * @see PreciseDisconnectCause#CALL_BARRED
221      * @see PreciseDisconnectCause#FDN_BLOCKED
222      * @see PreciseDisconnectCause#IMSI_UNKNOWN_IN_VLR
223      * @see PreciseDisconnectCause#IMEI_NOT_ACCEPTED
224      * @see PreciseDisconnectCause#CDMA_LOCKED_UNTIL_POWER_CYCLE
225      * @see PreciseDisconnectCause#CDMA_DROP
226      * @see PreciseDisconnectCause#CDMA_INTERCEPT
227      * @see PreciseDisconnectCause#CDMA_REORDER
228      * @see PreciseDisconnectCause#CDMA_SO_REJECT
229      * @see PreciseDisconnectCause#CDMA_RETRY_ORDER
230      * @see PreciseDisconnectCause#CDMA_ACCESS_FAILURE
231      * @see PreciseDisconnectCause#CDMA_PREEMPTED
232      * @see PreciseDisconnectCause#CDMA_NOT_EMERGENCY
233      * @see PreciseDisconnectCause#CDMA_ACCESS_BLOCKED
234      * @see PreciseDisconnectCause#ERROR_UNSPECIFIED
235      *
236      * TODO: remove precise disconnect cause from preciseCallState as there is no link between
237      * random connection disconnect cause with foreground, background or ringing call.
238      *
239      * @hide
240      */
241     @UnsupportedAppUsage
getPreciseDisconnectCause()242     public int getPreciseDisconnectCause() {
243         return mPreciseDisconnectCause;
244     }
245 
246     @Override
describeContents()247     public int describeContents() {
248         return 0;
249     }
250 
251     @Override
writeToParcel(Parcel out, int flags)252     public void writeToParcel(Parcel out, int flags) {
253         out.writeInt(mRingingCallState);
254         out.writeInt(mForegroundCallState);
255         out.writeInt(mBackgroundCallState);
256         out.writeInt(mDisconnectCause);
257         out.writeInt(mPreciseDisconnectCause);
258     }
259 
260     public static final @android.annotation.NonNull Parcelable.Creator<PreciseCallState> CREATOR
261             = new Parcelable.Creator<PreciseCallState>() {
262 
263         public PreciseCallState createFromParcel(Parcel in) {
264             return new PreciseCallState(in);
265         }
266 
267         public PreciseCallState[] newArray(int size) {
268             return new PreciseCallState[size];
269         }
270     };
271 
272     @Override
hashCode()273     public int hashCode() {
274         return Objects.hash(mRingingCallState, mForegroundCallState, mForegroundCallState,
275                 mDisconnectCause, mPreciseDisconnectCause);
276     }
277 
278     @Override
equals(Object obj)279     public boolean equals(Object obj) {
280         if (this == obj) {
281             return true;
282         }
283         if (obj == null) {
284             return false;
285         }
286         if (getClass() != obj.getClass()) {
287             return false;
288         }
289         PreciseCallState other = (PreciseCallState) obj;
290         return (mRingingCallState == other.mRingingCallState
291                 && mForegroundCallState == other.mForegroundCallState
292                 && mBackgroundCallState == other.mBackgroundCallState
293                 && mDisconnectCause == other.mDisconnectCause
294                 && mPreciseDisconnectCause == other.mPreciseDisconnectCause);
295     }
296 
297     @Override
toString()298     public String toString() {
299         StringBuffer sb = new StringBuffer();
300 
301         sb.append("Ringing call state: " + mRingingCallState);
302         sb.append(", Foreground call state: " + mForegroundCallState);
303         sb.append(", Background call state: " + mBackgroundCallState);
304         sb.append(", Disconnect cause: " + mDisconnectCause);
305         sb.append(", Precise disconnect cause: " + mPreciseDisconnectCause);
306 
307         return sb.toString();
308     }
309 }
310