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