blob: 09f60cf1bdb97939635fb82dd7753b9dc1d5437c [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;
Andrew Leee9a77652014-06-26 13:07:57 -070030import android.telecomm.InCallService;
Ihab Awadff7493a2014-06-10 13:47:44 -070031import android.telecomm.Response;
Nancy Chen77d2d0e2014-06-24 12:06:03 -070032import android.telecomm.Subscription;
Santos Cordon766d04f2014-05-06 10:28:25 -070033import android.telecomm.TelecommConstants;
Santos Cordon79ff2bc2014-03-27 15:31:27 -070034import android.telephony.DisconnectCause;
Sailesh Nepal6aca10a2014-03-24 16:11:02 -070035import android.telephony.PhoneNumberUtils;
Santos Cordonfd71f4a2014-05-28 13:59:49 -070036import android.text.TextUtils;
Santos Cordon0b03b4b2014-01-29 18:01:59 -080037
Santos Cordonfd71f4a2014-05-28 13:59:49 -070038import com.android.internal.telephony.CallerInfo;
39import com.android.internal.telephony.CallerInfoAsyncQuery;
40import com.android.internal.telephony.CallerInfoAsyncQuery.OnQueryCompleteListener;
Santos Cordon99c8a6f2014-05-28 18:28:47 -070041
Ihab Awadff7493a2014-06-10 13:47:44 -070042import com.android.internal.telephony.SmsApplication;
Santos Cordon99c8a6f2014-05-28 18:28:47 -070043import com.android.telecomm.ContactsAsyncHelper.OnImageLoadCompleteListener;
Santos Cordon61d0f702014-02-19 02:52:23 -080044import com.google.common.base.Preconditions;
Ihab Awadff7493a2014-06-10 13:47:44 -070045import com.google.common.collect.Sets;
Santos Cordon61d0f702014-02-19 02:52:23 -080046
Ihab Awadff7493a2014-06-10 13:47:44 -070047import java.util.Collections;
Santos Cordona1610702014-06-04 20:22:56 -070048import java.util.LinkedList;
49import java.util.List;
Sailesh Nepal91990782014-03-08 17:45:52 -080050import java.util.Locale;
Ben Gilad61925612014-03-11 19:06:36 -070051import java.util.Set;
Ben Gilad0407fb22014-01-09 16:18:41 -080052
Ben Gilad2495d572014-01-09 17:26:19 -080053/**
54 * Encapsulates all aspects of a given phone call throughout its lifecycle, starting
55 * from the time the call intent was received by Telecomm (vs. the time the call was
56 * connected etc).
57 */
Sailesh Nepal5a73b032014-06-25 15:53:21 -070058final class Call implements OutgoingCallResponse {
Santos Cordon766d04f2014-05-06 10:28:25 -070059
60 /**
61 * Listener for events on the call.
62 */
63 interface Listener {
64 void onSuccessfulOutgoingCall(Call call);
Sailesh Nepal5a73b032014-06-25 15:53:21 -070065 void onFailedOutgoingCall(Call call, int errorCode, String errorMsg);
66 void onCancelledOutgoingCall(Call call);
Santos Cordon766d04f2014-05-06 10:28:25 -070067 void onSuccessfulIncomingCall(Call call, CallInfo callInfo);
68 void onFailedIncomingCall(Call call);
Ihab Awadcb387ac2014-05-28 16:49:38 -070069 void onRequestingRingback(Call call, boolean requestingRingback);
Evan Charlton352105c2014-06-03 14:10:54 -070070 void onPostDialWait(Call call, String remaining);
Santos Cordona1610702014-06-04 20:22:56 -070071 void onIsConferenceCapableChanged(Call call, boolean isConferenceCapable);
72 void onExpiredConferenceCall(Call call);
73 void onConfirmedConferenceCall(Call call);
74 void onParentChanged(Call call);
75 void onChildrenChanged(Call call);
Ihab Awadff7493a2014-06-10 13:47:44 -070076 void onCannedSmsResponsesLoaded(Call call);
Santos Cordon766d04f2014-05-06 10:28:25 -070077 }
78
Santos Cordonfd71f4a2014-05-28 13:59:49 -070079 private static final OnQueryCompleteListener sCallerInfoQueryListener =
Santos Cordon99c8a6f2014-05-28 18:28:47 -070080 new OnQueryCompleteListener() {
81 /** ${inheritDoc} */
82 @Override
83 public void onQueryComplete(int token, Object cookie, CallerInfo callerInfo) {
84 if (cookie != null) {
85 ((Call) cookie).setCallerInfo(callerInfo, token);
86 }
Santos Cordonfd71f4a2014-05-28 13:59:49 -070087 }
Santos Cordon99c8a6f2014-05-28 18:28:47 -070088 };
89
90 private static final OnImageLoadCompleteListener sPhotoLoadListener =
91 new OnImageLoadCompleteListener() {
92 /** ${inheritDoc} */
93 @Override
94 public void onImageLoadComplete(
95 int token, Drawable photo, Bitmap photoIcon, Object cookie) {
96 if (cookie != null) {
97 ((Call) cookie).setPhoto(photo, photoIcon, token);
98 }
99 }
100 };
Ben Gilad0407fb22014-01-09 16:18:41 -0800101
Sailesh Nepal810735e2014-03-18 18:15:46 -0700102 /** True if this is an incoming call. */
103 private final boolean mIsIncoming;
104
Ben Gilad0407fb22014-01-09 16:18:41 -0800105 /**
106 * The time this call was created, typically also the time this call was added to the set
107 * of pending outgoing calls (mPendingOutgoingCalls) that's maintained by the switchboard.
108 * Beyond logging and such, may also be used for bookkeeping and specifically for marking
109 * certain call attempts as failed attempts.
110 */
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700111 private final long mCreationTimeMillis = System.currentTimeMillis();
112
Santos Cordonfd71f4a2014-05-28 13:59:49 -0700113 /** The gateway information associated with this call. This stores the original call handle
114 * that the user is attempting to connect to via the gateway, the actual handle to dial in
115 * order to connect the call via the gateway, as well as the package name of the gateway
116 * service. */
117 private final GatewayInfo mGatewayInfo;
118
Nancy Chen77d2d0e2014-06-24 12:06:03 -0700119 private final Subscription mSubscription;
120
Santos Cordon2174fb52014-05-29 08:22:56 -0700121 private final Handler mHandler = new Handler();
122
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700123 private long mConnectTimeMillis;
Ben Gilad0407fb22014-01-09 16:18:41 -0800124
Santos Cordon61d0f702014-02-19 02:52:23 -0800125 /** The state of the call. */
126 private CallState mState;
127
128 /** The handle with which to establish this call. */
Sailesh Nepalce704b92014-03-17 18:31:43 -0700129 private Uri mHandle;
Santos Cordon61d0f702014-02-19 02:52:23 -0800130
Ben Gilad0407fb22014-01-09 16:18:41 -0800131 /**
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800132 * The call service which is attempted or already connecting this call.
Santos Cordon681663d2014-01-30 04:32:15 -0800133 */
Santos Cordonc195e362014-02-11 17:05:31 -0800134 private CallServiceWrapper mCallService;
Santos Cordon681663d2014-01-30 04:32:15 -0800135
Ben Gilad8e55d1d2014-02-26 16:25:56 -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;
Santos Cordon682fe6b2014-05-20 08:56:39 -0700182
Santos Cordonfd71f4a2014-05-28 13:59:49 -0700183 /** Caller information retrieved from the latest contact query. */
184 private CallerInfo mCallerInfo;
185
186 /** The latest token used with a contact info query. */
187 private int mQueryToken = 0;
188
Ihab Awadcb387ac2014-05-28 16:49:38 -0700189 /** Whether this call is requesting that Telecomm play the ringback tone on its behalf. */
190 private boolean mRequestingRingback = false;
191
Santos Cordon2174fb52014-05-29 08:22:56 -0700192 /** Incoming call-info to use when direct-to-voicemail query finishes. */
193 private CallInfo mPendingDirectToVoicemailCallInfo;
194
Santos Cordona1610702014-06-04 20:22:56 -0700195 private boolean mIsConferenceCapable = false;
196
197 private boolean mIsConference = false;
198
199 private Call mParentCall = null;
200
201 private List<Call> mChildCalls = new LinkedList<>();
202
Ihab Awadff7493a2014-06-10 13:47:44 -0700203 /** Set of text message responses allowed for this call, if applicable. */
204 private List<String> mCannedSmsResponses = Collections.EMPTY_LIST;
205
206 /** Whether an attempt has been made to load the text message responses. */
207 private boolean mCannedSmsResponsesLoadingStarted = false;
208
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700209 /**
Sailesh Nepale59bb192014-04-01 18:33:59 -0700210 * Creates an empty call object.
Sailesh Nepal810735e2014-03-18 18:15:46 -0700211 *
212 * @param isIncoming True if this is an incoming call.
Santos Cordon493e8f22014-02-19 03:15:12 -0800213 */
Santos Cordona1610702014-06-04 20:22:56 -0700214 Call(boolean isIncoming, boolean isConference) {
Nancy Chen77d2d0e2014-06-24 12:06:03 -0700215 this(null, null, null, isIncoming, isConference);
Santos Cordon493e8f22014-02-19 03:15:12 -0800216 }
217
218 /**
Ben Gilad0407fb22014-01-09 16:18:41 -0800219 * Persists the specified parameters and initializes the new instance.
220 *
221 * @param handle The handle to dial.
Yorke Lee33501632014-03-17 19:24:12 -0700222 * @param gatewayInfo Gateway information to use for the call.
Nancy Chen77d2d0e2014-06-24 12:06:03 -0700223 * @param subscription Subscription 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 */
Nancy Chen77d2d0e2014-06-24 12:06:03 -0700226 Call(Uri handle, GatewayInfo gatewayInfo, Subscription subscription,
227 boolean isIncoming, boolean isConference) {
Santos Cordona1610702014-06-04 20:22:56 -0700228 mState = isConference ? CallState.ACTIVE : CallState.NEW;
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700229 setHandle(handle);
Yorke Lee33501632014-03-17 19:24:12 -0700230 mGatewayInfo = gatewayInfo;
Nancy Chen77d2d0e2014-06-24 12:06:03 -0700231 mSubscription = subscription;
Sailesh Nepal810735e2014-03-18 18:15:46 -0700232 mIsIncoming = isIncoming;
Santos Cordona1610702014-06-04 20:22:56 -0700233 mIsConference = isConference;
Ihab Awadff7493a2014-06-10 13:47:44 -0700234 maybeLoadCannedSmsResponses();
Ben Gilad0407fb22014-01-09 16:18:41 -0800235 }
236
Santos Cordon766d04f2014-05-06 10:28:25 -0700237 void addListener(Listener listener) {
238 mListeners.add(listener);
239 }
240
241 void removeListener(Listener listener) {
242 mListeners.remove(listener);
243 }
244
Santos Cordon61d0f702014-02-19 02:52:23 -0800245 /** {@inheritDoc} */
246 @Override public String toString() {
Sailesh Nepal4538f012014-04-15 11:40:33 -0700247 String component = null;
248 if (mCallService != null && mCallService.getComponentName() != null) {
249 component = mCallService.getComponentName().flattenToShortString();
250 }
251 return String.format(Locale.US, "[%s, %s, %s]", mState, component, Log.piiHandle(mHandle));
Santos Cordon61d0f702014-02-19 02:52:23 -0800252 }
253
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800254 CallState getState() {
Santos Cordona1610702014-06-04 20:22:56 -0700255 if (mIsConference) {
256 if (!mChildCalls.isEmpty()) {
257 // If we have child calls, just return the child call.
258 return mChildCalls.get(0).getState();
259 }
260 return CallState.ACTIVE;
261 } else {
262 return mState;
263 }
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800264 }
265
266 /**
267 * Sets the call state. Although there exists the notion of appropriate state transitions
268 * (see {@link CallState}), in practice those expectations break down when cellular systems
269 * misbehave and they do this very often. The result is that we do not enforce state transitions
270 * and instead keep the code resilient to unexpected state changes.
271 */
Sailesh Nepal810735e2014-03-18 18:15:46 -0700272 void setState(CallState newState) {
Santos Cordon79ff2bc2014-03-27 15:31:27 -0700273 Preconditions.checkState(newState != CallState.DISCONNECTED ||
274 mDisconnectCause != DisconnectCause.NOT_VALID);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700275 if (mState != newState) {
276 Log.v(this, "setState %s -> %s", mState, newState);
277 mState = newState;
Ihab Awadff7493a2014-06-10 13:47:44 -0700278 maybeLoadCannedSmsResponses();
Sailesh Nepal810735e2014-03-18 18:15:46 -0700279 }
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800280 }
281
Ihab Awadcb387ac2014-05-28 16:49:38 -0700282 void setRequestingRingback(boolean requestingRingback) {
283 mRequestingRingback = requestingRingback;
284 for (Listener l : mListeners) {
285 l.onRequestingRingback(this, mRequestingRingback);
286 }
287 }
288
289 boolean isRequestingRingback() {
290 return mRequestingRingback;
291 }
292
Sailesh Nepalce704b92014-03-17 18:31:43 -0700293 Uri getHandle() {
Ben Gilad0bf5b912014-01-28 17:55:57 -0800294 return mHandle;
295 }
296
Sailesh Nepalce704b92014-03-17 18:31:43 -0700297 void setHandle(Uri handle) {
Santos Cordonfd71f4a2014-05-28 13:59:49 -0700298 if ((mHandle == null && handle != null) || (mHandle != null && !mHandle.equals(handle))) {
299 mHandle = handle;
300 mIsEmergencyCall = mHandle != null && PhoneNumberUtils.isLocalEmergencyNumber(
Yorke Lee66255452014-06-05 08:09:24 -0700301 TelecommApp.getInstance(), mHandle.getSchemeSpecificPart());
Santos Cordonfd71f4a2014-05-28 13:59:49 -0700302 startCallerInfoLookup();
303 }
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700304 }
305
Santos Cordon99c8a6f2014-05-28 18:28:47 -0700306 String getName() {
307 return mCallerInfo == null ? null : mCallerInfo.name;
308 }
309
310 Bitmap getPhotoIcon() {
311 return mCallerInfo == null ? null : mCallerInfo.cachedPhotoIcon;
312 }
313
314 Drawable getPhoto() {
315 return mCallerInfo == null ? null : mCallerInfo.cachedPhoto;
316 }
317
Santos Cordon79ff2bc2014-03-27 15:31:27 -0700318 /**
319 * @param disconnectCause The reason for the disconnection, any of
320 * {@link android.telephony.DisconnectCause}.
321 * @param disconnectMessage Optional call-service-provided message about the disconnect.
322 */
323 void setDisconnectCause(int disconnectCause, String disconnectMessage) {
324 // TODO: Consider combining this method with a setDisconnected() method that is totally
325 // separate from setState.
326 mDisconnectCause = disconnectCause;
327 mDisconnectMessage = disconnectMessage;
328 }
329
330 int getDisconnectCause() {
331 return mDisconnectCause;
332 }
333
334 String getDisconnectMessage() {
335 return mDisconnectMessage;
336 }
337
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700338 boolean isEmergencyCall() {
339 return mIsEmergencyCall;
Santos Cordon61d0f702014-02-19 02:52:23 -0800340 }
341
Yorke Lee33501632014-03-17 19:24:12 -0700342 /**
343 * @return The original handle this call is associated with. In-call services should use this
344 * handle when indicating in their UI the handle that is being called.
345 */
346 public Uri getOriginalHandle() {
347 if (mGatewayInfo != null && !mGatewayInfo.isEmpty()) {
348 return mGatewayInfo.getOriginalHandle();
349 }
350 return getHandle();
351 }
352
353 GatewayInfo getGatewayInfo() {
354 return mGatewayInfo;
355 }
356
Nancy Chen77d2d0e2014-06-24 12:06:03 -0700357 Subscription getSubscription() {
358 return mSubscription;
359 }
360
Sailesh Nepal810735e2014-03-18 18:15:46 -0700361 boolean isIncoming() {
362 return mIsIncoming;
363 }
364
Ben Gilad0407fb22014-01-09 16:18:41 -0800365 /**
366 * @return The "age" of this call object in milliseconds, which typically also represents the
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700367 * period since this call was added to the set pending outgoing calls, see
368 * mCreationTimeMillis.
Ben Gilad0407fb22014-01-09 16:18:41 -0800369 */
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700370 long getAgeMillis() {
371 return System.currentTimeMillis() - mCreationTimeMillis;
Ben Gilad0407fb22014-01-09 16:18:41 -0800372 }
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800373
Yorke Leef98fb572014-03-05 10:56:55 -0800374 /**
375 * @return The time when this call object was created and added to the set of pending outgoing
376 * calls.
377 */
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700378 long getCreationTimeMillis() {
379 return mCreationTimeMillis;
380 }
381
382 long getConnectTimeMillis() {
383 return mConnectTimeMillis;
384 }
385
386 void setConnectTimeMillis(long connectTimeMillis) {
387 mConnectTimeMillis = connectTimeMillis;
Yorke Leef98fb572014-03-05 10:56:55 -0800388 }
389
Santos Cordona1610702014-06-04 20:22:56 -0700390 boolean isConferenceCapable() {
391 return mIsConferenceCapable;
392 }
393
394 void setIsConferenceCapable(boolean isConferenceCapable) {
395 if (mIsConferenceCapable != isConferenceCapable) {
396 mIsConferenceCapable = isConferenceCapable;
397 for (Listener l : mListeners) {
398 l.onIsConferenceCapableChanged(this, mIsConferenceCapable);
399 }
400 }
401 }
402
403 Call getParentCall() {
404 return mParentCall;
405 }
406
407 List<Call> getChildCalls() {
408 return mChildCalls;
409 }
410
Santos Cordonc195e362014-02-11 17:05:31 -0800411 CallServiceWrapper getCallService() {
Santos Cordon681663d2014-01-30 04:32:15 -0800412 return mCallService;
413 }
414
Santos Cordonc195e362014-02-11 17:05:31 -0800415 void setCallService(CallServiceWrapper callService) {
Sailesh Nepal0e5410a2014-04-04 01:20:58 -0700416 setCallService(callService, null);
417 }
418
419 /**
420 * Changes the call service this call is associated with. If callToReplace is non-null then this
421 * call takes its place within the call service.
422 */
423 void setCallService(CallServiceWrapper callService, Call callToReplace) {
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800424 Preconditions.checkNotNull(callService);
425
Yorke Leeadee12d2014-03-13 12:08:30 -0700426 clearCallService();
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800427
428 callService.incrementAssociatedCallCount();
Santos Cordon681663d2014-01-30 04:32:15 -0800429 mCallService = callService;
Sailesh Nepal0e5410a2014-04-04 01:20:58 -0700430 if (callToReplace == null) {
431 mCallService.addCall(this);
432 } else {
433 mCallService.replaceCall(this, callToReplace);
434 }
Santos Cordon681663d2014-01-30 04:32:15 -0800435 }
436
437 /**
438 * Clears the associated call service.
439 */
440 void clearCallService() {
Yorke Leeadee12d2014-03-13 12:08:30 -0700441 if (mCallService != null) {
Santos Cordonc499c1c2014-04-14 17:13:14 -0700442 CallServiceWrapper callServiceTemp = mCallService;
Yorke Leeadee12d2014-03-13 12:08:30 -0700443 mCallService = null;
Santos Cordonc499c1c2014-04-14 17:13:14 -0700444 callServiceTemp.removeCall(this);
445
446 // Decrementing the count can cause the service to unbind, which itself can trigger the
447 // service-death code. Since the service death code tries to clean up any associated
448 // calls, we need to make sure to remove that information (e.g., removeCall()) before
449 // we decrement. Technically, invoking removeCall() prior to decrementing is all that is
450 // necessary, but cleaning up mCallService prior to triggering an unbind is good to do.
451 // If you change this, make sure to update {@link clearCallServiceSelector} as well.
452 decrementAssociatedCallCount(callServiceTemp);
Yorke Leeadee12d2014-03-13 12:08:30 -0700453 }
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800454 }
455
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800456 /**
Santos Cordon766d04f2014-05-06 10:28:25 -0700457 * Starts the incoming call flow through the switchboard. When switchboard completes, it will
458 * invoke handle[Un]SuccessfulIncomingCall.
459 *
460 * @param descriptor The relevant call-service descriptor.
461 * @param extras The optional extras passed via
462 * {@link TelecommConstants#EXTRA_INCOMING_CALL_EXTRAS}.
463 */
464 void startIncoming(CallServiceDescriptor descriptor, Bundle extras) {
465 Switchboard.getInstance().retrieveIncomingCall(this, descriptor, extras);
466 }
467
Santos Cordon2174fb52014-05-29 08:22:56 -0700468 /**
469 * Takes a verified incoming call and uses the handle to lookup direct-to-voicemail property
470 * from the contacts provider. The call is not yet exposed to the user at this point and
471 * the result of the query will determine if the call is rejected or passed through to the
472 * in-call UI.
473 */
474 void handleVerifiedIncoming(CallInfo callInfo) {
Santos Cordon766d04f2014-05-06 10:28:25 -0700475 Preconditions.checkState(callInfo.getState() == CallState.RINGING);
Santos Cordon2174fb52014-05-29 08:22:56 -0700476
477 // We do not handle incoming calls immediately when they are verified by the call service.
478 // We allow the caller-info-query code to execute first so that we can read the
479 // direct-to-voicemail property before deciding if we want to show the incoming call to the
480 // user or if we want to reject the call.
481 mPendingDirectToVoicemailCallInfo = callInfo;
482
483 // Setting the handle triggers the caller info lookup code.
Santos Cordon766d04f2014-05-06 10:28:25 -0700484 setHandle(callInfo.getHandle());
485
Santos Cordon2174fb52014-05-29 08:22:56 -0700486 // Timeout the direct-to-voicemail lookup execution so that we dont wait too long before
487 // showing the user the incoming call screen.
488 mHandler.postDelayed(new Runnable() {
489 @Override
490 public void run() {
491 processDirectToVoicemail();
492 }
Santos Cordona1610702014-06-04 20:22:56 -0700493 }, Timeouts.getDirectToVoicemailMillis());
Santos Cordon2174fb52014-05-29 08:22:56 -0700494 }
Santos Cordon766d04f2014-05-06 10:28:25 -0700495
Santos Cordon2174fb52014-05-29 08:22:56 -0700496 void processDirectToVoicemail() {
497 if (mPendingDirectToVoicemailCallInfo != null) {
498 if (mCallerInfo != null && mCallerInfo.shouldSendToVoicemail) {
499 Log.i(this, "Directing call to voicemail: %s.", this);
500 // TODO(santoscordon): Once we move State handling from CallsManager to Call, we
501 // will not need to set RINGING state prior to calling reject.
502 setState(CallState.RINGING);
Ihab Awadff7493a2014-06-10 13:47:44 -0700503 reject(false, null);
Santos Cordon2174fb52014-05-29 08:22:56 -0700504 } else {
505 // TODO(santoscordon): Make this class (not CallsManager) responsible for changing
506 // the call state to RINGING.
507
508 // TODO(santoscordon): Replace this with state transition to RINGING.
509 for (Listener l : mListeners) {
510 l.onSuccessfulIncomingCall(this, mPendingDirectToVoicemailCallInfo);
511 }
512 }
513
514 mPendingDirectToVoicemailCallInfo = null;
Santos Cordon766d04f2014-05-06 10:28:25 -0700515 }
516 }
517
518 void handleFailedIncoming() {
519 clearCallService();
520
521 // TODO: Needs more specific disconnect error for this case.
522 setDisconnectCause(DisconnectCause.ERROR_UNSPECIFIED, null);
523 setState(CallState.DISCONNECTED);
524
525 // TODO(santoscordon): Replace this with state transitions related to "connecting".
526 for (Listener l : mListeners) {
527 l.onFailedIncomingCall(this);
528 }
529 }
530
531 /**
Santos Cordon682fe6b2014-05-20 08:56:39 -0700532 * Starts the outgoing call sequence. Upon completion, there should exist an active connection
533 * through a call service (or the call will have failed).
Santos Cordon766d04f2014-05-06 10:28:25 -0700534 */
535 void startOutgoing() {
Santos Cordon682fe6b2014-05-20 08:56:39 -0700536 Preconditions.checkState(mOutgoingCallProcessor == null);
537
538 mOutgoingCallProcessor = new OutgoingCallProcessor(
Sailesh Nepal5a73b032014-06-25 15:53:21 -0700539 this, Switchboard.getInstance().getCallServiceRepository(), this);
Santos Cordon682fe6b2014-05-20 08:56:39 -0700540 mOutgoingCallProcessor.process();
Santos Cordon766d04f2014-05-06 10:28:25 -0700541 }
542
Sailesh Nepal5a73b032014-06-25 15:53:21 -0700543 @Override
544 public void onOutgoingCallSuccess() {
Santos Cordon766d04f2014-05-06 10:28:25 -0700545 // TODO(santoscordon): Replace this with state transitions related to "connecting".
546 for (Listener l : mListeners) {
547 l.onSuccessfulOutgoingCall(this);
548 }
Sailesh Nepal5a73b032014-06-25 15:53:21 -0700549 mOutgoingCallProcessor = null;
Santos Cordon766d04f2014-05-06 10:28:25 -0700550 }
551
Sailesh Nepal5a73b032014-06-25 15:53:21 -0700552 @Override
553 public void onOutgoingCallFailure(int code, String msg) {
Santos Cordon766d04f2014-05-06 10:28:25 -0700554 // TODO(santoscordon): Replace this with state transitions related to "connecting".
555 for (Listener l : mListeners) {
Sailesh Nepal5a73b032014-06-25 15:53:21 -0700556 l.onFailedOutgoingCall(this, code, msg);
Santos Cordon766d04f2014-05-06 10:28:25 -0700557 }
Santos Cordon682fe6b2014-05-20 08:56:39 -0700558
559 clearCallService();
Sailesh Nepal5a73b032014-06-25 15:53:21 -0700560 mOutgoingCallProcessor = null;
561 }
562
563 @Override
564 public void onOutgoingCallCancel() {
565 // TODO(santoscordon): Replace this with state transitions related to "connecting".
566 for (Listener l : mListeners) {
567 l.onCancelledOutgoingCall(this);
568 }
569
570 clearCallService();
571 mOutgoingCallProcessor = null;
Santos Cordon766d04f2014-05-06 10:28:25 -0700572 }
573
574 /**
Ben Gilad61925612014-03-11 19:06:36 -0700575 * Adds the specified call service to the list of incompatible services. The set is used when
576 * attempting to switch a phone call between call services such that incompatible services can
577 * be avoided.
578 *
579 * @param callService The incompatible call service.
580 */
581 void addIncompatibleCallService(CallServiceWrapper callService) {
582 if (mIncompatibleCallServices == null) {
583 mIncompatibleCallServices = Sets.newHashSet();
584 }
585 mIncompatibleCallServices.add(callService);
586 }
587
588 /**
589 * Checks whether or not the specified callService was identified as incompatible in the
590 * context of this call.
591 *
592 * @param callService The call service to evaluate.
593 * @return True upon incompatible call services and false otherwise.
594 */
595 boolean isIncompatibleCallService(CallServiceWrapper callService) {
596 return mIncompatibleCallServices != null &&
597 mIncompatibleCallServices.contains(callService);
598 }
599
600 /**
Ihab Awad74549ec2014-03-10 15:33:25 -0700601 * Plays the specified DTMF tone.
602 */
603 void playDtmfTone(char digit) {
604 if (mCallService == null) {
605 Log.w(this, "playDtmfTone() request on a call without a call service.");
606 } else {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700607 Log.i(this, "Send playDtmfTone to call service for call %s", this);
608 mCallService.playDtmfTone(this, digit);
Ihab Awad74549ec2014-03-10 15:33:25 -0700609 }
610 }
611
612 /**
613 * Stops playing any currently playing DTMF tone.
614 */
615 void stopDtmfTone() {
616 if (mCallService == null) {
617 Log.w(this, "stopDtmfTone() request on a call without a call service.");
618 } else {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700619 Log.i(this, "Send stopDtmfTone to call service for call %s", this);
620 mCallService.stopDtmfTone(this);
Ihab Awad74549ec2014-03-10 15:33:25 -0700621 }
622 }
623
624 /**
Santos Cordon049b7b62014-01-30 05:34:26 -0800625 * Attempts to disconnect the call through the call service.
626 */
627 void disconnect() {
Santos Cordon766d04f2014-05-06 10:28:25 -0700628 if (mState == CallState.NEW) {
Santos Cordon682fe6b2014-05-20 08:56:39 -0700629 Log.v(this, "Aborting call %s", this);
630 abort();
Santos Cordon74d420b2014-05-07 14:38:47 -0700631 } else if (mState != CallState.ABORTED && mState != CallState.DISCONNECTED) {
Santos Cordon766d04f2014-05-06 10:28:25 -0700632 Preconditions.checkNotNull(mCallService);
633
Sailesh Nepale59bb192014-04-01 18:33:59 -0700634 Log.i(this, "Send disconnect to call service for call: %s", this);
Santos Cordonc195e362014-02-11 17:05:31 -0800635 // The call isn't officially disconnected until the call service confirms that the call
636 // was actually disconnected. Only then is the association between call and call service
637 // severed, see {@link CallsManager#markCallAsDisconnected}.
Sailesh Nepale59bb192014-04-01 18:33:59 -0700638 mCallService.disconnect(this);
Santos Cordon049b7b62014-01-30 05:34:26 -0800639 }
640 }
641
Santos Cordon682fe6b2014-05-20 08:56:39 -0700642 void abort() {
643 if (mOutgoingCallProcessor != null) {
644 mOutgoingCallProcessor.abort();
645 }
646 }
647
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800648 /**
Santos Cordon61d0f702014-02-19 02:52:23 -0800649 * Answers the call if it is ringing.
650 */
651 void answer() {
652 Preconditions.checkNotNull(mCallService);
653
654 // Check to verify that the call is still in the ringing state. A call can change states
655 // between the time the user hits 'answer' and Telecomm receives the command.
656 if (isRinging("answer")) {
657 // At this point, we are asking the call service to answer but we don't assume that
658 // it will work. Instead, we wait until confirmation from the call service that the
659 // call is in a non-RINGING state before changing the UI. See
660 // {@link CallServiceAdapter#setActive} and other set* methods.
Sailesh Nepale59bb192014-04-01 18:33:59 -0700661 mCallService.answer(this);
Santos Cordon61d0f702014-02-19 02:52:23 -0800662 }
663 }
664
665 /**
666 * Rejects the call if it is ringing.
Ihab Awadff7493a2014-06-10 13:47:44 -0700667 *
668 * @param rejectWithMessage Whether to send a text message as part of the call rejection.
669 * @param textMessage An optional text message to send as part of the rejection.
Santos Cordon61d0f702014-02-19 02:52:23 -0800670 */
Ihab Awadff7493a2014-06-10 13:47:44 -0700671 void reject(boolean rejectWithMessage, String textMessage) {
Santos Cordon61d0f702014-02-19 02:52:23 -0800672 Preconditions.checkNotNull(mCallService);
673
674 // Check to verify that the call is still in the ringing state. A call can change states
675 // between the time the user hits 'reject' and Telecomm receives the command.
676 if (isRinging("reject")) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700677 mCallService.reject(this);
Santos Cordon61d0f702014-02-19 02:52:23 -0800678 }
679 }
680
681 /**
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700682 * Puts the call on hold if it is currently active.
683 */
684 void hold() {
685 Preconditions.checkNotNull(mCallService);
686
687 if (mState == CallState.ACTIVE) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700688 mCallService.hold(this);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700689 }
690 }
691
692 /**
693 * Releases the call from hold if it is currently active.
694 */
695 void unhold() {
696 Preconditions.checkNotNull(mCallService);
697
698 if (mState == CallState.ON_HOLD) {
Sailesh Nepale59bb192014-04-01 18:33:59 -0700699 mCallService.unhold(this);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700700 }
701 }
702
703 /**
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800704 * @return An object containing read-only information about this call.
705 */
Sailesh Nepale59bb192014-04-01 18:33:59 -0700706 CallInfo toCallInfo(String callId) {
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700707 CallServiceDescriptor descriptor = null;
708 if (mCallService != null) {
709 descriptor = mCallService.getDescriptor();
710 } else if (mOriginalCall != null && mOriginalCall.mCallService != null) {
711 descriptor = mOriginalCall.mCallService.getDescriptor();
712 }
Santos Cordon571f0732014-06-25 18:13:15 -0700713 Bundle extras = mExtras;
714 if (mGatewayInfo != null && mGatewayInfo.getGatewayProviderPackageName() != null &&
715 mGatewayInfo.getOriginalHandle() != null) {
716 extras = (Bundle) mExtras.clone();
717 extras.putString(
718 NewOutgoingCallIntentBroadcaster.EXTRA_GATEWAY_PROVIDER_PACKAGE,
719 mGatewayInfo.getGatewayProviderPackageName());
720 extras.putParcelable(
721 NewOutgoingCallIntentBroadcaster.EXTRA_GATEWAY_ORIGINAL_URI,
722 mGatewayInfo.getOriginalHandle());
723
724 }
Nancy Chen77d2d0e2014-06-24 12:06:03 -0700725 return new CallInfo(callId, mState, mHandle, mGatewayInfo, mSubscription,
726 extras, descriptor);
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800727 }
728
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700729 /** Checks if this is a live call or not. */
730 boolean isAlive() {
731 switch (mState) {
732 case NEW:
733 case RINGING:
734 case DISCONNECTED:
735 case ABORTED:
736 return false;
737 default:
738 return true;
739 }
740 }
741
Santos Cordon40f78c22014-04-07 02:11:42 -0700742 boolean isActive() {
743 switch (mState) {
744 case ACTIVE:
745 case POST_DIAL:
746 case POST_DIAL_WAIT:
747 return true;
748 default:
749 return false;
750 }
751 }
752
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700753 Bundle getExtras() {
754 return mExtras;
755 }
756
757 void setExtras(Bundle extras) {
758 mExtras = extras;
759 }
760
761 Uri getHandoffHandle() {
762 return mHandoffHandle;
763 }
764
765 void setHandoffHandle(Uri handoffHandle) {
766 mHandoffHandle = handoffHandle;
767 }
768
769 Call getOriginalCall() {
770 return mOriginalCall;
771 }
772
773 void setOriginalCall(Call originalCall) {
774 mOriginalCall = originalCall;
775 }
776
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700777 CallServiceDescriptor getHandoffCallServiceDescriptor() {
778 return mHandoffCallServiceDescriptor;
779 }
780
781 void setHandoffCallServiceDescriptor(CallServiceDescriptor descriptor) {
782 mHandoffCallServiceDescriptor = descriptor;
783 }
784
Santos Cordon5ba7f272014-05-28 13:59:49 -0700785 Uri getRingtone() {
786 return mCallerInfo == null ? null : mCallerInfo.contactRingtoneUri;
787 }
788
Evan Charlton352105c2014-06-03 14:10:54 -0700789 void onPostDialWait(String remaining) {
790 for (Listener l : mListeners) {
791 l.onPostDialWait(this, remaining);
792 }
793 }
794
795 void postDialContinue(boolean proceed) {
796 getCallService().onPostDialContinue(this, proceed);
797 }
798
Santos Cordona1610702014-06-04 20:22:56 -0700799 void conferenceInto(Call conferenceCall) {
800 if (mCallService == null) {
801 Log.w(this, "conference requested on a call without a call service.");
802 } else {
803 mCallService.conference(conferenceCall, this);
804 }
805 }
806
807 void expireConference() {
808 // The conference call expired before we got a confirmation of the conference from the
809 // call service...so start shutting down.
810 clearCallService();
811 for (Listener l : mListeners) {
812 l.onExpiredConferenceCall(this);
813 }
814 }
815
816 void confirmConference() {
817 Log.v(this, "confirming Conf call %s", mListeners);
818 for (Listener l : mListeners) {
819 l.onConfirmedConferenceCall(this);
820 }
821 }
822
823 void splitFromConference() {
824 // TODO(santoscordon): todo
825 }
826
827 void setParentCall(Call parentCall) {
828 if (parentCall == this) {
829 Log.e(this, new Exception(), "setting the parent to self");
830 return;
831 }
832 Preconditions.checkState(parentCall == null || mParentCall == null);
833
834 Call oldParent = mParentCall;
835 if (mParentCall != null) {
836 mParentCall.removeChildCall(this);
837 }
838 mParentCall = parentCall;
839 if (mParentCall != null) {
840 mParentCall.addChildCall(this);
841 }
842
843 for (Listener l : mListeners) {
844 l.onParentChanged(this);
845 }
846 }
847
848 private void addChildCall(Call call) {
849 if (!mChildCalls.contains(call)) {
850 mChildCalls.add(call);
851
852 for (Listener l : mListeners) {
853 l.onChildrenChanged(this);
854 }
855 }
856 }
857
858 private void removeChildCall(Call call) {
859 if (mChildCalls.remove(call)) {
860 for (Listener l : mListeners) {
861 l.onChildrenChanged(this);
862 }
863 }
864 }
865
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800866 /**
Ihab Awadff7493a2014-06-10 13:47:44 -0700867 * Return whether the user can respond to this {@code Call} via an SMS message.
868 *
869 * @return true if the "Respond via SMS" feature should be enabled
870 * for this incoming call.
871 *
872 * The general rule is that we *do* allow "Respond via SMS" except for
873 * the few (relatively rare) cases where we know for sure it won't
874 * work, namely:
875 * - a bogus or blank incoming number
876 * - a call from a SIP address
877 * - a "call presentation" that doesn't allow the number to be revealed
878 *
879 * In all other cases, we allow the user to respond via SMS.
880 *
881 * Note that this behavior isn't perfect; for example we have no way
882 * to detect whether the incoming call is from a landline (with most
883 * networks at least), so we still enable this feature even though
884 * SMSes to that number will silently fail.
885 */
886 boolean isRespondViaSmsCapable() {
887 if (mState != CallState.RINGING) {
888 return false;
889 }
890
891 if (getHandle() == null) {
892 // No incoming number known or call presentation is "PRESENTATION_RESTRICTED", in
893 // other words, the user should not be able to see the incoming phone number.
894 return false;
895 }
896
897 if (PhoneNumberUtils.isUriNumber(getHandle().toString())) {
898 // The incoming number is actually a URI (i.e. a SIP address),
899 // not a regular PSTN phone number, and we can't send SMSes to
900 // SIP addresses.
901 // (TODO: That might still be possible eventually, though. Is
902 // there some SIP-specific equivalent to sending a text message?)
903 return false;
904 }
905
906 // Is there a valid SMS application on the phone?
907 if (SmsApplication.getDefaultRespondViaMessageApplication(TelecommApp.getInstance(),
908 true /*updateIfNeeded*/) == null) {
909 return false;
910 }
911
912 // TODO: with some carriers (in certain countries) you *can* actually
913 // tell whether a given number is a mobile phone or not. So in that
914 // case we could potentially return false here if the incoming call is
915 // from a land line.
916
917 // If none of the above special cases apply, it's OK to enable the
918 // "Respond via SMS" feature.
919 return true;
920 }
921
922 List<String> getCannedSmsResponses() {
923 return mCannedSmsResponses;
924 }
925
926 /**
Santos Cordon61d0f702014-02-19 02:52:23 -0800927 * @return True if the call is ringing, else logs the action name.
928 */
929 private boolean isRinging(String actionName) {
930 if (mState == CallState.RINGING) {
931 return true;
932 }
933
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800934 Log.i(this, "Request to %s a non-ringing call %s", actionName, this);
Santos Cordon61d0f702014-02-19 02:52:23 -0800935 return false;
936 }
937
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800938 @SuppressWarnings("rawtypes")
939 private void decrementAssociatedCallCount(ServiceBinder binder) {
940 if (binder != null) {
941 binder.decrementAssociatedCallCount();
942 }
943 }
Santos Cordonfd71f4a2014-05-28 13:59:49 -0700944
945 /**
946 * Looks up contact information based on the current handle.
947 */
948 private void startCallerInfoLookup() {
949 String number = mHandle == null ? null : mHandle.getSchemeSpecificPart();
950
951 mQueryToken++; // Updated so that previous queries can no longer set the information.
952 mCallerInfo = null;
953 if (!TextUtils.isEmpty(number)) {
Santos Cordon5ba7f272014-05-28 13:59:49 -0700954 Log.v(this, "Looking up information for: %s.", Log.piiHandle(number));
Santos Cordonfd71f4a2014-05-28 13:59:49 -0700955 CallerInfoAsyncQuery.startQuery(
956 mQueryToken,
957 TelecommApp.getInstance(),
958 number,
959 sCallerInfoQueryListener,
960 this);
961 }
962 }
963
964 /**
Santos Cordon99c8a6f2014-05-28 18:28:47 -0700965 * Saves the specified caller info if the specified token matches that of the last query
Santos Cordonfd71f4a2014-05-28 13:59:49 -0700966 * that was made.
967 *
968 * @param callerInfo The new caller information to set.
969 * @param token The token used with this query.
970 */
971 private void setCallerInfo(CallerInfo callerInfo, int token) {
Santos Cordon99c8a6f2014-05-28 18:28:47 -0700972 Preconditions.checkNotNull(callerInfo);
973
Santos Cordonfd71f4a2014-05-28 13:59:49 -0700974 if (mQueryToken == token) {
975 mCallerInfo = callerInfo;
Santos Cordon5ba7f272014-05-28 13:59:49 -0700976 Log.i(this, "CallerInfo received for %s: %s", Log.piiHandle(mHandle), callerInfo);
Santos Cordon99c8a6f2014-05-28 18:28:47 -0700977
978 if (mCallerInfo.person_id != 0) {
979 Uri personUri =
980 ContentUris.withAppendedId(Contacts.CONTENT_URI, mCallerInfo.person_id);
981 Log.d(this, "Searching person uri %s for call %s", personUri, this);
982 ContactsAsyncHelper.startObtainPhotoAsync(
983 token,
984 TelecommApp.getInstance(),
985 personUri,
986 sPhotoLoadListener,
987 this);
988 }
Santos Cordon2174fb52014-05-29 08:22:56 -0700989
990 processDirectToVoicemail();
Santos Cordon99c8a6f2014-05-28 18:28:47 -0700991 }
992 }
993
994 /**
995 * Saves the specified photo information if the specified token matches that of the last query.
996 *
997 * @param photo The photo as a drawable.
998 * @param photoIcon The photo as a small icon.
999 * @param token The token used with this query.
1000 */
1001 private void setPhoto(Drawable photo, Bitmap photoIcon, int token) {
1002 if (mQueryToken == token) {
1003 mCallerInfo.cachedPhoto = photo;
1004 mCallerInfo.cachedPhotoIcon = photoIcon;
Santos Cordonfd71f4a2014-05-28 13:59:49 -07001005 }
1006 }
Ihab Awadff7493a2014-06-10 13:47:44 -07001007
1008 private void maybeLoadCannedSmsResponses() {
1009 if (mIsIncoming && isRespondViaSmsCapable() && !mCannedSmsResponsesLoadingStarted) {
1010 Log.d(this, "maybeLoadCannedSmsResponses: starting task to load messages");
1011 mCannedSmsResponsesLoadingStarted = true;
1012 RespondViaSmsManager.getInstance().loadCannedTextMessages(
1013 new Response<Void, List<String>>() {
1014 @Override
1015 public void onResult(Void request, List<String>... result) {
1016 if (result.length > 0) {
1017 Log.d(this, "maybeLoadCannedSmsResponses: got %s", result[0]);
1018 mCannedSmsResponses = result[0];
1019 for (Listener l : mListeners) {
1020 l.onCannedSmsResponsesLoaded(Call.this);
1021 }
1022 }
1023 }
1024
1025 @Override
1026 public void onError(Void request, int code, String msg) {
1027 Log.w(Call.this, "Error obtaining canned SMS responses: %d %s", code,
1028 msg);
1029 }
1030 }
1031 );
1032 } else {
1033 Log.d(this, "maybeLoadCannedSmsResponses: doing nothing");
1034 }
1035 }
Sai Cheemalapatib7157e92014-06-11 17:51:55 -07001036
1037 /**
1038 * Sets speakerphone option on when call begins.
1039 */
1040 public void setStartWithSpeakerphoneOn(boolean startWithSpeakerphone) {
1041 mSpeakerphoneOn = startWithSpeakerphone;
1042 }
1043
1044 /**
1045 * Returns speakerphone option.
1046 *
1047 * @return Whether or not speakerphone should be set automatically when call begins.
1048 */
1049 public boolean getStartWithSpeakerphoneOn() {
1050 return mSpeakerphoneOn;
1051 }
Andrew Leee9a77652014-06-26 13:07:57 -07001052
1053 /**
1054 * Sets a call video provider for the call.
1055 */
1056 public void setCallVideoProvider() {
1057 //TODO: Implement this method. For now, it's just an empty stub.
1058 }
Ben Gilad9f2bed32013-12-12 17:43:26 -08001059}