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 17 package android.telecom; 18 19 import android.net.Uri; 20 import android.os.Bundle; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 import android.os.RemoteException; 24 25 import java.util.ArrayList; 26 import java.util.Collections; 27 import java.util.List; 28 29 import com.android.internal.telecom.IVideoProvider; 30 31 /** 32 * Information about a call that is used between InCallService and Telecom. 33 * @hide 34 */ 35 public 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 int mSupportedAudioRoutes; 43 private final long mConnectTimeMillis; 44 private final Uri mHandle; 45 private final int mHandlePresentation; 46 private final String mCallerDisplayName; 47 private final int mCallerDisplayNamePresentation; 48 private final GatewayInfo mGatewayInfo; 49 private final PhoneAccountHandle mAccountHandle; 50 private final boolean mIsVideoCallProviderChanged; 51 private final IVideoProvider mVideoCallProvider; 52 private VideoCallImpl mVideoCall; 53 private final boolean mIsRttCallChanged; 54 private final ParcelableRttCall mRttCall; 55 private final String mParentCallId; 56 private final List<String> mChildCallIds; 57 private final StatusHints mStatusHints; 58 private final int mVideoState; 59 private final List<String> mConferenceableCallIds; 60 private final Bundle mIntentExtras; 61 private final Bundle mExtras; 62 private final long mCreationTimeMillis; 63 ParcelableCall( String id, int state, DisconnectCause disconnectCause, List<String> cannedSmsResponses, int capabilities, int properties, int supportedAudioRoutes, long connectTimeMillis, Uri handle, int handlePresentation, String callerDisplayName, int callerDisplayNamePresentation, GatewayInfo gatewayInfo, PhoneAccountHandle accountHandle, boolean isVideoCallProviderChanged, IVideoProvider videoCallProvider, boolean isRttCallChanged, ParcelableRttCall rttCall, String parentCallId, List<String> childCallIds, StatusHints statusHints, int videoState, List<String> conferenceableCallIds, Bundle intentExtras, Bundle extras, long creationTimeMillis)64 public ParcelableCall( 65 String id, 66 int state, 67 DisconnectCause disconnectCause, 68 List<String> cannedSmsResponses, 69 int capabilities, 70 int properties, 71 int supportedAudioRoutes, 72 long connectTimeMillis, 73 Uri handle, 74 int handlePresentation, 75 String callerDisplayName, 76 int callerDisplayNamePresentation, 77 GatewayInfo gatewayInfo, 78 PhoneAccountHandle accountHandle, 79 boolean isVideoCallProviderChanged, 80 IVideoProvider videoCallProvider, 81 boolean isRttCallChanged, 82 ParcelableRttCall rttCall, 83 String parentCallId, 84 List<String> childCallIds, 85 StatusHints statusHints, 86 int videoState, 87 List<String> conferenceableCallIds, 88 Bundle intentExtras, 89 Bundle extras, 90 long creationTimeMillis) { 91 mId = id; 92 mState = state; 93 mDisconnectCause = disconnectCause; 94 mCannedSmsResponses = cannedSmsResponses; 95 mCapabilities = capabilities; 96 mProperties = properties; 97 mSupportedAudioRoutes = supportedAudioRoutes; 98 mConnectTimeMillis = connectTimeMillis; 99 mHandle = handle; 100 mHandlePresentation = handlePresentation; 101 mCallerDisplayName = callerDisplayName; 102 mCallerDisplayNamePresentation = callerDisplayNamePresentation; 103 mGatewayInfo = gatewayInfo; 104 mAccountHandle = accountHandle; 105 mIsVideoCallProviderChanged = isVideoCallProviderChanged; 106 mVideoCallProvider = videoCallProvider; 107 mIsRttCallChanged = isRttCallChanged; 108 mRttCall = rttCall; 109 mParentCallId = parentCallId; 110 mChildCallIds = childCallIds; 111 mStatusHints = statusHints; 112 mVideoState = videoState; 113 mConferenceableCallIds = Collections.unmodifiableList(conferenceableCallIds); 114 mIntentExtras = intentExtras; 115 mExtras = extras; 116 mCreationTimeMillis = creationTimeMillis; 117 } 118 119 /** The unique ID of the call. */ getId()120 public String getId() { 121 return mId; 122 } 123 124 /** The current state of the call. */ getState()125 public int getState() { 126 return mState; 127 } 128 129 /** 130 * Reason for disconnection, as described by {@link android.telecomm.DisconnectCause}. Valid 131 * when call state is {@link CallState#DISCONNECTED}. 132 */ getDisconnectCause()133 public DisconnectCause getDisconnectCause() { 134 return mDisconnectCause; 135 } 136 137 /** 138 * The set of possible text message responses when this call is incoming. 139 */ getCannedSmsResponses()140 public List<String> getCannedSmsResponses() { 141 return mCannedSmsResponses; 142 } 143 144 // Bit mask of actions a call supports, values are defined in {@link CallCapabilities}. getCapabilities()145 public int getCapabilities() { 146 return mCapabilities; 147 } 148 149 /** Bitmask of properties of the call. */ getProperties()150 public int getProperties() { return mProperties; } 151 152 /** Bitmask of supported routes of the call */ getSupportedAudioRoutes()153 public int getSupportedAudioRoutes() { 154 return mSupportedAudioRoutes; 155 } 156 157 /** The time that the call switched to the active state. */ getConnectTimeMillis()158 public long getConnectTimeMillis() { 159 return mConnectTimeMillis; 160 } 161 162 /** The endpoint to which the call is connected. */ getHandle()163 public Uri getHandle() { 164 return mHandle; 165 } 166 167 /** 168 * The presentation requirements for the handle. See {@link TelecomManager} for valid values. 169 */ getHandlePresentation()170 public int getHandlePresentation() { 171 return mHandlePresentation; 172 } 173 174 /** The endpoint to which the call is connected. */ getCallerDisplayName()175 public String getCallerDisplayName() { 176 return mCallerDisplayName; 177 } 178 179 /** 180 * The presentation requirements for the caller display name. 181 * See {@link TelecomManager} for valid values. 182 */ getCallerDisplayNamePresentation()183 public int getCallerDisplayNamePresentation() { 184 return mCallerDisplayNamePresentation; 185 } 186 187 /** Gateway information for the call. */ getGatewayInfo()188 public GatewayInfo getGatewayInfo() { 189 return mGatewayInfo; 190 } 191 192 /** PhoneAccountHandle information for the call. */ getAccountHandle()193 public PhoneAccountHandle getAccountHandle() { 194 return mAccountHandle; 195 } 196 197 /** 198 * Returns an object for remotely communicating through the video call provider's binder. 199 * 200 * @param callingPackageName the package name of the calling InCallService. 201 * @param targetSdkVersion the target SDK version of the calling InCallService. 202 * @return The video call. 203 */ getVideoCallImpl(String callingPackageName, int targetSdkVersion)204 public VideoCallImpl getVideoCallImpl(String callingPackageName, int targetSdkVersion) { 205 if (mVideoCall == null && mVideoCallProvider != null) { 206 try { 207 mVideoCall = new VideoCallImpl(mVideoCallProvider, callingPackageName, 208 targetSdkVersion); 209 } catch (RemoteException ignored) { 210 // Ignore RemoteException. 211 } 212 } 213 214 return mVideoCall; 215 } 216 getIsRttCallChanged()217 public boolean getIsRttCallChanged() { 218 return mIsRttCallChanged; 219 } 220 221 /** 222 * RTT communication channel information 223 * @return The ParcelableRttCall 224 */ getParcelableRttCall()225 public ParcelableRttCall getParcelableRttCall() { 226 return mRttCall; 227 } 228 229 /** 230 * The conference call to which this call is conferenced. Null if not conferenced. 231 */ getParentCallId()232 public String getParentCallId() { 233 return mParentCallId; 234 } 235 236 /** 237 * The child call-IDs if this call is a conference call. Returns an empty list if this is not 238 * a conference call or if the conference call contains no children. 239 */ getChildCallIds()240 public List<String> getChildCallIds() { 241 return mChildCallIds; 242 } 243 getConferenceableCallIds()244 public List<String> getConferenceableCallIds() { 245 return mConferenceableCallIds; 246 } 247 248 /** 249 * The status label and icon. 250 * 251 * @return Status hints. 252 */ getStatusHints()253 public StatusHints getStatusHints() { 254 return mStatusHints; 255 } 256 257 /** 258 * The video state. 259 * @return The video state of the call. 260 */ getVideoState()261 public int getVideoState() { 262 return mVideoState; 263 } 264 265 /** 266 * Any extras associated with this call. 267 * 268 * @return a bundle of extras 269 */ getExtras()270 public Bundle getExtras() { 271 return mExtras; 272 } 273 274 /** 275 * Extras passed in as part of the original call intent. 276 * 277 * @return The intent extras. 278 */ getIntentExtras()279 public Bundle getIntentExtras() { 280 return mIntentExtras; 281 } 282 283 /** 284 * Indicates to the receiver of the {@link ParcelableCall} whether a change has occurred in the 285 * {@link android.telecom.InCallService.VideoCall} associated with this call. Since 286 * {@link #getVideoCall()} creates a new {@link VideoCallImpl}, it is useful to know whether 287 * the provider has changed (which can influence whether it is accessed). 288 * 289 * @return {@code true} if the video call changed, {@code false} otherwise. 290 */ isVideoCallProviderChanged()291 public boolean isVideoCallProviderChanged() { 292 return mIsVideoCallProviderChanged; 293 } 294 295 /** 296 * @return The time the call was created, in milliseconds since the epoch. 297 */ getCreationTimeMillis()298 public long getCreationTimeMillis() { 299 return mCreationTimeMillis; 300 } 301 302 /** Responsible for creating ParcelableCall objects for deserialized Parcels. */ 303 public static final Parcelable.Creator<ParcelableCall> CREATOR = 304 new Parcelable.Creator<ParcelableCall> () { 305 @Override 306 public ParcelableCall createFromParcel(Parcel source) { 307 ClassLoader classLoader = ParcelableCall.class.getClassLoader(); 308 String id = source.readString(); 309 int state = source.readInt(); 310 DisconnectCause disconnectCause = source.readParcelable(classLoader); 311 List<String> cannedSmsResponses = new ArrayList<>(); 312 source.readList(cannedSmsResponses, classLoader); 313 int capabilities = source.readInt(); 314 int properties = source.readInt(); 315 long connectTimeMillis = source.readLong(); 316 Uri handle = source.readParcelable(classLoader); 317 int handlePresentation = source.readInt(); 318 String callerDisplayName = source.readString(); 319 int callerDisplayNamePresentation = source.readInt(); 320 GatewayInfo gatewayInfo = source.readParcelable(classLoader); 321 PhoneAccountHandle accountHandle = source.readParcelable(classLoader); 322 boolean isVideoCallProviderChanged = source.readByte() == 1; 323 IVideoProvider videoCallProvider = 324 IVideoProvider.Stub.asInterface(source.readStrongBinder()); 325 String parentCallId = source.readString(); 326 List<String> childCallIds = new ArrayList<>(); 327 source.readList(childCallIds, classLoader); 328 StatusHints statusHints = source.readParcelable(classLoader); 329 int videoState = source.readInt(); 330 List<String> conferenceableCallIds = new ArrayList<>(); 331 source.readList(conferenceableCallIds, classLoader); 332 Bundle intentExtras = source.readBundle(classLoader); 333 Bundle extras = source.readBundle(classLoader); 334 int supportedAudioRoutes = source.readInt(); 335 boolean isRttCallChanged = source.readByte() == 1; 336 ParcelableRttCall rttCall = source.readParcelable(classLoader); 337 long creationTimeMillis = source.readLong(); 338 return new ParcelableCall( 339 id, 340 state, 341 disconnectCause, 342 cannedSmsResponses, 343 capabilities, 344 properties, 345 supportedAudioRoutes, 346 connectTimeMillis, 347 handle, 348 handlePresentation, 349 callerDisplayName, 350 callerDisplayNamePresentation, 351 gatewayInfo, 352 accountHandle, 353 isVideoCallProviderChanged, 354 videoCallProvider, 355 isRttCallChanged, 356 rttCall, 357 parentCallId, 358 childCallIds, 359 statusHints, 360 videoState, 361 conferenceableCallIds, 362 intentExtras, 363 extras, 364 creationTimeMillis); 365 } 366 367 @Override 368 public ParcelableCall[] newArray(int size) { 369 return new ParcelableCall[size]; 370 } 371 }; 372 373 /** {@inheritDoc} */ 374 @Override describeContents()375 public int describeContents() { 376 return 0; 377 } 378 379 /** Writes ParcelableCall object into a Parcel. */ 380 @Override writeToParcel(Parcel destination, int flags)381 public void writeToParcel(Parcel destination, int flags) { 382 destination.writeString(mId); 383 destination.writeInt(mState); 384 destination.writeParcelable(mDisconnectCause, 0); 385 destination.writeList(mCannedSmsResponses); 386 destination.writeInt(mCapabilities); 387 destination.writeInt(mProperties); 388 destination.writeLong(mConnectTimeMillis); 389 destination.writeParcelable(mHandle, 0); 390 destination.writeInt(mHandlePresentation); 391 destination.writeString(mCallerDisplayName); 392 destination.writeInt(mCallerDisplayNamePresentation); 393 destination.writeParcelable(mGatewayInfo, 0); 394 destination.writeParcelable(mAccountHandle, 0); 395 destination.writeByte((byte) (mIsVideoCallProviderChanged ? 1 : 0)); 396 destination.writeStrongBinder( 397 mVideoCallProvider != null ? mVideoCallProvider.asBinder() : null); 398 destination.writeString(mParentCallId); 399 destination.writeList(mChildCallIds); 400 destination.writeParcelable(mStatusHints, 0); 401 destination.writeInt(mVideoState); 402 destination.writeList(mConferenceableCallIds); 403 destination.writeBundle(mIntentExtras); 404 destination.writeBundle(mExtras); 405 destination.writeInt(mSupportedAudioRoutes); 406 destination.writeByte((byte) (mIsRttCallChanged ? 1 : 0)); 407 destination.writeParcelable(mRttCall, 0); 408 destination.writeLong(mCreationTimeMillis); 409 } 410 411 @Override toString()412 public String toString() { 413 return String.format("[%s, parent:%s, children:%s]", mId, mParentCallId, mChildCallIds); 414 } 415 } 416