blob: 3b7e4dc8f7b0cdc907a28e2c4a207033d988d73b [file] [log] [blame]
Eric Erfanianccca3152017-02-22 16:32:36 -08001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.incallui.call;
18
wangqi9982f0d2017-10-11 17:46:07 -070019import android.Manifest.permission;
wangqida410d32018-03-06 16:51:38 -080020import android.annotation.SuppressLint;
wangqi8d407a02018-02-15 15:32:52 -080021import android.annotation.TargetApi;
Eric Erfanianccca3152017-02-22 16:32:36 -080022import android.content.Context;
23import android.hardware.camera2.CameraCharacteristics;
24import android.net.Uri;
erfanian2cf2c342017-12-21 12:01:33 -080025import android.os.Build;
Eric Erfanianccca3152017-02-22 16:32:36 -080026import android.os.Build.VERSION;
27import android.os.Build.VERSION_CODES;
28import android.os.Bundle;
wangqida410d32018-03-06 16:51:38 -080029import android.os.PersistableBundle;
Eric Erfanianccca3152017-02-22 16:32:36 -080030import android.os.Trace;
31import android.support.annotation.IntDef;
Eric Erfaniand5e47f62017-03-15 14:41:07 -070032import android.support.annotation.NonNull;
Eric Erfanianccca3152017-02-22 16:32:36 -080033import android.support.annotation.Nullable;
twyendde01c52017-09-22 10:07:31 -070034import android.support.annotation.VisibleForTesting;
wangqif4ba3452018-01-09 11:26:29 -080035import android.support.v4.os.BuildCompat;
Eric Erfanianccca3152017-02-22 16:32:36 -080036import android.telecom.Call;
37import android.telecom.Call.Details;
wangqi219b8702018-02-13 09:34:41 -080038import android.telecom.Call.RttCall;
Eric Erfanian8369df02017-05-03 10:27:13 -070039import android.telecom.CallAudioState;
Eric Erfanianccca3152017-02-22 16:32:36 -080040import android.telecom.Connection;
41import android.telecom.DisconnectCause;
42import android.telecom.GatewayInfo;
43import android.telecom.InCallService.VideoCall;
44import android.telecom.PhoneAccount;
45import android.telecom.PhoneAccountHandle;
46import android.telecom.StatusHints;
47import android.telecom.TelecomManager;
48import android.telecom.VideoProfile;
Eric Erfanianccca3152017-02-22 16:32:36 -080049import android.text.TextUtils;
roldenburg08424ee2018-03-28 17:02:46 -070050import android.widget.Toast;
Eric Erfanianccca3152017-02-22 16:32:36 -080051import com.android.contacts.common.compat.CallCompat;
Eric Erfanianccca3152017-02-22 16:32:36 -080052import com.android.contacts.common.compat.telecom.TelecomManagerCompat;
erfanian2cf2c342017-12-21 12:01:33 -080053import com.android.dialer.assisteddialing.ConcreteCreator;
erfaniand0f207f2017-10-11 12:23:29 -070054import com.android.dialer.assisteddialing.TransformationInfo;
Eric Erfanian8369df02017-05-03 10:27:13 -070055import com.android.dialer.callintent.CallInitiationType;
Eric Erfanianccca3152017-02-22 16:32:36 -080056import com.android.dialer.callintent.CallIntentParser;
Eric Erfanian8369df02017-05-03 10:27:13 -070057import com.android.dialer.callintent.CallSpecificAppData;
Eric Erfanianccca3152017-02-22 16:32:36 -080058import com.android.dialer.common.Assert;
Eric Erfanianccca3152017-02-22 16:32:36 -080059import com.android.dialer.common.LogUtil;
wangqid6b10d52018-04-12 14:44:06 -070060import com.android.dialer.common.concurrent.DefaultFutureCallback;
Eric Erfanian2ca43182017-08-31 06:57:16 -070061import com.android.dialer.compat.telephony.TelephonyManagerCompat;
62import com.android.dialer.configprovider.ConfigProviderBindings;
roldenburg4f026392017-10-13 18:42:20 -070063import com.android.dialer.duo.DuoComponent;
Eric Erfanian8369df02017-05-03 10:27:13 -070064import com.android.dialer.enrichedcall.EnrichedCallCapabilities;
Eric Erfaniand5e47f62017-03-15 14:41:07 -070065import com.android.dialer.enrichedcall.EnrichedCallComponent;
Eric Erfanian2ca43182017-08-31 06:57:16 -070066import com.android.dialer.enrichedcall.EnrichedCallManager;
67import com.android.dialer.enrichedcall.EnrichedCallManager.CapabilitiesListener;
68import com.android.dialer.enrichedcall.EnrichedCallManager.Filter;
69import com.android.dialer.enrichedcall.EnrichedCallManager.StateChangedListener;
Eric Erfanian8369df02017-05-03 10:27:13 -070070import com.android.dialer.enrichedcall.Session;
wangqi9982f0d2017-10-11 17:46:07 -070071import com.android.dialer.location.GeoUtil;
Eric Erfanian8369df02017-05-03 10:27:13 -070072import com.android.dialer.logging.ContactLookupResult;
twyendde01c52017-09-22 10:07:31 -070073import com.android.dialer.logging.ContactLookupResult.Type;
Eric Erfanian8369df02017-05-03 10:27:13 -070074import com.android.dialer.logging.DialerImpression;
75import com.android.dialer.logging.Logger;
twyen73a74c32018-03-07 12:12:24 -080076import com.android.dialer.preferredsim.PreferredAccountRecorder;
wangqied677ef2018-04-04 12:03:00 -070077import com.android.dialer.rtt.RttTranscript;
wangqid6b10d52018-04-12 14:44:06 -070078import com.android.dialer.rtt.RttTranscriptUtil;
twyena4745bd2017-12-12 18:40:11 -080079import com.android.dialer.telecom.TelecomCallUtil;
wangqi9982f0d2017-10-11 17:46:07 -070080import com.android.dialer.telecom.TelecomUtil;
Eric Erfanianc857f902017-05-15 14:05:33 -070081import com.android.dialer.theme.R;
wangqi9982f0d2017-10-11 17:46:07 -070082import com.android.dialer.util.PermissionsUtil;
Eric Erfanian8369df02017-05-03 10:27:13 -070083import com.android.incallui.audiomode.AudioModeProvider;
Eric Erfanianccca3152017-02-22 16:32:36 -080084import com.android.incallui.latencyreport.LatencyReport;
erfaniandcc84cd2018-04-17 12:41:05 -070085import com.android.incallui.speakeasy.runtime.Constraints;
Eric Erfaniand5e47f62017-03-15 14:41:07 -070086import com.android.incallui.videotech.VideoTech;
87import com.android.incallui.videotech.VideoTech.VideoTechListener;
roldenburg4f026392017-10-13 18:42:20 -070088import com.android.incallui.videotech.duo.DuoVideoTech;
Eric Erfaniand5e47f62017-03-15 14:41:07 -070089import com.android.incallui.videotech.empty.EmptyVideoTech;
90import com.android.incallui.videotech.ims.ImsVideoTech;
Eric Erfanian90508232017-03-24 09:31:16 -070091import com.android.incallui.videotech.utils.VideoUtils;
wangqid6b10d52018-04-12 14:44:06 -070092import com.google.common.util.concurrent.Futures;
wangqid6b10d52018-04-12 14:44:06 -070093import com.google.common.util.concurrent.MoreExecutors;
Eric Erfanianccca3152017-02-22 16:32:36 -080094import java.lang.annotation.Retention;
95import java.lang.annotation.RetentionPolicy;
96import java.util.ArrayList;
97import java.util.List;
98import java.util.Locale;
99import java.util.Objects;
100import java.util.UUID;
101import java.util.concurrent.CopyOnWriteArrayList;
102import java.util.concurrent.TimeUnit;
103
104/** Describes a single call and its state. */
Eric Erfanian2ca43182017-08-31 06:57:16 -0700105public class DialerCall implements VideoTechListener, StateChangedListener, CapabilitiesListener {
Eric Erfanianccca3152017-02-22 16:32:36 -0800106
107 public static final int CALL_HISTORY_STATUS_UNKNOWN = 0;
108 public static final int CALL_HISTORY_STATUS_PRESENT = 1;
109 public static final int CALL_HISTORY_STATUS_NOT_PRESENT = 2;
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700110
111 // Hard coded property for {@code Call}. Upstreamed change from Motorola.
Eric Erfanian938468d2017-10-24 14:05:52 -0700112 // TODO(a bug): Move it to Telecom in framework.
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700113 public static final int PROPERTY_CODEC_KNOWN = 0x04000000;
114
Eric Erfanianccca3152017-02-22 16:32:36 -0800115 private static final String ID_PREFIX = "DialerCall_";
116 private static final String CONFIG_EMERGENCY_CALLBACK_WINDOW_MILLIS =
117 "emergency_callback_window_millis";
linyuh183cb712017-12-27 17:02:37 -0800118 private static int idCounter = 0;
Eric Erfanianccca3152017-02-22 16:32:36 -0800119
120 /**
Eric Erfanianc857f902017-05-15 14:05:33 -0700121 * A counter used to append to restricted/private/hidden calls so that users can identify them in
122 * a conversation. This value is reset in {@link CallList#onCallRemoved(Context, Call)} when there
123 * are no live calls.
124 */
linyuh183cb712017-12-27 17:02:37 -0800125 private static int hiddenCounter;
Eric Erfanianc857f902017-05-15 14:05:33 -0700126
127 /**
Eric Erfanianccca3152017-02-22 16:32:36 -0800128 * The unique call ID for every call. This will help us to identify each call and allow us the
129 * ability to stitch impressions to calls if needed.
130 */
131 private final String uniqueCallId = UUID.randomUUID().toString();
132
linyuh183cb712017-12-27 17:02:37 -0800133 private final Call telecomCall;
134 private final LatencyReport latencyReport;
135 private final String id;
136 private final int hiddenId;
137 private final List<String> childCallIds = new ArrayList<>();
138 private final LogState logState = new LogState();
139 private final Context context;
140 private final DialerCallDelegate dialerCallDelegate;
141 private final List<DialerCallListener> listeners = new CopyOnWriteArrayList<>();
142 private final List<CannedTextResponsesLoadedListener> cannedTextResponsesLoadedListeners =
Eric Erfanianccca3152017-02-22 16:32:36 -0800143 new CopyOnWriteArrayList<>();
linyuh183cb712017-12-27 17:02:37 -0800144 private final VideoTechManager videoTechManager;
Eric Erfanianccca3152017-02-22 16:32:36 -0800145
erfaniand05d8992018-03-20 19:42:26 -0700146 private boolean isSpeakEasyCall;
linyuh183cb712017-12-27 17:02:37 -0800147 private boolean isEmergencyCall;
148 private Uri handle;
149 private int state = State.INVALID;
150 private DisconnectCause disconnectCause;
Eric Erfanianccca3152017-02-22 16:32:36 -0800151
roldenburg08424ee2018-03-28 17:02:46 -0700152 private boolean hasShownLteToWiFiHandoverToast;
Eric Erfanianccca3152017-02-22 16:32:36 -0800153 private boolean hasShownWiFiToLteHandoverToast;
154 private boolean doNotShowDialogForHandoffToWifiFailure;
155
linyuh183cb712017-12-27 17:02:37 -0800156 private String childNumber;
157 private String lastForwardedNumber;
wangqif4ba3452018-01-09 11:26:29 -0800158 private boolean isCallForwarded;
linyuh183cb712017-12-27 17:02:37 -0800159 private String callSubject;
160 private PhoneAccountHandle phoneAccountHandle;
161 @CallHistoryStatus private int callHistoryStatus = CALL_HISTORY_STATUS_UNKNOWN;
162 private boolean isSpam;
163 private boolean isBlocked;
Eric Erfanian938468d2017-10-24 14:05:52 -0700164
165 @Nullable private Boolean isInUserSpamList;
166
167 @Nullable private Boolean isInUserWhiteList;
168
169 @Nullable private Boolean isInGlobalSpamList;
Eric Erfanianccca3152017-02-22 16:32:36 -0800170 private boolean didShowCameraPermission;
wangqida410d32018-03-06 16:51:38 -0800171 private boolean didDismissVideoChargesAlertDialog;
172 private PersistableBundle carrierConfig;
Eric Erfanianccca3152017-02-22 16:32:36 -0800173 private String callProviderLabel;
174 private String callbackNumber;
linyuh183cb712017-12-27 17:02:37 -0800175 private int cameraDirection = CameraDirection.CAMERA_DIRECTION_UNKNOWN;
176 private EnrichedCallCapabilities enrichedCallCapabilities;
177 private Session enrichedCallSession;
Eric Erfanianccca3152017-02-22 16:32:36 -0800178
Eric Erfanian2ca43182017-08-31 06:57:16 -0700179 private int answerAndReleaseButtonDisplayedTimes = 0;
180 private boolean releasedByAnsweringSecondCall = false;
181 // Times when a second call is received but AnswerAndRelease button is not shown
182 // since it's not supported.
183 private int secondCallWithoutAnswerAndReleasedButtonTimes = 0;
roldenburg7bb96232017-10-09 10:32:05 -0700184 private VideoTech videoTech;
Eric Erfanian2ca43182017-08-31 06:57:16 -0700185
wangqi4d705e52017-09-28 12:23:35 -0700186 private com.android.dialer.logging.VideoTech.Type selectedAvailableVideoTechType =
187 com.android.dialer.logging.VideoTech.Type.NONE;
wangqi9982f0d2017-10-11 17:46:07 -0700188 private boolean isVoicemailNumber;
189 private List<PhoneAccountHandle> callCapableAccounts;
190 private String countryIso;
yueg457b3972017-09-18 15:11:47 -0700191
Android Dialer974fc292018-02-01 16:12:25 -0800192 private volatile boolean feedbackRequested = false;
193
twyen73a74c32018-03-07 12:12:24 -0800194 @Nullable private PreferredAccountRecorder preferredAccountRecorder;
195
Eric Erfanianccca3152017-02-22 16:32:36 -0800196 public static String getNumberFromHandle(Uri handle) {
197 return handle == null ? "" : handle.getSchemeSpecificPart();
198 }
199
200 /**
201 * Whether the call is put on hold by remote party. This is different than the {@link
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700202 * State#ONHOLD} state which indicates that the call is being held locally on the device.
Eric Erfanianccca3152017-02-22 16:32:36 -0800203 */
204 private boolean isRemotelyHeld;
205
Eric Erfanian2ca43182017-08-31 06:57:16 -0700206 /** Indicates whether this call is currently in the process of being merged into a conference. */
207 private boolean isMergeInProcess;
208
Eric Erfanianccca3152017-02-22 16:32:36 -0800209 /**
210 * Indicates whether the phone account associated with this call supports specifying a call
211 * subject.
212 */
linyuh183cb712017-12-27 17:02:37 -0800213 private boolean isCallSubjectSupported;
Eric Erfanianccca3152017-02-22 16:32:36 -0800214
wangqied677ef2018-04-04 12:03:00 -0700215 public RttTranscript getRttTranscript() {
216 return rttTranscript;
217 }
218
219 public void setRttTranscript(RttTranscript rttTranscript) {
220 this.rttTranscript = rttTranscript;
221 }
222
223 private RttTranscript rttTranscript;
224
linyuh183cb712017-12-27 17:02:37 -0800225 private final Call.Callback telecomCallCallback =
Eric Erfanianccca3152017-02-22 16:32:36 -0800226 new Call.Callback() {
227 @Override
228 public void onStateChanged(Call call, int newState) {
229 LogUtil.v("TelecomCallCallback.onStateChanged", "call=" + call + " newState=" + newState);
230 update();
231 }
232
233 @Override
234 public void onParentChanged(Call call, Call newParent) {
235 LogUtil.v(
236 "TelecomCallCallback.onParentChanged", "call=" + call + " newParent=" + newParent);
237 update();
238 }
239
240 @Override
241 public void onChildrenChanged(Call call, List<Call> children) {
242 update();
243 }
244
245 @Override
246 public void onDetailsChanged(Call call, Call.Details details) {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700247 LogUtil.v(
248 "TelecomCallCallback.onDetailsChanged", " call=" + call + " details=" + details);
Eric Erfanianccca3152017-02-22 16:32:36 -0800249 update();
250 }
251
252 @Override
253 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {
254 LogUtil.v(
Eric Erfanian2ca43182017-08-31 06:57:16 -0700255 "TelecomCallCallback.onCannedTextResponsesLoaded",
Eric Erfanianccca3152017-02-22 16:32:36 -0800256 "call=" + call + " cannedTextResponses=" + cannedTextResponses);
linyuh183cb712017-12-27 17:02:37 -0800257 for (CannedTextResponsesLoadedListener listener : cannedTextResponsesLoadedListeners) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800258 listener.onCannedTextResponsesLoaded(DialerCall.this);
259 }
260 }
261
262 @Override
263 public void onPostDialWait(Call call, String remainingPostDialSequence) {
264 LogUtil.v(
Eric Erfanian2ca43182017-08-31 06:57:16 -0700265 "TelecomCallCallback.onPostDialWait",
Eric Erfanianccca3152017-02-22 16:32:36 -0800266 "call=" + call + " remainingPostDialSequence=" + remainingPostDialSequence);
267 update();
268 }
269
270 @Override
271 public void onVideoCallChanged(Call call, VideoCall videoCall) {
272 LogUtil.v(
Eric Erfanian2ca43182017-08-31 06:57:16 -0700273 "TelecomCallCallback.onVideoCallChanged", "call=" + call + " videoCall=" + videoCall);
Eric Erfanianccca3152017-02-22 16:32:36 -0800274 update();
275 }
276
277 @Override
278 public void onCallDestroyed(Call call) {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700279 LogUtil.v("TelecomCallCallback.onCallDestroyed", "call=" + call);
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700280 unregisterCallback();
Eric Erfanianccca3152017-02-22 16:32:36 -0800281 }
282
283 @Override
284 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {
285 LogUtil.v(
Eric Erfanian2ca43182017-08-31 06:57:16 -0700286 "TelecomCallCallback.onConferenceableCallsChanged",
Eric Erfanianccca3152017-02-22 16:32:36 -0800287 "call %s, conferenceable calls: %d",
288 call,
289 conferenceableCalls.size());
290 update();
291 }
292
293 @Override
wangqi219b8702018-02-13 09:34:41 -0800294 public void onRttModeChanged(Call call, int mode) {
295 LogUtil.v("TelecomCallCallback.onRttModeChanged", "mode=%d", mode);
296 }
297
298 @Override
299 public void onRttRequest(Call call, int id) {
300 LogUtil.v("TelecomCallCallback.onRttRequest", "id=%d", id);
wangqibc28ea72018-04-02 16:23:00 -0700301 for (DialerCallListener listener : listeners) {
302 listener.onDialerCallUpgradeToRtt(id);
303 }
wangqi219b8702018-02-13 09:34:41 -0800304 }
305
306 @Override
307 public void onRttInitiationFailure(Call call, int reason) {
308 LogUtil.v("TelecomCallCallback.onRttInitiationFailure", "reason=%d", reason);
309 update();
310 }
311
312 @Override
313 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {
314 LogUtil.v("TelecomCallCallback.onRttStatusChanged", "enabled=%b", enabled);
315 update();
316 }
317
318 @Override
Eric Erfanianccca3152017-02-22 16:32:36 -0800319 public void onConnectionEvent(android.telecom.Call call, String event, Bundle extras) {
320 LogUtil.v(
Eric Erfanian2ca43182017-08-31 06:57:16 -0700321 "TelecomCallCallback.onConnectionEvent",
Eric Erfanianccca3152017-02-22 16:32:36 -0800322 "Call: " + call + ", Event: " + event + ", Extras: " + extras);
323 switch (event) {
324 // The Previous attempt to Merge two calls together has failed in Telecom. We must
325 // now update the UI to possibly re-enable the Merge button based on the number of
326 // currently conferenceable calls available or Connection Capabilities.
327 case android.telecom.Connection.EVENT_CALL_MERGE_FAILED:
328 update();
329 break;
330 case TelephonyManagerCompat.EVENT_HANDOVER_VIDEO_FROM_WIFI_TO_LTE:
331 notifyWiFiToLteHandover();
332 break;
roldenburg08424ee2018-03-28 17:02:46 -0700333 case TelephonyManagerCompat.EVENT_HANDOVER_VIDEO_FROM_LTE_TO_WIFI:
334 onLteToWifiHandover();
335 break;
Eric Erfanianccca3152017-02-22 16:32:36 -0800336 case TelephonyManagerCompat.EVENT_HANDOVER_TO_WIFI_FAILED:
337 notifyHandoverToWifiFailed();
338 break;
339 case TelephonyManagerCompat.EVENT_CALL_REMOTELY_HELD:
340 isRemotelyHeld = true;
341 update();
342 break;
343 case TelephonyManagerCompat.EVENT_CALL_REMOTELY_UNHELD:
344 isRemotelyHeld = false;
345 update();
346 break;
Eric Erfanianc857f902017-05-15 14:05:33 -0700347 case TelephonyManagerCompat.EVENT_NOTIFY_INTERNATIONAL_CALL_ON_WFC:
348 notifyInternationalCallOnWifi();
349 break;
Eric Erfanian2ca43182017-08-31 06:57:16 -0700350 case TelephonyManagerCompat.EVENT_MERGE_START:
351 LogUtil.i("DialerCall.onConnectionEvent", "merge start");
352 isMergeInProcess = true;
353 break;
354 case TelephonyManagerCompat.EVENT_MERGE_COMPLETE:
355 LogUtil.i("DialerCall.onConnectionEvent", "merge complete");
356 isMergeInProcess = false;
357 break;
wangqif4ba3452018-01-09 11:26:29 -0800358 case TelephonyManagerCompat.EVENT_CALL_FORWARDED:
359 // Only handle this event for P+ since it's unreliable pre-P.
360 if (BuildCompat.isAtLeastP()) {
361 isCallForwarded = true;
362 update();
363 }
364 break;
Eric Erfanianccca3152017-02-22 16:32:36 -0800365 default:
366 break;
367 }
368 }
369 };
Eric Erfanianc857f902017-05-15 14:05:33 -0700370
linyuh183cb712017-12-27 17:02:37 -0800371 private long timeAddedMs;
Eric Erfanianccca3152017-02-22 16:32:36 -0800372
373 public DialerCall(
374 Context context,
375 DialerCallDelegate dialerCallDelegate,
376 Call telecomCall,
377 LatencyReport latencyReport,
378 boolean registerCallback) {
379 Assert.isNotNull(context);
linyuh183cb712017-12-27 17:02:37 -0800380 this.context = context;
381 this.dialerCallDelegate = dialerCallDelegate;
382 this.telecomCall = telecomCall;
383 this.latencyReport = latencyReport;
384 id = ID_PREFIX + Integer.toString(idCounter++);
Eric Erfanianccca3152017-02-22 16:32:36 -0800385
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700386 // Must be after assigning mTelecomCall
linyuh183cb712017-12-27 17:02:37 -0800387 videoTechManager = new VideoTechManager(this);
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700388
389 updateFromTelecomCall();
Eric Erfanianc857f902017-05-15 14:05:33 -0700390 if (isHiddenNumber() && TextUtils.isEmpty(getNumber())) {
linyuh183cb712017-12-27 17:02:37 -0800391 hiddenId = ++hiddenCounter;
Eric Erfanianc857f902017-05-15 14:05:33 -0700392 } else {
linyuh183cb712017-12-27 17:02:37 -0800393 hiddenId = 0;
Eric Erfanianc857f902017-05-15 14:05:33 -0700394 }
Eric Erfanianccca3152017-02-22 16:32:36 -0800395
396 if (registerCallback) {
linyuh183cb712017-12-27 17:02:37 -0800397 this.telecomCall.registerCallback(telecomCallCallback);
Eric Erfanianccca3152017-02-22 16:32:36 -0800398 }
399
linyuh183cb712017-12-27 17:02:37 -0800400 timeAddedMs = System.currentTimeMillis();
Eric Erfanianccca3152017-02-22 16:32:36 -0800401 parseCallSpecificAppData();
Eric Erfanian2ca43182017-08-31 06:57:16 -0700402
403 updateEnrichedCallSession();
Eric Erfanianccca3152017-02-22 16:32:36 -0800404 }
405
twyendde01c52017-09-22 10:07:31 -0700406 /** Test only constructor to avoid initializing dependencies. */
407 @VisibleForTesting
408 DialerCall(Context context) {
linyuh183cb712017-12-27 17:02:37 -0800409 this.context = context;
410 telecomCall = null;
411 latencyReport = null;
412 id = null;
413 hiddenId = 0;
414 dialerCallDelegate = null;
415 videoTechManager = null;
twyendde01c52017-09-22 10:07:31 -0700416 }
417
Eric Erfanianccca3152017-02-22 16:32:36 -0800418 private static int translateState(int state) {
419 switch (state) {
420 case Call.STATE_NEW:
421 case Call.STATE_CONNECTING:
422 return DialerCall.State.CONNECTING;
423 case Call.STATE_SELECT_PHONE_ACCOUNT:
424 return DialerCall.State.SELECT_PHONE_ACCOUNT;
425 case Call.STATE_DIALING:
426 return DialerCall.State.DIALING;
427 case Call.STATE_PULLING_CALL:
428 return DialerCall.State.PULLING;
429 case Call.STATE_RINGING:
430 return DialerCall.State.INCOMING;
431 case Call.STATE_ACTIVE:
432 return DialerCall.State.ACTIVE;
433 case Call.STATE_HOLDING:
434 return DialerCall.State.ONHOLD;
435 case Call.STATE_DISCONNECTED:
436 return DialerCall.State.DISCONNECTED;
437 case Call.STATE_DISCONNECTING:
438 return DialerCall.State.DISCONNECTING;
439 default:
440 return DialerCall.State.INVALID;
441 }
442 }
443
444 public static boolean areSame(DialerCall call1, DialerCall call2) {
445 if (call1 == null && call2 == null) {
446 return true;
447 } else if (call1 == null || call2 == null) {
448 return false;
449 }
450
451 // otherwise compare call Ids
452 return call1.getId().equals(call2.getId());
453 }
454
Eric Erfanianccca3152017-02-22 16:32:36 -0800455 public void addListener(DialerCallListener listener) {
456 Assert.isMainThread();
linyuh183cb712017-12-27 17:02:37 -0800457 listeners.add(listener);
Eric Erfanianccca3152017-02-22 16:32:36 -0800458 }
459
460 public void removeListener(DialerCallListener listener) {
461 Assert.isMainThread();
linyuh183cb712017-12-27 17:02:37 -0800462 listeners.remove(listener);
Eric Erfanianccca3152017-02-22 16:32:36 -0800463 }
464
465 public void addCannedTextResponsesLoadedListener(CannedTextResponsesLoadedListener listener) {
466 Assert.isMainThread();
linyuh183cb712017-12-27 17:02:37 -0800467 cannedTextResponsesLoadedListeners.add(listener);
Eric Erfanianccca3152017-02-22 16:32:36 -0800468 }
469
470 public void removeCannedTextResponsesLoadedListener(CannedTextResponsesLoadedListener listener) {
471 Assert.isMainThread();
linyuh183cb712017-12-27 17:02:37 -0800472 cannedTextResponsesLoadedListeners.remove(listener);
Eric Erfanianccca3152017-02-22 16:32:36 -0800473 }
474
roldenburg08424ee2018-03-28 17:02:46 -0700475 private void onLteToWifiHandover() {
476 LogUtil.enterBlock("DialerCall.onLteToWifiHandover");
477 if (hasShownLteToWiFiHandoverToast) {
478 return;
479 }
480
481 Toast.makeText(context, R.string.video_call_lte_to_wifi_handover_toast, Toast.LENGTH_LONG)
482 .show();
483 hasShownLteToWiFiHandoverToast = true;
484 }
485
Eric Erfanianccca3152017-02-22 16:32:36 -0800486 public void notifyWiFiToLteHandover() {
487 LogUtil.i("DialerCall.notifyWiFiToLteHandover", "");
linyuh183cb712017-12-27 17:02:37 -0800488 for (DialerCallListener listener : listeners) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800489 listener.onWiFiToLteHandover();
490 }
491 }
492
493 public void notifyHandoverToWifiFailed() {
494 LogUtil.i("DialerCall.notifyHandoverToWifiFailed", "");
linyuh183cb712017-12-27 17:02:37 -0800495 for (DialerCallListener listener : listeners) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800496 listener.onHandoverToWifiFailure();
497 }
498 }
499
Eric Erfanianc857f902017-05-15 14:05:33 -0700500 public void notifyInternationalCallOnWifi() {
501 LogUtil.enterBlock("DialerCall.notifyInternationalCallOnWifi");
linyuh183cb712017-12-27 17:02:37 -0800502 for (DialerCallListener dialerCallListener : listeners) {
Eric Erfanianc857f902017-05-15 14:05:33 -0700503 dialerCallListener.onInternationalCallOnWifi();
504 }
505 }
506
Eric Erfanianccca3152017-02-22 16:32:36 -0800507 /* package-private */ Call getTelecomCall() {
linyuh183cb712017-12-27 17:02:37 -0800508 return telecomCall;
Eric Erfanianccca3152017-02-22 16:32:36 -0800509 }
wangqida410d32018-03-06 16:51:38 -0800510
Eric Erfanianccca3152017-02-22 16:32:36 -0800511 public StatusHints getStatusHints() {
linyuh183cb712017-12-27 17:02:37 -0800512 return telecomCall.getDetails().getStatusHints();
Eric Erfanianccca3152017-02-22 16:32:36 -0800513 }
514
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700515 public int getCameraDir() {
linyuh183cb712017-12-27 17:02:37 -0800516 return cameraDirection;
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700517 }
518
519 public void setCameraDir(int cameraDir) {
520 if (cameraDir == CameraDirection.CAMERA_DIRECTION_FRONT_FACING
521 || cameraDir == CameraDirection.CAMERA_DIRECTION_BACK_FACING) {
linyuh183cb712017-12-27 17:02:37 -0800522 cameraDirection = cameraDir;
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700523 } else {
linyuh183cb712017-12-27 17:02:37 -0800524 cameraDirection = CameraDirection.CAMERA_DIRECTION_UNKNOWN;
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700525 }
Eric Erfanianccca3152017-02-22 16:32:36 -0800526 }
527
Eric Erfanian2ca43182017-08-31 06:57:16 -0700528 public boolean wasParentCall() {
linyuh183cb712017-12-27 17:02:37 -0800529 return logState.conferencedCalls != 0;
Eric Erfanian2ca43182017-08-31 06:57:16 -0700530 }
531
wangqi9982f0d2017-10-11 17:46:07 -0700532 public boolean isVoiceMailNumber() {
533 return isVoicemailNumber;
534 }
535
536 public List<PhoneAccountHandle> getCallCapableAccounts() {
537 return callCapableAccounts;
538 }
539
540 public String getCountryIso() {
541 return countryIso;
542 }
543
544 private void updateIsVoiceMailNumber() {
545 if (getHandle() != null && PhoneAccount.SCHEME_VOICEMAIL.equals(getHandle().getScheme())) {
546 isVoicemailNumber = true;
roldenburg37a969d2018-02-22 14:46:44 -0800547 return;
wangqi9982f0d2017-10-11 17:46:07 -0700548 }
549
linyuh183cb712017-12-27 17:02:37 -0800550 if (!PermissionsUtil.hasPermission(context, permission.READ_PHONE_STATE)) {
wangqi9982f0d2017-10-11 17:46:07 -0700551 isVoicemailNumber = false;
roldenburg37a969d2018-02-22 14:46:44 -0800552 return;
wangqi9982f0d2017-10-11 17:46:07 -0700553 }
554
linyuh183cb712017-12-27 17:02:37 -0800555 isVoicemailNumber = TelecomUtil.isVoicemailNumber(context, getAccountHandle(), getNumber());
wangqi9982f0d2017-10-11 17:46:07 -0700556 }
557
Eric Erfanianccca3152017-02-22 16:32:36 -0800558 private void update() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700559 Trace.beginSection("DialerCall.update");
Eric Erfanianccca3152017-02-22 16:32:36 -0800560 int oldState = getState();
roldenburg7bb96232017-10-09 10:32:05 -0700561 // Clear any cache here that could potentially change on update.
562 videoTech = null;
Eric Erfanianccca3152017-02-22 16:32:36 -0800563 // We want to potentially register a video call callback here.
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700564 updateFromTelecomCall();
Eric Erfanianccca3152017-02-22 16:32:36 -0800565 if (oldState != getState() && getState() == DialerCall.State.DISCONNECTED) {
linyuh183cb712017-12-27 17:02:37 -0800566 for (DialerCallListener listener : listeners) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800567 listener.onDialerCallDisconnect();
568 }
linyuh183cb712017-12-27 17:02:37 -0800569 EnrichedCallComponent.get(context)
Eric Erfanian2ca43182017-08-31 06:57:16 -0700570 .getEnrichedCallManager()
571 .unregisterCapabilitiesListener(this);
linyuh183cb712017-12-27 17:02:37 -0800572 EnrichedCallComponent.get(context)
Eric Erfanian2ca43182017-08-31 06:57:16 -0700573 .getEnrichedCallManager()
574 .unregisterStateChangedListener(this);
Eric Erfanianccca3152017-02-22 16:32:36 -0800575 } else {
linyuh183cb712017-12-27 17:02:37 -0800576 for (DialerCallListener listener : listeners) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800577 listener.onDialerCallUpdate();
578 }
579 }
580 Trace.endSection();
581 }
582
wangqi9982f0d2017-10-11 17:46:07 -0700583 @SuppressWarnings("MissingPermission")
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700584 private void updateFromTelecomCall() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700585 Trace.beginSection("DialerCall.updateFromTelecomCall");
linyuh183cb712017-12-27 17:02:37 -0800586 LogUtil.v("DialerCall.updateFromTelecomCall", telecomCall.toString());
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700587
roldenburg6bd612f2018-01-18 12:57:19 -0800588 videoTechManager.dispatchCallStateChanged(telecomCall.getState(), getAccountHandle());
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700589
linyuh183cb712017-12-27 17:02:37 -0800590 final int translatedState = translateState(telecomCall.getState());
591 if (state != State.BLOCKED) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800592 setState(translatedState);
linyuh183cb712017-12-27 17:02:37 -0800593 setDisconnectCause(telecomCall.getDetails().getDisconnectCause());
Eric Erfanianccca3152017-02-22 16:32:36 -0800594 }
595
linyuh183cb712017-12-27 17:02:37 -0800596 childCallIds.clear();
597 final int numChildCalls = telecomCall.getChildren().size();
Eric Erfanianccca3152017-02-22 16:32:36 -0800598 for (int i = 0; i < numChildCalls; i++) {
linyuh183cb712017-12-27 17:02:37 -0800599 childCallIds.add(
600 dialerCallDelegate
601 .getDialerCallFromTelecomCall(telecomCall.getChildren().get(i))
Eric Erfanianccca3152017-02-22 16:32:36 -0800602 .getId());
603 }
604
605 // The number of conferenced calls can change over the course of the call, so use the
606 // maximum number of conferenced child calls as the metric for conference call usage.
linyuh183cb712017-12-27 17:02:37 -0800607 logState.conferencedCalls = Math.max(numChildCalls, logState.conferencedCalls);
Eric Erfanianccca3152017-02-22 16:32:36 -0800608
linyuh183cb712017-12-27 17:02:37 -0800609 updateFromCallExtras(telecomCall.getDetails().getExtras());
Eric Erfanianccca3152017-02-22 16:32:36 -0800610
611 // If the handle of the call has changed, update state for the call determining if it is an
612 // emergency call.
linyuh183cb712017-12-27 17:02:37 -0800613 Uri newHandle = telecomCall.getDetails().getHandle();
614 if (!Objects.equals(handle, newHandle)) {
615 handle = newHandle;
Eric Erfanianccca3152017-02-22 16:32:36 -0800616 updateEmergencyCallState();
617 }
618
linyuh183cb712017-12-27 17:02:37 -0800619 TelecomManager telecomManager = context.getSystemService(TelecomManager.class);
Eric Erfanianccca3152017-02-22 16:32:36 -0800620 // If the phone account handle of the call is set, cache capability bit indicating whether
621 // the phone account supports call subjects.
linyuh183cb712017-12-27 17:02:37 -0800622 PhoneAccountHandle newPhoneAccountHandle = telecomCall.getDetails().getAccountHandle();
623 if (!Objects.equals(phoneAccountHandle, newPhoneAccountHandle)) {
624 phoneAccountHandle = newPhoneAccountHandle;
Eric Erfanianccca3152017-02-22 16:32:36 -0800625
linyuh183cb712017-12-27 17:02:37 -0800626 if (phoneAccountHandle != null) {
627 PhoneAccount phoneAccount = telecomManager.getPhoneAccount(phoneAccountHandle);
Eric Erfanianccca3152017-02-22 16:32:36 -0800628 if (phoneAccount != null) {
linyuh183cb712017-12-27 17:02:37 -0800629 isCallSubjectSupported =
Eric Erfanianccca3152017-02-22 16:32:36 -0800630 phoneAccount.hasCapabilities(PhoneAccount.CAPABILITY_CALL_SUBJECT);
wangqida410d32018-03-06 16:51:38 -0800631 if (phoneAccount.hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)) {
632 cacheCarrierConfiguration(phoneAccountHandle);
633 }
Eric Erfanianccca3152017-02-22 16:32:36 -0800634 }
635 }
636 }
linyuh183cb712017-12-27 17:02:37 -0800637 if (PermissionsUtil.hasPermission(context, permission.READ_PHONE_STATE)) {
wangqi9982f0d2017-10-11 17:46:07 -0700638 updateIsVoiceMailNumber();
639 callCapableAccounts = telecomManager.getCallCapablePhoneAccounts();
linyuh183cb712017-12-27 17:02:37 -0800640 countryIso = GeoUtil.getCurrentCountryIso(context);
wangqi9982f0d2017-10-11 17:46:07 -0700641 }
Eric Erfanian2ca43182017-08-31 06:57:16 -0700642 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800643 }
644
645 /**
wangqida410d32018-03-06 16:51:38 -0800646 * Caches frequently used carrier configuration locally.
647 *
648 * @param accountHandle The PhoneAccount handle.
649 */
650 @SuppressLint("MissingPermission")
651 private void cacheCarrierConfiguration(PhoneAccountHandle accountHandle) {
652 if (!PermissionsUtil.hasPermission(context, permission.READ_PHONE_STATE)) {
653 return;
654 }
655 if (VERSION.SDK_INT < VERSION_CODES.O) {
656 return;
657 }
658 // TODO(a bug): This may take several seconds to complete, revisit it to move it to worker
659 // thread.
660 carrierConfig =
661 TelephonyManagerCompat.getTelephonyManagerForPhoneAccountHandle(context, accountHandle)
662 .getCarrierConfig();
663 }
664
665 /**
Eric Erfanianccca3152017-02-22 16:32:36 -0800666 * Tests corruption of the {@code callExtras} bundle by calling {@link
667 * Bundle#containsKey(String)}. If the bundle is corrupted a {@link IllegalArgumentException} will
668 * be thrown and caught by this function.
669 *
670 * @param callExtras the bundle to verify
671 * @return {@code true} if the bundle is corrupted, {@code false} otherwise.
672 */
673 protected boolean areCallExtrasCorrupted(Bundle callExtras) {
674 /**
Eric Erfanian938468d2017-10-24 14:05:52 -0700675 * There's currently a bug in Telephony service (a bug) that could corrupt the extras
Eric Erfanianccca3152017-02-22 16:32:36 -0800676 * bundle, resulting in a IllegalArgumentException while validating data under {@link
677 * Bundle#containsKey(String)}.
678 */
679 try {
680 callExtras.containsKey(Connection.EXTRA_CHILD_ADDRESS);
681 return false;
682 } catch (IllegalArgumentException e) {
683 LogUtil.e(
684 "DialerCall.areCallExtrasCorrupted", "callExtras is corrupted, ignoring exception", e);
685 return true;
686 }
687 }
688
689 protected void updateFromCallExtras(Bundle callExtras) {
690 if (callExtras == null || areCallExtrasCorrupted(callExtras)) {
691 /**
692 * If the bundle is corrupted, abandon information update as a work around. These are not
693 * critical for the dialer to function.
694 */
695 return;
696 }
697 // Check for a change in the child address and notify any listeners.
698 if (callExtras.containsKey(Connection.EXTRA_CHILD_ADDRESS)) {
699 String childNumber = callExtras.getString(Connection.EXTRA_CHILD_ADDRESS);
linyuh183cb712017-12-27 17:02:37 -0800700 if (!Objects.equals(childNumber, this.childNumber)) {
701 this.childNumber = childNumber;
702 for (DialerCallListener listener : listeners) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800703 listener.onDialerCallChildNumberChange();
704 }
705 }
706 }
707
708 // Last forwarded number comes in as an array of strings. We want to choose the
709 // last item in the array. The forwarding numbers arrive independently of when the
710 // call is originally set up, so we need to notify the the UI of the change.
711 if (callExtras.containsKey(Connection.EXTRA_LAST_FORWARDED_NUMBER)) {
712 ArrayList<String> lastForwardedNumbers =
713 callExtras.getStringArrayList(Connection.EXTRA_LAST_FORWARDED_NUMBER);
714
715 if (lastForwardedNumbers != null) {
716 String lastForwardedNumber = null;
717 if (!lastForwardedNumbers.isEmpty()) {
718 lastForwardedNumber = lastForwardedNumbers.get(lastForwardedNumbers.size() - 1);
719 }
720
linyuh183cb712017-12-27 17:02:37 -0800721 if (!Objects.equals(lastForwardedNumber, this.lastForwardedNumber)) {
722 this.lastForwardedNumber = lastForwardedNumber;
723 for (DialerCallListener listener : listeners) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800724 listener.onDialerCallLastForwardedNumberChange();
725 }
726 }
727 }
728 }
729
730 // DialerCall subject is present in the extras at the start of call, so we do not need to
731 // notify any other listeners of this.
732 if (callExtras.containsKey(Connection.EXTRA_CALL_SUBJECT)) {
733 String callSubject = callExtras.getString(Connection.EXTRA_CALL_SUBJECT);
linyuh183cb712017-12-27 17:02:37 -0800734 if (!Objects.equals(this.callSubject, callSubject)) {
735 this.callSubject = callSubject;
Eric Erfanianccca3152017-02-22 16:32:36 -0800736 }
737 }
738 }
739
Eric Erfanianccca3152017-02-22 16:32:36 -0800740 public String getId() {
linyuh183cb712017-12-27 17:02:37 -0800741 return id;
Eric Erfanianccca3152017-02-22 16:32:36 -0800742 }
743
Eric Erfanianc857f902017-05-15 14:05:33 -0700744 /**
745 * @return name appended with a number if the number is restricted/unknown and the user has
746 * received more than one restricted/unknown call.
747 */
748 @Nullable
749 public String updateNameIfRestricted(@Nullable String name) {
linyuh183cb712017-12-27 17:02:37 -0800750 if (name != null && isHiddenNumber() && hiddenId != 0 && hiddenCounter > 1) {
751 return context.getString(R.string.unknown_counter, name, hiddenId);
Eric Erfanianc857f902017-05-15 14:05:33 -0700752 }
753 return name;
754 }
755
756 public static void clearRestrictedCount() {
linyuh183cb712017-12-27 17:02:37 -0800757 hiddenCounter = 0;
Eric Erfanianc857f902017-05-15 14:05:33 -0700758 }
759
760 private boolean isHiddenNumber() {
761 return getNumberPresentation() == TelecomManager.PRESENTATION_RESTRICTED
762 || getNumberPresentation() == TelecomManager.PRESENTATION_UNKNOWN;
763 }
764
Eric Erfanianccca3152017-02-22 16:32:36 -0800765 public boolean hasShownWiFiToLteHandoverToast() {
766 return hasShownWiFiToLteHandoverToast;
767 }
768
769 public void setHasShownWiFiToLteHandoverToast() {
770 hasShownWiFiToLteHandoverToast = true;
771 }
772
773 public boolean showWifiHandoverAlertAsToast() {
774 return doNotShowDialogForHandoffToWifiFailure;
775 }
776
777 public void setDoNotShowDialogForHandoffToWifiFailure(boolean bool) {
778 doNotShowDialogForHandoffToWifiFailure = bool;
779 }
780
wangqida410d32018-03-06 16:51:38 -0800781 public boolean showVideoChargesAlertDialog() {
782 if (carrierConfig == null) {
783 return false;
784 }
785 return carrierConfig.getBoolean(
786 TelephonyManagerCompat.CARRIER_CONFIG_KEY_SHOW_VIDEO_CALL_CHARGES_ALERT_DIALOG_BOOL);
787 }
788
Eric Erfanianccca3152017-02-22 16:32:36 -0800789 public long getTimeAddedMs() {
linyuh183cb712017-12-27 17:02:37 -0800790 return timeAddedMs;
Eric Erfanianccca3152017-02-22 16:32:36 -0800791 }
792
793 @Nullable
794 public String getNumber() {
linyuh183cb712017-12-27 17:02:37 -0800795 return TelecomCallUtil.getNumber(telecomCall);
Eric Erfanianccca3152017-02-22 16:32:36 -0800796 }
797
798 public void blockCall() {
linyuh183cb712017-12-27 17:02:37 -0800799 telecomCall.reject(false, null);
Eric Erfanianccca3152017-02-22 16:32:36 -0800800 setState(State.BLOCKED);
801 }
802
803 @Nullable
804 public Uri getHandle() {
linyuh183cb712017-12-27 17:02:37 -0800805 return telecomCall == null ? null : telecomCall.getDetails().getHandle();
Eric Erfanianccca3152017-02-22 16:32:36 -0800806 }
807
808 public boolean isEmergencyCall() {
linyuh183cb712017-12-27 17:02:37 -0800809 return isEmergencyCall;
Eric Erfanianccca3152017-02-22 16:32:36 -0800810 }
811
812 public boolean isPotentialEmergencyCallback() {
813 // The property PROPERTY_EMERGENCY_CALLBACK_MODE is only set for CDMA calls when the system
814 // is actually in emergency callback mode (ie data is disabled).
815 if (hasProperty(Details.PROPERTY_EMERGENCY_CALLBACK_MODE)) {
816 return true;
817 }
818 // We want to treat any incoming call that arrives a short time after an outgoing emergency call
819 // as a potential emergency callback.
820 if (getExtras() != null
821 && getExtras().getLong(TelecomManagerCompat.EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS, 0)
822 > 0) {
823 long lastEmergencyCallMillis =
824 getExtras().getLong(TelecomManagerCompat.EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS, 0);
825 if (isInEmergencyCallbackWindow(lastEmergencyCallMillis)) {
826 return true;
827 }
828 }
829 return false;
830 }
831
832 boolean isInEmergencyCallbackWindow(long timestampMillis) {
833 long emergencyCallbackWindowMillis =
linyuh183cb712017-12-27 17:02:37 -0800834 ConfigProviderBindings.get(context)
Eric Erfanianccca3152017-02-22 16:32:36 -0800835 .getLong(CONFIG_EMERGENCY_CALLBACK_WINDOW_MILLIS, TimeUnit.MINUTES.toMillis(5));
836 return System.currentTimeMillis() - timestampMillis < emergencyCallbackWindowMillis;
837 }
838
839 public int getState() {
linyuh183cb712017-12-27 17:02:37 -0800840 if (telecomCall != null && telecomCall.getParent() != null) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800841 return State.CONFERENCED;
842 } else {
linyuh183cb712017-12-27 17:02:37 -0800843 return state;
Eric Erfanianccca3152017-02-22 16:32:36 -0800844 }
845 }
846
yueg265089a2017-10-06 14:35:15 -0700847 public int getNonConferenceState() {
linyuh183cb712017-12-27 17:02:37 -0800848 return state;
yueg265089a2017-10-06 14:35:15 -0700849 }
850
Eric Erfanianccca3152017-02-22 16:32:36 -0800851 public void setState(int state) {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700852 if (state == State.INCOMING) {
linyuh183cb712017-12-27 17:02:37 -0800853 logState.isIncoming = true;
Eric Erfanian2ca43182017-08-31 06:57:16 -0700854 } else if (state == State.DISCONNECTED) {
855 long newDuration =
Eric Erfanianccca3152017-02-22 16:32:36 -0800856 getConnectTimeMillis() == 0 ? 0 : System.currentTimeMillis() - getConnectTimeMillis();
linyuh183cb712017-12-27 17:02:37 -0800857 if (this.state != state) {
858 logState.duration = newDuration;
Eric Erfanian2ca43182017-08-31 06:57:16 -0700859 } else {
860 LogUtil.i(
861 "DialerCall.setState",
862 "ignoring state transition from DISCONNECTED to DISCONNECTED."
863 + " Duration would have changed from %s to %s",
linyuh183cb712017-12-27 17:02:37 -0800864 logState.duration,
Eric Erfanian2ca43182017-08-31 06:57:16 -0700865 newDuration);
866 }
Eric Erfanianccca3152017-02-22 16:32:36 -0800867 }
linyuh183cb712017-12-27 17:02:37 -0800868 this.state = state;
Eric Erfanianccca3152017-02-22 16:32:36 -0800869 }
870
871 public int getNumberPresentation() {
linyuh183cb712017-12-27 17:02:37 -0800872 return telecomCall == null ? -1 : telecomCall.getDetails().getHandlePresentation();
Eric Erfanianccca3152017-02-22 16:32:36 -0800873 }
874
875 public int getCnapNamePresentation() {
linyuh183cb712017-12-27 17:02:37 -0800876 return telecomCall == null ? -1 : telecomCall.getDetails().getCallerDisplayNamePresentation();
Eric Erfanianccca3152017-02-22 16:32:36 -0800877 }
878
879 @Nullable
880 public String getCnapName() {
linyuh183cb712017-12-27 17:02:37 -0800881 return telecomCall == null ? null : getTelecomCall().getDetails().getCallerDisplayName();
Eric Erfanianccca3152017-02-22 16:32:36 -0800882 }
883
884 public Bundle getIntentExtras() {
linyuh183cb712017-12-27 17:02:37 -0800885 return telecomCall.getDetails().getIntentExtras();
Eric Erfanianccca3152017-02-22 16:32:36 -0800886 }
887
888 @Nullable
889 public Bundle getExtras() {
linyuh183cb712017-12-27 17:02:37 -0800890 return telecomCall == null ? null : telecomCall.getDetails().getExtras();
Eric Erfanianccca3152017-02-22 16:32:36 -0800891 }
892
893 /** @return The child number for the call, or {@code null} if none specified. */
894 public String getChildNumber() {
linyuh183cb712017-12-27 17:02:37 -0800895 return childNumber;
Eric Erfanianccca3152017-02-22 16:32:36 -0800896 }
897
898 /** @return The last forwarded number for the call, or {@code null} if none specified. */
899 public String getLastForwardedNumber() {
linyuh183cb712017-12-27 17:02:37 -0800900 return lastForwardedNumber;
Eric Erfanianccca3152017-02-22 16:32:36 -0800901 }
902
wangqif4ba3452018-01-09 11:26:29 -0800903 public boolean isCallForwarded() {
904 return isCallForwarded;
905 }
906
Eric Erfanianccca3152017-02-22 16:32:36 -0800907 /** @return The call subject, or {@code null} if none specified. */
908 public String getCallSubject() {
linyuh183cb712017-12-27 17:02:37 -0800909 return callSubject;
Eric Erfanianccca3152017-02-22 16:32:36 -0800910 }
911
912 /**
913 * @return {@code true} if the call's phone account supports call subjects, {@code false}
914 * otherwise.
915 */
916 public boolean isCallSubjectSupported() {
linyuh183cb712017-12-27 17:02:37 -0800917 return isCallSubjectSupported;
Eric Erfanianccca3152017-02-22 16:32:36 -0800918 }
919
920 /** Returns call disconnect cause, defined by {@link DisconnectCause}. */
921 public DisconnectCause getDisconnectCause() {
linyuh183cb712017-12-27 17:02:37 -0800922 if (state == State.DISCONNECTED || state == State.IDLE) {
923 return disconnectCause;
Eric Erfanianccca3152017-02-22 16:32:36 -0800924 }
925
926 return new DisconnectCause(DisconnectCause.UNKNOWN);
927 }
928
929 public void setDisconnectCause(DisconnectCause disconnectCause) {
linyuh183cb712017-12-27 17:02:37 -0800930 this.disconnectCause = disconnectCause;
931 logState.disconnectCause = this.disconnectCause;
Eric Erfanianccca3152017-02-22 16:32:36 -0800932 }
933
934 /** Returns the possible text message responses. */
935 public List<String> getCannedSmsResponses() {
linyuh183cb712017-12-27 17:02:37 -0800936 return telecomCall.getCannedTextResponses();
Eric Erfanianccca3152017-02-22 16:32:36 -0800937 }
938
939 /** Checks if the call supports the given set of capabilities supplied as a bit mask. */
940 public boolean can(int capabilities) {
linyuh183cb712017-12-27 17:02:37 -0800941 int supportedCapabilities = telecomCall.getDetails().getCallCapabilities();
Eric Erfanianccca3152017-02-22 16:32:36 -0800942
943 if ((capabilities & Call.Details.CAPABILITY_MERGE_CONFERENCE) != 0) {
944 // We allow you to merge if the capabilities allow it or if it is a call with
945 // conferenceable calls.
linyuh183cb712017-12-27 17:02:37 -0800946 if (telecomCall.getConferenceableCalls().isEmpty()
Eric Erfanianccca3152017-02-22 16:32:36 -0800947 && ((Call.Details.CAPABILITY_MERGE_CONFERENCE & supportedCapabilities) == 0)) {
948 // Cannot merge calls if there are no calls to merge with.
949 return false;
950 }
951 capabilities &= ~Call.Details.CAPABILITY_MERGE_CONFERENCE;
952 }
953 return (capabilities == (capabilities & supportedCapabilities));
954 }
955
956 public boolean hasProperty(int property) {
linyuh183cb712017-12-27 17:02:37 -0800957 return telecomCall.getDetails().hasProperty(property);
Eric Erfanianccca3152017-02-22 16:32:36 -0800958 }
959
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700960 @NonNull
Eric Erfanianccca3152017-02-22 16:32:36 -0800961 public String getUniqueCallId() {
962 return uniqueCallId;
963 }
964
965 /** Gets the time when the call first became active. */
966 public long getConnectTimeMillis() {
linyuh183cb712017-12-27 17:02:37 -0800967 return telecomCall.getDetails().getConnectTimeMillis();
Eric Erfanianccca3152017-02-22 16:32:36 -0800968 }
969
wangqied677ef2018-04-04 12:03:00 -0700970 /**
971 * Gets the time when the call is created (see {@link Details#getCreationTimeMillis()}). This is
972 * the same time that is logged as the start time in the Call Log (see {@link
973 * android.provider.CallLog.Calls#DATE}).
974 */
975 @TargetApi(26)
976 public long getCreationTimeMillis() {
977 return telecomCall.getDetails().getCreationTimeMillis();
978 }
979
Eric Erfanianccca3152017-02-22 16:32:36 -0800980 public boolean isConferenceCall() {
981 return hasProperty(Call.Details.PROPERTY_CONFERENCE);
982 }
983
984 @Nullable
985 public GatewayInfo getGatewayInfo() {
linyuh183cb712017-12-27 17:02:37 -0800986 return telecomCall == null ? null : telecomCall.getDetails().getGatewayInfo();
Eric Erfanianccca3152017-02-22 16:32:36 -0800987 }
988
989 @Nullable
990 public PhoneAccountHandle getAccountHandle() {
linyuh183cb712017-12-27 17:02:37 -0800991 return telecomCall == null ? null : telecomCall.getDetails().getAccountHandle();
Eric Erfanianccca3152017-02-22 16:32:36 -0800992 }
993
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700994 /** @return The {@link VideoCall} instance associated with the {@link Call}. */
Eric Erfanianccca3152017-02-22 16:32:36 -0800995 public VideoCall getVideoCall() {
linyuh183cb712017-12-27 17:02:37 -0800996 return telecomCall == null ? null : telecomCall.getVideoCall();
Eric Erfanianccca3152017-02-22 16:32:36 -0800997 }
998
999 public List<String> getChildCallIds() {
linyuh183cb712017-12-27 17:02:37 -08001000 return childCallIds;
Eric Erfanianccca3152017-02-22 16:32:36 -08001001 }
1002
1003 public String getParentId() {
linyuh183cb712017-12-27 17:02:37 -08001004 Call parentCall = telecomCall.getParent();
Eric Erfanianccca3152017-02-22 16:32:36 -08001005 if (parentCall != null) {
linyuh183cb712017-12-27 17:02:37 -08001006 return dialerCallDelegate.getDialerCallFromTelecomCall(parentCall).getId();
Eric Erfanianccca3152017-02-22 16:32:36 -08001007 }
1008 return null;
1009 }
1010
1011 public int getVideoState() {
linyuh183cb712017-12-27 17:02:37 -08001012 return telecomCall.getDetails().getVideoState();
Eric Erfanianccca3152017-02-22 16:32:36 -08001013 }
1014
1015 public boolean isVideoCall() {
roldenburg2cec3802017-10-11 16:26:51 -07001016 return getVideoTech().isTransmittingOrReceiving() || VideoProfile.isVideo(getVideoState());
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001017 }
1018
wangqi8d407a02018-02-15 15:32:52 -08001019 @TargetApi(28)
wangqif6be6172018-03-30 15:57:56 -07001020 public boolean isActiveRttCall() {
wangqi219b8702018-02-13 09:34:41 -08001021 if (BuildCompat.isAtLeastP()) {
1022 return getTelecomCall().isRttActive();
1023 } else {
1024 return false;
1025 }
1026 }
1027
wangqi153af2f2018-02-15 16:21:49 -08001028 @TargetApi(28)
1029 public RttCall getRttCall() {
wangqif6be6172018-03-30 15:57:56 -07001030 if (!isActiveRttCall()) {
wangqi153af2f2018-02-15 16:21:49 -08001031 return null;
1032 }
1033 return getTelecomCall().getRttCall();
1034 }
1035
wangqif6be6172018-03-30 15:57:56 -07001036 @TargetApi(28)
1037 public boolean canUpgradeToRttCall() {
1038 PhoneAccount phoneAccount = getPhoneAccount();
1039 if (phoneAccount == null) {
1040 return false;
1041 }
1042 if (!phoneAccount.hasCapabilities(PhoneAccount.CAPABILITY_RTT)) {
1043 return false;
1044 }
1045 if (isActiveRttCall()) {
1046 return false;
1047 }
1048 if (isVideoCall()) {
1049 return false;
1050 }
1051 if (isConferenceCall()) {
1052 return false;
1053 }
1054 if (CallList.getInstance().hasActiveRttCall()) {
1055 return false;
1056 }
1057 return true;
1058 }
1059
1060 @TargetApi(28)
1061 public void sendRttUpgradeRequest() {
1062 getTelecomCall().sendRttRequest();
1063 }
1064
wangqibc28ea72018-04-02 16:23:00 -07001065 @TargetApi(28)
1066 public void respondToRttRequest(boolean accept, int rttRequestId) {
1067 getTelecomCall().respondToRttRequest(rttRequestId, accept);
1068 }
1069
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001070 public boolean hasReceivedVideoUpgradeRequest() {
1071 return VideoUtils.hasReceivedVideoUpgradeRequest(getVideoTech().getSessionModificationState());
1072 }
1073
1074 public boolean hasSentVideoUpgradeRequest() {
1075 return VideoUtils.hasSentVideoUpgradeRequest(getVideoTech().getSessionModificationState());
Eric Erfanianccca3152017-02-22 16:32:36 -08001076 }
1077
wangqi219b8702018-02-13 09:34:41 -08001078 public boolean hasSentRttUpgradeRequest() {
wangqi219b8702018-02-13 09:34:41 -08001079 return false;
1080 }
1081
Eric Erfanianccca3152017-02-22 16:32:36 -08001082 /**
1083 * Determines if the call handle is an emergency number or not and caches the result to avoid
1084 * repeated calls to isEmergencyNumber.
1085 */
1086 private void updateEmergencyCallState() {
linyuh183cb712017-12-27 17:02:37 -08001087 isEmergencyCall = TelecomCallUtil.isEmergencyCall(telecomCall);
Eric Erfanianccca3152017-02-22 16:32:36 -08001088 }
1089
Eric Erfanianccca3152017-02-22 16:32:36 -08001090 public LogState getLogState() {
linyuh183cb712017-12-27 17:02:37 -08001091 return logState;
Eric Erfanianccca3152017-02-22 16:32:36 -08001092 }
1093
1094 /**
1095 * Determines if the call is an external call.
1096 *
1097 * <p>An external call is one which does not exist locally for the {@link
1098 * android.telecom.ConnectionService} it is associated with.
1099 *
Eric Erfanianccca3152017-02-22 16:32:36 -08001100 * @return {@code true} if the call is an external call, {@code false} otherwise.
1101 */
linyuh437ae952018-03-26 12:46:18 -07001102 boolean isExternalCall() {
1103 return hasProperty(CallCompat.Details.PROPERTY_IS_EXTERNAL_CALL);
Eric Erfanianccca3152017-02-22 16:32:36 -08001104 }
1105
1106 /**
Eric Erfanianccca3152017-02-22 16:32:36 -08001107 * Determines if answering this call will cause an ongoing video call to be dropped.
1108 *
1109 * @return {@code true} if answering this call will drop an ongoing video call, {@code false}
1110 * otherwise.
1111 */
1112 public boolean answeringDisconnectsForegroundVideoCall() {
1113 Bundle extras = getExtras();
1114 if (extras == null
1115 || !extras.containsKey(CallCompat.Details.EXTRA_ANSWERING_DROPS_FOREGROUND_CALL)) {
1116 return false;
1117 }
1118 return extras.getBoolean(CallCompat.Details.EXTRA_ANSWERING_DROPS_FOREGROUND_CALL);
1119 }
1120
1121 private void parseCallSpecificAppData() {
1122 if (isExternalCall()) {
1123 return;
1124 }
1125
linyuh183cb712017-12-27 17:02:37 -08001126 logState.callSpecificAppData = CallIntentParser.getCallSpecificAppData(getIntentExtras());
1127 if (logState.callSpecificAppData == null) {
Eric Erfanian8369df02017-05-03 10:27:13 -07001128
linyuh183cb712017-12-27 17:02:37 -08001129 logState.callSpecificAppData =
Eric Erfanian8369df02017-05-03 10:27:13 -07001130 CallSpecificAppData.newBuilder()
1131 .setCallInitiationType(CallInitiationType.Type.EXTERNAL_INITIATION)
1132 .build();
Eric Erfanianccca3152017-02-22 16:32:36 -08001133 }
1134 if (getState() == State.INCOMING) {
linyuh183cb712017-12-27 17:02:37 -08001135 logState.callSpecificAppData =
1136 logState
Eric Erfanian8369df02017-05-03 10:27:13 -07001137 .callSpecificAppData
1138 .toBuilder()
1139 .setCallInitiationType(CallInitiationType.Type.INCOMING_INITIATION)
1140 .build();
Eric Erfanianccca3152017-02-22 16:32:36 -08001141 }
1142 }
1143
1144 @Override
1145 public String toString() {
linyuh183cb712017-12-27 17:02:37 -08001146 if (telecomCall == null) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001147 // This should happen only in testing since otherwise we would never have a null
1148 // Telecom call.
linyuh183cb712017-12-27 17:02:37 -08001149 return String.valueOf(id);
Eric Erfanianccca3152017-02-22 16:32:36 -08001150 }
1151
1152 return String.format(
1153 Locale.US,
1154 "[%s, %s, %s, %s, children:%s, parent:%s, "
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001155 + "conferenceable:%s, videoState:%s, mSessionModificationState:%d, CameraDir:%s]",
linyuh183cb712017-12-27 17:02:37 -08001156 id,
Eric Erfanianccca3152017-02-22 16:32:36 -08001157 State.toString(getState()),
linyuh183cb712017-12-27 17:02:37 -08001158 Details.capabilitiesToString(telecomCall.getDetails().getCallCapabilities()),
1159 Details.propertiesToString(telecomCall.getDetails().getCallProperties()),
1160 childCallIds,
Eric Erfanianccca3152017-02-22 16:32:36 -08001161 getParentId(),
linyuh183cb712017-12-27 17:02:37 -08001162 this.telecomCall.getConferenceableCalls(),
1163 VideoProfile.videoStateToString(telecomCall.getDetails().getVideoState()),
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001164 getVideoTech().getSessionModificationState(),
1165 getCameraDir());
Eric Erfanianccca3152017-02-22 16:32:36 -08001166 }
1167
1168 public String toSimpleString() {
1169 return super.toString();
1170 }
1171
1172 @CallHistoryStatus
1173 public int getCallHistoryStatus() {
linyuh183cb712017-12-27 17:02:37 -08001174 return callHistoryStatus;
Eric Erfanianccca3152017-02-22 16:32:36 -08001175 }
1176
1177 public void setCallHistoryStatus(@CallHistoryStatus int callHistoryStatus) {
linyuh183cb712017-12-27 17:02:37 -08001178 this.callHistoryStatus = callHistoryStatus;
Eric Erfanianccca3152017-02-22 16:32:36 -08001179 }
1180
1181 public boolean didShowCameraPermission() {
1182 return didShowCameraPermission;
1183 }
1184
1185 public void setDidShowCameraPermission(boolean didShow) {
1186 didShowCameraPermission = didShow;
1187 }
1188
wangqida410d32018-03-06 16:51:38 -08001189 public boolean didDismissVideoChargesAlertDialog() {
1190 return didDismissVideoChargesAlertDialog;
1191 }
1192
1193 public void setDidDismissVideoChargesAlertDialog(boolean didDismiss) {
1194 didDismissVideoChargesAlertDialog = didDismiss;
1195 }
1196
Eric Erfanian938468d2017-10-24 14:05:52 -07001197 @Nullable
1198 public Boolean isInGlobalSpamList() {
Eric Erfanianccca3152017-02-22 16:32:36 -08001199 return isInGlobalSpamList;
1200 }
1201
1202 public void setIsInGlobalSpamList(boolean inSpamList) {
1203 isInGlobalSpamList = inSpamList;
1204 }
1205
Eric Erfanian938468d2017-10-24 14:05:52 -07001206 @Nullable
1207 public Boolean isInUserSpamList() {
Eric Erfanianccca3152017-02-22 16:32:36 -08001208 return isInUserSpamList;
1209 }
1210
1211 public void setIsInUserSpamList(boolean inSpamList) {
1212 isInUserSpamList = inSpamList;
1213 }
1214
Eric Erfanian938468d2017-10-24 14:05:52 -07001215 @Nullable
1216 public Boolean isInUserWhiteList() {
Eric Erfanianccca3152017-02-22 16:32:36 -08001217 return isInUserWhiteList;
1218 }
1219
1220 public void setIsInUserWhiteList(boolean inWhiteList) {
1221 isInUserWhiteList = inWhiteList;
1222 }
1223
1224 public boolean isSpam() {
linyuh183cb712017-12-27 17:02:37 -08001225 return isSpam;
Eric Erfanianccca3152017-02-22 16:32:36 -08001226 }
1227
1228 public void setSpam(boolean isSpam) {
linyuh183cb712017-12-27 17:02:37 -08001229 this.isSpam = isSpam;
Eric Erfanianccca3152017-02-22 16:32:36 -08001230 }
1231
1232 public boolean isBlocked() {
linyuh183cb712017-12-27 17:02:37 -08001233 return isBlocked;
Eric Erfanianccca3152017-02-22 16:32:36 -08001234 }
1235
1236 public void setBlockedStatus(boolean isBlocked) {
linyuh183cb712017-12-27 17:02:37 -08001237 this.isBlocked = isBlocked;
Eric Erfanianccca3152017-02-22 16:32:36 -08001238 }
1239
1240 public boolean isRemotelyHeld() {
1241 return isRemotelyHeld;
1242 }
1243
Eric Erfanian2ca43182017-08-31 06:57:16 -07001244 public boolean isMergeInProcess() {
1245 return isMergeInProcess;
1246 }
1247
Eric Erfanianccca3152017-02-22 16:32:36 -08001248 public boolean isIncoming() {
linyuh183cb712017-12-27 17:02:37 -08001249 return logState.isIncoming;
Eric Erfanianccca3152017-02-22 16:32:36 -08001250 }
1251
erfanian2cf2c342017-12-21 12:01:33 -08001252 /**
1253 * Try and determine if the call used assisted dialing.
1254 *
1255 * <p>We will not be able to verify a call underwent assisted dialing until the Platform
1256 * implmentation is complete in P+.
1257 *
1258 * @return a boolean indicating assisted dialing may have been performed
1259 */
Eric Erfanian2ca43182017-08-31 06:57:16 -07001260 public boolean isAssistedDialed() {
1261 if (getIntentExtras() != null) {
erfaniand2e5d0b2018-03-02 14:54:35 -08001262 // P and below uses the existence of USE_ASSISTED_DIALING to indicate assisted dialing
erfanian2cf2c342017-12-21 12:01:33 -08001263 // was used. The Dialer client is responsible for performing assisted dialing before
1264 // placing the outgoing call.
1265 //
1266 // The existence of the assisted dialing extras indicates that assisted dialing took place.
1267 if (getIntentExtras().getBoolean(TelephonyManagerCompat.USE_ASSISTED_DIALING, false)
1268 && getAssistedDialingExtras() != null
1269 && Build.VERSION.SDK_INT <= ConcreteCreator.BUILD_CODE_CEILING) {
1270 return true;
1271 }
1272 }
1273
Eric Erfanian2ca43182017-08-31 06:57:16 -07001274 return false;
1275 }
1276
erfanian2cf2c342017-12-21 12:01:33 -08001277 @Nullable
erfaniand0f207f2017-10-11 12:23:29 -07001278 public TransformationInfo getAssistedDialingExtras() {
erfanian2cf2c342017-12-21 12:01:33 -08001279 if (getIntentExtras() == null) {
1280 return null;
erfaniand0f207f2017-10-11 12:23:29 -07001281 }
erfanian2cf2c342017-12-21 12:01:33 -08001282
1283 if (getIntentExtras().getBundle(TelephonyManagerCompat.ASSISTED_DIALING_EXTRAS) == null) {
1284 return null;
1285 }
1286
erfanianf2556612018-01-23 09:55:59 -08001287 // Used in N-OMR1
erfanian2cf2c342017-12-21 12:01:33 -08001288 return TransformationInfo.newInstanceFromBundle(
1289 getIntentExtras().getBundle(TelephonyManagerCompat.ASSISTED_DIALING_EXTRAS));
erfaniand0f207f2017-10-11 12:23:29 -07001290 }
1291
Eric Erfanianccca3152017-02-22 16:32:36 -08001292 public LatencyReport getLatencyReport() {
linyuh183cb712017-12-27 17:02:37 -08001293 return latencyReport;
Eric Erfanianccca3152017-02-22 16:32:36 -08001294 }
1295
Eric Erfanian2ca43182017-08-31 06:57:16 -07001296 public int getAnswerAndReleaseButtonDisplayedTimes() {
1297 return answerAndReleaseButtonDisplayedTimes;
1298 }
1299
1300 public void increaseAnswerAndReleaseButtonDisplayedTimes() {
1301 answerAndReleaseButtonDisplayedTimes++;
1302 }
1303
1304 public boolean getReleasedByAnsweringSecondCall() {
1305 return releasedByAnsweringSecondCall;
1306 }
1307
1308 public void setReleasedByAnsweringSecondCall(boolean releasedByAnsweringSecondCall) {
1309 this.releasedByAnsweringSecondCall = releasedByAnsweringSecondCall;
1310 }
1311
1312 public int getSecondCallWithoutAnswerAndReleasedButtonTimes() {
1313 return secondCallWithoutAnswerAndReleasedButtonTimes;
1314 }
1315
1316 public void increaseSecondCallWithoutAnswerAndReleasedButtonTimes() {
1317 secondCallWithoutAnswerAndReleasedButtonTimes++;
1318 }
1319
Eric Erfanian8369df02017-05-03 10:27:13 -07001320 @Nullable
1321 public EnrichedCallCapabilities getEnrichedCallCapabilities() {
linyuh183cb712017-12-27 17:02:37 -08001322 return enrichedCallCapabilities;
Eric Erfanian8369df02017-05-03 10:27:13 -07001323 }
1324
1325 public void setEnrichedCallCapabilities(
1326 @Nullable EnrichedCallCapabilities mEnrichedCallCapabilities) {
linyuh183cb712017-12-27 17:02:37 -08001327 this.enrichedCallCapabilities = mEnrichedCallCapabilities;
Eric Erfanian8369df02017-05-03 10:27:13 -07001328 }
1329
1330 @Nullable
1331 public Session getEnrichedCallSession() {
linyuh183cb712017-12-27 17:02:37 -08001332 return enrichedCallSession;
Eric Erfanian8369df02017-05-03 10:27:13 -07001333 }
1334
1335 public void setEnrichedCallSession(@Nullable Session mEnrichedCallSession) {
linyuh183cb712017-12-27 17:02:37 -08001336 this.enrichedCallSession = mEnrichedCallSession;
Eric Erfanian8369df02017-05-03 10:27:13 -07001337 }
1338
Eric Erfanianccca3152017-02-22 16:32:36 -08001339 public void unregisterCallback() {
linyuh183cb712017-12-27 17:02:37 -08001340 telecomCall.unregisterCallback(telecomCallCallback);
Eric Erfanianccca3152017-02-22 16:32:36 -08001341 }
1342
Eric Erfanianccca3152017-02-22 16:32:36 -08001343 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1344 LogUtil.i(
1345 "DialerCall.phoneAccountSelected",
1346 "accountHandle: %s, setDefault: %b",
1347 accountHandle,
1348 setDefault);
linyuh183cb712017-12-27 17:02:37 -08001349 telecomCall.phoneAccountSelected(accountHandle, setDefault);
Eric Erfanianccca3152017-02-22 16:32:36 -08001350 }
1351
1352 public void disconnect() {
1353 LogUtil.i("DialerCall.disconnect", "");
1354 setState(DialerCall.State.DISCONNECTING);
linyuh183cb712017-12-27 17:02:37 -08001355 for (DialerCallListener listener : listeners) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001356 listener.onDialerCallUpdate();
1357 }
linyuh183cb712017-12-27 17:02:37 -08001358 telecomCall.disconnect();
Eric Erfanianccca3152017-02-22 16:32:36 -08001359 }
1360
1361 public void hold() {
1362 LogUtil.i("DialerCall.hold", "");
linyuh183cb712017-12-27 17:02:37 -08001363 telecomCall.hold();
Eric Erfanianccca3152017-02-22 16:32:36 -08001364 }
1365
1366 public void unhold() {
1367 LogUtil.i("DialerCall.unhold", "");
linyuh183cb712017-12-27 17:02:37 -08001368 telecomCall.unhold();
Eric Erfanianccca3152017-02-22 16:32:36 -08001369 }
1370
1371 public void splitFromConference() {
1372 LogUtil.i("DialerCall.splitFromConference", "");
linyuh183cb712017-12-27 17:02:37 -08001373 telecomCall.splitFromConference();
Eric Erfanianccca3152017-02-22 16:32:36 -08001374 }
1375
1376 public void answer(int videoState) {
1377 LogUtil.i("DialerCall.answer", "videoState: " + videoState);
linyuh183cb712017-12-27 17:02:37 -08001378 telecomCall.answer(videoState);
Eric Erfanianccca3152017-02-22 16:32:36 -08001379 }
1380
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001381 public void answer() {
linyuh183cb712017-12-27 17:02:37 -08001382 answer(telecomCall.getDetails().getVideoState());
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001383 }
1384
Eric Erfanianccca3152017-02-22 16:32:36 -08001385 public void reject(boolean rejectWithMessage, String message) {
1386 LogUtil.i("DialerCall.reject", "");
linyuh183cb712017-12-27 17:02:37 -08001387 telecomCall.reject(rejectWithMessage, message);
Eric Erfanianccca3152017-02-22 16:32:36 -08001388 }
1389
1390 /** Return the string label to represent the call provider */
1391 public String getCallProviderLabel() {
1392 if (callProviderLabel == null) {
1393 PhoneAccount account = getPhoneAccount();
1394 if (account != null && !TextUtils.isEmpty(account.getLabel())) {
wangqi9982f0d2017-10-11 17:46:07 -07001395 if (callCapableAccounts != null && callCapableAccounts.size() > 1) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001396 callProviderLabel = account.getLabel().toString();
1397 }
1398 }
1399 if (callProviderLabel == null) {
1400 callProviderLabel = "";
1401 }
1402 }
1403 return callProviderLabel;
1404 }
1405
1406 private PhoneAccount getPhoneAccount() {
1407 PhoneAccountHandle accountHandle = getAccountHandle();
1408 if (accountHandle == null) {
1409 return null;
1410 }
linyuh183cb712017-12-27 17:02:37 -08001411 return context.getSystemService(TelecomManager.class).getPhoneAccount(accountHandle);
Eric Erfanianccca3152017-02-22 16:32:36 -08001412 }
1413
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001414 public VideoTech getVideoTech() {
roldenburg7bb96232017-10-09 10:32:05 -07001415 if (videoTech == null) {
roldenburg6bd612f2018-01-18 12:57:19 -08001416 videoTech = videoTechManager.getVideoTech(getAccountHandle());
roldenburg7bb96232017-10-09 10:32:05 -07001417
1418 // Only store the first video tech type found to be available during the life of the call.
1419 if (selectedAvailableVideoTechType == com.android.dialer.logging.VideoTech.Type.NONE) {
1420 // Update the video tech.
1421 selectedAvailableVideoTechType = videoTech.getVideoTechType();
1422 }
1423 }
Eric Erfanian2ca43182017-08-31 06:57:16 -07001424 return videoTech;
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001425 }
1426
Eric Erfanianccca3152017-02-22 16:32:36 -08001427 public String getCallbackNumber() {
1428 if (callbackNumber == null) {
1429 // Show the emergency callback number if either:
1430 // 1. This is an emergency call.
1431 // 2. The phone is in Emergency Callback Mode, which means we should show the callback
1432 // number.
1433 boolean showCallbackNumber = hasProperty(Details.PROPERTY_EMERGENCY_CALLBACK_MODE);
1434
1435 if (isEmergencyCall() || showCallbackNumber) {
wangqi339b4f32017-09-18 14:32:09 -07001436 callbackNumber =
linyuh183cb712017-12-27 17:02:37 -08001437 context.getSystemService(TelecomManager.class).getLine1Number(getAccountHandle());
Eric Erfanianccca3152017-02-22 16:32:36 -08001438 }
1439
Eric Erfanianccca3152017-02-22 16:32:36 -08001440 if (callbackNumber == null) {
1441 callbackNumber = "";
1442 }
1443 }
1444 return callbackNumber;
1445 }
1446
wangqi97539352017-09-25 11:15:16 -07001447 public String getSimCountryIso() {
1448 String simCountryIso =
linyuh183cb712017-12-27 17:02:37 -08001449 TelephonyManagerCompat.getTelephonyManagerForPhoneAccountHandle(context, getAccountHandle())
wangqi97539352017-09-25 11:15:16 -07001450 .getSimCountryIso();
1451 if (!TextUtils.isEmpty(simCountryIso)) {
1452 simCountryIso = simCountryIso.toUpperCase(Locale.US);
1453 }
1454 return simCountryIso;
1455 }
1456
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001457 @Override
1458 public void onVideoTechStateChanged() {
1459 update();
1460 }
1461
1462 @Override
1463 public void onSessionModificationStateChanged() {
wangqi9982f0d2017-10-11 17:46:07 -07001464 Trace.beginSection("DialerCall.onSessionModificationStateChanged");
linyuh183cb712017-12-27 17:02:37 -08001465 for (DialerCallListener listener : listeners) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001466 listener.onDialerCallSessionModificationStateChange();
1467 }
wangqi9982f0d2017-10-11 17:46:07 -07001468 Trace.endSection();
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001469 }
1470
1471 @Override
1472 public void onCameraDimensionsChanged(int width, int height) {
1473 InCallVideoCallCallbackNotifier.getInstance().cameraDimensionsChanged(this, width, height);
1474 }
1475
1476 @Override
1477 public void onPeerDimensionsChanged(int width, int height) {
1478 InCallVideoCallCallbackNotifier.getInstance().peerDimensionsChanged(this, width, height);
1479 }
1480
1481 @Override
1482 public void onVideoUpgradeRequestReceived() {
1483 LogUtil.enterBlock("DialerCall.onVideoUpgradeRequestReceived");
1484
linyuh183cb712017-12-27 17:02:37 -08001485 for (DialerCallListener listener : listeners) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001486 listener.onDialerCallUpgradeToVideo();
1487 }
1488
1489 update();
Eric Erfanian8369df02017-05-03 10:27:13 -07001490
linyuh183cb712017-12-27 17:02:37 -08001491 Logger.get(context)
Eric Erfanian8369df02017-05-03 10:27:13 -07001492 .logCallImpression(
1493 DialerImpression.Type.VIDEO_CALL_REQUEST_RECEIVED, getUniqueCallId(), getTimeAddedMs());
1494 }
1495
1496 @Override
1497 public void onUpgradedToVideo(boolean switchToSpeaker) {
1498 LogUtil.enterBlock("DialerCall.onUpgradedToVideo");
1499
1500 if (!switchToSpeaker) {
1501 return;
1502 }
1503
1504 CallAudioState audioState = AudioModeProvider.getInstance().getAudioState();
1505
1506 if (0 != (CallAudioState.ROUTE_BLUETOOTH & audioState.getSupportedRouteMask())) {
1507 LogUtil.e(
1508 "DialerCall.onUpgradedToVideo",
1509 "toggling speakerphone not allowed when bluetooth supported.");
1510 return;
1511 }
1512
1513 if (audioState.getRoute() == CallAudioState.ROUTE_SPEAKER) {
1514 return;
1515 }
1516
1517 TelecomAdapter.getInstance().setAudioRoute(CallAudioState.ROUTE_SPEAKER);
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001518 }
1519
Eric Erfanian2ca43182017-08-31 06:57:16 -07001520 @Override
1521 public void onCapabilitiesUpdated() {
1522 if (getNumber() == null) {
1523 return;
1524 }
1525 EnrichedCallCapabilities capabilities =
linyuh183cb712017-12-27 17:02:37 -08001526 EnrichedCallComponent.get(context).getEnrichedCallManager().getCapabilities(getNumber());
Eric Erfanian2ca43182017-08-31 06:57:16 -07001527 if (capabilities != null) {
1528 setEnrichedCallCapabilities(capabilities);
1529 update();
1530 }
1531 }
1532
1533 @Override
1534 public void onEnrichedCallStateChanged() {
1535 updateEnrichedCallSession();
1536 }
1537
1538 @Override
1539 public void onImpressionLoggingNeeded(DialerImpression.Type impressionType) {
linyuh183cb712017-12-27 17:02:37 -08001540 Logger.get(context).logCallImpression(impressionType, getUniqueCallId(), getTimeAddedMs());
twyendde01c52017-09-22 10:07:31 -07001541 if (impressionType == DialerImpression.Type.LIGHTBRINGER_UPGRADE_REQUESTED) {
1542 if (getLogState().contactLookupResult == Type.NOT_FOUND) {
linyuh183cb712017-12-27 17:02:37 -08001543 Logger.get(context)
twyendde01c52017-09-22 10:07:31 -07001544 .logCallImpression(
1545 DialerImpression.Type.LIGHTBRINGER_NON_CONTACT_UPGRADE_REQUESTED,
1546 getUniqueCallId(),
1547 getTimeAddedMs());
1548 }
1549 }
Eric Erfanian2ca43182017-08-31 06:57:16 -07001550 }
1551
1552 private void updateEnrichedCallSession() {
1553 if (getNumber() == null) {
1554 return;
1555 }
1556 if (getEnrichedCallSession() != null) {
1557 // State changes to existing sessions are currently handled by the UI components (which have
1558 // their own listeners). Someday instead we could remove those and just call update() here and
1559 // have the usual onDialerCallUpdate update the UI.
1560 dispatchOnEnrichedCallSessionUpdate();
1561 return;
1562 }
1563
linyuh183cb712017-12-27 17:02:37 -08001564 EnrichedCallManager manager = EnrichedCallComponent.get(context).getEnrichedCallManager();
Eric Erfanian2ca43182017-08-31 06:57:16 -07001565
1566 Filter filter =
1567 isIncoming()
1568 ? manager.createIncomingCallComposerFilter()
1569 : manager.createOutgoingCallComposerFilter();
1570
1571 Session session = manager.getSession(getUniqueCallId(), getNumber(), filter);
1572 if (session == null) {
1573 return;
1574 }
1575
1576 session.setUniqueDialerCallId(getUniqueCallId());
1577 setEnrichedCallSession(session);
1578
1579 LogUtil.i(
1580 "DialerCall.updateEnrichedCallSession",
1581 "setting session %d's dialer id to %s",
1582 session.getSessionId(),
1583 getUniqueCallId());
1584
1585 dispatchOnEnrichedCallSessionUpdate();
1586 }
1587
1588 private void dispatchOnEnrichedCallSessionUpdate() {
linyuh183cb712017-12-27 17:02:37 -08001589 for (DialerCallListener listener : listeners) {
Eric Erfanian2ca43182017-08-31 06:57:16 -07001590 listener.onEnrichedCallSessionUpdate();
1591 }
1592 }
1593
1594 void onRemovedFromCallList() {
wangqif1861052018-04-19 15:06:06 -07001595 LogUtil.enterBlock("DialerCall.onRemovedFromCallList");
Eric Erfanian2ca43182017-08-31 06:57:16 -07001596 // Ensure we clean up when this call is removed.
linyuh183cb712017-12-27 17:02:37 -08001597 videoTechManager.dispatchRemovedFromCallList();
wangqif1861052018-04-19 15:06:06 -07001598 if (rttTranscript != null) {
1599 Futures.addCallback(
1600 RttTranscriptUtil.saveRttTranscript(context, rttTranscript),
1601 new DefaultFutureCallback<>(),
1602 MoreExecutors.directExecutor());
1603 // Sets to null so it won't be saved again when called multiple times.
1604 rttTranscript = null;
1605 }
Eric Erfanian2ca43182017-08-31 06:57:16 -07001606 }
1607
wangqi4d705e52017-09-28 12:23:35 -07001608 public com.android.dialer.logging.VideoTech.Type getSelectedAvailableVideoTechType() {
1609 return selectedAvailableVideoTechType;
yueg457b3972017-09-18 15:11:47 -07001610 }
1611
Android Dialer974fc292018-02-01 16:12:25 -08001612 public void markFeedbackRequested() {
1613 feedbackRequested = true;
1614 }
1615
1616 public boolean isFeedbackRequested() {
1617 return feedbackRequested;
1618 }
1619
Eric Erfanianccca3152017-02-22 16:32:36 -08001620 /**
twyen73a74c32018-03-07 12:12:24 -08001621 * If the in call UI has shown the phone account selection dialog for the call, the {@link
1622 * PreferredAccountRecorder} to record the result from the dialog.
1623 */
1624 @Nullable
1625 public PreferredAccountRecorder getPreferredAccountRecorder() {
1626 return preferredAccountRecorder;
1627 }
1628
1629 public void setPreferredAccountRecorder(PreferredAccountRecorder preferredAccountRecorder) {
1630 this.preferredAccountRecorder = preferredAccountRecorder;
1631 }
1632
erfaniand05d8992018-03-20 19:42:26 -07001633 /** Indicates the call is eligible for SpeakEasy */
1634 public boolean isSpeakEasyEligible() {
erfaniandcc84cd2018-04-17 12:41:05 -07001635 if (!Constraints.isAvailable(context)) {
1636 return false;
1637 }
1638
1639 return !isPotentialEmergencyCallback()
1640 && !isEmergencyCall()
1641 && !isActiveRttCall()
1642 && !isConferenceCall()
1643 && !isVideoCall()
1644 && !isVoiceMailNumber();
erfaniand05d8992018-03-20 19:42:26 -07001645 }
1646
1647 /** Indicates the user has selected SpeakEasy */
1648 public boolean isSpeakEasyCall() {
1649 if (!isSpeakEasyEligible()) {
1650 return false;
1651 }
1652 return isSpeakEasyCall;
1653 }
1654
1655 /** Sets the user preference for SpeakEasy */
1656 public void setIsSpeakEasyCall(boolean isSpeakEasyCall) {
1657 this.isSpeakEasyCall = isSpeakEasyCall;
1658 }
1659
twyen73a74c32018-03-07 12:12:24 -08001660 /**
Eric Erfanianccca3152017-02-22 16:32:36 -08001661 * Specifies whether a number is in the call history or not. {@link #CALL_HISTORY_STATUS_UNKNOWN}
1662 * means there is no result.
1663 */
1664 @IntDef({
1665 CALL_HISTORY_STATUS_UNKNOWN,
1666 CALL_HISTORY_STATUS_PRESENT,
1667 CALL_HISTORY_STATUS_NOT_PRESENT
1668 })
1669 @Retention(RetentionPolicy.SOURCE)
1670 public @interface CallHistoryStatus {}
1671
1672 /* Defines different states of this call */
1673 public static class State {
1674
1675 public static final int INVALID = 0;
1676 public static final int NEW = 1; /* The call is new. */
1677 public static final int IDLE = 2; /* The call is idle. Nothing active */
1678 public static final int ACTIVE = 3; /* There is an active call */
1679 public static final int INCOMING = 4; /* A normal incoming phone call */
1680 public static final int CALL_WAITING = 5; /* Incoming call while another is active */
1681 public static final int DIALING = 6; /* An outgoing call during dial phase */
1682 public static final int REDIALING = 7; /* Subsequent dialing attempt after a failure */
1683 public static final int ONHOLD = 8; /* An active phone call placed on hold */
1684 public static final int DISCONNECTING = 9; /* A call is being ended. */
1685 public static final int DISCONNECTED = 10; /* State after a call disconnects */
1686 public static final int CONFERENCED = 11; /* DialerCall part of a conference call */
1687 public static final int SELECT_PHONE_ACCOUNT = 12; /* Waiting for account selection */
1688 public static final int CONNECTING = 13; /* Waiting for Telecom broadcast to finish */
1689 public static final int BLOCKED = 14; /* The number was found on the block list */
1690 public static final int PULLING = 15; /* An external call being pulled to the device */
Eric Erfanian2ca43182017-08-31 06:57:16 -07001691 public static final int CALL_PENDING = 16; /* A call is pending on a long process to finish */
Eric Erfanianccca3152017-02-22 16:32:36 -08001692
1693 public static boolean isConnectingOrConnected(int state) {
1694 switch (state) {
1695 case ACTIVE:
1696 case INCOMING:
1697 case CALL_WAITING:
1698 case CONNECTING:
1699 case DIALING:
1700 case PULLING:
1701 case REDIALING:
1702 case ONHOLD:
1703 case CONFERENCED:
1704 return true;
1705 default:
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001706 return false;
Eric Erfanianccca3152017-02-22 16:32:36 -08001707 }
Eric Erfanianccca3152017-02-22 16:32:36 -08001708 }
1709
1710 public static boolean isDialing(int state) {
1711 return state == DIALING || state == PULLING || state == REDIALING;
1712 }
1713
1714 public static String toString(int state) {
1715 switch (state) {
1716 case INVALID:
1717 return "INVALID";
1718 case NEW:
1719 return "NEW";
1720 case IDLE:
1721 return "IDLE";
1722 case ACTIVE:
1723 return "ACTIVE";
1724 case INCOMING:
1725 return "INCOMING";
1726 case CALL_WAITING:
1727 return "CALL_WAITING";
1728 case DIALING:
1729 return "DIALING";
1730 case PULLING:
1731 return "PULLING";
1732 case REDIALING:
1733 return "REDIALING";
1734 case ONHOLD:
1735 return "ONHOLD";
1736 case DISCONNECTING:
1737 return "DISCONNECTING";
1738 case DISCONNECTED:
1739 return "DISCONNECTED";
1740 case CONFERENCED:
1741 return "CONFERENCED";
1742 case SELECT_PHONE_ACCOUNT:
1743 return "SELECT_PHONE_ACCOUNT";
1744 case CONNECTING:
1745 return "CONNECTING";
1746 case BLOCKED:
1747 return "BLOCKED";
1748 default:
1749 return "UNKNOWN";
1750 }
1751 }
1752 }
1753
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001754 /** Camera direction constants */
1755 public static class CameraDirection {
Eric Erfanianccca3152017-02-22 16:32:36 -08001756 public static final int CAMERA_DIRECTION_UNKNOWN = -1;
1757 public static final int CAMERA_DIRECTION_FRONT_FACING = CameraCharacteristics.LENS_FACING_FRONT;
1758 public static final int CAMERA_DIRECTION_BACK_FACING = CameraCharacteristics.LENS_FACING_BACK;
Eric Erfanianccca3152017-02-22 16:32:36 -08001759 }
1760
1761 /**
1762 * Tracks any state variables that is useful for logging. There is some amount of overlap with
1763 * existing call member variables, but this duplication helps to ensure that none of these logging
1764 * variables will interface with/and affect call logic.
1765 */
1766 public static class LogState {
1767
1768 public DisconnectCause disconnectCause;
1769 public boolean isIncoming = false;
Eric Erfanian8369df02017-05-03 10:27:13 -07001770 public ContactLookupResult.Type contactLookupResult =
1771 ContactLookupResult.Type.UNKNOWN_LOOKUP_RESULT_TYPE;
Eric Erfanianccca3152017-02-22 16:32:36 -08001772 public CallSpecificAppData callSpecificAppData;
1773 // If this was a conference call, the total number of calls involved in the conference.
1774 public int conferencedCalls = 0;
1775 public long duration = 0;
1776 public boolean isLogged = false;
1777
Eric Erfanian8369df02017-05-03 10:27:13 -07001778 private static String lookupToString(ContactLookupResult.Type lookupType) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001779 switch (lookupType) {
Eric Erfanian8369df02017-05-03 10:27:13 -07001780 case LOCAL_CONTACT:
Eric Erfanianccca3152017-02-22 16:32:36 -08001781 return "Local";
Eric Erfanian8369df02017-05-03 10:27:13 -07001782 case LOCAL_CACHE:
Eric Erfanianccca3152017-02-22 16:32:36 -08001783 return "Cache";
Eric Erfanian8369df02017-05-03 10:27:13 -07001784 case REMOTE:
Eric Erfanianccca3152017-02-22 16:32:36 -08001785 return "Remote";
Eric Erfanian8369df02017-05-03 10:27:13 -07001786 case EMERGENCY:
Eric Erfanianccca3152017-02-22 16:32:36 -08001787 return "Emergency";
Eric Erfanian8369df02017-05-03 10:27:13 -07001788 case VOICEMAIL:
Eric Erfanianccca3152017-02-22 16:32:36 -08001789 return "Voicemail";
1790 default:
1791 return "Not found";
1792 }
1793 }
1794
1795 private static String initiationToString(CallSpecificAppData callSpecificAppData) {
1796 if (callSpecificAppData == null) {
1797 return "null";
1798 }
Eric Erfanian8369df02017-05-03 10:27:13 -07001799 switch (callSpecificAppData.getCallInitiationType()) {
1800 case INCOMING_INITIATION:
Eric Erfanianccca3152017-02-22 16:32:36 -08001801 return "Incoming";
Eric Erfanian8369df02017-05-03 10:27:13 -07001802 case DIALPAD:
Eric Erfanianccca3152017-02-22 16:32:36 -08001803 return "Dialpad";
Eric Erfanian8369df02017-05-03 10:27:13 -07001804 case SPEED_DIAL:
Eric Erfanianccca3152017-02-22 16:32:36 -08001805 return "Speed Dial";
Eric Erfanian8369df02017-05-03 10:27:13 -07001806 case REMOTE_DIRECTORY:
Eric Erfanianccca3152017-02-22 16:32:36 -08001807 return "Remote Directory";
Eric Erfanian8369df02017-05-03 10:27:13 -07001808 case SMART_DIAL:
Eric Erfanianccca3152017-02-22 16:32:36 -08001809 return "Smart Dial";
Eric Erfanian8369df02017-05-03 10:27:13 -07001810 case REGULAR_SEARCH:
Eric Erfanianccca3152017-02-22 16:32:36 -08001811 return "Regular Search";
Eric Erfanian8369df02017-05-03 10:27:13 -07001812 case CALL_LOG:
Eric Erfanianccca3152017-02-22 16:32:36 -08001813 return "DialerCall Log";
Eric Erfanian8369df02017-05-03 10:27:13 -07001814 case CALL_LOG_FILTER:
Eric Erfanianccca3152017-02-22 16:32:36 -08001815 return "DialerCall Log Filter";
Eric Erfanian8369df02017-05-03 10:27:13 -07001816 case VOICEMAIL_LOG:
Eric Erfanianccca3152017-02-22 16:32:36 -08001817 return "Voicemail Log";
Eric Erfanian8369df02017-05-03 10:27:13 -07001818 case CALL_DETAILS:
Eric Erfanianccca3152017-02-22 16:32:36 -08001819 return "DialerCall Details";
Eric Erfanian8369df02017-05-03 10:27:13 -07001820 case QUICK_CONTACTS:
Eric Erfanianccca3152017-02-22 16:32:36 -08001821 return "Quick Contacts";
Eric Erfanian8369df02017-05-03 10:27:13 -07001822 case EXTERNAL_INITIATION:
Eric Erfanianccca3152017-02-22 16:32:36 -08001823 return "External";
Eric Erfanian8369df02017-05-03 10:27:13 -07001824 case LAUNCHER_SHORTCUT:
Eric Erfanianccca3152017-02-22 16:32:36 -08001825 return "Launcher Shortcut";
1826 default:
Eric Erfanian8369df02017-05-03 10:27:13 -07001827 return "Unknown: " + callSpecificAppData.getCallInitiationType();
Eric Erfanianccca3152017-02-22 16:32:36 -08001828 }
1829 }
1830
1831 @Override
1832 public String toString() {
1833 return String.format(
1834 Locale.US,
1835 "["
1836 + "%s, " // DisconnectCause toString already describes the object type
1837 + "isIncoming: %s, "
1838 + "contactLookup: %s, "
1839 + "callInitiation: %s, "
1840 + "duration: %s"
1841 + "]",
1842 disconnectCause,
1843 isIncoming,
1844 lookupToString(contactLookupResult),
1845 initiationToString(callSpecificAppData),
1846 duration);
1847 }
1848 }
1849
roldenburgd7490db2018-01-09 13:51:29 -08001850 /** Coordinates the available VideoTech implementations for a call. */
1851 @VisibleForTesting
1852 public static class VideoTechManager {
Eric Erfaniand8046e52017-04-06 09:41:50 -07001853 private final Context context;
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001854 private final EmptyVideoTech emptyVideoTech = new EmptyVideoTech();
roldenburgd7490db2018-01-09 13:51:29 -08001855 private final VideoTech rcsVideoShare;
Eric Erfanian90508232017-03-24 09:31:16 -07001856 private final List<VideoTech> videoTechs;
roldenburg7bb96232017-10-09 10:32:05 -07001857 private VideoTech savedTech;
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001858
roldenburgd7490db2018-01-09 13:51:29 -08001859 @VisibleForTesting
1860 public VideoTechManager(DialerCall call) {
linyuh183cb712017-12-27 17:02:37 -08001861 this.context = call.context;
Eric Erfaniand8046e52017-04-06 09:41:50 -07001862
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001863 String phoneNumber = call.getNumber();
Eric Erfaniand8046e52017-04-06 09:41:50 -07001864 phoneNumber = phoneNumber != null ? phoneNumber : "";
Eric Erfanian2ca43182017-08-31 06:57:16 -07001865 phoneNumber = phoneNumber.replaceAll("[^+0-9]", "");
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001866
1867 // Insert order here determines the priority of that video tech option
Eric Erfanian8369df02017-05-03 10:27:13 -07001868 videoTechs = new ArrayList<>();
yueg457b3972017-09-18 15:11:47 -07001869
linyuh183cb712017-12-27 17:02:37 -08001870 videoTechs.add(new ImsVideoTech(Logger.get(call.context), call, call.telecomCall));
Eric Erfanian90508232017-03-24 09:31:16 -07001871
roldenburgd7490db2018-01-09 13:51:29 -08001872 rcsVideoShare =
linyuh183cb712017-12-27 17:02:37 -08001873 EnrichedCallComponent.get(call.context)
Eric Erfanian90508232017-03-24 09:31:16 -07001874 .getRcsVideoShareFactory()
1875 .newRcsVideoShare(
linyuh183cb712017-12-27 17:02:37 -08001876 EnrichedCallComponent.get(call.context).getEnrichedCallManager(),
Eric Erfanian90508232017-03-24 09:31:16 -07001877 call,
Eric Erfaniand8046e52017-04-06 09:41:50 -07001878 phoneNumber);
roldenburg3eca69f2018-01-16 12:07:04 -08001879 videoTechs.add(rcsVideoShare);
Eric Erfaniand8046e52017-04-06 09:41:50 -07001880
1881 videoTechs.add(
roldenburg4f026392017-10-13 18:42:20 -07001882 new DuoVideoTech(
linyuh183cb712017-12-27 17:02:37 -08001883 DuoComponent.get(call.context).getDuo(), call, call.telecomCall, phoneNumber));
roldenburgd7490db2018-01-09 13:51:29 -08001884
1885 savedTech = emptyVideoTech;
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001886 }
1887
roldenburgd7490db2018-01-09 13:51:29 -08001888 @VisibleForTesting
roldenburg6bd612f2018-01-18 12:57:19 -08001889 public VideoTech getVideoTech(PhoneAccountHandle phoneAccountHandle) {
roldenburgd7490db2018-01-09 13:51:29 -08001890 if (savedTech == emptyVideoTech) {
1891 for (VideoTech tech : videoTechs) {
roldenburg6bd612f2018-01-18 12:57:19 -08001892 if (tech.isAvailable(context, phoneAccountHandle)) {
roldenburgd7490db2018-01-09 13:51:29 -08001893 savedTech = tech;
1894 savedTech.becomePrimary();
1895 break;
1896 }
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001897 }
roldenburg6bd612f2018-01-18 12:57:19 -08001898 } else if (savedTech instanceof DuoVideoTech
1899 && rcsVideoShare.isAvailable(context, phoneAccountHandle)) {
roldenburgd7490db2018-01-09 13:51:29 -08001900 // RCS Video Share will become available after the capability exchange which is slower than
1901 // Duo reading local contacts for reachability. If Video Share becomes available and we are
1902 // not in the middle of any session changes, let it take over.
1903 savedTech = rcsVideoShare;
1904 rcsVideoShare.becomePrimary();
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001905 }
1906
roldenburgd7490db2018-01-09 13:51:29 -08001907 return savedTech;
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001908 }
1909
roldenburgd7490db2018-01-09 13:51:29 -08001910 @VisibleForTesting
roldenburg6bd612f2018-01-18 12:57:19 -08001911 public void dispatchCallStateChanged(int newState, PhoneAccountHandle phoneAccountHandle) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001912 for (VideoTech videoTech : videoTechs) {
roldenburg6bd612f2018-01-18 12:57:19 -08001913 videoTech.onCallStateChanged(context, newState, phoneAccountHandle);
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001914 }
1915 }
Eric Erfanian2ca43182017-08-31 06:57:16 -07001916
1917 void dispatchRemovedFromCallList() {
1918 for (VideoTech videoTech : videoTechs) {
1919 videoTech.onRemovedFromCallList();
1920 }
1921 }
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001922 }
1923
Eric Erfanianccca3152017-02-22 16:32:36 -08001924 /** Called when canned text responses have been loaded. */
1925 public interface CannedTextResponsesLoadedListener {
1926 void onCannedTextResponsesLoaded(DialerCall call);
1927 }
1928}