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; |
| 39 | import android.text.TextUtils; |
| 40 | import android.view.Display; |
| 41 | import android.view.View; |
| 42 | import android.view.accessibility.AccessibilityEvent; |
| 43 | import android.view.accessibility.AccessibilityManager; |
| 44 | import com.android.contacts.common.ContactsUtils; |
| 45 | import com.android.contacts.common.preference.ContactsPreferences; |
| 46 | import com.android.contacts.common.util.ContactDisplayUtils; |
| 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; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 49 | import com.android.dialer.compat.ActivityCompat; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 50 | import com.android.dialer.configprovider.ConfigProviderBindings; |
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 | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 67 | import com.android.incallui.call.DialerCall.State; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 68 | import com.android.incallui.call.DialerCallListener; |
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; |
| 125 | @Nullable private ContactsPreferences contactsPreferences; |
| 126 | private boolean isFullscreen = false; |
| 127 | private InCallScreen inCallScreen; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 128 | private boolean isInCallScreenReady; |
| 129 | private boolean shouldSendAccessibilityEvent; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 130 | |
| 131 | @NonNull private final CallLocation callLocation; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 132 | private final Runnable sendAccessibilityEventRunnable = |
| 133 | new Runnable() { |
| 134 | @Override |
| 135 | public void run() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 136 | shouldSendAccessibilityEvent = !sendAccessibilityEvent(context, getUi()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 137 | LogUtil.i( |
| 138 | "CallCardPresenter.sendAccessibilityEventRunnable", |
| 139 | "still should send: %b", |
| 140 | shouldSendAccessibilityEvent); |
| 141 | if (!shouldSendAccessibilityEvent) { |
| 142 | handler.removeCallbacks(this); |
| 143 | } |
| 144 | } |
| 145 | }; |
| 146 | |
| 147 | public CallCardPresenter(Context context) { |
wangqi | 385a5a1 | 2017-09-28 10:44:54 -0700 | [diff] [blame] | 148 | LogUtil.i("CallCardPresenter.constructor", null); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 149 | this.context = Assert.isNotNull(context).getApplicationContext(); |
| 150 | callLocation = CallLocationComponent.get(this.context).getCallLocation(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | private static boolean hasCallSubject(DialerCall call) { |
| 154 | return !TextUtils.isEmpty(call.getCallSubject()); |
| 155 | } |
| 156 | |
| 157 | @Override |
| 158 | public void onInCallScreenDelegateInit(InCallScreen inCallScreen) { |
| 159 | Assert.isNotNull(inCallScreen); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 160 | this.inCallScreen = inCallScreen; |
| 161 | contactsPreferences = ContactsPreferencesFactory.newContactsPreferences(context); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 162 | |
| 163 | // Call may be null if disconnect happened already. |
| 164 | DialerCall call = CallList.getInstance().getFirstCall(); |
| 165 | if (call != null) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 166 | primary = call; |
| 167 | if (shouldShowNoteSentToast(primary)) { |
| 168 | this.inCallScreen.showNoteSentToast(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 169 | } |
| 170 | call.addListener(this); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 171 | // start processing lookups right away. |
| 172 | if (!call.isConferenceCall()) { |
| 173 | startContactInfoSearch(call, true, call.getState() == DialerCall.State.INCOMING); |
| 174 | } else { |
| 175 | updateContactEntry(null, true); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | onStateChange(null, InCallPresenter.getInstance().getInCallState(), CallList.getInstance()); |
| 180 | } |
| 181 | |
| 182 | @Override |
| 183 | public void onInCallScreenReady() { |
wangqi | 385a5a1 | 2017-09-28 10:44:54 -0700 | [diff] [blame] | 184 | LogUtil.i("CallCardPresenter.onInCallScreenReady", null); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 185 | Assert.checkState(!isInCallScreenReady); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 186 | if (contactsPreferences != null) { |
| 187 | contactsPreferences.refreshValue(ContactsPreferences.DISPLAY_ORDER_KEY); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 188 | } |
| 189 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 190 | // Contact search may have completed before ui is ready. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 191 | if (primaryContactInfo != null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 192 | updatePrimaryDisplayInfo(); |
| 193 | } |
| 194 | |
| 195 | // Register for call state changes last |
| 196 | InCallPresenter.getInstance().addListener(this); |
| 197 | InCallPresenter.getInstance().addIncomingCallListener(this); |
| 198 | InCallPresenter.getInstance().addDetailsListener(this); |
| 199 | InCallPresenter.getInstance().addInCallEventListener(this); |
| 200 | isInCallScreenReady = true; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 201 | |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 202 | // Log location impressions |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 203 | if (isOutgoingEmergencyCall(primary)) { |
| 204 | Logger.get(context).logImpression(DialerImpression.Type.EMERGENCY_NEW_EMERGENCY_CALL); |
| 205 | } else if (isIncomingEmergencyCall(primary) || isIncomingEmergencyCall(secondary)) { |
| 206 | Logger.get(context).logImpression(DialerImpression.Type.EMERGENCY_CALLBACK); |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 209 | // Showing the location may have been skipped if the UI wasn't ready during previous layout. |
| 210 | if (shouldShowLocation()) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 211 | inCallScreen.showLocationUi(getLocationFragment()); |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 212 | |
| 213 | // Log location impressions |
| 214 | if (!hasLocationPermission()) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 215 | Logger.get(context).logImpression(DialerImpression.Type.EMERGENCY_NO_LOCATION_PERMISSION); |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 216 | } else if (isBatteryTooLowForEmergencyLocation()) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 217 | Logger.get(context) |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 218 | .logImpression(DialerImpression.Type.EMERGENCY_BATTERY_TOO_LOW_TO_GET_LOCATION); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 219 | } else if (!callLocation.canGetLocation(context)) { |
| 220 | Logger.get(context).logImpression(DialerImpression.Type.EMERGENCY_CANT_GET_LOCATION); |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 221 | } |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 222 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | @Override |
| 226 | public void onInCallScreenUnready() { |
wangqi | 385a5a1 | 2017-09-28 10:44:54 -0700 | [diff] [blame] | 227 | LogUtil.i("CallCardPresenter.onInCallScreenUnready", null); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 228 | Assert.checkState(isInCallScreenReady); |
| 229 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 230 | // stop getting call state changes |
| 231 | InCallPresenter.getInstance().removeListener(this); |
| 232 | InCallPresenter.getInstance().removeIncomingCallListener(this); |
| 233 | InCallPresenter.getInstance().removeDetailsListener(this); |
| 234 | InCallPresenter.getInstance().removeInCallEventListener(this); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 235 | if (primary != null) { |
| 236 | primary.removeListener(this); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 237 | } |
| 238 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 239 | callLocation.close(); |
| 240 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 241 | primary = null; |
| 242 | primaryContactInfo = null; |
| 243 | secondaryContactInfo = null; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 244 | isInCallScreenReady = false; |
| 245 | } |
| 246 | |
| 247 | @Override |
| 248 | public void onIncomingCall(InCallState oldState, InCallState newState, DialerCall call) { |
| 249 | // same logic should happen as with onStateChange() |
| 250 | onStateChange(oldState, newState, CallList.getInstance()); |
| 251 | } |
| 252 | |
| 253 | @Override |
| 254 | public void onStateChange(InCallState oldState, InCallState newState, CallList callList) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 255 | Trace.beginSection("CallCardPresenter.onStateChange"); |
| 256 | LogUtil.v("CallCardPresenter.onStateChange", "oldState: %s, newState: %s", oldState, newState); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 257 | if (inCallScreen == null) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 258 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 259 | return; |
| 260 | } |
| 261 | |
| 262 | DialerCall primary = null; |
| 263 | DialerCall secondary = null; |
| 264 | |
| 265 | if (newState == InCallState.INCOMING) { |
| 266 | primary = callList.getIncomingCall(); |
| 267 | } else if (newState == InCallState.PENDING_OUTGOING || newState == InCallState.OUTGOING) { |
| 268 | primary = callList.getOutgoingCall(); |
| 269 | if (primary == null) { |
| 270 | primary = callList.getPendingOutgoingCall(); |
| 271 | } |
| 272 | |
| 273 | // getCallToDisplay doesn't go through outgoing or incoming calls. It will return the |
| 274 | // highest priority call to display as the secondary call. |
| 275 | secondary = getCallToDisplay(callList, null, true); |
| 276 | } else if (newState == InCallState.INCALL) { |
| 277 | primary = getCallToDisplay(callList, null, false); |
| 278 | secondary = getCallToDisplay(callList, primary, true); |
| 279 | } |
| 280 | |
| 281 | LogUtil.v("CallCardPresenter.onStateChange", "primary call: " + primary); |
| 282 | LogUtil.v("CallCardPresenter.onStateChange", "secondary call: " + secondary); |
wangqi | dd5f1a5 | 2018-01-23 18:01:00 -0800 | [diff] [blame] | 283 | String primaryNumber = null; |
| 284 | String secondaryNumber = null; |
| 285 | if (primary != null) { |
| 286 | primaryNumber = primary.getNumber(); |
| 287 | } |
| 288 | if (secondary != null) { |
| 289 | secondaryNumber = secondary.getNumber(); |
| 290 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 291 | |
| 292 | final boolean primaryChanged = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 293 | !(DialerCall.areSame(this.primary, primary) |
wangqi | dd5f1a5 | 2018-01-23 18:01:00 -0800 | [diff] [blame] | 294 | && TextUtils.equals(this.primaryNumber, primaryNumber)); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 295 | final boolean secondaryChanged = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 296 | !(DialerCall.areSame(this.secondary, secondary) |
wangqi | dd5f1a5 | 2018-01-23 18:01:00 -0800 | [diff] [blame] | 297 | && TextUtils.equals(this.secondaryNumber, secondaryNumber)); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 298 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 299 | this.secondary = secondary; |
wangqi | dd5f1a5 | 2018-01-23 18:01:00 -0800 | [diff] [blame] | 300 | this.secondaryNumber = secondaryNumber; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 301 | DialerCall previousPrimary = this.primary; |
| 302 | this.primary = primary; |
wangqi | dd5f1a5 | 2018-01-23 18:01:00 -0800 | [diff] [blame] | 303 | this.primaryNumber = primaryNumber; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 304 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 305 | if (this.primary != null) { |
| 306 | InCallPresenter.getInstance().onForegroundCallChanged(this.primary); |
| 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 | |
| 640 | /** |
| 641 | * Get the highest priority call to display. Goes through the calls and chooses which to return |
| 642 | * based on priority of which type of call to display to the user. Callers can use the "ignore" |
| 643 | * feature to get the second best call by passing a previously found primary call as ignore. |
| 644 | * |
| 645 | * @param ignore A call to ignore if found. |
| 646 | */ |
| 647 | private DialerCall getCallToDisplay( |
| 648 | CallList callList, DialerCall ignore, boolean skipDisconnected) { |
| 649 | // Active calls come second. An active call always gets precedent. |
| 650 | DialerCall retval = callList.getActiveCall(); |
| 651 | if (retval != null && retval != ignore) { |
| 652 | return retval; |
| 653 | } |
| 654 | |
| 655 | // Sometimes there is intemediate state that two calls are in active even one is about |
| 656 | // to be on hold. |
| 657 | retval = callList.getSecondActiveCall(); |
| 658 | if (retval != null && retval != ignore) { |
| 659 | return retval; |
| 660 | } |
| 661 | |
| 662 | // Disconnected calls get primary position if there are no active calls |
| 663 | // to let user know quickly what call has disconnected. Disconnected |
| 664 | // calls are very short lived. |
| 665 | if (!skipDisconnected) { |
| 666 | retval = callList.getDisconnectingCall(); |
| 667 | if (retval != null && retval != ignore) { |
| 668 | return retval; |
| 669 | } |
| 670 | retval = callList.getDisconnectedCall(); |
| 671 | if (retval != null && retval != ignore) { |
| 672 | return retval; |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | // Then we go to background call (calls on hold) |
| 677 | retval = callList.getBackgroundCall(); |
| 678 | if (retval != null && retval != ignore) { |
| 679 | return retval; |
| 680 | } |
| 681 | |
| 682 | // Lastly, we go to a second background call. |
| 683 | retval = callList.getSecondBackgroundCall(); |
| 684 | |
| 685 | return retval; |
| 686 | } |
| 687 | |
| 688 | private void updatePrimaryDisplayInfo() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 689 | if (inCallScreen == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 690 | // TODO: May also occur if search result comes back after ui is destroyed. Look into |
| 691 | // removing that case completely. |
| 692 | LogUtil.v( |
| 693 | "CallCardPresenter.updatePrimaryDisplayInfo", |
| 694 | "updatePrimaryDisplayInfo called but ui is null!"); |
| 695 | return; |
| 696 | } |
| 697 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 698 | if (primary == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 699 | // Clear the primary display info. |
Android Dialer | f943910 | 2018-02-21 08:05:14 -0800 | [diff] [blame] | 700 | inCallScreen.setPrimary(PrimaryInfo.empty()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 701 | return; |
| 702 | } |
| 703 | |
| 704 | // Hide the contact photo if we are in a video call and the incoming video surface is |
| 705 | // showing. |
| 706 | boolean showContactPhoto = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 707 | !VideoCallPresenter.showIncomingVideo(primary.getVideoState(), primary.getState()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 708 | |
| 709 | // DialerCall placed through a work phone account. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 710 | boolean hasWorkCallProperty = primary.hasProperty(PROPERTY_ENTERPRISE_CALL); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 711 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 712 | MultimediaData multimediaData = null; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 713 | if (primary.getEnrichedCallSession() != null) { |
| 714 | multimediaData = primary.getEnrichedCallSession().getMultimediaData(); |
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 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 717 | if (primary.isConferenceCall()) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 718 | LogUtil.v( |
| 719 | "CallCardPresenter.updatePrimaryDisplayInfo", |
| 720 | "update primary display info for conference call."); |
| 721 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 722 | inCallScreen.setPrimary( |
Android Dialer | f943910 | 2018-02-21 08:05:14 -0800 | [diff] [blame] | 723 | PrimaryInfo.builder() |
| 724 | .setName( |
| 725 | CallerInfoUtils.getConferenceString( |
| 726 | context, primary.hasProperty(Details.PROPERTY_GENERIC_CONFERENCE))) |
| 727 | .setNameIsNumber(false) |
| 728 | .setPhotoType(ContactPhotoType.DEFAULT_PLACEHOLDER) |
| 729 | .setIsSipCall(false) |
| 730 | .setIsContactPhotoShown(showContactPhoto) |
| 731 | .setIsWorkCall(hasWorkCallProperty) |
| 732 | .setIsSpam(false) |
| 733 | .setIsLocalContact(false) |
| 734 | .setAnsweringDisconnectsOngoingCall(false) |
| 735 | .setShouldShowLocation(shouldShowLocation()) |
| 736 | .setShowInCallButtonGrid(true) |
| 737 | .setNumberPresentation(primary.getNumberPresentation()) |
| 738 | .build()); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 739 | } else if (primaryContactInfo != null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 740 | LogUtil.v( |
| 741 | "CallCardPresenter.updatePrimaryDisplayInfo", |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 742 | "update primary display info for " + primaryContactInfo); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 743 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 744 | String name = getNameForCall(primaryContactInfo); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 745 | String number; |
| 746 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 747 | boolean isChildNumberShown = !TextUtils.isEmpty(primary.getChildNumber()); |
| 748 | boolean isForwardedNumberShown = !TextUtils.isEmpty(primary.getLastForwardedNumber()); |
| 749 | boolean isCallSubjectShown = shouldShowCallSubject(primary); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 750 | |
| 751 | if (isCallSubjectShown) { |
| 752 | number = null; |
| 753 | } else if (isChildNumberShown) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 754 | number = context.getString(R.string.child_number, primary.getChildNumber()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 755 | } else if (isForwardedNumberShown) { |
| 756 | // Use last forwarded number instead of second line, if present. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 757 | number = primary.getLastForwardedNumber(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 758 | } else { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 759 | number = primaryContactInfo.number; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 760 | } |
| 761 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 762 | boolean nameIsNumber = name != null && name.equals(primaryContactInfo.number); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 763 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 764 | // DialerCall with caller that is a work contact. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 765 | boolean isWorkContact = (primaryContactInfo.userType == ContactsUtils.USER_TYPE_WORK); |
| 766 | inCallScreen.setPrimary( |
Android Dialer | f943910 | 2018-02-21 08:05:14 -0800 | [diff] [blame] | 767 | PrimaryInfo.builder() |
| 768 | .setNumber(number) |
| 769 | .setName(primary.updateNameIfRestricted(name)) |
| 770 | .setNameIsNumber(nameIsNumber) |
| 771 | .setLabel( |
| 772 | shouldShowLocationAsLabel(nameIsNumber, primaryContactInfo.shouldShowLocation) |
| 773 | ? primaryContactInfo.location |
| 774 | : null) |
| 775 | .setLocation( |
| 776 | isChildNumberShown || isCallSubjectShown ? null : primaryContactInfo.label) |
| 777 | .setPhoto(primaryContactInfo.photo) |
| 778 | .setPhotoType(primaryContactInfo.photoType) |
| 779 | .setIsSipCall(primaryContactInfo.isSipCall) |
| 780 | .setIsContactPhotoShown(showContactPhoto) |
| 781 | .setIsWorkCall(hasWorkCallProperty || isWorkContact) |
| 782 | .setIsSpam(primary.isSpam()) |
| 783 | .setIsLocalContact(primaryContactInfo.isLocalContact()) |
| 784 | .setAnsweringDisconnectsOngoingCall(primary.answeringDisconnectsForegroundVideoCall()) |
| 785 | .setShouldShowLocation(shouldShowLocation()) |
| 786 | .setContactInfoLookupKey(primaryContactInfo.lookupKey) |
| 787 | .setMultimediaData(multimediaData) |
| 788 | .setShowInCallButtonGrid(true) |
| 789 | .setNumberPresentation(primary.getNumberPresentation()) |
| 790 | .build()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 791 | } else { |
| 792 | // Clear the primary display info. |
Android Dialer | f943910 | 2018-02-21 08:05:14 -0800 | [diff] [blame] | 793 | inCallScreen.setPrimary(PrimaryInfo.empty()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 794 | } |
| 795 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 796 | if (isInCallScreenReady) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 797 | inCallScreen.showLocationUi(getLocationFragment()); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 798 | } else { |
| 799 | LogUtil.i("CallCardPresenter.updatePrimaryDisplayInfo", "UI not ready, not showing location"); |
| 800 | } |
| 801 | } |
| 802 | |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 803 | private static boolean shouldShowLocationAsLabel( |
| 804 | boolean nameIsNumber, boolean shouldShowLocation) { |
| 805 | if (nameIsNumber) { |
| 806 | return true; |
| 807 | } |
| 808 | if (shouldShowLocation) { |
| 809 | return true; |
| 810 | } |
| 811 | return false; |
| 812 | } |
| 813 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 814 | private Fragment getLocationFragment() { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 815 | if (!shouldShowLocation()) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 816 | return null; |
| 817 | } |
| 818 | LogUtil.i("CallCardPresenter.getLocationFragment", "returning location fragment"); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 819 | return callLocation.getLocationFragment(context); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | private boolean shouldShowLocation() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 823 | if (!ConfigProviderBindings.get(context) |
wangqi | 1d62ab2 | 2017-11-29 14:29:31 -0800 | [diff] [blame] | 824 | .getBoolean(CONFIG_ENABLE_EMERGENCY_LOCATION, CONFIG_ENABLE_EMERGENCY_LOCATION_DEFAULT)) { |
| 825 | LogUtil.i("CallCardPresenter.getLocationFragment", "disabled by config."); |
| 826 | return false; |
| 827 | } |
| 828 | if (!isPotentialEmergencyCall()) { |
| 829 | LogUtil.i("CallCardPresenter.getLocationFragment", "shouldn't show location"); |
| 830 | return false; |
| 831 | } |
| 832 | if (!hasLocationPermission()) { |
| 833 | LogUtil.i("CallCardPresenter.getLocationFragment", "no location permission."); |
| 834 | return false; |
| 835 | } |
| 836 | if (isBatteryTooLowForEmergencyLocation()) { |
| 837 | LogUtil.i("CallCardPresenter.getLocationFragment", "low battery."); |
| 838 | return false; |
| 839 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 840 | if (ActivityCompat.isInMultiWindowMode(inCallScreen.getInCallScreenFragment().getActivity())) { |
wangqi | 1d62ab2 | 2017-11-29 14:29:31 -0800 | [diff] [blame] | 841 | LogUtil.i("CallCardPresenter.getLocationFragment", "in multi-window mode"); |
| 842 | return false; |
| 843 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 844 | if (primary.isVideoCall()) { |
wangqi | 1d62ab2 | 2017-11-29 14:29:31 -0800 | [diff] [blame] | 845 | LogUtil.i("CallCardPresenter.getLocationFragment", "emergency video calls not supported"); |
| 846 | return false; |
| 847 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 848 | if (!callLocation.canGetLocation(context)) { |
wangqi | 1d62ab2 | 2017-11-29 14:29:31 -0800 | [diff] [blame] | 849 | LogUtil.i("CallCardPresenter.getLocationFragment", "can't get current location"); |
| 850 | return false; |
| 851 | } |
| 852 | return true; |
| 853 | } |
| 854 | |
| 855 | private boolean isPotentialEmergencyCall() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 856 | if (isOutgoingEmergencyCall(primary)) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 857 | LogUtil.i("CallCardPresenter.shouldShowLocation", "new emergency call"); |
| 858 | return true; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 859 | } else if (isIncomingEmergencyCall(primary)) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 860 | LogUtil.i("CallCardPresenter.shouldShowLocation", "potential emergency callback"); |
| 861 | return true; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 862 | } else if (isIncomingEmergencyCall(secondary)) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 863 | LogUtil.i("CallCardPresenter.shouldShowLocation", "has potential emergency callback"); |
| 864 | return true; |
| 865 | } |
| 866 | return false; |
| 867 | } |
| 868 | |
| 869 | private static boolean isOutgoingEmergencyCall(@Nullable DialerCall call) { |
| 870 | return call != null && !call.isIncoming() && call.isEmergencyCall(); |
| 871 | } |
| 872 | |
| 873 | private static boolean isIncomingEmergencyCall(@Nullable DialerCall call) { |
| 874 | return call != null && call.isIncoming() && call.isPotentialEmergencyCallback(); |
| 875 | } |
| 876 | |
| 877 | private boolean hasLocationPermission() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 878 | return ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 879 | == PackageManager.PERMISSION_GRANTED; |
| 880 | } |
| 881 | |
| 882 | private boolean isBatteryTooLowForEmergencyLocation() { |
| 883 | Intent batteryStatus = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 884 | context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 885 | int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1); |
| 886 | if (status == BatteryManager.BATTERY_STATUS_CHARGING |
| 887 | || status == BatteryManager.BATTERY_STATUS_FULL) { |
| 888 | // Plugged in or full battery |
| 889 | return false; |
| 890 | } |
| 891 | int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); |
| 892 | int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1); |
| 893 | float batteryPercent = (100f * level) / scale; |
| 894 | long threshold = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 895 | ConfigProviderBindings.get(context) |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 896 | .getLong( |
| 897 | CONFIG_MIN_BATTERY_PERCENT_FOR_EMERGENCY_LOCATION, |
| 898 | CONFIG_MIN_BATTERY_PERCENT_FOR_EMERGENCY_LOCATION_DEFAULT); |
| 899 | LogUtil.i( |
| 900 | "CallCardPresenter.isBatteryTooLowForEmergencyLocation", |
| 901 | "percent charged: " + batteryPercent + ", min required charge: " + threshold); |
| 902 | return batteryPercent < threshold; |
| 903 | } |
| 904 | |
| 905 | private void updateSecondaryDisplayInfo() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 906 | if (inCallScreen == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 907 | return; |
| 908 | } |
| 909 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 910 | if (secondary == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 911 | // Clear the secondary display info. |
Android Dialer | 9e335e2 | 2018-03-01 08:27:39 -0800 | [diff] [blame] | 912 | inCallScreen.setSecondary(SecondaryInfo.builder().setIsFullscreen(isFullscreen).build()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 913 | return; |
| 914 | } |
| 915 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 916 | if (secondary.isMergeInProcess()) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 917 | LogUtil.i( |
| 918 | "CallCardPresenter.updateSecondaryDisplayInfo", |
| 919 | "secondary call is merge in process, clearing info"); |
Android Dialer | 9e335e2 | 2018-03-01 08:27:39 -0800 | [diff] [blame] | 920 | inCallScreen.setSecondary(SecondaryInfo.builder().setIsFullscreen(isFullscreen).build()); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 921 | return; |
| 922 | } |
| 923 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 924 | if (secondary.isConferenceCall()) { |
| 925 | inCallScreen.setSecondary( |
Android Dialer | 9e335e2 | 2018-03-01 08:27:39 -0800 | [diff] [blame] | 926 | SecondaryInfo.builder() |
| 927 | .setShouldShow(true) |
| 928 | .setName( |
| 929 | CallerInfoUtils.getConferenceString( |
| 930 | context, secondary.hasProperty(Details.PROPERTY_GENERIC_CONFERENCE))) |
| 931 | .setProviderLabel(secondary.getCallProviderLabel()) |
| 932 | .setIsConference(true) |
| 933 | .setIsVideoCall(secondary.isVideoCall()) |
| 934 | .setIsFullscreen(isFullscreen) |
| 935 | .build()); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 936 | } else if (secondaryContactInfo != null) { |
| 937 | LogUtil.v("CallCardPresenter.updateSecondaryDisplayInfo", "" + secondaryContactInfo); |
| 938 | String name = getNameForCall(secondaryContactInfo); |
| 939 | boolean nameIsNumber = name != null && name.equals(secondaryContactInfo.number); |
| 940 | inCallScreen.setSecondary( |
Android Dialer | 9e335e2 | 2018-03-01 08:27:39 -0800 | [diff] [blame] | 941 | SecondaryInfo.builder() |
| 942 | .setShouldShow(true) |
| 943 | .setName(secondary.updateNameIfRestricted(name)) |
| 944 | .setNameIsNumber(nameIsNumber) |
| 945 | .setLabel(secondaryContactInfo.label) |
| 946 | .setProviderLabel(secondary.getCallProviderLabel()) |
| 947 | .setIsVideoCall(secondary.isVideoCall()) |
| 948 | .setIsFullscreen(isFullscreen) |
| 949 | .build()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 950 | } else { |
| 951 | // Clear the secondary display info. |
Android Dialer | 9e335e2 | 2018-03-01 08:27:39 -0800 | [diff] [blame] | 952 | inCallScreen.setSecondary(SecondaryInfo.builder().setIsFullscreen(isFullscreen).build()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 953 | } |
| 954 | } |
| 955 | |
| 956 | /** Returns the gateway number for any existing outgoing call. */ |
| 957 | private String getGatewayNumber() { |
| 958 | if (hasOutgoingGatewayCall()) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 959 | return DialerCall.getNumberFromHandle(primary.getGatewayInfo().getGatewayAddress()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 960 | } |
| 961 | return null; |
| 962 | } |
| 963 | |
| 964 | /** |
| 965 | * Returns the label (line of text above the number/name) for any given call. For example, |
| 966 | * "calling via [Account/Google Voice]" for outgoing calls. |
| 967 | */ |
| 968 | private String getConnectionLabel() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 969 | if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 970 | != PackageManager.PERMISSION_GRANTED) { |
| 971 | return null; |
| 972 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 973 | StatusHints statusHints = primary.getStatusHints(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 974 | if (statusHints != null && !TextUtils.isEmpty(statusHints.getLabel())) { |
| 975 | return statusHints.getLabel().toString(); |
| 976 | } |
| 977 | |
| 978 | if (hasOutgoingGatewayCall() && getUi() != null) { |
| 979 | // Return the label for the gateway app on outgoing calls. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 980 | final PackageManager pm = context.getPackageManager(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 981 | try { |
| 982 | ApplicationInfo info = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 983 | pm.getApplicationInfo(primary.getGatewayInfo().getGatewayProviderPackageName(), 0); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 984 | return pm.getApplicationLabel(info).toString(); |
| 985 | } catch (PackageManager.NameNotFoundException e) { |
| 986 | LogUtil.e("CallCardPresenter.getConnectionLabel", "gateway Application Not Found.", e); |
| 987 | return null; |
| 988 | } |
| 989 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 990 | return primary.getCallProviderLabel(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 991 | } |
| 992 | |
twyen | 4fde0ac | 2018-03-22 18:04:23 -0700 | [diff] [blame^] | 993 | @Nullable |
| 994 | private SuggestionProvider.Reason getSimSuggestionReason() { |
| 995 | String value = |
| 996 | primary.getIntentExtras().getString(SuggestionProvider.EXTRA_SIM_SUGGESTION_REASON); |
| 997 | if (value == null) { |
| 998 | return null; |
| 999 | } |
| 1000 | try { |
| 1001 | return SuggestionProvider.Reason.valueOf(value); |
| 1002 | } catch (IllegalArgumentException e) { |
| 1003 | LogUtil.e("CallCardPresenter.getConnectionLabel", "unknown reason " + value); |
| 1004 | return null; |
| 1005 | } |
| 1006 | } |
| 1007 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1008 | private Drawable getCallStateIcon() { |
| 1009 | // Return connection icon if one exists. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1010 | StatusHints statusHints = primary.getStatusHints(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1011 | if (statusHints != null && statusHints.getIcon() != null) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1012 | Drawable icon = statusHints.getIcon().loadDrawable(context); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1013 | if (icon != null) { |
| 1014 | return icon; |
| 1015 | } |
| 1016 | } |
| 1017 | |
| 1018 | return null; |
| 1019 | } |
| 1020 | |
| 1021 | private boolean hasOutgoingGatewayCall() { |
| 1022 | // We only display the gateway information while STATE_DIALING so return false for any other |
| 1023 | // call state. |
| 1024 | // TODO: mPrimary can be null because this is called from updatePrimaryDisplayInfo which |
| 1025 | // is also called after a contact search completes (call is not present yet). Split the |
| 1026 | // UI update so it can receive independent updates. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1027 | if (primary == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1028 | return false; |
| 1029 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1030 | return DialerCall.State.isDialing(primary.getState()) |
| 1031 | && primary.getGatewayInfo() != null |
| 1032 | && !primary.getGatewayInfo().isEmpty(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | /** Gets the name to display for the call. */ |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1036 | private String getNameForCall(ContactCacheEntry contactInfo) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1037 | String preferredName = |
| 1038 | ContactDisplayUtils.getPreferredDisplayName( |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1039 | contactInfo.namePrimary, contactInfo.nameAlternative, contactsPreferences); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1040 | if (TextUtils.isEmpty(preferredName)) { |
| 1041 | return contactInfo.number; |
| 1042 | } |
| 1043 | return preferredName; |
| 1044 | } |
| 1045 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1046 | @Override |
| 1047 | public void onSecondaryInfoClicked() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1048 | if (secondary == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1049 | LogUtil.e( |
| 1050 | "CallCardPresenter.onSecondaryInfoClicked", |
| 1051 | "secondary info clicked but no secondary call."); |
| 1052 | return; |
| 1053 | } |
| 1054 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1055 | Logger.get(context) |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1056 | .logCallImpression( |
| 1057 | DialerImpression.Type.IN_CALL_SWAP_SECONDARY_BUTTON_PRESSED, |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1058 | primary.getUniqueCallId(), |
| 1059 | primary.getTimeAddedMs()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1060 | LogUtil.i( |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1061 | "CallCardPresenter.onSecondaryInfoClicked", "swapping call to foreground: " + secondary); |
| 1062 | secondary.unhold(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | @Override |
| 1066 | public void onEndCallClicked() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1067 | LogUtil.i("CallCardPresenter.onEndCallClicked", "disconnecting call: " + primary); |
| 1068 | if (primary != null) { |
| 1069 | primary.disconnect(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1070 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1071 | PostCall.onDisconnectPressed(context); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | /** |
| 1075 | * Handles a change to the fullscreen mode of the in-call UI. |
| 1076 | * |
| 1077 | * @param isFullscreenMode {@code True} if the in-call UI is entering full screen mode. |
| 1078 | */ |
| 1079 | @Override |
| 1080 | public void onFullscreenModeChanged(boolean isFullscreenMode) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1081 | isFullscreen = isFullscreenMode; |
| 1082 | if (inCallScreen == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1083 | return; |
| 1084 | } |
| 1085 | maybeShowManageConferenceCallButton(); |
| 1086 | } |
| 1087 | |
| 1088 | private boolean isPrimaryCallActive() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1089 | return primary != null && primary.getState() == DialerCall.State.ACTIVE; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1090 | } |
| 1091 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1092 | private boolean shouldShowEndCallButton(DialerCall primary, int callState) { |
| 1093 | if (primary == null) { |
| 1094 | return false; |
| 1095 | } |
| 1096 | if ((!DialerCall.State.isConnectingOrConnected(callState) |
| 1097 | && callState != DialerCall.State.DISCONNECTING |
| 1098 | && callState != DialerCall.State.DISCONNECTED) |
| 1099 | || callState == DialerCall.State.INCOMING) { |
| 1100 | return false; |
| 1101 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1102 | if (this.primary.getVideoTech().getSessionModificationState() |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 1103 | == SessionModificationState.RECEIVED_UPGRADE_TO_VIDEO_REQUEST) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1104 | return false; |
| 1105 | } |
| 1106 | return true; |
| 1107 | } |
| 1108 | |
| 1109 | @Override |
| 1110 | public void onInCallScreenResumed() { |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 1111 | updatePrimaryDisplayInfo(); |
| 1112 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1113 | if (shouldSendAccessibilityEvent) { |
| 1114 | handler.postDelayed(sendAccessibilityEventRunnable, ACCESSIBILITY_ANNOUNCEMENT_DELAY_MILLIS); |
| 1115 | } |
| 1116 | } |
| 1117 | |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 1118 | @Override |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1119 | public void onInCallScreenPaused() {} |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 1120 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1121 | static boolean sendAccessibilityEvent(Context context, InCallScreen inCallScreen) { |
| 1122 | AccessibilityManager am = |
| 1123 | (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE); |
| 1124 | if (!am.isEnabled()) { |
| 1125 | LogUtil.w("CallCardPresenter.sendAccessibilityEvent", "accessibility is off"); |
| 1126 | return false; |
| 1127 | } |
| 1128 | if (inCallScreen == null) { |
| 1129 | LogUtil.w("CallCardPresenter.sendAccessibilityEvent", "incallscreen is null"); |
| 1130 | return false; |
| 1131 | } |
| 1132 | Fragment fragment = inCallScreen.getInCallScreenFragment(); |
| 1133 | if (fragment == null || fragment.getView() == null || fragment.getView().getParent() == null) { |
| 1134 | LogUtil.w("CallCardPresenter.sendAccessibilityEvent", "fragment/view/parent is null"); |
| 1135 | return false; |
| 1136 | } |
| 1137 | |
| 1138 | DisplayManager displayManager = |
| 1139 | (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE); |
| 1140 | Display display = displayManager.getDisplay(Display.DEFAULT_DISPLAY); |
| 1141 | boolean screenIsOn = display.getState() == Display.STATE_ON; |
| 1142 | LogUtil.d("CallCardPresenter.sendAccessibilityEvent", "screen is on: %b", screenIsOn); |
| 1143 | if (!screenIsOn) { |
| 1144 | return false; |
| 1145 | } |
| 1146 | |
| 1147 | AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_ANNOUNCEMENT); |
| 1148 | inCallScreen.dispatchPopulateAccessibilityEvent(event); |
| 1149 | View view = inCallScreen.getInCallScreenFragment().getView(); |
| 1150 | view.getParent().requestSendAccessibilityEvent(view, event); |
| 1151 | return true; |
| 1152 | } |
| 1153 | |
| 1154 | private void maybeSendAccessibilityEvent( |
| 1155 | InCallState oldState, final InCallState newState, boolean primaryChanged) { |
| 1156 | shouldSendAccessibilityEvent = false; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1157 | if (context == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1158 | return; |
| 1159 | } |
| 1160 | final AccessibilityManager am = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1161 | (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1162 | if (!am.isEnabled()) { |
| 1163 | return; |
| 1164 | } |
| 1165 | // Announce the current call if it's new incoming/outgoing call or primary call is changed |
| 1166 | // due to switching calls between two ongoing calls (one is on hold). |
| 1167 | if ((oldState != InCallState.OUTGOING && newState == InCallState.OUTGOING) |
| 1168 | || (oldState != InCallState.INCOMING && newState == InCallState.INCOMING) |
| 1169 | || primaryChanged) { |
| 1170 | LogUtil.i( |
| 1171 | "CallCardPresenter.maybeSendAccessibilityEvent", "schedule accessibility announcement"); |
| 1172 | shouldSendAccessibilityEvent = true; |
| 1173 | handler.postDelayed(sendAccessibilityEventRunnable, ACCESSIBILITY_ANNOUNCEMENT_DELAY_MILLIS); |
| 1174 | } |
| 1175 | } |
| 1176 | |
| 1177 | /** |
| 1178 | * Determines whether the call subject should be visible on the UI. For the call subject to be |
| 1179 | * visible, the call has to be in an incoming or waiting state, and the subject must not be empty. |
| 1180 | * |
| 1181 | * @param call The call. |
| 1182 | * @return {@code true} if the subject should be shown, {@code false} otherwise. |
| 1183 | */ |
| 1184 | private boolean shouldShowCallSubject(DialerCall call) { |
| 1185 | if (call == null) { |
| 1186 | return false; |
| 1187 | } |
| 1188 | |
| 1189 | boolean isIncomingOrWaiting = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1190 | primary.getState() == DialerCall.State.INCOMING |
| 1191 | || primary.getState() == DialerCall.State.CALL_WAITING; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1192 | return isIncomingOrWaiting |
| 1193 | && !TextUtils.isEmpty(call.getCallSubject()) |
| 1194 | && call.getNumberPresentation() == TelecomManager.PRESENTATION_ALLOWED |
| 1195 | && call.isCallSubjectSupported(); |
| 1196 | } |
| 1197 | |
| 1198 | /** |
| 1199 | * Determines whether the "note sent" toast should be shown. It should be shown for a new outgoing |
| 1200 | * call with a subject. |
| 1201 | * |
| 1202 | * @param call The call |
| 1203 | * @return {@code true} if the toast should be shown, {@code false} otherwise. |
| 1204 | */ |
| 1205 | private boolean shouldShowNoteSentToast(DialerCall call) { |
| 1206 | return call != null |
| 1207 | && hasCallSubject(call) |
| 1208 | && (call.getState() == DialerCall.State.DIALING |
| 1209 | || call.getState() == DialerCall.State.CONNECTING); |
| 1210 | } |
| 1211 | |
| 1212 | private InCallScreen getUi() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1213 | return inCallScreen; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1214 | } |
| 1215 | |
Android Dialer | f943910 | 2018-02-21 08:05:14 -0800 | [diff] [blame] | 1216 | /** Callback for contact lookup. */ |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1217 | public static class ContactLookupCallback implements ContactInfoCacheCallback { |
| 1218 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1219 | private final WeakReference<CallCardPresenter> callCardPresenter; |
| 1220 | private final boolean isPrimary; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1221 | |
| 1222 | public ContactLookupCallback(CallCardPresenter callCardPresenter, boolean isPrimary) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1223 | this.callCardPresenter = new WeakReference<CallCardPresenter>(callCardPresenter); |
| 1224 | this.isPrimary = isPrimary; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | @Override |
| 1228 | public void onContactInfoComplete(String callId, ContactCacheEntry entry) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1229 | CallCardPresenter presenter = callCardPresenter.get(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1230 | if (presenter != null) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1231 | presenter.onContactInfoComplete(callId, entry, isPrimary); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1232 | } |
| 1233 | } |
| 1234 | |
| 1235 | @Override |
| 1236 | public void onImageLoadComplete(String callId, ContactCacheEntry entry) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1237 | CallCardPresenter presenter = callCardPresenter.get(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1238 | if (presenter != null) { |
| 1239 | presenter.onImageLoadComplete(callId, entry); |
| 1240 | } |
| 1241 | } |
| 1242 | } |
| 1243 | } |