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