blob: e21f3de91d1d5fbc0e6da4a49b24cc387228a6fd [file] [log] [blame]
Ben Gilad0407fb22014-01-09 16:18:41 -08001/*
2 * Copyright (C) 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
Ben Gilad9f2bed32013-12-12 17:43:26 -080017package com.android.telecomm;
18
Sailesh Nepalce704b92014-03-17 18:31:43 -070019import android.net.Uri;
Sailesh Nepal84fa5f82014-04-02 11:01:11 -070020import android.os.Bundle;
Santos Cordon0b03b4b2014-01-29 18:01:59 -080021import android.telecomm.CallInfo;
Sailesh Nepal84fa5f82014-04-02 11:01:11 -070022import android.telecomm.CallServiceDescriptor;
Santos Cordon0b03b4b2014-01-29 18:01:59 -080023import android.telecomm.CallState;
Yorke Lee33501632014-03-17 19:24:12 -070024import android.telecomm.GatewayInfo;
Santos Cordon79ff2bc2014-03-27 15:31:27 -070025import android.telephony.DisconnectCause;
Sailesh Nepal6aca10a2014-03-24 16:11:02 -070026import android.telephony.PhoneNumberUtils;
Santos Cordon0b03b4b2014-01-29 18:01:59 -080027
Ben Gilad61925612014-03-11 19:06:36 -070028import com.google.android.collect.Sets;
Santos Cordon61d0f702014-02-19 02:52:23 -080029import com.google.common.base.Preconditions;
30
Sailesh Nepal91990782014-03-08 17:45:52 -080031import java.util.Locale;
Ben Gilad61925612014-03-11 19:06:36 -070032import java.util.Set;
Ben Gilad0407fb22014-01-09 16:18:41 -080033
Ben Gilad2495d572014-01-09 17:26:19 -080034/**
35 * Encapsulates all aspects of a given phone call throughout its lifecycle, starting
36 * from the time the call intent was received by Telecomm (vs. the time the call was
37 * connected etc).
38 */
Ben Gilad0407fb22014-01-09 16:18:41 -080039final class Call {
Ben Gilad0407fb22014-01-09 16:18:41 -080040 /** Additional contact information beyond handle above, optional. */
Ben Gilad0bf5b912014-01-28 17:55:57 -080041 private final ContactInfo mContactInfo;
Ben Gilad0407fb22014-01-09 16:18:41 -080042
Sailesh Nepal810735e2014-03-18 18:15:46 -070043 /** True if this is an incoming call. */
44 private final boolean mIsIncoming;
45
Ben Gilad0407fb22014-01-09 16:18:41 -080046 /**
47 * The time this call was created, typically also the time this call was added to the set
48 * of pending outgoing calls (mPendingOutgoingCalls) that's maintained by the switchboard.
49 * Beyond logging and such, may also be used for bookkeeping and specifically for marking
50 * certain call attempts as failed attempts.
51 */
Sailesh Nepal8c85dee2014-04-07 22:21:40 -070052 private final long mCreationTimeMillis = System.currentTimeMillis();
53
54 private long mConnectTimeMillis;
Ben Gilad0407fb22014-01-09 16:18:41 -080055
Santos Cordon61d0f702014-02-19 02:52:23 -080056 /** The state of the call. */
57 private CallState mState;
58
59 /** The handle with which to establish this call. */
Sailesh Nepalce704b92014-03-17 18:31:43 -070060 private Uri mHandle;
Santos Cordon61d0f702014-02-19 02:52:23 -080061
Yorke Lee33501632014-03-17 19:24:12 -070062 /** The gateway information associated with this call. This stores the original call handle
63 * that the user is attempting to connect to via the gateway, the actual handle to dial in
64 * order to connect the call via the gateway, as well as the package name of the gateway
65 * service. */
66 private final GatewayInfo mGatewayInfo;
67
Ben Gilad0407fb22014-01-09 16:18:41 -080068 /**
Ben Gilad8e55d1d2014-02-26 16:25:56 -080069 * The call service which is attempted or already connecting this call.
Santos Cordon681663d2014-01-30 04:32:15 -080070 */
Santos Cordonc195e362014-02-11 17:05:31 -080071 private CallServiceWrapper mCallService;
Santos Cordon681663d2014-01-30 04:32:15 -080072
Ben Gilad8e55d1d2014-02-26 16:25:56 -080073 /**
74 * The call-service selector for this call.
Ben Gilad8e55d1d2014-02-26 16:25:56 -080075 */
Sailesh Nepal18386a82014-03-19 10:22:40 -070076 private CallServiceSelectorWrapper mCallServiceSelector;
Ben Gilad8e55d1d2014-02-26 16:25:56 -080077
Santos Cordon0b03b4b2014-01-29 18:01:59 -080078 /**
Ben Gilad61925612014-03-11 19:06:36 -070079 * The set of call services that were attempted in the process of placing/switching this call
80 * but turned out unsuitable. Only used in the context of call switching.
81 */
82 private Set<CallServiceWrapper> mIncompatibleCallServices;
83
Sailesh Nepal6aca10a2014-03-24 16:11:02 -070084 private boolean mIsEmergencyCall;
85
Ben Gilad61925612014-03-11 19:06:36 -070086 /**
Santos Cordon79ff2bc2014-03-27 15:31:27 -070087 * Disconnect cause for the call. Only valid if the state of the call is DISCONNECTED.
88 * See {@link android.telephony.DisconnectCause}.
89 */
Sailesh Nepal8c85dee2014-04-07 22:21:40 -070090 private int mDisconnectCause = DisconnectCause.NOT_VALID;
Santos Cordon79ff2bc2014-03-27 15:31:27 -070091
92 /**
93 * Additional disconnect information provided by the call service.
94 */
95 private String mDisconnectMessage;
96
Sailesh Nepal84fa5f82014-04-02 11:01:11 -070097 /** Info used by the call services. */
Sailesh Nepal8c85dee2014-04-07 22:21:40 -070098 private Bundle mExtras = Bundle.EMPTY;
Sailesh Nepal84fa5f82014-04-02 11:01:11 -070099
100 /** The Uri to dial to perform the handoff. If this is null then handoff is not supported. */
101 private Uri mHandoffHandle;
102
103 /**
104 * References the call that is being handed off. This value is non-null for untracked calls
105 * that are being used to perform a handoff.
106 */
107 private Call mOriginalCall;
108
Santos Cordon79ff2bc2014-03-27 15:31:27 -0700109 /**
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700110 * The descriptor for the call service that this call is being switched to, null if handoff is
111 * not in progress.
112 */
113 private CallServiceDescriptor mHandoffCallServiceDescriptor;
114
115 /**
Sailesh Nepale59bb192014-04-01 18:33:59 -0700116 * Creates an empty call object.
Sailesh Nepal810735e2014-03-18 18:15:46 -0700117 *
118 * @param isIncoming True if this is an incoming call.
Santos Cordon493e8f22014-02-19 03:15:12 -0800119 */
Sailesh Nepal810735e2014-03-18 18:15:46 -0700120 Call(boolean isIncoming) {
Yorke Lee33501632014-03-17 19:24:12 -0700121 this(null, null, null, isIncoming);
Santos Cordon493e8f22014-02-19 03:15:12 -0800122 }
123
124 /**
Ben Gilad0407fb22014-01-09 16:18:41 -0800125 * Persists the specified parameters and initializes the new instance.
126 *
127 * @param handle The handle to dial.
128 * @param contactInfo Information about the entity being called.
Yorke Lee33501632014-03-17 19:24:12 -0700129 * @param gatewayInfo Gateway information to use for the call.
Sailesh Nepal810735e2014-03-18 18:15:46 -0700130 * @param isIncoming True if this is an incoming call.
Ben Gilad0407fb22014-01-09 16:18:41 -0800131 */
Yorke Lee33501632014-03-17 19:24:12 -0700132 Call(Uri handle, ContactInfo contactInfo, GatewayInfo gatewayInfo, boolean isIncoming) {
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800133 mState = CallState.NEW;
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700134 setHandle(handle);
Ben Gilad0407fb22014-01-09 16:18:41 -0800135 mContactInfo = contactInfo;
Yorke Lee33501632014-03-17 19:24:12 -0700136 mGatewayInfo = gatewayInfo;
Sailesh Nepal810735e2014-03-18 18:15:46 -0700137 mIsIncoming = isIncoming;
Ben Gilad0407fb22014-01-09 16:18:41 -0800138 }
139
Santos Cordon61d0f702014-02-19 02:52:23 -0800140 /** {@inheritDoc} */
141 @Override public String toString() {
Sailesh Nepal4538f012014-04-15 11:40:33 -0700142 String component = null;
143 if (mCallService != null && mCallService.getComponentName() != null) {
144 component = mCallService.getComponentName().flattenToShortString();
145 }
146 return String.format(Locale.US, "[%s, %s, %s]", mState, component, Log.piiHandle(mHandle));
Santos Cordon61d0f702014-02-19 02:52:23 -0800147 }
148
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800149 CallState getState() {
150 return mState;
151 }
152
153 /**
154 * Sets the call state. Although there exists the notion of appropriate state transitions
155 * (see {@link CallState}), in practice those expectations break down when cellular systems
156 * misbehave and they do this very often. The result is that we do not enforce state transitions
157 * and instead keep the code resilient to unexpected state changes.
158 */
Sailesh Nepal810735e2014-03-18 18:15:46 -0700159 void setState(CallState newState) {
Santos Cordon79ff2bc2014-03-27 15:31:27 -0700160 Preconditions.checkState(newState != CallState.DISCONNECTED ||
161 mDisconnectCause != DisconnectCause.NOT_VALID);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700162 if (mState != newState) {
163 Log.v(this, "setState %s -> %s", mState, newState);
164 mState = newState;
Sailesh Nepal810735e2014-03-18 18:15:46 -0700165 }
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800166 }
167
Sailesh Nepalce704b92014-03-17 18:31:43 -0700168 Uri getHandle() {
Ben Gilad0bf5b912014-01-28 17:55:57 -0800169 return mHandle;
170 }
171
Sailesh Nepalce704b92014-03-17 18:31:43 -0700172 void setHandle(Uri handle) {
Santos Cordon61d0f702014-02-19 02:52:23 -0800173 mHandle = handle;
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700174 mIsEmergencyCall = mHandle != null && PhoneNumberUtils.isLocalEmergencyNumber(
175 mHandle.getSchemeSpecificPart(), TelecommApp.getInstance());
176 }
177
Santos Cordon79ff2bc2014-03-27 15:31:27 -0700178 /**
179 * @param disconnectCause The reason for the disconnection, any of
180 * {@link android.telephony.DisconnectCause}.
181 * @param disconnectMessage Optional call-service-provided message about the disconnect.
182 */
183 void setDisconnectCause(int disconnectCause, String disconnectMessage) {
184 // TODO: Consider combining this method with a setDisconnected() method that is totally
185 // separate from setState.
186 mDisconnectCause = disconnectCause;
187 mDisconnectMessage = disconnectMessage;
188 }
189
190 int getDisconnectCause() {
191 return mDisconnectCause;
192 }
193
194 String getDisconnectMessage() {
195 return mDisconnectMessage;
196 }
197
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700198 boolean isEmergencyCall() {
199 return mIsEmergencyCall;
Santos Cordon61d0f702014-02-19 02:52:23 -0800200 }
201
Yorke Lee33501632014-03-17 19:24:12 -0700202 /**
203 * @return The original handle this call is associated with. In-call services should use this
204 * handle when indicating in their UI the handle that is being called.
205 */
206 public Uri getOriginalHandle() {
207 if (mGatewayInfo != null && !mGatewayInfo.isEmpty()) {
208 return mGatewayInfo.getOriginalHandle();
209 }
210 return getHandle();
211 }
212
213 GatewayInfo getGatewayInfo() {
214 return mGatewayInfo;
215 }
216
Ben Gilad0bf5b912014-01-28 17:55:57 -0800217 ContactInfo getContactInfo() {
218 return mContactInfo;
219 }
220
Sailesh Nepal810735e2014-03-18 18:15:46 -0700221 boolean isIncoming() {
222 return mIsIncoming;
223 }
224
Ben Gilad0407fb22014-01-09 16:18:41 -0800225 /**
226 * @return The "age" of this call object in milliseconds, which typically also represents the
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700227 * period since this call was added to the set pending outgoing calls, see
228 * mCreationTimeMillis.
Ben Gilad0407fb22014-01-09 16:18:41 -0800229 */
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700230 long getAgeMillis() {
231 return System.currentTimeMillis() - mCreationTimeMillis;
Ben Gilad0407fb22014-01-09 16:18:41 -0800232 }
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800233
Yorke Leef98fb572014-03-05 10:56:55 -0800234 /**
235 * @return The time when this call object was created and added to the set of pending outgoing
236 * calls.
237 */
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700238 long getCreationTimeMillis() {
239 return mCreationTimeMillis;
240 }
241
242 long getConnectTimeMillis() {
243 return mConnectTimeMillis;
244 }
245
246 void setConnectTimeMillis(long connectTimeMillis) {
247 mConnectTimeMillis = connectTimeMillis;
Yorke Leef98fb572014-03-05 10:56:55 -0800248 }
249
Santos Cordonc195e362014-02-11 17:05:31 -0800250 CallServiceWrapper getCallService() {
Santos Cordon681663d2014-01-30 04:32:15 -0800251 return mCallService;
252 }
253
Santos Cordonc195e362014-02-11 17:05:31 -0800254 void setCallService(CallServiceWrapper callService) {
Sailesh Nepal0e5410a2014-04-04 01:20:58 -0700255 setCallService(callService, null);
256 }
257
258 /**
259 * Changes the call service this call is associated with. If callToReplace is non-null then this
260 * call takes its place within the call service.
261 */
262 void setCallService(CallServiceWrapper callService, Call callToReplace) {
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800263 Preconditions.checkNotNull(callService);
264
Yorke Leeadee12d2014-03-13 12:08:30 -0700265 clearCallService();
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800266
267 callService.incrementAssociatedCallCount();
Santos Cordon681663d2014-01-30 04:32:15 -0800268 mCallService = callService;
Sailesh Nepal0e5410a2014-04-04 01:20:58 -0700269 if (callToReplace == null) {
270 mCallService.addCall(this);
271 } else {
272 mCallService.replaceCall(this, callToReplace);
273 }
Santos Cordon681663d2014-01-30 04:32:15 -0800274 }
275
276 /**
277 * Clears the associated call service.
278 */
279 void clearCallService() {
Yorke Leeadee12d2014-03-13 12:08:30 -0700280 if (mCallService != null) {
Santos Cordonc499c1c2014-04-14 17:13:14 -0700281 CallServiceWrapper callServiceTemp = mCallService;
Yorke Leeadee12d2014-03-13 12:08:30 -0700282 mCallService = null;
Santos Cordonc499c1c2014-04-14 17:13:14 -0700283 callServiceTemp.removeCall(this);
284
285 // Decrementing the count can cause the service to unbind, which itself can trigger the
286 // service-death code. Since the service death code tries to clean up any associated
287 // calls, we need to make sure to remove that information (e.g., removeCall()) before
288 // we decrement. Technically, invoking removeCall() prior to decrementing is all that is
289 // necessary, but cleaning up mCallService prior to triggering an unbind is good to do.
290 // If you change this, make sure to update {@link clearCallServiceSelector} as well.
291 decrementAssociatedCallCount(callServiceTemp);
Yorke Leeadee12d2014-03-13 12:08:30 -0700292 }
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800293 }
294
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700295 CallServiceSelectorWrapper getCallServiceSelector() {
296 return mCallServiceSelector;
297 }
298
Sailesh Nepal18386a82014-03-19 10:22:40 -0700299 void setCallServiceSelector(CallServiceSelectorWrapper selector) {
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800300 Preconditions.checkNotNull(selector);
Sailesh Nepale59bb192014-04-01 18:33:59 -0700301
302 clearCallServiceSelector();
303
Santos Cordonc499c1c2014-04-14 17:13:14 -0700304 selector.incrementAssociatedCallCount();
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800305 mCallServiceSelector = selector;
Sailesh Nepale59bb192014-04-01 18:33:59 -0700306 mCallServiceSelector.addCall(this);
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800307 }
308
309 void clearCallServiceSelector() {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700310 if (mCallServiceSelector != null) {
Santos Cordonc499c1c2014-04-14 17:13:14 -0700311 CallServiceSelectorWrapper selectorTemp = mCallServiceSelector;
Sailesh Nepale59bb192014-04-01 18:33:59 -0700312 mCallServiceSelector = null;
Santos Cordonc499c1c2014-04-14 17:13:14 -0700313 selectorTemp.removeCall(this);
314
315 // See comment on {@link #clearCallService}.
316 decrementAssociatedCallCount(selectorTemp);
Sailesh Nepale59bb192014-04-01 18:33:59 -0700317 }
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800318 }
319
320 /**
Ben Gilad61925612014-03-11 19:06:36 -0700321 * Adds the specified call service to the list of incompatible services. The set is used when
322 * attempting to switch a phone call between call services such that incompatible services can
323 * be avoided.
324 *
325 * @param callService The incompatible call service.
326 */
327 void addIncompatibleCallService(CallServiceWrapper callService) {
328 if (mIncompatibleCallServices == null) {
329 mIncompatibleCallServices = Sets.newHashSet();
330 }
331 mIncompatibleCallServices.add(callService);
332 }
333
334 /**
335 * Checks whether or not the specified callService was identified as incompatible in the
336 * context of this call.
337 *
338 * @param callService The call service to evaluate.
339 * @return True upon incompatible call services and false otherwise.
340 */
341 boolean isIncompatibleCallService(CallServiceWrapper callService) {
342 return mIncompatibleCallServices != null &&
343 mIncompatibleCallServices.contains(callService);
344 }
345
346 /**
Ben Gilad28e8ad62014-03-06 17:01:54 -0800347 * Aborts ongoing attempts to connect this call. Only applicable to {@link CallState#NEW}
348 * outgoing calls. See {@link #disconnect} for already-connected calls.
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800349 */
350 void abort() {
Ben Gilad28e8ad62014-03-06 17:01:54 -0800351 if (mState == CallState.NEW) {
352 if (mCallService != null) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700353 mCallService.abort(this);
Ben Gilad28e8ad62014-03-06 17:01:54 -0800354 }
Ben Gilad9c234112014-03-04 16:07:33 -0800355 clearCallService();
356 clearCallServiceSelector();
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800357 }
Santos Cordon681663d2014-01-30 04:32:15 -0800358 }
359
Santos Cordonc195e362014-02-11 17:05:31 -0800360 /**
Ihab Awad74549ec2014-03-10 15:33:25 -0700361 * Plays the specified DTMF tone.
362 */
363 void playDtmfTone(char digit) {
364 if (mCallService == null) {
365 Log.w(this, "playDtmfTone() request on a call without a call service.");
366 } else {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700367 Log.i(this, "Send playDtmfTone to call service for call %s", this);
368 mCallService.playDtmfTone(this, digit);
Ihab Awad74549ec2014-03-10 15:33:25 -0700369 }
370 }
371
372 /**
373 * Stops playing any currently playing DTMF tone.
374 */
375 void stopDtmfTone() {
376 if (mCallService == null) {
377 Log.w(this, "stopDtmfTone() request on a call without a call service.");
378 } else {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700379 Log.i(this, "Send stopDtmfTone to call service for call %s", this);
380 mCallService.stopDtmfTone(this);
Ihab Awad74549ec2014-03-10 15:33:25 -0700381 }
382 }
383
384 /**
Santos Cordon049b7b62014-01-30 05:34:26 -0800385 * Attempts to disconnect the call through the call service.
386 */
387 void disconnect() {
388 if (mCallService == null) {
Ihab Awad4e0f1922014-04-14 17:35:38 -0700389 Log.d(this, "disconnect() request on a call without a call service.");
390 // In case this call is ringing, ensure we abort and clean up right away.
391 CallsManager.getInstance().abortCall(this);
Santos Cordon049b7b62014-01-30 05:34:26 -0800392 } else {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700393 Log.i(this, "Send disconnect to call service for call: %s", this);
Santos Cordonc195e362014-02-11 17:05:31 -0800394 // The call isn't officially disconnected until the call service confirms that the call
395 // was actually disconnected. Only then is the association between call and call service
396 // severed, see {@link CallsManager#markCallAsDisconnected}.
Sailesh Nepale59bb192014-04-01 18:33:59 -0700397 mCallService.disconnect(this);
Santos Cordon049b7b62014-01-30 05:34:26 -0800398 }
399 }
400
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800401 /**
Santos Cordon61d0f702014-02-19 02:52:23 -0800402 * Answers the call if it is ringing.
403 */
404 void answer() {
405 Preconditions.checkNotNull(mCallService);
406
407 // Check to verify that the call is still in the ringing state. A call can change states
408 // between the time the user hits 'answer' and Telecomm receives the command.
409 if (isRinging("answer")) {
410 // At this point, we are asking the call service to answer but we don't assume that
411 // it will work. Instead, we wait until confirmation from the call service that the
412 // call is in a non-RINGING state before changing the UI. See
413 // {@link CallServiceAdapter#setActive} and other set* methods.
Sailesh Nepale59bb192014-04-01 18:33:59 -0700414 mCallService.answer(this);
Santos Cordon61d0f702014-02-19 02:52:23 -0800415 }
416 }
417
418 /**
419 * Rejects the call if it is ringing.
420 */
421 void reject() {
422 Preconditions.checkNotNull(mCallService);
423
424 // Check to verify that the call is still in the ringing state. A call can change states
425 // between the time the user hits 'reject' and Telecomm receives the command.
426 if (isRinging("reject")) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700427 mCallService.reject(this);
Santos Cordon61d0f702014-02-19 02:52:23 -0800428 }
429 }
430
431 /**
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700432 * Puts the call on hold if it is currently active.
433 */
434 void hold() {
435 Preconditions.checkNotNull(mCallService);
436
437 if (mState == CallState.ACTIVE) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700438 mCallService.hold(this);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700439 }
440 }
441
442 /**
443 * Releases the call from hold if it is currently active.
444 */
445 void unhold() {
446 Preconditions.checkNotNull(mCallService);
447
448 if (mState == CallState.ON_HOLD) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700449 mCallService.unhold(this);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700450 }
451 }
452
453 /**
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800454 * @return An object containing read-only information about this call.
455 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700456 CallInfo toCallInfo(String callId) {
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700457 CallServiceDescriptor descriptor = null;
458 if (mCallService != null) {
459 descriptor = mCallService.getDescriptor();
460 } else if (mOriginalCall != null && mOriginalCall.mCallService != null) {
461 descriptor = mOriginalCall.mCallService.getDescriptor();
462 }
463 return new CallInfo(callId, mState, mHandle, mGatewayInfo, mExtras, descriptor);
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800464 }
465
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700466 /** Checks if this is a live call or not. */
467 boolean isAlive() {
468 switch (mState) {
469 case NEW:
470 case RINGING:
471 case DISCONNECTED:
472 case ABORTED:
473 return false;
474 default:
475 return true;
476 }
477 }
478
Santos Cordon40f78c22014-04-07 02:11:42 -0700479 boolean isActive() {
480 switch (mState) {
481 case ACTIVE:
482 case POST_DIAL:
483 case POST_DIAL_WAIT:
484 return true;
485 default:
486 return false;
487 }
488 }
489
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700490 Bundle getExtras() {
491 return mExtras;
492 }
493
494 void setExtras(Bundle extras) {
495 mExtras = extras;
496 }
497
498 Uri getHandoffHandle() {
499 return mHandoffHandle;
500 }
501
502 void setHandoffHandle(Uri handoffHandle) {
503 mHandoffHandle = handoffHandle;
504 }
505
506 Call getOriginalCall() {
507 return mOriginalCall;
508 }
509
510 void setOriginalCall(Call originalCall) {
511 mOriginalCall = originalCall;
512 }
513
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700514 CallServiceDescriptor getHandoffCallServiceDescriptor() {
515 return mHandoffCallServiceDescriptor;
516 }
517
518 void setHandoffCallServiceDescriptor(CallServiceDescriptor descriptor) {
519 mHandoffCallServiceDescriptor = descriptor;
520 }
521
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800522 /**
Santos Cordon61d0f702014-02-19 02:52:23 -0800523 * @return True if the call is ringing, else logs the action name.
524 */
525 private boolean isRinging(String actionName) {
526 if (mState == CallState.RINGING) {
527 return true;
528 }
529
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800530 Log.i(this, "Request to %s a non-ringing call %s", actionName, this);
Santos Cordon61d0f702014-02-19 02:52:23 -0800531 return false;
532 }
533
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800534 @SuppressWarnings("rawtypes")
535 private void decrementAssociatedCallCount(ServiceBinder binder) {
536 if (binder != null) {
537 binder.decrementAssociatedCallCount();
538 }
539 }
Ben Gilad9f2bed32013-12-12 17:43:26 -0800540}