ParcelableConnection.java revision 6b7f955c2d9b231660b8c54f8ef8e8e6ad802625
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; 23 24import com.android.internal.telecom.IVideoProvider; 25 26import java.util.ArrayList; 27import 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 */ 35public final class ParcelableConnection implements Parcelable { 36 private final PhoneAccountHandle mPhoneAccount; 37 private final int mState; 38 private final int mConnectionCapabilities; 39 private final Uri mAddress; 40 private final int mAddressPresentation; 41 private final String mCallerDisplayName; 42 private final int mCallerDisplayNamePresentation; 43 private final IVideoProvider mVideoProvider; 44 private final int mVideoState; 45 private final boolean mRingbackRequested; 46 private final boolean mIsVoipAudioMode; 47 private final StatusHints mStatusHints; 48 private final DisconnectCause mDisconnectCause; 49 private final List<String> mConferenceableConnectionIds; 50 private final Bundle mExtras; 51 52 /** @hide */ 53 public ParcelableConnection( 54 PhoneAccountHandle phoneAccount, 55 int state, 56 int capabilities, 57 Uri address, 58 int addressPresentation, 59 String callerDisplayName, 60 int callerDisplayNamePresentation, 61 IVideoProvider videoProvider, 62 int videoState, 63 boolean ringbackRequested, 64 boolean isVoipAudioMode, 65 StatusHints statusHints, 66 DisconnectCause disconnectCause, 67 List<String> conferenceableConnectionIds, 68 Bundle extras) { 69 mPhoneAccount = phoneAccount; 70 mState = state; 71 mConnectionCapabilities = capabilities; 72 mAddress = address; 73 mAddressPresentation = addressPresentation; 74 mCallerDisplayName = callerDisplayName; 75 mCallerDisplayNamePresentation = callerDisplayNamePresentation; 76 mVideoProvider = videoProvider; 77 mVideoState = videoState; 78 mRingbackRequested = ringbackRequested; 79 mIsVoipAudioMode = isVoipAudioMode; 80 mStatusHints = statusHints; 81 mDisconnectCause = disconnectCause; 82 mConferenceableConnectionIds = conferenceableConnectionIds; 83 mExtras = extras; 84 } 85 86 public PhoneAccountHandle getPhoneAccount() { 87 return mPhoneAccount; 88 } 89 90 public int getState() { 91 return mState; 92 } 93 94 // Bit mask of actions a call supports, values are defined in {@link CallCapabilities}. 95 public int getConnectionCapabilities() { 96 return mConnectionCapabilities; 97 } 98 99 public Uri getHandle() { 100 return mAddress; 101 } 102 103 public int getHandlePresentation() { 104 return mAddressPresentation; 105 } 106 107 public String getCallerDisplayName() { 108 return mCallerDisplayName; 109 } 110 111 public int getCallerDisplayNamePresentation() { 112 return mCallerDisplayNamePresentation; 113 } 114 115 public IVideoProvider getVideoProvider() { 116 return mVideoProvider; 117 } 118 119 public int getVideoState() { 120 return mVideoState; 121 } 122 123 public boolean isRingbackRequested() { 124 return mRingbackRequested; 125 } 126 127 public boolean getIsVoipAudioMode() { 128 return mIsVoipAudioMode; 129 } 130 131 public final StatusHints getStatusHints() { 132 return mStatusHints; 133 } 134 135 public final DisconnectCause getDisconnectCause() { 136 return mDisconnectCause; 137 } 138 139 public final List<String> getConferenceableConnectionIds() { 140 return mConferenceableConnectionIds; 141 } 142 143 public final Bundle getExtras() { 144 return mExtras; 145 } 146 147 @Override 148 public String toString() { 149 return new StringBuilder() 150 .append("ParcelableConnection [act:") 151 .append(mPhoneAccount) 152 .append("], state:") 153 .append(mState) 154 .append(", capabilities:") 155 .append(Connection.capabilitiesToString(mConnectionCapabilities)) 156 .append(", extras:") 157 .append(mExtras) 158 .toString(); 159 } 160 161 public static final Parcelable.Creator<ParcelableConnection> CREATOR = 162 new Parcelable.Creator<ParcelableConnection> () { 163 @Override 164 public ParcelableConnection createFromParcel(Parcel source) { 165 ClassLoader classLoader = ParcelableConnection.class.getClassLoader(); 166 167 PhoneAccountHandle phoneAccount = source.readParcelable(classLoader); 168 int state = source.readInt(); 169 int capabilities = source.readInt(); 170 Uri address = source.readParcelable(classLoader); 171 int addressPresentation = source.readInt(); 172 String callerDisplayName = source.readString(); 173 int callerDisplayNamePresentation = source.readInt(); 174 IVideoProvider videoCallProvider = 175 IVideoProvider.Stub.asInterface(source.readStrongBinder()); 176 int videoState = source.readInt(); 177 boolean ringbackRequested = source.readByte() == 1; 178 boolean audioModeIsVoip = source.readByte() == 1; 179 StatusHints statusHints = source.readParcelable(classLoader); 180 DisconnectCause disconnectCause = source.readParcelable(classLoader); 181 List<String> conferenceableConnectionIds = new ArrayList<>(); 182 source.readStringList(conferenceableConnectionIds); 183 Bundle extras = source.readBundle(classLoader); 184 185 return new ParcelableConnection( 186 phoneAccount, 187 state, 188 capabilities, 189 address, 190 addressPresentation, 191 callerDisplayName, 192 callerDisplayNamePresentation, 193 videoCallProvider, 194 videoState, 195 ringbackRequested, 196 audioModeIsVoip, 197 statusHints, 198 disconnectCause, 199 conferenceableConnectionIds, 200 extras); 201 } 202 203 @Override 204 public ParcelableConnection[] newArray(int size) { 205 return new ParcelableConnection[size]; 206 } 207 }; 208 209 /** {@inheritDoc} */ 210 @Override 211 public int describeContents() { 212 return 0; 213 } 214 215 /** Writes ParcelableConnection object into a Parcel. */ 216 @Override 217 public void writeToParcel(Parcel destination, int flags) { 218 destination.writeParcelable(mPhoneAccount, 0); 219 destination.writeInt(mState); 220 destination.writeInt(mConnectionCapabilities); 221 destination.writeParcelable(mAddress, 0); 222 destination.writeInt(mAddressPresentation); 223 destination.writeString(mCallerDisplayName); 224 destination.writeInt(mCallerDisplayNamePresentation); 225 destination.writeStrongBinder( 226 mVideoProvider != null ? mVideoProvider.asBinder() : null); 227 destination.writeInt(mVideoState); 228 destination.writeByte((byte) (mRingbackRequested ? 1 : 0)); 229 destination.writeByte((byte) (mIsVoipAudioMode ? 1 : 0)); 230 destination.writeParcelable(mStatusHints, 0); 231 destination.writeParcelable(mDisconnectCause, 0); 232 destination.writeStringList(mConferenceableConnectionIds); 233 destination.writeBundle(mExtras); 234 } 235} 236