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