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