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