ParcelableCall.java revision 07366813cdf3768dcd69a1f744023747564d654a
1/* 2 * Copyright 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.telecom; 18 19import android.net.Uri; 20import android.os.Bundle; 21import android.os.Parcel; 22import android.os.Parcelable; 23import android.os.RemoteException; 24 25import java.util.ArrayList; 26import java.util.Collections; 27import java.util.List; 28 29import com.android.internal.telecom.IVideoProvider; 30 31/** 32 * Information about a call that is used between InCallService and Telecom. 33 * @hide 34 */ 35public final class ParcelableCall implements Parcelable { 36 private final String mId; 37 private final int mState; 38 private final DisconnectCause mDisconnectCause; 39 private final List<String> mCannedSmsResponses; 40 private final int mCapabilities; 41 private final int mProperties; 42 private final long mConnectTimeMillis; 43 private final Uri mHandle; 44 private final int mHandlePresentation; 45 private final String mCallerDisplayName; 46 private final int mCallerDisplayNamePresentation; 47 private final GatewayInfo mGatewayInfo; 48 private final PhoneAccountHandle mAccountHandle; 49 private final IVideoProvider mVideoCallProvider; 50 private InCallService.VideoCall mVideoCall; 51 private final String mParentCallId; 52 private final List<String> mChildCallIds; 53 private final StatusHints mStatusHints; 54 private final int mVideoState; 55 private final List<String> mConferenceableCallIds; 56 private final Bundle mExtras; 57 private int mCallSubstate; 58 59 public ParcelableCall( 60 String id, 61 int state, 62 DisconnectCause disconnectCause, 63 List<String> cannedSmsResponses, 64 int capabilities, 65 int properties, 66 long connectTimeMillis, 67 Uri handle, 68 int handlePresentation, 69 String callerDisplayName, 70 int callerDisplayNamePresentation, 71 GatewayInfo gatewayInfo, 72 PhoneAccountHandle accountHandle, 73 IVideoProvider videoCallProvider, 74 String parentCallId, 75 List<String> childCallIds, 76 StatusHints statusHints, 77 int videoState, 78 List<String> conferenceableCallIds, 79 Bundle extras, 80 int callSubstate) { 81 mId = id; 82 mState = state; 83 mDisconnectCause = disconnectCause; 84 mCannedSmsResponses = cannedSmsResponses; 85 mCapabilities = capabilities; 86 mProperties = properties; 87 mConnectTimeMillis = connectTimeMillis; 88 mHandle = handle; 89 mHandlePresentation = handlePresentation; 90 mCallerDisplayName = callerDisplayName; 91 mCallerDisplayNamePresentation = callerDisplayNamePresentation; 92 mGatewayInfo = gatewayInfo; 93 mAccountHandle = accountHandle; 94 mVideoCallProvider = videoCallProvider; 95 mParentCallId = parentCallId; 96 mChildCallIds = childCallIds; 97 mStatusHints = statusHints; 98 mVideoState = videoState; 99 mConferenceableCallIds = Collections.unmodifiableList(conferenceableCallIds); 100 mExtras = extras; 101 mCallSubstate = callSubstate; 102 } 103 104 /** The unique ID of the call. */ 105 public String getId() { 106 return mId; 107 } 108 109 /** The current state of the call. */ 110 public int getState() { 111 return mState; 112 } 113 114 /** 115 * Reason for disconnection, as described by {@link android.telecomm.DisconnectCause}. Valid 116 * when call state is {@link CallState#DISCONNECTED}. 117 */ 118 public DisconnectCause getDisconnectCause() { 119 return mDisconnectCause; 120 } 121 122 /** 123 * The set of possible text message responses when this call is incoming. 124 */ 125 public List<String> getCannedSmsResponses() { 126 return mCannedSmsResponses; 127 } 128 129 // Bit mask of actions a call supports, values are defined in {@link CallCapabilities}. 130 public int getCapabilities() { 131 return mCapabilities; 132 } 133 134 /** Bitmask of properties of the call. */ 135 public int getProperties() { return mProperties; } 136 137 /** The time that the call switched to the active state. */ 138 public long getConnectTimeMillis() { 139 return mConnectTimeMillis; 140 } 141 142 /** The endpoint to which the call is connected. */ 143 public Uri getHandle() { 144 return mHandle; 145 } 146 147 /** 148 * The presentation requirements for the handle. See {@link TelecomManager} for valid values. 149 */ 150 public int getHandlePresentation() { 151 return mHandlePresentation; 152 } 153 154 /** The endpoint to which the call is connected. */ 155 public String getCallerDisplayName() { 156 return mCallerDisplayName; 157 } 158 159 /** 160 * The presentation requirements for the caller display name. 161 * See {@link TelecomManager} for valid values. 162 */ 163 public int getCallerDisplayNamePresentation() { 164 return mCallerDisplayNamePresentation; 165 } 166 167 /** Gateway information for the call. */ 168 public GatewayInfo getGatewayInfo() { 169 return mGatewayInfo; 170 } 171 172 /** PhoneAccountHandle information for the call. */ 173 public PhoneAccountHandle getAccountHandle() { 174 return mAccountHandle; 175 } 176 177 /** 178 * Returns an object for remotely communicating through the video call provider's binder. 179 * @return The video call. 180 */ 181 public InCallService.VideoCall getVideoCall() { 182 if (mVideoCall == null && mVideoCallProvider != null) { 183 try { 184 mVideoCall = new VideoCallImpl(mVideoCallProvider); 185 } catch (RemoteException ignored) { 186 // Ignore RemoteException. 187 } 188 } 189 190 return mVideoCall; 191 } 192 193 /** 194 * The conference call to which this call is conferenced. Null if not conferenced. 195 */ 196 public String getParentCallId() { 197 return mParentCallId; 198 } 199 200 /** 201 * The child call-IDs if this call is a conference call. Returns an empty list if this is not 202 * a conference call or if the conference call contains no children. 203 */ 204 public List<String> getChildCallIds() { 205 return mChildCallIds; 206 } 207 208 public List<String> getConferenceableCallIds() { 209 return mConferenceableCallIds; 210 } 211 212 /** 213 * The status label and icon. 214 * 215 * @return Status hints. 216 */ 217 public StatusHints getStatusHints() { 218 return mStatusHints; 219 } 220 221 /** 222 * The video state. 223 * @return The video state of the call. 224 */ 225 public int getVideoState() { 226 return mVideoState; 227 } 228 229 /** 230 * Any extras to pass with the call 231 * 232 * @return a bundle of extras 233 */ 234 public Bundle getExtras() { 235 return mExtras; 236 } 237 238 /** 239 * The call substate. 240 * @return The substate of the call. 241 */ 242 public int getCallSubstate() { 243 return mCallSubstate; 244 } 245 246 /** Responsible for creating ParcelableCall objects for deserialized Parcels. */ 247 public static final Parcelable.Creator<ParcelableCall> CREATOR = 248 new Parcelable.Creator<ParcelableCall> () { 249 @Override 250 public ParcelableCall createFromParcel(Parcel source) { 251 ClassLoader classLoader = ParcelableCall.class.getClassLoader(); 252 String id = source.readString(); 253 int state = source.readInt(); 254 DisconnectCause disconnectCause = source.readParcelable(classLoader); 255 List<String> cannedSmsResponses = new ArrayList<>(); 256 source.readList(cannedSmsResponses, classLoader); 257 int capabilities = source.readInt(); 258 int properties = source.readInt(); 259 long connectTimeMillis = source.readLong(); 260 Uri handle = source.readParcelable(classLoader); 261 int handlePresentation = source.readInt(); 262 String callerDisplayName = source.readString(); 263 int callerDisplayNamePresentation = source.readInt(); 264 GatewayInfo gatewayInfo = source.readParcelable(classLoader); 265 PhoneAccountHandle accountHandle = source.readParcelable(classLoader); 266 IVideoProvider videoCallProvider = 267 IVideoProvider.Stub.asInterface(source.readStrongBinder()); 268 String parentCallId = source.readString(); 269 List<String> childCallIds = new ArrayList<>(); 270 source.readList(childCallIds, classLoader); 271 StatusHints statusHints = source.readParcelable(classLoader); 272 int videoState = source.readInt(); 273 List<String> conferenceableCallIds = new ArrayList<>(); 274 source.readList(conferenceableCallIds, classLoader); 275 Bundle extras = source.readParcelable(classLoader); 276 int callSubstate = source.readInt(); 277 return new ParcelableCall( 278 id, 279 state, 280 disconnectCause, 281 cannedSmsResponses, 282 capabilities, 283 properties, 284 connectTimeMillis, 285 handle, 286 handlePresentation, 287 callerDisplayName, 288 callerDisplayNamePresentation, 289 gatewayInfo, 290 accountHandle, 291 videoCallProvider, 292 parentCallId, 293 childCallIds, 294 statusHints, 295 videoState, 296 conferenceableCallIds, 297 extras, 298 callSubstate); 299 } 300 301 @Override 302 public ParcelableCall[] newArray(int size) { 303 return new ParcelableCall[size]; 304 } 305 }; 306 307 /** {@inheritDoc} */ 308 @Override 309 public int describeContents() { 310 return 0; 311 } 312 313 /** Writes ParcelableCall object into a Parcel. */ 314 @Override 315 public void writeToParcel(Parcel destination, int flags) { 316 destination.writeString(mId); 317 destination.writeInt(mState); 318 destination.writeParcelable(mDisconnectCause, 0); 319 destination.writeList(mCannedSmsResponses); 320 destination.writeInt(mCapabilities); 321 destination.writeInt(mProperties); 322 destination.writeLong(mConnectTimeMillis); 323 destination.writeParcelable(mHandle, 0); 324 destination.writeInt(mHandlePresentation); 325 destination.writeString(mCallerDisplayName); 326 destination.writeInt(mCallerDisplayNamePresentation); 327 destination.writeParcelable(mGatewayInfo, 0); 328 destination.writeParcelable(mAccountHandle, 0); 329 destination.writeStrongBinder( 330 mVideoCallProvider != null ? mVideoCallProvider.asBinder() : null); 331 destination.writeString(mParentCallId); 332 destination.writeList(mChildCallIds); 333 destination.writeParcelable(mStatusHints, 0); 334 destination.writeInt(mVideoState); 335 destination.writeList(mConferenceableCallIds); 336 destination.writeParcelable(mExtras, 0); 337 destination.writeInt(mCallSubstate); 338 } 339 340 @Override 341 public String toString() { 342 return String.format("[%s, parent:%s, children:%s]", mId, mParentCallId, mChildCallIds); 343 } 344} 345