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