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