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