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