This repository has been archived by the owner on Nov 8, 2023. It is now read-only.
/
CallCard.java
1783 lines (1567 loc) · 79.9 KB
/
CallCard.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2006 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.phone;
import android.animation.LayoutTransition;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.provider.ContactsContract.Contacts;
import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.view.accessibility.AccessibilityEvent;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.android.internal.telephony.Call;
import com.android.internal.telephony.CallManager;
import com.android.internal.telephony.CallerInfo;
import com.android.internal.telephony.CallerInfoAsyncQuery;
import com.android.internal.telephony.Connection;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneConstants;
import java.util.List;
/**
* "Call card" UI element: the in-call screen contains a tiled layout of call
* cards, each representing the state of a current "call" (ie. an active call,
* a call on hold, or an incoming call.)
*/
public class CallCard extends LinearLayout
implements CallTime.OnTickListener, CallerInfoAsyncQuery.OnQueryCompleteListener,
ContactsAsyncHelper.OnImageLoadCompleteListener {
private static final String LOG_TAG = "CallCard";
private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
private static final int TOKEN_UPDATE_PHOTO_FOR_CALL_STATE = 0;
private static final int TOKEN_DO_NOTHING = 1;
/**
* Used with {@link ContactsAsyncHelper#startObtainPhotoAsync(int, Context, Uri,
* ContactsAsyncHelper.OnImageLoadCompleteListener, Object)}
*/
private static class AsyncLoadCookie {
public final ImageView imageView;
public final CallerInfo callerInfo;
public final Call call;
public AsyncLoadCookie(ImageView imageView, CallerInfo callerInfo, Call call) {
this.imageView = imageView;
this.callerInfo = callerInfo;
this.call = call;
}
}
/**
* Reference to the InCallScreen activity that owns us. This may be
* null if we haven't been initialized yet *or* after the InCallScreen
* activity has been destroyed.
*/
private InCallScreen mInCallScreen;
// Phone app instance
private PhoneGlobals mApplication;
// Top-level subviews of the CallCard
/** Container for info about the current call(s) */
private ViewGroup mCallInfoContainer;
/** Primary "call info" block (the foreground or ringing call) */
private ViewGroup mPrimaryCallInfo;
/** "Call banner" for the primary call */
private ViewGroup mPrimaryCallBanner;
/** Secondary "call info" block (the background "on hold" call) */
private ViewStub mSecondaryCallInfo;
/**
* Container for both provider info and call state. This will take care of showing/hiding
* animation for those views.
*/
private ViewGroup mSecondaryInfoContainer;
private ViewGroup mProviderInfo;
private TextView mProviderLabel;
private TextView mProviderAddress;
// "Call state" widgets
private TextView mCallStateLabel;
private TextView mElapsedTime;
// Text colors, used for various labels / titles
private int mTextColorCallTypeSip;
// The main block of info about the "primary" or "active" call,
// including photo / name / phone number / etc.
private ImageView mPhoto;
private View mPhotoDimEffect;
private TextView mName;
private TextView mPhoneNumber;
private TextView mLabel;
private TextView mCallTypeLabel;
// private TextView mSocialStatus;
/**
* Uri being used to load contact photo for mPhoto. Will be null when nothing is being loaded,
* or a photo is already loaded.
*/
private Uri mLoadingPersonUri;
// Info about the "secondary" call, which is the "call on hold" when
// two lines are in use.
private TextView mSecondaryCallName;
private ImageView mSecondaryCallPhoto;
private View mSecondaryCallPhotoDimEffect;
// Onscreen hint for the incoming call RotarySelector widget.
private int mIncomingCallWidgetHintTextResId;
private int mIncomingCallWidgetHintColorResId;
private CallTime mCallTime;
// Track the state for the photo.
private ContactsAsyncHelper.ImageTracker mPhotoTracker;
// Cached DisplayMetrics density.
private float mDensity;
/**
* Sent when it takes too long (MESSAGE_DELAY msec) to load a contact photo for the given
* person, at which we just start showing the default avatar picture instead of the person's
* one. Note that we will *not* cancel the ongoing query and eventually replace the avatar
* with the person's photo, when it is available anyway.
*/
private static final int MESSAGE_SHOW_UNKNOWN_PHOTO = 101;
private static final int MESSAGE_DELAY = 500; // msec
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MESSAGE_SHOW_UNKNOWN_PHOTO:
showImage(mPhoto, R.drawable.picture_unknown);
break;
default:
Log.wtf(LOG_TAG, "mHandler: unexpected message: " + msg);
break;
}
}
};
public CallCard(Context context, AttributeSet attrs) {
super(context, attrs);
if (DBG) log("CallCard constructor...");
if (DBG) log("- this = " + this);
if (DBG) log("- context " + context + ", attrs " + attrs);
mApplication = PhoneGlobals.getInstance();
mCallTime = new CallTime(this);
// create a new object to track the state for the photo.
mPhotoTracker = new ContactsAsyncHelper.ImageTracker();
mDensity = getResources().getDisplayMetrics().density;
if (DBG) log("- Density: " + mDensity);
}
/* package */ void setInCallScreenInstance(InCallScreen inCallScreen) {
mInCallScreen = inCallScreen;
}
@Override
public void onTickForCallTimeElapsed(long timeElapsed) {
// While a call is in progress, update the elapsed time shown
// onscreen.
updateElapsedTimeWidget(timeElapsed);
}
/* package */ void stopTimer() {
mCallTime.cancelTimer();
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
if (DBG) log("CallCard onFinishInflate(this = " + this + ")...");
mCallInfoContainer = (ViewGroup) findViewById(R.id.call_info_container);
mPrimaryCallInfo = (ViewGroup) findViewById(R.id.primary_call_info);
mPrimaryCallBanner = (ViewGroup) findViewById(R.id.primary_call_banner);
mSecondaryInfoContainer = (ViewGroup) findViewById(R.id.secondary_info_container);
mProviderInfo = (ViewGroup) findViewById(R.id.providerInfo);
mProviderLabel = (TextView) findViewById(R.id.providerLabel);
mProviderAddress = (TextView) findViewById(R.id.providerAddress);
mCallStateLabel = (TextView) findViewById(R.id.callStateLabel);
mElapsedTime = (TextView) findViewById(R.id.elapsedTime);
// Text colors
mTextColorCallTypeSip = getResources().getColor(R.color.incall_callTypeSip);
// "Caller info" area, including photo / name / phone numbers / etc
mPhoto = (ImageView) findViewById(R.id.photo);
mPhotoDimEffect = findViewById(R.id.dim_effect_for_primary_photo);
mName = (TextView) findViewById(R.id.name);
mPhoneNumber = (TextView) findViewById(R.id.phoneNumber);
mLabel = (TextView) findViewById(R.id.label);
mCallTypeLabel = (TextView) findViewById(R.id.callTypeLabel);
// mSocialStatus = (TextView) findViewById(R.id.socialStatus);
// Secondary info area, for the background ("on hold") call
mSecondaryCallInfo = (ViewStub) findViewById(R.id.secondary_call_info);
}
/**
* Updates the state of all UI elements on the CallCard, based on the
* current state of the phone.
*/
/* package */ void updateState(CallManager cm) {
if (DBG) log("updateState(" + cm + ")...");
// Update the onscreen UI based on the current state of the phone.
PhoneConstants.State state = cm.getState(); // IDLE, RINGING, or OFFHOOK
Call ringingCall = cm.getFirstActiveRingingCall();
Call fgCall = cm.getActiveFgCall();
Call bgCall = cm.getFirstActiveBgCall();
// Update the overall layout of the onscreen elements, if in PORTRAIT.
// Portrait uses a programatically altered layout, whereas landscape uses layout xml's.
// Landscape view has the views side by side, so no shifting of the picture is needed
if (!PhoneUtils.isLandscape(this.getContext())) {
updateCallInfoLayout(state);
}
// If the FG call is dialing/alerting, we should display for that call
// and ignore the ringing call. This case happens when the telephony
// layer rejects the ringing call while the FG call is dialing/alerting,
// but the incoming call *does* briefly exist in the DISCONNECTING or
// DISCONNECTED state.
if ((ringingCall.getState() != Call.State.IDLE)
&& !fgCall.getState().isDialing()) {
// A phone call is ringing, call waiting *or* being rejected
// (ie. another call may also be active as well.)
updateRingingCall(cm);
} else if ((fgCall.getState() != Call.State.IDLE)
|| (bgCall.getState() != Call.State.IDLE)) {
// We are here because either:
// (1) the phone is off hook. At least one call exists that is
// dialing, active, or holding, and no calls are ringing or waiting,
// or:
// (2) the phone is IDLE but a call just ended and it's still in
// the DISCONNECTING or DISCONNECTED state. In this case, we want
// the main CallCard to display "Hanging up" or "Call ended".
// The normal "foreground call" code path handles both cases.
updateForegroundCall(cm);
} else {
// We don't have any DISCONNECTED calls, which means that the phone
// is *truly* idle.
if (mApplication.inCallUiState.showAlreadyDisconnectedState) {
// showAlreadyDisconnectedState implies the phone call is disconnected
// and we want to show the disconnected phone call for a moment.
//
// This happens when a phone call ends while the screen is off,
// which means the user had no chance to see the last status of
// the call. We'll turn off showAlreadyDisconnectedState flag
// and bail out of the in-call screen soon.
updateAlreadyDisconnected(cm);
} else {
// It's very rare to be on the InCallScreen at all in this
// state, but it can happen in some cases:
// - A stray onPhoneStateChanged() event came in to the
// InCallScreen *after* it was dismissed.
// - We're allowed to be on the InCallScreen because
// an MMI or USSD is running, but there's no actual "call"
// to display.
// - We're displaying an error dialog to the user
// (explaining why the call failed), so we need to stay on
// the InCallScreen so that the dialog will be visible.
//
// In these cases, put the callcard into a sane but "blank" state:
updateNoCall(cm);
}
}
}
/**
* Updates the overall size and positioning of mCallInfoContainer and
* the "Call info" blocks, based on the phone state.
*/
private void updateCallInfoLayout(PhoneConstants.State state) {
boolean ringing = (state == PhoneConstants.State.RINGING);
if (DBG) log("updateCallInfoLayout()... ringing = " + ringing);
// Based on the current state, update the overall
// CallCard layout:
// - Update the bottom margin of mCallInfoContainer to make sure
// the call info area won't overlap with the touchable
// controls on the bottom part of the screen.
int reservedVerticalSpace = mInCallScreen.getInCallTouchUi().getTouchUiHeight();
ViewGroup.MarginLayoutParams callInfoLp =
(ViewGroup.MarginLayoutParams) mCallInfoContainer.getLayoutParams();
callInfoLp.bottomMargin = reservedVerticalSpace; // Equivalent to setting
// android:layout_marginBottom in XML
if (DBG) log(" ==> callInfoLp.bottomMargin: " + reservedVerticalSpace);
mCallInfoContainer.setLayoutParams(callInfoLp);
}
/**
* Updates the UI for the state where the phone is in use, but not ringing.
*/
private void updateForegroundCall(CallManager cm) {
if (DBG) log("updateForegroundCall()...");
// if (DBG) PhoneUtils.dumpCallManager();
Call fgCall = cm.getActiveFgCall();
Call bgCall = cm.getFirstActiveBgCall();
if (fgCall.getState() == Call.State.IDLE) {
if (DBG) log("updateForegroundCall: no active call, show holding call");
// TODO: make sure this case agrees with the latest UI spec.
// Display the background call in the main info area of the
// CallCard, since there is no foreground call. Note that
// displayMainCallStatus() will notice if the call we passed in is on
// hold, and display the "on hold" indication.
fgCall = bgCall;
// And be sure to not display anything in the "on hold" box.
bgCall = null;
}
displayMainCallStatus(cm, fgCall);
Phone phone = fgCall.getPhone();
int phoneType = phone.getPhoneType();
if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
if ((mApplication.cdmaPhoneCallState.getCurrentCallState()
== CdmaPhoneCallState.PhoneCallState.THRWAY_ACTIVE)
&& mApplication.cdmaPhoneCallState.IsThreeWayCallOrigStateDialing()) {
displaySecondaryCallStatus(cm, fgCall);
} else {
//This is required so that even if a background call is not present
// we need to clean up the background call area.
displaySecondaryCallStatus(cm, bgCall);
}
} else if ((phoneType == PhoneConstants.PHONE_TYPE_GSM)
|| (phoneType == PhoneConstants.PHONE_TYPE_SIP)) {
displaySecondaryCallStatus(cm, bgCall);
}
}
/**
* Updates the UI for the state where an incoming call is ringing (or
* call waiting), regardless of whether the phone's already offhook.
*/
private void updateRingingCall(CallManager cm) {
if (DBG) log("updateRingingCall()...");
Call ringingCall = cm.getFirstActiveRingingCall();
// Display caller-id info and photo from the incoming call:
displayMainCallStatus(cm, ringingCall);
// And even in the Call Waiting case, *don't* show any info about
// the current ongoing call and/or the current call on hold.
// (Since the caller-id info for the incoming call totally trumps
// any info about the current call(s) in progress.)
displaySecondaryCallStatus(cm, null);
}
/**
* Updates the UI for the state where an incoming call is just disconnected while we want to
* show the screen for a moment.
*
* This case happens when the whole in-call screen is in background when phone calls are hanged
* up, which means there's no way to determine which call was the last call finished. Right now
* this method simply shows the previous primary call status with a photo, closing the
* secondary call status. In most cases (including conference call or misc call happening in
* CDMA) this behaves right.
*
* If there were two phone calls both of which were hung up but the primary call was the
* first, this would behave a bit odd (since the first one still appears as the
* "last disconnected").
*/
private void updateAlreadyDisconnected(CallManager cm) {
// For the foreground call, we manually set up every component based on previous state.
mPrimaryCallInfo.setVisibility(View.VISIBLE);
mSecondaryInfoContainer.setLayoutTransition(null);
mProviderInfo.setVisibility(View.GONE);
mCallStateLabel.setVisibility(View.VISIBLE);
mCallStateLabel.setText(mContext.getString(R.string.card_title_call_ended));
mElapsedTime.setVisibility(View.VISIBLE);
mCallTime.cancelTimer();
// Just hide it.
displaySecondaryCallStatus(cm, null);
}
/**
* Updates the UI for the state where the phone is not in use.
* This is analogous to updateForegroundCall() and updateRingingCall(),
* but for the (uncommon) case where the phone is
* totally idle. (See comments in updateState() above.)
*
* This puts the callcard into a sane but "blank" state.
*/
private void updateNoCall(CallManager cm) {
if (DBG) log("updateNoCall()...");
displayMainCallStatus(cm, null);
displaySecondaryCallStatus(cm, null);
}
/**
* Updates the main block of caller info on the CallCard
* (ie. the stuff in the primaryCallInfo block) based on the specified Call.
*/
private void displayMainCallStatus(CallManager cm, Call call) {
if (DBG) log("displayMainCallStatus(call " + call + ")...");
if (call == null) {
// There's no call to display, presumably because the phone is idle.
mPrimaryCallInfo.setVisibility(View.GONE);
return;
}
mPrimaryCallInfo.setVisibility(View.VISIBLE);
Call.State state = call.getState();
if (DBG) log(" - call.state: " + call.getState());
switch (state) {
case ACTIVE:
case DISCONNECTING:
// update timer field
if (DBG) log("displayMainCallStatus: start periodicUpdateTimer");
mCallTime.setActiveCallMode(call);
mCallTime.reset();
mCallTime.periodicUpdateTimer();
break;
case HOLDING:
// update timer field
mCallTime.cancelTimer();
break;
case DISCONNECTED:
// Stop getting timer ticks from this call
mCallTime.cancelTimer();
break;
case DIALING:
case ALERTING:
// Stop getting timer ticks from a previous call
mCallTime.cancelTimer();
break;
case INCOMING:
case WAITING:
// Stop getting timer ticks from a previous call
mCallTime.cancelTimer();
break;
case IDLE:
// The "main CallCard" should never be trying to display
// an idle call! In updateState(), if the phone is idle,
// we call updateNoCall(), which means that we shouldn't
// have passed a call into this method at all.
Log.w(LOG_TAG, "displayMainCallStatus: IDLE call in the main call card!");
// (It is possible, though, that we had a valid call which
// became idle *after* the check in updateState() but
// before we get here... So continue the best we can,
// with whatever (stale) info we can get from the
// passed-in Call object.)
break;
default:
Log.w(LOG_TAG, "displayMainCallStatus: unexpected call state: " + state);
break;
}
updateCallStateWidgets(call);
if (PhoneUtils.isConferenceCall(call)) {
// Update onscreen info for a conference call.
updateDisplayForConference(call);
} else {
// Update onscreen info for a regular call (which presumably
// has only one connection.)
Connection conn = null;
int phoneType = call.getPhone().getPhoneType();
if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
conn = call.getLatestConnection();
} else if ((phoneType == PhoneConstants.PHONE_TYPE_GSM)
|| (phoneType == PhoneConstants.PHONE_TYPE_SIP)) {
conn = call.getEarliestConnection();
} else {
throw new IllegalStateException("Unexpected phone type: " + phoneType);
}
if (conn == null) {
if (DBG) log("displayMainCallStatus: connection is null, using default values.");
// if the connection is null, we run through the behaviour
// we had in the past, which breaks down into trivial steps
// with the current implementation of getCallerInfo and
// updateDisplayForPerson.
CallerInfo info = PhoneUtils.getCallerInfo(getContext(), null /* conn */);
updateDisplayForPerson(info, PhoneConstants.PRESENTATION_ALLOWED, false, call,
conn);
} else {
if (DBG) log(" - CONN: " + conn + ", state = " + conn.getState());
int presentation = conn.getNumberPresentation();
// make sure that we only make a new query when the current
// callerinfo differs from what we've been requested to display.
boolean runQuery = true;
Object o = conn.getUserData();
if (o instanceof PhoneUtils.CallerInfoToken) {
runQuery = mPhotoTracker.isDifferentImageRequest(
((PhoneUtils.CallerInfoToken) o).currentInfo);
} else {
runQuery = mPhotoTracker.isDifferentImageRequest(conn);
}
// Adding a check to see if the update was caused due to a Phone number update
// or CNAP update. If so then we need to start a new query
if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
Object obj = conn.getUserData();
String updatedNumber = conn.getAddress();
String updatedCnapName = conn.getCnapName();
CallerInfo info = null;
if (obj instanceof PhoneUtils.CallerInfoToken) {
info = ((PhoneUtils.CallerInfoToken) o).currentInfo;
} else if (o instanceof CallerInfo) {
info = (CallerInfo) o;
}
if (info != null) {
if (updatedNumber != null && !updatedNumber.equals(info.phoneNumber)) {
if (DBG) log("- displayMainCallStatus: updatedNumber = "
+ updatedNumber);
runQuery = true;
}
if (updatedCnapName != null && !updatedCnapName.equals(info.cnapName)) {
if (DBG) log("- displayMainCallStatus: updatedCnapName = "
+ updatedCnapName);
runQuery = true;
}
}
}
if (runQuery) {
if (DBG) log("- displayMainCallStatus: starting CallerInfo query...");
PhoneUtils.CallerInfoToken info =
PhoneUtils.startGetCallerInfo(getContext(), conn, this, call);
updateDisplayForPerson(info.currentInfo, presentation, !info.isFinal,
call, conn);
} else {
// No need to fire off a new query. We do still need
// to update the display, though (since we might have
// previously been in the "conference call" state.)
if (DBG) log("- displayMainCallStatus: using data we already have...");
if (o instanceof CallerInfo) {
CallerInfo ci = (CallerInfo) o;
// Update CNAP information if Phone state change occurred
ci.cnapName = conn.getCnapName();
ci.numberPresentation = conn.getNumberPresentation();
ci.namePresentation = conn.getCnapNamePresentation();
if (DBG) log("- displayMainCallStatus: CNAP data from Connection: "
+ "CNAP name=" + ci.cnapName
+ ", Number/Name Presentation=" + ci.numberPresentation);
if (DBG) log(" ==> Got CallerInfo; updating display: ci = " + ci);
updateDisplayForPerson(ci, presentation, false, call, conn);
} else if (o instanceof PhoneUtils.CallerInfoToken){
CallerInfo ci = ((PhoneUtils.CallerInfoToken) o).currentInfo;
if (DBG) log("- displayMainCallStatus: CNAP data from Connection: "
+ "CNAP name=" + ci.cnapName
+ ", Number/Name Presentation=" + ci.numberPresentation);
if (DBG) log(" ==> Got CallerInfoToken; updating display: ci = " + ci);
updateDisplayForPerson(ci, presentation, true, call, conn);
} else {
Log.w(LOG_TAG, "displayMainCallStatus: runQuery was false, "
+ "but we didn't have a cached CallerInfo object! o = " + o);
// TODO: any easy way to recover here (given that
// the CallCard is probably displaying stale info
// right now?) Maybe force the CallCard into the
// "Unknown" state?
}
}
}
}
// In some states we override the "photo" ImageView to be an
// indication of the current state, rather than displaying the
// regular photo as set above.
updatePhotoForCallState(call);
// One special feature of the "number" text field: For incoming
// calls, while the user is dragging the RotarySelector widget, we
// use mPhoneNumber to display a hint like "Rotate to answer".
if (mIncomingCallWidgetHintTextResId != 0) {
// Display the hint!
mPhoneNumber.setText(mIncomingCallWidgetHintTextResId);
mPhoneNumber.setTextColor(getResources().getColor(mIncomingCallWidgetHintColorResId));
mPhoneNumber.setVisibility(View.VISIBLE);
mLabel.setVisibility(View.GONE);
}
// If we don't have a hint to display, just don't touch
// mPhoneNumber and mLabel. (Their text / color / visibility have
// already been set correctly, by either updateDisplayForPerson()
// or updateDisplayForConference().)
}
/**
* Implemented for CallerInfoAsyncQuery.OnQueryCompleteListener interface.
* refreshes the CallCard data when it called.
*/
@Override
public void onQueryComplete(int token, Object cookie, CallerInfo ci) {
if (DBG) log("onQueryComplete: token " + token + ", cookie " + cookie + ", ci " + ci);
if (cookie instanceof Call) {
// grab the call object and update the display for an individual call,
// as well as the successive call to update image via call state.
// If the object is a textview instead, we update it as we need to.
if (DBG) log("callerinfo query complete, updating ui from displayMainCallStatus()");
Call call = (Call) cookie;
Connection conn = null;
int phoneType = call.getPhone().getPhoneType();
if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
conn = call.getLatestConnection();
} else if ((phoneType == PhoneConstants.PHONE_TYPE_GSM)
|| (phoneType == PhoneConstants.PHONE_TYPE_SIP)) {
conn = call.getEarliestConnection();
} else {
throw new IllegalStateException("Unexpected phone type: " + phoneType);
}
PhoneUtils.CallerInfoToken cit =
PhoneUtils.startGetCallerInfo(getContext(), conn, this, null);
int presentation = PhoneConstants.PRESENTATION_ALLOWED;
if (conn != null) presentation = conn.getNumberPresentation();
if (DBG) log("- onQueryComplete: presentation=" + presentation
+ ", contactExists=" + ci.contactExists);
// Depending on whether there was a contact match or not, we want to pass in different
// CallerInfo (for CNAP). Therefore if ci.contactExists then use the ci passed in.
// Otherwise, regenerate the CIT from the Connection and use the CallerInfo from there.
if (ci.contactExists) {
updateDisplayForPerson(ci, PhoneConstants.PRESENTATION_ALLOWED, false, call, conn);
} else {
updateDisplayForPerson(cit.currentInfo, presentation, false, call, conn);
}
updatePhotoForCallState(call);
} else if (cookie instanceof TextView){
if (DBG) log("callerinfo query complete, updating ui from ongoing or onhold");
((TextView) cookie).setText(PhoneUtils.getCompactNameFromCallerInfo(ci, mContext));
}
}
/**
* Implemented for ContactsAsyncHelper.OnImageLoadCompleteListener interface.
* make sure that the call state is reflected after the image is loaded.
*/
@Override
public void onImageLoadComplete(int token, Drawable photo, Bitmap photoIcon, Object cookie) {
mHandler.removeMessages(MESSAGE_SHOW_UNKNOWN_PHOTO);
if (mLoadingPersonUri != null) {
// Start sending view notification after the current request being done.
// New image may possibly be available from the next phone calls.
//
// TODO: may be nice to update the image view again once the newer one
// is available on contacts database.
PhoneUtils.sendViewNotificationAsync(mApplication, mLoadingPersonUri);
} else {
// This should not happen while we need some verbose info if it happens..
Log.w(LOG_TAG, "Person Uri isn't available while Image is successfully loaded.");
}
mLoadingPersonUri = null;
AsyncLoadCookie asyncLoadCookie = (AsyncLoadCookie) cookie;
CallerInfo callerInfo = asyncLoadCookie.callerInfo;
ImageView imageView = asyncLoadCookie.imageView;
Call call = asyncLoadCookie.call;
callerInfo.cachedPhoto = photo;
callerInfo.cachedPhotoIcon = photoIcon;
callerInfo.isCachedPhotoCurrent = true;
// Note: previously ContactsAsyncHelper has done this job.
// TODO: We will need fade-in animation. See issue 5236130.
if (photo != null) {
showImage(imageView, photo);
} else if (photoIcon != null) {
showImage(imageView, photoIcon);
} else {
showImage(imageView, R.drawable.picture_unknown);
}
if (token == TOKEN_UPDATE_PHOTO_FOR_CALL_STATE) {
updatePhotoForCallState(call);
}
}
/**
* Updates the "call state label" and the elapsed time widget based on the
* current state of the call.
*/
private void updateCallStateWidgets(Call call) {
if (DBG) log("updateCallStateWidgets(call " + call + ")...");
final Call.State state = call.getState();
final Context context = getContext();
final Phone phone = call.getPhone();
final int phoneType = phone.getPhoneType();
String callStateLabel = null; // Label to display as part of the call banner
int bluetoothIconId = 0; // Icon to display alongside the call state label
switch (state) {
case IDLE:
// "Call state" is meaningless in this state.
break;
case ACTIVE:
// We normally don't show a "call state label" at all in
// this state (but see below for some special cases).
break;
case HOLDING:
callStateLabel = context.getString(R.string.card_title_on_hold);
break;
case DIALING:
case ALERTING:
callStateLabel = context.getString(R.string.card_title_dialing);
break;
case INCOMING:
case WAITING:
callStateLabel = context.getString(R.string.card_title_incoming_call);
// Also, display a special icon (alongside the "Incoming call"
// label) if there's an incoming call and audio will be routed
// to bluetooth when you answer it.
if (mApplication.showBluetoothIndication()) {
bluetoothIconId = R.drawable.ic_incoming_call_bluetooth;
}
break;
case DISCONNECTING:
// While in the DISCONNECTING state we display a "Hanging up"
// message in order to make the UI feel more responsive. (In
// GSM it's normal to see a delay of a couple of seconds while
// negotiating the disconnect with the network, so the "Hanging
// up" state at least lets the user know that we're doing
// something. This state is currently not used with CDMA.)
callStateLabel = context.getString(R.string.card_title_hanging_up);
break;
case DISCONNECTED:
callStateLabel = getCallFailedString(call);
break;
default:
Log.wtf(LOG_TAG, "updateCallStateWidgets: unexpected call state: " + state);
break;
}
// Check a couple of other special cases (these are all CDMA-specific).
if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
if ((state == Call.State.ACTIVE)
&& mApplication.cdmaPhoneCallState.IsThreeWayCallOrigStateDialing()) {
// Display "Dialing" while dialing a 3Way call, even
// though the foreground call state is actually ACTIVE.
callStateLabel = context.getString(R.string.card_title_dialing);
} else if (PhoneGlobals.getInstance().notifier.getIsCdmaRedialCall()) {
callStateLabel = context.getString(R.string.card_title_redialing);
}
}
if (PhoneUtils.isPhoneInEcm(phone)) {
// In emergency callback mode (ECM), use a special label
// that shows your own phone number.
callStateLabel = getECMCardTitle(context, phone);
}
final InCallUiState inCallUiState = mApplication.inCallUiState;
if (DBG) {
log("==> callStateLabel: '" + callStateLabel
+ "', bluetoothIconId = " + bluetoothIconId
+ ", providerInfoVisible = " + inCallUiState.providerInfoVisible);
}
// Animation will be done by mCallerDetail's LayoutTransition, but in some cases, we don't
// want that.
// - DIALING: This is at the beginning of the phone call.
// - DISCONNECTING, DISCONNECTED: Screen will disappear soon; we have no time for animation.
final boolean skipAnimation = (state == Call.State.DIALING
|| state == Call.State.DISCONNECTING
|| state == Call.State.DISCONNECTED);
LayoutTransition layoutTransition = null;
if (skipAnimation) {
// Evict LayoutTransition object to skip animation.
layoutTransition = mSecondaryInfoContainer.getLayoutTransition();
mSecondaryInfoContainer.setLayoutTransition(null);
}
if (inCallUiState.providerInfoVisible) {
mProviderInfo.setVisibility(View.VISIBLE);
mProviderLabel.setText(context.getString(R.string.calling_via_template,
inCallUiState.providerLabel));
mProviderAddress.setText(inCallUiState.providerAddress);
mInCallScreen.requestRemoveProviderInfoWithDelay();
} else {
mProviderInfo.setVisibility(View.GONE);
}
if (!TextUtils.isEmpty(callStateLabel)) {
mCallStateLabel.setVisibility(View.VISIBLE);
mCallStateLabel.setText(callStateLabel);
// ...and display the icon too if necessary.
if (bluetoothIconId != 0) {
mCallStateLabel.setCompoundDrawablesWithIntrinsicBounds(bluetoothIconId, 0, 0, 0);
mCallStateLabel.setCompoundDrawablePadding((int) (mDensity * 5));
} else {
// Clear out any icons
mCallStateLabel.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
}
} else {
mCallStateLabel.setVisibility(View.GONE);
// Gravity is aligned left when receiving an incoming call in landscape.
// In that rare case, the gravity needs to be reset to the right.
// Also, setText("") is used since there is a delay in making the view GONE,
// so the user will otherwise see the text jump to the right side before disappearing.
if(mCallStateLabel.getGravity() != Gravity.RIGHT) {
mCallStateLabel.setText("");
mCallStateLabel.setGravity(Gravity.RIGHT);
}
}
if (skipAnimation) {
// Restore LayoutTransition object to recover animation.
mSecondaryInfoContainer.setLayoutTransition(layoutTransition);
}
// ...and update the elapsed time widget too.
switch (state) {
case ACTIVE:
case DISCONNECTING:
// Show the time with fade-in animation.
AnimationUtils.Fade.show(mElapsedTime);
updateElapsedTimeWidget(call);
break;
case DISCONNECTED:
// In the "Call ended" state, leave the mElapsedTime widget
// visible, but don't touch it (so we continue to see the
// elapsed time of the call that just ended.)
// Check visibility to keep possible fade-in animation.
if (mElapsedTime.getVisibility() != View.VISIBLE) {
mElapsedTime.setVisibility(View.VISIBLE);
}
break;
default:
// Call state here is IDLE, ACTIVE, HOLDING, DIALING, ALERTING,
// INCOMING, or WAITING.
// In all of these states, the "elapsed time" is meaningless, so
// don't show it.
AnimationUtils.Fade.hide(mElapsedTime, View.INVISIBLE);
// Additionally, in call states that can only occur at the start
// of a call, reset the elapsed time to be sure we won't display
// stale info later (like if we somehow go straight from DIALING
// or ALERTING to DISCONNECTED, which can actually happen in
// some failure cases like "line busy").
if ((state == Call.State.DIALING) || (state == Call.State.ALERTING)) {
updateElapsedTimeWidget(0);
}
break;
}
}
/**
* Updates mElapsedTime based on the given {@link Call} object's information.
*
* @see CallTime#getCallDuration(Call)
* @see Connection#getDurationMillis()
*/
/* package */ void updateElapsedTimeWidget(Call call) {
long duration = CallTime.getCallDuration(call); // msec
updateElapsedTimeWidget(duration / 1000);
// Also see onTickForCallTimeElapsed(), which updates this
// widget once per second while the call is active.
}
/**
* Updates mElapsedTime based on the specified number of seconds.
*/
private void updateElapsedTimeWidget(long timeElapsed) {
// if (DBG) log("updateElapsedTimeWidget: " + timeElapsed);
mElapsedTime.setText(DateUtils.formatElapsedTime(timeElapsed));
}
/**
* Updates the "on hold" box in the "other call" info area
* (ie. the stuff in the secondaryCallInfo block)
* based on the specified Call.
* Or, clear out the "on hold" box if the specified call
* is null or idle.
*/
private void displaySecondaryCallStatus(CallManager cm, Call call) {
if (DBG) log("displayOnHoldCallStatus(call =" + call + ")...");
if ((call == null) || (PhoneGlobals.getInstance().isOtaCallInActiveState())) {
mSecondaryCallInfo.setVisibility(View.GONE);
return;
}
Call.State state = call.getState();
switch (state) {
case HOLDING:
// Ok, there actually is a background call on hold.
// Display the "on hold" box.
// Note this case occurs only on GSM devices. (On CDMA,
// the "call on hold" is actually the 2nd connection of
// that ACTIVE call; see the ACTIVE case below.)
showSecondaryCallInfo();
if (PhoneUtils.isConferenceCall(call)) {
if (DBG) log("==> conference call.");
mSecondaryCallName.setText(getContext().getString(R.string.confCall));
showImage(mSecondaryCallPhoto, R.drawable.picture_conference);
} else {
// perform query and update the name temporarily
// make sure we hand the textview we want updated to the
// callback function.
if (DBG) log("==> NOT a conf call; call startGetCallerInfo...");
PhoneUtils.CallerInfoToken infoToken = PhoneUtils.startGetCallerInfo(
getContext(), call, this, mSecondaryCallName);
mSecondaryCallName.setText(
PhoneUtils.getCompactNameFromCallerInfo(infoToken.currentInfo,
getContext()));
// Also pull the photo out of the current CallerInfo.
// (Note we assume we already have a valid photo at
// this point, since *presumably* the caller-id query
// was already run at some point *before* this call
// got put on hold. If there's no cached photo, just
// fall back to the default "unknown" image.)
if (infoToken.isFinal) {
showCachedImage(mSecondaryCallPhoto, infoToken.currentInfo);
} else {
showImage(mSecondaryCallPhoto, R.drawable.picture_unknown);
}
}