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; |
| 18 | |
| 19 | import static com.android.contacts.common.compat.CallCompat.Details.PROPERTY_ENTERPRISE_CALL; |
| 20 | |
| 21 | import android.Manifest; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
| 24 | import android.content.IntentFilter; |
| 25 | import android.content.pm.ApplicationInfo; |
| 26 | import android.content.pm.PackageManager; |
| 27 | import android.graphics.drawable.Drawable; |
| 28 | import android.hardware.display.DisplayManager; |
| 29 | import android.os.BatteryManager; |
| 30 | import android.os.Handler; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 31 | import android.os.Trace; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 32 | import android.support.annotation.NonNull; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 33 | import android.support.annotation.Nullable; |
| 34 | import android.support.v4.app.Fragment; |
| 35 | import android.support.v4.content.ContextCompat; |
| 36 | import android.telecom.Call.Details; |
| 37 | import android.telecom.StatusHints; |
| 38 | import android.telecom.TelecomManager; |
wangqi | a462370 | 2018-04-02 14:23:38 -0700 | [diff] [blame] | 39 | import android.text.BidiFormatter; |
| 40 | import android.text.TextDirectionHeuristics; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 41 | import android.text.TextUtils; |
| 42 | import android.view.Display; |
| 43 | import android.view.View; |
| 44 | import android.view.accessibility.AccessibilityEvent; |
| 45 | import android.view.accessibility.AccessibilityManager; |
| 46 | import com.android.contacts.common.ContactsUtils; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 47 | import com.android.dialer.common.Assert; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 48 | import com.android.dialer.common.LogUtil; |
zachh | 190343a | 2018-05-31 17:30:46 -0700 | [diff] [blame] | 49 | import com.android.dialer.configprovider.ConfigProviderComponent; |
twyen | 5578d92 | 2018-06-25 12:36:26 -0700 | [diff] [blame] | 50 | import com.android.dialer.contacts.ContactsComponent; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 51 | import com.android.dialer.logging.DialerImpression; |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 52 | import com.android.dialer.logging.Logger; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 53 | import com.android.dialer.multimedia.MultimediaData; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 54 | import com.android.dialer.oem.MotorolaUtils; |
wangqi | 9753935 | 2017-09-25 11:15:16 -0700 | [diff] [blame] | 55 | import com.android.dialer.phonenumberutil.PhoneNumberHelper; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 56 | import com.android.dialer.postcall.PostCall; |
twyen | 4fde0ac | 2018-03-22 18:04:23 -0700 | [diff] [blame] | 57 | import com.android.dialer.preferredsim.suggestion.SuggestionProvider; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 58 | import com.android.incallui.ContactInfoCache.ContactCacheEntry; |
| 59 | import com.android.incallui.ContactInfoCache.ContactInfoCacheCallback; |
| 60 | import com.android.incallui.InCallPresenter.InCallDetailsListener; |
| 61 | import com.android.incallui.InCallPresenter.InCallEventListener; |
| 62 | import com.android.incallui.InCallPresenter.InCallState; |
| 63 | import com.android.incallui.InCallPresenter.InCallStateListener; |
| 64 | import com.android.incallui.InCallPresenter.IncomingCallListener; |
| 65 | import com.android.incallui.call.CallList; |
| 66 | import com.android.incallui.call.DialerCall; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 67 | import com.android.incallui.call.DialerCallListener; |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame] | 68 | import com.android.incallui.call.state.DialerCallState; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 69 | import com.android.incallui.calllocation.CallLocation; |
| 70 | import com.android.incallui.calllocation.CallLocationComponent; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 71 | import com.android.incallui.incall.protocol.ContactPhotoType; |
| 72 | import com.android.incallui.incall.protocol.InCallScreen; |
| 73 | import com.android.incallui.incall.protocol.InCallScreenDelegate; |
| 74 | import com.android.incallui.incall.protocol.PrimaryCallState; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 75 | import com.android.incallui.incall.protocol.PrimaryCallState.ButtonState; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 76 | import com.android.incallui.incall.protocol.PrimaryInfo; |
| 77 | import com.android.incallui.incall.protocol.SecondaryInfo; |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 78 | import com.android.incallui.videotech.utils.SessionModificationState; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 79 | import java.lang.ref.WeakReference; |
| 80 | |
| 81 | /** |
| 82 | * Controller for the Call Card Fragment. This class listens for changes to InCallState and passes |
| 83 | * it along to the fragment. |
| 84 | */ |
| 85 | public class CallCardPresenter |
| 86 | implements InCallStateListener, |
| 87 | IncomingCallListener, |
| 88 | InCallDetailsListener, |
| 89 | InCallEventListener, |
| 90 | InCallScreenDelegate, |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 91 | DialerCallListener { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 92 | |
| 93 | /** |
| 94 | * Amount of time to wait before sending an announcement via the accessibility manager. When the |
| 95 | * call state changes to an outgoing or incoming state for the first time, the UI can often be |
| 96 | * changing due to call updates or contact lookup. This allows the UI to settle to a stable state |
| 97 | * to ensure that the correct information is announced. |
| 98 | */ |
| 99 | private static final long ACCESSIBILITY_ANNOUNCEMENT_DELAY_MILLIS = 500; |
| 100 | |
| 101 | /** Flag to allow the user's current location to be shown during emergency calls. */ |
| 102 | private static final String CONFIG_ENABLE_EMERGENCY_LOCATION = "config_enable_emergency_location"; |
| 103 | |
| 104 | private static final boolean CONFIG_ENABLE_EMERGENCY_LOCATION_DEFAULT = true; |
| 105 | |
| 106 | /** |
| 107 | * Make it possible to not get location during an emergency call if the battery is too low, since |
| 108 | * doing so could trigger gps and thus potentially cause the phone to die in the middle of the |
| 109 | * call. |
| 110 | */ |
| 111 | private static final String CONFIG_MIN_BATTERY_PERCENT_FOR_EMERGENCY_LOCATION = |
| 112 | "min_battery_percent_for_emergency_location"; |
| 113 | |
| 114 | private static final long CONFIG_MIN_BATTERY_PERCENT_FOR_EMERGENCY_LOCATION_DEFAULT = 10; |
| 115 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 116 | private final Context context; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 117 | private final Handler handler = new Handler(); |
| 118 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 119 | private DialerCall primary; |
wangqi | dd5f1a5 | 2018-01-23 18:01:00 -0800 | [diff] [blame] | 120 | private String primaryNumber; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 121 | private DialerCall secondary; |
wangqi | dd5f1a5 | 2018-01-23 18:01:00 -0800 | [diff] [blame] | 122 | private String secondaryNumber; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 123 | private ContactCacheEntry primaryContactInfo; |
| 124 | private ContactCacheEntry secondaryContactInfo; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 125 | private boolean isFullscreen = false; |
| 126 | private InCallScreen inCallScreen; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 127 | private boolean isInCallScreenReady; |
| 128 | private boolean shouldSendAccessibilityEvent; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 129 | |
| 130 | @NonNull private final CallLocation callLocation; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 131 | private final Runnable sendAccessibilityEventRunnable = |
| 132 | new Runnable() { |
| 133 | @Override |
| 134 | public void run() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 135 | shouldSendAccessibilityEvent = !sendAccessibilityEvent(context, getUi()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 136 | LogUtil.i( |
| 137 | "CallCardPresenter.sendAccessibilityEventRunnable", |
| 138 | "still should send: %b", |
| 139 | shouldSendAccessibilityEvent); |
| 140 | if (!shouldSendAccessibilityEvent) { |
| 141 | handler.removeCallbacks(this); |
| 142 | } |
| 143 | } |
| 144 | }; |
| 145 | |
| 146 | public CallCardPresenter(Context context) { |
wangqi | 385a5a1 | 2017-09-28 10:44:54 -0700 | [diff] [blame] | 147 | LogUtil.i("CallCardPresenter.constructor", null); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 148 | this.context = Assert.isNotNull(context).getApplicationContext(); |
| 149 | callLocation = CallLocationComponent.get(this.context).getCallLocation(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | private static boolean hasCallSubject(DialerCall call) { |
| 153 | return !TextUtils.isEmpty(call.getCallSubject()); |
| 154 | } |
| 155 | |
| 156 | @Override |
| 157 | public void onInCallScreenDelegateInit(InCallScreen inCallScreen) { |
| 158 | Assert.isNotNull(inCallScreen); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 159 | this.inCallScreen = inCallScreen; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 160 | |
| 161 | // Call may be null if disconnect happened already. |
| 162 | DialerCall call = CallList.getInstance().getFirstCall(); |
| 163 | if (call != null) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 164 | primary = call; |
| 165 | if (shouldShowNoteSentToast(primary)) { |
| 166 | this.inCallScreen.showNoteSentToast(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 167 | } |
| 168 | call.addListener(this); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 169 | // start processing lookups right away. |
| 170 | if (!call.isConferenceCall()) { |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame] | 171 | startContactInfoSearch(call, true, call.getState() == DialerCallState.INCOMING); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 172 | } else { |
| 173 | updateContactEntry(null, true); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | onStateChange(null, InCallPresenter.getInstance().getInCallState(), CallList.getInstance()); |
| 178 | } |
| 179 | |
| 180 | @Override |
| 181 | public void onInCallScreenReady() { |
wangqi | 385a5a1 | 2017-09-28 10:44:54 -0700 | [diff] [blame] | 182 | LogUtil.i("CallCardPresenter.onInCallScreenReady", null); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 183 | Assert.checkState(!isInCallScreenReady); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 184 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 185 | // Contact search may have completed before ui is ready. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 186 | if (primaryContactInfo != null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 187 | updatePrimaryDisplayInfo(); |
| 188 | } |
| 189 | |
| 190 | // Register for call state changes last |
| 191 | InCallPresenter.getInstance().addListener(this); |
| 192 | InCallPresenter.getInstance().addIncomingCallListener(this); |
| 193 | InCallPresenter.getInstance().addDetailsListener(this); |
| 194 | InCallPresenter.getInstance().addInCallEventListener(this); |
| 195 | isInCallScreenReady = true; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 196 | |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 197 | // Log location impressions |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 198 | if (isOutgoingEmergencyCall(primary)) { |
| 199 | Logger.get(context).logImpression(DialerImpression.Type.EMERGENCY_NEW_EMERGENCY_CALL); |
| 200 | } else if (isIncomingEmergencyCall(primary) || isIncomingEmergencyCall(secondary)) { |
| 201 | Logger.get(context).logImpression(DialerImpression.Type.EMERGENCY_CALLBACK); |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 204 | // Showing the location may have been skipped if the UI wasn't ready during previous layout. |
| 205 | if (shouldShowLocation()) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 206 | inCallScreen.showLocationUi(getLocationFragment()); |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 207 | |
| 208 | // Log location impressions |
| 209 | if (!hasLocationPermission()) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 210 | Logger.get(context).logImpression(DialerImpression.Type.EMERGENCY_NO_LOCATION_PERMISSION); |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 211 | } else if (isBatteryTooLowForEmergencyLocation()) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 212 | Logger.get(context) |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 213 | .logImpression(DialerImpression.Type.EMERGENCY_BATTERY_TOO_LOW_TO_GET_LOCATION); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 214 | } else if (!callLocation.canGetLocation(context)) { |
| 215 | Logger.get(context).logImpression(DialerImpression.Type.EMERGENCY_CANT_GET_LOCATION); |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 216 | } |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 217 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | @Override |
| 221 | public void onInCallScreenUnready() { |
wangqi | 385a5a1 | 2017-09-28 10:44:54 -0700 | [diff] [blame] | 222 | LogUtil.i("CallCardPresenter.onInCallScreenUnready", null); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 223 | Assert.checkState(isInCallScreenReady); |
| 224 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 225 | // stop getting call state changes |
| 226 | InCallPresenter.getInstance().removeListener(this); |
| 227 | InCallPresenter.getInstance().removeIncomingCallListener(this); |
| 228 | InCallPresenter.getInstance().removeDetailsListener(this); |
| 229 | InCallPresenter.getInstance().removeInCallEventListener(this); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 230 | if (primary != null) { |
| 231 | primary.removeListener(this); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 232 | } |
| 233 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 234 | callLocation.close(); |
| 235 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 236 | primary = null; |
| 237 | primaryContactInfo = null; |
| 238 | secondaryContactInfo = null; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 239 | isInCallScreenReady = false; |
| 240 | } |
| 241 | |
| 242 | @Override |
| 243 | public void onIncomingCall(InCallState oldState, InCallState newState, DialerCall call) { |
| 244 | // same logic should happen as with onStateChange() |
| 245 | onStateChange(oldState, newState, CallList.getInstance()); |
| 246 | } |
| 247 | |
| 248 | @Override |
| 249 | public void onStateChange(InCallState oldState, InCallState newState, CallList callList) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 250 | Trace.beginSection("CallCardPresenter.onStateChange"); |
| 251 | LogUtil.v("CallCardPresenter.onStateChange", "oldState: %s, newState: %s", oldState, newState); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 252 | if (inCallScreen == null) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 253 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 254 | return; |
| 255 | } |
| 256 | |
| 257 | DialerCall primary = null; |
| 258 | DialerCall secondary = null; |
| 259 | |
| 260 | if (newState == InCallState.INCOMING) { |
| 261 | primary = callList.getIncomingCall(); |
| 262 | } else if (newState == InCallState.PENDING_OUTGOING || newState == InCallState.OUTGOING) { |
| 263 | primary = callList.getOutgoingCall(); |
| 264 | if (primary == null) { |
| 265 | primary = callList.getPendingOutgoingCall(); |
| 266 | } |
| 267 | |
| 268 | // getCallToDisplay doesn't go through outgoing or incoming calls. It will return the |
| 269 | // highest priority call to display as the secondary call. |
yueg | b910304 | 2018-03-30 12:12:25 -0700 | [diff] [blame] | 270 | secondary = InCallPresenter.getCallToDisplay(callList, null, true); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 271 | } else if (newState == InCallState.INCALL) { |
yueg | b910304 | 2018-03-30 12:12:25 -0700 | [diff] [blame] | 272 | primary = InCallPresenter.getCallToDisplay(callList, null, false); |
| 273 | secondary = InCallPresenter.getCallToDisplay(callList, primary, true); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | LogUtil.v("CallCardPresenter.onStateChange", "primary call: " + primary); |
| 277 | LogUtil.v("CallCardPresenter.onStateChange", "secondary call: " + secondary); |
wangqi | dd5f1a5 | 2018-01-23 18:01:00 -0800 | [diff] [blame] | 278 | String primaryNumber = null; |
| 279 | String secondaryNumber = null; |
| 280 | if (primary != null) { |
| 281 | primaryNumber = primary.getNumber(); |
| 282 | } |
| 283 | if (secondary != null) { |
| 284 | secondaryNumber = secondary.getNumber(); |
| 285 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 286 | |
| 287 | final boolean primaryChanged = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 288 | !(DialerCall.areSame(this.primary, primary) |
wangqi | dd5f1a5 | 2018-01-23 18:01:00 -0800 | [diff] [blame] | 289 | && TextUtils.equals(this.primaryNumber, primaryNumber)); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 290 | final boolean secondaryChanged = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 291 | !(DialerCall.areSame(this.secondary, secondary) |
wangqi | dd5f1a5 | 2018-01-23 18:01:00 -0800 | [diff] [blame] | 292 | && TextUtils.equals(this.secondaryNumber, secondaryNumber)); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 293 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 294 | this.secondary = secondary; |
wangqi | dd5f1a5 | 2018-01-23 18:01:00 -0800 | [diff] [blame] | 295 | this.secondaryNumber = secondaryNumber; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 296 | DialerCall previousPrimary = this.primary; |
| 297 | this.primary = primary; |
wangqi | dd5f1a5 | 2018-01-23 18:01:00 -0800 | [diff] [blame] | 298 | this.primaryNumber = primaryNumber; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 299 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 300 | if (this.primary != null) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 301 | inCallScreen.updateInCallScreenColors(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | if (primaryChanged && shouldShowNoteSentToast(primary)) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 305 | inCallScreen.showNoteSentToast(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | // Refresh primary call information if either: |
| 309 | // 1. Primary call changed. |
| 310 | // 2. The call's ability to manage conference has changed. |
| 311 | if (shouldRefreshPrimaryInfo(primaryChanged)) { |
| 312 | // primary call has changed |
| 313 | if (previousPrimary != null) { |
| 314 | previousPrimary.removeListener(this); |
| 315 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 316 | this.primary.addListener(this); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 317 | |
twyen | a40a9ef | 2018-05-22 17:35:59 -0700 | [diff] [blame] | 318 | primaryContactInfo = ContactInfoCache.buildCacheEntryFromCall(context, this.primary); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 319 | updatePrimaryDisplayInfo(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 320 | maybeStartSearch(this.primary, true); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 321 | } |
| 322 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 323 | if (previousPrimary != null && this.primary == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 324 | previousPrimary.removeListener(this); |
| 325 | } |
| 326 | |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 327 | if (secondaryChanged) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 328 | if (this.secondary == null) { |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 329 | // Secondary call may have ended. Update the ui. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 330 | secondaryContactInfo = null; |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 331 | updateSecondaryDisplayInfo(); |
| 332 | } else { |
| 333 | // secondary call has changed |
twyen | a40a9ef | 2018-05-22 17:35:59 -0700 | [diff] [blame] | 334 | secondaryContactInfo = ContactInfoCache.buildCacheEntryFromCall(context, this.secondary); |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 335 | updateSecondaryDisplayInfo(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 336 | maybeStartSearch(this.secondary, false); |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 337 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | // Set the call state |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame] | 341 | int callState = DialerCallState.IDLE; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 342 | if (this.primary != null) { |
| 343 | callState = this.primary.getState(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 344 | updatePrimaryCallState(); |
| 345 | } else { |
Android Dialer | 31fe998 | 2018-02-26 13:29:09 -0800 | [diff] [blame] | 346 | getUi().setCallState(PrimaryCallState.empty()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | maybeShowManageConferenceCallButton(); |
| 350 | |
| 351 | // Hide the end call button instantly if we're receiving an incoming call. |
| 352 | getUi() |
| 353 | .setEndCallButtonEnabled( |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 354 | shouldShowEndCallButton(this.primary, callState), |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame] | 355 | callState != DialerCallState.INCOMING /* animate */); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 356 | |
| 357 | maybeSendAccessibilityEvent(oldState, newState, primaryChanged); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 358 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | @Override |
| 362 | public void onDetailsChanged(DialerCall call, Details details) { |
| 363 | updatePrimaryCallState(); |
| 364 | |
| 365 | if (call.can(Details.CAPABILITY_MANAGE_CONFERENCE) |
| 366 | != details.can(Details.CAPABILITY_MANAGE_CONFERENCE)) { |
| 367 | maybeShowManageConferenceCallButton(); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | @Override |
| 372 | public void onDialerCallDisconnect() {} |
| 373 | |
| 374 | @Override |
| 375 | public void onDialerCallUpdate() { |
| 376 | // No-op; specific call updates handled elsewhere. |
| 377 | } |
| 378 | |
| 379 | @Override |
| 380 | public void onWiFiToLteHandover() {} |
| 381 | |
| 382 | @Override |
| 383 | public void onHandoverToWifiFailure() {} |
| 384 | |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 385 | @Override |
| 386 | public void onInternationalCallOnWifi() {} |
| 387 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 388 | @Override |
| 389 | public void onEnrichedCallSessionUpdate() { |
| 390 | LogUtil.enterBlock("CallCardPresenter.onEnrichedCallSessionUpdate"); |
| 391 | updatePrimaryDisplayInfo(); |
| 392 | } |
| 393 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 394 | /** Handles a change to the child number by refreshing the primary call info. */ |
| 395 | @Override |
| 396 | public void onDialerCallChildNumberChange() { |
| 397 | LogUtil.v("CallCardPresenter.onDialerCallChildNumberChange", ""); |
| 398 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 399 | if (primary == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 400 | return; |
| 401 | } |
| 402 | updatePrimaryDisplayInfo(); |
| 403 | } |
| 404 | |
| 405 | /** Handles a change to the last forwarding number by refreshing the primary call info. */ |
| 406 | @Override |
| 407 | public void onDialerCallLastForwardedNumberChange() { |
| 408 | LogUtil.v("CallCardPresenter.onDialerCallLastForwardedNumberChange", ""); |
| 409 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 410 | if (primary == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 411 | return; |
| 412 | } |
| 413 | updatePrimaryDisplayInfo(); |
| 414 | updatePrimaryCallState(); |
| 415 | } |
| 416 | |
| 417 | @Override |
| 418 | public void onDialerCallUpgradeToVideo() {} |
| 419 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 420 | /** Handles a change to the session modification state for a call. */ |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 421 | @Override |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 422 | public void onDialerCallSessionModificationStateChange() { |
| 423 | LogUtil.enterBlock("CallCardPresenter.onDialerCallSessionModificationStateChange"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 424 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 425 | if (primary == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 426 | return; |
| 427 | } |
| 428 | getUi() |
| 429 | .setEndCallButtonEnabled( |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 430 | primary.getVideoTech().getSessionModificationState() |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 431 | != SessionModificationState.RECEIVED_UPGRADE_TO_VIDEO_REQUEST, |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 432 | true /* shouldAnimate */); |
| 433 | updatePrimaryCallState(); |
| 434 | } |
| 435 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 436 | private boolean shouldRefreshPrimaryInfo(boolean primaryChanged) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 437 | if (primary == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 438 | return false; |
| 439 | } |
| 440 | return primaryChanged |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 441 | || inCallScreen.isManageConferenceVisible() != shouldShowManageConference(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | private void updatePrimaryCallState() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 445 | if (getUi() != null && primary != null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 446 | boolean isWorkCall = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 447 | primary.hasProperty(PROPERTY_ENTERPRISE_CALL) |
| 448 | || (primaryContactInfo != null |
| 449 | && primaryContactInfo.userType == ContactsUtils.USER_TYPE_WORK); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 450 | boolean isHdAudioCall = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 451 | isPrimaryCallActive() && primary.hasProperty(Details.PROPERTY_HIGH_DEF_AUDIO); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 452 | boolean isAttemptingHdAudioCall = |
| 453 | !isHdAudioCall |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 454 | && !primary.hasProperty(DialerCall.PROPERTY_CODEC_KNOWN) |
| 455 | && MotorolaUtils.shouldBlinkHdIconWhenConnectingCall(context); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 456 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 457 | boolean isBusiness = primaryContactInfo != null && primaryContactInfo.isBusiness; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 458 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 459 | // Check for video state change and update the visibility of the contact photo. The contact |
| 460 | // photo is hidden when the incoming video surface is shown. |
| 461 | // The contact photo visibility can also change in setPrimary(). |
| 462 | boolean shouldShowContactPhoto = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 463 | !VideoCallPresenter.showIncomingVideo(primary.getVideoState(), primary.getState()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 464 | getUi() |
| 465 | .setCallState( |
Android Dialer | 31fe998 | 2018-02-26 13:29:09 -0800 | [diff] [blame] | 466 | PrimaryCallState.builder() |
| 467 | .setState(primary.getState()) |
| 468 | .setIsVideoCall(primary.isVideoCall()) |
| 469 | .setSessionModificationState(primary.getVideoTech().getSessionModificationState()) |
| 470 | .setDisconnectCause(primary.getDisconnectCause()) |
| 471 | .setConnectionLabel(getConnectionLabel()) |
wangqi | d745887 | 2018-06-26 13:39:18 -0700 | [diff] [blame] | 472 | .setPrimaryColor( |
| 473 | InCallPresenter.getInstance().getThemeColorManager().getPrimaryColor()) |
twyen | 4fde0ac | 2018-03-22 18:04:23 -0700 | [diff] [blame] | 474 | .setSimSuggestionReason(getSimSuggestionReason()) |
Android Dialer | 31fe998 | 2018-02-26 13:29:09 -0800 | [diff] [blame] | 475 | .setConnectionIcon(getCallStateIcon()) |
| 476 | .setGatewayNumber(getGatewayNumber()) |
| 477 | .setCallSubject(shouldShowCallSubject(primary) ? primary.getCallSubject() : null) |
| 478 | .setCallbackNumber( |
| 479 | PhoneNumberHelper.formatNumber( |
linyuh | b06d009 | 2018-03-01 15:05:36 -0800 | [diff] [blame] | 480 | context, primary.getCallbackNumber(), primary.getSimCountryIso())) |
Android Dialer | 31fe998 | 2018-02-26 13:29:09 -0800 | [diff] [blame] | 481 | .setIsWifi(primary.hasProperty(Details.PROPERTY_WIFI)) |
| 482 | .setIsConference( |
| 483 | primary.isConferenceCall() |
| 484 | && !primary.hasProperty(Details.PROPERTY_GENERIC_CONFERENCE)) |
| 485 | .setIsWorkCall(isWorkCall) |
| 486 | .setIsHdAttempting(isAttemptingHdAudioCall) |
| 487 | .setIsHdAudioCall(isHdAudioCall) |
| 488 | .setIsForwardedNumber( |
| 489 | !TextUtils.isEmpty(primary.getLastForwardedNumber()) |
| 490 | || primary.isCallForwarded()) |
| 491 | .setShouldShowContactPhoto(shouldShowContactPhoto) |
| 492 | .setConnectTimeMillis(primary.getConnectTimeMillis()) |
| 493 | .setIsVoiceMailNumber(primary.isVoiceMailNumber()) |
| 494 | .setIsRemotelyHeld(primary.isRemotelyHeld()) |
| 495 | .setIsBusinessNumber(isBusiness) |
| 496 | .setSupportsCallOnHold(supports2ndCallOnHold()) |
| 497 | .setSwapToSecondaryButtonState(getSwapToSecondaryButtonState()) |
| 498 | .setIsAssistedDialed(primary.isAssistedDialed()) |
| 499 | .setCustomLabel(null) |
| 500 | .setAssistedDialingExtras(primary.getAssistedDialingExtras()) |
| 501 | .build()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 502 | |
| 503 | InCallActivity activity = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 504 | (InCallActivity) (inCallScreen.getInCallScreenFragment().getActivity()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 505 | if (activity != null) { |
| 506 | activity.onPrimaryCallStateChanged(); |
| 507 | } |
| 508 | } |
| 509 | } |
| 510 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 511 | private @ButtonState int getSwapToSecondaryButtonState() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 512 | if (secondary == null) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 513 | return ButtonState.NOT_SUPPORT; |
| 514 | } |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame] | 515 | if (primary.getState() == DialerCallState.ACTIVE) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 516 | return ButtonState.ENABLED; |
| 517 | } |
| 518 | return ButtonState.DISABLED; |
| 519 | } |
| 520 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 521 | /** Only show the conference call button if we can manage the conference. */ |
| 522 | private void maybeShowManageConferenceCallButton() { |
| 523 | getUi().showManageConferenceCallButton(shouldShowManageConference()); |
| 524 | } |
| 525 | |
| 526 | /** |
| 527 | * Determines if the manage conference button should be visible, based on the current primary |
| 528 | * call. |
| 529 | * |
| 530 | * @return {@code True} if the manage conference button should be visible. |
| 531 | */ |
| 532 | private boolean shouldShowManageConference() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 533 | if (primary == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 534 | return false; |
| 535 | } |
| 536 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 537 | return primary.can(android.telecom.Call.Details.CAPABILITY_MANAGE_CONFERENCE) && !isFullscreen; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 538 | } |
| 539 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 540 | private boolean supports2ndCallOnHold() { |
| 541 | DialerCall firstCall = CallList.getInstance().getActiveOrBackgroundCall(); |
| 542 | DialerCall incomingCall = CallList.getInstance().getIncomingCall(); |
| 543 | if (firstCall != null && incomingCall != null && firstCall != incomingCall) { |
| 544 | return incomingCall.can(Details.CAPABILITY_HOLD); |
| 545 | } |
| 546 | return true; |
| 547 | } |
| 548 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 549 | @Override |
| 550 | public void onCallStateButtonClicked() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 551 | Intent broadcastIntent = Bindings.get(context).getCallStateButtonBroadcastIntent(context); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 552 | if (broadcastIntent != null) { |
| 553 | LogUtil.v( |
| 554 | "CallCardPresenter.onCallStateButtonClicked", |
| 555 | "sending call state button broadcast: " + broadcastIntent); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 556 | context.sendBroadcast(broadcastIntent, Manifest.permission.READ_PHONE_STATE); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 557 | } |
| 558 | } |
| 559 | |
| 560 | @Override |
| 561 | public void onManageConferenceClicked() { |
| 562 | InCallActivity activity = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 563 | (InCallActivity) (inCallScreen.getInCallScreenFragment().getActivity()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 564 | activity.showConferenceFragment(true); |
| 565 | } |
| 566 | |
| 567 | @Override |
| 568 | public void onShrinkAnimationComplete() { |
| 569 | InCallPresenter.getInstance().onShrinkAnimationComplete(); |
| 570 | } |
| 571 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 572 | private void maybeStartSearch(DialerCall call, boolean isPrimary) { |
| 573 | // no need to start search for conference calls which show generic info. |
| 574 | if (call != null && !call.isConferenceCall()) { |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame] | 575 | startContactInfoSearch(call, isPrimary, call.getState() == DialerCallState.INCOMING); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 576 | } |
| 577 | } |
| 578 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 579 | /** Starts a query for more contact data for the save primary and secondary calls. */ |
| 580 | private void startContactInfoSearch( |
| 581 | final DialerCall call, final boolean isPrimary, boolean isIncoming) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 582 | final ContactInfoCache cache = ContactInfoCache.getInstance(context); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 583 | |
| 584 | cache.findInfo(call, isIncoming, new ContactLookupCallback(this, isPrimary)); |
| 585 | } |
| 586 | |
| 587 | private void onContactInfoComplete(String callId, ContactCacheEntry entry, boolean isPrimary) { |
| 588 | final boolean entryMatchesExistingCall = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 589 | (isPrimary && primary != null && TextUtils.equals(callId, primary.getId())) |
| 590 | || (!isPrimary && secondary != null && TextUtils.equals(callId, secondary.getId())); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 591 | if (entryMatchesExistingCall) { |
| 592 | updateContactEntry(entry, isPrimary); |
| 593 | } else { |
| 594 | LogUtil.e( |
| 595 | "CallCardPresenter.onContactInfoComplete", |
| 596 | "dropping stale contact lookup info for " + callId); |
| 597 | } |
| 598 | |
| 599 | final DialerCall call = CallList.getInstance().getCallById(callId); |
| 600 | if (call != null) { |
| 601 | call.getLogState().contactLookupResult = entry.contactLookupResult; |
| 602 | } |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 603 | if (entry.lookupUri != null) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 604 | CallerInfoUtils.sendViewNotification(context, entry.lookupUri); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 605 | } |
| 606 | } |
| 607 | |
| 608 | private void onImageLoadComplete(String callId, ContactCacheEntry entry) { |
| 609 | if (getUi() == null) { |
| 610 | return; |
| 611 | } |
| 612 | |
| 613 | if (entry.photo != null) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 614 | if (primary != null && callId.equals(primary.getId())) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 615 | updateContactEntry(entry, true /* isPrimary */); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 616 | } else if (secondary != null && callId.equals(secondary.getId())) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 617 | updateContactEntry(entry, false /* isPrimary */); |
| 618 | } |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | private void updateContactEntry(ContactCacheEntry entry, boolean isPrimary) { |
| 623 | if (isPrimary) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 624 | primaryContactInfo = entry; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 625 | updatePrimaryDisplayInfo(); |
| 626 | } else { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 627 | secondaryContactInfo = entry; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 628 | updateSecondaryDisplayInfo(); |
| 629 | } |
| 630 | } |
| 631 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 632 | private void updatePrimaryDisplayInfo() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 633 | if (inCallScreen == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 634 | // TODO: May also occur if search result comes back after ui is destroyed. Look into |
| 635 | // removing that case completely. |
| 636 | LogUtil.v( |
| 637 | "CallCardPresenter.updatePrimaryDisplayInfo", |
| 638 | "updatePrimaryDisplayInfo called but ui is null!"); |
| 639 | return; |
| 640 | } |
| 641 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 642 | if (primary == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 643 | // Clear the primary display info. |
Android Dialer | f943910 | 2018-02-21 08:05:14 -0800 | [diff] [blame] | 644 | inCallScreen.setPrimary(PrimaryInfo.empty()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 645 | return; |
| 646 | } |
| 647 | |
| 648 | // Hide the contact photo if we are in a video call and the incoming video surface is |
| 649 | // showing. |
| 650 | boolean showContactPhoto = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 651 | !VideoCallPresenter.showIncomingVideo(primary.getVideoState(), primary.getState()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 652 | |
| 653 | // DialerCall placed through a work phone account. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 654 | boolean hasWorkCallProperty = primary.hasProperty(PROPERTY_ENTERPRISE_CALL); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 655 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 656 | MultimediaData multimediaData = null; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 657 | if (primary.getEnrichedCallSession() != null) { |
| 658 | multimediaData = primary.getEnrichedCallSession().getMultimediaData(); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 659 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 660 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 661 | if (primary.isConferenceCall()) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 662 | LogUtil.v( |
| 663 | "CallCardPresenter.updatePrimaryDisplayInfo", |
| 664 | "update primary display info for conference call."); |
| 665 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 666 | inCallScreen.setPrimary( |
Android Dialer | f943910 | 2018-02-21 08:05:14 -0800 | [diff] [blame] | 667 | PrimaryInfo.builder() |
| 668 | .setName( |
| 669 | CallerInfoUtils.getConferenceString( |
| 670 | context, primary.hasProperty(Details.PROPERTY_GENERIC_CONFERENCE))) |
| 671 | .setNameIsNumber(false) |
| 672 | .setPhotoType(ContactPhotoType.DEFAULT_PLACEHOLDER) |
| 673 | .setIsSipCall(false) |
| 674 | .setIsContactPhotoShown(showContactPhoto) |
| 675 | .setIsWorkCall(hasWorkCallProperty) |
| 676 | .setIsSpam(false) |
| 677 | .setIsLocalContact(false) |
| 678 | .setAnsweringDisconnectsOngoingCall(false) |
| 679 | .setShouldShowLocation(shouldShowLocation()) |
| 680 | .setShowInCallButtonGrid(true) |
| 681 | .setNumberPresentation(primary.getNumberPresentation()) |
| 682 | .build()); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 683 | } else if (primaryContactInfo != null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 684 | LogUtil.v( |
| 685 | "CallCardPresenter.updatePrimaryDisplayInfo", |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 686 | "update primary display info for " + primaryContactInfo); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 687 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 688 | String name = getNameForCall(primaryContactInfo); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 689 | String number; |
| 690 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 691 | boolean isChildNumberShown = !TextUtils.isEmpty(primary.getChildNumber()); |
| 692 | boolean isForwardedNumberShown = !TextUtils.isEmpty(primary.getLastForwardedNumber()); |
| 693 | boolean isCallSubjectShown = shouldShowCallSubject(primary); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 694 | |
| 695 | if (isCallSubjectShown) { |
| 696 | number = null; |
| 697 | } else if (isChildNumberShown) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 698 | number = context.getString(R.string.child_number, primary.getChildNumber()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 699 | } else if (isForwardedNumberShown) { |
| 700 | // Use last forwarded number instead of second line, if present. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 701 | number = primary.getLastForwardedNumber(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 702 | } else { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 703 | number = primaryContactInfo.number; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 704 | } |
| 705 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 706 | boolean nameIsNumber = name != null && name.equals(primaryContactInfo.number); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 707 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 708 | // DialerCall with caller that is a work contact. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 709 | boolean isWorkContact = (primaryContactInfo.userType == ContactsUtils.USER_TYPE_WORK); |
| 710 | inCallScreen.setPrimary( |
Android Dialer | f943910 | 2018-02-21 08:05:14 -0800 | [diff] [blame] | 711 | PrimaryInfo.builder() |
| 712 | .setNumber(number) |
| 713 | .setName(primary.updateNameIfRestricted(name)) |
| 714 | .setNameIsNumber(nameIsNumber) |
twyen | cb2a981 | 2018-03-23 18:21:13 -0700 | [diff] [blame] | 715 | .setLocation( |
Android Dialer | f943910 | 2018-02-21 08:05:14 -0800 | [diff] [blame] | 716 | shouldShowLocationAsLabel(nameIsNumber, primaryContactInfo.shouldShowLocation) |
| 717 | ? primaryContactInfo.location |
| 718 | : null) |
twyen | cb2a981 | 2018-03-23 18:21:13 -0700 | [diff] [blame] | 719 | .setLabel(isChildNumberShown || isCallSubjectShown ? null : primaryContactInfo.label) |
Android Dialer | f943910 | 2018-02-21 08:05:14 -0800 | [diff] [blame] | 720 | .setPhoto(primaryContactInfo.photo) |
Android Dialer | f13f0b8 | 2018-05-23 14:05:34 -0700 | [diff] [blame] | 721 | .setPhotoUri(primaryContactInfo.displayPhotoUri) |
Android Dialer | f943910 | 2018-02-21 08:05:14 -0800 | [diff] [blame] | 722 | .setPhotoType(primaryContactInfo.photoType) |
| 723 | .setIsSipCall(primaryContactInfo.isSipCall) |
| 724 | .setIsContactPhotoShown(showContactPhoto) |
| 725 | .setIsWorkCall(hasWorkCallProperty || isWorkContact) |
| 726 | .setIsSpam(primary.isSpam()) |
| 727 | .setIsLocalContact(primaryContactInfo.isLocalContact()) |
| 728 | .setAnsweringDisconnectsOngoingCall(primary.answeringDisconnectsForegroundVideoCall()) |
| 729 | .setShouldShowLocation(shouldShowLocation()) |
| 730 | .setContactInfoLookupKey(primaryContactInfo.lookupKey) |
| 731 | .setMultimediaData(multimediaData) |
| 732 | .setShowInCallButtonGrid(true) |
| 733 | .setNumberPresentation(primary.getNumberPresentation()) |
| 734 | .build()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 735 | } else { |
| 736 | // Clear the primary display info. |
Android Dialer | f943910 | 2018-02-21 08:05:14 -0800 | [diff] [blame] | 737 | inCallScreen.setPrimary(PrimaryInfo.empty()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 738 | } |
| 739 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 740 | if (isInCallScreenReady) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 741 | inCallScreen.showLocationUi(getLocationFragment()); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 742 | } else { |
| 743 | LogUtil.i("CallCardPresenter.updatePrimaryDisplayInfo", "UI not ready, not showing location"); |
| 744 | } |
| 745 | } |
| 746 | |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 747 | private static boolean shouldShowLocationAsLabel( |
| 748 | boolean nameIsNumber, boolean shouldShowLocation) { |
| 749 | if (nameIsNumber) { |
| 750 | return true; |
| 751 | } |
| 752 | if (shouldShowLocation) { |
| 753 | return true; |
| 754 | } |
| 755 | return false; |
| 756 | } |
| 757 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 758 | private Fragment getLocationFragment() { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 759 | if (!shouldShowLocation()) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 760 | return null; |
| 761 | } |
| 762 | LogUtil.i("CallCardPresenter.getLocationFragment", "returning location fragment"); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 763 | return callLocation.getLocationFragment(context); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | private boolean shouldShowLocation() { |
zachh | 190343a | 2018-05-31 17:30:46 -0700 | [diff] [blame] | 767 | if (!ConfigProviderComponent.get(context) |
| 768 | .getConfigProvider() |
wangqi | 1d62ab2 | 2017-11-29 14:29:31 -0800 | [diff] [blame] | 769 | .getBoolean(CONFIG_ENABLE_EMERGENCY_LOCATION, CONFIG_ENABLE_EMERGENCY_LOCATION_DEFAULT)) { |
| 770 | LogUtil.i("CallCardPresenter.getLocationFragment", "disabled by config."); |
| 771 | return false; |
| 772 | } |
| 773 | if (!isPotentialEmergencyCall()) { |
| 774 | LogUtil.i("CallCardPresenter.getLocationFragment", "shouldn't show location"); |
| 775 | return false; |
| 776 | } |
| 777 | if (!hasLocationPermission()) { |
| 778 | LogUtil.i("CallCardPresenter.getLocationFragment", "no location permission."); |
| 779 | return false; |
| 780 | } |
| 781 | if (isBatteryTooLowForEmergencyLocation()) { |
| 782 | LogUtil.i("CallCardPresenter.getLocationFragment", "low battery."); |
| 783 | return false; |
| 784 | } |
linyuh | 437ae95 | 2018-03-26 12:46:18 -0700 | [diff] [blame] | 785 | if (inCallScreen.getInCallScreenFragment().getActivity().isInMultiWindowMode()) { |
wangqi | 1d62ab2 | 2017-11-29 14:29:31 -0800 | [diff] [blame] | 786 | LogUtil.i("CallCardPresenter.getLocationFragment", "in multi-window mode"); |
| 787 | return false; |
| 788 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 789 | if (primary.isVideoCall()) { |
wangqi | 1d62ab2 | 2017-11-29 14:29:31 -0800 | [diff] [blame] | 790 | LogUtil.i("CallCardPresenter.getLocationFragment", "emergency video calls not supported"); |
| 791 | return false; |
| 792 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 793 | if (!callLocation.canGetLocation(context)) { |
wangqi | 1d62ab2 | 2017-11-29 14:29:31 -0800 | [diff] [blame] | 794 | LogUtil.i("CallCardPresenter.getLocationFragment", "can't get current location"); |
| 795 | return false; |
| 796 | } |
| 797 | return true; |
| 798 | } |
| 799 | |
| 800 | private boolean isPotentialEmergencyCall() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 801 | if (isOutgoingEmergencyCall(primary)) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 802 | LogUtil.i("CallCardPresenter.shouldShowLocation", "new emergency call"); |
| 803 | return true; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 804 | } else if (isIncomingEmergencyCall(primary)) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 805 | LogUtil.i("CallCardPresenter.shouldShowLocation", "potential emergency callback"); |
| 806 | return true; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 807 | } else if (isIncomingEmergencyCall(secondary)) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 808 | LogUtil.i("CallCardPresenter.shouldShowLocation", "has potential emergency callback"); |
| 809 | return true; |
| 810 | } |
| 811 | return false; |
| 812 | } |
| 813 | |
| 814 | private static boolean isOutgoingEmergencyCall(@Nullable DialerCall call) { |
| 815 | return call != null && !call.isIncoming() && call.isEmergencyCall(); |
| 816 | } |
| 817 | |
| 818 | private static boolean isIncomingEmergencyCall(@Nullable DialerCall call) { |
| 819 | return call != null && call.isIncoming() && call.isPotentialEmergencyCallback(); |
| 820 | } |
| 821 | |
| 822 | private boolean hasLocationPermission() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 823 | return ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 824 | == PackageManager.PERMISSION_GRANTED; |
| 825 | } |
| 826 | |
| 827 | private boolean isBatteryTooLowForEmergencyLocation() { |
| 828 | Intent batteryStatus = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 829 | context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 830 | int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1); |
| 831 | if (status == BatteryManager.BATTERY_STATUS_CHARGING |
| 832 | || status == BatteryManager.BATTERY_STATUS_FULL) { |
| 833 | // Plugged in or full battery |
| 834 | return false; |
| 835 | } |
| 836 | int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); |
| 837 | int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1); |
| 838 | float batteryPercent = (100f * level) / scale; |
| 839 | long threshold = |
zachh | 190343a | 2018-05-31 17:30:46 -0700 | [diff] [blame] | 840 | ConfigProviderComponent.get(context) |
| 841 | .getConfigProvider() |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 842 | .getLong( |
| 843 | CONFIG_MIN_BATTERY_PERCENT_FOR_EMERGENCY_LOCATION, |
| 844 | CONFIG_MIN_BATTERY_PERCENT_FOR_EMERGENCY_LOCATION_DEFAULT); |
| 845 | LogUtil.i( |
| 846 | "CallCardPresenter.isBatteryTooLowForEmergencyLocation", |
| 847 | "percent charged: " + batteryPercent + ", min required charge: " + threshold); |
| 848 | return batteryPercent < threshold; |
| 849 | } |
| 850 | |
| 851 | private void updateSecondaryDisplayInfo() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 852 | if (inCallScreen == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 853 | return; |
| 854 | } |
| 855 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 856 | if (secondary == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 857 | // Clear the secondary display info. |
Android Dialer | 9e335e2 | 2018-03-01 08:27:39 -0800 | [diff] [blame] | 858 | inCallScreen.setSecondary(SecondaryInfo.builder().setIsFullscreen(isFullscreen).build()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 859 | return; |
| 860 | } |
| 861 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 862 | if (secondary.isMergeInProcess()) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 863 | LogUtil.i( |
| 864 | "CallCardPresenter.updateSecondaryDisplayInfo", |
| 865 | "secondary call is merge in process, clearing info"); |
Android Dialer | 9e335e2 | 2018-03-01 08:27:39 -0800 | [diff] [blame] | 866 | inCallScreen.setSecondary(SecondaryInfo.builder().setIsFullscreen(isFullscreen).build()); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 867 | return; |
| 868 | } |
| 869 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 870 | if (secondary.isConferenceCall()) { |
| 871 | inCallScreen.setSecondary( |
Android Dialer | 9e335e2 | 2018-03-01 08:27:39 -0800 | [diff] [blame] | 872 | SecondaryInfo.builder() |
| 873 | .setShouldShow(true) |
| 874 | .setName( |
| 875 | CallerInfoUtils.getConferenceString( |
| 876 | context, secondary.hasProperty(Details.PROPERTY_GENERIC_CONFERENCE))) |
| 877 | .setProviderLabel(secondary.getCallProviderLabel()) |
| 878 | .setIsConference(true) |
| 879 | .setIsVideoCall(secondary.isVideoCall()) |
| 880 | .setIsFullscreen(isFullscreen) |
| 881 | .build()); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 882 | } else if (secondaryContactInfo != null) { |
| 883 | LogUtil.v("CallCardPresenter.updateSecondaryDisplayInfo", "" + secondaryContactInfo); |
| 884 | String name = getNameForCall(secondaryContactInfo); |
| 885 | boolean nameIsNumber = name != null && name.equals(secondaryContactInfo.number); |
| 886 | inCallScreen.setSecondary( |
Android Dialer | 9e335e2 | 2018-03-01 08:27:39 -0800 | [diff] [blame] | 887 | SecondaryInfo.builder() |
| 888 | .setShouldShow(true) |
| 889 | .setName(secondary.updateNameIfRestricted(name)) |
| 890 | .setNameIsNumber(nameIsNumber) |
| 891 | .setLabel(secondaryContactInfo.label) |
| 892 | .setProviderLabel(secondary.getCallProviderLabel()) |
| 893 | .setIsVideoCall(secondary.isVideoCall()) |
| 894 | .setIsFullscreen(isFullscreen) |
| 895 | .build()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 896 | } else { |
| 897 | // Clear the secondary display info. |
Android Dialer | 9e335e2 | 2018-03-01 08:27:39 -0800 | [diff] [blame] | 898 | inCallScreen.setSecondary(SecondaryInfo.builder().setIsFullscreen(isFullscreen).build()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 899 | } |
| 900 | } |
| 901 | |
| 902 | /** Returns the gateway number for any existing outgoing call. */ |
| 903 | private String getGatewayNumber() { |
| 904 | if (hasOutgoingGatewayCall()) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 905 | return DialerCall.getNumberFromHandle(primary.getGatewayInfo().getGatewayAddress()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 906 | } |
| 907 | return null; |
| 908 | } |
| 909 | |
| 910 | /** |
| 911 | * Returns the label (line of text above the number/name) for any given call. For example, |
| 912 | * "calling via [Account/Google Voice]" for outgoing calls. |
| 913 | */ |
| 914 | private String getConnectionLabel() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 915 | if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 916 | != PackageManager.PERMISSION_GRANTED) { |
| 917 | return null; |
| 918 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 919 | StatusHints statusHints = primary.getStatusHints(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 920 | if (statusHints != null && !TextUtils.isEmpty(statusHints.getLabel())) { |
| 921 | return statusHints.getLabel().toString(); |
| 922 | } |
| 923 | |
| 924 | if (hasOutgoingGatewayCall() && getUi() != null) { |
| 925 | // Return the label for the gateway app on outgoing calls. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 926 | final PackageManager pm = context.getPackageManager(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 927 | try { |
| 928 | ApplicationInfo info = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 929 | pm.getApplicationInfo(primary.getGatewayInfo().getGatewayProviderPackageName(), 0); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 930 | return pm.getApplicationLabel(info).toString(); |
| 931 | } catch (PackageManager.NameNotFoundException e) { |
| 932 | LogUtil.e("CallCardPresenter.getConnectionLabel", "gateway Application Not Found.", e); |
| 933 | return null; |
| 934 | } |
| 935 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 936 | return primary.getCallProviderLabel(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 937 | } |
| 938 | |
twyen | 4fde0ac | 2018-03-22 18:04:23 -0700 | [diff] [blame] | 939 | @Nullable |
| 940 | private SuggestionProvider.Reason getSimSuggestionReason() { |
| 941 | String value = |
| 942 | primary.getIntentExtras().getString(SuggestionProvider.EXTRA_SIM_SUGGESTION_REASON); |
| 943 | if (value == null) { |
| 944 | return null; |
| 945 | } |
| 946 | try { |
| 947 | return SuggestionProvider.Reason.valueOf(value); |
| 948 | } catch (IllegalArgumentException e) { |
| 949 | LogUtil.e("CallCardPresenter.getConnectionLabel", "unknown reason " + value); |
| 950 | return null; |
| 951 | } |
| 952 | } |
| 953 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 954 | private Drawable getCallStateIcon() { |
| 955 | // Return connection icon if one exists. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 956 | StatusHints statusHints = primary.getStatusHints(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 957 | if (statusHints != null && statusHints.getIcon() != null) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 958 | Drawable icon = statusHints.getIcon().loadDrawable(context); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 959 | if (icon != null) { |
| 960 | return icon; |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | return null; |
| 965 | } |
| 966 | |
| 967 | private boolean hasOutgoingGatewayCall() { |
| 968 | // We only display the gateway information while STATE_DIALING so return false for any other |
| 969 | // call state. |
| 970 | // TODO: mPrimary can be null because this is called from updatePrimaryDisplayInfo which |
| 971 | // is also called after a contact search completes (call is not present yet). Split the |
| 972 | // UI update so it can receive independent updates. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 973 | if (primary == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 974 | return false; |
| 975 | } |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame] | 976 | return DialerCallState.isDialing(primary.getState()) |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 977 | && primary.getGatewayInfo() != null |
| 978 | && !primary.getGatewayInfo().isEmpty(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | /** Gets the name to display for the call. */ |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 982 | private String getNameForCall(ContactCacheEntry contactInfo) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 983 | String preferredName = |
twyen | 5578d92 | 2018-06-25 12:36:26 -0700 | [diff] [blame] | 984 | ContactsComponent.get(context) |
| 985 | .contactDisplayPreferences() |
| 986 | .getDisplayName(contactInfo.namePrimary, contactInfo.nameAlternative); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 987 | if (TextUtils.isEmpty(preferredName)) { |
wangqi | a462370 | 2018-04-02 14:23:38 -0700 | [diff] [blame] | 988 | return TextUtils.isEmpty(contactInfo.number) |
| 989 | ? null |
| 990 | : BidiFormatter.getInstance() |
| 991 | .unicodeWrap(contactInfo.number, TextDirectionHeuristics.LTR); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 992 | } |
| 993 | return preferredName; |
| 994 | } |
| 995 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 996 | @Override |
| 997 | public void onSecondaryInfoClicked() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 998 | if (secondary == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 999 | LogUtil.e( |
| 1000 | "CallCardPresenter.onSecondaryInfoClicked", |
| 1001 | "secondary info clicked but no secondary call."); |
| 1002 | return; |
| 1003 | } |
| 1004 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1005 | Logger.get(context) |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1006 | .logCallImpression( |
| 1007 | DialerImpression.Type.IN_CALL_SWAP_SECONDARY_BUTTON_PRESSED, |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1008 | primary.getUniqueCallId(), |
| 1009 | primary.getTimeAddedMs()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1010 | LogUtil.i( |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1011 | "CallCardPresenter.onSecondaryInfoClicked", "swapping call to foreground: " + secondary); |
| 1012 | secondary.unhold(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | @Override |
| 1016 | public void onEndCallClicked() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1017 | LogUtil.i("CallCardPresenter.onEndCallClicked", "disconnecting call: " + primary); |
| 1018 | if (primary != null) { |
| 1019 | primary.disconnect(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1020 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1021 | PostCall.onDisconnectPressed(context); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | /** |
| 1025 | * Handles a change to the fullscreen mode of the in-call UI. |
| 1026 | * |
| 1027 | * @param isFullscreenMode {@code True} if the in-call UI is entering full screen mode. |
| 1028 | */ |
| 1029 | @Override |
| 1030 | public void onFullscreenModeChanged(boolean isFullscreenMode) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1031 | isFullscreen = isFullscreenMode; |
| 1032 | if (inCallScreen == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1033 | return; |
| 1034 | } |
| 1035 | maybeShowManageConferenceCallButton(); |
| 1036 | } |
| 1037 | |
| 1038 | private boolean isPrimaryCallActive() { |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame] | 1039 | return primary != null && primary.getState() == DialerCallState.ACTIVE; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1040 | } |
| 1041 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1042 | private boolean shouldShowEndCallButton(DialerCall primary, int callState) { |
| 1043 | if (primary == null) { |
| 1044 | return false; |
| 1045 | } |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame] | 1046 | if ((!DialerCallState.isConnectingOrConnected(callState) |
| 1047 | && callState != DialerCallState.DISCONNECTING |
| 1048 | && callState != DialerCallState.DISCONNECTED) |
| 1049 | || callState == DialerCallState.INCOMING) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1050 | return false; |
| 1051 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1052 | if (this.primary.getVideoTech().getSessionModificationState() |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 1053 | == SessionModificationState.RECEIVED_UPGRADE_TO_VIDEO_REQUEST) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1054 | return false; |
| 1055 | } |
| 1056 | return true; |
| 1057 | } |
| 1058 | |
| 1059 | @Override |
| 1060 | public void onInCallScreenResumed() { |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 1061 | updatePrimaryDisplayInfo(); |
| 1062 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1063 | if (shouldSendAccessibilityEvent) { |
| 1064 | handler.postDelayed(sendAccessibilityEventRunnable, ACCESSIBILITY_ANNOUNCEMENT_DELAY_MILLIS); |
| 1065 | } |
| 1066 | } |
| 1067 | |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 1068 | @Override |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1069 | public void onInCallScreenPaused() {} |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 1070 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1071 | static boolean sendAccessibilityEvent(Context context, InCallScreen inCallScreen) { |
| 1072 | AccessibilityManager am = |
| 1073 | (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE); |
| 1074 | if (!am.isEnabled()) { |
| 1075 | LogUtil.w("CallCardPresenter.sendAccessibilityEvent", "accessibility is off"); |
| 1076 | return false; |
| 1077 | } |
| 1078 | if (inCallScreen == null) { |
| 1079 | LogUtil.w("CallCardPresenter.sendAccessibilityEvent", "incallscreen is null"); |
| 1080 | return false; |
| 1081 | } |
| 1082 | Fragment fragment = inCallScreen.getInCallScreenFragment(); |
| 1083 | if (fragment == null || fragment.getView() == null || fragment.getView().getParent() == null) { |
| 1084 | LogUtil.w("CallCardPresenter.sendAccessibilityEvent", "fragment/view/parent is null"); |
| 1085 | return false; |
| 1086 | } |
| 1087 | |
| 1088 | DisplayManager displayManager = |
| 1089 | (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE); |
| 1090 | Display display = displayManager.getDisplay(Display.DEFAULT_DISPLAY); |
| 1091 | boolean screenIsOn = display.getState() == Display.STATE_ON; |
| 1092 | LogUtil.d("CallCardPresenter.sendAccessibilityEvent", "screen is on: %b", screenIsOn); |
| 1093 | if (!screenIsOn) { |
| 1094 | return false; |
| 1095 | } |
| 1096 | |
| 1097 | AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_ANNOUNCEMENT); |
| 1098 | inCallScreen.dispatchPopulateAccessibilityEvent(event); |
| 1099 | View view = inCallScreen.getInCallScreenFragment().getView(); |
| 1100 | view.getParent().requestSendAccessibilityEvent(view, event); |
| 1101 | return true; |
| 1102 | } |
| 1103 | |
| 1104 | private void maybeSendAccessibilityEvent( |
| 1105 | InCallState oldState, final InCallState newState, boolean primaryChanged) { |
| 1106 | shouldSendAccessibilityEvent = false; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1107 | if (context == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1108 | return; |
| 1109 | } |
| 1110 | final AccessibilityManager am = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1111 | (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1112 | if (!am.isEnabled()) { |
| 1113 | return; |
| 1114 | } |
| 1115 | // Announce the current call if it's new incoming/outgoing call or primary call is changed |
| 1116 | // due to switching calls between two ongoing calls (one is on hold). |
| 1117 | if ((oldState != InCallState.OUTGOING && newState == InCallState.OUTGOING) |
| 1118 | || (oldState != InCallState.INCOMING && newState == InCallState.INCOMING) |
| 1119 | || primaryChanged) { |
| 1120 | LogUtil.i( |
| 1121 | "CallCardPresenter.maybeSendAccessibilityEvent", "schedule accessibility announcement"); |
| 1122 | shouldSendAccessibilityEvent = true; |
| 1123 | handler.postDelayed(sendAccessibilityEventRunnable, ACCESSIBILITY_ANNOUNCEMENT_DELAY_MILLIS); |
| 1124 | } |
| 1125 | } |
| 1126 | |
| 1127 | /** |
| 1128 | * Determines whether the call subject should be visible on the UI. For the call subject to be |
| 1129 | * visible, the call has to be in an incoming or waiting state, and the subject must not be empty. |
| 1130 | * |
| 1131 | * @param call The call. |
| 1132 | * @return {@code true} if the subject should be shown, {@code false} otherwise. |
| 1133 | */ |
| 1134 | private boolean shouldShowCallSubject(DialerCall call) { |
| 1135 | if (call == null) { |
| 1136 | return false; |
| 1137 | } |
| 1138 | |
| 1139 | boolean isIncomingOrWaiting = |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame] | 1140 | primary.getState() == DialerCallState.INCOMING |
| 1141 | || primary.getState() == DialerCallState.CALL_WAITING; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1142 | return isIncomingOrWaiting |
| 1143 | && !TextUtils.isEmpty(call.getCallSubject()) |
| 1144 | && call.getNumberPresentation() == TelecomManager.PRESENTATION_ALLOWED |
| 1145 | && call.isCallSubjectSupported(); |
| 1146 | } |
| 1147 | |
| 1148 | /** |
| 1149 | * Determines whether the "note sent" toast should be shown. It should be shown for a new outgoing |
| 1150 | * call with a subject. |
| 1151 | * |
| 1152 | * @param call The call |
| 1153 | * @return {@code true} if the toast should be shown, {@code false} otherwise. |
| 1154 | */ |
| 1155 | private boolean shouldShowNoteSentToast(DialerCall call) { |
| 1156 | return call != null |
| 1157 | && hasCallSubject(call) |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame] | 1158 | && (call.getState() == DialerCallState.DIALING |
| 1159 | || call.getState() == DialerCallState.CONNECTING); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | private InCallScreen getUi() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1163 | return inCallScreen; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1164 | } |
| 1165 | |
Android Dialer | f943910 | 2018-02-21 08:05:14 -0800 | [diff] [blame] | 1166 | /** Callback for contact lookup. */ |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1167 | public static class ContactLookupCallback implements ContactInfoCacheCallback { |
| 1168 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1169 | private final WeakReference<CallCardPresenter> callCardPresenter; |
| 1170 | private final boolean isPrimary; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1171 | |
| 1172 | public ContactLookupCallback(CallCardPresenter callCardPresenter, boolean isPrimary) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1173 | this.callCardPresenter = new WeakReference<CallCardPresenter>(callCardPresenter); |
| 1174 | this.isPrimary = isPrimary; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | @Override |
| 1178 | public void onContactInfoComplete(String callId, ContactCacheEntry entry) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1179 | CallCardPresenter presenter = callCardPresenter.get(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1180 | if (presenter != null) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1181 | presenter.onContactInfoComplete(callId, entry, isPrimary); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1182 | } |
| 1183 | } |
| 1184 | |
| 1185 | @Override |
| 1186 | public void onImageLoadComplete(String callId, ContactCacheEntry entry) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1187 | CallCardPresenter presenter = callCardPresenter.get(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1188 | if (presenter != null) { |
| 1189 | presenter.onImageLoadComplete(callId, entry); |
| 1190 | } |
| 1191 | } |
| 1192 | } |
| 1193 | } |