blob: bf0f349b983084ef1aa00cab53dd432274e57944 [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
Santos Cordon99c8a6f2014-05-28 18:28:47 -070019import android.content.ContentUris;
20import android.graphics.Bitmap;
21import android.graphics.drawable.Drawable;
Sailesh Nepalce704b92014-03-17 18:31:43 -070022import android.net.Uri;
Sailesh Nepal84fa5f82014-04-02 11:01:11 -070023import android.os.Bundle;
Santos Cordonfd71f4a2014-05-28 13:59:49 -070024import android.os.Handler;
Santos Cordon99c8a6f2014-05-28 18:28:47 -070025import android.provider.ContactsContract.Contacts;
Santos Cordon0b03b4b2014-01-29 18:01:59 -080026import android.telecomm.CallInfo;
Sailesh Nepal84fa5f82014-04-02 11:01:11 -070027import android.telecomm.CallServiceDescriptor;
Santos Cordon0b03b4b2014-01-29 18:01:59 -080028import android.telecomm.CallState;
Yorke Lee33501632014-03-17 19:24:12 -070029import android.telecomm.GatewayInfo;
Ihab Awadff7493a2014-06-10 13:47:44 -070030import android.telecomm.Response;
Santos Cordon766d04f2014-05-06 10:28:25 -070031import android.telecomm.TelecommConstants;
Santos Cordon79ff2bc2014-03-27 15:31:27 -070032import android.telephony.DisconnectCause;
Sailesh Nepal6aca10a2014-03-24 16:11:02 -070033import android.telephony.PhoneNumberUtils;
Santos Cordonfd71f4a2014-05-28 13:59:49 -070034import android.text.TextUtils;
Santos Cordon0b03b4b2014-01-29 18:01:59 -080035
Santos Cordonfd71f4a2014-05-28 13:59:49 -070036import com.android.internal.telephony.CallerInfo;
37import com.android.internal.telephony.CallerInfoAsyncQuery;
38import com.android.internal.telephony.CallerInfoAsyncQuery.OnQueryCompleteListener;
Santos Cordon99c8a6f2014-05-28 18:28:47 -070039
Ihab Awadff7493a2014-06-10 13:47:44 -070040import com.android.internal.telephony.SmsApplication;
Santos Cordon99c8a6f2014-05-28 18:28:47 -070041import com.android.telecomm.ContactsAsyncHelper.OnImageLoadCompleteListener;
Santos Cordon61d0f702014-02-19 02:52:23 -080042import com.google.common.base.Preconditions;
Ihab Awadff7493a2014-06-10 13:47:44 -070043import com.google.common.collect.Sets;
Santos Cordon61d0f702014-02-19 02:52:23 -080044
Ihab Awadff7493a2014-06-10 13:47:44 -070045import java.util.Collections;
Santos Cordona1610702014-06-04 20:22:56 -070046import java.util.LinkedList;
47import java.util.List;
Sailesh Nepal91990782014-03-08 17:45:52 -080048import java.util.Locale;
Ben Gilad61925612014-03-11 19:06:36 -070049import java.util.Set;
Ben Gilad0407fb22014-01-09 16:18:41 -080050
Ben Gilad2495d572014-01-09 17:26:19 -080051/**
52 * Encapsulates all aspects of a given phone call throughout its lifecycle, starting
53 * from the time the call intent was received by Telecomm (vs. the time the call was
54 * connected etc).
55 */
Ben Gilad0407fb22014-01-09 16:18:41 -080056final class Call {
Santos Cordon766d04f2014-05-06 10:28:25 -070057
58 /**
59 * Listener for events on the call.
60 */
61 interface Listener {
62 void onSuccessfulOutgoingCall(Call call);
Ihab Awad0fea3f22014-06-03 18:45:05 -070063 void onFailedOutgoingCall(Call call, boolean isAborted, int errorCode, String errorMsg);
Santos Cordon766d04f2014-05-06 10:28:25 -070064 void onSuccessfulIncomingCall(Call call, CallInfo callInfo);
65 void onFailedIncomingCall(Call call);
Ihab Awadcb387ac2014-05-28 16:49:38 -070066 void onRequestingRingback(Call call, boolean requestingRingback);
Evan Charlton352105c2014-06-03 14:10:54 -070067 void onPostDialWait(Call call, String remaining);
Santos Cordona1610702014-06-04 20:22:56 -070068 void onIsConferenceCapableChanged(Call call, boolean isConferenceCapable);
69 void onExpiredConferenceCall(Call call);
70 void onConfirmedConferenceCall(Call call);
71 void onParentChanged(Call call);
72 void onChildrenChanged(Call call);
Ihab Awadff7493a2014-06-10 13:47:44 -070073 void onCannedSmsResponsesLoaded(Call call);
Santos Cordon766d04f2014-05-06 10:28:25 -070074 }
75
Santos Cordonfd71f4a2014-05-28 13:59:49 -070076 private static final OnQueryCompleteListener sCallerInfoQueryListener =
Santos Cordon99c8a6f2014-05-28 18:28:47 -070077 new OnQueryCompleteListener() {
78 /** ${inheritDoc} */
79 @Override
80 public void onQueryComplete(int token, Object cookie, CallerInfo callerInfo) {
81 if (cookie != null) {
82 ((Call) cookie).setCallerInfo(callerInfo, token);
83 }
Santos Cordonfd71f4a2014-05-28 13:59:49 -070084 }
Santos Cordon99c8a6f2014-05-28 18:28:47 -070085 };
86
87 private static final OnImageLoadCompleteListener sPhotoLoadListener =
88 new OnImageLoadCompleteListener() {
89 /** ${inheritDoc} */
90 @Override
91 public void onImageLoadComplete(
92 int token, Drawable photo, Bitmap photoIcon, Object cookie) {
93 if (cookie != null) {
94 ((Call) cookie).setPhoto(photo, photoIcon, token);
95 }
96 }
97 };
Ben Gilad0407fb22014-01-09 16:18:41 -080098
Sailesh Nepal810735e2014-03-18 18:15:46 -070099 /** True if this is an incoming call. */
100 private final boolean mIsIncoming;
101
Ben Gilad0407fb22014-01-09 16:18:41 -0800102 /**
103 * The time this call was created, typically also the time this call was added to the set
104 * of pending outgoing calls (mPendingOutgoingCalls) that's maintained by the switchboard.
105 * Beyond logging and such, may also be used for bookkeeping and specifically for marking
106 * certain call attempts as failed attempts.
107 */
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700108 private final long mCreationTimeMillis = System.currentTimeMillis();
109
Santos Cordonfd71f4a2014-05-28 13:59:49 -0700110 /** The gateway information associated with this call. This stores the original call handle
111 * that the user is attempting to connect to via the gateway, the actual handle to dial in
112 * order to connect the call via the gateway, as well as the package name of the gateway
113 * service. */
114 private final GatewayInfo mGatewayInfo;
115
Santos Cordon2174fb52014-05-29 08:22:56 -0700116 private final Handler mHandler = new Handler();
117
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700118 private long mConnectTimeMillis;
Ben Gilad0407fb22014-01-09 16:18:41 -0800119
Santos Cordon61d0f702014-02-19 02:52:23 -0800120 /** The state of the call. */
121 private CallState mState;
122
123 /** The handle with which to establish this call. */
Sailesh Nepalce704b92014-03-17 18:31:43 -0700124 private Uri mHandle;
Santos Cordon61d0f702014-02-19 02:52:23 -0800125
Ben Gilad0407fb22014-01-09 16:18:41 -0800126 /**
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800127 * The call service which is attempted or already connecting this call.
Santos Cordon681663d2014-01-30 04:32:15 -0800128 */
Santos Cordonc195e362014-02-11 17:05:31 -0800129 private CallServiceWrapper mCallService;
Santos Cordon681663d2014-01-30 04:32:15 -0800130
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800131 /**
132 * The call-service selector for this call.
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800133 */
Sailesh Nepal18386a82014-03-19 10:22:40 -0700134 private CallServiceSelectorWrapper mCallServiceSelector;
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800135
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800136 /**
Ben Gilad61925612014-03-11 19:06:36 -0700137 * The set of call services that were attempted in the process of placing/switching this call
138 * but turned out unsuitable. Only used in the context of call switching.
139 */
140 private Set<CallServiceWrapper> mIncompatibleCallServices;
141
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700142 private boolean mIsEmergencyCall;
143
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700144 private boolean mSpeakerphoneOn;
145
Ben Gilad61925612014-03-11 19:06:36 -0700146 /**
Santos Cordon79ff2bc2014-03-27 15:31:27 -0700147 * Disconnect cause for the call. Only valid if the state of the call is DISCONNECTED.
148 * See {@link android.telephony.DisconnectCause}.
149 */
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700150 private int mDisconnectCause = DisconnectCause.NOT_VALID;
Santos Cordon79ff2bc2014-03-27 15:31:27 -0700151
152 /**
153 * Additional disconnect information provided by the call service.
154 */
155 private String mDisconnectMessage;
156
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700157 /** Info used by the call services. */
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700158 private Bundle mExtras = Bundle.EMPTY;
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700159
160 /** The Uri to dial to perform the handoff. If this is null then handoff is not supported. */
161 private Uri mHandoffHandle;
162
163 /**
164 * References the call that is being handed off. This value is non-null for untracked calls
165 * that are being used to perform a handoff.
166 */
167 private Call mOriginalCall;
168
Santos Cordon79ff2bc2014-03-27 15:31:27 -0700169 /**
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700170 * The descriptor for the call service that this call is being switched to, null if handoff is
171 * not in progress.
172 */
173 private CallServiceDescriptor mHandoffCallServiceDescriptor;
174
Santos Cordon766d04f2014-05-06 10:28:25 -0700175 /** Set of listeners on this call. */
176 private Set<Listener> mListeners = Sets.newHashSet();
177
Santos Cordon682fe6b2014-05-20 08:56:39 -0700178 private OutgoingCallProcessor mOutgoingCallProcessor;
179
180 // TODO(santoscordon): The repositories should be changed into singleton types.
181 private CallServiceRepository mCallServiceRepository;
182 private CallServiceSelectorRepository mSelectorRepository;
183
Santos Cordonfd71f4a2014-05-28 13:59:49 -0700184 /** Caller information retrieved from the latest contact query. */
185 private CallerInfo mCallerInfo;
186
187 /** The latest token used with a contact info query. */
188 private int mQueryToken = 0;
189
Ihab Awadcb387ac2014-05-28 16:49:38 -0700190 /** Whether this call is requesting that Telecomm play the ringback tone on its behalf. */
191 private boolean mRequestingRingback = false;
192
Santos Cordon2174fb52014-05-29 08:22:56 -0700193 /** Incoming call-info to use when direct-to-voicemail query finishes. */
194 private CallInfo mPendingDirectToVoicemailCallInfo;
195
Santos Cordona1610702014-06-04 20:22:56 -0700196 private boolean mIsConferenceCapable = false;
197
198 private boolean mIsConference = false;
199
200 private Call mParentCall = null;
201
202 private List<Call> mChildCalls = new LinkedList<>();
203
Ihab Awadff7493a2014-06-10 13:47:44 -0700204 /** Set of text message responses allowed for this call, if applicable. */
205 private List<String> mCannedSmsResponses = Collections.EMPTY_LIST;
206
207 /** Whether an attempt has been made to load the text message responses. */
208 private boolean mCannedSmsResponsesLoadingStarted = false;
209
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700210 /**
Sailesh Nepale59bb192014-04-01 18:33:59 -0700211 * Creates an empty call object.
Sailesh Nepal810735e2014-03-18 18:15:46 -0700212 *
213 * @param isIncoming True if this is an incoming call.
Santos Cordon493e8f22014-02-19 03:15:12 -0800214 */
Santos Cordona1610702014-06-04 20:22:56 -0700215 Call(boolean isIncoming, boolean isConference) {
216 this(null, null, isIncoming, isConference);
Santos Cordon493e8f22014-02-19 03:15:12 -0800217 }
218
219 /**
Ben Gilad0407fb22014-01-09 16:18:41 -0800220 * Persists the specified parameters and initializes the new instance.
221 *
222 * @param handle The handle to dial.
Yorke Lee33501632014-03-17 19:24:12 -0700223 * @param gatewayInfo Gateway information to use for the call.
Sailesh Nepal810735e2014-03-18 18:15:46 -0700224 * @param isIncoming True if this is an incoming call.
Ben Gilad0407fb22014-01-09 16:18:41 -0800225 */
Santos Cordona1610702014-06-04 20:22:56 -0700226 Call(Uri handle, GatewayInfo gatewayInfo, boolean isIncoming, boolean isConference) {
227 mState = isConference ? CallState.ACTIVE : CallState.NEW;
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700228 setHandle(handle);
Yorke Lee33501632014-03-17 19:24:12 -0700229 mGatewayInfo = gatewayInfo;
Sailesh Nepal810735e2014-03-18 18:15:46 -0700230 mIsIncoming = isIncoming;
Santos Cordona1610702014-06-04 20:22:56 -0700231 mIsConference = isConference;
Ihab Awadff7493a2014-06-10 13:47:44 -0700232 maybeLoadCannedSmsResponses();
Ben Gilad0407fb22014-01-09 16:18:41 -0800233 }
234
Santos Cordon766d04f2014-05-06 10:28:25 -0700235 void addListener(Listener listener) {
236 mListeners.add(listener);
237 }
238
239 void removeListener(Listener listener) {
240 mListeners.remove(listener);
241 }
242
Santos Cordon61d0f702014-02-19 02:52:23 -0800243 /** {@inheritDoc} */
244 @Override public String toString() {
Sailesh Nepal4538f012014-04-15 11:40:33 -0700245 String component = null;
246 if (mCallService != null && mCallService.getComponentName() != null) {
247 component = mCallService.getComponentName().flattenToShortString();
248 }
249 return String.format(Locale.US, "[%s, %s, %s]", mState, component, Log.piiHandle(mHandle));
Santos Cordon61d0f702014-02-19 02:52:23 -0800250 }
251
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800252 CallState getState() {
Santos Cordona1610702014-06-04 20:22:56 -0700253 if (mIsConference) {
254 if (!mChildCalls.isEmpty()) {
255 // If we have child calls, just return the child call.
256 return mChildCalls.get(0).getState();
257 }
258 return CallState.ACTIVE;
259 } else {
260 return mState;
261 }
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800262 }
263
264 /**
265 * Sets the call state. Although there exists the notion of appropriate state transitions
266 * (see {@link CallState}), in practice those expectations break down when cellular systems
267 * misbehave and they do this very often. The result is that we do not enforce state transitions
268 * and instead keep the code resilient to unexpected state changes.
269 */
Sailesh Nepal810735e2014-03-18 18:15:46 -0700270 void setState(CallState newState) {
Santos Cordon79ff2bc2014-03-27 15:31:27 -0700271 Preconditions.checkState(newState != CallState.DISCONNECTED ||
272 mDisconnectCause != DisconnectCause.NOT_VALID);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700273 if (mState != newState) {
274 Log.v(this, "setState %s -> %s", mState, newState);
275 mState = newState;
Ihab Awadff7493a2014-06-10 13:47:44 -0700276 maybeLoadCannedSmsResponses();
Sailesh Nepal810735e2014-03-18 18:15:46 -0700277 }
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800278 }
279
Ihab Awadcb387ac2014-05-28 16:49:38 -0700280 void setRequestingRingback(boolean requestingRingback) {
281 mRequestingRingback = requestingRingback;
282 for (Listener l : mListeners) {
283 l.onRequestingRingback(this, mRequestingRingback);
284 }
285 }
286
287 boolean isRequestingRingback() {
288 return mRequestingRingback;
289 }
290
Sailesh Nepalce704b92014-03-17 18:31:43 -0700291 Uri getHandle() {
Ben Gilad0bf5b912014-01-28 17:55:57 -0800292 return mHandle;
293 }
294
Sailesh Nepalce704b92014-03-17 18:31:43 -0700295 void setHandle(Uri handle) {
Santos Cordonfd71f4a2014-05-28 13:59:49 -0700296 if ((mHandle == null && handle != null) || (mHandle != null && !mHandle.equals(handle))) {
297 mHandle = handle;
298 mIsEmergencyCall = mHandle != null && PhoneNumberUtils.isLocalEmergencyNumber(
Yorke Lee66255452014-06-05 08:09:24 -0700299 TelecommApp.getInstance(), mHandle.getSchemeSpecificPart());
Santos Cordonfd71f4a2014-05-28 13:59:49 -0700300 startCallerInfoLookup();
301 }
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700302 }
303
Santos Cordon99c8a6f2014-05-28 18:28:47 -0700304 String getName() {
305 return mCallerInfo == null ? null : mCallerInfo.name;
306 }
307
308 Bitmap getPhotoIcon() {
309 return mCallerInfo == null ? null : mCallerInfo.cachedPhotoIcon;
310 }
311
312 Drawable getPhoto() {
313 return mCallerInfo == null ? null : mCallerInfo.cachedPhoto;
314 }
315
Santos Cordon79ff2bc2014-03-27 15:31:27 -0700316 /**
317 * @param disconnectCause The reason for the disconnection, any of
318 * {@link android.telephony.DisconnectCause}.
319 * @param disconnectMessage Optional call-service-provided message about the disconnect.
320 */
321 void setDisconnectCause(int disconnectCause, String disconnectMessage) {
322 // TODO: Consider combining this method with a setDisconnected() method that is totally
323 // separate from setState.
324 mDisconnectCause = disconnectCause;
325 mDisconnectMessage = disconnectMessage;
326 }
327
328 int getDisconnectCause() {
329 return mDisconnectCause;
330 }
331
332 String getDisconnectMessage() {
333 return mDisconnectMessage;
334 }
335
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700336 boolean isEmergencyCall() {
337 return mIsEmergencyCall;
Santos Cordon61d0f702014-02-19 02:52:23 -0800338 }
339
Yorke Lee33501632014-03-17 19:24:12 -0700340 /**
341 * @return The original handle this call is associated with. In-call services should use this
342 * handle when indicating in their UI the handle that is being called.
343 */
344 public Uri getOriginalHandle() {
345 if (mGatewayInfo != null && !mGatewayInfo.isEmpty()) {
346 return mGatewayInfo.getOriginalHandle();
347 }
348 return getHandle();
349 }
350
351 GatewayInfo getGatewayInfo() {
352 return mGatewayInfo;
353 }
354
Sailesh Nepal810735e2014-03-18 18:15:46 -0700355 boolean isIncoming() {
356 return mIsIncoming;
357 }
358
Ben Gilad0407fb22014-01-09 16:18:41 -0800359 /**
360 * @return The "age" of this call object in milliseconds, which typically also represents the
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700361 * period since this call was added to the set pending outgoing calls, see
362 * mCreationTimeMillis.
Ben Gilad0407fb22014-01-09 16:18:41 -0800363 */
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700364 long getAgeMillis() {
365 return System.currentTimeMillis() - mCreationTimeMillis;
Ben Gilad0407fb22014-01-09 16:18:41 -0800366 }
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800367
Yorke Leef98fb572014-03-05 10:56:55 -0800368 /**
369 * @return The time when this call object was created and added to the set of pending outgoing
370 * calls.
371 */
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700372 long getCreationTimeMillis() {
373 return mCreationTimeMillis;
374 }
375
376 long getConnectTimeMillis() {
377 return mConnectTimeMillis;
378 }
379
380 void setConnectTimeMillis(long connectTimeMillis) {
381 mConnectTimeMillis = connectTimeMillis;
Yorke Leef98fb572014-03-05 10:56:55 -0800382 }
383
Santos Cordona1610702014-06-04 20:22:56 -0700384 boolean isConferenceCapable() {
385 return mIsConferenceCapable;
386 }
387
388 void setIsConferenceCapable(boolean isConferenceCapable) {
389 if (mIsConferenceCapable != isConferenceCapable) {
390 mIsConferenceCapable = isConferenceCapable;
391 for (Listener l : mListeners) {
392 l.onIsConferenceCapableChanged(this, mIsConferenceCapable);
393 }
394 }
395 }
396
397 Call getParentCall() {
398 return mParentCall;
399 }
400
401 List<Call> getChildCalls() {
402 return mChildCalls;
403 }
404
Santos Cordonc195e362014-02-11 17:05:31 -0800405 CallServiceWrapper getCallService() {
Santos Cordon681663d2014-01-30 04:32:15 -0800406 return mCallService;
407 }
408
Santos Cordonc195e362014-02-11 17:05:31 -0800409 void setCallService(CallServiceWrapper callService) {
Sailesh Nepal0e5410a2014-04-04 01:20:58 -0700410 setCallService(callService, null);
411 }
412
413 /**
414 * Changes the call service this call is associated with. If callToReplace is non-null then this
415 * call takes its place within the call service.
416 */
417 void setCallService(CallServiceWrapper callService, Call callToReplace) {
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800418 Preconditions.checkNotNull(callService);
419
Yorke Leeadee12d2014-03-13 12:08:30 -0700420 clearCallService();
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800421
422 callService.incrementAssociatedCallCount();
Santos Cordon681663d2014-01-30 04:32:15 -0800423 mCallService = callService;
Sailesh Nepal0e5410a2014-04-04 01:20:58 -0700424 if (callToReplace == null) {
425 mCallService.addCall(this);
426 } else {
427 mCallService.replaceCall(this, callToReplace);
428 }
Santos Cordon681663d2014-01-30 04:32:15 -0800429 }
430
431 /**
432 * Clears the associated call service.
433 */
434 void clearCallService() {
Yorke Leeadee12d2014-03-13 12:08:30 -0700435 if (mCallService != null) {
Santos Cordonc499c1c2014-04-14 17:13:14 -0700436 CallServiceWrapper callServiceTemp = mCallService;
Yorke Leeadee12d2014-03-13 12:08:30 -0700437 mCallService = null;
Santos Cordonc499c1c2014-04-14 17:13:14 -0700438 callServiceTemp.removeCall(this);
439
440 // Decrementing the count can cause the service to unbind, which itself can trigger the
441 // service-death code. Since the service death code tries to clean up any associated
442 // calls, we need to make sure to remove that information (e.g., removeCall()) before
443 // we decrement. Technically, invoking removeCall() prior to decrementing is all that is
444 // necessary, but cleaning up mCallService prior to triggering an unbind is good to do.
445 // If you change this, make sure to update {@link clearCallServiceSelector} as well.
446 decrementAssociatedCallCount(callServiceTemp);
Yorke Leeadee12d2014-03-13 12:08:30 -0700447 }
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800448 }
449
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700450 CallServiceSelectorWrapper getCallServiceSelector() {
451 return mCallServiceSelector;
452 }
453
Sailesh Nepal18386a82014-03-19 10:22:40 -0700454 void setCallServiceSelector(CallServiceSelectorWrapper selector) {
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800455 Preconditions.checkNotNull(selector);
Sailesh Nepale59bb192014-04-01 18:33:59 -0700456
457 clearCallServiceSelector();
458
Santos Cordonc499c1c2014-04-14 17:13:14 -0700459 selector.incrementAssociatedCallCount();
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800460 mCallServiceSelector = selector;
Sailesh Nepale59bb192014-04-01 18:33:59 -0700461 mCallServiceSelector.addCall(this);
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800462 }
463
464 void clearCallServiceSelector() {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700465 if (mCallServiceSelector != null) {
Santos Cordonc499c1c2014-04-14 17:13:14 -0700466 CallServiceSelectorWrapper selectorTemp = mCallServiceSelector;
Sailesh Nepale59bb192014-04-01 18:33:59 -0700467 mCallServiceSelector = null;
Santos Cordonc499c1c2014-04-14 17:13:14 -0700468 selectorTemp.removeCall(this);
469
470 // See comment on {@link #clearCallService}.
471 decrementAssociatedCallCount(selectorTemp);
Sailesh Nepale59bb192014-04-01 18:33:59 -0700472 }
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800473 }
474
475 /**
Santos Cordon766d04f2014-05-06 10:28:25 -0700476 * Starts the incoming call flow through the switchboard. When switchboard completes, it will
477 * invoke handle[Un]SuccessfulIncomingCall.
478 *
479 * @param descriptor The relevant call-service descriptor.
480 * @param extras The optional extras passed via
481 * {@link TelecommConstants#EXTRA_INCOMING_CALL_EXTRAS}.
482 */
483 void startIncoming(CallServiceDescriptor descriptor, Bundle extras) {
484 Switchboard.getInstance().retrieveIncomingCall(this, descriptor, extras);
485 }
486
Santos Cordon2174fb52014-05-29 08:22:56 -0700487 /**
488 * Takes a verified incoming call and uses the handle to lookup direct-to-voicemail property
489 * from the contacts provider. The call is not yet exposed to the user at this point and
490 * the result of the query will determine if the call is rejected or passed through to the
491 * in-call UI.
492 */
493 void handleVerifiedIncoming(CallInfo callInfo) {
Santos Cordon766d04f2014-05-06 10:28:25 -0700494 Preconditions.checkState(callInfo.getState() == CallState.RINGING);
Santos Cordon2174fb52014-05-29 08:22:56 -0700495
496 // We do not handle incoming calls immediately when they are verified by the call service.
497 // We allow the caller-info-query code to execute first so that we can read the
498 // direct-to-voicemail property before deciding if we want to show the incoming call to the
499 // user or if we want to reject the call.
500 mPendingDirectToVoicemailCallInfo = callInfo;
501
502 // Setting the handle triggers the caller info lookup code.
Santos Cordon766d04f2014-05-06 10:28:25 -0700503 setHandle(callInfo.getHandle());
504
Santos Cordon2174fb52014-05-29 08:22:56 -0700505 // Timeout the direct-to-voicemail lookup execution so that we dont wait too long before
506 // showing the user the incoming call screen.
507 mHandler.postDelayed(new Runnable() {
508 @Override
509 public void run() {
510 processDirectToVoicemail();
511 }
Santos Cordona1610702014-06-04 20:22:56 -0700512 }, Timeouts.getDirectToVoicemailMillis());
Santos Cordon2174fb52014-05-29 08:22:56 -0700513 }
Santos Cordon766d04f2014-05-06 10:28:25 -0700514
Santos Cordon2174fb52014-05-29 08:22:56 -0700515 void processDirectToVoicemail() {
516 if (mPendingDirectToVoicemailCallInfo != null) {
517 if (mCallerInfo != null && mCallerInfo.shouldSendToVoicemail) {
518 Log.i(this, "Directing call to voicemail: %s.", this);
519 // TODO(santoscordon): Once we move State handling from CallsManager to Call, we
520 // will not need to set RINGING state prior to calling reject.
521 setState(CallState.RINGING);
Ihab Awadff7493a2014-06-10 13:47:44 -0700522 reject(false, null);
Santos Cordon2174fb52014-05-29 08:22:56 -0700523 } else {
524 // TODO(santoscordon): Make this class (not CallsManager) responsible for changing
525 // the call state to RINGING.
526
527 // TODO(santoscordon): Replace this with state transition to RINGING.
528 for (Listener l : mListeners) {
529 l.onSuccessfulIncomingCall(this, mPendingDirectToVoicemailCallInfo);
530 }
531 }
532
533 mPendingDirectToVoicemailCallInfo = null;
Santos Cordon766d04f2014-05-06 10:28:25 -0700534 }
535 }
536
537 void handleFailedIncoming() {
538 clearCallService();
539
540 // TODO: Needs more specific disconnect error for this case.
541 setDisconnectCause(DisconnectCause.ERROR_UNSPECIFIED, null);
542 setState(CallState.DISCONNECTED);
543
544 // TODO(santoscordon): Replace this with state transitions related to "connecting".
545 for (Listener l : mListeners) {
546 l.onFailedIncomingCall(this);
547 }
548 }
549
550 /**
Santos Cordon682fe6b2014-05-20 08:56:39 -0700551 * Starts the outgoing call sequence. Upon completion, there should exist an active connection
552 * through a call service (or the call will have failed).
Santos Cordon766d04f2014-05-06 10:28:25 -0700553 */
554 void startOutgoing() {
Santos Cordon682fe6b2014-05-20 08:56:39 -0700555 Preconditions.checkState(mOutgoingCallProcessor == null);
556
557 mOutgoingCallProcessor = new OutgoingCallProcessor(
558 this,
559 Switchboard.getInstance().getCallServiceRepository(),
560 Switchboard.getInstance().getSelectorRepository(),
561 new AsyncResultCallback<Boolean>() {
562 @Override
Ihab Awad0fea3f22014-06-03 18:45:05 -0700563 public void onResult(Boolean wasCallPlaced, int errorCode, String errorMsg) {
Santos Cordon682fe6b2014-05-20 08:56:39 -0700564 if (wasCallPlaced) {
565 handleSuccessfulOutgoing();
566 } else {
Ihab Awad0fea3f22014-06-03 18:45:05 -0700567 handleFailedOutgoing(
568 mOutgoingCallProcessor.isAborted(), errorCode, errorMsg);
Santos Cordon682fe6b2014-05-20 08:56:39 -0700569 }
570 mOutgoingCallProcessor = null;
571 }
572 });
573 mOutgoingCallProcessor.process();
Santos Cordon766d04f2014-05-06 10:28:25 -0700574 }
575
576 void handleSuccessfulOutgoing() {
577 // TODO(santoscordon): Replace this with state transitions related to "connecting".
578 for (Listener l : mListeners) {
579 l.onSuccessfulOutgoingCall(this);
580 }
581 }
582
Ihab Awad0fea3f22014-06-03 18:45:05 -0700583 void handleFailedOutgoing(boolean isAborted, int errorCode, String errorMsg) {
Santos Cordon766d04f2014-05-06 10:28:25 -0700584 // TODO(santoscordon): Replace this with state transitions related to "connecting".
585 for (Listener l : mListeners) {
Ihab Awad0fea3f22014-06-03 18:45:05 -0700586 l.onFailedOutgoingCall(this, isAborted, errorCode, errorMsg);
Santos Cordon766d04f2014-05-06 10:28:25 -0700587 }
Santos Cordon682fe6b2014-05-20 08:56:39 -0700588
589 clearCallService();
590 clearCallServiceSelector();
Santos Cordon766d04f2014-05-06 10:28:25 -0700591 }
592
593 /**
Ben Gilad61925612014-03-11 19:06:36 -0700594 * Adds the specified call service to the list of incompatible services. The set is used when
595 * attempting to switch a phone call between call services such that incompatible services can
596 * be avoided.
597 *
598 * @param callService The incompatible call service.
599 */
600 void addIncompatibleCallService(CallServiceWrapper callService) {
601 if (mIncompatibleCallServices == null) {
602 mIncompatibleCallServices = Sets.newHashSet();
603 }
604 mIncompatibleCallServices.add(callService);
605 }
606
607 /**
608 * Checks whether or not the specified callService was identified as incompatible in the
609 * context of this call.
610 *
611 * @param callService The call service to evaluate.
612 * @return True upon incompatible call services and false otherwise.
613 */
614 boolean isIncompatibleCallService(CallServiceWrapper callService) {
615 return mIncompatibleCallServices != null &&
616 mIncompatibleCallServices.contains(callService);
617 }
618
619 /**
Ihab Awad74549ec2014-03-10 15:33:25 -0700620 * Plays the specified DTMF tone.
621 */
622 void playDtmfTone(char digit) {
623 if (mCallService == null) {
624 Log.w(this, "playDtmfTone() request on a call without a call service.");
625 } else {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700626 Log.i(this, "Send playDtmfTone to call service for call %s", this);
627 mCallService.playDtmfTone(this, digit);
Ihab Awad74549ec2014-03-10 15:33:25 -0700628 }
629 }
630
631 /**
632 * Stops playing any currently playing DTMF tone.
633 */
634 void stopDtmfTone() {
635 if (mCallService == null) {
636 Log.w(this, "stopDtmfTone() request on a call without a call service.");
637 } else {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700638 Log.i(this, "Send stopDtmfTone to call service for call %s", this);
639 mCallService.stopDtmfTone(this);
Ihab Awad74549ec2014-03-10 15:33:25 -0700640 }
641 }
642
643 /**
Santos Cordon049b7b62014-01-30 05:34:26 -0800644 * Attempts to disconnect the call through the call service.
645 */
646 void disconnect() {
Santos Cordon766d04f2014-05-06 10:28:25 -0700647 if (mState == CallState.NEW) {
Santos Cordon682fe6b2014-05-20 08:56:39 -0700648 Log.v(this, "Aborting call %s", this);
649 abort();
Santos Cordon74d420b2014-05-07 14:38:47 -0700650 } else if (mState != CallState.ABORTED && mState != CallState.DISCONNECTED) {
Santos Cordon766d04f2014-05-06 10:28:25 -0700651 Preconditions.checkNotNull(mCallService);
652
Sailesh Nepale59bb192014-04-01 18:33:59 -0700653 Log.i(this, "Send disconnect to call service for call: %s", this);
Santos Cordonc195e362014-02-11 17:05:31 -0800654 // The call isn't officially disconnected until the call service confirms that the call
655 // was actually disconnected. Only then is the association between call and call service
656 // severed, see {@link CallsManager#markCallAsDisconnected}.
Sailesh Nepale59bb192014-04-01 18:33:59 -0700657 mCallService.disconnect(this);
Santos Cordon049b7b62014-01-30 05:34:26 -0800658 }
659 }
660
Santos Cordon682fe6b2014-05-20 08:56:39 -0700661 void abort() {
662 if (mOutgoingCallProcessor != null) {
663 mOutgoingCallProcessor.abort();
664 }
665 }
666
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800667 /**
Santos Cordon61d0f702014-02-19 02:52:23 -0800668 * Answers the call if it is ringing.
669 */
670 void answer() {
671 Preconditions.checkNotNull(mCallService);
672
673 // Check to verify that the call is still in the ringing state. A call can change states
674 // between the time the user hits 'answer' and Telecomm receives the command.
675 if (isRinging("answer")) {
676 // At this point, we are asking the call service to answer but we don't assume that
677 // it will work. Instead, we wait until confirmation from the call service that the
678 // call is in a non-RINGING state before changing the UI. See
679 // {@link CallServiceAdapter#setActive} and other set* methods.
Sailesh Nepale59bb192014-04-01 18:33:59 -0700680 mCallService.answer(this);
Santos Cordon61d0f702014-02-19 02:52:23 -0800681 }
682 }
683
684 /**
685 * Rejects the call if it is ringing.
Ihab Awadff7493a2014-06-10 13:47:44 -0700686 *
687 * @param rejectWithMessage Whether to send a text message as part of the call rejection.
688 * @param textMessage An optional text message to send as part of the rejection.
Santos Cordon61d0f702014-02-19 02:52:23 -0800689 */
Ihab Awadff7493a2014-06-10 13:47:44 -0700690 void reject(boolean rejectWithMessage, String textMessage) {
Santos Cordon61d0f702014-02-19 02:52:23 -0800691 Preconditions.checkNotNull(mCallService);
692
693 // Check to verify that the call is still in the ringing state. A call can change states
694 // between the time the user hits 'reject' and Telecomm receives the command.
695 if (isRinging("reject")) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700696 mCallService.reject(this);
Santos Cordon61d0f702014-02-19 02:52:23 -0800697 }
698 }
699
700 /**
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700701 * Puts the call on hold if it is currently active.
702 */
703 void hold() {
704 Preconditions.checkNotNull(mCallService);
705
706 if (mState == CallState.ACTIVE) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700707 mCallService.hold(this);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700708 }
709 }
710
711 /**
712 * Releases the call from hold if it is currently active.
713 */
714 void unhold() {
715 Preconditions.checkNotNull(mCallService);
716
717 if (mState == CallState.ON_HOLD) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700718 mCallService.unhold(this);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700719 }
720 }
721
722 /**
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800723 * @return An object containing read-only information about this call.
724 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700725 CallInfo toCallInfo(String callId) {
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700726 CallServiceDescriptor descriptor = null;
727 if (mCallService != null) {
728 descriptor = mCallService.getDescriptor();
729 } else if (mOriginalCall != null && mOriginalCall.mCallService != null) {
730 descriptor = mOriginalCall.mCallService.getDescriptor();
731 }
732 return new CallInfo(callId, mState, mHandle, mGatewayInfo, mExtras, descriptor);
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800733 }
734
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700735 /** Checks if this is a live call or not. */
736 boolean isAlive() {
737 switch (mState) {
738 case NEW:
739 case RINGING:
740 case DISCONNECTED:
741 case ABORTED:
742 return false;
743 default:
744 return true;
745 }
746 }
747
Santos Cordon40f78c22014-04-07 02:11:42 -0700748 boolean isActive() {
749 switch (mState) {
750 case ACTIVE:
751 case POST_DIAL:
752 case POST_DIAL_WAIT:
753 return true;
754 default:
755 return false;
756 }
757 }
758
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700759 Bundle getExtras() {
760 return mExtras;
761 }
762
763 void setExtras(Bundle extras) {
764 mExtras = extras;
765 }
766
767 Uri getHandoffHandle() {
768 return mHandoffHandle;
769 }
770
771 void setHandoffHandle(Uri handoffHandle) {
772 mHandoffHandle = handoffHandle;
773 }
774
775 Call getOriginalCall() {
776 return mOriginalCall;
777 }
778
779 void setOriginalCall(Call originalCall) {
780 mOriginalCall = originalCall;
781 }
782
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700783 CallServiceDescriptor getHandoffCallServiceDescriptor() {
784 return mHandoffCallServiceDescriptor;
785 }
786
787 void setHandoffCallServiceDescriptor(CallServiceDescriptor descriptor) {
788 mHandoffCallServiceDescriptor = descriptor;
789 }
790
Santos Cordon5ba7f272014-05-28 13:59:49 -0700791 Uri getRingtone() {
792 return mCallerInfo == null ? null : mCallerInfo.contactRingtoneUri;
793 }
794
Evan Charlton352105c2014-06-03 14:10:54 -0700795 void onPostDialWait(String remaining) {
796 for (Listener l : mListeners) {
797 l.onPostDialWait(this, remaining);
798 }
799 }
800
801 void postDialContinue(boolean proceed) {
802 getCallService().onPostDialContinue(this, proceed);
803 }
804
Santos Cordona1610702014-06-04 20:22:56 -0700805 void conferenceInto(Call conferenceCall) {
806 if (mCallService == null) {
807 Log.w(this, "conference requested on a call without a call service.");
808 } else {
809 mCallService.conference(conferenceCall, this);
810 }
811 }
812
813 void expireConference() {
814 // The conference call expired before we got a confirmation of the conference from the
815 // call service...so start shutting down.
816 clearCallService();
817 for (Listener l : mListeners) {
818 l.onExpiredConferenceCall(this);
819 }
820 }
821
822 void confirmConference() {
823 Log.v(this, "confirming Conf call %s", mListeners);
824 for (Listener l : mListeners) {
825 l.onConfirmedConferenceCall(this);
826 }
827 }
828
829 void splitFromConference() {
830 // TODO(santoscordon): todo
831 }
832
833 void setParentCall(Call parentCall) {
834 if (parentCall == this) {
835 Log.e(this, new Exception(), "setting the parent to self");
836 return;
837 }
838 Preconditions.checkState(parentCall == null || mParentCall == null);
839
840 Call oldParent = mParentCall;
841 if (mParentCall != null) {
842 mParentCall.removeChildCall(this);
843 }
844 mParentCall = parentCall;
845 if (mParentCall != null) {
846 mParentCall.addChildCall(this);
847 }
848
849 for (Listener l : mListeners) {
850 l.onParentChanged(this);
851 }
852 }
853
854 private void addChildCall(Call call) {
855 if (!mChildCalls.contains(call)) {
856 mChildCalls.add(call);
857
858 for (Listener l : mListeners) {
859 l.onChildrenChanged(this);
860 }
861 }
862 }
863
864 private void removeChildCall(Call call) {
865 if (mChildCalls.remove(call)) {
866 for (Listener l : mListeners) {
867 l.onChildrenChanged(this);
868 }
869 }
870 }
871
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800872 /**
Ihab Awadff7493a2014-06-10 13:47:44 -0700873 * Return whether the user can respond to this {@code Call} via an SMS message.
874 *
875 * @return true if the "Respond via SMS" feature should be enabled
876 * for this incoming call.
877 *
878 * The general rule is that we *do* allow "Respond via SMS" except for
879 * the few (relatively rare) cases where we know for sure it won't
880 * work, namely:
881 * - a bogus or blank incoming number
882 * - a call from a SIP address
883 * - a "call presentation" that doesn't allow the number to be revealed
884 *
885 * In all other cases, we allow the user to respond via SMS.
886 *
887 * Note that this behavior isn't perfect; for example we have no way
888 * to detect whether the incoming call is from a landline (with most
889 * networks at least), so we still enable this feature even though
890 * SMSes to that number will silently fail.
891 */
892 boolean isRespondViaSmsCapable() {
893 if (mState != CallState.RINGING) {
894 return false;
895 }
896
897 if (getHandle() == null) {
898 // No incoming number known or call presentation is "PRESENTATION_RESTRICTED", in
899 // other words, the user should not be able to see the incoming phone number.
900 return false;
901 }
902
903 if (PhoneNumberUtils.isUriNumber(getHandle().toString())) {
904 // The incoming number is actually a URI (i.e. a SIP address),
905 // not a regular PSTN phone number, and we can't send SMSes to
906 // SIP addresses.
907 // (TODO: That might still be possible eventually, though. Is
908 // there some SIP-specific equivalent to sending a text message?)
909 return false;
910 }
911
912 // Is there a valid SMS application on the phone?
913 if (SmsApplication.getDefaultRespondViaMessageApplication(TelecommApp.getInstance(),
914 true /*updateIfNeeded*/) == null) {
915 return false;
916 }
917
918 // TODO: with some carriers (in certain countries) you *can* actually
919 // tell whether a given number is a mobile phone or not. So in that
920 // case we could potentially return false here if the incoming call is
921 // from a land line.
922
923 // If none of the above special cases apply, it's OK to enable the
924 // "Respond via SMS" feature.
925 return true;
926 }
927
928 List<String> getCannedSmsResponses() {
929 return mCannedSmsResponses;
930 }
931
932 /**
Santos Cordon61d0f702014-02-19 02:52:23 -0800933 * @return True if the call is ringing, else logs the action name.
934 */
935 private boolean isRinging(String actionName) {
936 if (mState == CallState.RINGING) {
937 return true;
938 }
939
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800940 Log.i(this, "Request to %s a non-ringing call %s", actionName, this);
Santos Cordon61d0f702014-02-19 02:52:23 -0800941 return false;
942 }
943
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800944 @SuppressWarnings("rawtypes")
945 private void decrementAssociatedCallCount(ServiceBinder binder) {
946 if (binder != null) {
947 binder.decrementAssociatedCallCount();
948 }
949 }
Santos Cordonfd71f4a2014-05-28 13:59:49 -0700950
951 /**
952 * Looks up contact information based on the current handle.
953 */
954 private void startCallerInfoLookup() {
955 String number = mHandle == null ? null : mHandle.getSchemeSpecificPart();
956
957 mQueryToken++; // Updated so that previous queries can no longer set the information.
958 mCallerInfo = null;
959 if (!TextUtils.isEmpty(number)) {
Santos Cordon5ba7f272014-05-28 13:59:49 -0700960 Log.v(this, "Looking up information for: %s.", Log.piiHandle(number));
Santos Cordonfd71f4a2014-05-28 13:59:49 -0700961 CallerInfoAsyncQuery.startQuery(
962 mQueryToken,
963 TelecommApp.getInstance(),
964 number,
965 sCallerInfoQueryListener,
966 this);
967 }
968 }
969
970 /**
Santos Cordon99c8a6f2014-05-28 18:28:47 -0700971 * Saves the specified caller info if the specified token matches that of the last query
Santos Cordonfd71f4a2014-05-28 13:59:49 -0700972 * that was made.
973 *
974 * @param callerInfo The new caller information to set.
975 * @param token The token used with this query.
976 */
977 private void setCallerInfo(CallerInfo callerInfo, int token) {
Santos Cordon99c8a6f2014-05-28 18:28:47 -0700978 Preconditions.checkNotNull(callerInfo);
979
Santos Cordonfd71f4a2014-05-28 13:59:49 -0700980 if (mQueryToken == token) {
981 mCallerInfo = callerInfo;
Santos Cordon5ba7f272014-05-28 13:59:49 -0700982 Log.i(this, "CallerInfo received for %s: %s", Log.piiHandle(mHandle), callerInfo);
Santos Cordon99c8a6f2014-05-28 18:28:47 -0700983
984 if (mCallerInfo.person_id != 0) {
985 Uri personUri =
986 ContentUris.withAppendedId(Contacts.CONTENT_URI, mCallerInfo.person_id);
987 Log.d(this, "Searching person uri %s for call %s", personUri, this);
988 ContactsAsyncHelper.startObtainPhotoAsync(
989 token,
990 TelecommApp.getInstance(),
991 personUri,
992 sPhotoLoadListener,
993 this);
994 }
Santos Cordon2174fb52014-05-29 08:22:56 -0700995
996 processDirectToVoicemail();
Santos Cordon99c8a6f2014-05-28 18:28:47 -0700997 }
998 }
999
1000 /**
1001 * Saves the specified photo information if the specified token matches that of the last query.
1002 *
1003 * @param photo The photo as a drawable.
1004 * @param photoIcon The photo as a small icon.
1005 * @param token The token used with this query.
1006 */
1007 private void setPhoto(Drawable photo, Bitmap photoIcon, int token) {
1008 if (mQueryToken == token) {
1009 mCallerInfo.cachedPhoto = photo;
1010 mCallerInfo.cachedPhotoIcon = photoIcon;
Santos Cordonfd71f4a2014-05-28 13:59:49 -07001011 }
1012 }
Ihab Awadff7493a2014-06-10 13:47:44 -07001013
1014 private void maybeLoadCannedSmsResponses() {
1015 if (mIsIncoming && isRespondViaSmsCapable() && !mCannedSmsResponsesLoadingStarted) {
1016 Log.d(this, "maybeLoadCannedSmsResponses: starting task to load messages");
1017 mCannedSmsResponsesLoadingStarted = true;
1018 RespondViaSmsManager.getInstance().loadCannedTextMessages(
1019 new Response<Void, List<String>>() {
1020 @Override
1021 public void onResult(Void request, List<String>... result) {
1022 if (result.length > 0) {
1023 Log.d(this, "maybeLoadCannedSmsResponses: got %s", result[0]);
1024 mCannedSmsResponses = result[0];
1025 for (Listener l : mListeners) {
1026 l.onCannedSmsResponsesLoaded(Call.this);
1027 }
1028 }
1029 }
1030
1031 @Override
1032 public void onError(Void request, int code, String msg) {
1033 Log.w(Call.this, "Error obtaining canned SMS responses: %d %s", code,
1034 msg);
1035 }
1036 }
1037 );
1038 } else {
1039 Log.d(this, "maybeLoadCannedSmsResponses: doing nothing");
1040 }
1041 }
Sai Cheemalapatib7157e92014-06-11 17:51:55 -07001042
1043 /**
1044 * Sets speakerphone option on when call begins.
1045 */
1046 public void setStartWithSpeakerphoneOn(boolean startWithSpeakerphone) {
1047 mSpeakerphoneOn = startWithSpeakerphone;
1048 }
1049
1050 /**
1051 * Returns speakerphone option.
1052 *
1053 * @return Whether or not speakerphone should be set automatically when call begins.
1054 */
1055 public boolean getStartWithSpeakerphoneOn() {
1056 return mSpeakerphoneOn;
1057 }
Ben Gilad9f2bed32013-12-12 17:43:26 -08001058}