forked from darchstar/android_packages_apps_Phone
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathInCallScreen.java
More file actions
executable file
·4495 lines (3948 loc) · 198 KB
/
Copy pathInCallScreen.java
File metadata and controls
executable file
·4495 lines (3948 loc) · 198 KB
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.app.ProgressDialog;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothProfile;
import android.content.ActivityNotFoundException;
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.Configuration;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.media.AudioManager;
import android.os.AsyncResult;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.PowerManager;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.telephony.ServiceState;
import android.text.TextUtils;
import android.text.method.DialerKeyListener;
import android.util.EventLog;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.view.Window;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.android.internal.telephony.Call;
import com.android.internal.telephony.CallManager;
import com.android.internal.telephony.Connection;
import com.android.internal.telephony.MmiCode;
import com.android.internal.telephony.Phone;
import com.android.phone.Constants.CallStatusCode;
import com.android.phone.InCallUiState.InCallScreenMode;
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 {
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);
/**
* 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";
// 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 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
// 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 ALLOW_SCREEN_ON = 112;
private static final int REQUEST_UPDATE_BLUETOOTH_INDICATION = 114;
private static final int PHONE_CDMA_CALL_WAITING = 115;
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_SCREEN = 122;
private static final int PHONE_INCOMING_RING = 123;
private static final int PHONE_NEW_RINGING_CONNECTION = 124;
// 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";
/** Status codes returned from syncWithPhoneState(). */
private enum SyncWithPhoneStateStatus {
/**
* Successfully updated our internal state based on the telephony state.
*/
SUCCESS,
/**
* There was no phone state to sync with (i.e. the phone was
* completely idle). In most cases this means that the
* in-call UI shouldn't be visible in the first place, unless
* we need to remain in the foreground while displaying an
* error message.
*/
PHONE_NOT_IN_USE
}
private boolean mRegisteredForPhoneStates;
private PhoneApp mApp;
private CallManager mCM;
// TODO: need to clean up all remaining uses of mPhone.
// (There may be more than one Phone instance on the device, so it's wrong
// to just keep a single mPhone field. Instead, any time we need a Phone
// reference we should get it dynamically from the CallManager, probably
// based on the current foreground Call.)
private Phone mPhone;
private BluetoothHandsfree mBluetoothHandsfree;
private BluetoothHeadset mBluetoothHeadset;
private BluetoothAdapter mAdapter;
private boolean mBluetoothConnectionPending;
private long mBluetoothConnectionRequestTime;
// Main in-call UI ViewGroups
private ViewGroup mInCallPanel;
// Main in-call UI elements:
private CallCard mCallCard;
// UI controls:
private InCallControlState mInCallControlState;
private InCallTouchUi mInCallTouchUi;
private RespondViaSmsManager mRespondViaSmsManager; // see internalRespondViaSms()
private ManageConferenceUtils mManageConferenceUtils;
// DTMF Dialer controller and its view:
private DTMFTwelveKeyDialer mDialer;
private DTMFTwelveKeyDialerView mDialerView;
private EditText mWildPromptText;
// 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;
private AlertDialog mExitingECMDialog;
// NOTE: if you add a new dialog here, be sure to add it to dismissAllDialogs() also.
// ProgressDialog created by showProgressIndication()
private ProgressDialog mProgressDialog;
// 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;
private boolean mIsForegroundActivityForProximity = false;
private PowerManager mPowerManager;
// For use with Pause/Wait dialogs
private String mPostDialStrAfterPause;
private boolean mPauseInProgress = false;
// Info about the most-recently-disconnected Connection, which is used
// to determine what should happen when exiting the InCallScreen after a
// call. (This info is set by onDisconnect(), and used by
// delayedCleanupAfterDisconnect().)
private Connection.DisconnectCause mLastDisconnectCause;
/** In-call audio routing options; see switchInCallAudio(). */
public enum InCallAudioMode {
SPEAKER, // Speakerphone
BLUETOOTH, // Bluetooth headset (if available)
EARPIECE, // Handset earpiece (or wired headset, if connected)
}
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...
}
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 (such
// as the "Speaker" button) may 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 onscreen UI element. (But even a full updateScreen()
// is still pretty cheap, so let's keep this simple
// for now.)
updateScreen();
// Also, force the "audio mode" popup to refresh itself if
// it's visible, since one of its items is either "Wired
// headset" or "Handset earpiece" depending on whether the
// headset is plugged in or not.
mInCallTouchUi.refreshAudioModePopup(); // safe even if the popup's not active
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, mApp, 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 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.)
mApp.preventScreenOn(false);
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 = mCM.getFirstActiveRingingCall().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();
mApp.updateWakeState();
}
break;
case REQUEST_CLOSE_SPC_ERROR_NOTICE:
if (mApp.otaUtils != null) {
mApp.otaUtils.onOtaCloseSpcNotice();
}
break;
case REQUEST_CLOSE_OTA_FAILURE_NOTICE:
if (mApp.otaUtils != null) {
mApp.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:
mApp.inCallUiState.providerOverlayVisible = false;
updateProviderOverlay(); // Clear the overlay.
break;
case REQUEST_UPDATE_SCREEN:
updateScreen();
break;
case PHONE_INCOMING_RING:
onIncomingRing();
break;
case PHONE_NEW_RINGING_CONNECTION:
onNewRingingConnection();
break;
default:
Log.wtf(LOG_TAG, "mHandler: unexpected message: " + msg);
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);
}
}
};
@Override
protected void onCreate(Bundle icicle) {
Log.i(LOG_TAG, "onCreate()... this = " + this);
Profiler.callScreenOnCreate();
super.onCreate(icicle);
// Make sure this is a voice-capable device.
if (!PhoneApp.sVoiceCapable) {
// There should be no way to ever reach the InCallScreen on a
// non-voice-capable device, since this activity is not exported by
// our manifest, and we explicitly disable any other external APIs
// like the CALL intent and ITelephony.showCallScreen().
// So the fact that we got here indicates a phone app bug.
Log.wtf(LOG_TAG, "onCreate() reached on non-voice-capable device");
finish();
return;
}
mApp = PhoneApp.getInstance();
mApp.setInCallScreenInstance(this);
// set this flag so this activity will stay in front of the keyguard
int flags = WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
if (mApp.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);
// Also put the system bar (if present on this device) into
// "lights out" mode any time we're the foreground activity.
WindowManager.LayoutParams params = getWindow().getAttributes();
params.systemUiVisibility = View.SYSTEM_UI_FLAG_LOW_PROFILE;
getWindow().setAttributes(params);
setPhone(mApp.phone); // Sets mPhone
mCM = mApp.mCM;
log("- onCreate: phone state = " + mCM.getState());
mBluetoothHandsfree = mApp.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.
mAdapter = BluetoothAdapter.getDefaultAdapter();
mAdapter.getProfileProxy(getApplicationContext(), mBluetoothProfileServiceListener,
BluetoothProfile.HEADSET);
}
requestWindowFeature(Window.FEATURE_NO_TITLE);
// Inflate everything in incall_screen.xml and add it to the screen.
setContentView(R.layout.incall_screen);
initInCallScreen();
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...");
internalResolveIntent(getIntent());
}
Profiler.callScreenCreated();
if (DBG) log("onCreate(): exit");
}
private BluetoothProfile.ServiceListener mBluetoothProfileServiceListener =
new BluetoothProfile.ServiceListener() {
public void onServiceConnected(int profile, BluetoothProfile proxy) {
mBluetoothHeadset = (BluetoothHeadset) proxy;
if (VDBG) log("- Got BluetoothHeadset: " + mBluetoothHeadset);
}
public void onServiceDisconnected(int profile) {
mBluetoothHeadset = null;
}
};
/**
* 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;
}
@Override
protected void onResume() {
if (DBG) log("onResume()...");
super.onResume();
mIsForegroundActivity = true;
mIsForegroundActivityForProximity = true;
final InCallUiState inCallUiState = mApp.inCallUiState;
if (VDBG) inCallUiState.dumpState();
// 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.
mApp.setIgnoreTouchUserActivity(true);
// Disable the status bar "window shade" the entire time we're on
// the in-call screen.
mApp.notificationMgr.statusBarHelper.enableExpandedView(false);
// ...and update the in-call notification too, since the status bar
// icon needs to be hidden while we're the foreground activity:
mApp.notificationMgr.updateInCallNotification();
// 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();
// Restore various other state from the InCallUiState object:
// Update the onscreen dialpad state to match the InCallUiState.
if (inCallUiState.showDialpad) {
showDialpadInternal(false); // no "opening" animation
} else {
hideDialpadInternal(false); // no "closing" animation
}
//
// TODO: also need to load inCallUiState.dialpadDigits into the dialpad
// If there's a "Respond via SMS" popup still around since the
// last time we were the foreground activity, make sure it's not
// still active!
// (The popup should *never* be visible initially when we first
// come to the foreground; it only ever comes up in response to
// the user selecting the "SMS" option from the incoming call
// widget.)
if (mRespondViaSmsManager != null) {
mRespondViaSmsManager.dismissPopup(); // safe even if already dismissed
}
// Display an error / diagnostic indication if necessary.
//
// When the InCallScreen comes to the foreground, we normally we
// display the in-call UI in whatever state is appropriate based on
// the state of the telephony framework (e.g. an outgoing call in
// DIALING state, an incoming call, etc.)
//
// But if the InCallUiState has a "pending call status code" set,
// that means we need to display some kind of status or error
// indication to the user instead of the regular in-call UI. (The
// most common example of this is when there's some kind of
// failure while initiating an outgoing call; see
// CallController.placeCall().)
//
boolean handledStartupError = false;
if (inCallUiState.hasPendingCallStatusCode()) {
if (DBG) log("- onResume: need to show status indication!");
showStatusIndication(inCallUiState.getPendingCallStatusCode());
// Set handledStartupError to ensure that we won't bail out below.
// (We need to stay here in the InCallScreen so that the user
// is able to see the error dialog!)
handledStartupError = true;
}
// 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);
// If an OTASP call is in progress, use the special OTASP-specific UI.
boolean inOtaCall = false;
if (TelephonyCapabilities.supportsOtasp(mPhone)) {
inOtaCall = checkOtaspStateOnResume();
}
if (!inOtaCall) {
// Always start off in NORMAL mode
setInCallScreenMode(InCallScreenMode.NORMAL);
}
// Before checking the state of the CallManager, 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.)
mCM.clearDisconnected();
// Update the onscreen UI to reflect the current telephony state.
SyncWithPhoneStateStatus status = syncWithPhoneState();
// Note there's no need to call updateScreen() here;
// syncWithPhoneState() already did that if necessary.
if (status != SyncWithPhoneStateStatus.SUCCESS) {
if (DBG) log("- onResume: syncWithPhoneState failed! status = " + status);
// Couldn't update the UI, presumably because the phone is totally
// idle.
// Even though the phone is idle, though, we do still need to
// stay here on the InCallScreen if we're displaying an
// error dialog (see "showStatusIndication()" above).
if (handledStartupError) {
// Stay here for now. We'll eventually leave the
// InCallScreen when the user presses the dialog's OK
// button (see bailOutAfterErrorDialog()), or when the
// progress indicator goes away.
Log.i(LOG_TAG, " ==> syncWithPhoneState failed, but staying here anyway.");
} else {
// The phone is idle, and we did NOT handle a
// startup error during this pass thru onResume.
//
// This basically means that we're being resumed because of
// some action *other* than a new intent. (For example,
// the user pressing POWER to wake up the device, causing
// the InCallScreen to come back to the foreground.)
//
// In this scenario we do NOT want to stay here on the
// InCallScreen: we're not showing any useful info to the
// user (like a dialog), and the in-call UI itself is
// useless if there's no active call. So bail out.
Log.i(LOG_TAG, " ==> syncWithPhoneState failed; bailing out!");
dismissAllDialogs();
// Force the InCallScreen to truly finish(), rather than just
// moving it to the back of the activity stack (which is what
// our finish() method usually does.)
// This is necessary to avoid an obscure scenario where the
// InCallScreen can get stuck in an inconsistent state, somehow
// causing a *subsequent* outgoing call to fail (bug 4172599).
endInCallScreenSession(true /* force a real finish() call */);
return;
}
} else if (TelephonyCapabilities.supportsOtasp(mPhone)) {
if (inCallUiState.inCallScreenMode == InCallScreenMode.OTA_NORMAL ||
inCallUiState.inCallScreenMode == InCallScreenMode.OTA_ENDED) {
if (mInCallPanel != null) mInCallPanel.setVisibility(View.GONE);
updateScreen();
return;
}
}
// InCallScreen is now active.
EventLog.writeEvent(EventLogTags.PHONE_UI_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 (mCM.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
// CallNotifier.showIncomingCall().)
//
// 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:
mApp.preventScreenOn(false);
}
mApp.updateWakeState();
// Restore the mute state if the last mute state change was NOT
// done by the user.
if (mApp.getRestoreMuteOnInCallResume()) {
// Mute state is based on the foreground call
PhoneUtils.restoreMuteState();
mApp.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();
if (mPowerManager.isScreenOn()) {
mIsForegroundActivityForProximity = false;
}
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.
mApp.inCallUiState.providerOverlayVisible = false;
updateProviderOverlay();
// A safety measure to disable proximity sensor in case call failed
// and the telephony state did not change.
mApp.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)
&& mCM.getState() != Phone.State.RINGING) {
log("DELAYED_CLEANUP_AFTER_DISCONNECT detected, moving UI to background.");
endInCallScreenSession();
}
EventLog.writeEvent(EventLogTags.PHONE_UI_EXIT);
// 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().)
mApp.notificationMgr.statusBarHelper.enableExpandedView(true);
// ...and the in-call notification too:
mApp.notificationMgr.updateInCallNotification();
// ...and *always* reset the system bar back to its normal state
// when leaving the in-call UI.
// (While we're the foreground activity, we disable navigation in
// some call states; see InCallTouchUi.updateState().)
mApp.notificationMgr.statusBarHelper.enableSystemBarNavigation(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() {
mApp.setIgnoreTouchUserActivity(false);
}
}, 500);
// Make sure we revert the poke lock and wake lock when we move to
// the background.
mApp.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 = mCM.getState();
if (DBG) log("onStop: state = " + state);
if (state == Phone.State.IDLE) {
// 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 ((mApp.cdmaOtaProvisionData != null) && (mApp.cdmaOtaScreenState != null)
&& ((mApp.cdmaOtaScreenState.otaScreenState !=
CdmaOtaScreenState.OtaScreenState.OTA_STATUS_ACTIVATION)
&& (mApp.cdmaOtaScreenState.otaScreenState !=
CdmaOtaScreenState.OtaScreenState.OTA_STATUS_SUCCESS_FAILURE_DLG)
&& (!mApp.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 (mApp.otaUtils != null) {
mApp.otaUtils.cleanOtaScreen(true);
}
}
}
}
@Override
protected void onDestroy() {
Log.i(LOG_TAG, "onDestroy()... this = " + this);
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;
mApp.setInCallScreenInstance(null);
// Clear out the InCallScreen references in various helper objects
// (to let them know we've been destroyed).
if (mCallCard != null) {
mCallCard.setInCallScreenInstance(null);
}
if (mInCallTouchUi != null) {
mInCallTouchUi.setInCallScreenInstance(null);
}
if (mRespondViaSmsManager != null) {
mRespondViaSmsManager.setInCallScreenInstance(null);
}
mDialer.clearInCallScreenReference();
mDialer = null;
unregisterForPhoneStates();
// No need to change wake state here; that happens in onPause() when we
// are moving out of the foreground.
if (mBluetoothHeadset != null) {
mAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset);
mBluetoothHeadset = null;
}
// Dismiss all dialogs, to be absolutely sure we won't leak any of
// them while changing orientation.
dismissAllDialogs();
// If there's an OtaUtils instance around, clear out its
// references to our internal widgets.
if (mApp.otaUtils != null) {
mApp.otaUtils.clearUiWidgets();
}
}
/**
* Dismisses the in-call screen.
*
* We never *really* finish() the InCallScreen, since we don't want to
* get destroyed and then have to be re-created from scratch for the
* next call. Instead, we just move ourselves to the back of the
* activity stack.
*
* This also means that we'll no longer be reachable via the BACK
* button (since moveTaskToBack() puts us behind the Home app, but the
* home app doesn't allow the BACK key to move you any farther down in
* the history stack.)
*
* (Since the Phone app itself is never killed, this basically means
* that we'll keep a single InCallScreen instance around for the
* entire uptime of the device. This noticeably improves the UI
* responsiveness for incoming calls.)
*/
@Override
public void finish() {
if (DBG) log("finish()...");
moveTaskToBack(true);
}
/**
* End the current in call screen session.
*
* This must be called when an InCallScreen session has
* complete so that the next invocation via an onResume will
* not be in an old state.
*/
public void endInCallScreenSession() {
if (DBG) log("endInCallScreenSession()... phone state = " + mCM.getState());
endInCallScreenSession(false);
}
/**
* Internal version of endInCallScreenSession().
*
* @param forceFinish If true, force the InCallScreen to
* truly finish() rather than just calling moveTaskToBack().
* @see finish()
*/
private void endInCallScreenSession(boolean forceFinish) {