-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInCallScreen.java
executable file
·4986 lines (4386 loc) · 216 KB
/
InCallScreen.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.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.net.Uri;
import android.os.AsyncResult;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.provider.Checkin;
import android.provider.Settings;
import android.telephony.PhoneNumberUtils;
import android.telephony.ServiceState;
import android.text.TextUtils;
import android.text.method.DialerKeyListener;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.SlidingDrawer;
import android.widget.TextView;
import android.widget.Toast;
import com.android.internal.telephony.Call;
import com.android.internal.telephony.Connection;
import com.android.internal.telephony.MmiCode;
import com.android.internal.telephony.Phone;
import com.android.phone.OtaUtils.CdmaOtaInCallScreenUiState;
import com.android.phone.OtaUtils.CdmaOtaScreenState;
import java.util.List;
/**
* Phone app "in call" screen.
*/
public class InCallScreen extends Activity
implements View.OnClickListener, View.OnTouchListener, View.OnLongClickListener {
private static final String LOG_TAG = "InCallScreen";
private static final boolean DBG =
(PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
private static final boolean VDBG = (PhoneApp.DBG_LEVEL >= 2);
// Enable detailed logs of user actions while on the in-call screen.
// TODO: For now this is totally disabled. But for future user
// research, we should change the PHONE_UI_EVENT_* events to use
// android.util.EventLog rather than Checkin.logEvent, so that we can
// select which of those events to upload on a tag-by-tag basis
// (which means that we could actually ship devices with this logging
// enabled.)
/* package */ static final boolean ENABLE_PHONE_UI_EVENT_LOGGING = false;
/**
* Intent extra used to specify whether the DTMF dialpad should be
* initially visible when bringing up the InCallScreen. (If this
* extra is present, the dialpad will be initially shown if the extra
* has the boolean value true, and initially hidden otherwise.)
*/
// TODO: Should be EXTRA_SHOW_DIALPAD for consistency.
static final String SHOW_DIALPAD_EXTRA = "com.android.phone.ShowDialpad";
/**
* Intent extra to specify the package name of the gateway
* provider. Used to get the name displayed in the in-call screen
* during the call setup. The value is a string.
*/
// TODO: This extra is currently set by the gateway application as
// a temporary measure. Ultimately, the framework will securely
// set it.
/* package */ static final String EXTRA_GATEWAY_PROVIDER_PACKAGE =
"com.android.phone.extra.GATEWAY_PROVIDER_PACKAGE";
/**
* Intent extra to specify the URI of the provider to place the
* call. The value is a string. It holds the gateway address
* (phone gateway URL should start with the 'tel:' scheme) that
* will actually be contacted to call the number passed in the
* intent URL or in the EXTRA_PHONE_NUMBER extra.
*/
// TODO: Should the value be a Uri (Parcelable)? Need to make sure
// MMI code '#' don't get confused as URI fragments.
/* package */ static final String EXTRA_GATEWAY_URI =
"com.android.phone.extra.GATEWAY_URI";
// Event values used with Checkin.Events.Tag.PHONE_UI events:
/** The in-call UI became active */
static final String PHONE_UI_EVENT_ENTER = "enter";
/** User exited the in-call UI */
static final String PHONE_UI_EVENT_EXIT = "exit";
/** User clicked one of the touchable in-call buttons */
static final String PHONE_UI_EVENT_BUTTON_CLICK = "button_click";
// Amount of time (in msec) that we display the "Call ended" state.
// The "short" value is for calls ended by the local user, and the
// "long" value is for calls ended by the remote caller.
private static final int CALL_ENDED_SHORT_DELAY = 200; // msec
private static final int CALL_ENDED_LONG_DELAY = 2000; // msec
// Amount of time (in msec) that we keep the in-call menu onscreen
// *after* the user changes the state of one of the toggle buttons.
private static final int MENU_DISMISS_DELAY = 1000; // msec
// Amount of time that we display the PAUSE alert Dialog showing the
// post dial string yet to be send out to the n/w
private static final int PAUSE_PROMPT_DIALOG_TIMEOUT = 2000; //msec
// The "touch lock" overlay timeout comes from Gservices; this is the default.
private static final int TOUCH_LOCK_DELAY_DEFAULT = 6000; // msec
// Amount of time for Displaying "Dialing" for 3way Calling origination
private static final int THREEWAY_CALLERINFO_DISPLAY_TIME = 3000; // msec
// Amount of time that we display the provider's overlay if applicable.
private static final int PROVIDER_OVERLAY_TIMEOUT = 5000; // msec
// These are values for the settings of the auto retry mode:
// 0 = disabled
// 1 = enabled
// TODO (Moto):These constants don't really belong here,
// they should be moved to Settings where the value is being looked up in the first place
static final int AUTO_RETRY_OFF = 0;
static final int AUTO_RETRY_ON = 1;
// Message codes; see mHandler below.
// Note message codes < 100 are reserved for the PhoneApp.
private static final int PHONE_STATE_CHANGED = 101;
private static final int PHONE_DISCONNECT = 102;
private static final int EVENT_HEADSET_PLUG_STATE_CHANGED = 103;
private static final int POST_ON_DIAL_CHARS = 104;
private static final int WILD_PROMPT_CHAR_ENTERED = 105;
private static final int ADD_VOICEMAIL_NUMBER = 106;
private static final int DONT_ADD_VOICEMAIL_NUMBER = 107;
private static final int DELAYED_CLEANUP_AFTER_DISCONNECT = 108;
private static final int SUPP_SERVICE_FAILED = 110;
private static final int DISMISS_MENU = 111;
private static final int ALLOW_SCREEN_ON = 112;
private static final int TOUCH_LOCK_TIMER = 113;
private static final int REQUEST_UPDATE_BLUETOOTH_INDICATION = 114;
private static final int PHONE_CDMA_CALL_WAITING = 115;
private static final int THREEWAY_CALLERINFO_DISPLAY_DONE = 116;
private static final int EVENT_OTA_PROVISION_CHANGE = 117;
private static final int REQUEST_CLOSE_SPC_ERROR_NOTICE = 118;
private static final int REQUEST_CLOSE_OTA_FAILURE_NOTICE = 119;
private static final int EVENT_PAUSE_DIALOG_COMPLETE = 120;
private static final int EVENT_HIDE_PROVIDER_OVERLAY = 121; // Time to remove the overlay.
private static final int REQUEST_UPDATE_TOUCH_UI = 122;
//following constants are used for OTA Call
public static final String ACTION_SHOW_ACTIVATION =
"com.android.phone.InCallScreen.SHOW_ACTIVATION";
public static final String OTA_NUMBER = "*228";
public static final String EXTRA_OTA_CALL = "android.phone.extra.OTA_CALL";
// When InCallScreenMode is UNDEFINED set the default action
// to ACTION_UNDEFINED so if we are resumed the activity will
// know its undefined. In particular checkIsOtaCall will return
// false.
public static final String ACTION_UNDEFINED = "com.android.phone.InCallScreen.UNDEFINED";
// High-level "modes" of the in-call UI.
private enum InCallScreenMode {
/**
* Normal in-call UI elements visible.
*/
NORMAL,
/**
* "Manage conference" UI is visible, totally replacing the
* normal in-call UI.
*/
MANAGE_CONFERENCE,
/**
* Non-interactive UI state. Call card is visible,
* displaying information about the call that just ended.
*/
CALL_ENDED,
/**
* Normal OTA in-call UI elements visible.
*/
OTA_NORMAL,
/**
* OTA call ended UI visible, replacing normal OTA in-call UI.
*/
OTA_ENDED,
/**
* Default state when not on call
*/
UNDEFINED
}
private InCallScreenMode mInCallScreenMode = InCallScreenMode.UNDEFINED;
// Possible error conditions that can happen on startup.
// These are returned as status codes from the various helper
// functions we call from onCreate() and/or onResume().
// See syncWithPhoneState() and checkIfOkToInitiateOutgoingCall() for details.
private enum InCallInitStatus {
SUCCESS,
VOICEMAIL_NUMBER_MISSING,
POWER_OFF,
EMERGENCY_ONLY,
PHONE_NOT_IN_USE,
NO_PHONE_NUMBER_SUPPLIED,
DIALED_MMI,
CALL_FAILED
}
private InCallInitStatus mInCallInitialStatus; // see onResume()
private boolean mRegisteredForPhoneStates;
private boolean mNeedShowCallLostDialog;
private Phone mPhone;
private Call mForegroundCall;
private Call mBackgroundCall;
private Call mRingingCall;
private BluetoothHandsfree mBluetoothHandsfree;
private BluetoothHeadset mBluetoothHeadset;
private boolean mBluetoothConnectionPending;
private long mBluetoothConnectionRequestTime;
// Main in-call UI ViewGroups
private ViewGroup mMainFrame;
private ViewGroup mInCallPanel;
// Main in-call UI elements:
private CallCard mCallCard;
// UI controls:
private InCallControlState mInCallControlState;
private InCallMenu mInCallMenu; // used on some devices
private InCallTouchUi mInCallTouchUi; // used on some devices
private ManageConferenceUtils mManageConferenceUtils;
// DTMF Dialer controller and its view:
private DTMFTwelveKeyDialer mDialer;
private DTMFTwelveKeyDialerView mDialerView;
// TODO: Move these providers related fields in their own class.
// Optional overlay when a 3rd party provider is used.
private boolean mProviderOverlayVisible = false;
private CharSequence mProviderLabel;
private Drawable mProviderIcon;
private Uri mProviderGatewayUri;
// The formated address extracted from mProviderGatewayUri. User visible.
private String mProviderAddress;
// For OTA Call
public OtaUtils otaUtils;
private EditText mWildPromptText;
// "Touch lock overlay" feature
private boolean mUseTouchLockOverlay; // True if we use this feature on the current device
private View mTouchLockOverlay; // The overlay over the whole screen
private View mTouchLockIcon; // The "lock" icon in the middle of the screen
private Animation mTouchLockFadeIn;
private long mTouchLockLastTouchTime; // in SystemClock.uptimeMillis() time base
// Various dialogs we bring up (see dismissAllDialogs()).
// TODO: convert these all to use the "managed dialogs" framework.
//
// The MMI started dialog can actually be one of 2 items:
// 1. An alert dialog if the MMI code is a normal MMI
// 2. A progress dialog if the user requested a USSD
private Dialog mMmiStartedDialog;
private AlertDialog mMissingVoicemailDialog;
private AlertDialog mGenericErrorDialog;
private AlertDialog mSuppServiceFailureDialog;
private AlertDialog mWaitPromptDialog;
private AlertDialog mWildPromptDialog;
private AlertDialog mCallLostDialog;
private AlertDialog mPausePromptDialog;
// NOTE: if you add a new dialog here, be sure to add it to dismissAllDialogs() also.
// TODO: If the Activity class ever provides an easy way to get the
// current "activity lifecycle" state, we can remove these flags.
private boolean mIsDestroyed = false;
private boolean mIsForegroundActivity = false;
// For use with CDMA Pause/Wait dialogs
private String mPostDialStrAfterPause;
private boolean mPauseInProgress = false;
// Flag indicating whether or not we should bring up the Call Log when
// exiting the in-call UI due to the Phone becoming idle. (This is
// true if the most recently disconnected Call was initiated by the
// user, or false if it was an incoming call.)
// This flag is used by delayedCleanupAfterDisconnect(), and is set by
// onDisconnect() (which is the only place that either posts a
// DELAYED_CLEANUP_AFTER_DISCONNECT event *or* calls
// delayedCleanupAfterDisconnect() directly.)
private boolean mShowCallLogAfterDisconnect;
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (mIsDestroyed) {
if (DBG) log("Handler: ignoring message " + msg + "; we're destroyed!");
return;
}
if (!mIsForegroundActivity) {
if (DBG) log("Handler: handling message " + msg + " while not in foreground");
// Continue anyway; some of the messages below *want* to
// be handled even if we're not the foreground activity
// (like DELAYED_CLEANUP_AFTER_DISCONNECT), and they all
// should at least be safe to handle if we're not in the
// foreground...
}
PhoneApp app = PhoneApp.getInstance();
switch (msg.what) {
case SUPP_SERVICE_FAILED:
onSuppServiceFailed((AsyncResult) msg.obj);
break;
case PHONE_STATE_CHANGED:
onPhoneStateChanged((AsyncResult) msg.obj);
break;
case PHONE_DISCONNECT:
onDisconnect((AsyncResult) msg.obj);
break;
case EVENT_HEADSET_PLUG_STATE_CHANGED:
// Update the in-call UI, since some UI elements (in
// particular the "Speaker" menu button) change state
// depending on whether a headset is plugged in.
// TODO: A full updateScreen() is overkill here, since
// the value of PhoneApp.isHeadsetPlugged() only affects a
// single menu item. (But even a full updateScreen()
// is still pretty cheap, so let's keep this simple
// for now.)
if (!isBluetoothAudioConnected()) {
if (msg.arg1 != 1){
// If the state is "not connected", restore the speaker state.
// We ONLY want to do this on the wired headset connect /
// disconnect events for now though, so we're only triggering
// on EVENT_HEADSET_PLUG_STATE_CHANGED.
PhoneUtils.restoreSpeakerMode(InCallScreen.this);
} else {
// If the state is "connected", force the speaker off without
// storing the state.
PhoneUtils.turnOnSpeaker(InCallScreen.this, false, false);
// If the dialpad is open, we need to start the timer that will
// eventually bring up the "touch lock" overlay.
if (mDialer.isOpened() && !isTouchLocked()) {
resetTouchLockTimer();
}
}
}
updateScreen();
break;
case PhoneApp.MMI_INITIATE:
onMMIInitiate((AsyncResult) msg.obj);
break;
case PhoneApp.MMI_CANCEL:
onMMICancel();
break;
// handle the mmi complete message.
// since the message display class has been replaced with
// a system dialog in PhoneUtils.displayMMIComplete(), we
// should finish the activity here to close the window.
case PhoneApp.MMI_COMPLETE:
// Check the code to see if the request is ready to
// finish, this includes any MMI state that is not
// PENDING.
MmiCode mmiCode = (MmiCode) ((AsyncResult) msg.obj).result;
// if phone is a CDMA phone display feature code completed message
int phoneType = mPhone.getPhoneType();
if (phoneType == Phone.PHONE_TYPE_CDMA) {
PhoneUtils.displayMMIComplete(mPhone, app, mmiCode, null, null);
} else if (phoneType == Phone.PHONE_TYPE_GSM) {
if (mmiCode.getState() != MmiCode.State.PENDING) {
if (DBG) log("Got MMI_COMPLETE, finishing InCallScreen...");
endInCallScreenSession();
}
}
break;
case POST_ON_DIAL_CHARS:
handlePostOnDialChars((AsyncResult) msg.obj, (char) msg.arg1);
break;
case ADD_VOICEMAIL_NUMBER:
addVoiceMailNumberPanel();
break;
case DONT_ADD_VOICEMAIL_NUMBER:
dontAddVoiceMailNumber();
break;
case DELAYED_CLEANUP_AFTER_DISCONNECT:
delayedCleanupAfterDisconnect();
break;
case DISMISS_MENU:
// dismissMenu() has no effect if the menu is already closed.
dismissMenu(true); // dismissImmediate = true
break;
case ALLOW_SCREEN_ON:
if (VDBG) log("ALLOW_SCREEN_ON message...");
// Undo our previous call to preventScreenOn(true).
// (Note this will cause the screen to turn on
// immediately, if it's currently off because of a
// prior preventScreenOn(true) call.)
app.preventScreenOn(false);
break;
case TOUCH_LOCK_TIMER:
if (VDBG) log("TOUCH_LOCK_TIMER...");
touchLockTimerExpired();
break;
case REQUEST_UPDATE_BLUETOOTH_INDICATION:
if (VDBG) log("REQUEST_UPDATE_BLUETOOTH_INDICATION...");
// The bluetooth headset state changed, so some UI
// elements may need to update. (There's no need to
// look up the current state here, since any UI
// elements that care about the bluetooth state get it
// directly from PhoneApp.showBluetoothIndication().)
updateScreen();
break;
case PHONE_CDMA_CALL_WAITING:
if (DBG) log("Received PHONE_CDMA_CALL_WAITING event ...");
Connection cn = mRingingCall.getLatestConnection();
// Only proceed if we get a valid connection object
if (cn != null) {
// Finally update screen with Call waiting info and request
// screen to wake up
updateScreen();
app.updateWakeState();
}
break;
case THREEWAY_CALLERINFO_DISPLAY_DONE:
if (DBG) log("Received THREEWAY_CALLERINFO_DISPLAY_DONE event ...");
if (app.cdmaPhoneCallState.getCurrentCallState()
== CdmaPhoneCallState.PhoneCallState.THRWAY_ACTIVE) {
// Set the mThreeWayCallOrigStateDialing state to true
app.cdmaPhoneCallState.setThreeWayCallOrigState(false);
//Finally update screen with with the current on going call
updateScreen();
}
break;
case EVENT_OTA_PROVISION_CHANGE:
if (otaUtils != null) {
otaUtils.onOtaProvisionStatusChanged((AsyncResult) msg.obj);
}
break;
case REQUEST_CLOSE_SPC_ERROR_NOTICE:
if (otaUtils != null) {
otaUtils.onOtaCloseSpcNotice();
}
break;
case REQUEST_CLOSE_OTA_FAILURE_NOTICE:
if (otaUtils != null) {
otaUtils.onOtaCloseFailureNotice();
}
break;
case EVENT_PAUSE_DIALOG_COMPLETE:
if (mPausePromptDialog != null) {
if (DBG) log("- DISMISSING mPausePromptDialog.");
mPausePromptDialog.dismiss(); // safe even if already dismissed
mPausePromptDialog = null;
}
break;
case EVENT_HIDE_PROVIDER_OVERLAY:
mProviderOverlayVisible = false;
updateProviderOverlay(); // Clear the overlay.
break;
case REQUEST_UPDATE_TOUCH_UI:
updateInCallTouchUi();
break;
}
}
};
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(Intent.ACTION_HEADSET_PLUG)) {
// Listen for ACTION_HEADSET_PLUG broadcasts so that we
// can update the onscreen UI when the headset state changes.
// if (DBG) log("mReceiver: ACTION_HEADSET_PLUG");
// if (DBG) log("==> intent: " + intent);
// if (DBG) log(" state: " + intent.getIntExtra("state", 0));
// if (DBG) log(" name: " + intent.getStringExtra("name"));
// send the event and add the state as an argument.
Message message = Message.obtain(mHandler, EVENT_HEADSET_PLUG_STATE_CHANGED,
intent.getIntExtra("state", 0), 0);
mHandler.sendMessage(message);
}
}
};
private CallFeaturesSetting mSettings;
private boolean mForceTouch;
@Override
protected void onCreate(Bundle icicle) {
if (DBG) log("onCreate()... this = " + this);
Profiler.callScreenOnCreate();
super.onCreate(icicle);
final PhoneApp app = PhoneApp.getInstance();
app.setInCallScreenInstance(this);
// set this flag so this activity will stay in front of the keyguard
int flags = WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
if (app.getPhoneState() == Phone.State.OFFHOOK) {
// While we are in call, the in-call screen should dismiss the keyguard.
// This allows the user to press Home to go directly home without going through
// an insecure lock screen.
// But we do not want to do this if there is no active call so we do not
// bypass the keyguard if the call is not answered or declined.
flags |= WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
}
getWindow().addFlags(flags);
setPhone(app.phone); // Sets mPhone and mForegroundCall/mBackgroundCall/mRingingCall
mBluetoothHandsfree = app.getBluetoothHandsfree();
if (VDBG) log("- mBluetoothHandsfree: " + mBluetoothHandsfree);
if (mBluetoothHandsfree != null) {
// The PhoneApp only creates a BluetoothHandsfree instance in the
// first place if BluetoothAdapter.getDefaultAdapter()
// succeeds. So at this point we know the device is BT-capable.
mBluetoothHeadset = new BluetoothHeadset(this, null);
if (VDBG) log("- Got BluetoothHeadset: " + mBluetoothHeadset);
}
requestWindowFeature(Window.FEATURE_NO_TITLE);
// Inflate everything in incall_screen.xml and add it to the screen.
setContentView(R.layout.incall_screen);
initInCallScreen();
initDialPad();
registerForPhoneStates();
// No need to change wake state here; that happens in onResume() when we
// are actually displayed.
// Handle the Intent we were launched with, but only if this is the
// the very first time we're being launched (ie. NOT if we're being
// re-initialized after previously being shut down.)
// Once we're up and running, any future Intents we need
// to handle will come in via the onNewIntent() method.
if (icicle == null) {
if (DBG) log("onCreate(): this is our very first launch, checking intent...");
// Stash the result code from internalResolveIntent() in the
// mInCallInitialStatus field. If it's an error code, we'll
// handle it in onResume().
mInCallInitialStatus = internalResolveIntent(getIntent());
if (DBG) log("onCreate(): mInCallInitialStatus = " + mInCallInitialStatus);
if (mInCallInitialStatus != InCallInitStatus.SUCCESS) {
Log.w(LOG_TAG, "onCreate: status " + mInCallInitialStatus
+ " from internalResolveIntent()");
// See onResume() for the actual error handling.
}
} else {
mInCallInitialStatus = InCallInitStatus.SUCCESS;
}
mSettings = CallFeaturesSetting.getInstance(android.preference.PreferenceManager.getDefaultSharedPreferences(this));
mForceTouch = mSettings.mForceTouch;
// The "touch lock overlay" feature is used only on devices that
// *don't* use a proximity sensor to turn the screen off while in-call.
// add by cytown: also turn off if force show the touch keyboard.
mUseTouchLockOverlay = !app.proximitySensorModeEnabled() && !mForceTouch;
Profiler.callScreenCreated();
if (DBG) log("onCreate(): exit");
}
private void initDialPad() {
// Create the dtmf dialer. The dialer view we use depends on the
// current platform:
//
// - On non-prox-sensor devices, it's the dialpad contained inside
// a SlidingDrawer widget (see dtmf_twelve_key_dialer.xml).
//
// - On "full touch UI" devices, it's the compact non-sliding
// dialpad that appears on the upper half of the screen,
// above the main cluster of InCallTouchUi buttons
// (see non_drawer_dialpad.xml).
//
// TODO: These should both be ViewStubs, and right here we should
// inflate one or the other. (Also, while doing that, let's also
// move this block of code over to initInCallScreen().)
//
SlidingDrawer dialerDrawer;
if (isTouchUiEnabled()) {
// This is a "full touch" device.
mDialerView = (DTMFTwelveKeyDialerView) findViewById(R.id.non_drawer_dtmf_dialer);
if (DBG) log("- Full touch device! Found dialerView: " + mDialerView);
dialerDrawer = null; // No SlidingDrawer used on this device.
} else {
// Use the old-style dialpad contained within the SlidingDrawer.
mDialerView = (DTMFTwelveKeyDialerView) findViewById(R.id.dtmf_dialer);
if (DBG) log("- Using SlidingDrawer-based dialpad. Found dialerView: " + mDialerView);
dialerDrawer = (SlidingDrawer) findViewById(R.id.dialer_container);
if (DBG) log(" ...and the SlidingDrawer: " + dialerDrawer);
}
// Sanity-check that (regardless of the device) at least the
// dialer view is present:
if (mDialerView == null) {
Log.e(LOG_TAG, "onCreate: couldn't find dialerView", new IllegalStateException());
}
// Finally, create the DTMFTwelveKeyDialer instance.
mDialer = new DTMFTwelveKeyDialer(this, mDialerView, dialerDrawer);
}
/**
* Sets the Phone object used internally by the InCallScreen.
*
* In normal operation this is called from onCreate(), and the
* passed-in Phone object comes from the PhoneApp.
* For testing, test classes can use this method to
* inject a test Phone instance.
*/
/* package */ void setPhone(Phone phone) {
mPhone = phone;
// Hang onto the three Call objects too; they're singletons that
// are constant (and never null) for the life of the Phone.
mForegroundCall = mPhone.getForegroundCall();
mBackgroundCall = mPhone.getBackgroundCall();
mRingingCall = mPhone.getRingingCall();
}
@Override
protected void onResume() {
if (DBG) log("onResume()...");
super.onResume();
mIsForegroundActivity = true;
final PhoneApp app = PhoneApp.getInstance();
// add by cytown: if mForceTouch changed, re-init dialpad.
if (mForceTouch != mSettings.mForceTouch) {
if (DBG) log("Force Touch setting changed, re-init dialpad");
mForceTouch = mSettings.mForceTouch;
mUseTouchLockOverlay = !app.proximitySensorModeEnabled() && !mForceTouch;
initDialPad();
}
app.disableStatusBar();
// Touch events are never considered "user activity" while the
// InCallScreen is active, so that unintentional touches won't
// prevent the device from going to sleep.
app.setIgnoreTouchUserActivity(true);
// KrazyKrivda's mod to enabled the notification bar from
// the in-call screen.
NotificationMgr.getDefault().getStatusBarMgr().enableExpandedView(true);
// Listen for broadcast intents that might affect the onscreen UI.
registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_HEADSET_PLUG));
// Keep a "dialer session" active when we're in the foreground.
// (This is needed to play DTMF tones.)
mDialer.startDialerSession();
// Check for any failures that happened during onCreate() or onNewIntent().
if (DBG) log("- onResume: initial status = " + mInCallInitialStatus);
if (mInCallInitialStatus != InCallInitStatus.SUCCESS) {
if (DBG) log("- onResume: failure during startup: " + mInCallInitialStatus);
// Don't bring up the regular Phone UI! Instead bring up
// something more specific to let the user deal with the
// problem.
handleStartupError(mInCallInitialStatus);
// But it *is* OK to continue with the rest of onResume(),
// since any further setup steps (like updateScreen() and the
// CallCard setup) will fall back to a "blank" state if the
// phone isn't in use.
mInCallInitialStatus = InCallInitStatus.SUCCESS;
}
// Set the volume control handler while we are in the foreground.
final boolean bluetoothConnected = isBluetoothAudioConnected();
if (bluetoothConnected) {
setVolumeControlStream(AudioManager.STREAM_BLUETOOTH_SCO);
} else {
setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
}
takeKeyEvents(true);
boolean phoneIsCdma = (mPhone.getPhoneType() == Phone.PHONE_TYPE_CDMA);
boolean inOtaCall = false;
if (phoneIsCdma) {
inOtaCall = initOtaState();
}
if (!inOtaCall) {
// Always start off in NORMAL mode
setInCallScreenMode(InCallScreenMode.NORMAL);
}
// Before checking the state of the phone, clean up any
// connections in the DISCONNECTED state.
// (The DISCONNECTED state is used only to drive the "call ended"
// UI; it's totally useless when *entering* the InCallScreen.)
mPhone.clearDisconnected();
InCallInitStatus status = syncWithPhoneState();
if (status != InCallInitStatus.SUCCESS) {
if (DBG) log("- syncWithPhoneState failed! status = " + status);
// Couldn't update the UI, presumably because the phone is totally
// idle. But don't endInCallScreenSession immediately, since we might still
// have an error dialog up that the user needs to see.
// (And in that case, the error dialog is responsible for calling
// endInCallScreenSession when the user dismisses it.)
} else if (phoneIsCdma) {
if (mInCallScreenMode == InCallScreenMode.OTA_NORMAL ||
mInCallScreenMode == InCallScreenMode.OTA_ENDED) {
mDialer.setHandleVisible(false);
if (mInCallPanel != null) mInCallPanel.setVisibility(View.GONE);
updateScreen();
return;
}
}
if (ENABLE_PHONE_UI_EVENT_LOGGING) {
// InCallScreen is now active.
Checkin.logEvent(getContentResolver(),
Checkin.Events.Tag.PHONE_UI,
PHONE_UI_EVENT_ENTER);
}
// Update the poke lock and wake lock when we move to
// the foreground.
//
// But we need to do something special if we're coming
// to the foreground while an incoming call is ringing:
if (mPhone.getState() == Phone.State.RINGING) {
// If the phone is ringing, we *should* already be holding a
// full wake lock (which we would have acquired before
// firing off the intent that brought us here; see
// PhoneUtils.showIncomingCallUi().)
//
// We also called preventScreenOn(true) at that point, to
// avoid cosmetic glitches while we were being launched.
// So now we need to post an ALLOW_SCREEN_ON message to
// (eventually) undo the prior preventScreenOn(true) call.
//
// (In principle we shouldn't do this until after our first
// layout/draw pass. But in practice, the delay caused by
// simply waiting for the end of the message queue is long
// enough to avoid any flickering of the lock screen before
// the InCallScreen comes up.)
if (VDBG) log("- posting ALLOW_SCREEN_ON message...");
mHandler.removeMessages(ALLOW_SCREEN_ON);
mHandler.sendEmptyMessage(ALLOW_SCREEN_ON);
// TODO: There ought to be a more elegant way of doing this,
// probably by having the PowerManager and ActivityManager
// work together to let apps request that the screen on/off
// state be synchronized with the Activity lifecycle.
// (See bug 1648751.)
} else {
// The phone isn't ringing; this is either an outgoing call, or
// we're returning to a call in progress. There *shouldn't* be
// any prior preventScreenOn(true) call that we need to undo,
// but let's do this just to be safe:
app.preventScreenOn(false);
}
app.updateWakeState();
// The "touch lock" overlay is NEVER visible when we resume.
// (In particular, this check ensures that we won't still be
// locked after the user wakes up the screen by pressing MENU.)
enableTouchLock(false);
// ...but if the dialpad is open we DO need to start the timer
// that will eventually bring up the "touch lock" overlay.
if (mDialer.isOpened()) resetTouchLockTimer();
// Restore the mute state if the last mute state change was NOT
// done by the user.
if (app.getRestoreMuteOnInCallResume()) {
PhoneUtils.restoreMuteState(mPhone);
app.setRestoreMuteOnInCallResume(false);
}
Profiler.profileViewCreate(getWindow(), InCallScreen.class.getName());
if (VDBG) log("onResume() done.");
}
// onPause is guaranteed to be called when the InCallScreen goes
// in the background.
@Override
protected void onPause() {
if (DBG) log("onPause()...");
super.onPause();
mIsForegroundActivity = false;
// Force a clear of the provider overlay' frame. Since the
// overlay is removed using a timed message, it is
// possible we missed it if the prev call was interrupted.
mProviderOverlayVisible = false;
updateProviderOverlay();
final PhoneApp app = PhoneApp.getInstance();
// A safety measure to disable proximity sensor in case call failed
// and the telephony state did not change.
app.setBeginningCall(false);
// Make sure the "Manage conference" chronometer is stopped when
// we move away from the foreground.
mManageConferenceUtils.stopConferenceTime();
// as a catch-all, make sure that any dtmf tones are stopped
// when the UI is no longer in the foreground.
mDialer.onDialerKeyUp(null);
// Release any "dialer session" resources, now that we're no
// longer in the foreground.
mDialer.stopDialerSession();
// If the device is put to sleep as the phone call is ending,
// we may see cases where the DELAYED_CLEANUP_AFTER_DISCONNECT
// event gets handled AFTER the device goes to sleep and wakes
// up again.
// This is because it is possible for a sleep command
// (executed with the End Call key) to come during the 2
// seconds that the "Call Ended" screen is up. Sleep then
// pauses the device (including the cleanup event) and
// resumes the event when it wakes up.
// To fix this, we introduce a bit of code that pushes the UI
// to the background if we pause and see a request to
// DELAYED_CLEANUP_AFTER_DISCONNECT.
// Note: We can try to finish directly, by:
// 1. Removing the DELAYED_CLEANUP_AFTER_DISCONNECT messages
// 2. Calling delayedCleanupAfterDisconnect directly
// However, doing so can cause problems between the phone
// app and the keyguard - the keyguard is trying to sleep at
// the same time that the phone state is changing. This can
// end up causing the sleep request to be ignored.
if (mHandler.hasMessages(DELAYED_CLEANUP_AFTER_DISCONNECT)
&& mPhone.getState() != Phone.State.RINGING) {
if (DBG) log("DELAYED_CLEANUP_AFTER_DISCONNECT detected, moving UI to background.");
endInCallScreenSession();
}
if (ENABLE_PHONE_UI_EVENT_LOGGING) {
// InCallScreen is no longer active.
Checkin.logEvent(getContentResolver(),
Checkin.Events.Tag.PHONE_UI,
PHONE_UI_EVENT_EXIT);
}
// Clean up the menu, in case we get paused while the menu is up
// for some reason.
dismissMenu(true); // dismiss immediately
// Dismiss any dialogs we may have brought up, just to be 100%
// sure they won't still be around when we get back here.
dismissAllDialogs();
// Re-enable the status bar (which we disabled in onResume().)
NotificationMgr.getDefault().getStatusBarMgr().enableExpandedView(true);
// Unregister for broadcast intents. (These affect the visible UI
// of the InCallScreen, so we only care about them while we're in the
// foreground.)
unregisterReceiver(mReceiver);
// Re-enable "user activity" for touch events.
// We actually do this slightly *after* onPause(), to work around a
// race condition where a touch can come in after we've paused
// but before the device actually goes to sleep.
// TODO: The PowerManager itself should prevent this from happening.
mHandler.postDelayed(new Runnable() {
public void run() {
app.setIgnoreTouchUserActivity(false);
}
}, 500);
app.reenableStatusBar();
// Make sure we revert the poke lock and wake lock when we move to
// the background.
app.updateWakeState();
// clear the dismiss keyguard flag so we are back to the default state
// when we next resume
updateKeyguardPolicy(false);
}
@Override
protected void onStop() {
if (DBG) log("onStop()...");
super.onStop();
stopTimer();
Phone.State state = mPhone.getState();
if (DBG) log("onStop: state = " + state);
if (state == Phone.State.IDLE) {
final PhoneApp app = PhoneApp.getInstance();
// when OTA Activation, OTA Success/Failure dialog or OTA SPC
// failure dialog is running, do not destroy inCallScreen. Because call
// is already ended and dialog will not get redrawn on slider event.
if ((app.cdmaOtaProvisionData != null) && (app.cdmaOtaScreenState != null)
&& ((app.cdmaOtaScreenState.otaScreenState !=
CdmaOtaScreenState.OtaScreenState.OTA_STATUS_ACTIVATION)
&& (app.cdmaOtaScreenState.otaScreenState !=
CdmaOtaScreenState.OtaScreenState.OTA_STATUS_SUCCESS_FAILURE_DLG)
&& (!app.cdmaOtaProvisionData.inOtaSpcState))) {
// we don't want the call screen to remain in the activity history
// if there are not active or ringing calls.
if (DBG) log("- onStop: calling finish() to clear activity history...");
moveTaskToBack(true);
if (otaUtils != null) {
otaUtils.cleanOtaScreen(true);
}
}
}
}
@Override
protected void onDestroy() {
if (DBG) log("onDestroy()...");
super.onDestroy();
// Set the magic flag that tells us NOT to handle any handler
// messages that come in asynchronously after we get destroyed.
mIsDestroyed = true;