blob: db06c302e7fc135f6e34e145fe2bab0149887951 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
19import android.app.Activity;
20import android.app.KeyguardManager;
21import android.app.PendingIntent;
22import android.app.ProgressDialog;
Yorke Leeca6ec3b2013-08-29 14:21:43 -070023import android.app.TaskStackBuilder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.bluetooth.BluetoothAdapter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.bluetooth.IBluetoothHeadsetPhone;
26import android.content.ActivityNotFoundException;
27import android.content.BroadcastReceiver;
28import android.content.ComponentName;
29import android.content.ContentResolver;
30import android.content.Context;
31import android.content.ContextWrapper;
32import android.content.Intent;
33import android.content.IntentFilter;
34import android.content.ServiceConnection;
35import android.content.res.Configuration;
36import android.media.AudioManager;
37import android.net.Uri;
38import android.os.AsyncResult;
39import android.os.Binder;
40import android.os.Handler;
41import android.os.IBinder;
42import android.os.IPowerManager;
43import android.os.Message;
44import android.os.PowerManager;
45import android.os.RemoteException;
46import android.os.ServiceManager;
47import android.os.SystemClock;
48import android.os.SystemProperties;
49import android.os.UpdateLock;
50import android.os.UserHandle;
51import android.preference.PreferenceManager;
52import android.provider.Settings.System;
53import android.telephony.ServiceState;
54import android.text.TextUtils;
55import android.util.Log;
56import android.util.Slog;
57import android.view.KeyEvent;
58
59import com.android.internal.telephony.Call;
60import com.android.internal.telephony.CallManager;
61import com.android.internal.telephony.IccCard;
62import com.android.internal.telephony.IccCardConstants;
63import com.android.internal.telephony.MmiCode;
64import com.android.internal.telephony.Phone;
65import com.android.internal.telephony.PhoneConstants;
66import com.android.internal.telephony.PhoneFactory;
67import com.android.internal.telephony.TelephonyCapabilities;
68import com.android.internal.telephony.TelephonyIntents;
69import com.android.internal.telephony.cdma.TtyIntent;
70import com.android.phone.common.CallLogAsync;
71import com.android.phone.OtaUtils.CdmaOtaScreenState;
Santos Cordon593ab382013-08-06 21:58:23 -070072import com.android.phone.WiredHeadsetManager.WiredHeadsetListener;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import com.android.server.sip.SipService;
Santos Cordon593ab382013-08-06 21:58:23 -070074import com.android.services.telephony.common.AudioMode;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075
76/**
77 * Global state for the telephony subsystem when running in the primary
78 * phone process.
79 */
Santos Cordonfc309812013-08-20 18:33:16 -070080public class PhoneGlobals extends ContextWrapper implements WiredHeadsetListener {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081 /* package */ static final String LOG_TAG = "PhoneApp";
82
83 /**
84 * Phone app-wide debug level:
85 * 0 - no debug logging
86 * 1 - normal debug logging if ro.debuggable is set (which is true in
87 * "eng" and "userdebug" builds but not "user" builds)
88 * 2 - ultra-verbose debug logging
89 *
90 * Most individual classes in the phone app have a local DBG constant,
91 * typically set to
92 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
93 * or else
94 * (PhoneApp.DBG_LEVEL >= 2)
95 * depending on the desired verbosity.
96 *
97 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
98 */
99 /* package */ static final int DBG_LEVEL = 0;
100
101 private static final boolean DBG =
102 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
103 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
104
105 // Message codes; see mHandler below.
106 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107 private static final int EVENT_SIM_STATE_CHANGED = 8;
108 private static final int EVENT_UPDATE_INCALL_NOTIFICATION = 9;
109 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
110 private static final int EVENT_DATA_ROAMING_OK = 11;
111 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 12;
112 private static final int EVENT_DOCK_STATE_CHANGED = 13;
113 private static final int EVENT_TTY_PREFERRED_MODE_CHANGED = 14;
114 private static final int EVENT_TTY_MODE_GET = 15;
115 private static final int EVENT_TTY_MODE_SET = 16;
116 private static final int EVENT_START_SIP_SERVICE = 17;
117
118 // The MMI codes are also used by the InCallScreen.
119 public static final int MMI_INITIATE = 51;
120 public static final int MMI_COMPLETE = 52;
121 public static final int MMI_CANCEL = 53;
122 // Don't use message codes larger than 99 here; those are reserved for
123 // the individual Activities of the Phone UI.
124
125 /**
126 * Allowable values for the wake lock code.
127 * SLEEP means the device can be put to sleep.
128 * PARTIAL means wake the processor, but we display can be kept off.
129 * FULL means wake both the processor and the display.
130 */
131 public enum WakeState {
132 SLEEP,
133 PARTIAL,
134 FULL
135 }
136
137 /**
138 * Intent Action used for hanging up the current call from Notification bar. This will
139 * choose first ringing call, first active call, or first background call (typically in
140 * HOLDING state).
141 */
142 public static final String ACTION_HANG_UP_ONGOING_CALL =
143 "com.android.phone.ACTION_HANG_UP_ONGOING_CALL";
144
145 /**
146 * Intent Action used for making a phone call from Notification bar.
147 * This is for missed call notifications.
148 */
149 public static final String ACTION_CALL_BACK_FROM_NOTIFICATION =
150 "com.android.phone.ACTION_CALL_BACK_FROM_NOTIFICATION";
151
152 /**
153 * Intent Action used for sending a SMS from notification bar.
154 * This is for missed call notifications.
155 */
156 public static final String ACTION_SEND_SMS_FROM_NOTIFICATION =
157 "com.android.phone.ACTION_SEND_SMS_FROM_NOTIFICATION";
158
159 private static PhoneGlobals sMe;
160
161 // A few important fields we expose to the rest of the package
162 // directly (rather than thru set/get methods) for efficiency.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700163 CallController callController;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700164 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700165 CallNotifier notifier;
166 CallerInfoCache callerInfoCache;
167 InCallUiState inCallUiState;
168 NotificationMgr notificationMgr;
169 Phone phone;
170 PhoneInterfaceManager phoneMgr;
171
Santos Cordon9b7bac72013-08-06 08:04:52 -0700172 private AudioRouter audioRouter;
Santos Cordon27a3c1f2013-08-06 07:49:27 -0700173 private BluetoothManager bluetoothManager;
Santos Cordon63a84242013-07-23 13:32:52 -0700174 private CallCommandService callCommandService;
Santos Cordon69a69192013-08-22 14:25:42 -0700175 private CallGatewayManager callGatewayManager;
Santos Cordon63a84242013-07-23 13:32:52 -0700176 private CallHandlerServiceProxy callHandlerServiceProxy;
177 private CallModeler callModeler;
178 private CallStateMonitor callStateMonitor;
Santos Cordon2eaff902013-08-05 04:37:55 -0700179 private DTMFTonePlayer dtmfTonePlayer;
Christine Chenee09a492013-08-06 16:02:29 -0700180 private RejectWithTextMessageManager rejectWithTextMessageManager;
Santos Cordon63a84242013-07-23 13:32:52 -0700181 private IBluetoothHeadsetPhone mBluetoothPhone;
182 private Ringer ringer;
Santos Cordon593ab382013-08-06 21:58:23 -0700183 private WiredHeadsetManager wiredHeadsetManager;
Santos Cordon63a84242013-07-23 13:32:52 -0700184
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185 static int mDockState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
186 static boolean sVoiceCapable = true;
187
188 // Internal PhoneApp Call state tracker
189 CdmaPhoneCallState cdmaPhoneCallState;
190
191 // The InCallScreen instance (or null if the InCallScreen hasn't been
192 // created yet.)
193 private InCallScreen mInCallScreen;
194
195 // The currently-active PUK entry activity and progress dialog.
196 // Normally, these are the Emergency Dialer and the subsequent
197 // progress dialog. null if there is are no such objects in
198 // the foreground.
199 private Activity mPUKEntryActivity;
200 private ProgressDialog mPUKEntryProgressDialog;
201
202 private boolean mIsSimPinEnabled;
203 private String mCachedSimPin;
204
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700205 // True if we are beginning a call, but the phone state has not changed yet
206 private boolean mBeginningCall;
207
208 // Last phone state seen by updatePhoneState()
209 private PhoneConstants.State mLastPhoneState = PhoneConstants.State.IDLE;
210
211 private WakeState mWakeState = WakeState.SLEEP;
212
213 private PowerManager mPowerManager;
214 private IPowerManager mPowerManagerService;
215 private PowerManager.WakeLock mWakeLock;
216 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700217 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700218
219 private UpdateLock mUpdateLock;
220
221 // Broadcast receiver for various intent broadcasts (see onCreate())
222 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
223
224 // Broadcast receiver purely for ACTION_MEDIA_BUTTON broadcasts
225 private final BroadcastReceiver mMediaButtonReceiver = new MediaButtonBroadcastReceiver();
226
227 /** boolean indicating restoring mute state on InCallScreen.onResume() */
228 private boolean mShouldRestoreMuteOnInCallResume;
229
230 /**
231 * The singleton OtaUtils instance used for OTASP calls.
232 *
233 * The OtaUtils instance is created lazily the first time we need to
234 * make an OTASP call, regardless of whether it's an interactive or
235 * non-interactive OTASP call.
236 */
237 public OtaUtils otaUtils;
238
239 // Following are the CDMA OTA information Objects used during OTA Call.
240 // cdmaOtaProvisionData object store static OTA information that needs
241 // to be maintained even during Slider open/close scenarios.
242 // cdmaOtaConfigData object stores configuration info to control visiblity
243 // of each OTA Screens.
244 // cdmaOtaScreenState object store OTA Screen State information.
245 public OtaUtils.CdmaOtaProvisionData cdmaOtaProvisionData;
246 public OtaUtils.CdmaOtaConfigData cdmaOtaConfigData;
247 public OtaUtils.CdmaOtaScreenState cdmaOtaScreenState;
248 public OtaUtils.CdmaOtaInCallScreenUiState cdmaOtaInCallScreenUiState;
249
250 // TTY feature enabled on this platform
251 private boolean mTtyEnabled;
252 // Current TTY operating mode selected by user
253 private int mPreferredTtyMode = Phone.TTY_MODE_OFF;
254
255 /**
256 * Set the restore mute state flag. Used when we are setting the mute state
257 * OUTSIDE of user interaction {@link PhoneUtils#startNewCall(Phone)}
258 */
259 /*package*/void setRestoreMuteOnInCallResume (boolean mode) {
260 mShouldRestoreMuteOnInCallResume = mode;
261 }
262
263 /**
264 * Get the restore mute state flag.
265 * This is used by the InCallScreen {@link InCallScreen#onResume()} to figure
266 * out if we need to restore the mute state for the current active call.
267 */
268 /*package*/boolean getRestoreMuteOnInCallResume () {
269 return mShouldRestoreMuteOnInCallResume;
270 }
271
272 Handler mHandler = new Handler() {
273 @Override
274 public void handleMessage(Message msg) {
275 PhoneConstants.State phoneState;
276 switch (msg.what) {
277 // Starts the SIP service. It's a no-op if SIP API is not supported
278 // on the deivce.
279 // TODO: Having the phone process host the SIP service is only
280 // temporary. Will move it to a persistent communication process
281 // later.
282 case EVENT_START_SIP_SERVICE:
283 SipService.start(getApplicationContext());
284 break;
285
286 // TODO: This event should be handled by the lock screen, just
287 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
288 case EVENT_SIM_NETWORK_LOCKED:
289 if (getResources().getBoolean(R.bool.ignore_sim_network_locked_events)) {
290 // Some products don't have the concept of a "SIM network lock"
291 Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; "
292 + "not showing 'SIM network unlock' PIN entry screen");
293 } else {
294 // Normal case: show the "SIM network unlock" PIN entry screen.
295 // The user won't be able to do anything else until
296 // they enter a valid SIM network PIN.
297 Log.i(LOG_TAG, "show sim depersonal panel");
298 IccNetworkDepersonalizationPanel ndpPanel =
299 new IccNetworkDepersonalizationPanel(PhoneGlobals.getInstance());
300 ndpPanel.show();
301 }
302 break;
303
304 case EVENT_UPDATE_INCALL_NOTIFICATION:
305 // Tell the NotificationMgr to update the "ongoing
306 // call" icon in the status bar, if necessary.
307 // Currently, this is triggered by a bluetooth headset
308 // state change (since the status bar icon needs to
309 // turn blue when bluetooth is active.)
310 if (DBG) Log.d (LOG_TAG, "- updating in-call notification from handler...");
311 notificationMgr.updateInCallNotification();
312 break;
313
314 case EVENT_DATA_ROAMING_DISCONNECTED:
315 notificationMgr.showDataDisconnectedRoaming();
316 break;
317
318 case EVENT_DATA_ROAMING_OK:
319 notificationMgr.hideDataDisconnectedRoaming();
320 break;
321
322 case MMI_COMPLETE:
323 onMMIComplete((AsyncResult) msg.obj);
324 break;
325
326 case MMI_CANCEL:
327 PhoneUtils.cancelMmiCode(phone);
328 break;
329
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700330 case EVENT_SIM_STATE_CHANGED:
331 // Marks the event where the SIM goes into ready state.
332 // Right now, this is only used for the PUK-unlocking
333 // process.
334 if (msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_READY)) {
335 // when the right event is triggered and there
336 // are UI objects in the foreground, we close
337 // them to display the lock panel.
338 if (mPUKEntryActivity != null) {
339 mPUKEntryActivity.finish();
340 mPUKEntryActivity = null;
341 }
342 if (mPUKEntryProgressDialog != null) {
343 mPUKEntryProgressDialog.dismiss();
344 mPUKEntryProgressDialog = null;
345 }
346 }
347 break;
348
349 case EVENT_UNSOL_CDMA_INFO_RECORD:
350 //TODO: handle message here;
351 break;
352
353 case EVENT_DOCK_STATE_CHANGED:
354 // If the phone is docked/undocked during a call, and no wired or BT headset
355 // is connected: turn on/off the speaker accordingly.
356 boolean inDockMode = false;
357 if (mDockState != Intent.EXTRA_DOCK_STATE_UNDOCKED) {
358 inDockMode = true;
359 }
360 if (VDBG) Log.d(LOG_TAG, "received EVENT_DOCK_STATE_CHANGED. Phone inDock = "
361 + inDockMode);
362
363 phoneState = mCM.getState();
364 if (phoneState == PhoneConstants.State.OFFHOOK &&
Santos Cordon593ab382013-08-06 21:58:23 -0700365 !wiredHeadsetManager.isHeadsetPlugged() &&
366 !bluetoothManager.isBluetoothHeadsetAudioOn()) {
367 audioRouter.setSpeaker(inDockMode);
368
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369 PhoneUtils.turnOnSpeaker(getApplicationContext(), inDockMode, true);
370 updateInCallScreen(); // Has no effect if the InCallScreen isn't visible
371 }
372 break;
373
374 case EVENT_TTY_PREFERRED_MODE_CHANGED:
375 // TTY mode is only applied if a headset is connected
376 int ttyMode;
Santos Cordon593ab382013-08-06 21:58:23 -0700377 if (wiredHeadsetManager.isHeadsetPlugged()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700378 ttyMode = mPreferredTtyMode;
379 } else {
380 ttyMode = Phone.TTY_MODE_OFF;
381 }
382 phone.setTTYMode(ttyMode, mHandler.obtainMessage(EVENT_TTY_MODE_SET));
383 break;
384
385 case EVENT_TTY_MODE_GET:
386 handleQueryTTYModeResponse(msg);
387 break;
388
389 case EVENT_TTY_MODE_SET:
390 handleSetTTYModeResponse(msg);
391 break;
392 }
393 }
394 };
395
396 public PhoneGlobals(Context context) {
397 super(context);
398 sMe = this;
399 }
400
401 public void onCreate() {
402 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
403
404 ContentResolver resolver = getContentResolver();
405
406 // Cache the "voice capable" flag.
407 // This flag currently comes from a resource (which is
408 // overrideable on a per-product basis):
409 sVoiceCapable =
410 getResources().getBoolean(com.android.internal.R.bool.config_voice_capable);
411 // ...but this might eventually become a PackageManager "system
412 // feature" instead, in which case we'd do something like:
413 // sVoiceCapable =
414 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
415
416 if (phone == null) {
417 // Initialize the telephony framework
418 PhoneFactory.makeDefaultPhones(this);
419
420 // Get the default phone
421 phone = PhoneFactory.getDefaultPhone();
422
423 // Start TelephonyDebugService After the default phone is created.
424 Intent intent = new Intent(this, TelephonyDebugService.class);
425 startService(intent);
426
427 mCM = CallManager.getInstance();
428 mCM.registerPhone(phone);
429
430 // Create the NotificationMgr singleton, which is used to display
431 // status bar icons and control other status bar behavior.
432 notificationMgr = NotificationMgr.init(this);
433
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434 mHandler.sendEmptyMessage(EVENT_START_SIP_SERVICE);
435
436 int phoneType = phone.getPhoneType();
437
438 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
439 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
440 cdmaPhoneCallState = new CdmaPhoneCallState();
441 cdmaPhoneCallState.CdmaPhoneCallStateInit();
442 }
443
444 if (BluetoothAdapter.getDefaultAdapter() != null) {
445 // Start BluetoothPhoneService even if device is not voice capable.
446 // The device can still support VOIP.
447 startService(new Intent(this, BluetoothPhoneService.class));
448 bindService(new Intent(this, BluetoothPhoneService.class),
449 mBluetoothPhoneConnection, 0);
450 } else {
451 // Device is not bluetooth capable
452 mBluetoothPhone = null;
453 }
454
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700455 // before registering for phone state changes
456 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
457 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
458 // lock used to keep the processor awake, when we don't care for the display.
459 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
460 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700461
462 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
463
464 // get a handle to the service so that we can use it later when we
465 // want to set the poke lock.
466 mPowerManagerService = IPowerManager.Stub.asInterface(
467 ServiceManager.getService("power"));
468
469 // Get UpdateLock to suppress system-update related events (e.g. dialog show-up)
470 // during phone calls.
471 mUpdateLock = new UpdateLock("phone");
472
473 if (DBG) Log.d(LOG_TAG, "onCreate: mUpdateLock: " + mUpdateLock);
474
475 CallLogger callLogger = new CallLogger(this, new CallLogAsync());
476
Santos Cordon69a69192013-08-22 14:25:42 -0700477 callGatewayManager = new CallGatewayManager();
478
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700479 // Create the CallController singleton, which is the interface
480 // to the telephony layer for user-initiated telephony functionality
481 // (like making outgoing calls.)
Santos Cordon69a69192013-08-22 14:25:42 -0700482 callController = CallController.init(this, callLogger, callGatewayManager);
483
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700484 // ...and also the InCallUiState instance, used by the CallController to
485 // keep track of some "persistent state" of the in-call UI.
486 inCallUiState = InCallUiState.init(this);
487
488 // Create the CallerInfoCache singleton, which remembers custom ring tone and
489 // send-to-voicemail settings.
490 //
491 // The asynchronous caching will start just after this call.
492 callerInfoCache = CallerInfoCache.init(this);
493
494 // Monitors call activity from the telephony layer
495 callStateMonitor = new CallStateMonitor(mCM);
496
Christine Chenee09a492013-08-06 16:02:29 -0700497 // Rejects calls with TextMessages
498 rejectWithTextMessageManager = new RejectWithTextMessageManager();
499
Santos Cordon63a84242013-07-23 13:32:52 -0700500 // Creates call models for use with CallHandlerService.
Santos Cordon69a69192013-08-22 14:25:42 -0700501 callModeler = new CallModeler(callStateMonitor, mCM, rejectWithTextMessageManager,
502 callGatewayManager);
Santos Cordon63a84242013-07-23 13:32:52 -0700503
Santos Cordon2eaff902013-08-05 04:37:55 -0700504 // Plays DTMF Tones
505 dtmfTonePlayer = new DTMFTonePlayer(mCM, callModeler);
506
Santos Cordon593ab382013-08-06 21:58:23 -0700507 // Manages wired headset state
508 wiredHeadsetManager = new WiredHeadsetManager(this);
509 wiredHeadsetManager.addWiredHeadsetListener(this);
510
Santos Cordon2c2d3cf2013-08-08 03:53:47 -0700511 // Bluetooth manager
512 bluetoothManager = new BluetoothManager(this, mCM, callModeler);
Santos Cordon2c2d3cf2013-08-08 03:53:47 -0700513
514 ringer = Ringer.init(this, bluetoothManager);
515
Santos Cordon9b7bac72013-08-06 08:04:52 -0700516 // Audio router
Santos Cordon593ab382013-08-06 21:58:23 -0700517 audioRouter = new AudioRouter(this, bluetoothManager, wiredHeadsetManager, mCM);
Santos Cordon9b7bac72013-08-06 08:04:52 -0700518
Santos Cordon249efd02013-08-05 03:33:56 -0700519 // Service used by in-call UI to control calls
Santos Cordon9b7bac72013-08-06 08:04:52 -0700520 callCommandService = new CallCommandService(this, mCM, callModeler, dtmfTonePlayer,
Christine Chenee09a492013-08-06 16:02:29 -0700521 audioRouter, rejectWithTextMessageManager);
Santos Cordon249efd02013-08-05 03:33:56 -0700522
Santos Cordon89647a62013-07-16 13:38:09 -0700523 // Sends call state to the UI
Santos Cordon63a84242013-07-23 13:32:52 -0700524 callHandlerServiceProxy = new CallHandlerServiceProxy(this, callModeler,
Santos Cordon593ab382013-08-06 21:58:23 -0700525 callCommandService, audioRouter);
Santos Cordon89647a62013-07-16 13:38:09 -0700526
Santos Cordon406c0342013-08-28 00:07:47 -0700527 phoneMgr = PhoneInterfaceManager.init(this, phone, callHandlerServiceProxy);
528
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700529 // Create the CallNotifer singleton, which handles
530 // asynchronous events from the telephony layer (like
531 // launching the incoming-call UI when an incoming call comes
532 // in.)
Santos Cordon27a3c1f2013-08-06 07:49:27 -0700533 notifier = CallNotifier.init(this, phone, ringer, callLogger, callStateMonitor,
534 bluetoothManager);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700535
536 // register for ICC status
537 IccCard sim = phone.getIccCard();
538 if (sim != null) {
539 if (VDBG) Log.v(LOG_TAG, "register for ICC status");
540 sim.registerForNetworkLocked(mHandler, EVENT_SIM_NETWORK_LOCKED, null);
541 }
542
543 // register for MMI/USSD
544 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
545
546 // register connection tracking to PhoneUtils
547 PhoneUtils.initializeConnectionHandler(mCM);
548
549 // Read platform settings for TTY feature
550 mTtyEnabled = getResources().getBoolean(R.bool.tty_enabled);
551
552 // Register for misc other intent broadcasts.
553 IntentFilter intentFilter =
554 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700555 intentFilter.addAction(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700556 intentFilter.addAction(Intent.ACTION_DOCK_EVENT);
557 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
558 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
559 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
560 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
561 if (mTtyEnabled) {
562 intentFilter.addAction(TtyIntent.TTY_PREFERRED_MODE_CHANGE_ACTION);
563 }
564 intentFilter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
565 registerReceiver(mReceiver, intentFilter);
566
567 // Use a separate receiver for ACTION_MEDIA_BUTTON broadcasts,
568 // since we need to manually adjust its priority (to make sure
569 // we get these intents *before* the media player.)
570 IntentFilter mediaButtonIntentFilter =
571 new IntentFilter(Intent.ACTION_MEDIA_BUTTON);
572 // TODO verify the independent priority doesn't need to be handled thanks to the
573 // private intent handler registration
574 // Make sure we're higher priority than the media player's
575 // MediaButtonIntentReceiver (which currently has the default
576 // priority of zero; see apps/Music/AndroidManifest.xml.)
577 mediaButtonIntentFilter.setPriority(1);
578 //
579 registerReceiver(mMediaButtonReceiver, mediaButtonIntentFilter);
580 // register the component so it gets priority for calls
581 AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
582 am.registerMediaButtonEventReceiverForCalls(new ComponentName(this.getPackageName(),
583 MediaButtonBroadcastReceiver.class.getName()));
584
585 //set the default values for the preferences in the phone.
586 PreferenceManager.setDefaultValues(this, R.xml.network_setting, false);
587
588 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
589
590 // Make sure the audio mode (along with some
591 // audio-mode-related state of our own) is initialized
592 // correctly, given the current state of the phone.
593 PhoneUtils.setAudioMode(mCM);
594 }
595
596 if (TelephonyCapabilities.supportsOtasp(phone)) {
597 cdmaOtaProvisionData = new OtaUtils.CdmaOtaProvisionData();
598 cdmaOtaConfigData = new OtaUtils.CdmaOtaConfigData();
599 cdmaOtaScreenState = new OtaUtils.CdmaOtaScreenState();
600 cdmaOtaInCallScreenUiState = new OtaUtils.CdmaOtaInCallScreenUiState();
601 }
602
603 // XXX pre-load the SimProvider so that it's ready
604 resolver.getType(Uri.parse("content://icc/adn"));
605
606 // start with the default value to set the mute state.
607 mShouldRestoreMuteOnInCallResume = false;
608
609 // TODO: Register for Cdma Information Records
610 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
611
612 // Read TTY settings and store it into BP NV.
613 // AP owns (i.e. stores) the TTY setting in AP settings database and pushes the setting
614 // to BP at power up (BP does not need to make the TTY setting persistent storage).
615 // This way, there is a single owner (i.e AP) for the TTY setting in the phone.
616 if (mTtyEnabled) {
617 mPreferredTtyMode = android.provider.Settings.Secure.getInt(
618 phone.getContext().getContentResolver(),
619 android.provider.Settings.Secure.PREFERRED_TTY_MODE,
620 Phone.TTY_MODE_OFF);
621 mHandler.sendMessage(mHandler.obtainMessage(EVENT_TTY_PREFERRED_MODE_CHANGED, 0));
622 }
623 // Read HAC settings and configure audio hardware
624 if (getResources().getBoolean(R.bool.hac_enabled)) {
625 int hac = android.provider.Settings.System.getInt(phone.getContext().getContentResolver(),
626 android.provider.Settings.System.HEARING_AID,
627 0);
628 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
629 audioManager.setParameter(CallFeaturesSetting.HAC_KEY, hac != 0 ?
630 CallFeaturesSetting.HAC_VAL_ON :
631 CallFeaturesSetting.HAC_VAL_OFF);
632 }
633 }
634
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700635 /**
636 * Returns the singleton instance of the PhoneApp.
637 */
638 static PhoneGlobals getInstance() {
639 if (sMe == null) {
640 throw new IllegalStateException("No PhoneGlobals here!");
641 }
642 return sMe;
643 }
644
645 /**
646 * Returns the singleton instance of the PhoneApp if running as the
647 * primary user, otherwise null.
648 */
649 static PhoneGlobals getInstanceIfPrimary() {
650 return sMe;
651 }
652
653 /**
654 * Returns the Phone associated with this instance
655 */
656 static Phone getPhone() {
657 return getInstance().phone;
658 }
659
660 Ringer getRinger() {
661 return ringer;
662 }
663
664 IBluetoothHeadsetPhone getBluetoothPhoneService() {
665 return mBluetoothPhone;
666 }
667
Santos Cordon27a3c1f2013-08-06 07:49:27 -0700668 /* package */ BluetoothManager getBluetoothManager() {
669 return bluetoothManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700670 }
671
Santos Cordon593ab382013-08-06 21:58:23 -0700672 /* package */ WiredHeadsetManager getWiredHeadsetManager() {
673 return wiredHeadsetManager;
674 }
675
676 /* package */ AudioRouter getAudioRouter() {
677 return audioRouter;
678 }
679
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700680 /**
681 * Returns an Intent that can be used to go to the "Call log"
682 * UI (aka CallLogActivity) in the Contacts app.
683 *
684 * Watch out: there's no guarantee that the system has any activity to
685 * handle this intent. (In particular there may be no "Call log" at
686 * all on on non-voice-capable devices.)
687 */
688 /* package */ static Intent createCallLogIntent() {
689 Intent intent = new Intent(Intent.ACTION_VIEW, null);
690 intent.setType("vnd.android.cursor.dir/calls");
691 return intent;
692 }
693
Yorke Leeca6ec3b2013-08-29 14:21:43 -0700694 /* package */static PendingIntent createPendingCallLogIntent(Context context) {
695 final Intent callLogIntent = PhoneGlobals.createCallLogIntent();
696 final TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
697 taskStackBuilder.addNextIntent(callLogIntent);
698 return taskStackBuilder.getPendingIntent(0, 0);
699 }
700
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700701 /**
702 * Return an Intent that can be used to bring up the in-call screen.
703 *
704 * This intent can only be used from within the Phone app, since the
705 * InCallScreen is not exported from our AndroidManifest.
706 */
707 /* package */ static Intent createInCallIntent() {
708 Intent intent = new Intent(Intent.ACTION_MAIN, null);
709 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
710 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
711 | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
712 intent.setClassName("com.android.phone", getCallScreenClassName());
713 return intent;
714 }
715
716 /**
717 * Variation of createInCallIntent() that also specifies whether the
718 * DTMF dialpad should be initially visible when the InCallScreen
719 * comes up.
720 */
721 /* package */ static Intent createInCallIntent(boolean showDialpad) {
722 Intent intent = createInCallIntent();
723 intent.putExtra(InCallScreen.SHOW_DIALPAD_EXTRA, showDialpad);
724 return intent;
725 }
726
727 /**
728 * Returns PendingIntent for hanging up ongoing phone call. This will typically be used from
729 * Notification context.
730 */
731 /* package */ static PendingIntent createHangUpOngoingCallPendingIntent(Context context) {
732 Intent intent = new Intent(PhoneGlobals.ACTION_HANG_UP_ONGOING_CALL, null,
733 context, NotificationBroadcastReceiver.class);
734 return PendingIntent.getBroadcast(context, 0, intent, 0);
735 }
736
737 /* package */ static PendingIntent getCallBackPendingIntent(Context context, String number) {
738 Intent intent = new Intent(ACTION_CALL_BACK_FROM_NOTIFICATION,
739 Uri.fromParts(Constants.SCHEME_TEL, number, null),
740 context, NotificationBroadcastReceiver.class);
741 return PendingIntent.getBroadcast(context, 0, intent, 0);
742 }
743
744 /* package */ static PendingIntent getSendSmsFromNotificationPendingIntent(
745 Context context, String number) {
746 Intent intent = new Intent(ACTION_SEND_SMS_FROM_NOTIFICATION,
747 Uri.fromParts(Constants.SCHEME_SMSTO, number, null),
748 context, NotificationBroadcastReceiver.class);
749 return PendingIntent.getBroadcast(context, 0, intent, 0);
750 }
751
752 private static String getCallScreenClassName() {
Chiao Cheng7f7c6522013-07-16 18:39:35 -0700753 //InCallScreen.class.getName();
754 return "blah";
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700755 }
756
757 /**
758 * Starts the InCallScreen Activity.
759 */
760 /* package */ void displayCallScreen() {
761 if (VDBG) Log.d(LOG_TAG, "displayCallScreen()...");
762
763 // On non-voice-capable devices we shouldn't ever be trying to
764 // bring up the InCallScreen in the first place.
765 if (!sVoiceCapable) {
766 Log.w(LOG_TAG, "displayCallScreen() not allowed: non-voice-capable device",
767 new Throwable("stack dump")); // Include a stack trace since this warning
768 // indicates a bug in our caller
769 return;
770 }
771
772 try {
Chiao Cheng7f7c6522013-07-16 18:39:35 -0700773 //startActivity(createInCallIntent());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700774 } catch (ActivityNotFoundException e) {
775 // It's possible that the in-call UI might not exist (like on
776 // non-voice-capable devices), so don't crash if someone
777 // accidentally tries to bring it up...
778 Log.w(LOG_TAG, "displayCallScreen: transition to InCallScreen failed: " + e);
779 }
780 Profiler.callScreenRequested();
781 }
782
783 boolean isSimPinEnabled() {
784 return mIsSimPinEnabled;
785 }
786
787 boolean authenticateAgainstCachedSimPin(String pin) {
788 return (mCachedSimPin != null && mCachedSimPin.equals(pin));
789 }
790
791 void setCachedSimPin(String pin) {
792 mCachedSimPin = pin;
793 }
794
795 void setInCallScreenInstance(InCallScreen inCallScreen) {
796 mInCallScreen = inCallScreen;
797 }
798
799 /**
800 * @return true if the in-call UI is running as the foreground
801 * activity. (In other words, from the perspective of the
802 * InCallScreen activity, return true between onResume() and
803 * onPause().)
804 *
805 * Note this method will return false if the screen is currently off,
806 * even if the InCallScreen *was* in the foreground just before the
807 * screen turned off. (This is because the foreground activity is
808 * always "paused" while the screen is off.)
809 */
810 boolean isShowingCallScreen() {
811 if (mInCallScreen == null) return false;
812 return mInCallScreen.isForegroundActivity();
813 }
814
815 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700816 * Dismisses the in-call UI.
817 *
818 * This also ensures that you won't be able to get back to the in-call
819 * UI via the BACK button (since this call removes the InCallScreen
820 * from the activity history.)
821 * For OTA Call, it call InCallScreen api to handle OTA Call End scenario
822 * to display OTA Call End screen.
823 */
824 /* package */ void dismissCallScreen() {
825 if (mInCallScreen != null) {
826 if ((TelephonyCapabilities.supportsOtasp(phone)) &&
827 (mInCallScreen.isOtaCallInActiveState()
828 || mInCallScreen.isOtaCallInEndState()
829 || ((cdmaOtaScreenState != null)
830 && (cdmaOtaScreenState.otaScreenState
831 != CdmaOtaScreenState.OtaScreenState.OTA_STATUS_UNDEFINED)))) {
832 // TODO: During OTA Call, display should not become dark to
833 // allow user to see OTA UI update. Phone app needs to hold
834 // a SCREEN_DIM_WAKE_LOCK wake lock during the entire OTA call.
835 wakeUpScreen();
836 // If InCallScreen is not in foreground we resume it to show the OTA call end screen
837 // Fire off the InCallScreen intent
838 displayCallScreen();
839
840 mInCallScreen.handleOtaCallEnd();
841 return;
842 } else {
843 mInCallScreen.finish();
844 }
845 }
846 }
847
848 /**
849 * Handles OTASP-related events from the telephony layer.
850 *
851 * While an OTASP call is active, the CallNotifier forwards
852 * OTASP-related telephony events to this method.
853 */
854 void handleOtaspEvent(Message msg) {
855 if (DBG) Log.d(LOG_TAG, "handleOtaspEvent(message " + msg + ")...");
856
857 if (otaUtils == null) {
858 // We shouldn't be getting OTASP events without ever
859 // having started the OTASP call in the first place!
860 Log.w(LOG_TAG, "handleOtaEvents: got an event but otaUtils is null! "
861 + "message = " + msg);
862 return;
863 }
864
865 otaUtils.onOtaProvisionStatusChanged((AsyncResult) msg.obj);
866 }
867
868 /**
869 * Similarly, handle the disconnect event of an OTASP call
870 * by forwarding it to the OtaUtils instance.
871 */
872 /* package */ void handleOtaspDisconnect() {
873 if (DBG) Log.d(LOG_TAG, "handleOtaspDisconnect()...");
874
875 if (otaUtils == null) {
876 // We shouldn't be getting OTASP events without ever
877 // having started the OTASP call in the first place!
878 Log.w(LOG_TAG, "handleOtaspDisconnect: otaUtils is null!");
879 return;
880 }
881
882 otaUtils.onOtaspDisconnect();
883 }
884
885 /**
886 * Sets the activity responsible for un-PUK-blocking the device
887 * so that we may close it when we receive a positive result.
888 * mPUKEntryActivity is also used to indicate to the device that
889 * we are trying to un-PUK-lock the phone. In other words, iff
890 * it is NOT null, then we are trying to unlock and waiting for
891 * the SIM to move to READY state.
892 *
893 * @param activity is the activity to close when PUK has
894 * finished unlocking. Can be set to null to indicate the unlock
895 * or SIM READYing process is over.
896 */
897 void setPukEntryActivity(Activity activity) {
898 mPUKEntryActivity = activity;
899 }
900
901 Activity getPUKEntryActivity() {
902 return mPUKEntryActivity;
903 }
904
905 /**
906 * Sets the dialog responsible for notifying the user of un-PUK-
907 * blocking - SIM READYing progress, so that we may dismiss it
908 * when we receive a positive result.
909 *
910 * @param dialog indicates the progress dialog informing the user
911 * of the state of the device. Dismissed upon completion of
912 * READYing process
913 */
914 void setPukEntryProgressDialog(ProgressDialog dialog) {
915 mPUKEntryProgressDialog = dialog;
916 }
917
918 ProgressDialog getPUKEntryProgressDialog() {
919 return mPUKEntryProgressDialog;
920 }
921
922 /**
923 * Controls whether or not the screen is allowed to sleep.
924 *
925 * Once sleep is allowed (WakeState is SLEEP), it will rely on the
926 * settings for the poke lock to determine when to timeout and let
927 * the device sleep {@link PhoneGlobals#setScreenTimeout}.
928 *
929 * @param ws tells the device to how to wake.
930 */
931 /* package */ void requestWakeState(WakeState ws) {
932 if (VDBG) Log.d(LOG_TAG, "requestWakeState(" + ws + ")...");
933 synchronized (this) {
934 if (mWakeState != ws) {
935 switch (ws) {
936 case PARTIAL:
937 // acquire the processor wake lock, and release the FULL
938 // lock if it is being held.
939 mPartialWakeLock.acquire();
940 if (mWakeLock.isHeld()) {
941 mWakeLock.release();
942 }
943 break;
944 case FULL:
945 // acquire the full wake lock, and release the PARTIAL
946 // lock if it is being held.
947 mWakeLock.acquire();
948 if (mPartialWakeLock.isHeld()) {
949 mPartialWakeLock.release();
950 }
951 break;
952 case SLEEP:
953 default:
954 // release both the PARTIAL and FULL locks.
955 if (mWakeLock.isHeld()) {
956 mWakeLock.release();
957 }
958 if (mPartialWakeLock.isHeld()) {
959 mPartialWakeLock.release();
960 }
961 break;
962 }
963 mWakeState = ws;
964 }
965 }
966 }
967
968 /**
969 * If we are not currently keeping the screen on, then poke the power
970 * manager to wake up the screen for the user activity timeout duration.
971 */
972 /* package */ void wakeUpScreen() {
973 synchronized (this) {
974 if (mWakeState == WakeState.SLEEP) {
975 if (DBG) Log.d(LOG_TAG, "pulse screen lock");
976 mPowerManager.wakeUp(SystemClock.uptimeMillis());
977 }
978 }
979 }
980
981 /**
982 * Sets the wake state and screen timeout based on the current state
983 * of the phone, and the current state of the in-call UI.
984 *
985 * This method is a "UI Policy" wrapper around
986 * {@link PhoneGlobals#requestWakeState} and {@link PhoneGlobals#setScreenTimeout}.
987 *
988 * It's safe to call this method regardless of the state of the Phone
989 * (e.g. whether or not it's idle), and regardless of the state of the
990 * Phone UI (e.g. whether or not the InCallScreen is active.)
991 */
992 /* package */ void updateWakeState() {
993 PhoneConstants.State state = mCM.getState();
994
995 // True if the in-call UI is the foreground activity.
996 // (Note this will be false if the screen is currently off,
997 // since in that case *no* activity is in the foreground.)
998 boolean isShowingCallScreen = isShowingCallScreen();
999
1000 // True if the InCallScreen's DTMF dialer is currently opened.
1001 // (Note this does NOT imply whether or not the InCallScreen
1002 // itself is visible.)
1003 boolean isDialerOpened = (mInCallScreen != null) && mInCallScreen.isDialerOpened();
1004
1005 // True if the speakerphone is in use. (If so, we *always* use
1006 // the default timeout. Since the user is obviously not holding
1007 // the phone up to his/her face, we don't need to worry about
1008 // false touches, and thus don't need to turn the screen off so
1009 // aggressively.)
1010 // Note that we need to make a fresh call to this method any
1011 // time the speaker state changes. (That happens in
1012 // PhoneUtils.turnOnSpeaker().)
1013 boolean isSpeakerInUse = (state == PhoneConstants.State.OFFHOOK) && PhoneUtils.isSpeakerOn(this);
1014
1015 // TODO (bug 1440854): The screen timeout *might* also need to
1016 // depend on the bluetooth state, but this isn't as clear-cut as
1017 // the speaker state (since while using BT it's common for the
1018 // user to put the phone straight into a pocket, in which case the
1019 // timeout should probably still be short.)
1020
1021 if (DBG) Log.d(LOG_TAG, "updateWakeState: callscreen " + isShowingCallScreen
1022 + ", dialer " + isDialerOpened
1023 + ", speaker " + isSpeakerInUse + "...");
1024
1025 //
1026 // Decide whether to force the screen on or not.
1027 //
1028 // Force the screen to be on if the phone is ringing or dialing,
1029 // or if we're displaying the "Call ended" UI for a connection in
1030 // the "disconnected" state.
1031 // However, if the phone is disconnected while the user is in the
1032 // middle of selecting a quick response message, we should not force
1033 // the screen to be on.
1034 //
1035 boolean isRinging = (state == PhoneConstants.State.RINGING);
1036 boolean isDialing = (phone.getForegroundCall().getState() == Call.State.DIALING);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001037 boolean showingDisconnectedConnection =
1038 PhoneUtils.hasDisconnectedConnections(phone) && isShowingCallScreen;
Christine Chen0ce0e852013-08-09 18:26:31 -07001039 boolean keepScreenOn = isRinging || isDialing || showingDisconnectedConnection;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001040 if (DBG) Log.d(LOG_TAG, "updateWakeState: keepScreenOn = " + keepScreenOn
1041 + " (isRinging " + isRinging
1042 + ", isDialing " + isDialing
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001043 + ", showingDisc " + showingDisconnectedConnection + ")");
1044 // keepScreenOn == true means we'll hold a full wake lock:
1045 requestWakeState(keepScreenOn ? WakeState.FULL : WakeState.SLEEP);
1046 }
1047
1048 /**
1049 * Manually pokes the PowerManager's userActivity method. Since we
1050 * set the {@link WindowManager.LayoutParams#INPUT_FEATURE_DISABLE_USER_ACTIVITY}
1051 * flag while the InCallScreen is active when there is no proximity sensor,
1052 * we need to do this for touch events that really do count as user activity
1053 * (like pressing any onscreen UI elements.)
1054 */
1055 /* package */ void pokeUserActivity() {
1056 if (VDBG) Log.d(LOG_TAG, "pokeUserActivity()...");
1057 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
1058 }
1059
1060 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001061 * Notifies the phone app when the phone state changes.
1062 *
Santos Cordonfc309812013-08-20 18:33:16 -07001063 * This method will updates various states inside Phone app (e.g. update-lock state, etc.)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001064 */
1065 /* package */ void updatePhoneState(PhoneConstants.State state) {
1066 if (state != mLastPhoneState) {
1067 mLastPhoneState = state;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001068
1069 // Try to acquire or release UpdateLock.
1070 //
1071 // Watch out: we don't release the lock here when the screen is still in foreground.
1072 // At that time InCallScreen will release it on onPause().
1073 if (state != PhoneConstants.State.IDLE) {
1074 // UpdateLock is a recursive lock, while we may get "acquire" request twice and
1075 // "release" request once for a single call (RINGING + OFFHOOK and IDLE).
1076 // We need to manually ensure the lock is just acquired once for each (and this
1077 // will prevent other possible buggy situations too).
1078 if (!mUpdateLock.isHeld()) {
1079 mUpdateLock.acquire();
1080 }
1081 } else {
1082 if (!isShowingCallScreen()) {
1083 if (!mUpdateLock.isHeld()) {
1084 mUpdateLock.release();
1085 }
1086 } else {
1087 // For this case InCallScreen will take care of the release() call.
1088 }
1089 }
1090
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001091 // While we are in call, the in-call screen should dismiss the keyguard.
1092 // This allows the user to press Home to go directly home without going through
1093 // an insecure lock screen.
1094 // But we do not want to do this if there is no active call so we do not
1095 // bypass the keyguard if the call is not answered or declined.
1096 if (mInCallScreen != null) {
1097 mInCallScreen.updateKeyguardPolicy(state == PhoneConstants.State.OFFHOOK);
1098 }
1099 }
1100 }
1101
1102 /* package */ PhoneConstants.State getPhoneState() {
1103 return mLastPhoneState;
1104 }
1105
1106 /**
1107 * Returns UpdateLock object.
1108 */
1109 /* package */ UpdateLock getUpdateLock() {
1110 return mUpdateLock;
1111 }
1112
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001113 KeyguardManager getKeyguardManager() {
1114 return mKeyguardManager;
1115 }
1116
1117 private void onMMIComplete(AsyncResult r) {
1118 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
1119 MmiCode mmiCode = (MmiCode) r.result;
1120 PhoneUtils.displayMMIComplete(phone, getInstance(), mmiCode, null, null);
1121 }
1122
1123 private void initForNewRadioTechnology() {
1124 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
1125
1126 if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1127 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
1128 cdmaPhoneCallState = new CdmaPhoneCallState();
1129 cdmaPhoneCallState.CdmaPhoneCallStateInit();
1130 }
1131 if (TelephonyCapabilities.supportsOtasp(phone)) {
1132 //create instances of CDMA OTA data classes
1133 if (cdmaOtaProvisionData == null) {
1134 cdmaOtaProvisionData = new OtaUtils.CdmaOtaProvisionData();
1135 }
1136 if (cdmaOtaConfigData == null) {
1137 cdmaOtaConfigData = new OtaUtils.CdmaOtaConfigData();
1138 }
1139 if (cdmaOtaScreenState == null) {
1140 cdmaOtaScreenState = new OtaUtils.CdmaOtaScreenState();
1141 }
1142 if (cdmaOtaInCallScreenUiState == null) {
1143 cdmaOtaInCallScreenUiState = new OtaUtils.CdmaOtaInCallScreenUiState();
1144 }
1145 } else {
1146 //Clean up OTA data in GSM/UMTS. It is valid only for CDMA
1147 clearOtaState();
1148 }
1149
1150 ringer.updateRingerContextAfterRadioTechnologyChange(this.phone);
1151 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
1152 callStateMonitor.updateAfterRadioTechnologyChange();
1153
1154 if (mBluetoothPhone != null) {
1155 try {
1156 mBluetoothPhone.updateBtHandsfreeAfterRadioTechnologyChange();
1157 } catch (RemoteException e) {
1158 Log.e(LOG_TAG, Log.getStackTraceString(new Throwable()));
1159 }
1160 }
1161 if (mInCallScreen != null) {
1162 mInCallScreen.updateAfterRadioTechnologyChange();
1163 }
1164
1165 // Update registration for ICC status after radio technology change
1166 IccCard sim = phone.getIccCard();
1167 if (sim != null) {
1168 if (DBG) Log.d(LOG_TAG, "Update registration for ICC status...");
1169
1170 //Register all events new to the new active phone
1171 sim.registerForNetworkLocked(mHandler, EVENT_SIM_NETWORK_LOCKED, null);
1172 }
1173 }
1174
1175
1176 /**
Santos Cordon593ab382013-08-06 21:58:23 -07001177 * This is called when the wired headset state changes.
1178 */
1179 @Override
1180 public void onWiredHeadsetConnection(boolean pluggedIn) {
1181 PhoneConstants.State phoneState = mCM.getState();
1182
Santos Cordon593ab382013-08-06 21:58:23 -07001183 // Force TTY state update according to new headset state
1184 if (mTtyEnabled) {
1185 mHandler.sendMessage(mHandler.obtainMessage(EVENT_TTY_PREFERRED_MODE_CHANGED, 0));
1186 }
1187 }
1188
1189 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001190 * Receiver for misc intent broadcasts the Phone app cares about.
1191 */
1192 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
1193 @Override
1194 public void onReceive(Context context, Intent intent) {
1195 String action = intent.getAction();
1196 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
1197 boolean enabled = System.getInt(getContentResolver(),
1198 System.AIRPLANE_MODE_ON, 0) == 0;
1199 phone.setRadioPower(enabled);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001200 } else if (action.equals(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) {
1201 if (VDBG) Log.d(LOG_TAG, "mReceiver: ACTION_ANY_DATA_CONNECTION_STATE_CHANGED");
1202 if (VDBG) Log.d(LOG_TAG, "- state: " + intent.getStringExtra(PhoneConstants.STATE_KEY));
1203 if (VDBG) Log.d(LOG_TAG, "- reason: "
1204 + intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY));
1205
1206 // The "data disconnected due to roaming" notification is shown
1207 // if (a) you have the "data roaming" feature turned off, and
1208 // (b) you just lost data connectivity because you're roaming.
1209 boolean disconnectedDueToRoaming =
1210 !phone.getDataRoamingEnabled()
1211 && "DISCONNECTED".equals(intent.getStringExtra(PhoneConstants.STATE_KEY))
1212 && Phone.REASON_ROAMING_ON.equals(
1213 intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY));
1214 mHandler.sendEmptyMessage(disconnectedDueToRoaming
1215 ? EVENT_DATA_ROAMING_DISCONNECTED
1216 : EVENT_DATA_ROAMING_OK);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001217 } else if ((action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) &&
1218 (mPUKEntryActivity != null)) {
1219 // if an attempt to un-PUK-lock the device was made, while we're
1220 // receiving this state change notification, notify the handler.
1221 // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has
1222 // been attempted.
1223 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
1224 intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE)));
1225 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
1226 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
1227 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
1228 initForNewRadioTechnology();
1229 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
1230 handleServiceStateChanged(intent);
1231 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
1232 if (TelephonyCapabilities.supportsEcm(phone)) {
1233 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
1234 // Start Emergency Callback Mode service
1235 if (intent.getBooleanExtra("phoneinECMState", false)) {
1236 context.startService(new Intent(context,
1237 EmergencyCallbackModeService.class));
1238 }
1239 } else {
1240 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
1241 // on a device that doesn't support ECM in the first place.
1242 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, "
1243 + "but ECM isn't supported for phone: " + phone.getPhoneName());
1244 }
1245 } else if (action.equals(Intent.ACTION_DOCK_EVENT)) {
1246 mDockState = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1247 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1248 if (VDBG) Log.d(LOG_TAG, "ACTION_DOCK_EVENT -> mDockState = " + mDockState);
1249 mHandler.sendMessage(mHandler.obtainMessage(EVENT_DOCK_STATE_CHANGED, 0));
1250 } else if (action.equals(TtyIntent.TTY_PREFERRED_MODE_CHANGE_ACTION)) {
1251 mPreferredTtyMode = intent.getIntExtra(TtyIntent.TTY_PREFFERED_MODE,
1252 Phone.TTY_MODE_OFF);
1253 if (VDBG) Log.d(LOG_TAG, "mReceiver: TTY_PREFERRED_MODE_CHANGE_ACTION");
1254 if (VDBG) Log.d(LOG_TAG, " mode: " + mPreferredTtyMode);
1255 mHandler.sendMessage(mHandler.obtainMessage(EVENT_TTY_PREFERRED_MODE_CHANGED, 0));
1256 } else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
1257 int ringerMode = intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE,
1258 AudioManager.RINGER_MODE_NORMAL);
1259 if (ringerMode == AudioManager.RINGER_MODE_SILENT) {
1260 notifier.silenceRinger();
1261 }
1262 }
1263 }
1264 }
1265
1266 /**
1267 * Broadcast receiver for the ACTION_MEDIA_BUTTON broadcast intent.
1268 *
1269 * This functionality isn't lumped in with the other intents in
1270 * PhoneAppBroadcastReceiver because we instantiate this as a totally
1271 * separate BroadcastReceiver instance, since we need to manually
1272 * adjust its IntentFilter's priority (to make sure we get these
1273 * intents *before* the media player.)
1274 */
1275 private class MediaButtonBroadcastReceiver extends BroadcastReceiver {
1276 @Override
1277 public void onReceive(Context context, Intent intent) {
1278 KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
1279 if (VDBG) Log.d(LOG_TAG,
1280 "MediaButtonBroadcastReceiver.onReceive()... event = " + event);
1281 if ((event != null)
1282 && (event.getKeyCode() == KeyEvent.KEYCODE_HEADSETHOOK)) {
1283 if (VDBG) Log.d(LOG_TAG, "MediaButtonBroadcastReceiver: HEADSETHOOK");
1284 boolean consumed = PhoneUtils.handleHeadsetHook(phone, event);
1285 if (VDBG) Log.d(LOG_TAG, "==> handleHeadsetHook(): consumed = " + consumed);
1286 if (consumed) {
1287 // If a headset is attached and the press is consumed, also update
1288 // any UI items (such as an InCallScreen mute button) that may need to
1289 // be updated if their state changed.
1290 updateInCallScreen(); // Has no effect if the InCallScreen isn't visible
1291 abortBroadcast();
1292 }
1293 } else {
1294 if (mCM.getState() != PhoneConstants.State.IDLE) {
1295 // If the phone is anything other than completely idle,
1296 // then we consume and ignore any media key events,
1297 // Otherwise it is too easy to accidentally start
1298 // playing music while a phone call is in progress.
1299 if (VDBG) Log.d(LOG_TAG, "MediaButtonBroadcastReceiver: consumed");
1300 abortBroadcast();
1301 }
1302 }
1303 }
1304 }
1305
1306 /**
1307 * Accepts broadcast Intents which will be prepared by {@link NotificationMgr} and thus
1308 * sent from framework's notification mechanism (which is outside Phone context).
1309 * This should be visible from outside, but shouldn't be in "exported" state.
1310 *
1311 * TODO: If possible merge this into PhoneAppBroadcastReceiver.
1312 */
1313 public static class NotificationBroadcastReceiver extends BroadcastReceiver {
1314 @Override
1315 public void onReceive(Context context, Intent intent) {
1316 String action = intent.getAction();
1317 // TODO: use "if (VDBG)" here.
1318 Log.d(LOG_TAG, "Broadcast from Notification: " + action);
1319
1320 if (action.equals(ACTION_HANG_UP_ONGOING_CALL)) {
1321 PhoneUtils.hangup(PhoneGlobals.getInstance().mCM);
1322 } else if (action.equals(ACTION_CALL_BACK_FROM_NOTIFICATION)) {
1323 // Collapse the expanded notification and the notification item itself.
1324 closeSystemDialogs(context);
1325 clearMissedCallNotification(context);
1326
1327 Intent callIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED, intent.getData());
1328 callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1329 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1330 context.startActivity(callIntent);
1331 } else if (action.equals(ACTION_SEND_SMS_FROM_NOTIFICATION)) {
1332 // Collapse the expanded notification and the notification item itself.
1333 closeSystemDialogs(context);
1334 clearMissedCallNotification(context);
1335
1336 Intent smsIntent = new Intent(Intent.ACTION_SENDTO, intent.getData());
1337 smsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1338 context.startActivity(smsIntent);
1339 } else {
1340 Log.w(LOG_TAG, "Received hang-up request from notification,"
1341 + " but there's no call the system can hang up.");
1342 }
1343 }
1344
1345 private void closeSystemDialogs(Context context) {
1346 Intent intent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
1347 context.sendBroadcastAsUser(intent, UserHandle.ALL);
1348 }
1349
1350 private void clearMissedCallNotification(Context context) {
1351 Intent clearIntent = new Intent(context, ClearMissedCallsService.class);
1352 clearIntent.setAction(ClearMissedCallsService.ACTION_CLEAR_MISSED_CALLS);
1353 context.startService(clearIntent);
1354 }
1355 }
1356
1357 private void handleServiceStateChanged(Intent intent) {
1358 /**
1359 * This used to handle updating EriTextWidgetProvider this routine
1360 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
1361 * be removed. But leaving just in case it might be needed in the near
1362 * future.
1363 */
1364
1365 // If service just returned, start sending out the queued messages
1366 ServiceState ss = ServiceState.newFromBundle(intent.getExtras());
1367
1368 if (ss != null) {
1369 int state = ss.getState();
1370 notificationMgr.updateNetworkSelection(state);
1371 }
1372 }
1373
1374 public boolean isOtaCallInActiveState() {
1375 boolean otaCallActive = false;
1376 if (mInCallScreen != null) {
1377 otaCallActive = mInCallScreen.isOtaCallInActiveState();
1378 }
1379 if (VDBG) Log.d(LOG_TAG, "- isOtaCallInActiveState " + otaCallActive);
1380 return otaCallActive;
1381 }
1382
1383 public boolean isOtaCallInEndState() {
1384 boolean otaCallEnded = false;
1385 if (mInCallScreen != null) {
1386 otaCallEnded = mInCallScreen.isOtaCallInEndState();
1387 }
1388 if (VDBG) Log.d(LOG_TAG, "- isOtaCallInEndState " + otaCallEnded);
1389 return otaCallEnded;
1390 }
1391
1392 // it is safe to call clearOtaState() even if the InCallScreen isn't active
1393 public void clearOtaState() {
1394 if (DBG) Log.d(LOG_TAG, "- clearOtaState ...");
1395 if ((mInCallScreen != null)
1396 && (otaUtils != null)) {
1397 otaUtils.cleanOtaScreen(true);
1398 if (DBG) Log.d(LOG_TAG, " - clearOtaState clears OTA screen");
1399 }
1400 }
1401
1402 // it is safe to call dismissOtaDialogs() even if the InCallScreen isn't active
1403 public void dismissOtaDialogs() {
1404 if (DBG) Log.d(LOG_TAG, "- dismissOtaDialogs ...");
1405 if ((mInCallScreen != null)
1406 && (otaUtils != null)) {
1407 otaUtils.dismissAllOtaDialogs();
1408 if (DBG) Log.d(LOG_TAG, " - dismissOtaDialogs clears OTA dialogs");
1409 }
1410 }
1411
1412 // it is safe to call clearInCallScreenMode() even if the InCallScreen isn't active
1413 public void clearInCallScreenMode() {
1414 if (DBG) Log.d(LOG_TAG, "- clearInCallScreenMode ...");
1415 if (mInCallScreen != null) {
1416 mInCallScreen.resetInCallScreenMode();
1417 }
1418 }
1419
1420 /**
1421 * Force the in-call UI to refresh itself, if it's currently visible.
1422 *
1423 * This method can be used any time there's a state change anywhere in
1424 * the phone app that needs to be reflected in the onscreen UI.
1425 *
1426 * Note that it's *not* necessary to manually refresh the in-call UI
1427 * (via this method) for regular telephony state changes like
1428 * DIALING -> ALERTING -> ACTIVE, since the InCallScreen already
1429 * listens for those state changes itself.
1430 *
1431 * This method does *not* force the in-call UI to come up if it's not
1432 * already visible. To do that, use displayCallScreen().
1433 */
1434 /* package */ void updateInCallScreen() {
1435 if (DBG) Log.d(LOG_TAG, "- updateInCallScreen()...");
1436 if (mInCallScreen != null) {
1437 // Post an updateScreen() request. Note that the
1438 // updateScreen() call will end up being a no-op if the
1439 // InCallScreen isn't the foreground activity.
1440 mInCallScreen.requestUpdateScreen();
1441 }
1442 }
1443
1444 private void handleQueryTTYModeResponse(Message msg) {
1445 AsyncResult ar = (AsyncResult) msg.obj;
1446 if (ar.exception != null) {
1447 if (DBG) Log.d(LOG_TAG, "handleQueryTTYModeResponse: Error getting TTY state.");
1448 } else {
1449 if (DBG) Log.d(LOG_TAG,
1450 "handleQueryTTYModeResponse: TTY enable state successfully queried.");
1451
1452 int ttymode = ((int[]) ar.result)[0];
1453 if (DBG) Log.d(LOG_TAG, "handleQueryTTYModeResponse:ttymode=" + ttymode);
1454
1455 Intent ttyModeChanged = new Intent(TtyIntent.TTY_ENABLED_CHANGE_ACTION);
1456 ttyModeChanged.putExtra("ttyEnabled", ttymode != Phone.TTY_MODE_OFF);
1457 sendBroadcastAsUser(ttyModeChanged, UserHandle.ALL);
1458
1459 String audioTtyMode;
1460 switch (ttymode) {
1461 case Phone.TTY_MODE_FULL:
1462 audioTtyMode = "tty_full";
1463 break;
1464 case Phone.TTY_MODE_VCO:
1465 audioTtyMode = "tty_vco";
1466 break;
1467 case Phone.TTY_MODE_HCO:
1468 audioTtyMode = "tty_hco";
1469 break;
1470 case Phone.TTY_MODE_OFF:
1471 default:
1472 audioTtyMode = "tty_off";
1473 break;
1474 }
1475 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
1476 audioManager.setParameters("tty_mode="+audioTtyMode);
1477 }
1478 }
1479
1480 private void handleSetTTYModeResponse(Message msg) {
1481 AsyncResult ar = (AsyncResult) msg.obj;
1482
1483 if (ar.exception != null) {
1484 if (DBG) Log.d (LOG_TAG,
1485 "handleSetTTYModeResponse: Error setting TTY mode, ar.exception"
1486 + ar.exception);
1487 }
1488 phone.queryTTYMode(mHandler.obtainMessage(EVENT_TTY_MODE_GET));
1489 }
1490
1491 /**
1492 * "Call origin" may be used by Contacts app to specify where the phone call comes from.
1493 * Currently, the only permitted value for this extra is {@link #ALLOWED_EXTRA_CALL_ORIGIN}.
1494 * Any other value will be ignored, to make sure that malicious apps can't trick the in-call
1495 * UI into launching some random other app after a call ends.
1496 *
1497 * TODO: make this more generic. Note that we should let the "origin" specify its package
1498 * while we are now assuming it is "com.android.contacts"
1499 */
1500 public static final String EXTRA_CALL_ORIGIN = "com.android.phone.CALL_ORIGIN";
1501 private static final String DEFAULT_CALL_ORIGIN_PACKAGE = "com.android.dialer";
1502 private static final String ALLOWED_EXTRA_CALL_ORIGIN =
1503 "com.android.dialer.DialtactsActivity";
1504 /**
1505 * Used to determine if the preserved call origin is fresh enough.
1506 */
1507 private static final long CALL_ORIGIN_EXPIRATION_MILLIS = 30 * 1000;
1508
1509 public void setLatestActiveCallOrigin(String callOrigin) {
1510 inCallUiState.latestActiveCallOrigin = callOrigin;
1511 if (callOrigin != null) {
1512 inCallUiState.latestActiveCallOriginTimeStamp = SystemClock.elapsedRealtime();
1513 } else {
1514 inCallUiState.latestActiveCallOriginTimeStamp = 0;
1515 }
1516 }
1517
1518 /**
1519 * Reset call origin depending on its timestamp.
1520 *
1521 * See if the current call origin preserved by the app is fresh enough or not. If it is,
1522 * previous call origin will be used as is. If not, call origin will be reset.
1523 *
1524 * This will be effective especially for 3rd party apps which want to bypass phone calls with
1525 * their own telephone lines. In that case Phone app may finish the phone call once and make
1526 * another for the external apps, which will drop call origin information in Intent.
1527 * Even in that case we are sure the second phone call should be initiated just after the first
1528 * phone call, so here we restore it from the previous information iff the second call is done
1529 * fairly soon.
1530 */
1531 public void resetLatestActiveCallOrigin() {
1532 final long callOriginTimestamp = inCallUiState.latestActiveCallOriginTimeStamp;
1533 final long currentTimestamp = SystemClock.elapsedRealtime();
1534 if (VDBG) {
1535 Log.d(LOG_TAG, "currentTimeMillis: " + currentTimestamp
1536 + ", saved timestamp for call origin: " + callOriginTimestamp);
1537 }
1538 if (inCallUiState.latestActiveCallOriginTimeStamp > 0
1539 && (currentTimestamp - callOriginTimestamp < CALL_ORIGIN_EXPIRATION_MILLIS)) {
1540 if (VDBG) {
1541 Log.d(LOG_TAG, "Resume previous call origin (" +
1542 inCallUiState.latestActiveCallOrigin + ")");
1543 }
1544 // Do nothing toward call origin itself but update the timestamp just in case.
1545 inCallUiState.latestActiveCallOriginTimeStamp = currentTimestamp;
1546 } else {
1547 if (VDBG) Log.d(LOG_TAG, "Drop previous call origin and set the current one to null");
1548 setLatestActiveCallOrigin(null);
1549 }
1550 }
1551
1552 /**
1553 * @return Intent which will be used when in-call UI is shown and the phone call is hang up.
1554 * By default CallLog screen will be introduced, but the destination may change depending on
1555 * its latest call origin state.
1556 */
1557 public Intent createPhoneEndIntentUsingCallOrigin() {
1558 if (TextUtils.equals(inCallUiState.latestActiveCallOrigin, ALLOWED_EXTRA_CALL_ORIGIN)) {
1559 if (VDBG) Log.d(LOG_TAG, "Valid latestActiveCallOrigin("
1560 + inCallUiState.latestActiveCallOrigin + ") was found. "
1561 + "Go back to the previous screen.");
1562 // Right now we just launch the Activity which launched in-call UI. Note that we're
1563 // assuming the origin is from "com.android.dialer", which may be incorrect in the
1564 // future.
1565 final Intent intent = new Intent();
1566 intent.setClassName(DEFAULT_CALL_ORIGIN_PACKAGE, inCallUiState.latestActiveCallOrigin);
1567 return intent;
1568 } else {
1569 if (VDBG) Log.d(LOG_TAG, "Current latestActiveCallOrigin ("
1570 + inCallUiState.latestActiveCallOrigin + ") is not valid. "
1571 + "Just use CallLog as a default destination.");
1572 return PhoneGlobals.createCallLogIntent();
1573 }
1574 }
1575
1576 /** Service connection */
1577 private final ServiceConnection mBluetoothPhoneConnection = new ServiceConnection() {
1578
1579 /** Handle the task of binding the local object to the service */
1580 public void onServiceConnected(ComponentName className, IBinder service) {
1581 Log.i(LOG_TAG, "Headset phone created, binding local service.");
1582 mBluetoothPhone = IBluetoothHeadsetPhone.Stub.asInterface(service);
1583 }
1584
1585 /** Handle the task of cleaning up the local binding */
1586 public void onServiceDisconnected(ComponentName className) {
1587 Log.i(LOG_TAG, "Headset phone disconnected, cleaning local binding.");
1588 mBluetoothPhone = null;
1589 }
1590 };
1591}