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