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