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.os.Parcel; 20 import android.os.Parcelable; 21 import android.telephony.DisconnectCause; 22 import android.telephony.PreciseDisconnectCause; 23 24 /** 25 * Contains precise call state and call fail causes generated by the 26 * framework and the RIL. 27 * 28 * The following call information is included in returned PreciseCallState: 29 * 30 * <ul> 31 * <li>Ringing call state. 32 * <li>Foreground call state. 33 * <li>Background call state. 34 * <li>Disconnect cause; generated by the framework. 35 * <li>Precise disconnect cause; generated by the RIL. 36 * </ul> 37 * 38 * @hide 39 */ 40 public class PreciseCallState implements Parcelable { 41 42 /** Call state is not valid (Not received a call state). */ 43 public static final int PRECISE_CALL_STATE_NOT_VALID = -1; 44 /** Call state: No activity. */ 45 public static final int PRECISE_CALL_STATE_IDLE = 0; 46 /** Call state: Active. */ 47 public static final int PRECISE_CALL_STATE_ACTIVE = 1; 48 /** Call state: On hold. */ 49 public static final int PRECISE_CALL_STATE_HOLDING = 2; 50 /** Call state: Dialing. */ 51 public static final int PRECISE_CALL_STATE_DIALING = 3; 52 /** Call state: Alerting. */ 53 public static final int PRECISE_CALL_STATE_ALERTING = 4; 54 /** Call state: Incoming. */ 55 public static final int PRECISE_CALL_STATE_INCOMING = 5; 56 /** Call state: Waiting. */ 57 public static final int PRECISE_CALL_STATE_WAITING = 6; 58 /** Call state: Disconnected. */ 59 public static final int PRECISE_CALL_STATE_DISCONNECTED = 7; 60 /** Call state: Disconnecting. */ 61 public static final int PRECISE_CALL_STATE_DISCONNECTING = 8; 62 63 private int mRingingCallState = PRECISE_CALL_STATE_NOT_VALID; 64 private int mForegroundCallState = PRECISE_CALL_STATE_NOT_VALID; 65 private int mBackgroundCallState = PRECISE_CALL_STATE_NOT_VALID; 66 private int mDisconnectCause = DisconnectCause.NOT_VALID; 67 private int mPreciseDisconnectCause = PreciseDisconnectCause.NOT_VALID; 68 69 /** 70 * Constructor 71 * 72 * @hide 73 */ PreciseCallState(int ringingCall, int foregroundCall, int backgroundCall, int disconnectCause, int preciseDisconnectCause)74 public PreciseCallState(int ringingCall, int foregroundCall, int backgroundCall, 75 int disconnectCause, int preciseDisconnectCause) { 76 mRingingCallState = ringingCall; 77 mForegroundCallState = foregroundCall; 78 mBackgroundCallState = backgroundCall; 79 mDisconnectCause = disconnectCause; 80 mPreciseDisconnectCause = preciseDisconnectCause; 81 } 82 83 /** 84 * Empty Constructor 85 * 86 * @hide 87 */ PreciseCallState()88 public PreciseCallState() { 89 } 90 91 /** 92 * Construct a PreciseCallState object from the given parcel. 93 */ PreciseCallState(Parcel in)94 private PreciseCallState(Parcel in) { 95 mRingingCallState = in.readInt(); 96 mForegroundCallState = in.readInt(); 97 mBackgroundCallState = in.readInt(); 98 mDisconnectCause = in.readInt(); 99 mPreciseDisconnectCause = in.readInt(); 100 } 101 102 /** 103 * Get precise ringing call state 104 * 105 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 106 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 107 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 108 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 109 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 110 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 111 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 112 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 113 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 114 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 115 */ getRingingCallState()116 public int getRingingCallState() { 117 return mRingingCallState; 118 } 119 120 /** 121 * Get precise foreground call state 122 * 123 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 124 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 125 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 126 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 127 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 128 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 129 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 130 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 131 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 132 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 133 */ getForegroundCallState()134 public int getForegroundCallState() { 135 return mForegroundCallState; 136 } 137 138 /** 139 * Get precise background call state 140 * 141 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 142 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 143 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 144 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 145 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 146 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 147 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 148 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 149 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 150 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 151 */ getBackgroundCallState()152 public int getBackgroundCallState() { 153 return mBackgroundCallState; 154 } 155 156 /** 157 * Get disconnect cause generated by the framework 158 * 159 * @see DisconnectCause#NOT_VALID 160 * @see DisconnectCause#NOT_DISCONNECTED 161 * @see DisconnectCause#INCOMING_MISSED 162 * @see DisconnectCause#NORMAL 163 * @see DisconnectCause#LOCAL 164 * @see DisconnectCause#BUSY 165 * @see DisconnectCause#CONGESTION 166 * @see DisconnectCause#MMI 167 * @see DisconnectCause#INVALID_NUMBER 168 * @see DisconnectCause#NUMBER_UNREACHABLE 169 * @see DisconnectCause#SERVER_UNREACHABLE 170 * @see DisconnectCause#INVALID_CREDENTIALS 171 * @see DisconnectCause#OUT_OF_NETWORK 172 * @see DisconnectCause#SERVER_ERROR 173 * @see DisconnectCause#TIMED_OUT 174 * @see DisconnectCause#LOST_SIGNAL 175 * @see DisconnectCause#LIMIT_EXCEEDED 176 * @see DisconnectCause#INCOMING_REJECTED 177 * @see DisconnectCause#POWER_OFF 178 * @see DisconnectCause#OUT_OF_SERVICE 179 * @see DisconnectCause#ICC_ERROR 180 * @see DisconnectCause#CALL_BARRED 181 * @see DisconnectCause#FDN_BLOCKED 182 * @see DisconnectCause#CS_RESTRICTED 183 * @see DisconnectCause#CS_RESTRICTED_NORMAL 184 * @see DisconnectCause#CS_RESTRICTED_EMERGENCY 185 * @see DisconnectCause#UNOBTAINABLE_NUMBER 186 * @see DisconnectCause#CDMA_LOCKED_UNTIL_POWER_CYCLE 187 * @see DisconnectCause#CDMA_DROP 188 * @see DisconnectCause#CDMA_INTERCEPT 189 * @see DisconnectCause#CDMA_REORDER 190 * @see DisconnectCause#CDMA_SO_REJECT 191 * @see DisconnectCause#CDMA_RETRY_ORDER 192 * @see DisconnectCause#CDMA_ACCESS_FAILURE 193 * @see DisconnectCause#CDMA_PREEMPTED 194 * @see DisconnectCause#CDMA_NOT_EMERGENCY 195 * @see DisconnectCause#CDMA_ACCESS_BLOCKED 196 * @see DisconnectCause#ERROR_UNSPECIFIED 197 */ 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 */ getPreciseDisconnectCause()236 public int getPreciseDisconnectCause() { 237 return mPreciseDisconnectCause; 238 } 239 240 @Override describeContents()241 public int describeContents() { 242 return 0; 243 } 244 245 @Override writeToParcel(Parcel out, int flags)246 public void writeToParcel(Parcel out, int flags) { 247 out.writeInt(mRingingCallState); 248 out.writeInt(mForegroundCallState); 249 out.writeInt(mBackgroundCallState); 250 out.writeInt(mDisconnectCause); 251 out.writeInt(mPreciseDisconnectCause); 252 } 253 254 public static final Parcelable.Creator<PreciseCallState> CREATOR 255 = new Parcelable.Creator<PreciseCallState>() { 256 257 public PreciseCallState createFromParcel(Parcel in) { 258 return new PreciseCallState(in); 259 } 260 261 public PreciseCallState[] newArray(int size) { 262 return new PreciseCallState[size]; 263 } 264 }; 265 266 @Override hashCode()267 public int hashCode() { 268 final int prime = 31; 269 int result = 1; 270 result = prime * result + mRingingCallState; 271 result = prime * result + mForegroundCallState; 272 result = prime * result + mBackgroundCallState; 273 result = prime * result + mDisconnectCause; 274 result = prime * result + mPreciseDisconnectCause; 275 return result; 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