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