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