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 24 import com.android.internal.telecom.IVideoProvider; 25 26 import java.util.ArrayList; 27 import java.util.List; 28 29 /** 30 * Information about a connection that is used between Telecom and the ConnectionService. 31 * This is used to send initial Connection information to Telecom when the connection is 32 * first created. 33 * @hide 34 */ 35 public final class ParcelableConnection implements Parcelable { 36 private final PhoneAccountHandle mPhoneAccount; 37 private final int mState; 38 private final int mConnectionCapabilities; 39 private final int mConnectionProperties; 40 private final int mSupportedAudioRoutes; 41 private final Uri mAddress; 42 private final int mAddressPresentation; 43 private final String mCallerDisplayName; 44 private final int mCallerDisplayNamePresentation; 45 private final IVideoProvider mVideoProvider; 46 private final int mVideoState; 47 private final boolean mRingbackRequested; 48 private final boolean mIsVoipAudioMode; 49 private final long mConnectTimeMillis; 50 private final long mConnectElapsedTimeMillis; 51 private final StatusHints mStatusHints; 52 private final DisconnectCause mDisconnectCause; 53 private final List<String> mConferenceableConnectionIds; 54 private final Bundle mExtras; 55 private String mParentCallId; 56 private @Call.Details.CallDirection int mCallDirection; 57 private @Connection.VerificationStatus int mCallerNumberVerificationStatus; 58 59 /** @hide */ ParcelableConnection( PhoneAccountHandle phoneAccount, int state, int capabilities, int properties, int supportedAudioRoutes, Uri address, int addressPresentation, String callerDisplayName, int callerDisplayNamePresentation, IVideoProvider videoProvider, int videoState, boolean ringbackRequested, boolean isVoipAudioMode, long connectTimeMillis, long connectElapsedTimeMillis, StatusHints statusHints, DisconnectCause disconnectCause, List<String> conferenceableConnectionIds, Bundle extras, String parentCallId, @Call.Details.CallDirection int callDirection, @Connection.VerificationStatus int callerNumberVerificationStatus)60 public ParcelableConnection( 61 PhoneAccountHandle phoneAccount, 62 int state, 63 int capabilities, 64 int properties, 65 int supportedAudioRoutes, 66 Uri address, 67 int addressPresentation, 68 String callerDisplayName, 69 int callerDisplayNamePresentation, 70 IVideoProvider videoProvider, 71 int videoState, 72 boolean ringbackRequested, 73 boolean isVoipAudioMode, 74 long connectTimeMillis, 75 long connectElapsedTimeMillis, 76 StatusHints statusHints, 77 DisconnectCause disconnectCause, 78 List<String> conferenceableConnectionIds, 79 Bundle extras, 80 String parentCallId, 81 @Call.Details.CallDirection int callDirection, 82 @Connection.VerificationStatus int callerNumberVerificationStatus) { 83 this(phoneAccount, state, capabilities, properties, supportedAudioRoutes, address, 84 addressPresentation, callerDisplayName, callerDisplayNamePresentation, 85 videoProvider, videoState, ringbackRequested, isVoipAudioMode, connectTimeMillis, 86 connectElapsedTimeMillis, statusHints, disconnectCause, conferenceableConnectionIds, 87 extras, callerNumberVerificationStatus); 88 mParentCallId = parentCallId; 89 mCallDirection = callDirection; 90 } 91 92 /** @hide */ ParcelableConnection( PhoneAccountHandle phoneAccount, int state, int capabilities, int properties, int supportedAudioRoutes, Uri address, int addressPresentation, String callerDisplayName, int callerDisplayNamePresentation, IVideoProvider videoProvider, int videoState, boolean ringbackRequested, boolean isVoipAudioMode, long connectTimeMillis, long connectElapsedTimeMillis, StatusHints statusHints, DisconnectCause disconnectCause, List<String> conferenceableConnectionIds, Bundle extras, @Connection.VerificationStatus int callerNumberVerificationStatus)93 public ParcelableConnection( 94 PhoneAccountHandle phoneAccount, 95 int state, 96 int capabilities, 97 int properties, 98 int supportedAudioRoutes, 99 Uri address, 100 int addressPresentation, 101 String callerDisplayName, 102 int callerDisplayNamePresentation, 103 IVideoProvider videoProvider, 104 int videoState, 105 boolean ringbackRequested, 106 boolean isVoipAudioMode, 107 long connectTimeMillis, 108 long connectElapsedTimeMillis, 109 StatusHints statusHints, 110 DisconnectCause disconnectCause, 111 List<String> conferenceableConnectionIds, 112 Bundle extras, 113 @Connection.VerificationStatus int callerNumberVerificationStatus) { 114 mPhoneAccount = phoneAccount; 115 mState = state; 116 mConnectionCapabilities = capabilities; 117 mConnectionProperties = properties; 118 mSupportedAudioRoutes = supportedAudioRoutes; 119 mAddress = address; 120 mAddressPresentation = addressPresentation; 121 mCallerDisplayName = callerDisplayName; 122 mCallerDisplayNamePresentation = callerDisplayNamePresentation; 123 mVideoProvider = videoProvider; 124 mVideoState = videoState; 125 mRingbackRequested = ringbackRequested; 126 mIsVoipAudioMode = isVoipAudioMode; 127 mConnectTimeMillis = connectTimeMillis; 128 mConnectElapsedTimeMillis = connectElapsedTimeMillis; 129 mStatusHints = statusHints; 130 mDisconnectCause = disconnectCause; 131 mConferenceableConnectionIds = conferenceableConnectionIds; 132 mExtras = extras; 133 mParentCallId = null; 134 mCallDirection = Call.Details.DIRECTION_UNKNOWN; 135 mCallerNumberVerificationStatus = callerNumberVerificationStatus; 136 } 137 getPhoneAccount()138 public PhoneAccountHandle getPhoneAccount() { 139 return mPhoneAccount; 140 } 141 getState()142 public int getState() { 143 return mState; 144 } 145 146 /** 147 * Returns the current connection capabilities bit-mask. Connection capabilities are defined as 148 * {@code CAPABILITY_*} constants in {@link Connection}. 149 * 150 * @return Bit-mask containing capabilities of the connection. 151 */ getConnectionCapabilities()152 public int getConnectionCapabilities() { 153 return mConnectionCapabilities; 154 } 155 156 /** 157 * Returns the current connection properties bit-mask. Connection properties are defined as 158 * {@code PROPERTY_*} constants in {@link Connection}. 159 * 160 * @return Bit-mask containing properties of the connection. 161 */ getConnectionProperties()162 public int getConnectionProperties() { 163 return mConnectionProperties; 164 } 165 getSupportedAudioRoutes()166 public int getSupportedAudioRoutes() { 167 return mSupportedAudioRoutes; 168 } 169 getHandle()170 public Uri getHandle() { 171 return mAddress; 172 } 173 getHandlePresentation()174 public int getHandlePresentation() { 175 return mAddressPresentation; 176 } 177 getCallerDisplayName()178 public String getCallerDisplayName() { 179 return mCallerDisplayName; 180 } 181 getCallerDisplayNamePresentation()182 public int getCallerDisplayNamePresentation() { 183 return mCallerDisplayNamePresentation; 184 } 185 getVideoProvider()186 public IVideoProvider getVideoProvider() { 187 return mVideoProvider; 188 } 189 getVideoState()190 public int getVideoState() { 191 return mVideoState; 192 } 193 isRingbackRequested()194 public boolean isRingbackRequested() { 195 return mRingbackRequested; 196 } 197 getIsVoipAudioMode()198 public boolean getIsVoipAudioMode() { 199 return mIsVoipAudioMode; 200 } 201 getConnectTimeMillis()202 public long getConnectTimeMillis() { 203 return mConnectTimeMillis; 204 } 205 getConnectElapsedTimeMillis()206 public long getConnectElapsedTimeMillis() { 207 return mConnectElapsedTimeMillis; 208 } 209 getStatusHints()210 public final StatusHints getStatusHints() { 211 return mStatusHints; 212 } 213 getDisconnectCause()214 public final DisconnectCause getDisconnectCause() { 215 return mDisconnectCause; 216 } 217 getConferenceableConnectionIds()218 public final List<String> getConferenceableConnectionIds() { 219 return mConferenceableConnectionIds; 220 } 221 getExtras()222 public final Bundle getExtras() { 223 return mExtras; 224 } 225 getParentCallId()226 public final String getParentCallId() { 227 return mParentCallId; 228 } 229 getCallDirection()230 public @Call.Details.CallDirection int getCallDirection() { 231 return mCallDirection; 232 } 233 getCallerNumberVerificationStatus()234 public @Connection.VerificationStatus int getCallerNumberVerificationStatus() { 235 return mCallerNumberVerificationStatus; 236 } 237 238 @Override toString()239 public String toString() { 240 return new StringBuilder() 241 .append("ParcelableConnection [act:") 242 .append(mPhoneAccount) 243 .append("], state:") 244 .append(mState) 245 .append(", capabilities:") 246 .append(Connection.capabilitiesToString(mConnectionCapabilities)) 247 .append(", properties:") 248 .append(Connection.propertiesToString(mConnectionProperties)) 249 .append(", extras:") 250 .append(mExtras) 251 .append(", parent:") 252 .append(mParentCallId) 253 .append(", callDirection:") 254 .append(mCallDirection) 255 .toString(); 256 } 257 258 public static final @android.annotation.NonNull Parcelable.Creator<ParcelableConnection> CREATOR = 259 new Parcelable.Creator<ParcelableConnection> () { 260 @Override 261 public ParcelableConnection createFromParcel(Parcel source) { 262 ClassLoader classLoader = ParcelableConnection.class.getClassLoader(); 263 264 PhoneAccountHandle phoneAccount = source.readParcelable(classLoader); 265 int state = source.readInt(); 266 int capabilities = source.readInt(); 267 Uri address = source.readParcelable(classLoader); 268 int addressPresentation = source.readInt(); 269 String callerDisplayName = source.readString(); 270 int callerDisplayNamePresentation = source.readInt(); 271 IVideoProvider videoCallProvider = 272 IVideoProvider.Stub.asInterface(source.readStrongBinder()); 273 int videoState = source.readInt(); 274 boolean ringbackRequested = source.readByte() == 1; 275 boolean audioModeIsVoip = source.readByte() == 1; 276 long connectTimeMillis = source.readLong(); 277 StatusHints statusHints = source.readParcelable(classLoader); 278 DisconnectCause disconnectCause = source.readParcelable(classLoader); 279 List<String> conferenceableConnectionIds = new ArrayList<>(); 280 source.readStringList(conferenceableConnectionIds); 281 Bundle extras = Bundle.setDefusable(source.readBundle(classLoader), true); 282 int properties = source.readInt(); 283 int supportedAudioRoutes = source.readInt(); 284 String parentCallId = source.readString(); 285 long connectElapsedTimeMillis = source.readLong(); 286 int callDirection = source.readInt(); 287 int callerNumberVerificationStatus = source.readInt(); 288 289 return new ParcelableConnection( 290 phoneAccount, 291 state, 292 capabilities, 293 properties, 294 supportedAudioRoutes, 295 address, 296 addressPresentation, 297 callerDisplayName, 298 callerDisplayNamePresentation, 299 videoCallProvider, 300 videoState, 301 ringbackRequested, 302 audioModeIsVoip, 303 connectTimeMillis, 304 connectElapsedTimeMillis, 305 statusHints, 306 disconnectCause, 307 conferenceableConnectionIds, 308 extras, 309 parentCallId, 310 callDirection, 311 callerNumberVerificationStatus); 312 } 313 314 @Override 315 public ParcelableConnection[] newArray(int size) { 316 return new ParcelableConnection[size]; 317 } 318 }; 319 320 /** {@inheritDoc} */ 321 @Override describeContents()322 public int describeContents() { 323 return 0; 324 } 325 326 /** Writes ParcelableConnection object into a Parcel. */ 327 @Override writeToParcel(Parcel destination, int flags)328 public void writeToParcel(Parcel destination, int flags) { 329 destination.writeParcelable(mPhoneAccount, 0); 330 destination.writeInt(mState); 331 destination.writeInt(mConnectionCapabilities); 332 destination.writeParcelable(mAddress, 0); 333 destination.writeInt(mAddressPresentation); 334 destination.writeString(mCallerDisplayName); 335 destination.writeInt(mCallerDisplayNamePresentation); 336 destination.writeStrongBinder( 337 mVideoProvider != null ? mVideoProvider.asBinder() : null); 338 destination.writeInt(mVideoState); 339 destination.writeByte((byte) (mRingbackRequested ? 1 : 0)); 340 destination.writeByte((byte) (mIsVoipAudioMode ? 1 : 0)); 341 destination.writeLong(mConnectTimeMillis); 342 destination.writeParcelable(mStatusHints, 0); 343 destination.writeParcelable(mDisconnectCause, 0); 344 destination.writeStringList(mConferenceableConnectionIds); 345 destination.writeBundle(mExtras); 346 destination.writeInt(mConnectionProperties); 347 destination.writeInt(mSupportedAudioRoutes); 348 destination.writeString(mParentCallId); 349 destination.writeLong(mConnectElapsedTimeMillis); 350 destination.writeInt(mCallDirection); 351 destination.writeInt(mCallerNumberVerificationStatus); 352 } 353 } 354