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