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