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