blob: 49e72b2c51aefa3ee52f81b1acc5c507f42e7dd6 [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;
Sailesh Nepal84fa5f82014-04-02 11:01:11 -070026import android.telecomm.CallServiceDescriptor;
Santos Cordon0b03b4b2014-01-29 18:01:59 -080027import android.telecomm.CallState;
Sailesh Nepalc92c4362014-07-04 18:33:21 -070028import android.telecomm.ConnectionRequest;
Yorke Lee33501632014-03-17 19:24:12 -070029import android.telecomm.GatewayInfo;
Ihab Awad98a55602014-06-30 21:27:28 -070030import android.telecomm.PhoneAccount;
Ihab Awadff7493a2014-06-10 13:47:44 -070031import android.telecomm.Response;
Sailesh Nepal35faf8c2014-07-08 22:02:34 -070032import android.telecomm.StatusHints;
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
Nancy Chena65d41f2014-06-24 12:06:03 -070038import com.android.internal.telecomm.ICallVideoProvider;
Santos Cordonfd71f4a2014-05-28 13:59:49 -070039import com.android.internal.telephony.CallerInfo;
40import com.android.internal.telephony.CallerInfoAsyncQuery;
41import com.android.internal.telephony.CallerInfoAsyncQuery.OnQueryCompleteListener;
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 * Listener for events on the call.
61 */
62 interface Listener {
63 void onSuccessfulOutgoingCall(Call call);
Sailesh Nepal5a73b032014-06-25 15:53:21 -070064 void onFailedOutgoingCall(Call call, int errorCode, String errorMsg);
65 void onCancelledOutgoingCall(Call call);
Sailesh Nepalc92c4362014-07-04 18:33:21 -070066 void onSuccessfulIncomingCall(Call call);
Santos Cordon766d04f2014-05-06 10:28:25 -070067 void onFailedIncomingCall(Call call);
Ihab Awadcb387ac2014-05-28 16:49:38 -070068 void onRequestingRingback(Call call, boolean requestingRingback);
Evan Charlton352105c2014-06-03 14:10:54 -070069 void onPostDialWait(Call call, String remaining);
Santos Cordona1610702014-06-04 20:22:56 -070070 void onIsConferenceCapableChanged(Call call, boolean isConferenceCapable);
71 void onExpiredConferenceCall(Call call);
72 void onConfirmedConferenceCall(Call call);
73 void onParentChanged(Call call);
74 void onChildrenChanged(Call call);
Ihab Awadff7493a2014-06-10 13:47:44 -070075 void onCannedSmsResponsesLoaded(Call call);
Nancy Chena65d41f2014-06-24 12:06:03 -070076 void onCallVideoProviderChanged(Call call);
Tyler Gunne19cc002014-07-01 11:32:53 -070077 void onFeaturesChanged(Call call);
Santos Cordon64c7e962014-07-02 15:15:27 -070078 void onCallerInfoChanged(Call call);
Sailesh Nepal7e669572014-07-08 21:29:12 -070079 void onAudioModeIsVoipChanged(Call call);
Sailesh Nepal35faf8c2014-07-08 22:02:34 -070080 void onStatusHintsChanged(Call call);
Santos Cordon64c7e962014-07-02 15:15:27 -070081 }
82
83 abstract static class ListenerBase implements Listener {
84 @Override
85 public void onSuccessfulOutgoingCall(Call call) {}
86 @Override
87 public void onFailedOutgoingCall(Call call, int errorCode, String errorMsg) {}
88 @Override
89 public void onCancelledOutgoingCall(Call call) {}
90 @Override
Sailesh Nepalc92c4362014-07-04 18:33:21 -070091 public void onSuccessfulIncomingCall(Call call) {}
Santos Cordon64c7e962014-07-02 15:15:27 -070092 @Override
93 public void onFailedIncomingCall(Call call) {}
94 @Override
95 public void onRequestingRingback(Call call, boolean requestingRingback) {}
96 @Override
97 public void onPostDialWait(Call call, String remaining) {}
98 @Override
99 public void onIsConferenceCapableChanged(Call call, boolean isConferenceCapable) {}
100 @Override
101 public void onExpiredConferenceCall(Call call) {}
102 @Override
103 public void onConfirmedConferenceCall(Call call) {}
104 @Override
105 public void onParentChanged(Call call) {}
106 @Override
107 public void onChildrenChanged(Call call) {}
108 @Override
109 public void onCannedSmsResponsesLoaded(Call call) {}
110 @Override
111 public void onCallVideoProviderChanged(Call call) {}
112 @Override
113 public void onFeaturesChanged(Call call) {}
114 @Override
115 public void onCallerInfoChanged(Call call) {}
Sailesh Nepal7e669572014-07-08 21:29:12 -0700116 @Override
117 public void onAudioModeIsVoipChanged(Call call) {}
Sailesh Nepal35faf8c2014-07-08 22:02:34 -0700118 @Override
119 public void onStatusHintsChanged(Call call) {}
Santos Cordon766d04f2014-05-06 10:28:25 -0700120 }
121
Santos Cordonfd71f4a2014-05-28 13:59:49 -0700122 private static final OnQueryCompleteListener sCallerInfoQueryListener =
Santos Cordon99c8a6f2014-05-28 18:28:47 -0700123 new OnQueryCompleteListener() {
124 /** ${inheritDoc} */
125 @Override
126 public void onQueryComplete(int token, Object cookie, CallerInfo callerInfo) {
127 if (cookie != null) {
128 ((Call) cookie).setCallerInfo(callerInfo, token);
129 }
Santos Cordonfd71f4a2014-05-28 13:59:49 -0700130 }
Santos Cordon99c8a6f2014-05-28 18:28:47 -0700131 };
132
133 private static final OnImageLoadCompleteListener sPhotoLoadListener =
134 new OnImageLoadCompleteListener() {
135 /** ${inheritDoc} */
136 @Override
137 public void onImageLoadComplete(
138 int token, Drawable photo, Bitmap photoIcon, Object cookie) {
139 if (cookie != null) {
140 ((Call) cookie).setPhoto(photo, photoIcon, token);
141 }
142 }
143 };
Ben Gilad0407fb22014-01-09 16:18:41 -0800144
Sailesh Nepal810735e2014-03-18 18:15:46 -0700145 /** True if this is an incoming call. */
146 private final boolean mIsIncoming;
147
Ben Gilad0407fb22014-01-09 16:18:41 -0800148 /**
149 * The time this call was created, typically also the time this call was added to the set
150 * of pending outgoing calls (mPendingOutgoingCalls) that's maintained by the switchboard.
151 * Beyond logging and such, may also be used for bookkeeping and specifically for marking
152 * certain call attempts as failed attempts.
153 */
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700154 private final long mCreationTimeMillis = System.currentTimeMillis();
155
Santos Cordonfd71f4a2014-05-28 13:59:49 -0700156 /** The gateway information associated with this call. This stores the original call handle
157 * that the user is attempting to connect to via the gateway, the actual handle to dial in
158 * order to connect the call via the gateway, as well as the package name of the gateway
159 * service. */
160 private final GatewayInfo mGatewayInfo;
161
Ihab Awad98a55602014-06-30 21:27:28 -0700162 private final PhoneAccount mAccount;
Nancy Chen77d2d0e2014-06-24 12:06:03 -0700163
Santos Cordon2174fb52014-05-29 08:22:56 -0700164 private final Handler mHandler = new Handler();
165
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700166 private long mConnectTimeMillis;
Ben Gilad0407fb22014-01-09 16:18:41 -0800167
Santos Cordon61d0f702014-02-19 02:52:23 -0800168 /** The state of the call. */
169 private CallState mState;
170
171 /** The handle with which to establish this call. */
Sailesh Nepalce704b92014-03-17 18:31:43 -0700172 private Uri mHandle;
Santos Cordon61d0f702014-02-19 02:52:23 -0800173
Ben Gilad0407fb22014-01-09 16:18:41 -0800174 /**
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700175 * The connection service which is attempted or already connecting this call.
Santos Cordon681663d2014-01-30 04:32:15 -0800176 */
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700177 private ConnectionServiceWrapper mConnectionService;
Ben Gilad61925612014-03-11 19:06:36 -0700178
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700179 private boolean mIsEmergencyCall;
180
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700181 private boolean mSpeakerphoneOn;
182
Tyler Gunnc4abd912014-07-08 14:22:10 -0700183 private int mVideoState;
184
Ben Gilad61925612014-03-11 19:06:36 -0700185 /**
Santos Cordon79ff2bc2014-03-27 15:31:27 -0700186 * Disconnect cause for the call. Only valid if the state of the call is DISCONNECTED.
187 * See {@link android.telephony.DisconnectCause}.
188 */
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700189 private int mDisconnectCause = DisconnectCause.NOT_VALID;
Santos Cordon79ff2bc2014-03-27 15:31:27 -0700190
191 /**
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700192 * Additional disconnect information provided by the connection service.
Santos Cordon79ff2bc2014-03-27 15:31:27 -0700193 */
194 private String mDisconnectMessage;
195
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700196 /** Info used by the connection services. */
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700197 private Bundle mExtras = Bundle.EMPTY;
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700198
Santos Cordon766d04f2014-05-06 10:28:25 -0700199 /** Set of listeners on this call. */
200 private Set<Listener> mListeners = Sets.newHashSet();
201
Santos Cordon682fe6b2014-05-20 08:56:39 -0700202 private OutgoingCallProcessor mOutgoingCallProcessor;
203
204 // TODO(santoscordon): The repositories should be changed into singleton types.
205 private CallServiceRepository mCallServiceRepository;
Santos Cordon682fe6b2014-05-20 08:56:39 -0700206
Santos Cordonfd71f4a2014-05-28 13:59:49 -0700207 /** Caller information retrieved from the latest contact query. */
208 private CallerInfo mCallerInfo;
209
210 /** The latest token used with a contact info query. */
211 private int mQueryToken = 0;
212
Ihab Awadcb387ac2014-05-28 16:49:38 -0700213 /** Whether this call is requesting that Telecomm play the ringback tone on its behalf. */
214 private boolean mRequestingRingback = false;
215
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700216 /** Whether direct-to-voicemail query is pending. */
217 private boolean mDirectToVoicemailQueryPending;
Santos Cordon2174fb52014-05-29 08:22:56 -0700218
Santos Cordona1610702014-06-04 20:22:56 -0700219 private boolean mIsConferenceCapable = false;
220
221 private boolean mIsConference = false;
222
223 private Call mParentCall = null;
224
225 private List<Call> mChildCalls = new LinkedList<>();
226
Ihab Awadff7493a2014-06-10 13:47:44 -0700227 /** Set of text message responses allowed for this call, if applicable. */
228 private List<String> mCannedSmsResponses = Collections.EMPTY_LIST;
229
230 /** Whether an attempt has been made to load the text message responses. */
231 private boolean mCannedSmsResponsesLoadingStarted = false;
232
Nancy Chena65d41f2014-06-24 12:06:03 -0700233 private ICallVideoProvider mCallVideoProvider;
234
Tyler Gunne19cc002014-07-01 11:32:53 -0700235 /** Features associated with the call which the InCall UI may wish to show icons for. */
236 private int mFeatures;
237
Sailesh Nepal7e669572014-07-08 21:29:12 -0700238 private boolean mAudioModeIsVoip;
Sailesh Nepal35faf8c2014-07-08 22:02:34 -0700239 private StatusHints mStatusHints;
Sailesh Nepal7e669572014-07-08 21:29:12 -0700240
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700241 /**
Sailesh Nepale59bb192014-04-01 18:33:59 -0700242 * Creates an empty call object.
Sailesh Nepal810735e2014-03-18 18:15:46 -0700243 *
244 * @param isIncoming True if this is an incoming call.
Santos Cordon493e8f22014-02-19 03:15:12 -0800245 */
Santos Cordona1610702014-06-04 20:22:56 -0700246 Call(boolean isIncoming, boolean isConference) {
Nancy Chen77d2d0e2014-06-24 12:06:03 -0700247 this(null, null, null, isIncoming, isConference);
Santos Cordon493e8f22014-02-19 03:15:12 -0800248 }
249
250 /**
Ben Gilad0407fb22014-01-09 16:18:41 -0800251 * Persists the specified parameters and initializes the new instance.
252 *
253 * @param handle The handle to dial.
Yorke Lee33501632014-03-17 19:24:12 -0700254 * @param gatewayInfo Gateway information to use for the call.
Ihab Awad98a55602014-06-30 21:27:28 -0700255 * @param account Account information to use for the call.
Sailesh Nepal810735e2014-03-18 18:15:46 -0700256 * @param isIncoming True if this is an incoming call.
Ben Gilad0407fb22014-01-09 16:18:41 -0800257 */
Ihab Awad98a55602014-06-30 21:27:28 -0700258 Call(Uri handle, GatewayInfo gatewayInfo, PhoneAccount account,
Nancy Chen77d2d0e2014-06-24 12:06:03 -0700259 boolean isIncoming, boolean isConference) {
Santos Cordona1610702014-06-04 20:22:56 -0700260 mState = isConference ? CallState.ACTIVE : CallState.NEW;
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700261 setHandle(handle);
Yorke Lee33501632014-03-17 19:24:12 -0700262 mGatewayInfo = gatewayInfo;
Ihab Awad98a55602014-06-30 21:27:28 -0700263 mAccount = account;
Sailesh Nepal810735e2014-03-18 18:15:46 -0700264 mIsIncoming = isIncoming;
Santos Cordona1610702014-06-04 20:22:56 -0700265 mIsConference = isConference;
Ihab Awadff7493a2014-06-10 13:47:44 -0700266 maybeLoadCannedSmsResponses();
Ben Gilad0407fb22014-01-09 16:18:41 -0800267 }
268
Santos Cordon766d04f2014-05-06 10:28:25 -0700269 void addListener(Listener listener) {
270 mListeners.add(listener);
271 }
272
273 void removeListener(Listener listener) {
274 mListeners.remove(listener);
275 }
276
Santos Cordon61d0f702014-02-19 02:52:23 -0800277 /** {@inheritDoc} */
278 @Override public String toString() {
Sailesh Nepal4538f012014-04-15 11:40:33 -0700279 String component = null;
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700280 if (mConnectionService != null && mConnectionService.getComponentName() != null) {
281 component = mConnectionService.getComponentName().flattenToShortString();
Sailesh Nepal4538f012014-04-15 11:40:33 -0700282 }
283 return String.format(Locale.US, "[%s, %s, %s]", mState, component, Log.piiHandle(mHandle));
Santos Cordon61d0f702014-02-19 02:52:23 -0800284 }
285
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800286 CallState getState() {
Santos Cordona1610702014-06-04 20:22:56 -0700287 if (mIsConference) {
288 if (!mChildCalls.isEmpty()) {
289 // If we have child calls, just return the child call.
290 return mChildCalls.get(0).getState();
291 }
292 return CallState.ACTIVE;
293 } else {
294 return mState;
295 }
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800296 }
297
298 /**
299 * Sets the call state. Although there exists the notion of appropriate state transitions
300 * (see {@link CallState}), in practice those expectations break down when cellular systems
301 * misbehave and they do this very often. The result is that we do not enforce state transitions
302 * and instead keep the code resilient to unexpected state changes.
303 */
Sailesh Nepal810735e2014-03-18 18:15:46 -0700304 void setState(CallState newState) {
Santos Cordon79ff2bc2014-03-27 15:31:27 -0700305 Preconditions.checkState(newState != CallState.DISCONNECTED ||
306 mDisconnectCause != DisconnectCause.NOT_VALID);
Sailesh Nepal810735e2014-03-18 18:15:46 -0700307 if (mState != newState) {
308 Log.v(this, "setState %s -> %s", mState, newState);
309 mState = newState;
Ihab Awadff7493a2014-06-10 13:47:44 -0700310 maybeLoadCannedSmsResponses();
Sailesh Nepal810735e2014-03-18 18:15:46 -0700311 }
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800312 }
313
Ihab Awadcb387ac2014-05-28 16:49:38 -0700314 void setRequestingRingback(boolean requestingRingback) {
315 mRequestingRingback = requestingRingback;
316 for (Listener l : mListeners) {
317 l.onRequestingRingback(this, mRequestingRingback);
318 }
319 }
320
321 boolean isRequestingRingback() {
322 return mRequestingRingback;
323 }
324
Sailesh Nepalce704b92014-03-17 18:31:43 -0700325 Uri getHandle() {
Ben Gilad0bf5b912014-01-28 17:55:57 -0800326 return mHandle;
327 }
328
Sailesh Nepalce704b92014-03-17 18:31:43 -0700329 void setHandle(Uri handle) {
Santos Cordonfd71f4a2014-05-28 13:59:49 -0700330 if ((mHandle == null && handle != null) || (mHandle != null && !mHandle.equals(handle))) {
331 mHandle = handle;
332 mIsEmergencyCall = mHandle != null && PhoneNumberUtils.isLocalEmergencyNumber(
Yorke Lee66255452014-06-05 08:09:24 -0700333 TelecommApp.getInstance(), mHandle.getSchemeSpecificPart());
Santos Cordonfd71f4a2014-05-28 13:59:49 -0700334 startCallerInfoLookup();
335 }
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700336 }
337
Santos Cordon99c8a6f2014-05-28 18:28:47 -0700338 String getName() {
339 return mCallerInfo == null ? null : mCallerInfo.name;
340 }
341
342 Bitmap getPhotoIcon() {
343 return mCallerInfo == null ? null : mCallerInfo.cachedPhotoIcon;
344 }
345
346 Drawable getPhoto() {
347 return mCallerInfo == null ? null : mCallerInfo.cachedPhoto;
348 }
349
Santos Cordon79ff2bc2014-03-27 15:31:27 -0700350 /**
351 * @param disconnectCause The reason for the disconnection, any of
352 * {@link android.telephony.DisconnectCause}.
353 * @param disconnectMessage Optional call-service-provided message about the disconnect.
354 */
355 void setDisconnectCause(int disconnectCause, String disconnectMessage) {
356 // TODO: Consider combining this method with a setDisconnected() method that is totally
357 // separate from setState.
358 mDisconnectCause = disconnectCause;
359 mDisconnectMessage = disconnectMessage;
360 }
361
362 int getDisconnectCause() {
363 return mDisconnectCause;
364 }
365
366 String getDisconnectMessage() {
367 return mDisconnectMessage;
368 }
369
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700370 boolean isEmergencyCall() {
371 return mIsEmergencyCall;
Santos Cordon61d0f702014-02-19 02:52:23 -0800372 }
373
Yorke Lee33501632014-03-17 19:24:12 -0700374 /**
375 * @return The original handle this call is associated with. In-call services should use this
376 * handle when indicating in their UI the handle that is being called.
377 */
378 public Uri getOriginalHandle() {
379 if (mGatewayInfo != null && !mGatewayInfo.isEmpty()) {
380 return mGatewayInfo.getOriginalHandle();
381 }
382 return getHandle();
383 }
384
385 GatewayInfo getGatewayInfo() {
386 return mGatewayInfo;
387 }
388
Ihab Awad98a55602014-06-30 21:27:28 -0700389 PhoneAccount getAccount() {
390 return mAccount;
Nancy Chen77d2d0e2014-06-24 12:06:03 -0700391 }
392
Sailesh Nepal810735e2014-03-18 18:15:46 -0700393 boolean isIncoming() {
394 return mIsIncoming;
395 }
396
Ben Gilad0407fb22014-01-09 16:18:41 -0800397 /**
398 * @return The "age" of this call object in milliseconds, which typically also represents the
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700399 * period since this call was added to the set pending outgoing calls, see
400 * mCreationTimeMillis.
Ben Gilad0407fb22014-01-09 16:18:41 -0800401 */
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700402 long getAgeMillis() {
403 return System.currentTimeMillis() - mCreationTimeMillis;
Ben Gilad0407fb22014-01-09 16:18:41 -0800404 }
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800405
Yorke Leef98fb572014-03-05 10:56:55 -0800406 /**
407 * @return The time when this call object was created and added to the set of pending outgoing
408 * calls.
409 */
Sailesh Nepal8c85dee2014-04-07 22:21:40 -0700410 long getCreationTimeMillis() {
411 return mCreationTimeMillis;
412 }
413
414 long getConnectTimeMillis() {
415 return mConnectTimeMillis;
416 }
417
418 void setConnectTimeMillis(long connectTimeMillis) {
419 mConnectTimeMillis = connectTimeMillis;
Yorke Leef98fb572014-03-05 10:56:55 -0800420 }
421
Santos Cordona1610702014-06-04 20:22:56 -0700422 boolean isConferenceCapable() {
423 return mIsConferenceCapable;
424 }
425
426 void setIsConferenceCapable(boolean isConferenceCapable) {
427 if (mIsConferenceCapable != isConferenceCapable) {
428 mIsConferenceCapable = isConferenceCapable;
429 for (Listener l : mListeners) {
430 l.onIsConferenceCapableChanged(this, mIsConferenceCapable);
431 }
432 }
433 }
434
435 Call getParentCall() {
436 return mParentCall;
437 }
438
439 List<Call> getChildCalls() {
440 return mChildCalls;
441 }
442
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700443 ConnectionServiceWrapper getConnectionService() {
444 return mConnectionService;
Santos Cordon681663d2014-01-30 04:32:15 -0800445 }
446
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700447 void setConnectionService(ConnectionServiceWrapper service) {
448 Preconditions.checkNotNull(service);
449
450 clearConnectionService();
451
452 service.incrementAssociatedCallCount();
453 mConnectionService = service;
454 mConnectionService.addCall(this);
Sailesh Nepal0e5410a2014-04-04 01:20:58 -0700455 }
456
457 /**
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700458 * Clears the associated connection service.
Sailesh Nepal0e5410a2014-04-04 01:20:58 -0700459 */
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700460 void clearConnectionService() {
461 if (mConnectionService != null) {
462 ConnectionServiceWrapper serviceTemp = mConnectionService;
463 mConnectionService = null;
464 serviceTemp.removeCall(this);
Santos Cordonc499c1c2014-04-14 17:13:14 -0700465
466 // Decrementing the count can cause the service to unbind, which itself can trigger the
467 // service-death code. Since the service death code tries to clean up any associated
468 // calls, we need to make sure to remove that information (e.g., removeCall()) before
469 // we decrement. Technically, invoking removeCall() prior to decrementing is all that is
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700470 // necessary, but cleaning up mConnectionService prior to triggering an unbind is good
471 // to do.
472 decrementAssociatedCallCount(serviceTemp);
Yorke Leeadee12d2014-03-13 12:08:30 -0700473 }
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800474 }
475
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800476 /**
Santos Cordon766d04f2014-05-06 10:28:25 -0700477 * Starts the incoming call flow through the switchboard. When switchboard completes, it will
478 * invoke handle[Un]SuccessfulIncomingCall.
479 *
480 * @param descriptor The relevant call-service descriptor.
481 * @param extras The optional extras passed via
482 * {@link TelecommConstants#EXTRA_INCOMING_CALL_EXTRAS}.
483 */
484 void startIncoming(CallServiceDescriptor descriptor, Bundle extras) {
485 Switchboard.getInstance().retrieveIncomingCall(this, descriptor, extras);
486 }
487
Santos Cordon2174fb52014-05-29 08:22:56 -0700488 /**
489 * Takes a verified incoming call and uses the handle to lookup direct-to-voicemail property
490 * from the contacts provider. The call is not yet exposed to the user at this point and
491 * the result of the query will determine if the call is rejected or passed through to the
492 * in-call UI.
493 */
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700494 void handleVerifiedIncoming(ConnectionRequest request) {
495 // We do not handle incoming calls immediately when they are verified by the connection
496 // service. We allow the caller-info-query code to execute first so that we can read the
Santos Cordon2174fb52014-05-29 08:22:56 -0700497 // direct-to-voicemail property before deciding if we want to show the incoming call to the
498 // user or if we want to reject the call.
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700499 mDirectToVoicemailQueryPending = true;
Santos Cordon2174fb52014-05-29 08:22:56 -0700500
501 // Setting the handle triggers the caller info lookup code.
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700502 setHandle(request.getHandle());
Santos Cordon766d04f2014-05-06 10:28:25 -0700503
Santos Cordon2174fb52014-05-29 08:22:56 -0700504 // Timeout the direct-to-voicemail lookup execution so that we dont wait too long before
505 // showing the user the incoming call screen.
506 mHandler.postDelayed(new Runnable() {
507 @Override
508 public void run() {
509 processDirectToVoicemail();
510 }
Santos Cordona1610702014-06-04 20:22:56 -0700511 }, Timeouts.getDirectToVoicemailMillis());
Santos Cordon2174fb52014-05-29 08:22:56 -0700512 }
Santos Cordon766d04f2014-05-06 10:28:25 -0700513
Santos Cordon2174fb52014-05-29 08:22:56 -0700514 void processDirectToVoicemail() {
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700515 if (mDirectToVoicemailQueryPending) {
Santos Cordon2174fb52014-05-29 08:22:56 -0700516 if (mCallerInfo != null && mCallerInfo.shouldSendToVoicemail) {
517 Log.i(this, "Directing call to voicemail: %s.", this);
518 // TODO(santoscordon): Once we move State handling from CallsManager to Call, we
519 // will not need to set RINGING state prior to calling reject.
520 setState(CallState.RINGING);
Ihab Awadff7493a2014-06-10 13:47:44 -0700521 reject(false, null);
Santos Cordon2174fb52014-05-29 08:22:56 -0700522 } else {
523 // TODO(santoscordon): Make this class (not CallsManager) responsible for changing
524 // the call state to RINGING.
525
526 // TODO(santoscordon): Replace this with state transition to RINGING.
527 for (Listener l : mListeners) {
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700528 l.onSuccessfulIncomingCall(this);
Santos Cordon2174fb52014-05-29 08:22:56 -0700529 }
530 }
531
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700532 mDirectToVoicemailQueryPending = false;
Santos Cordon766d04f2014-05-06 10:28:25 -0700533 }
534 }
535
536 void handleFailedIncoming() {
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700537 clearConnectionService();
Santos Cordon766d04f2014-05-06 10:28:25 -0700538
539 // TODO: Needs more specific disconnect error for this case.
540 setDisconnectCause(DisconnectCause.ERROR_UNSPECIFIED, null);
541 setState(CallState.DISCONNECTED);
542
543 // TODO(santoscordon): Replace this with state transitions related to "connecting".
544 for (Listener l : mListeners) {
545 l.onFailedIncomingCall(this);
546 }
547 }
548
549 /**
Santos Cordon682fe6b2014-05-20 08:56:39 -0700550 * Starts the outgoing call sequence. Upon completion, there should exist an active connection
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700551 * through a connection service (or the call will have failed).
Santos Cordon766d04f2014-05-06 10:28:25 -0700552 */
553 void startOutgoing() {
Santos Cordon682fe6b2014-05-20 08:56:39 -0700554 Preconditions.checkState(mOutgoingCallProcessor == null);
555
556 mOutgoingCallProcessor = new OutgoingCallProcessor(
Sailesh Nepal5a73b032014-06-25 15:53:21 -0700557 this, Switchboard.getInstance().getCallServiceRepository(), this);
Santos Cordon682fe6b2014-05-20 08:56:39 -0700558 mOutgoingCallProcessor.process();
Santos Cordon766d04f2014-05-06 10:28:25 -0700559 }
560
Sailesh Nepal5a73b032014-06-25 15:53:21 -0700561 @Override
562 public void onOutgoingCallSuccess() {
Santos Cordon766d04f2014-05-06 10:28:25 -0700563 // TODO(santoscordon): Replace this with state transitions related to "connecting".
564 for (Listener l : mListeners) {
565 l.onSuccessfulOutgoingCall(this);
566 }
Sailesh Nepal5a73b032014-06-25 15:53:21 -0700567 mOutgoingCallProcessor = null;
Santos Cordon766d04f2014-05-06 10:28:25 -0700568 }
569
Sailesh Nepal5a73b032014-06-25 15:53:21 -0700570 @Override
571 public void onOutgoingCallFailure(int code, String msg) {
Santos Cordon766d04f2014-05-06 10:28:25 -0700572 // TODO(santoscordon): Replace this with state transitions related to "connecting".
573 for (Listener l : mListeners) {
Sailesh Nepal5a73b032014-06-25 15:53:21 -0700574 l.onFailedOutgoingCall(this, code, msg);
Santos Cordon766d04f2014-05-06 10:28:25 -0700575 }
Santos Cordon682fe6b2014-05-20 08:56:39 -0700576
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700577 clearConnectionService();
Sailesh Nepal5a73b032014-06-25 15:53:21 -0700578 mOutgoingCallProcessor = null;
579 }
580
581 @Override
582 public void onOutgoingCallCancel() {
583 // TODO(santoscordon): Replace this with state transitions related to "connecting".
584 for (Listener l : mListeners) {
585 l.onCancelledOutgoingCall(this);
586 }
587
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700588 clearConnectionService();
Sailesh Nepal5a73b032014-06-25 15:53:21 -0700589 mOutgoingCallProcessor = null;
Santos Cordon766d04f2014-05-06 10:28:25 -0700590 }
591
592 /**
Ihab Awad74549ec2014-03-10 15:33:25 -0700593 * Plays the specified DTMF tone.
594 */
595 void playDtmfTone(char digit) {
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700596 if (mConnectionService == null) {
597 Log.w(this, "playDtmfTone() request on a call without a connection service.");
Ihab Awad74549ec2014-03-10 15:33:25 -0700598 } else {
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700599 Log.i(this, "Send playDtmfTone to connection service for call %s", this);
600 mConnectionService.playDtmfTone(this, digit);
Ihab Awad74549ec2014-03-10 15:33:25 -0700601 }
602 }
603
604 /**
605 * Stops playing any currently playing DTMF tone.
606 */
607 void stopDtmfTone() {
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700608 if (mConnectionService == null) {
609 Log.w(this, "stopDtmfTone() request on a call without a connectino service.");
Ihab Awad74549ec2014-03-10 15:33:25 -0700610 } else {
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700611 Log.i(this, "Send stopDtmfTone to connection service for call %s", this);
612 mConnectionService.stopDtmfTone(this);
Ihab Awad74549ec2014-03-10 15:33:25 -0700613 }
614 }
615
616 /**
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700617 * Attempts to disconnect the call through the connection service.
Santos Cordon049b7b62014-01-30 05:34:26 -0800618 */
619 void disconnect() {
Santos Cordon766d04f2014-05-06 10:28:25 -0700620 if (mState == CallState.NEW) {
Santos Cordon682fe6b2014-05-20 08:56:39 -0700621 Log.v(this, "Aborting call %s", this);
622 abort();
Santos Cordon74d420b2014-05-07 14:38:47 -0700623 } else if (mState != CallState.ABORTED && mState != CallState.DISCONNECTED) {
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700624 Preconditions.checkNotNull(mConnectionService);
Santos Cordon766d04f2014-05-06 10:28:25 -0700625
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700626 Log.i(this, "Send disconnect to connection service for call: %s", this);
627 // The call isn't officially disconnected until the connection service confirms that the
628 // call was actually disconnected. Only then is the association between call and
629 // connection service severed, see {@link CallsManager#markCallAsDisconnected}.
630 mConnectionService.disconnect(this);
Santos Cordon049b7b62014-01-30 05:34:26 -0800631 }
632 }
633
Santos Cordon682fe6b2014-05-20 08:56:39 -0700634 void abort() {
635 if (mOutgoingCallProcessor != null) {
636 mOutgoingCallProcessor.abort();
637 }
638 }
639
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800640 /**
Santos Cordon61d0f702014-02-19 02:52:23 -0800641 * Answers the call if it is ringing.
642 */
643 void answer() {
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700644 Preconditions.checkNotNull(mConnectionService);
Santos Cordon61d0f702014-02-19 02:52:23 -0800645
646 // Check to verify that the call is still in the ringing state. A call can change states
647 // between the time the user hits 'answer' and Telecomm receives the command.
648 if (isRinging("answer")) {
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700649 // At this point, we are asking the connection service to answer but we don't assume
650 // that it will work. Instead, we wait until confirmation from the connectino service
651 // that the call is in a non-RINGING state before changing the UI. See
652 // {@link ConnectionServiceAdapter#setActive} and other set* methods.
653 mConnectionService.answer(this);
Santos Cordon61d0f702014-02-19 02:52:23 -0800654 }
655 }
656
657 /**
658 * Rejects the call if it is ringing.
Ihab Awadff7493a2014-06-10 13:47:44 -0700659 *
660 * @param rejectWithMessage Whether to send a text message as part of the call rejection.
661 * @param textMessage An optional text message to send as part of the rejection.
Santos Cordon61d0f702014-02-19 02:52:23 -0800662 */
Ihab Awadff7493a2014-06-10 13:47:44 -0700663 void reject(boolean rejectWithMessage, String textMessage) {
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700664 Preconditions.checkNotNull(mConnectionService);
Santos Cordon61d0f702014-02-19 02:52:23 -0800665
666 // Check to verify that the call is still in the ringing state. A call can change states
667 // between the time the user hits 'reject' and Telecomm receives the command.
668 if (isRinging("reject")) {
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700669 mConnectionService.reject(this);
Santos Cordon61d0f702014-02-19 02:52:23 -0800670 }
671 }
672
673 /**
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700674 * Puts the call on hold if it is currently active.
675 */
676 void hold() {
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700677 Preconditions.checkNotNull(mConnectionService);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700678
679 if (mState == CallState.ACTIVE) {
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700680 mConnectionService.hold(this);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700681 }
682 }
683
684 /**
685 * Releases the call from hold if it is currently active.
686 */
687 void unhold() {
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700688 Preconditions.checkNotNull(mConnectionService);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700689
690 if (mState == CallState.ON_HOLD) {
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700691 mConnectionService.unhold(this);
Yorke Leecdf3ebd2014-03-12 18:31:41 -0700692 }
693 }
694
Sailesh Nepal6aca10a2014-03-24 16:11:02 -0700695 /** Checks if this is a live call or not. */
696 boolean isAlive() {
697 switch (mState) {
698 case NEW:
699 case RINGING:
700 case DISCONNECTED:
701 case ABORTED:
702 return false;
703 default:
704 return true;
705 }
706 }
707
Santos Cordon40f78c22014-04-07 02:11:42 -0700708 boolean isActive() {
709 switch (mState) {
710 case ACTIVE:
711 case POST_DIAL:
712 case POST_DIAL_WAIT:
713 return true;
714 default:
715 return false;
716 }
717 }
718
Sailesh Nepal84fa5f82014-04-02 11:01:11 -0700719 Bundle getExtras() {
720 return mExtras;
721 }
722
723 void setExtras(Bundle extras) {
724 mExtras = extras;
725 }
726
Santos Cordon5ba7f272014-05-28 13:59:49 -0700727 Uri getRingtone() {
728 return mCallerInfo == null ? null : mCallerInfo.contactRingtoneUri;
729 }
730
Evan Charlton352105c2014-06-03 14:10:54 -0700731 void onPostDialWait(String remaining) {
732 for (Listener l : mListeners) {
733 l.onPostDialWait(this, remaining);
734 }
735 }
736
737 void postDialContinue(boolean proceed) {
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700738 mConnectionService.onPostDialContinue(this, proceed);
Evan Charlton352105c2014-06-03 14:10:54 -0700739 }
740
Sailesh Nepal77da19e2014-07-02 21:31:16 -0700741 void phoneAccountClicked() {
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700742 mConnectionService.onPhoneAccountClicked(this);
Sailesh Nepal77da19e2014-07-02 21:31:16 -0700743 }
744
Santos Cordona1610702014-06-04 20:22:56 -0700745 void conferenceInto(Call conferenceCall) {
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700746 if (mConnectionService == null) {
747 Log.w(this, "conference requested on a call without a connection service.");
Santos Cordona1610702014-06-04 20:22:56 -0700748 } else {
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700749 mConnectionService.conference(conferenceCall, this);
Santos Cordona1610702014-06-04 20:22:56 -0700750 }
751 }
752
753 void expireConference() {
754 // The conference call expired before we got a confirmation of the conference from the
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700755 // connection service...so start shutting down.
756 clearConnectionService();
Santos Cordona1610702014-06-04 20:22:56 -0700757 for (Listener l : mListeners) {
758 l.onExpiredConferenceCall(this);
759 }
760 }
761
762 void confirmConference() {
763 Log.v(this, "confirming Conf call %s", mListeners);
764 for (Listener l : mListeners) {
765 l.onConfirmedConferenceCall(this);
766 }
767 }
768
769 void splitFromConference() {
770 // TODO(santoscordon): todo
771 }
772
773 void setParentCall(Call parentCall) {
774 if (parentCall == this) {
775 Log.e(this, new Exception(), "setting the parent to self");
776 return;
777 }
778 Preconditions.checkState(parentCall == null || mParentCall == null);
779
780 Call oldParent = mParentCall;
781 if (mParentCall != null) {
782 mParentCall.removeChildCall(this);
783 }
784 mParentCall = parentCall;
785 if (mParentCall != null) {
786 mParentCall.addChildCall(this);
787 }
788
789 for (Listener l : mListeners) {
790 l.onParentChanged(this);
791 }
792 }
793
794 private void addChildCall(Call call) {
795 if (!mChildCalls.contains(call)) {
796 mChildCalls.add(call);
797
798 for (Listener l : mListeners) {
799 l.onChildrenChanged(this);
800 }
801 }
802 }
803
804 private void removeChildCall(Call call) {
805 if (mChildCalls.remove(call)) {
806 for (Listener l : mListeners) {
807 l.onChildrenChanged(this);
808 }
809 }
810 }
811
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800812 /**
Ihab Awadff7493a2014-06-10 13:47:44 -0700813 * Return whether the user can respond to this {@code Call} via an SMS message.
814 *
815 * @return true if the "Respond via SMS" feature should be enabled
816 * for this incoming call.
817 *
818 * The general rule is that we *do* allow "Respond via SMS" except for
819 * the few (relatively rare) cases where we know for sure it won't
820 * work, namely:
821 * - a bogus or blank incoming number
822 * - a call from a SIP address
823 * - a "call presentation" that doesn't allow the number to be revealed
824 *
825 * In all other cases, we allow the user to respond via SMS.
826 *
827 * Note that this behavior isn't perfect; for example we have no way
828 * to detect whether the incoming call is from a landline (with most
829 * networks at least), so we still enable this feature even though
830 * SMSes to that number will silently fail.
831 */
832 boolean isRespondViaSmsCapable() {
833 if (mState != CallState.RINGING) {
834 return false;
835 }
836
837 if (getHandle() == null) {
838 // No incoming number known or call presentation is "PRESENTATION_RESTRICTED", in
839 // other words, the user should not be able to see the incoming phone number.
840 return false;
841 }
842
843 if (PhoneNumberUtils.isUriNumber(getHandle().toString())) {
844 // The incoming number is actually a URI (i.e. a SIP address),
845 // not a regular PSTN phone number, and we can't send SMSes to
846 // SIP addresses.
847 // (TODO: That might still be possible eventually, though. Is
848 // there some SIP-specific equivalent to sending a text message?)
849 return false;
850 }
851
852 // Is there a valid SMS application on the phone?
853 if (SmsApplication.getDefaultRespondViaMessageApplication(TelecommApp.getInstance(),
854 true /*updateIfNeeded*/) == null) {
855 return false;
856 }
857
858 // TODO: with some carriers (in certain countries) you *can* actually
859 // tell whether a given number is a mobile phone or not. So in that
860 // case we could potentially return false here if the incoming call is
861 // from a land line.
862
863 // If none of the above special cases apply, it's OK to enable the
864 // "Respond via SMS" feature.
865 return true;
866 }
867
868 List<String> getCannedSmsResponses() {
869 return mCannedSmsResponses;
870 }
871
872 /**
Santos Cordon61d0f702014-02-19 02:52:23 -0800873 * @return True if the call is ringing, else logs the action name.
874 */
875 private boolean isRinging(String actionName) {
876 if (mState == CallState.RINGING) {
877 return true;
878 }
879
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800880 Log.i(this, "Request to %s a non-ringing call %s", actionName, this);
Santos Cordon61d0f702014-02-19 02:52:23 -0800881 return false;
882 }
883
Ben Gilad8e55d1d2014-02-26 16:25:56 -0800884 @SuppressWarnings("rawtypes")
885 private void decrementAssociatedCallCount(ServiceBinder binder) {
886 if (binder != null) {
887 binder.decrementAssociatedCallCount();
888 }
889 }
Santos Cordonfd71f4a2014-05-28 13:59:49 -0700890
891 /**
892 * Looks up contact information based on the current handle.
893 */
894 private void startCallerInfoLookup() {
895 String number = mHandle == null ? null : mHandle.getSchemeSpecificPart();
896
897 mQueryToken++; // Updated so that previous queries can no longer set the information.
898 mCallerInfo = null;
899 if (!TextUtils.isEmpty(number)) {
Santos Cordon5ba7f272014-05-28 13:59:49 -0700900 Log.v(this, "Looking up information for: %s.", Log.piiHandle(number));
Santos Cordonfd71f4a2014-05-28 13:59:49 -0700901 CallerInfoAsyncQuery.startQuery(
902 mQueryToken,
903 TelecommApp.getInstance(),
904 number,
905 sCallerInfoQueryListener,
906 this);
907 }
908 }
909
910 /**
Santos Cordon99c8a6f2014-05-28 18:28:47 -0700911 * Saves the specified caller info if the specified token matches that of the last query
Santos Cordonfd71f4a2014-05-28 13:59:49 -0700912 * that was made.
913 *
914 * @param callerInfo The new caller information to set.
915 * @param token The token used with this query.
916 */
917 private void setCallerInfo(CallerInfo callerInfo, int token) {
Santos Cordon99c8a6f2014-05-28 18:28:47 -0700918 Preconditions.checkNotNull(callerInfo);
919
Santos Cordonfd71f4a2014-05-28 13:59:49 -0700920 if (mQueryToken == token) {
921 mCallerInfo = callerInfo;
Santos Cordon5ba7f272014-05-28 13:59:49 -0700922 Log.i(this, "CallerInfo received for %s: %s", Log.piiHandle(mHandle), callerInfo);
Santos Cordon99c8a6f2014-05-28 18:28:47 -0700923
924 if (mCallerInfo.person_id != 0) {
925 Uri personUri =
926 ContentUris.withAppendedId(Contacts.CONTENT_URI, mCallerInfo.person_id);
927 Log.d(this, "Searching person uri %s for call %s", personUri, this);
928 ContactsAsyncHelper.startObtainPhotoAsync(
929 token,
930 TelecommApp.getInstance(),
931 personUri,
932 sPhotoLoadListener,
933 this);
Santos Cordon64c7e962014-07-02 15:15:27 -0700934 } else {
935 for (Listener l : mListeners) {
936 l.onCallerInfoChanged(this);
937 }
Santos Cordon99c8a6f2014-05-28 18:28:47 -0700938 }
Santos Cordon2174fb52014-05-29 08:22:56 -0700939
940 processDirectToVoicemail();
Santos Cordon99c8a6f2014-05-28 18:28:47 -0700941 }
942 }
943
944 /**
945 * Saves the specified photo information if the specified token matches that of the last query.
946 *
947 * @param photo The photo as a drawable.
948 * @param photoIcon The photo as a small icon.
949 * @param token The token used with this query.
950 */
951 private void setPhoto(Drawable photo, Bitmap photoIcon, int token) {
952 if (mQueryToken == token) {
953 mCallerInfo.cachedPhoto = photo;
954 mCallerInfo.cachedPhotoIcon = photoIcon;
Santos Cordon64c7e962014-07-02 15:15:27 -0700955
956 for (Listener l : mListeners) {
957 l.onCallerInfoChanged(this);
958 }
Santos Cordonfd71f4a2014-05-28 13:59:49 -0700959 }
960 }
Ihab Awadff7493a2014-06-10 13:47:44 -0700961
962 private void maybeLoadCannedSmsResponses() {
963 if (mIsIncoming && isRespondViaSmsCapable() && !mCannedSmsResponsesLoadingStarted) {
964 Log.d(this, "maybeLoadCannedSmsResponses: starting task to load messages");
965 mCannedSmsResponsesLoadingStarted = true;
966 RespondViaSmsManager.getInstance().loadCannedTextMessages(
967 new Response<Void, List<String>>() {
968 @Override
969 public void onResult(Void request, List<String>... result) {
970 if (result.length > 0) {
971 Log.d(this, "maybeLoadCannedSmsResponses: got %s", result[0]);
972 mCannedSmsResponses = result[0];
973 for (Listener l : mListeners) {
974 l.onCannedSmsResponsesLoaded(Call.this);
975 }
976 }
977 }
978
979 @Override
980 public void onError(Void request, int code, String msg) {
981 Log.w(Call.this, "Error obtaining canned SMS responses: %d %s", code,
982 msg);
983 }
984 }
985 );
986 } else {
987 Log.d(this, "maybeLoadCannedSmsResponses: doing nothing");
988 }
989 }
Sai Cheemalapatib7157e92014-06-11 17:51:55 -0700990
991 /**
992 * Sets speakerphone option on when call begins.
993 */
994 public void setStartWithSpeakerphoneOn(boolean startWithSpeakerphone) {
995 mSpeakerphoneOn = startWithSpeakerphone;
996 }
997
998 /**
999 * Returns speakerphone option.
1000 *
1001 * @return Whether or not speakerphone should be set automatically when call begins.
1002 */
1003 public boolean getStartWithSpeakerphoneOn() {
1004 return mSpeakerphoneOn;
1005 }
Andrew Leee9a77652014-06-26 13:07:57 -07001006
1007 /**
1008 * Sets a call video provider for the call.
1009 */
Nancy Chena65d41f2014-06-24 12:06:03 -07001010 public void setCallVideoProvider(ICallVideoProvider callVideoProvider) {
1011 mCallVideoProvider = callVideoProvider;
1012 for (Listener l : mListeners) {
1013 l.onCallVideoProviderChanged(Call.this);
1014 }
1015 }
1016
1017 /**
1018 * @return Return the call video Provider binder.
1019 */
1020 public ICallVideoProvider getCallVideoProvider() {
1021 return mCallVideoProvider;
Andrew Leee9a77652014-06-26 13:07:57 -07001022 }
Tyler Gunne19cc002014-07-01 11:32:53 -07001023
1024 /**
1025 * Returns the features of this call.
1026 *
1027 * @return The features of this call.
1028 */
1029 public int getFeatures() {
1030 return mFeatures;
1031 }
1032
1033 /**
1034 * Set the features associated with the call and notify any listeners of the change.
1035 *
1036 * @param features The features.
1037 */
1038 public void setFeatures(int features) {
1039 Log.d(this, "setFeatures: %d", features);
1040 mFeatures = features;
1041 for (Listener l : mListeners) {
1042 l.onFeaturesChanged(Call.this);
1043 }
1044 }
Tyler Gunnc4abd912014-07-08 14:22:10 -07001045
1046 /**
1047 * The current video state for the call.
1048 * Valid values: {@link android.telecomm.VideoCallProfile#VIDEO_STATE_AUDIO_ONLY},
1049 * {@link android.telecomm.VideoCallProfile#VIDEO_STATE_BIDIRECTIONAL},
1050 * {@link android.telecomm.VideoCallProfile#VIDEO_STATE_TX_ENABLED},
1051 * {@link android.telecomm.VideoCallProfile#VIDEO_STATE_RX_ENABLED}.
1052 *
1053 * @return True if video is enabled.
1054 */
1055 public int getVideoState() {
1056 return mVideoState;
1057 }
1058
1059 /**
1060 * At the start of the call, determines the desired video state for the call.
1061 * Valid values: {@link android.telecomm.VideoCallProfile#VIDEO_STATE_AUDIO_ONLY},
1062 * {@link android.telecomm.VideoCallProfile#VIDEO_STATE_BIDIRECTIONAL},
1063 * {@link android.telecomm.VideoCallProfile#VIDEO_STATE_TX_ENABLED},
1064 * {@link android.telecomm.VideoCallProfile#VIDEO_STATE_RX_ENABLED}.
1065 *
1066 * @param videoState The desired video state for the call.
1067 */
1068 public void setVideoState(int videoState) {
1069 mVideoState = videoState;
1070 }
Sailesh Nepal7e669572014-07-08 21:29:12 -07001071
1072 public boolean getAudioModeIsVoip() {
1073 return mAudioModeIsVoip;
1074 }
1075
1076 public void setAudioModeIsVoip(boolean audioModeIsVoip) {
1077 mAudioModeIsVoip = audioModeIsVoip;
1078 for (Listener l : mListeners) {
Sailesh Nepal35faf8c2014-07-08 22:02:34 -07001079 l.onAudioModeIsVoipChanged(this);
1080 }
1081 }
1082
1083 public StatusHints getStatusHints() {
1084 return mStatusHints;
1085 }
1086
1087 public void setStatusHints(StatusHints statusHints) {
1088 mStatusHints = statusHints;
1089 for (Listener l : mListeners) {
1090 l.onStatusHintsChanged(this);
Sailesh Nepal7e669572014-07-08 21:29:12 -07001091 }
1092 }
Ben Gilad9f2bed32013-12-12 17:43:26 -08001093}