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