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