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