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