blob: e5269f9e149594af9759ec089ce1ba265d8627d3 [file] [log] [blame]
Sailesh Nepal60437932014-04-05 16:44:55 -07001/*
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.telecomm;
18
19import android.net.Uri;
Sailesh Nepal60437932014-04-05 16:44:55 -070020import android.os.Parcel;
21import android.os.Parcelable;
Andrew Lee5dc30752014-06-27 17:02:19 -070022import android.os.RemoteException;
Sailesh Nepal60437932014-04-05 16:44:55 -070023import android.telephony.DisconnectCause;
24
Andrew Lee5dc30752014-06-27 17:02:19 -070025import com.android.internal.telecomm.ICallVideoProvider;
26
Santos Cordon980acb92014-05-31 10:31:19 -070027import java.util.ArrayList;
Santos Cordon980acb92014-05-31 10:31:19 -070028import java.util.List;
Sailesh Nepal60437932014-04-05 16:44:55 -070029
30/**
31 * Information about a call that is used between InCallService and Telecomm.
32 */
33public final class InCallCall implements Parcelable {
34 private final String mId;
35 private final CallState mState;
Ihab Awadfbb092f2014-06-03 18:40:45 -070036 private final int mDisconnectCauseCode;
37 private final String mDisconnectCauseMsg;
Ihab Awadc0677542014-06-10 13:29:47 -070038 private final List<String> mCannedSmsResponses;
Sailesh Nepal60437932014-04-05 16:44:55 -070039 private final int mCapabilities;
40 private final long mConnectTimeMillis;
41 private final Uri mHandle;
Sailesh Nepal61203862014-07-11 14:50:13 -070042 private final int mHandlePresentation;
43 private final String mCallerDisplayName;
44 private final int mCallerDisplayNamePresentation;
Sailesh Nepal60437932014-04-05 16:44:55 -070045 private final GatewayInfo mGatewayInfo;
Evan Charlton6eb262c2014-07-19 18:18:19 -070046 private final PhoneAccountHandle mAccount;
Andrew Lee5dc30752014-06-27 17:02:19 -070047 private final ICallVideoProvider mCallVideoProvider;
48 private RemoteCallVideoProvider mRemoteCallVideoProvider;
Santos Cordon980acb92014-05-31 10:31:19 -070049 private final String mParentCallId;
50 private final List<String> mChildCallIds;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070051 private final StatusHints mStatusHints;
Andrew Lee85f5d422014-07-11 17:22:03 -070052 private final int mVideoState;
Santos Cordon980acb92014-05-31 10:31:19 -070053
54 /** @hide */
Sailesh Nepal60437932014-04-05 16:44:55 -070055 public InCallCall(
56 String id,
57 CallState state,
Ihab Awadfbb092f2014-06-03 18:40:45 -070058 int disconnectCauseCode,
59 String disconnectCauseMsg,
Ihab Awadc0677542014-06-10 13:29:47 -070060 List<String> cannedSmsResponses,
Sailesh Nepal60437932014-04-05 16:44:55 -070061 int capabilities,
62 long connectTimeMillis,
63 Uri handle,
Sailesh Nepal61203862014-07-11 14:50:13 -070064 int handlePresentation,
65 String callerDisplayName,
66 int callerDisplayNamePresentation,
Sailesh Nepal60437932014-04-05 16:44:55 -070067 GatewayInfo gatewayInfo,
Evan Charlton6eb262c2014-07-19 18:18:19 -070068 PhoneAccountHandle account,
Andrew Lee5dc30752014-06-27 17:02:19 -070069 ICallVideoProvider callVideoProvider,
Santos Cordon980acb92014-05-31 10:31:19 -070070 String parentCallId,
Tyler Gunn8d83fa92014-07-01 11:31:21 -070071 List<String> childCallIds,
Andrew Lee85f5d422014-07-11 17:22:03 -070072 StatusHints statusHints,
73 int videoState) {
Sailesh Nepal60437932014-04-05 16:44:55 -070074 mId = id;
75 mState = state;
Ihab Awadfbb092f2014-06-03 18:40:45 -070076 mDisconnectCauseCode = disconnectCauseCode;
77 mDisconnectCauseMsg = disconnectCauseMsg;
Ihab Awadc0677542014-06-10 13:29:47 -070078 mCannedSmsResponses = cannedSmsResponses;
Sailesh Nepal60437932014-04-05 16:44:55 -070079 mCapabilities = capabilities;
80 mConnectTimeMillis = connectTimeMillis;
81 mHandle = handle;
Sailesh Nepal61203862014-07-11 14:50:13 -070082 mHandlePresentation = handlePresentation;
83 mCallerDisplayName = callerDisplayName;
84 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Sailesh Nepal60437932014-04-05 16:44:55 -070085 mGatewayInfo = gatewayInfo;
Sailesh Nepal2bed9562014-07-02 21:26:12 -070086 mAccount = account;
Andrew Lee5dc30752014-06-27 17:02:19 -070087 mCallVideoProvider = callVideoProvider;
Santos Cordon980acb92014-05-31 10:31:19 -070088 mParentCallId = parentCallId;
89 mChildCallIds = childCallIds;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070090 mStatusHints = statusHints;
Andrew Lee85f5d422014-07-11 17:22:03 -070091 mVideoState = videoState;
Sailesh Nepal60437932014-04-05 16:44:55 -070092 }
93
94 /** The unique ID of the call. */
95 public String getId() {
96 return mId;
97 }
98
99 /** The current state of the call. */
100 public CallState getState() {
101 return mState;
102 }
103
104 /**
105 * Reason for disconnection, values are defined in {@link DisconnectCause}. Valid when call
Sailesh Nepalc1a48ef2014-04-08 14:32:20 -0700106 * state is {@link CallState#DISCONNECTED}.
Sailesh Nepal60437932014-04-05 16:44:55 -0700107 */
Ihab Awadfbb092f2014-06-03 18:40:45 -0700108 public int getDisconnectCauseCode() {
109 return mDisconnectCauseCode;
110 }
111
112 /**
113 * Further optional textual information about the reason for disconnection. Valid when call
114 * state is {@link CallState#DISCONNECTED}.
115 */
116 public String getDisconnectCauseMsg() {
117 return mDisconnectCauseMsg;
Sailesh Nepal60437932014-04-05 16:44:55 -0700118 }
119
Ihab Awadc0677542014-06-10 13:29:47 -0700120 /**
121 * The set of possible text message responses when this call is incoming.
122 */
123 public List<String> getCannedSmsResponses() {
124 return mCannedSmsResponses;
125 }
126
Sailesh Nepal60437932014-04-05 16:44:55 -0700127 // Bit mask of actions a call supports, values are defined in {@link CallCapabilities}.
128 public int getCapabilities() {
129 return mCapabilities;
130 }
131
132 /** The time that the call switched to the active state. */
133 public long getConnectTimeMillis() {
134 return mConnectTimeMillis;
135 }
136
137 /** The endpoint to which the call is connected. */
138 public Uri getHandle() {
139 return mHandle;
140 }
141
Sailesh Nepal61203862014-07-11 14:50:13 -0700142 /** The {@link CallPropertyPresentation} which controls how the handle is shown. */
143 public int getHandlePresentation() {
144 return mHandlePresentation;
145 }
146
147 /** The endpoint to which the call is connected. */
148 public String getCallerDisplayName() {
149 return mCallerDisplayName;
150 }
151
152 /** The {@link CallPropertyPresentation} which controls how the caller display name is shown. */
153 public int getCallerDisplayNamePresentation() {
154 return mCallerDisplayNamePresentation;
155 }
156
Sailesh Nepal60437932014-04-05 16:44:55 -0700157 /** Gateway information for the call. */
158 public GatewayInfo getGatewayInfo() {
159 return mGatewayInfo;
160 }
161
Evan Charlton6eb262c2014-07-19 18:18:19 -0700162 /** PhoneAccountHandle information for the call. */
163 public PhoneAccountHandle getAccount() {
Ihab Awad9c3f1882014-06-30 21:17:13 -0700164 return mAccount;
Nancy Chen5ffbfcc2014-06-25 14:22:55 -0700165 }
166
Sailesh Nepal60437932014-04-05 16:44:55 -0700167 /**
Andrew Lee5dc30752014-06-27 17:02:19 -0700168 * Returns an object for remotely communicating through the call video provider's binder.
169 * @return The call video provider.
170 */
171 public RemoteCallVideoProvider getCallVideoProvider() throws RemoteException {
Tyler Gunn807de8a2014-06-30 14:22:57 -0700172 if (mRemoteCallVideoProvider == null && mCallVideoProvider != null) {
Andrew Lee5dc30752014-06-27 17:02:19 -0700173 try {
174 mRemoteCallVideoProvider = new RemoteCallVideoProvider(mCallVideoProvider);
175 } catch (RemoteException ignored) {
176 // Ignore RemoteException.
177 }
178 }
179
180 return mRemoteCallVideoProvider;
181 }
182
183 /**
Santos Cordon980acb92014-05-31 10:31:19 -0700184 * The conference call to which this call is conferenced. Null if not conferenced.
185 * @hide
186 */
187 public String getParentCallId() {
188 return mParentCallId;
189 }
190
191 /**
192 * The child call-IDs if this call is a conference call. Returns an empty list if this is not
193 * a conference call or if the conference call contains no children.
194 * @hide
195 */
196 public List<String> getChildCallIds() {
197 return mChildCallIds;
198 }
199
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700200 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700201 * The status label and icon.
202 *
203 * @return Status hints.
204 */
205 public StatusHints getStatusHints() {
206 return mStatusHints;
207 }
208
Andrew Lee85f5d422014-07-11 17:22:03 -0700209 /**
210 * The video state.
211 * @return The video state of the call.
212 */
213 public int getVideoState() {
214 return mVideoState;
215 }
216
Sailesh Nepal60437932014-04-05 16:44:55 -0700217 /** Responsible for creating InCallCall objects for deserialized Parcels. */
218 public static final Parcelable.Creator<InCallCall> CREATOR =
219 new Parcelable.Creator<InCallCall> () {
220 @Override
221 public InCallCall createFromParcel(Parcel source) {
Ihab Awadc0677542014-06-10 13:29:47 -0700222 ClassLoader classLoader = InCallCall.class.getClassLoader();
Sailesh Nepal60437932014-04-05 16:44:55 -0700223 String id = source.readString();
224 CallState state = CallState.valueOf(source.readString());
Ihab Awadfbb092f2014-06-03 18:40:45 -0700225 int disconnectCauseCode = source.readInt();
226 String disconnectCauseMsg = source.readString();
Ihab Awadc0677542014-06-10 13:29:47 -0700227 List<String> cannedSmsResponses = new ArrayList<>();
228 source.readList(cannedSmsResponses, classLoader);
Sailesh Nepal60437932014-04-05 16:44:55 -0700229 int capabilities = source.readInt();
230 long connectTimeMillis = source.readLong();
Sailesh Nepal60437932014-04-05 16:44:55 -0700231 Uri handle = source.readParcelable(classLoader);
Sailesh Nepal61203862014-07-11 14:50:13 -0700232 int handlePresentation = source.readInt();
233 String callerDisplayName = source.readString();
234 int callerDisplayNamePresentation = source.readInt();
Sailesh Nepal60437932014-04-05 16:44:55 -0700235 GatewayInfo gatewayInfo = source.readParcelable(classLoader);
Evan Charlton6eb262c2014-07-19 18:18:19 -0700236 PhoneAccountHandle account = source.readParcelable(classLoader);
Andrew Lee5dc30752014-06-27 17:02:19 -0700237 ICallVideoProvider callVideoProvider =
238 ICallVideoProvider.Stub.asInterface(source.readStrongBinder());
Santos Cordon980acb92014-05-31 10:31:19 -0700239 String parentCallId = source.readString();
240 List<String> childCallIds = new ArrayList<>();
241 source.readList(childCallIds, classLoader);
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700242 StatusHints statusHints = source.readParcelable(classLoader);
Andrew Lee85f5d422014-07-11 17:22:03 -0700243 int videoState = source.readInt();
Ihab Awadc0677542014-06-10 13:29:47 -0700244 return new InCallCall(id, state, disconnectCauseCode, disconnectCauseMsg,
Sailesh Nepal61203862014-07-11 14:50:13 -0700245 cannedSmsResponses, capabilities, connectTimeMillis, handle, handlePresentation,
246 callerDisplayName, callerDisplayNamePresentation, gatewayInfo,
Andrew Lee85f5d422014-07-11 17:22:03 -0700247 account, callVideoProvider, parentCallId, childCallIds, statusHints,
248 videoState);
Sailesh Nepal60437932014-04-05 16:44:55 -0700249 }
250
251 @Override
252 public InCallCall[] newArray(int size) {
253 return new InCallCall[size];
254 }
255 };
256
257 /** {@inheritDoc} */
258 @Override
259 public int describeContents() {
260 return 0;
261 }
262
263 /** Writes InCallCall object into a Parcel. */
264 @Override
265 public void writeToParcel(Parcel destination, int flags) {
266 destination.writeString(mId);
267 destination.writeString(mState.name());
Ihab Awadfbb092f2014-06-03 18:40:45 -0700268 destination.writeInt(mDisconnectCauseCode);
269 destination.writeString(mDisconnectCauseMsg);
Ihab Awadc0677542014-06-10 13:29:47 -0700270 destination.writeList(mCannedSmsResponses);
Sailesh Nepal60437932014-04-05 16:44:55 -0700271 destination.writeInt(mCapabilities);
272 destination.writeLong(mConnectTimeMillis);
273 destination.writeParcelable(mHandle, 0);
Sailesh Nepal61203862014-07-11 14:50:13 -0700274 destination.writeInt(mHandlePresentation);
275 destination.writeString(mCallerDisplayName);
276 destination.writeInt(mCallerDisplayNamePresentation);
Sailesh Nepal60437932014-04-05 16:44:55 -0700277 destination.writeParcelable(mGatewayInfo, 0);
Ihab Awad9c3f1882014-06-30 21:17:13 -0700278 destination.writeParcelable(mAccount, 0);
Tyler Gunn807de8a2014-06-30 14:22:57 -0700279 destination.writeStrongBinder(
280 mCallVideoProvider != null ? mCallVideoProvider.asBinder() : null);
Santos Cordon980acb92014-05-31 10:31:19 -0700281 destination.writeString(mParentCallId);
282 destination.writeList(mChildCallIds);
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700283 destination.writeParcelable(mStatusHints, 0);
Andrew Lee85f5d422014-07-11 17:22:03 -0700284 destination.writeInt(mVideoState);
Sailesh Nepal60437932014-04-05 16:44:55 -0700285 }
Santos Cordonb6939982014-06-04 20:20:58 -0700286
287 @Override
288 public String toString() {
289 return String.format("[%s, parent:%s, children:%s]", mId, mParentCallId, mChildCallIds);
290 }
Sailesh Nepal60437932014-04-05 16:44:55 -0700291}