ParcelableCall.java revision 4538216a31d15b01e18c7b504e51031da0ce6e40
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 boolean mIsVideoCallProviderChanged; 50 private final IVideoProvider mVideoCallProvider; 51 private InCallService.VideoCall mVideoCall; 52 private final String mParentCallId; 53 private final List<String> mChildCallIds; 54 private final StatusHints mStatusHints; 55 private final int mVideoState; 56 private final List<String> mConferenceableCallIds; 57 private final Bundle mExtras; 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 boolean isVideoCallProviderChanged, 74 IVideoProvider videoCallProvider, 75 String parentCallId, 76 List<String> childCallIds, 77 StatusHints statusHints, 78 int videoState, 79 List<String> conferenceableCallIds, 80 Bundle extras) { 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 mIsVideoCallProviderChanged = isVideoCallProviderChanged; 95 mVideoCallProvider = videoCallProvider; 96 mParentCallId = parentCallId; 97 mChildCallIds = childCallIds; 98 mStatusHints = statusHints; 99 mVideoState = videoState; 100 mConferenceableCallIds = Collections.unmodifiableList(conferenceableCallIds); 101 mExtras = extras; 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(Call call) { 182 if (mVideoCall == null && mVideoCallProvider != null) { 183 try { 184 mVideoCall = new VideoCallImpl(mVideoCallProvider, call); 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 * Indicates to the receiver of the {@link ParcelableCall} whether a change has occurred in the 240 * {@link android.telecom.InCallService.VideoCall} associated with this call. Since 241 * {@link #getVideoCall()} creates a new {@link VideoCallImpl}, it is useful to know whether 242 * the provider has changed (which can influence whether it is accessed). 243 * 244 * @return {@code true} if the video call changed, {@code false} otherwise. 245 */ 246 public boolean isVideoCallProviderChanged() { 247 return mIsVideoCallProviderChanged; 248 } 249 250 /** Responsible for creating ParcelableCall objects for deserialized Parcels. */ 251 public static final Parcelable.Creator<ParcelableCall> CREATOR = 252 new Parcelable.Creator<ParcelableCall> () { 253 @Override 254 public ParcelableCall createFromParcel(Parcel source) { 255 ClassLoader classLoader = ParcelableCall.class.getClassLoader(); 256 String id = source.readString(); 257 int state = source.readInt(); 258 DisconnectCause disconnectCause = source.readParcelable(classLoader); 259 List<String> cannedSmsResponses = new ArrayList<>(); 260 source.readList(cannedSmsResponses, classLoader); 261 int capabilities = source.readInt(); 262 int properties = source.readInt(); 263 long connectTimeMillis = source.readLong(); 264 Uri handle = source.readParcelable(classLoader); 265 int handlePresentation = source.readInt(); 266 String callerDisplayName = source.readString(); 267 int callerDisplayNamePresentation = source.readInt(); 268 GatewayInfo gatewayInfo = source.readParcelable(classLoader); 269 PhoneAccountHandle accountHandle = source.readParcelable(classLoader); 270 boolean isVideoCallProviderChanged = source.readByte() == 1; 271 IVideoProvider videoCallProvider = 272 IVideoProvider.Stub.asInterface(source.readStrongBinder()); 273 String parentCallId = source.readString(); 274 List<String> childCallIds = new ArrayList<>(); 275 source.readList(childCallIds, classLoader); 276 StatusHints statusHints = source.readParcelable(classLoader); 277 int videoState = source.readInt(); 278 List<String> conferenceableCallIds = new ArrayList<>(); 279 source.readList(conferenceableCallIds, classLoader); 280 Bundle extras = source.readParcelable(classLoader); 281 return new ParcelableCall( 282 id, 283 state, 284 disconnectCause, 285 cannedSmsResponses, 286 capabilities, 287 properties, 288 connectTimeMillis, 289 handle, 290 handlePresentation, 291 callerDisplayName, 292 callerDisplayNamePresentation, 293 gatewayInfo, 294 accountHandle, 295 isVideoCallProviderChanged, 296 videoCallProvider, 297 parentCallId, 298 childCallIds, 299 statusHints, 300 videoState, 301 conferenceableCallIds, 302 extras); 303 } 304 305 @Override 306 public ParcelableCall[] newArray(int size) { 307 return new ParcelableCall[size]; 308 } 309 }; 310 311 /** {@inheritDoc} */ 312 @Override 313 public int describeContents() { 314 return 0; 315 } 316 317 /** Writes ParcelableCall object into a Parcel. */ 318 @Override 319 public void writeToParcel(Parcel destination, int flags) { 320 destination.writeString(mId); 321 destination.writeInt(mState); 322 destination.writeParcelable(mDisconnectCause, 0); 323 destination.writeList(mCannedSmsResponses); 324 destination.writeInt(mCapabilities); 325 destination.writeInt(mProperties); 326 destination.writeLong(mConnectTimeMillis); 327 destination.writeParcelable(mHandle, 0); 328 destination.writeInt(mHandlePresentation); 329 destination.writeString(mCallerDisplayName); 330 destination.writeInt(mCallerDisplayNamePresentation); 331 destination.writeParcelable(mGatewayInfo, 0); 332 destination.writeParcelable(mAccountHandle, 0); 333 destination.writeByte((byte) (mIsVideoCallProviderChanged ? 1 : 0)); 334 destination.writeStrongBinder( 335 mVideoCallProvider != null ? mVideoCallProvider.asBinder() : null); 336 destination.writeString(mParentCallId); 337 destination.writeList(mChildCallIds); 338 destination.writeParcelable(mStatusHints, 0); 339 destination.writeInt(mVideoState); 340 destination.writeList(mConferenceableCallIds); 341 destination.writeParcelable(mExtras, 0); 342 } 343 344 @Override 345 public String toString() { 346 return String.format("[%s, parent:%s, children:%s]", mId, mParentCallId, mChildCallIds); 347 } 348} 349