Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.incallui.call; |
| 18 | |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 19 | import android.Manifest.permission; |
wangqi | da410d3 | 2018-03-06 16:51:38 -0800 | [diff] [blame] | 20 | import android.annotation.SuppressLint; |
wangqi | 8d407a0 | 2018-02-15 15:32:52 -0800 | [diff] [blame] | 21 | import android.annotation.TargetApi; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.hardware.camera2.CameraCharacteristics; |
| 24 | import android.net.Uri; |
erfanian | 2cf2c34 | 2017-12-21 12:01:33 -0800 | [diff] [blame] | 25 | import android.os.Build; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 26 | import android.os.Build.VERSION; |
| 27 | import android.os.Build.VERSION_CODES; |
| 28 | import android.os.Bundle; |
wangqi | da410d3 | 2018-03-06 16:51:38 -0800 | [diff] [blame] | 29 | import android.os.PersistableBundle; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 30 | import android.os.Trace; |
| 31 | import android.support.annotation.IntDef; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 32 | import android.support.annotation.NonNull; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 33 | import android.support.annotation.Nullable; |
twyen | dde01c5 | 2017-09-22 10:07:31 -0700 | [diff] [blame] | 34 | import android.support.annotation.VisibleForTesting; |
wangqi | f4ba345 | 2018-01-09 11:26:29 -0800 | [diff] [blame] | 35 | import android.support.v4.os.BuildCompat; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 36 | import android.telecom.Call; |
| 37 | import android.telecom.Call.Details; |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 38 | import android.telecom.Call.RttCall; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 39 | import android.telecom.CallAudioState; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 40 | import android.telecom.Connection; |
| 41 | import android.telecom.DisconnectCause; |
| 42 | import android.telecom.GatewayInfo; |
| 43 | import android.telecom.InCallService.VideoCall; |
| 44 | import android.telecom.PhoneAccount; |
| 45 | import android.telecom.PhoneAccountHandle; |
| 46 | import android.telecom.StatusHints; |
| 47 | import android.telecom.TelecomManager; |
| 48 | import android.telecom.VideoProfile; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 49 | import android.text.TextUtils; |
roldenburg | 08424ee | 2018-03-28 17:02:46 -0700 | [diff] [blame] | 50 | import android.widget.Toast; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 51 | import com.android.contacts.common.compat.CallCompat; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 52 | import com.android.contacts.common.compat.telecom.TelecomManagerCompat; |
erfanian | 2cf2c34 | 2017-12-21 12:01:33 -0800 | [diff] [blame] | 53 | import com.android.dialer.assisteddialing.ConcreteCreator; |
erfanian | d0f207f | 2017-10-11 12:23:29 -0700 | [diff] [blame] | 54 | import com.android.dialer.assisteddialing.TransformationInfo; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 55 | import com.android.dialer.callintent.CallInitiationType; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 56 | import com.android.dialer.callintent.CallIntentParser; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 57 | import com.android.dialer.callintent.CallSpecificAppData; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 58 | import com.android.dialer.common.Assert; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 59 | import com.android.dialer.common.LogUtil; |
wangqi | d6b10d5 | 2018-04-12 14:44:06 -0700 | [diff] [blame] | 60 | import com.android.dialer.common.concurrent.DefaultFutureCallback; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 61 | import com.android.dialer.compat.telephony.TelephonyManagerCompat; |
| 62 | import com.android.dialer.configprovider.ConfigProviderBindings; |
roldenburg | 4f02639 | 2017-10-13 18:42:20 -0700 | [diff] [blame] | 63 | import com.android.dialer.duo.DuoComponent; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 64 | import com.android.dialer.enrichedcall.EnrichedCallCapabilities; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 65 | import com.android.dialer.enrichedcall.EnrichedCallComponent; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 66 | import com.android.dialer.enrichedcall.EnrichedCallManager; |
| 67 | import com.android.dialer.enrichedcall.EnrichedCallManager.CapabilitiesListener; |
| 68 | import com.android.dialer.enrichedcall.EnrichedCallManager.Filter; |
| 69 | import com.android.dialer.enrichedcall.EnrichedCallManager.StateChangedListener; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 70 | import com.android.dialer.enrichedcall.Session; |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 71 | import com.android.dialer.location.GeoUtil; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 72 | import com.android.dialer.logging.ContactLookupResult; |
twyen | dde01c5 | 2017-09-22 10:07:31 -0700 | [diff] [blame] | 73 | import com.android.dialer.logging.ContactLookupResult.Type; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 74 | import com.android.dialer.logging.DialerImpression; |
| 75 | import com.android.dialer.logging.Logger; |
twyen | 73a74c3 | 2018-03-07 12:12:24 -0800 | [diff] [blame] | 76 | import com.android.dialer.preferredsim.PreferredAccountRecorder; |
wangqi | ed677ef | 2018-04-04 12:03:00 -0700 | [diff] [blame] | 77 | import com.android.dialer.rtt.RttTranscript; |
wangqi | d6b10d5 | 2018-04-12 14:44:06 -0700 | [diff] [blame] | 78 | import com.android.dialer.rtt.RttTranscriptUtil; |
twyen | a4745bd | 2017-12-12 18:40:11 -0800 | [diff] [blame] | 79 | import com.android.dialer.telecom.TelecomCallUtil; |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 80 | import com.android.dialer.telecom.TelecomUtil; |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 81 | import com.android.dialer.theme.R; |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 82 | import com.android.dialer.util.PermissionsUtil; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 83 | import com.android.incallui.audiomode.AudioModeProvider; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 84 | import com.android.incallui.latencyreport.LatencyReport; |
erfanian | dcc84cd | 2018-04-17 12:41:05 -0700 | [diff] [blame] | 85 | import com.android.incallui.speakeasy.runtime.Constraints; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 86 | import com.android.incallui.videotech.VideoTech; |
| 87 | import com.android.incallui.videotech.VideoTech.VideoTechListener; |
roldenburg | 4f02639 | 2017-10-13 18:42:20 -0700 | [diff] [blame] | 88 | import com.android.incallui.videotech.duo.DuoVideoTech; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 89 | import com.android.incallui.videotech.empty.EmptyVideoTech; |
| 90 | import com.android.incallui.videotech.ims.ImsVideoTech; |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 91 | import com.android.incallui.videotech.utils.VideoUtils; |
wangqi | d6b10d5 | 2018-04-12 14:44:06 -0700 | [diff] [blame] | 92 | import com.google.common.util.concurrent.Futures; |
wangqi | d6b10d5 | 2018-04-12 14:44:06 -0700 | [diff] [blame] | 93 | import com.google.common.util.concurrent.MoreExecutors; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 94 | import java.lang.annotation.Retention; |
| 95 | import java.lang.annotation.RetentionPolicy; |
| 96 | import java.util.ArrayList; |
| 97 | import java.util.List; |
| 98 | import java.util.Locale; |
| 99 | import java.util.Objects; |
| 100 | import java.util.UUID; |
| 101 | import java.util.concurrent.CopyOnWriteArrayList; |
| 102 | import java.util.concurrent.TimeUnit; |
| 103 | |
| 104 | /** Describes a single call and its state. */ |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 105 | public class DialerCall implements VideoTechListener, StateChangedListener, CapabilitiesListener { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 106 | |
| 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 Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 110 | |
| 111 | // Hard coded property for {@code Call}. Upstreamed change from Motorola. |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 112 | // TODO(a bug): Move it to Telecom in framework. |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 113 | public static final int PROPERTY_CODEC_KNOWN = 0x04000000; |
| 114 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 115 | private static final String ID_PREFIX = "DialerCall_"; |
| 116 | private static final String CONFIG_EMERGENCY_CALLBACK_WINDOW_MILLIS = |
| 117 | "emergency_callback_window_millis"; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 118 | private static int idCounter = 0; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 119 | |
| 120 | /** |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 121 | * 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 | */ |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 125 | private static int hiddenCounter; |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 126 | |
| 127 | /** |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 128 | * 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 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 133 | 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 Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 143 | new CopyOnWriteArrayList<>(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 144 | private final VideoTechManager videoTechManager; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 145 | |
erfanian | d05d899 | 2018-03-20 19:42:26 -0700 | [diff] [blame] | 146 | private boolean isSpeakEasyCall; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 147 | private boolean isEmergencyCall; |
| 148 | private Uri handle; |
| 149 | private int state = State.INVALID; |
| 150 | private DisconnectCause disconnectCause; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 151 | |
roldenburg | 08424ee | 2018-03-28 17:02:46 -0700 | [diff] [blame] | 152 | private boolean hasShownLteToWiFiHandoverToast; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 153 | private boolean hasShownWiFiToLteHandoverToast; |
| 154 | private boolean doNotShowDialogForHandoffToWifiFailure; |
| 155 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 156 | private String childNumber; |
| 157 | private String lastForwardedNumber; |
wangqi | f4ba345 | 2018-01-09 11:26:29 -0800 | [diff] [blame] | 158 | private boolean isCallForwarded; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 159 | private String callSubject; |
twyen | 27c3718 | 2018-04-24 11:48:12 -0700 | [diff] [blame] | 160 | @Nullable private PhoneAccountHandle phoneAccountHandle; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 161 | @CallHistoryStatus private int callHistoryStatus = CALL_HISTORY_STATUS_UNKNOWN; |
| 162 | private boolean isSpam; |
| 163 | private boolean isBlocked; |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 164 | |
| 165 | @Nullable private Boolean isInUserSpamList; |
| 166 | |
| 167 | @Nullable private Boolean isInUserWhiteList; |
| 168 | |
| 169 | @Nullable private Boolean isInGlobalSpamList; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 170 | private boolean didShowCameraPermission; |
wangqi | da410d3 | 2018-03-06 16:51:38 -0800 | [diff] [blame] | 171 | private boolean didDismissVideoChargesAlertDialog; |
| 172 | private PersistableBundle carrierConfig; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 173 | private String callProviderLabel; |
| 174 | private String callbackNumber; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 175 | private int cameraDirection = CameraDirection.CAMERA_DIRECTION_UNKNOWN; |
| 176 | private EnrichedCallCapabilities enrichedCallCapabilities; |
| 177 | private Session enrichedCallSession; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 178 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 179 | 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; |
roldenburg | 7bb9623 | 2017-10-09 10:32:05 -0700 | [diff] [blame] | 184 | private VideoTech videoTech; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 185 | |
wangqi | 4d705e5 | 2017-09-28 12:23:35 -0700 | [diff] [blame] | 186 | private com.android.dialer.logging.VideoTech.Type selectedAvailableVideoTechType = |
| 187 | com.android.dialer.logging.VideoTech.Type.NONE; |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 188 | private boolean isVoicemailNumber; |
| 189 | private List<PhoneAccountHandle> callCapableAccounts; |
| 190 | private String countryIso; |
yueg | 457b397 | 2017-09-18 15:11:47 -0700 | [diff] [blame] | 191 | |
Android Dialer | 974fc29 | 2018-02-01 16:12:25 -0800 | [diff] [blame] | 192 | private volatile boolean feedbackRequested = false; |
| 193 | |
twyen | 73a74c3 | 2018-03-07 12:12:24 -0800 | [diff] [blame] | 194 | @Nullable private PreferredAccountRecorder preferredAccountRecorder; |
wangqi | a0c49f6 | 2018-04-25 15:04:01 -0700 | [diff] [blame^] | 195 | private boolean isCallRemoved; |
twyen | 73a74c3 | 2018-03-07 12:12:24 -0800 | [diff] [blame] | 196 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 197 | public static String getNumberFromHandle(Uri handle) { |
| 198 | return handle == null ? "" : handle.getSchemeSpecificPart(); |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Whether the call is put on hold by remote party. This is different than the {@link |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 203 | * State#ONHOLD} state which indicates that the call is being held locally on the device. |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 204 | */ |
| 205 | private boolean isRemotelyHeld; |
| 206 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 207 | /** Indicates whether this call is currently in the process of being merged into a conference. */ |
| 208 | private boolean isMergeInProcess; |
| 209 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 210 | /** |
| 211 | * Indicates whether the phone account associated with this call supports specifying a call |
| 212 | * subject. |
| 213 | */ |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 214 | private boolean isCallSubjectSupported; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 215 | |
wangqi | ed677ef | 2018-04-04 12:03:00 -0700 | [diff] [blame] | 216 | public RttTranscript getRttTranscript() { |
| 217 | return rttTranscript; |
| 218 | } |
| 219 | |
| 220 | public void setRttTranscript(RttTranscript rttTranscript) { |
| 221 | this.rttTranscript = rttTranscript; |
| 222 | } |
| 223 | |
| 224 | private RttTranscript rttTranscript; |
| 225 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 226 | private final Call.Callback telecomCallCallback = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 227 | new Call.Callback() { |
| 228 | @Override |
| 229 | public void onStateChanged(Call call, int newState) { |
| 230 | LogUtil.v("TelecomCallCallback.onStateChanged", "call=" + call + " newState=" + newState); |
| 231 | update(); |
| 232 | } |
| 233 | |
| 234 | @Override |
| 235 | public void onParentChanged(Call call, Call newParent) { |
| 236 | LogUtil.v( |
| 237 | "TelecomCallCallback.onParentChanged", "call=" + call + " newParent=" + newParent); |
| 238 | update(); |
| 239 | } |
| 240 | |
| 241 | @Override |
| 242 | public void onChildrenChanged(Call call, List<Call> children) { |
| 243 | update(); |
| 244 | } |
| 245 | |
| 246 | @Override |
| 247 | public void onDetailsChanged(Call call, Call.Details details) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 248 | LogUtil.v( |
| 249 | "TelecomCallCallback.onDetailsChanged", " call=" + call + " details=" + details); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 250 | update(); |
| 251 | } |
| 252 | |
| 253 | @Override |
| 254 | public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) { |
| 255 | LogUtil.v( |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 256 | "TelecomCallCallback.onCannedTextResponsesLoaded", |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 257 | "call=" + call + " cannedTextResponses=" + cannedTextResponses); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 258 | for (CannedTextResponsesLoadedListener listener : cannedTextResponsesLoadedListeners) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 259 | listener.onCannedTextResponsesLoaded(DialerCall.this); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | @Override |
| 264 | public void onPostDialWait(Call call, String remainingPostDialSequence) { |
| 265 | LogUtil.v( |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 266 | "TelecomCallCallback.onPostDialWait", |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 267 | "call=" + call + " remainingPostDialSequence=" + remainingPostDialSequence); |
| 268 | update(); |
| 269 | } |
| 270 | |
| 271 | @Override |
| 272 | public void onVideoCallChanged(Call call, VideoCall videoCall) { |
| 273 | LogUtil.v( |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 274 | "TelecomCallCallback.onVideoCallChanged", "call=" + call + " videoCall=" + videoCall); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 275 | update(); |
| 276 | } |
| 277 | |
| 278 | @Override |
| 279 | public void onCallDestroyed(Call call) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 280 | LogUtil.v("TelecomCallCallback.onCallDestroyed", "call=" + call); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 281 | unregisterCallback(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | @Override |
| 285 | public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) { |
| 286 | LogUtil.v( |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 287 | "TelecomCallCallback.onConferenceableCallsChanged", |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 288 | "call %s, conferenceable calls: %d", |
| 289 | call, |
| 290 | conferenceableCalls.size()); |
| 291 | update(); |
| 292 | } |
| 293 | |
| 294 | @Override |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 295 | public void onRttModeChanged(Call call, int mode) { |
| 296 | LogUtil.v("TelecomCallCallback.onRttModeChanged", "mode=%d", mode); |
| 297 | } |
| 298 | |
| 299 | @Override |
| 300 | public void onRttRequest(Call call, int id) { |
| 301 | LogUtil.v("TelecomCallCallback.onRttRequest", "id=%d", id); |
wangqi | bc28ea7 | 2018-04-02 16:23:00 -0700 | [diff] [blame] | 302 | for (DialerCallListener listener : listeners) { |
| 303 | listener.onDialerCallUpgradeToRtt(id); |
| 304 | } |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | @Override |
| 308 | public void onRttInitiationFailure(Call call, int reason) { |
| 309 | LogUtil.v("TelecomCallCallback.onRttInitiationFailure", "reason=%d", reason); |
| 310 | update(); |
| 311 | } |
| 312 | |
| 313 | @Override |
| 314 | public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) { |
| 315 | LogUtil.v("TelecomCallCallback.onRttStatusChanged", "enabled=%b", enabled); |
wangqi | 81e373e | 2018-04-24 10:50:57 -0700 | [diff] [blame] | 316 | if (enabled) { |
| 317 | Logger.get(context) |
| 318 | .logCallImpression( |
| 319 | DialerImpression.Type.RTT_MID_CALL_ENABLED, |
| 320 | getUniqueCallId(), |
| 321 | getTimeAddedMs()); |
| 322 | } |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 323 | update(); |
| 324 | } |
| 325 | |
| 326 | @Override |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 327 | public void onConnectionEvent(android.telecom.Call call, String event, Bundle extras) { |
| 328 | LogUtil.v( |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 329 | "TelecomCallCallback.onConnectionEvent", |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 330 | "Call: " + call + ", Event: " + event + ", Extras: " + extras); |
| 331 | switch (event) { |
| 332 | // The Previous attempt to Merge two calls together has failed in Telecom. We must |
| 333 | // now update the UI to possibly re-enable the Merge button based on the number of |
| 334 | // currently conferenceable calls available or Connection Capabilities. |
| 335 | case android.telecom.Connection.EVENT_CALL_MERGE_FAILED: |
| 336 | update(); |
| 337 | break; |
| 338 | case TelephonyManagerCompat.EVENT_HANDOVER_VIDEO_FROM_WIFI_TO_LTE: |
| 339 | notifyWiFiToLteHandover(); |
| 340 | break; |
roldenburg | 08424ee | 2018-03-28 17:02:46 -0700 | [diff] [blame] | 341 | case TelephonyManagerCompat.EVENT_HANDOVER_VIDEO_FROM_LTE_TO_WIFI: |
| 342 | onLteToWifiHandover(); |
| 343 | break; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 344 | case TelephonyManagerCompat.EVENT_HANDOVER_TO_WIFI_FAILED: |
| 345 | notifyHandoverToWifiFailed(); |
| 346 | break; |
| 347 | case TelephonyManagerCompat.EVENT_CALL_REMOTELY_HELD: |
| 348 | isRemotelyHeld = true; |
| 349 | update(); |
| 350 | break; |
| 351 | case TelephonyManagerCompat.EVENT_CALL_REMOTELY_UNHELD: |
| 352 | isRemotelyHeld = false; |
| 353 | update(); |
| 354 | break; |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 355 | case TelephonyManagerCompat.EVENT_NOTIFY_INTERNATIONAL_CALL_ON_WFC: |
| 356 | notifyInternationalCallOnWifi(); |
| 357 | break; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 358 | case TelephonyManagerCompat.EVENT_MERGE_START: |
| 359 | LogUtil.i("DialerCall.onConnectionEvent", "merge start"); |
| 360 | isMergeInProcess = true; |
| 361 | break; |
| 362 | case TelephonyManagerCompat.EVENT_MERGE_COMPLETE: |
| 363 | LogUtil.i("DialerCall.onConnectionEvent", "merge complete"); |
| 364 | isMergeInProcess = false; |
| 365 | break; |
wangqi | f4ba345 | 2018-01-09 11:26:29 -0800 | [diff] [blame] | 366 | case TelephonyManagerCompat.EVENT_CALL_FORWARDED: |
| 367 | // Only handle this event for P+ since it's unreliable pre-P. |
| 368 | if (BuildCompat.isAtLeastP()) { |
| 369 | isCallForwarded = true; |
| 370 | update(); |
| 371 | } |
| 372 | break; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 373 | default: |
| 374 | break; |
| 375 | } |
| 376 | } |
| 377 | }; |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 378 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 379 | private long timeAddedMs; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 380 | |
| 381 | public DialerCall( |
| 382 | Context context, |
| 383 | DialerCallDelegate dialerCallDelegate, |
| 384 | Call telecomCall, |
| 385 | LatencyReport latencyReport, |
| 386 | boolean registerCallback) { |
| 387 | Assert.isNotNull(context); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 388 | this.context = context; |
| 389 | this.dialerCallDelegate = dialerCallDelegate; |
| 390 | this.telecomCall = telecomCall; |
| 391 | this.latencyReport = latencyReport; |
| 392 | id = ID_PREFIX + Integer.toString(idCounter++); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 393 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 394 | // Must be after assigning mTelecomCall |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 395 | videoTechManager = new VideoTechManager(this); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 396 | |
| 397 | updateFromTelecomCall(); |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 398 | if (isHiddenNumber() && TextUtils.isEmpty(getNumber())) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 399 | hiddenId = ++hiddenCounter; |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 400 | } else { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 401 | hiddenId = 0; |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 402 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 403 | |
| 404 | if (registerCallback) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 405 | this.telecomCall.registerCallback(telecomCallCallback); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 406 | } |
| 407 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 408 | timeAddedMs = System.currentTimeMillis(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 409 | parseCallSpecificAppData(); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 410 | |
| 411 | updateEnrichedCallSession(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 412 | } |
| 413 | |
twyen | dde01c5 | 2017-09-22 10:07:31 -0700 | [diff] [blame] | 414 | /** Test only constructor to avoid initializing dependencies. */ |
| 415 | @VisibleForTesting |
| 416 | DialerCall(Context context) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 417 | this.context = context; |
| 418 | telecomCall = null; |
| 419 | latencyReport = null; |
| 420 | id = null; |
| 421 | hiddenId = 0; |
| 422 | dialerCallDelegate = null; |
| 423 | videoTechManager = null; |
twyen | dde01c5 | 2017-09-22 10:07:31 -0700 | [diff] [blame] | 424 | } |
| 425 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 426 | private static int translateState(int state) { |
| 427 | switch (state) { |
| 428 | case Call.STATE_NEW: |
| 429 | case Call.STATE_CONNECTING: |
| 430 | return DialerCall.State.CONNECTING; |
| 431 | case Call.STATE_SELECT_PHONE_ACCOUNT: |
| 432 | return DialerCall.State.SELECT_PHONE_ACCOUNT; |
| 433 | case Call.STATE_DIALING: |
| 434 | return DialerCall.State.DIALING; |
| 435 | case Call.STATE_PULLING_CALL: |
| 436 | return DialerCall.State.PULLING; |
| 437 | case Call.STATE_RINGING: |
| 438 | return DialerCall.State.INCOMING; |
| 439 | case Call.STATE_ACTIVE: |
| 440 | return DialerCall.State.ACTIVE; |
| 441 | case Call.STATE_HOLDING: |
| 442 | return DialerCall.State.ONHOLD; |
| 443 | case Call.STATE_DISCONNECTED: |
| 444 | return DialerCall.State.DISCONNECTED; |
| 445 | case Call.STATE_DISCONNECTING: |
| 446 | return DialerCall.State.DISCONNECTING; |
| 447 | default: |
| 448 | return DialerCall.State.INVALID; |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | public static boolean areSame(DialerCall call1, DialerCall call2) { |
| 453 | if (call1 == null && call2 == null) { |
| 454 | return true; |
| 455 | } else if (call1 == null || call2 == null) { |
| 456 | return false; |
| 457 | } |
| 458 | |
| 459 | // otherwise compare call Ids |
| 460 | return call1.getId().equals(call2.getId()); |
| 461 | } |
| 462 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 463 | public void addListener(DialerCallListener listener) { |
| 464 | Assert.isMainThread(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 465 | listeners.add(listener); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | public void removeListener(DialerCallListener listener) { |
| 469 | Assert.isMainThread(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 470 | listeners.remove(listener); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | public void addCannedTextResponsesLoadedListener(CannedTextResponsesLoadedListener listener) { |
| 474 | Assert.isMainThread(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 475 | cannedTextResponsesLoadedListeners.add(listener); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | public void removeCannedTextResponsesLoadedListener(CannedTextResponsesLoadedListener listener) { |
| 479 | Assert.isMainThread(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 480 | cannedTextResponsesLoadedListeners.remove(listener); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 481 | } |
| 482 | |
roldenburg | 08424ee | 2018-03-28 17:02:46 -0700 | [diff] [blame] | 483 | private void onLteToWifiHandover() { |
| 484 | LogUtil.enterBlock("DialerCall.onLteToWifiHandover"); |
| 485 | if (hasShownLteToWiFiHandoverToast) { |
| 486 | return; |
| 487 | } |
| 488 | |
| 489 | Toast.makeText(context, R.string.video_call_lte_to_wifi_handover_toast, Toast.LENGTH_LONG) |
| 490 | .show(); |
| 491 | hasShownLteToWiFiHandoverToast = true; |
| 492 | } |
| 493 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 494 | public void notifyWiFiToLteHandover() { |
| 495 | LogUtil.i("DialerCall.notifyWiFiToLteHandover", ""); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 496 | for (DialerCallListener listener : listeners) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 497 | listener.onWiFiToLteHandover(); |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | public void notifyHandoverToWifiFailed() { |
| 502 | LogUtil.i("DialerCall.notifyHandoverToWifiFailed", ""); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 503 | for (DialerCallListener listener : listeners) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 504 | listener.onHandoverToWifiFailure(); |
| 505 | } |
| 506 | } |
| 507 | |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 508 | public void notifyInternationalCallOnWifi() { |
| 509 | LogUtil.enterBlock("DialerCall.notifyInternationalCallOnWifi"); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 510 | for (DialerCallListener dialerCallListener : listeners) { |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 511 | dialerCallListener.onInternationalCallOnWifi(); |
| 512 | } |
| 513 | } |
| 514 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 515 | /* package-private */ Call getTelecomCall() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 516 | return telecomCall; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 517 | } |
wangqi | da410d3 | 2018-03-06 16:51:38 -0800 | [diff] [blame] | 518 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 519 | public StatusHints getStatusHints() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 520 | return telecomCall.getDetails().getStatusHints(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 521 | } |
| 522 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 523 | public int getCameraDir() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 524 | return cameraDirection; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | public void setCameraDir(int cameraDir) { |
| 528 | if (cameraDir == CameraDirection.CAMERA_DIRECTION_FRONT_FACING |
| 529 | || cameraDir == CameraDirection.CAMERA_DIRECTION_BACK_FACING) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 530 | cameraDirection = cameraDir; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 531 | } else { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 532 | cameraDirection = CameraDirection.CAMERA_DIRECTION_UNKNOWN; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 533 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 534 | } |
| 535 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 536 | public boolean wasParentCall() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 537 | return logState.conferencedCalls != 0; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 538 | } |
| 539 | |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 540 | public boolean isVoiceMailNumber() { |
| 541 | return isVoicemailNumber; |
| 542 | } |
| 543 | |
| 544 | public List<PhoneAccountHandle> getCallCapableAccounts() { |
| 545 | return callCapableAccounts; |
| 546 | } |
| 547 | |
| 548 | public String getCountryIso() { |
| 549 | return countryIso; |
| 550 | } |
| 551 | |
| 552 | private void updateIsVoiceMailNumber() { |
| 553 | if (getHandle() != null && PhoneAccount.SCHEME_VOICEMAIL.equals(getHandle().getScheme())) { |
| 554 | isVoicemailNumber = true; |
roldenburg | 37a969d | 2018-02-22 14:46:44 -0800 | [diff] [blame] | 555 | return; |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 556 | } |
| 557 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 558 | if (!PermissionsUtil.hasPermission(context, permission.READ_PHONE_STATE)) { |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 559 | isVoicemailNumber = false; |
roldenburg | 37a969d | 2018-02-22 14:46:44 -0800 | [diff] [blame] | 560 | return; |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 561 | } |
| 562 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 563 | isVoicemailNumber = TelecomUtil.isVoicemailNumber(context, getAccountHandle(), getNumber()); |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 564 | } |
| 565 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 566 | private void update() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 567 | Trace.beginSection("DialerCall.update"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 568 | int oldState = getState(); |
roldenburg | 7bb9623 | 2017-10-09 10:32:05 -0700 | [diff] [blame] | 569 | // Clear any cache here that could potentially change on update. |
| 570 | videoTech = null; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 571 | // We want to potentially register a video call callback here. |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 572 | updateFromTelecomCall(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 573 | if (oldState != getState() && getState() == DialerCall.State.DISCONNECTED) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 574 | for (DialerCallListener listener : listeners) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 575 | listener.onDialerCallDisconnect(); |
| 576 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 577 | EnrichedCallComponent.get(context) |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 578 | .getEnrichedCallManager() |
| 579 | .unregisterCapabilitiesListener(this); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 580 | EnrichedCallComponent.get(context) |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 581 | .getEnrichedCallManager() |
| 582 | .unregisterStateChangedListener(this); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 583 | } else { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 584 | for (DialerCallListener listener : listeners) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 585 | listener.onDialerCallUpdate(); |
| 586 | } |
| 587 | } |
| 588 | Trace.endSection(); |
| 589 | } |
| 590 | |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 591 | @SuppressWarnings("MissingPermission") |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 592 | private void updateFromTelecomCall() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 593 | Trace.beginSection("DialerCall.updateFromTelecomCall"); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 594 | LogUtil.v("DialerCall.updateFromTelecomCall", telecomCall.toString()); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 595 | |
roldenburg | 6bd612f | 2018-01-18 12:57:19 -0800 | [diff] [blame] | 596 | videoTechManager.dispatchCallStateChanged(telecomCall.getState(), getAccountHandle()); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 597 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 598 | final int translatedState = translateState(telecomCall.getState()); |
| 599 | if (state != State.BLOCKED) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 600 | setState(translatedState); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 601 | setDisconnectCause(telecomCall.getDetails().getDisconnectCause()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 602 | } |
| 603 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 604 | childCallIds.clear(); |
| 605 | final int numChildCalls = telecomCall.getChildren().size(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 606 | for (int i = 0; i < numChildCalls; i++) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 607 | childCallIds.add( |
| 608 | dialerCallDelegate |
| 609 | .getDialerCallFromTelecomCall(telecomCall.getChildren().get(i)) |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 610 | .getId()); |
| 611 | } |
| 612 | |
| 613 | // The number of conferenced calls can change over the course of the call, so use the |
| 614 | // maximum number of conferenced child calls as the metric for conference call usage. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 615 | logState.conferencedCalls = Math.max(numChildCalls, logState.conferencedCalls); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 616 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 617 | updateFromCallExtras(telecomCall.getDetails().getExtras()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 618 | |
| 619 | // If the handle of the call has changed, update state for the call determining if it is an |
| 620 | // emergency call. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 621 | Uri newHandle = telecomCall.getDetails().getHandle(); |
| 622 | if (!Objects.equals(handle, newHandle)) { |
| 623 | handle = newHandle; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 624 | updateEmergencyCallState(); |
| 625 | } |
| 626 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 627 | TelecomManager telecomManager = context.getSystemService(TelecomManager.class); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 628 | // If the phone account handle of the call is set, cache capability bit indicating whether |
| 629 | // the phone account supports call subjects. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 630 | PhoneAccountHandle newPhoneAccountHandle = telecomCall.getDetails().getAccountHandle(); |
| 631 | if (!Objects.equals(phoneAccountHandle, newPhoneAccountHandle)) { |
| 632 | phoneAccountHandle = newPhoneAccountHandle; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 633 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 634 | if (phoneAccountHandle != null) { |
| 635 | PhoneAccount phoneAccount = telecomManager.getPhoneAccount(phoneAccountHandle); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 636 | if (phoneAccount != null) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 637 | isCallSubjectSupported = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 638 | phoneAccount.hasCapabilities(PhoneAccount.CAPABILITY_CALL_SUBJECT); |
wangqi | da410d3 | 2018-03-06 16:51:38 -0800 | [diff] [blame] | 639 | if (phoneAccount.hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)) { |
| 640 | cacheCarrierConfiguration(phoneAccountHandle); |
| 641 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 642 | } |
| 643 | } |
| 644 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 645 | if (PermissionsUtil.hasPermission(context, permission.READ_PHONE_STATE)) { |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 646 | updateIsVoiceMailNumber(); |
| 647 | callCapableAccounts = telecomManager.getCallCapablePhoneAccounts(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 648 | countryIso = GeoUtil.getCurrentCountryIso(context); |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 649 | } |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 650 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | /** |
wangqi | da410d3 | 2018-03-06 16:51:38 -0800 | [diff] [blame] | 654 | * Caches frequently used carrier configuration locally. |
| 655 | * |
| 656 | * @param accountHandle The PhoneAccount handle. |
| 657 | */ |
| 658 | @SuppressLint("MissingPermission") |
| 659 | private void cacheCarrierConfiguration(PhoneAccountHandle accountHandle) { |
| 660 | if (!PermissionsUtil.hasPermission(context, permission.READ_PHONE_STATE)) { |
| 661 | return; |
| 662 | } |
| 663 | if (VERSION.SDK_INT < VERSION_CODES.O) { |
| 664 | return; |
| 665 | } |
| 666 | // TODO(a bug): This may take several seconds to complete, revisit it to move it to worker |
| 667 | // thread. |
| 668 | carrierConfig = |
| 669 | TelephonyManagerCompat.getTelephonyManagerForPhoneAccountHandle(context, accountHandle) |
| 670 | .getCarrierConfig(); |
| 671 | } |
| 672 | |
| 673 | /** |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 674 | * Tests corruption of the {@code callExtras} bundle by calling {@link |
| 675 | * Bundle#containsKey(String)}. If the bundle is corrupted a {@link IllegalArgumentException} will |
| 676 | * be thrown and caught by this function. |
| 677 | * |
| 678 | * @param callExtras the bundle to verify |
| 679 | * @return {@code true} if the bundle is corrupted, {@code false} otherwise. |
| 680 | */ |
| 681 | protected boolean areCallExtrasCorrupted(Bundle callExtras) { |
| 682 | /** |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 683 | * There's currently a bug in Telephony service (a bug) that could corrupt the extras |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 684 | * bundle, resulting in a IllegalArgumentException while validating data under {@link |
| 685 | * Bundle#containsKey(String)}. |
| 686 | */ |
| 687 | try { |
| 688 | callExtras.containsKey(Connection.EXTRA_CHILD_ADDRESS); |
| 689 | return false; |
| 690 | } catch (IllegalArgumentException e) { |
| 691 | LogUtil.e( |
| 692 | "DialerCall.areCallExtrasCorrupted", "callExtras is corrupted, ignoring exception", e); |
| 693 | return true; |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | protected void updateFromCallExtras(Bundle callExtras) { |
| 698 | if (callExtras == null || areCallExtrasCorrupted(callExtras)) { |
| 699 | /** |
| 700 | * If the bundle is corrupted, abandon information update as a work around. These are not |
| 701 | * critical for the dialer to function. |
| 702 | */ |
| 703 | return; |
| 704 | } |
| 705 | // Check for a change in the child address and notify any listeners. |
| 706 | if (callExtras.containsKey(Connection.EXTRA_CHILD_ADDRESS)) { |
| 707 | String childNumber = callExtras.getString(Connection.EXTRA_CHILD_ADDRESS); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 708 | if (!Objects.equals(childNumber, this.childNumber)) { |
| 709 | this.childNumber = childNumber; |
| 710 | for (DialerCallListener listener : listeners) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 711 | listener.onDialerCallChildNumberChange(); |
| 712 | } |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | // Last forwarded number comes in as an array of strings. We want to choose the |
| 717 | // last item in the array. The forwarding numbers arrive independently of when the |
| 718 | // call is originally set up, so we need to notify the the UI of the change. |
| 719 | if (callExtras.containsKey(Connection.EXTRA_LAST_FORWARDED_NUMBER)) { |
| 720 | ArrayList<String> lastForwardedNumbers = |
| 721 | callExtras.getStringArrayList(Connection.EXTRA_LAST_FORWARDED_NUMBER); |
| 722 | |
| 723 | if (lastForwardedNumbers != null) { |
| 724 | String lastForwardedNumber = null; |
| 725 | if (!lastForwardedNumbers.isEmpty()) { |
| 726 | lastForwardedNumber = lastForwardedNumbers.get(lastForwardedNumbers.size() - 1); |
| 727 | } |
| 728 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 729 | if (!Objects.equals(lastForwardedNumber, this.lastForwardedNumber)) { |
| 730 | this.lastForwardedNumber = lastForwardedNumber; |
| 731 | for (DialerCallListener listener : listeners) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 732 | listener.onDialerCallLastForwardedNumberChange(); |
| 733 | } |
| 734 | } |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | // DialerCall subject is present in the extras at the start of call, so we do not need to |
| 739 | // notify any other listeners of this. |
| 740 | if (callExtras.containsKey(Connection.EXTRA_CALL_SUBJECT)) { |
| 741 | String callSubject = callExtras.getString(Connection.EXTRA_CALL_SUBJECT); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 742 | if (!Objects.equals(this.callSubject, callSubject)) { |
| 743 | this.callSubject = callSubject; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 744 | } |
| 745 | } |
| 746 | } |
| 747 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 748 | public String getId() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 749 | return id; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 750 | } |
| 751 | |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 752 | /** |
| 753 | * @return name appended with a number if the number is restricted/unknown and the user has |
| 754 | * received more than one restricted/unknown call. |
| 755 | */ |
| 756 | @Nullable |
| 757 | public String updateNameIfRestricted(@Nullable String name) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 758 | if (name != null && isHiddenNumber() && hiddenId != 0 && hiddenCounter > 1) { |
| 759 | return context.getString(R.string.unknown_counter, name, hiddenId); |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 760 | } |
| 761 | return name; |
| 762 | } |
| 763 | |
| 764 | public static void clearRestrictedCount() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 765 | hiddenCounter = 0; |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | private boolean isHiddenNumber() { |
| 769 | return getNumberPresentation() == TelecomManager.PRESENTATION_RESTRICTED |
| 770 | || getNumberPresentation() == TelecomManager.PRESENTATION_UNKNOWN; |
| 771 | } |
| 772 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 773 | public boolean hasShownWiFiToLteHandoverToast() { |
| 774 | return hasShownWiFiToLteHandoverToast; |
| 775 | } |
| 776 | |
| 777 | public void setHasShownWiFiToLteHandoverToast() { |
| 778 | hasShownWiFiToLteHandoverToast = true; |
| 779 | } |
| 780 | |
| 781 | public boolean showWifiHandoverAlertAsToast() { |
| 782 | return doNotShowDialogForHandoffToWifiFailure; |
| 783 | } |
| 784 | |
| 785 | public void setDoNotShowDialogForHandoffToWifiFailure(boolean bool) { |
| 786 | doNotShowDialogForHandoffToWifiFailure = bool; |
| 787 | } |
| 788 | |
wangqi | da410d3 | 2018-03-06 16:51:38 -0800 | [diff] [blame] | 789 | public boolean showVideoChargesAlertDialog() { |
| 790 | if (carrierConfig == null) { |
| 791 | return false; |
| 792 | } |
| 793 | return carrierConfig.getBoolean( |
| 794 | TelephonyManagerCompat.CARRIER_CONFIG_KEY_SHOW_VIDEO_CALL_CHARGES_ALERT_DIALOG_BOOL); |
| 795 | } |
| 796 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 797 | public long getTimeAddedMs() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 798 | return timeAddedMs; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | @Nullable |
| 802 | public String getNumber() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 803 | return TelecomCallUtil.getNumber(telecomCall); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | public void blockCall() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 807 | telecomCall.reject(false, null); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 808 | setState(State.BLOCKED); |
| 809 | } |
| 810 | |
| 811 | @Nullable |
| 812 | public Uri getHandle() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 813 | return telecomCall == null ? null : telecomCall.getDetails().getHandle(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | public boolean isEmergencyCall() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 817 | return isEmergencyCall; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | public boolean isPotentialEmergencyCallback() { |
| 821 | // The property PROPERTY_EMERGENCY_CALLBACK_MODE is only set for CDMA calls when the system |
| 822 | // is actually in emergency callback mode (ie data is disabled). |
| 823 | if (hasProperty(Details.PROPERTY_EMERGENCY_CALLBACK_MODE)) { |
| 824 | return true; |
| 825 | } |
| 826 | // We want to treat any incoming call that arrives a short time after an outgoing emergency call |
| 827 | // as a potential emergency callback. |
| 828 | if (getExtras() != null |
| 829 | && getExtras().getLong(TelecomManagerCompat.EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS, 0) |
| 830 | > 0) { |
| 831 | long lastEmergencyCallMillis = |
| 832 | getExtras().getLong(TelecomManagerCompat.EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS, 0); |
| 833 | if (isInEmergencyCallbackWindow(lastEmergencyCallMillis)) { |
| 834 | return true; |
| 835 | } |
| 836 | } |
| 837 | return false; |
| 838 | } |
| 839 | |
| 840 | boolean isInEmergencyCallbackWindow(long timestampMillis) { |
| 841 | long emergencyCallbackWindowMillis = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 842 | ConfigProviderBindings.get(context) |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 843 | .getLong(CONFIG_EMERGENCY_CALLBACK_WINDOW_MILLIS, TimeUnit.MINUTES.toMillis(5)); |
| 844 | return System.currentTimeMillis() - timestampMillis < emergencyCallbackWindowMillis; |
| 845 | } |
| 846 | |
| 847 | public int getState() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 848 | if (telecomCall != null && telecomCall.getParent() != null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 849 | return State.CONFERENCED; |
| 850 | } else { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 851 | return state; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 852 | } |
| 853 | } |
| 854 | |
yueg | 265089a | 2017-10-06 14:35:15 -0700 | [diff] [blame] | 855 | public int getNonConferenceState() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 856 | return state; |
yueg | 265089a | 2017-10-06 14:35:15 -0700 | [diff] [blame] | 857 | } |
| 858 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 859 | public void setState(int state) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 860 | if (state == State.INCOMING) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 861 | logState.isIncoming = true; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 862 | } else if (state == State.DISCONNECTED) { |
| 863 | long newDuration = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 864 | getConnectTimeMillis() == 0 ? 0 : System.currentTimeMillis() - getConnectTimeMillis(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 865 | if (this.state != state) { |
| 866 | logState.duration = newDuration; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 867 | } else { |
| 868 | LogUtil.i( |
| 869 | "DialerCall.setState", |
| 870 | "ignoring state transition from DISCONNECTED to DISCONNECTED." |
| 871 | + " Duration would have changed from %s to %s", |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 872 | logState.duration, |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 873 | newDuration); |
| 874 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 875 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 876 | this.state = state; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | public int getNumberPresentation() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 880 | return telecomCall == null ? -1 : telecomCall.getDetails().getHandlePresentation(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | public int getCnapNamePresentation() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 884 | return telecomCall == null ? -1 : telecomCall.getDetails().getCallerDisplayNamePresentation(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | @Nullable |
| 888 | public String getCnapName() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 889 | return telecomCall == null ? null : getTelecomCall().getDetails().getCallerDisplayName(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 890 | } |
| 891 | |
| 892 | public Bundle getIntentExtras() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 893 | return telecomCall.getDetails().getIntentExtras(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | @Nullable |
| 897 | public Bundle getExtras() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 898 | return telecomCall == null ? null : telecomCall.getDetails().getExtras(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | /** @return The child number for the call, or {@code null} if none specified. */ |
| 902 | public String getChildNumber() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 903 | return childNumber; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | /** @return The last forwarded number for the call, or {@code null} if none specified. */ |
| 907 | public String getLastForwardedNumber() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 908 | return lastForwardedNumber; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 909 | } |
| 910 | |
wangqi | f4ba345 | 2018-01-09 11:26:29 -0800 | [diff] [blame] | 911 | public boolean isCallForwarded() { |
| 912 | return isCallForwarded; |
| 913 | } |
| 914 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 915 | /** @return The call subject, or {@code null} if none specified. */ |
| 916 | public String getCallSubject() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 917 | return callSubject; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | /** |
| 921 | * @return {@code true} if the call's phone account supports call subjects, {@code false} |
| 922 | * otherwise. |
| 923 | */ |
| 924 | public boolean isCallSubjectSupported() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 925 | return isCallSubjectSupported; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | /** Returns call disconnect cause, defined by {@link DisconnectCause}. */ |
| 929 | public DisconnectCause getDisconnectCause() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 930 | if (state == State.DISCONNECTED || state == State.IDLE) { |
| 931 | return disconnectCause; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | return new DisconnectCause(DisconnectCause.UNKNOWN); |
| 935 | } |
| 936 | |
| 937 | public void setDisconnectCause(DisconnectCause disconnectCause) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 938 | this.disconnectCause = disconnectCause; |
| 939 | logState.disconnectCause = this.disconnectCause; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | /** Returns the possible text message responses. */ |
| 943 | public List<String> getCannedSmsResponses() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 944 | return telecomCall.getCannedTextResponses(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | /** Checks if the call supports the given set of capabilities supplied as a bit mask. */ |
| 948 | public boolean can(int capabilities) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 949 | int supportedCapabilities = telecomCall.getDetails().getCallCapabilities(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 950 | |
| 951 | if ((capabilities & Call.Details.CAPABILITY_MERGE_CONFERENCE) != 0) { |
| 952 | // We allow you to merge if the capabilities allow it or if it is a call with |
| 953 | // conferenceable calls. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 954 | if (telecomCall.getConferenceableCalls().isEmpty() |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 955 | && ((Call.Details.CAPABILITY_MERGE_CONFERENCE & supportedCapabilities) == 0)) { |
| 956 | // Cannot merge calls if there are no calls to merge with. |
| 957 | return false; |
| 958 | } |
| 959 | capabilities &= ~Call.Details.CAPABILITY_MERGE_CONFERENCE; |
| 960 | } |
| 961 | return (capabilities == (capabilities & supportedCapabilities)); |
| 962 | } |
| 963 | |
| 964 | public boolean hasProperty(int property) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 965 | return telecomCall.getDetails().hasProperty(property); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 966 | } |
| 967 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 968 | @NonNull |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 969 | public String getUniqueCallId() { |
| 970 | return uniqueCallId; |
| 971 | } |
| 972 | |
| 973 | /** Gets the time when the call first became active. */ |
| 974 | public long getConnectTimeMillis() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 975 | return telecomCall.getDetails().getConnectTimeMillis(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 976 | } |
| 977 | |
wangqi | ed677ef | 2018-04-04 12:03:00 -0700 | [diff] [blame] | 978 | /** |
| 979 | * Gets the time when the call is created (see {@link Details#getCreationTimeMillis()}). This is |
| 980 | * the same time that is logged as the start time in the Call Log (see {@link |
| 981 | * android.provider.CallLog.Calls#DATE}). |
| 982 | */ |
| 983 | @TargetApi(26) |
| 984 | public long getCreationTimeMillis() { |
| 985 | return telecomCall.getDetails().getCreationTimeMillis(); |
| 986 | } |
| 987 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 988 | public boolean isConferenceCall() { |
| 989 | return hasProperty(Call.Details.PROPERTY_CONFERENCE); |
| 990 | } |
| 991 | |
| 992 | @Nullable |
| 993 | public GatewayInfo getGatewayInfo() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 994 | return telecomCall == null ? null : telecomCall.getDetails().getGatewayInfo(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | @Nullable |
| 998 | public PhoneAccountHandle getAccountHandle() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 999 | return telecomCall == null ? null : telecomCall.getDetails().getAccountHandle(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1000 | } |
| 1001 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1002 | /** @return The {@link VideoCall} instance associated with the {@link Call}. */ |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1003 | public VideoCall getVideoCall() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1004 | return telecomCall == null ? null : telecomCall.getVideoCall(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | public List<String> getChildCallIds() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1008 | return childCallIds; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | public String getParentId() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1012 | Call parentCall = telecomCall.getParent(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1013 | if (parentCall != null) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1014 | return dialerCallDelegate.getDialerCallFromTelecomCall(parentCall).getId(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1015 | } |
| 1016 | return null; |
| 1017 | } |
| 1018 | |
| 1019 | public int getVideoState() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1020 | return telecomCall.getDetails().getVideoState(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | public boolean isVideoCall() { |
roldenburg | 2cec380 | 2017-10-11 16:26:51 -0700 | [diff] [blame] | 1024 | return getVideoTech().isTransmittingOrReceiving() || VideoProfile.isVideo(getVideoState()); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
wangqi | 8d407a0 | 2018-02-15 15:32:52 -0800 | [diff] [blame] | 1027 | @TargetApi(28) |
wangqi | f6be617 | 2018-03-30 15:57:56 -0700 | [diff] [blame] | 1028 | public boolean isActiveRttCall() { |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 1029 | if (BuildCompat.isAtLeastP()) { |
| 1030 | return getTelecomCall().isRttActive(); |
| 1031 | } else { |
| 1032 | return false; |
| 1033 | } |
| 1034 | } |
| 1035 | |
wangqi | 153af2f | 2018-02-15 16:21:49 -0800 | [diff] [blame] | 1036 | @TargetApi(28) |
| 1037 | public RttCall getRttCall() { |
wangqi | f6be617 | 2018-03-30 15:57:56 -0700 | [diff] [blame] | 1038 | if (!isActiveRttCall()) { |
wangqi | 153af2f | 2018-02-15 16:21:49 -0800 | [diff] [blame] | 1039 | return null; |
| 1040 | } |
| 1041 | return getTelecomCall().getRttCall(); |
| 1042 | } |
| 1043 | |
wangqi | f6be617 | 2018-03-30 15:57:56 -0700 | [diff] [blame] | 1044 | @TargetApi(28) |
| 1045 | public boolean canUpgradeToRttCall() { |
| 1046 | PhoneAccount phoneAccount = getPhoneAccount(); |
| 1047 | if (phoneAccount == null) { |
| 1048 | return false; |
| 1049 | } |
| 1050 | if (!phoneAccount.hasCapabilities(PhoneAccount.CAPABILITY_RTT)) { |
| 1051 | return false; |
| 1052 | } |
| 1053 | if (isActiveRttCall()) { |
| 1054 | return false; |
| 1055 | } |
| 1056 | if (isVideoCall()) { |
| 1057 | return false; |
| 1058 | } |
| 1059 | if (isConferenceCall()) { |
| 1060 | return false; |
| 1061 | } |
| 1062 | if (CallList.getInstance().hasActiveRttCall()) { |
| 1063 | return false; |
| 1064 | } |
| 1065 | return true; |
| 1066 | } |
| 1067 | |
| 1068 | @TargetApi(28) |
| 1069 | public void sendRttUpgradeRequest() { |
| 1070 | getTelecomCall().sendRttRequest(); |
| 1071 | } |
| 1072 | |
wangqi | bc28ea7 | 2018-04-02 16:23:00 -0700 | [diff] [blame] | 1073 | @TargetApi(28) |
| 1074 | public void respondToRttRequest(boolean accept, int rttRequestId) { |
wangqi | 81e373e | 2018-04-24 10:50:57 -0700 | [diff] [blame] | 1075 | Logger.get(context) |
| 1076 | .logCallImpression( |
| 1077 | accept |
| 1078 | ? DialerImpression.Type.RTT_MID_CALL_ACCEPTED |
| 1079 | : DialerImpression.Type.RTT_MID_CALL_REJECTED, |
| 1080 | getUniqueCallId(), |
| 1081 | getTimeAddedMs()); |
wangqi | bc28ea7 | 2018-04-02 16:23:00 -0700 | [diff] [blame] | 1082 | getTelecomCall().respondToRttRequest(rttRequestId, accept); |
| 1083 | } |
| 1084 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1085 | public boolean hasReceivedVideoUpgradeRequest() { |
| 1086 | return VideoUtils.hasReceivedVideoUpgradeRequest(getVideoTech().getSessionModificationState()); |
| 1087 | } |
| 1088 | |
| 1089 | public boolean hasSentVideoUpgradeRequest() { |
| 1090 | return VideoUtils.hasSentVideoUpgradeRequest(getVideoTech().getSessionModificationState()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1091 | } |
| 1092 | |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 1093 | public boolean hasSentRttUpgradeRequest() { |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 1094 | return false; |
| 1095 | } |
| 1096 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1097 | /** |
| 1098 | * Determines if the call handle is an emergency number or not and caches the result to avoid |
| 1099 | * repeated calls to isEmergencyNumber. |
| 1100 | */ |
| 1101 | private void updateEmergencyCallState() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1102 | isEmergencyCall = TelecomCallUtil.isEmergencyCall(telecomCall); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1103 | } |
| 1104 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1105 | public LogState getLogState() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1106 | return logState; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | /** |
| 1110 | * Determines if the call is an external call. |
| 1111 | * |
| 1112 | * <p>An external call is one which does not exist locally for the {@link |
| 1113 | * android.telecom.ConnectionService} it is associated with. |
| 1114 | * |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1115 | * @return {@code true} if the call is an external call, {@code false} otherwise. |
| 1116 | */ |
linyuh | 437ae95 | 2018-03-26 12:46:18 -0700 | [diff] [blame] | 1117 | boolean isExternalCall() { |
| 1118 | return hasProperty(CallCompat.Details.PROPERTY_IS_EXTERNAL_CALL); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | /** |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1122 | * Determines if answering this call will cause an ongoing video call to be dropped. |
| 1123 | * |
| 1124 | * @return {@code true} if answering this call will drop an ongoing video call, {@code false} |
| 1125 | * otherwise. |
| 1126 | */ |
| 1127 | public boolean answeringDisconnectsForegroundVideoCall() { |
| 1128 | Bundle extras = getExtras(); |
| 1129 | if (extras == null |
| 1130 | || !extras.containsKey(CallCompat.Details.EXTRA_ANSWERING_DROPS_FOREGROUND_CALL)) { |
| 1131 | return false; |
| 1132 | } |
| 1133 | return extras.getBoolean(CallCompat.Details.EXTRA_ANSWERING_DROPS_FOREGROUND_CALL); |
| 1134 | } |
| 1135 | |
| 1136 | private void parseCallSpecificAppData() { |
| 1137 | if (isExternalCall()) { |
| 1138 | return; |
| 1139 | } |
| 1140 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1141 | logState.callSpecificAppData = CallIntentParser.getCallSpecificAppData(getIntentExtras()); |
| 1142 | if (logState.callSpecificAppData == null) { |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1143 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1144 | logState.callSpecificAppData = |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1145 | CallSpecificAppData.newBuilder() |
| 1146 | .setCallInitiationType(CallInitiationType.Type.EXTERNAL_INITIATION) |
| 1147 | .build(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1148 | } |
| 1149 | if (getState() == State.INCOMING) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1150 | logState.callSpecificAppData = |
| 1151 | logState |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1152 | .callSpecificAppData |
| 1153 | .toBuilder() |
| 1154 | .setCallInitiationType(CallInitiationType.Type.INCOMING_INITIATION) |
| 1155 | .build(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1156 | } |
| 1157 | } |
| 1158 | |
| 1159 | @Override |
| 1160 | public String toString() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1161 | if (telecomCall == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1162 | // This should happen only in testing since otherwise we would never have a null |
| 1163 | // Telecom call. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1164 | return String.valueOf(id); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | return String.format( |
| 1168 | Locale.US, |
| 1169 | "[%s, %s, %s, %s, children:%s, parent:%s, " |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1170 | + "conferenceable:%s, videoState:%s, mSessionModificationState:%d, CameraDir:%s]", |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1171 | id, |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1172 | State.toString(getState()), |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1173 | Details.capabilitiesToString(telecomCall.getDetails().getCallCapabilities()), |
| 1174 | Details.propertiesToString(telecomCall.getDetails().getCallProperties()), |
| 1175 | childCallIds, |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1176 | getParentId(), |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1177 | this.telecomCall.getConferenceableCalls(), |
| 1178 | VideoProfile.videoStateToString(telecomCall.getDetails().getVideoState()), |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1179 | getVideoTech().getSessionModificationState(), |
| 1180 | getCameraDir()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | public String toSimpleString() { |
| 1184 | return super.toString(); |
| 1185 | } |
| 1186 | |
| 1187 | @CallHistoryStatus |
| 1188 | public int getCallHistoryStatus() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1189 | return callHistoryStatus; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | public void setCallHistoryStatus(@CallHistoryStatus int callHistoryStatus) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1193 | this.callHistoryStatus = callHistoryStatus; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | public boolean didShowCameraPermission() { |
| 1197 | return didShowCameraPermission; |
| 1198 | } |
| 1199 | |
| 1200 | public void setDidShowCameraPermission(boolean didShow) { |
| 1201 | didShowCameraPermission = didShow; |
| 1202 | } |
| 1203 | |
wangqi | da410d3 | 2018-03-06 16:51:38 -0800 | [diff] [blame] | 1204 | public boolean didDismissVideoChargesAlertDialog() { |
| 1205 | return didDismissVideoChargesAlertDialog; |
| 1206 | } |
| 1207 | |
| 1208 | public void setDidDismissVideoChargesAlertDialog(boolean didDismiss) { |
| 1209 | didDismissVideoChargesAlertDialog = didDismiss; |
| 1210 | } |
| 1211 | |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 1212 | @Nullable |
| 1213 | public Boolean isInGlobalSpamList() { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1214 | return isInGlobalSpamList; |
| 1215 | } |
| 1216 | |
| 1217 | public void setIsInGlobalSpamList(boolean inSpamList) { |
| 1218 | isInGlobalSpamList = inSpamList; |
| 1219 | } |
| 1220 | |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 1221 | @Nullable |
| 1222 | public Boolean isInUserSpamList() { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1223 | return isInUserSpamList; |
| 1224 | } |
| 1225 | |
| 1226 | public void setIsInUserSpamList(boolean inSpamList) { |
| 1227 | isInUserSpamList = inSpamList; |
| 1228 | } |
| 1229 | |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 1230 | @Nullable |
| 1231 | public Boolean isInUserWhiteList() { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1232 | return isInUserWhiteList; |
| 1233 | } |
| 1234 | |
| 1235 | public void setIsInUserWhiteList(boolean inWhiteList) { |
| 1236 | isInUserWhiteList = inWhiteList; |
| 1237 | } |
| 1238 | |
| 1239 | public boolean isSpam() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1240 | return isSpam; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | public void setSpam(boolean isSpam) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1244 | this.isSpam = isSpam; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | public boolean isBlocked() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1248 | return isBlocked; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | public void setBlockedStatus(boolean isBlocked) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1252 | this.isBlocked = isBlocked; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | public boolean isRemotelyHeld() { |
| 1256 | return isRemotelyHeld; |
| 1257 | } |
| 1258 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1259 | public boolean isMergeInProcess() { |
| 1260 | return isMergeInProcess; |
| 1261 | } |
| 1262 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1263 | public boolean isIncoming() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1264 | return logState.isIncoming; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1265 | } |
| 1266 | |
erfanian | 2cf2c34 | 2017-12-21 12:01:33 -0800 | [diff] [blame] | 1267 | /** |
| 1268 | * Try and determine if the call used assisted dialing. |
| 1269 | * |
| 1270 | * <p>We will not be able to verify a call underwent assisted dialing until the Platform |
| 1271 | * implmentation is complete in P+. |
| 1272 | * |
| 1273 | * @return a boolean indicating assisted dialing may have been performed |
| 1274 | */ |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1275 | public boolean isAssistedDialed() { |
| 1276 | if (getIntentExtras() != null) { |
erfanian | d2e5d0b | 2018-03-02 14:54:35 -0800 | [diff] [blame] | 1277 | // P and below uses the existence of USE_ASSISTED_DIALING to indicate assisted dialing |
erfanian | 2cf2c34 | 2017-12-21 12:01:33 -0800 | [diff] [blame] | 1278 | // was used. The Dialer client is responsible for performing assisted dialing before |
| 1279 | // placing the outgoing call. |
| 1280 | // |
| 1281 | // The existence of the assisted dialing extras indicates that assisted dialing took place. |
| 1282 | if (getIntentExtras().getBoolean(TelephonyManagerCompat.USE_ASSISTED_DIALING, false) |
| 1283 | && getAssistedDialingExtras() != null |
| 1284 | && Build.VERSION.SDK_INT <= ConcreteCreator.BUILD_CODE_CEILING) { |
| 1285 | return true; |
| 1286 | } |
| 1287 | } |
| 1288 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1289 | return false; |
| 1290 | } |
| 1291 | |
erfanian | 2cf2c34 | 2017-12-21 12:01:33 -0800 | [diff] [blame] | 1292 | @Nullable |
erfanian | d0f207f | 2017-10-11 12:23:29 -0700 | [diff] [blame] | 1293 | public TransformationInfo getAssistedDialingExtras() { |
erfanian | 2cf2c34 | 2017-12-21 12:01:33 -0800 | [diff] [blame] | 1294 | if (getIntentExtras() == null) { |
| 1295 | return null; |
erfanian | d0f207f | 2017-10-11 12:23:29 -0700 | [diff] [blame] | 1296 | } |
erfanian | 2cf2c34 | 2017-12-21 12:01:33 -0800 | [diff] [blame] | 1297 | |
| 1298 | if (getIntentExtras().getBundle(TelephonyManagerCompat.ASSISTED_DIALING_EXTRAS) == null) { |
| 1299 | return null; |
| 1300 | } |
| 1301 | |
erfanian | f255661 | 2018-01-23 09:55:59 -0800 | [diff] [blame] | 1302 | // Used in N-OMR1 |
erfanian | 2cf2c34 | 2017-12-21 12:01:33 -0800 | [diff] [blame] | 1303 | return TransformationInfo.newInstanceFromBundle( |
| 1304 | getIntentExtras().getBundle(TelephonyManagerCompat.ASSISTED_DIALING_EXTRAS)); |
erfanian | d0f207f | 2017-10-11 12:23:29 -0700 | [diff] [blame] | 1305 | } |
| 1306 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1307 | public LatencyReport getLatencyReport() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1308 | return latencyReport; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1309 | } |
| 1310 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1311 | public int getAnswerAndReleaseButtonDisplayedTimes() { |
| 1312 | return answerAndReleaseButtonDisplayedTimes; |
| 1313 | } |
| 1314 | |
| 1315 | public void increaseAnswerAndReleaseButtonDisplayedTimes() { |
| 1316 | answerAndReleaseButtonDisplayedTimes++; |
| 1317 | } |
| 1318 | |
| 1319 | public boolean getReleasedByAnsweringSecondCall() { |
| 1320 | return releasedByAnsweringSecondCall; |
| 1321 | } |
| 1322 | |
| 1323 | public void setReleasedByAnsweringSecondCall(boolean releasedByAnsweringSecondCall) { |
| 1324 | this.releasedByAnsweringSecondCall = releasedByAnsweringSecondCall; |
| 1325 | } |
| 1326 | |
| 1327 | public int getSecondCallWithoutAnswerAndReleasedButtonTimes() { |
| 1328 | return secondCallWithoutAnswerAndReleasedButtonTimes; |
| 1329 | } |
| 1330 | |
| 1331 | public void increaseSecondCallWithoutAnswerAndReleasedButtonTimes() { |
| 1332 | secondCallWithoutAnswerAndReleasedButtonTimes++; |
| 1333 | } |
| 1334 | |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1335 | @Nullable |
| 1336 | public EnrichedCallCapabilities getEnrichedCallCapabilities() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1337 | return enrichedCallCapabilities; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | public void setEnrichedCallCapabilities( |
| 1341 | @Nullable EnrichedCallCapabilities mEnrichedCallCapabilities) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1342 | this.enrichedCallCapabilities = mEnrichedCallCapabilities; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | @Nullable |
| 1346 | public Session getEnrichedCallSession() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1347 | return enrichedCallSession; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | public void setEnrichedCallSession(@Nullable Session mEnrichedCallSession) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1351 | this.enrichedCallSession = mEnrichedCallSession; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1352 | } |
| 1353 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1354 | public void unregisterCallback() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1355 | telecomCall.unregisterCallback(telecomCallCallback); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1356 | } |
| 1357 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1358 | public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) { |
| 1359 | LogUtil.i( |
| 1360 | "DialerCall.phoneAccountSelected", |
| 1361 | "accountHandle: %s, setDefault: %b", |
| 1362 | accountHandle, |
| 1363 | setDefault); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1364 | telecomCall.phoneAccountSelected(accountHandle, setDefault); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | public void disconnect() { |
| 1368 | LogUtil.i("DialerCall.disconnect", ""); |
| 1369 | setState(DialerCall.State.DISCONNECTING); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1370 | for (DialerCallListener listener : listeners) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1371 | listener.onDialerCallUpdate(); |
| 1372 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1373 | telecomCall.disconnect(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | public void hold() { |
| 1377 | LogUtil.i("DialerCall.hold", ""); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1378 | telecomCall.hold(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | public void unhold() { |
| 1382 | LogUtil.i("DialerCall.unhold", ""); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1383 | telecomCall.unhold(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | public void splitFromConference() { |
| 1387 | LogUtil.i("DialerCall.splitFromConference", ""); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1388 | telecomCall.splitFromConference(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | public void answer(int videoState) { |
| 1392 | LogUtil.i("DialerCall.answer", "videoState: " + videoState); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1393 | telecomCall.answer(videoState); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1394 | } |
| 1395 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1396 | public void answer() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1397 | answer(telecomCall.getDetails().getVideoState()); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1398 | } |
| 1399 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1400 | public void reject(boolean rejectWithMessage, String message) { |
| 1401 | LogUtil.i("DialerCall.reject", ""); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1402 | telecomCall.reject(rejectWithMessage, message); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1403 | } |
| 1404 | |
| 1405 | /** Return the string label to represent the call provider */ |
| 1406 | public String getCallProviderLabel() { |
| 1407 | if (callProviderLabel == null) { |
| 1408 | PhoneAccount account = getPhoneAccount(); |
| 1409 | if (account != null && !TextUtils.isEmpty(account.getLabel())) { |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 1410 | if (callCapableAccounts != null && callCapableAccounts.size() > 1) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1411 | callProviderLabel = account.getLabel().toString(); |
| 1412 | } |
| 1413 | } |
| 1414 | if (callProviderLabel == null) { |
| 1415 | callProviderLabel = ""; |
| 1416 | } |
| 1417 | } |
| 1418 | return callProviderLabel; |
| 1419 | } |
| 1420 | |
| 1421 | private PhoneAccount getPhoneAccount() { |
| 1422 | PhoneAccountHandle accountHandle = getAccountHandle(); |
| 1423 | if (accountHandle == null) { |
| 1424 | return null; |
| 1425 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1426 | return context.getSystemService(TelecomManager.class).getPhoneAccount(accountHandle); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1427 | } |
| 1428 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1429 | public VideoTech getVideoTech() { |
roldenburg | 7bb9623 | 2017-10-09 10:32:05 -0700 | [diff] [blame] | 1430 | if (videoTech == null) { |
roldenburg | 6bd612f | 2018-01-18 12:57:19 -0800 | [diff] [blame] | 1431 | videoTech = videoTechManager.getVideoTech(getAccountHandle()); |
roldenburg | 7bb9623 | 2017-10-09 10:32:05 -0700 | [diff] [blame] | 1432 | |
| 1433 | // Only store the first video tech type found to be available during the life of the call. |
| 1434 | if (selectedAvailableVideoTechType == com.android.dialer.logging.VideoTech.Type.NONE) { |
| 1435 | // Update the video tech. |
| 1436 | selectedAvailableVideoTechType = videoTech.getVideoTechType(); |
| 1437 | } |
| 1438 | } |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1439 | return videoTech; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1440 | } |
| 1441 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1442 | public String getCallbackNumber() { |
| 1443 | if (callbackNumber == null) { |
| 1444 | // Show the emergency callback number if either: |
| 1445 | // 1. This is an emergency call. |
| 1446 | // 2. The phone is in Emergency Callback Mode, which means we should show the callback |
| 1447 | // number. |
| 1448 | boolean showCallbackNumber = hasProperty(Details.PROPERTY_EMERGENCY_CALLBACK_MODE); |
| 1449 | |
| 1450 | if (isEmergencyCall() || showCallbackNumber) { |
wangqi | 339b4f3 | 2017-09-18 14:32:09 -0700 | [diff] [blame] | 1451 | callbackNumber = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1452 | context.getSystemService(TelecomManager.class).getLine1Number(getAccountHandle()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1453 | } |
| 1454 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1455 | if (callbackNumber == null) { |
| 1456 | callbackNumber = ""; |
| 1457 | } |
| 1458 | } |
| 1459 | return callbackNumber; |
| 1460 | } |
| 1461 | |
wangqi | 9753935 | 2017-09-25 11:15:16 -0700 | [diff] [blame] | 1462 | public String getSimCountryIso() { |
| 1463 | String simCountryIso = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1464 | TelephonyManagerCompat.getTelephonyManagerForPhoneAccountHandle(context, getAccountHandle()) |
wangqi | 9753935 | 2017-09-25 11:15:16 -0700 | [diff] [blame] | 1465 | .getSimCountryIso(); |
| 1466 | if (!TextUtils.isEmpty(simCountryIso)) { |
| 1467 | simCountryIso = simCountryIso.toUpperCase(Locale.US); |
| 1468 | } |
| 1469 | return simCountryIso; |
| 1470 | } |
| 1471 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1472 | @Override |
| 1473 | public void onVideoTechStateChanged() { |
| 1474 | update(); |
| 1475 | } |
| 1476 | |
| 1477 | @Override |
| 1478 | public void onSessionModificationStateChanged() { |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 1479 | Trace.beginSection("DialerCall.onSessionModificationStateChanged"); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1480 | for (DialerCallListener listener : listeners) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1481 | listener.onDialerCallSessionModificationStateChange(); |
| 1482 | } |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 1483 | Trace.endSection(); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1484 | } |
| 1485 | |
| 1486 | @Override |
| 1487 | public void onCameraDimensionsChanged(int width, int height) { |
| 1488 | InCallVideoCallCallbackNotifier.getInstance().cameraDimensionsChanged(this, width, height); |
| 1489 | } |
| 1490 | |
| 1491 | @Override |
| 1492 | public void onPeerDimensionsChanged(int width, int height) { |
| 1493 | InCallVideoCallCallbackNotifier.getInstance().peerDimensionsChanged(this, width, height); |
| 1494 | } |
| 1495 | |
| 1496 | @Override |
| 1497 | public void onVideoUpgradeRequestReceived() { |
| 1498 | LogUtil.enterBlock("DialerCall.onVideoUpgradeRequestReceived"); |
| 1499 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1500 | for (DialerCallListener listener : listeners) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1501 | listener.onDialerCallUpgradeToVideo(); |
| 1502 | } |
| 1503 | |
| 1504 | update(); |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1505 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1506 | Logger.get(context) |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1507 | .logCallImpression( |
| 1508 | DialerImpression.Type.VIDEO_CALL_REQUEST_RECEIVED, getUniqueCallId(), getTimeAddedMs()); |
| 1509 | } |
| 1510 | |
| 1511 | @Override |
| 1512 | public void onUpgradedToVideo(boolean switchToSpeaker) { |
| 1513 | LogUtil.enterBlock("DialerCall.onUpgradedToVideo"); |
| 1514 | |
| 1515 | if (!switchToSpeaker) { |
| 1516 | return; |
| 1517 | } |
| 1518 | |
| 1519 | CallAudioState audioState = AudioModeProvider.getInstance().getAudioState(); |
| 1520 | |
| 1521 | if (0 != (CallAudioState.ROUTE_BLUETOOTH & audioState.getSupportedRouteMask())) { |
| 1522 | LogUtil.e( |
| 1523 | "DialerCall.onUpgradedToVideo", |
| 1524 | "toggling speakerphone not allowed when bluetooth supported."); |
| 1525 | return; |
| 1526 | } |
| 1527 | |
| 1528 | if (audioState.getRoute() == CallAudioState.ROUTE_SPEAKER) { |
| 1529 | return; |
| 1530 | } |
| 1531 | |
| 1532 | TelecomAdapter.getInstance().setAudioRoute(CallAudioState.ROUTE_SPEAKER); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1533 | } |
| 1534 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1535 | @Override |
| 1536 | public void onCapabilitiesUpdated() { |
| 1537 | if (getNumber() == null) { |
| 1538 | return; |
| 1539 | } |
| 1540 | EnrichedCallCapabilities capabilities = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1541 | EnrichedCallComponent.get(context).getEnrichedCallManager().getCapabilities(getNumber()); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1542 | if (capabilities != null) { |
| 1543 | setEnrichedCallCapabilities(capabilities); |
| 1544 | update(); |
| 1545 | } |
| 1546 | } |
| 1547 | |
| 1548 | @Override |
| 1549 | public void onEnrichedCallStateChanged() { |
| 1550 | updateEnrichedCallSession(); |
| 1551 | } |
| 1552 | |
| 1553 | @Override |
| 1554 | public void onImpressionLoggingNeeded(DialerImpression.Type impressionType) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1555 | Logger.get(context).logCallImpression(impressionType, getUniqueCallId(), getTimeAddedMs()); |
twyen | dde01c5 | 2017-09-22 10:07:31 -0700 | [diff] [blame] | 1556 | if (impressionType == DialerImpression.Type.LIGHTBRINGER_UPGRADE_REQUESTED) { |
| 1557 | if (getLogState().contactLookupResult == Type.NOT_FOUND) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1558 | Logger.get(context) |
twyen | dde01c5 | 2017-09-22 10:07:31 -0700 | [diff] [blame] | 1559 | .logCallImpression( |
| 1560 | DialerImpression.Type.LIGHTBRINGER_NON_CONTACT_UPGRADE_REQUESTED, |
| 1561 | getUniqueCallId(), |
| 1562 | getTimeAddedMs()); |
| 1563 | } |
| 1564 | } |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | private void updateEnrichedCallSession() { |
| 1568 | if (getNumber() == null) { |
| 1569 | return; |
| 1570 | } |
| 1571 | if (getEnrichedCallSession() != null) { |
| 1572 | // State changes to existing sessions are currently handled by the UI components (which have |
| 1573 | // their own listeners). Someday instead we could remove those and just call update() here and |
| 1574 | // have the usual onDialerCallUpdate update the UI. |
| 1575 | dispatchOnEnrichedCallSessionUpdate(); |
| 1576 | return; |
| 1577 | } |
| 1578 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1579 | EnrichedCallManager manager = EnrichedCallComponent.get(context).getEnrichedCallManager(); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1580 | |
| 1581 | Filter filter = |
| 1582 | isIncoming() |
| 1583 | ? manager.createIncomingCallComposerFilter() |
| 1584 | : manager.createOutgoingCallComposerFilter(); |
| 1585 | |
| 1586 | Session session = manager.getSession(getUniqueCallId(), getNumber(), filter); |
| 1587 | if (session == null) { |
| 1588 | return; |
| 1589 | } |
| 1590 | |
| 1591 | session.setUniqueDialerCallId(getUniqueCallId()); |
| 1592 | setEnrichedCallSession(session); |
| 1593 | |
| 1594 | LogUtil.i( |
| 1595 | "DialerCall.updateEnrichedCallSession", |
| 1596 | "setting session %d's dialer id to %s", |
| 1597 | session.getSessionId(), |
| 1598 | getUniqueCallId()); |
| 1599 | |
| 1600 | dispatchOnEnrichedCallSessionUpdate(); |
| 1601 | } |
| 1602 | |
| 1603 | private void dispatchOnEnrichedCallSessionUpdate() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1604 | for (DialerCallListener listener : listeners) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1605 | listener.onEnrichedCallSessionUpdate(); |
| 1606 | } |
| 1607 | } |
| 1608 | |
| 1609 | void onRemovedFromCallList() { |
wangqi | f186105 | 2018-04-19 15:06:06 -0700 | [diff] [blame] | 1610 | LogUtil.enterBlock("DialerCall.onRemovedFromCallList"); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1611 | // Ensure we clean up when this call is removed. |
wangqi | a0c49f6 | 2018-04-25 15:04:01 -0700 | [diff] [blame^] | 1612 | if (videoTechManager != null) { |
| 1613 | videoTechManager.dispatchRemovedFromCallList(); |
| 1614 | } |
| 1615 | // TODO(a bug): Add tests for it to make sure no crash on subsequent call to this method. |
| 1616 | if (rttTranscript != null && !isCallRemoved) { |
wangqi | f186105 | 2018-04-19 15:06:06 -0700 | [diff] [blame] | 1617 | Futures.addCallback( |
| 1618 | RttTranscriptUtil.saveRttTranscript(context, rttTranscript), |
| 1619 | new DefaultFutureCallback<>(), |
| 1620 | MoreExecutors.directExecutor()); |
wangqi | f186105 | 2018-04-19 15:06:06 -0700 | [diff] [blame] | 1621 | } |
wangqi | a0c49f6 | 2018-04-25 15:04:01 -0700 | [diff] [blame^] | 1622 | isCallRemoved = true; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1623 | } |
| 1624 | |
wangqi | 4d705e5 | 2017-09-28 12:23:35 -0700 | [diff] [blame] | 1625 | public com.android.dialer.logging.VideoTech.Type getSelectedAvailableVideoTechType() { |
| 1626 | return selectedAvailableVideoTechType; |
yueg | 457b397 | 2017-09-18 15:11:47 -0700 | [diff] [blame] | 1627 | } |
| 1628 | |
Android Dialer | 974fc29 | 2018-02-01 16:12:25 -0800 | [diff] [blame] | 1629 | public void markFeedbackRequested() { |
| 1630 | feedbackRequested = true; |
| 1631 | } |
| 1632 | |
| 1633 | public boolean isFeedbackRequested() { |
| 1634 | return feedbackRequested; |
| 1635 | } |
| 1636 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1637 | /** |
twyen | 73a74c3 | 2018-03-07 12:12:24 -0800 | [diff] [blame] | 1638 | * If the in call UI has shown the phone account selection dialog for the call, the {@link |
| 1639 | * PreferredAccountRecorder} to record the result from the dialog. |
| 1640 | */ |
| 1641 | @Nullable |
| 1642 | public PreferredAccountRecorder getPreferredAccountRecorder() { |
| 1643 | return preferredAccountRecorder; |
| 1644 | } |
| 1645 | |
| 1646 | public void setPreferredAccountRecorder(PreferredAccountRecorder preferredAccountRecorder) { |
| 1647 | this.preferredAccountRecorder = preferredAccountRecorder; |
| 1648 | } |
| 1649 | |
erfanian | d05d899 | 2018-03-20 19:42:26 -0700 | [diff] [blame] | 1650 | /** Indicates the call is eligible for SpeakEasy */ |
| 1651 | public boolean isSpeakEasyEligible() { |
erfanian | dcc84cd | 2018-04-17 12:41:05 -0700 | [diff] [blame] | 1652 | if (!Constraints.isAvailable(context)) { |
| 1653 | return false; |
| 1654 | } |
| 1655 | |
| 1656 | return !isPotentialEmergencyCallback() |
| 1657 | && !isEmergencyCall() |
| 1658 | && !isActiveRttCall() |
| 1659 | && !isConferenceCall() |
| 1660 | && !isVideoCall() |
| 1661 | && !isVoiceMailNumber(); |
erfanian | d05d899 | 2018-03-20 19:42:26 -0700 | [diff] [blame] | 1662 | } |
| 1663 | |
| 1664 | /** Indicates the user has selected SpeakEasy */ |
| 1665 | public boolean isSpeakEasyCall() { |
| 1666 | if (!isSpeakEasyEligible()) { |
| 1667 | return false; |
| 1668 | } |
| 1669 | return isSpeakEasyCall; |
| 1670 | } |
| 1671 | |
| 1672 | /** Sets the user preference for SpeakEasy */ |
| 1673 | public void setIsSpeakEasyCall(boolean isSpeakEasyCall) { |
| 1674 | this.isSpeakEasyCall = isSpeakEasyCall; |
| 1675 | } |
| 1676 | |
twyen | 73a74c3 | 2018-03-07 12:12:24 -0800 | [diff] [blame] | 1677 | /** |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1678 | * Specifies whether a number is in the call history or not. {@link #CALL_HISTORY_STATUS_UNKNOWN} |
| 1679 | * means there is no result. |
| 1680 | */ |
| 1681 | @IntDef({ |
| 1682 | CALL_HISTORY_STATUS_UNKNOWN, |
| 1683 | CALL_HISTORY_STATUS_PRESENT, |
| 1684 | CALL_HISTORY_STATUS_NOT_PRESENT |
| 1685 | }) |
| 1686 | @Retention(RetentionPolicy.SOURCE) |
| 1687 | public @interface CallHistoryStatus {} |
| 1688 | |
| 1689 | /* Defines different states of this call */ |
| 1690 | public static class State { |
| 1691 | |
| 1692 | public static final int INVALID = 0; |
| 1693 | public static final int NEW = 1; /* The call is new. */ |
| 1694 | public static final int IDLE = 2; /* The call is idle. Nothing active */ |
| 1695 | public static final int ACTIVE = 3; /* There is an active call */ |
| 1696 | public static final int INCOMING = 4; /* A normal incoming phone call */ |
| 1697 | public static final int CALL_WAITING = 5; /* Incoming call while another is active */ |
| 1698 | public static final int DIALING = 6; /* An outgoing call during dial phase */ |
| 1699 | public static final int REDIALING = 7; /* Subsequent dialing attempt after a failure */ |
| 1700 | public static final int ONHOLD = 8; /* An active phone call placed on hold */ |
| 1701 | public static final int DISCONNECTING = 9; /* A call is being ended. */ |
| 1702 | public static final int DISCONNECTED = 10; /* State after a call disconnects */ |
| 1703 | public static final int CONFERENCED = 11; /* DialerCall part of a conference call */ |
| 1704 | public static final int SELECT_PHONE_ACCOUNT = 12; /* Waiting for account selection */ |
| 1705 | public static final int CONNECTING = 13; /* Waiting for Telecom broadcast to finish */ |
| 1706 | public static final int BLOCKED = 14; /* The number was found on the block list */ |
| 1707 | public static final int PULLING = 15; /* An external call being pulled to the device */ |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1708 | public static final int CALL_PENDING = 16; /* A call is pending on a long process to finish */ |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1709 | |
| 1710 | public static boolean isConnectingOrConnected(int state) { |
| 1711 | switch (state) { |
| 1712 | case ACTIVE: |
| 1713 | case INCOMING: |
| 1714 | case CALL_WAITING: |
| 1715 | case CONNECTING: |
| 1716 | case DIALING: |
| 1717 | case PULLING: |
| 1718 | case REDIALING: |
| 1719 | case ONHOLD: |
| 1720 | case CONFERENCED: |
| 1721 | return true; |
| 1722 | default: |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1723 | return false; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1724 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | public static boolean isDialing(int state) { |
| 1728 | return state == DIALING || state == PULLING || state == REDIALING; |
| 1729 | } |
| 1730 | |
| 1731 | public static String toString(int state) { |
| 1732 | switch (state) { |
| 1733 | case INVALID: |
| 1734 | return "INVALID"; |
| 1735 | case NEW: |
| 1736 | return "NEW"; |
| 1737 | case IDLE: |
| 1738 | return "IDLE"; |
| 1739 | case ACTIVE: |
| 1740 | return "ACTIVE"; |
| 1741 | case INCOMING: |
| 1742 | return "INCOMING"; |
| 1743 | case CALL_WAITING: |
| 1744 | return "CALL_WAITING"; |
| 1745 | case DIALING: |
| 1746 | return "DIALING"; |
| 1747 | case PULLING: |
| 1748 | return "PULLING"; |
| 1749 | case REDIALING: |
| 1750 | return "REDIALING"; |
| 1751 | case ONHOLD: |
| 1752 | return "ONHOLD"; |
| 1753 | case DISCONNECTING: |
| 1754 | return "DISCONNECTING"; |
| 1755 | case DISCONNECTED: |
| 1756 | return "DISCONNECTED"; |
| 1757 | case CONFERENCED: |
| 1758 | return "CONFERENCED"; |
| 1759 | case SELECT_PHONE_ACCOUNT: |
| 1760 | return "SELECT_PHONE_ACCOUNT"; |
| 1761 | case CONNECTING: |
| 1762 | return "CONNECTING"; |
| 1763 | case BLOCKED: |
| 1764 | return "BLOCKED"; |
| 1765 | default: |
| 1766 | return "UNKNOWN"; |
| 1767 | } |
| 1768 | } |
| 1769 | } |
| 1770 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1771 | /** Camera direction constants */ |
| 1772 | public static class CameraDirection { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1773 | public static final int CAMERA_DIRECTION_UNKNOWN = -1; |
| 1774 | public static final int CAMERA_DIRECTION_FRONT_FACING = CameraCharacteristics.LENS_FACING_FRONT; |
| 1775 | public static final int CAMERA_DIRECTION_BACK_FACING = CameraCharacteristics.LENS_FACING_BACK; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1776 | } |
| 1777 | |
| 1778 | /** |
| 1779 | * Tracks any state variables that is useful for logging. There is some amount of overlap with |
| 1780 | * existing call member variables, but this duplication helps to ensure that none of these logging |
| 1781 | * variables will interface with/and affect call logic. |
| 1782 | */ |
| 1783 | public static class LogState { |
| 1784 | |
| 1785 | public DisconnectCause disconnectCause; |
| 1786 | public boolean isIncoming = false; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1787 | public ContactLookupResult.Type contactLookupResult = |
| 1788 | ContactLookupResult.Type.UNKNOWN_LOOKUP_RESULT_TYPE; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1789 | public CallSpecificAppData callSpecificAppData; |
| 1790 | // If this was a conference call, the total number of calls involved in the conference. |
| 1791 | public int conferencedCalls = 0; |
| 1792 | public long duration = 0; |
| 1793 | public boolean isLogged = false; |
| 1794 | |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1795 | private static String lookupToString(ContactLookupResult.Type lookupType) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1796 | switch (lookupType) { |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1797 | case LOCAL_CONTACT: |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1798 | return "Local"; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1799 | case LOCAL_CACHE: |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1800 | return "Cache"; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1801 | case REMOTE: |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1802 | return "Remote"; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1803 | case EMERGENCY: |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1804 | return "Emergency"; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1805 | case VOICEMAIL: |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1806 | return "Voicemail"; |
| 1807 | default: |
| 1808 | return "Not found"; |
| 1809 | } |
| 1810 | } |
| 1811 | |
| 1812 | private static String initiationToString(CallSpecificAppData callSpecificAppData) { |
| 1813 | if (callSpecificAppData == null) { |
| 1814 | return "null"; |
| 1815 | } |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1816 | switch (callSpecificAppData.getCallInitiationType()) { |
| 1817 | case INCOMING_INITIATION: |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1818 | return "Incoming"; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1819 | case DIALPAD: |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1820 | return "Dialpad"; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1821 | case SPEED_DIAL: |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1822 | return "Speed Dial"; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1823 | case REMOTE_DIRECTORY: |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1824 | return "Remote Directory"; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1825 | case SMART_DIAL: |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1826 | return "Smart Dial"; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1827 | case REGULAR_SEARCH: |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1828 | return "Regular Search"; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1829 | case CALL_LOG: |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1830 | return "DialerCall Log"; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1831 | case CALL_LOG_FILTER: |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1832 | return "DialerCall Log Filter"; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1833 | case VOICEMAIL_LOG: |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1834 | return "Voicemail Log"; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1835 | case CALL_DETAILS: |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1836 | return "DialerCall Details"; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1837 | case QUICK_CONTACTS: |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1838 | return "Quick Contacts"; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1839 | case EXTERNAL_INITIATION: |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1840 | return "External"; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1841 | case LAUNCHER_SHORTCUT: |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1842 | return "Launcher Shortcut"; |
| 1843 | default: |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1844 | return "Unknown: " + callSpecificAppData.getCallInitiationType(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1845 | } |
| 1846 | } |
| 1847 | |
| 1848 | @Override |
| 1849 | public String toString() { |
| 1850 | return String.format( |
| 1851 | Locale.US, |
| 1852 | "[" |
| 1853 | + "%s, " // DisconnectCause toString already describes the object type |
| 1854 | + "isIncoming: %s, " |
| 1855 | + "contactLookup: %s, " |
| 1856 | + "callInitiation: %s, " |
| 1857 | + "duration: %s" |
| 1858 | + "]", |
| 1859 | disconnectCause, |
| 1860 | isIncoming, |
| 1861 | lookupToString(contactLookupResult), |
| 1862 | initiationToString(callSpecificAppData), |
| 1863 | duration); |
| 1864 | } |
| 1865 | } |
| 1866 | |
roldenburg | d7490db | 2018-01-09 13:51:29 -0800 | [diff] [blame] | 1867 | /** Coordinates the available VideoTech implementations for a call. */ |
| 1868 | @VisibleForTesting |
| 1869 | public static class VideoTechManager { |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 1870 | private final Context context; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1871 | private final EmptyVideoTech emptyVideoTech = new EmptyVideoTech(); |
roldenburg | d7490db | 2018-01-09 13:51:29 -0800 | [diff] [blame] | 1872 | private final VideoTech rcsVideoShare; |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 1873 | private final List<VideoTech> videoTechs; |
roldenburg | 7bb9623 | 2017-10-09 10:32:05 -0700 | [diff] [blame] | 1874 | private VideoTech savedTech; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1875 | |
roldenburg | d7490db | 2018-01-09 13:51:29 -0800 | [diff] [blame] | 1876 | @VisibleForTesting |
| 1877 | public VideoTechManager(DialerCall call) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1878 | this.context = call.context; |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 1879 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1880 | String phoneNumber = call.getNumber(); |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 1881 | phoneNumber = phoneNumber != null ? phoneNumber : ""; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1882 | phoneNumber = phoneNumber.replaceAll("[^+0-9]", ""); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1883 | |
| 1884 | // Insert order here determines the priority of that video tech option |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 1885 | videoTechs = new ArrayList<>(); |
yueg | 457b397 | 2017-09-18 15:11:47 -0700 | [diff] [blame] | 1886 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1887 | videoTechs.add(new ImsVideoTech(Logger.get(call.context), call, call.telecomCall)); |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 1888 | |
roldenburg | d7490db | 2018-01-09 13:51:29 -0800 | [diff] [blame] | 1889 | rcsVideoShare = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1890 | EnrichedCallComponent.get(call.context) |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 1891 | .getRcsVideoShareFactory() |
| 1892 | .newRcsVideoShare( |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1893 | EnrichedCallComponent.get(call.context).getEnrichedCallManager(), |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 1894 | call, |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 1895 | phoneNumber); |
roldenburg | 3eca69f | 2018-01-16 12:07:04 -0800 | [diff] [blame] | 1896 | videoTechs.add(rcsVideoShare); |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 1897 | |
| 1898 | videoTechs.add( |
roldenburg | 4f02639 | 2017-10-13 18:42:20 -0700 | [diff] [blame] | 1899 | new DuoVideoTech( |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1900 | DuoComponent.get(call.context).getDuo(), call, call.telecomCall, phoneNumber)); |
roldenburg | d7490db | 2018-01-09 13:51:29 -0800 | [diff] [blame] | 1901 | |
| 1902 | savedTech = emptyVideoTech; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1903 | } |
| 1904 | |
roldenburg | d7490db | 2018-01-09 13:51:29 -0800 | [diff] [blame] | 1905 | @VisibleForTesting |
roldenburg | 6bd612f | 2018-01-18 12:57:19 -0800 | [diff] [blame] | 1906 | public VideoTech getVideoTech(PhoneAccountHandle phoneAccountHandle) { |
roldenburg | d7490db | 2018-01-09 13:51:29 -0800 | [diff] [blame] | 1907 | if (savedTech == emptyVideoTech) { |
| 1908 | for (VideoTech tech : videoTechs) { |
roldenburg | 6bd612f | 2018-01-18 12:57:19 -0800 | [diff] [blame] | 1909 | if (tech.isAvailable(context, phoneAccountHandle)) { |
roldenburg | d7490db | 2018-01-09 13:51:29 -0800 | [diff] [blame] | 1910 | savedTech = tech; |
| 1911 | savedTech.becomePrimary(); |
| 1912 | break; |
| 1913 | } |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1914 | } |
roldenburg | 6bd612f | 2018-01-18 12:57:19 -0800 | [diff] [blame] | 1915 | } else if (savedTech instanceof DuoVideoTech |
| 1916 | && rcsVideoShare.isAvailable(context, phoneAccountHandle)) { |
roldenburg | d7490db | 2018-01-09 13:51:29 -0800 | [diff] [blame] | 1917 | // RCS Video Share will become available after the capability exchange which is slower than |
| 1918 | // Duo reading local contacts for reachability. If Video Share becomes available and we are |
| 1919 | // not in the middle of any session changes, let it take over. |
| 1920 | savedTech = rcsVideoShare; |
| 1921 | rcsVideoShare.becomePrimary(); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1922 | } |
| 1923 | |
roldenburg | d7490db | 2018-01-09 13:51:29 -0800 | [diff] [blame] | 1924 | return savedTech; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1925 | } |
| 1926 | |
roldenburg | d7490db | 2018-01-09 13:51:29 -0800 | [diff] [blame] | 1927 | @VisibleForTesting |
roldenburg | 6bd612f | 2018-01-18 12:57:19 -0800 | [diff] [blame] | 1928 | public void dispatchCallStateChanged(int newState, PhoneAccountHandle phoneAccountHandle) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1929 | for (VideoTech videoTech : videoTechs) { |
roldenburg | 6bd612f | 2018-01-18 12:57:19 -0800 | [diff] [blame] | 1930 | videoTech.onCallStateChanged(context, newState, phoneAccountHandle); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1931 | } |
| 1932 | } |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1933 | |
| 1934 | void dispatchRemovedFromCallList() { |
| 1935 | for (VideoTech videoTech : videoTechs) { |
| 1936 | videoTech.onRemovedFromCallList(); |
| 1937 | } |
| 1938 | } |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1939 | } |
| 1940 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1941 | /** Called when canned text responses have been loaded. */ |
| 1942 | public interface CannedTextResponsesLoadedListener { |
| 1943 | void onCannedTextResponsesLoaded(DialerCall call); |
| 1944 | } |
| 1945 | } |