blob: 7e26c0ee4df0c1d063023a186486a8323c6eb422 [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070026import 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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070034import android.media.AudioManager;
35import android.net.Uri;
36import android.os.AsyncResult;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.os.Handler;
38import android.os.IBinder;
39import android.os.IPowerManager;
40import android.os.Message;
41import android.os.PowerManager;
42import android.os.RemoteException;
43import android.os.ServiceManager;
44import android.os.SystemClock;
45import android.os.SystemProperties;
46import android.os.UpdateLock;
47import android.os.UserHandle;
48import android.preference.PreferenceManager;
49import android.provider.Settings.System;
50import android.telephony.ServiceState;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import android.util.Log;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052
53import com.android.internal.telephony.Call;
54import com.android.internal.telephony.CallManager;
55import com.android.internal.telephony.IccCard;
56import com.android.internal.telephony.IccCardConstants;
57import com.android.internal.telephony.MmiCode;
58import com.android.internal.telephony.Phone;
59import com.android.internal.telephony.PhoneConstants;
60import com.android.internal.telephony.PhoneFactory;
61import com.android.internal.telephony.TelephonyCapabilities;
62import com.android.internal.telephony.TelephonyIntents;
63import com.android.internal.telephony.cdma.TtyIntent;
Santos Cordon593ab382013-08-06 21:58:23 -070064import com.android.phone.WiredHeadsetManager.WiredHeadsetListener;
Santos Cordon352ff652014-05-30 01:41:45 -070065import com.android.phone.common.CallLogAsync;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066import com.android.server.sip.SipService;
67
68/**
69 * Global state for the telephony subsystem when running in the primary
70 * phone process.
71 */
Santos Cordonfc309812013-08-20 18:33:16 -070072public class PhoneGlobals extends ContextWrapper implements WiredHeadsetListener {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073 /* package */ static final String LOG_TAG = "PhoneApp";
74
75 /**
76 * Phone app-wide debug level:
77 * 0 - no debug logging
78 * 1 - normal debug logging if ro.debuggable is set (which is true in
79 * "eng" and "userdebug" builds but not "user" builds)
80 * 2 - ultra-verbose debug logging
81 *
82 * Most individual classes in the phone app have a local DBG constant,
83 * typically set to
84 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
85 * or else
86 * (PhoneApp.DBG_LEVEL >= 2)
87 * depending on the desired verbosity.
88 *
89 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
90 */
91 /* package */ static final int DBG_LEVEL = 0;
92
93 private static final boolean DBG =
94 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
95 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
96
97 // Message codes; see mHandler below.
98 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700100 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
101 private static final int EVENT_DATA_ROAMING_OK = 11;
102 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 12;
103 private static final int EVENT_DOCK_STATE_CHANGED = 13;
104 private static final int EVENT_TTY_PREFERRED_MODE_CHANGED = 14;
105 private static final int EVENT_TTY_MODE_GET = 15;
106 private static final int EVENT_TTY_MODE_SET = 16;
107 private static final int EVENT_START_SIP_SERVICE = 17;
108
109 // The MMI codes are also used by the InCallScreen.
110 public static final int MMI_INITIATE = 51;
111 public static final int MMI_COMPLETE = 52;
112 public static final int MMI_CANCEL = 53;
113 // Don't use message codes larger than 99 here; those are reserved for
114 // the individual Activities of the Phone UI.
115
116 /**
117 * Allowable values for the wake lock code.
118 * SLEEP means the device can be put to sleep.
119 * PARTIAL means wake the processor, but we display can be kept off.
120 * FULL means wake both the processor and the display.
121 */
122 public enum WakeState {
123 SLEEP,
124 PARTIAL,
125 FULL
126 }
127
128 /**
129 * Intent Action used for hanging up the current call from Notification bar. This will
130 * choose first ringing call, first active call, or first background call (typically in
131 * HOLDING state).
132 */
133 public static final String ACTION_HANG_UP_ONGOING_CALL =
134 "com.android.phone.ACTION_HANG_UP_ONGOING_CALL";
135
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136 private static PhoneGlobals sMe;
137
138 // A few important fields we expose to the rest of the package
139 // directly (rather than thru set/get methods) for efficiency.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140 CallController callController;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700142 CallNotifier notifier;
143 CallerInfoCache callerInfoCache;
Santos Cordon63a84242013-07-23 13:32:52 -0700144 NotificationMgr notificationMgr;
145 Phone phone;
146 PhoneInterfaceManager phoneMgr;
147
Santos Cordon9b7bac72013-08-06 08:04:52 -0700148 private AudioRouter audioRouter;
Santos Cordon27a3c1f2013-08-06 07:49:27 -0700149 private BluetoothManager bluetoothManager;
Santos Cordon69a69192013-08-22 14:25:42 -0700150 private CallGatewayManager callGatewayManager;
Santos Cordon63a84242013-07-23 13:32:52 -0700151 private CallModeler callModeler;
152 private CallStateMonitor callStateMonitor;
Santos Cordon2eaff902013-08-05 04:37:55 -0700153 private DTMFTonePlayer dtmfTonePlayer;
Santos Cordon63a84242013-07-23 13:32:52 -0700154 private IBluetoothHeadsetPhone mBluetoothPhone;
155 private Ringer ringer;
Santos Cordon593ab382013-08-06 21:58:23 -0700156 private WiredHeadsetManager wiredHeadsetManager;
Santos Cordon63a84242013-07-23 13:32:52 -0700157
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700158 static int mDockState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
159 static boolean sVoiceCapable = true;
160
161 // Internal PhoneApp Call state tracker
162 CdmaPhoneCallState cdmaPhoneCallState;
163
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700164 // The currently-active PUK entry activity and progress dialog.
165 // Normally, these are the Emergency Dialer and the subsequent
166 // progress dialog. null if there is are no such objects in
167 // the foreground.
168 private Activity mPUKEntryActivity;
169 private ProgressDialog mPUKEntryProgressDialog;
170
171 private boolean mIsSimPinEnabled;
172 private String mCachedSimPin;
173
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174 // True if we are beginning a call, but the phone state has not changed yet
175 private boolean mBeginningCall;
176
177 // Last phone state seen by updatePhoneState()
178 private PhoneConstants.State mLastPhoneState = PhoneConstants.State.IDLE;
179
180 private WakeState mWakeState = WakeState.SLEEP;
181
182 private PowerManager mPowerManager;
183 private IPowerManager mPowerManagerService;
184 private PowerManager.WakeLock mWakeLock;
185 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700187
188 private UpdateLock mUpdateLock;
189
190 // Broadcast receiver for various intent broadcasts (see onCreate())
191 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
192
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193 /** boolean indicating restoring mute state on InCallScreen.onResume() */
194 private boolean mShouldRestoreMuteOnInCallResume;
195
196 /**
197 * The singleton OtaUtils instance used for OTASP calls.
198 *
199 * The OtaUtils instance is created lazily the first time we need to
200 * make an OTASP call, regardless of whether it's an interactive or
201 * non-interactive OTASP call.
202 */
203 public OtaUtils otaUtils;
204
205 // Following are the CDMA OTA information Objects used during OTA Call.
206 // cdmaOtaProvisionData object store static OTA information that needs
207 // to be maintained even during Slider open/close scenarios.
208 // cdmaOtaConfigData object stores configuration info to control visiblity
209 // of each OTA Screens.
210 // cdmaOtaScreenState object store OTA Screen State information.
211 public OtaUtils.CdmaOtaProvisionData cdmaOtaProvisionData;
212 public OtaUtils.CdmaOtaConfigData cdmaOtaConfigData;
213 public OtaUtils.CdmaOtaScreenState cdmaOtaScreenState;
214 public OtaUtils.CdmaOtaInCallScreenUiState cdmaOtaInCallScreenUiState;
215
216 // TTY feature enabled on this platform
217 private boolean mTtyEnabled;
218 // Current TTY operating mode selected by user
219 private int mPreferredTtyMode = Phone.TTY_MODE_OFF;
220
221 /**
222 * Set the restore mute state flag. Used when we are setting the mute state
223 * OUTSIDE of user interaction {@link PhoneUtils#startNewCall(Phone)}
224 */
225 /*package*/void setRestoreMuteOnInCallResume (boolean mode) {
226 mShouldRestoreMuteOnInCallResume = mode;
227 }
228
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700229 Handler mHandler = new Handler() {
230 @Override
231 public void handleMessage(Message msg) {
232 PhoneConstants.State phoneState;
233 switch (msg.what) {
234 // Starts the SIP service. It's a no-op if SIP API is not supported
235 // on the deivce.
236 // TODO: Having the phone process host the SIP service is only
237 // temporary. Will move it to a persistent communication process
238 // later.
239 case EVENT_START_SIP_SERVICE:
240 SipService.start(getApplicationContext());
241 break;
242
243 // TODO: This event should be handled by the lock screen, just
244 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
245 case EVENT_SIM_NETWORK_LOCKED:
246 if (getResources().getBoolean(R.bool.ignore_sim_network_locked_events)) {
247 // Some products don't have the concept of a "SIM network lock"
248 Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; "
249 + "not showing 'SIM network unlock' PIN entry screen");
250 } else {
251 // Normal case: show the "SIM network unlock" PIN entry screen.
252 // The user won't be able to do anything else until
253 // they enter a valid SIM network PIN.
254 Log.i(LOG_TAG, "show sim depersonal panel");
255 IccNetworkDepersonalizationPanel ndpPanel =
256 new IccNetworkDepersonalizationPanel(PhoneGlobals.getInstance());
257 ndpPanel.show();
258 }
259 break;
260
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700261 case EVENT_DATA_ROAMING_DISCONNECTED:
262 notificationMgr.showDataDisconnectedRoaming();
263 break;
264
265 case EVENT_DATA_ROAMING_OK:
266 notificationMgr.hideDataDisconnectedRoaming();
267 break;
268
269 case MMI_COMPLETE:
270 onMMIComplete((AsyncResult) msg.obj);
271 break;
272
273 case MMI_CANCEL:
274 PhoneUtils.cancelMmiCode(phone);
275 break;
276
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700277 case EVENT_SIM_STATE_CHANGED:
278 // Marks the event where the SIM goes into ready state.
279 // Right now, this is only used for the PUK-unlocking
280 // process.
281 if (msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_READY)) {
282 // when the right event is triggered and there
283 // are UI objects in the foreground, we close
284 // them to display the lock panel.
285 if (mPUKEntryActivity != null) {
286 mPUKEntryActivity.finish();
287 mPUKEntryActivity = null;
288 }
289 if (mPUKEntryProgressDialog != null) {
290 mPUKEntryProgressDialog.dismiss();
291 mPUKEntryProgressDialog = null;
292 }
293 }
294 break;
295
296 case EVENT_UNSOL_CDMA_INFO_RECORD:
297 //TODO: handle message here;
298 break;
299
300 case EVENT_DOCK_STATE_CHANGED:
301 // If the phone is docked/undocked during a call, and no wired or BT headset
302 // is connected: turn on/off the speaker accordingly.
303 boolean inDockMode = false;
304 if (mDockState != Intent.EXTRA_DOCK_STATE_UNDOCKED) {
305 inDockMode = true;
306 }
307 if (VDBG) Log.d(LOG_TAG, "received EVENT_DOCK_STATE_CHANGED. Phone inDock = "
308 + inDockMode);
309
310 phoneState = mCM.getState();
311 if (phoneState == PhoneConstants.State.OFFHOOK &&
Santos Cordon593ab382013-08-06 21:58:23 -0700312 !wiredHeadsetManager.isHeadsetPlugged() &&
313 !bluetoothManager.isBluetoothHeadsetAudioOn()) {
314 audioRouter.setSpeaker(inDockMode);
315
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700316 PhoneUtils.turnOnSpeaker(getApplicationContext(), inDockMode, true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700317 }
318 break;
319
320 case EVENT_TTY_PREFERRED_MODE_CHANGED:
321 // TTY mode is only applied if a headset is connected
322 int ttyMode;
Santos Cordon593ab382013-08-06 21:58:23 -0700323 if (wiredHeadsetManager.isHeadsetPlugged()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700324 ttyMode = mPreferredTtyMode;
325 } else {
326 ttyMode = Phone.TTY_MODE_OFF;
327 }
328 phone.setTTYMode(ttyMode, mHandler.obtainMessage(EVENT_TTY_MODE_SET));
329 break;
330
331 case EVENT_TTY_MODE_GET:
332 handleQueryTTYModeResponse(msg);
333 break;
334
335 case EVENT_TTY_MODE_SET:
336 handleSetTTYModeResponse(msg);
337 break;
338 }
339 }
340 };
341
342 public PhoneGlobals(Context context) {
343 super(context);
344 sMe = this;
345 }
346
347 public void onCreate() {
348 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
349
350 ContentResolver resolver = getContentResolver();
351
352 // Cache the "voice capable" flag.
353 // This flag currently comes from a resource (which is
354 // overrideable on a per-product basis):
355 sVoiceCapable =
356 getResources().getBoolean(com.android.internal.R.bool.config_voice_capable);
357 // ...but this might eventually become a PackageManager "system
358 // feature" instead, in which case we'd do something like:
359 // sVoiceCapable =
360 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
361
362 if (phone == null) {
363 // Initialize the telephony framework
364 PhoneFactory.makeDefaultPhones(this);
365
366 // Get the default phone
367 phone = PhoneFactory.getDefaultPhone();
368
369 // Start TelephonyDebugService After the default phone is created.
370 Intent intent = new Intent(this, TelephonyDebugService.class);
371 startService(intent);
372
373 mCM = CallManager.getInstance();
374 mCM.registerPhone(phone);
375
376 // Create the NotificationMgr singleton, which is used to display
377 // status bar icons and control other status bar behavior.
378 notificationMgr = NotificationMgr.init(this);
379
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380 mHandler.sendEmptyMessage(EVENT_START_SIP_SERVICE);
381
382 int phoneType = phone.getPhoneType();
383
384 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
385 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
386 cdmaPhoneCallState = new CdmaPhoneCallState();
387 cdmaPhoneCallState.CdmaPhoneCallStateInit();
388 }
389
390 if (BluetoothAdapter.getDefaultAdapter() != null) {
391 // Start BluetoothPhoneService even if device is not voice capable.
392 // The device can still support VOIP.
393 startService(new Intent(this, BluetoothPhoneService.class));
394 bindService(new Intent(this, BluetoothPhoneService.class),
395 mBluetoothPhoneConnection, 0);
396 } else {
397 // Device is not bluetooth capable
398 mBluetoothPhone = null;
399 }
400
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401 // before registering for phone state changes
402 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
403 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
404 // lock used to keep the processor awake, when we don't care for the display.
405 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
406 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700407
408 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
409
410 // get a handle to the service so that we can use it later when we
411 // want to set the poke lock.
412 mPowerManagerService = IPowerManager.Stub.asInterface(
413 ServiceManager.getService("power"));
414
415 // Get UpdateLock to suppress system-update related events (e.g. dialog show-up)
416 // during phone calls.
417 mUpdateLock = new UpdateLock("phone");
418
419 if (DBG) Log.d(LOG_TAG, "onCreate: mUpdateLock: " + mUpdateLock);
420
421 CallLogger callLogger = new CallLogger(this, new CallLogAsync());
422
Jay Shrauner21a75342013-11-25 16:14:43 -0800423 callGatewayManager = CallGatewayManager.getInstance();
Santos Cordon69a69192013-08-22 14:25:42 -0700424
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700425 // Create the CallController singleton, which is the interface
426 // to the telephony layer for user-initiated telephony functionality
427 // (like making outgoing calls.)
Santos Cordon69a69192013-08-22 14:25:42 -0700428 callController = CallController.init(this, callLogger, callGatewayManager);
429
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700430 // Create the CallerInfoCache singleton, which remembers custom ring tone and
431 // send-to-voicemail settings.
432 //
433 // The asynchronous caching will start just after this call.
434 callerInfoCache = CallerInfoCache.init(this);
435
436 // Monitors call activity from the telephony layer
437 callStateMonitor = new CallStateMonitor(mCM);
438
Sailesh Nepal194161e2014-07-03 08:57:44 -0700439 // Creates call models.
David Braun35272072013-09-24 17:19:26 -0700440 callModeler = new CallModeler(callStateMonitor, mCM, callGatewayManager);
Santos Cordon63a84242013-07-23 13:32:52 -0700441
Santos Cordon2eaff902013-08-05 04:37:55 -0700442 // Plays DTMF Tones
443 dtmfTonePlayer = new DTMFTonePlayer(mCM, callModeler);
444
Santos Cordon593ab382013-08-06 21:58:23 -0700445 // Manages wired headset state
446 wiredHeadsetManager = new WiredHeadsetManager(this);
447 wiredHeadsetManager.addWiredHeadsetListener(this);
448
Santos Cordon2c2d3cf2013-08-08 03:53:47 -0700449 // Bluetooth manager
450 bluetoothManager = new BluetoothManager(this, mCM, callModeler);
Santos Cordon2c2d3cf2013-08-08 03:53:47 -0700451
452 ringer = Ringer.init(this, bluetoothManager);
453
Santos Cordon9b7bac72013-08-06 08:04:52 -0700454 // Audio router
Santos Cordon593ab382013-08-06 21:58:23 -0700455 audioRouter = new AudioRouter(this, bluetoothManager, wiredHeadsetManager, mCM);
Santos Cordon9b7bac72013-08-06 08:04:52 -0700456
Sailesh Nepal194161e2014-07-03 08:57:44 -0700457 phoneMgr = PhoneInterfaceManager.init(this, phone);
Santos Cordon406c0342013-08-28 00:07:47 -0700458
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700459 // Create the CallNotifer singleton, which handles
460 // asynchronous events from the telephony layer (like
461 // launching the incoming-call UI when an incoming call comes
462 // in.)
Santos Cordon27a3c1f2013-08-06 07:49:27 -0700463 notifier = CallNotifier.init(this, phone, ringer, callLogger, callStateMonitor,
Santos Cordona5d5db82013-09-15 13:00:34 -0700464 bluetoothManager, callModeler);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700465
466 // register for ICC status
467 IccCard sim = phone.getIccCard();
468 if (sim != null) {
469 if (VDBG) Log.v(LOG_TAG, "register for ICC status");
470 sim.registerForNetworkLocked(mHandler, EVENT_SIM_NETWORK_LOCKED, null);
471 }
472
473 // register for MMI/USSD
474 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
475
476 // register connection tracking to PhoneUtils
477 PhoneUtils.initializeConnectionHandler(mCM);
478
479 // Read platform settings for TTY feature
480 mTtyEnabled = getResources().getBoolean(R.bool.tty_enabled);
481
482 // Register for misc other intent broadcasts.
483 IntentFilter intentFilter =
484 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700485 intentFilter.addAction(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486 intentFilter.addAction(Intent.ACTION_DOCK_EVENT);
487 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
488 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
489 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
490 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
491 if (mTtyEnabled) {
492 intentFilter.addAction(TtyIntent.TTY_PREFERRED_MODE_CHANGE_ACTION);
493 }
494 intentFilter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
495 registerReceiver(mReceiver, intentFilter);
496
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700497 //set the default values for the preferences in the phone.
498 PreferenceManager.setDefaultValues(this, R.xml.network_setting, false);
499
500 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
501
502 // Make sure the audio mode (along with some
503 // audio-mode-related state of our own) is initialized
504 // correctly, given the current state of the phone.
505 PhoneUtils.setAudioMode(mCM);
506 }
507
508 if (TelephonyCapabilities.supportsOtasp(phone)) {
509 cdmaOtaProvisionData = new OtaUtils.CdmaOtaProvisionData();
510 cdmaOtaConfigData = new OtaUtils.CdmaOtaConfigData();
511 cdmaOtaScreenState = new OtaUtils.CdmaOtaScreenState();
512 cdmaOtaInCallScreenUiState = new OtaUtils.CdmaOtaInCallScreenUiState();
513 }
514
515 // XXX pre-load the SimProvider so that it's ready
516 resolver.getType(Uri.parse("content://icc/adn"));
517
518 // start with the default value to set the mute state.
519 mShouldRestoreMuteOnInCallResume = false;
520
521 // TODO: Register for Cdma Information Records
522 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
523
524 // Read TTY settings and store it into BP NV.
525 // AP owns (i.e. stores) the TTY setting in AP settings database and pushes the setting
526 // to BP at power up (BP does not need to make the TTY setting persistent storage).
527 // This way, there is a single owner (i.e AP) for the TTY setting in the phone.
528 if (mTtyEnabled) {
529 mPreferredTtyMode = android.provider.Settings.Secure.getInt(
530 phone.getContext().getContentResolver(),
531 android.provider.Settings.Secure.PREFERRED_TTY_MODE,
532 Phone.TTY_MODE_OFF);
533 mHandler.sendMessage(mHandler.obtainMessage(EVENT_TTY_PREFERRED_MODE_CHANGED, 0));
534 }
535 // Read HAC settings and configure audio hardware
536 if (getResources().getBoolean(R.bool.hac_enabled)) {
537 int hac = android.provider.Settings.System.getInt(phone.getContext().getContentResolver(),
538 android.provider.Settings.System.HEARING_AID,
539 0);
540 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
541 audioManager.setParameter(CallFeaturesSetting.HAC_KEY, hac != 0 ?
542 CallFeaturesSetting.HAC_VAL_ON :
543 CallFeaturesSetting.HAC_VAL_OFF);
544 }
Santos Cordonff506f52013-11-21 19:13:19 -0800545 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700546
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700547 /**
548 * Returns the singleton instance of the PhoneApp.
549 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800550 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700551 if (sMe == null) {
552 throw new IllegalStateException("No PhoneGlobals here!");
553 }
554 return sMe;
555 }
556
557 /**
558 * Returns the singleton instance of the PhoneApp if running as the
559 * primary user, otherwise null.
560 */
561 static PhoneGlobals getInstanceIfPrimary() {
562 return sMe;
563 }
564
565 /**
566 * Returns the Phone associated with this instance
567 */
568 static Phone getPhone() {
569 return getInstance().phone;
570 }
571
572 Ringer getRinger() {
573 return ringer;
574 }
575
576 IBluetoothHeadsetPhone getBluetoothPhoneService() {
577 return mBluetoothPhone;
578 }
579
Santos Cordon27a3c1f2013-08-06 07:49:27 -0700580 /* package */ BluetoothManager getBluetoothManager() {
581 return bluetoothManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700582 }
583
Santos Cordon593ab382013-08-06 21:58:23 -0700584 /* package */ WiredHeadsetManager getWiredHeadsetManager() {
585 return wiredHeadsetManager;
586 }
587
588 /* package */ AudioRouter getAudioRouter() {
589 return audioRouter;
590 }
591
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800592 public CallModeler getCallModeler() {
Santos Cordonad1ed6d2013-09-16 03:04:23 -0700593 return callModeler;
594 }
595
Santos Cordonde10b752013-09-19 04:11:33 -0700596 /* package */ CallManager getCallManager() {
597 return mCM;
598 }
599
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700600 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700601 * Returns PendingIntent for hanging up ongoing phone call. This will typically be used from
602 * Notification context.
603 */
604 /* package */ static PendingIntent createHangUpOngoingCallPendingIntent(Context context) {
605 Intent intent = new Intent(PhoneGlobals.ACTION_HANG_UP_ONGOING_CALL, null,
606 context, NotificationBroadcastReceiver.class);
607 return PendingIntent.getBroadcast(context, 0, intent, 0);
608 }
609
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700610 boolean isSimPinEnabled() {
611 return mIsSimPinEnabled;
612 }
613
614 boolean authenticateAgainstCachedSimPin(String pin) {
615 return (mCachedSimPin != null && mCachedSimPin.equals(pin));
616 }
617
618 void setCachedSimPin(String pin) {
619 mCachedSimPin = pin;
620 }
621
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700622 /**
623 * Handles OTASP-related events from the telephony layer.
624 *
625 * While an OTASP call is active, the CallNotifier forwards
626 * OTASP-related telephony events to this method.
627 */
628 void handleOtaspEvent(Message msg) {
629 if (DBG) Log.d(LOG_TAG, "handleOtaspEvent(message " + msg + ")...");
630
631 if (otaUtils == null) {
632 // We shouldn't be getting OTASP events without ever
633 // having started the OTASP call in the first place!
634 Log.w(LOG_TAG, "handleOtaEvents: got an event but otaUtils is null! "
635 + "message = " + msg);
636 return;
637 }
638
639 otaUtils.onOtaProvisionStatusChanged((AsyncResult) msg.obj);
640 }
641
642 /**
643 * Similarly, handle the disconnect event of an OTASP call
644 * by forwarding it to the OtaUtils instance.
645 */
646 /* package */ void handleOtaspDisconnect() {
647 if (DBG) Log.d(LOG_TAG, "handleOtaspDisconnect()...");
648
649 if (otaUtils == null) {
650 // We shouldn't be getting OTASP events without ever
651 // having started the OTASP call in the first place!
652 Log.w(LOG_TAG, "handleOtaspDisconnect: otaUtils is null!");
653 return;
654 }
655
656 otaUtils.onOtaspDisconnect();
657 }
658
659 /**
660 * Sets the activity responsible for un-PUK-blocking the device
661 * so that we may close it when we receive a positive result.
662 * mPUKEntryActivity is also used to indicate to the device that
663 * we are trying to un-PUK-lock the phone. In other words, iff
664 * it is NOT null, then we are trying to unlock and waiting for
665 * the SIM to move to READY state.
666 *
667 * @param activity is the activity to close when PUK has
668 * finished unlocking. Can be set to null to indicate the unlock
669 * or SIM READYing process is over.
670 */
671 void setPukEntryActivity(Activity activity) {
672 mPUKEntryActivity = activity;
673 }
674
675 Activity getPUKEntryActivity() {
676 return mPUKEntryActivity;
677 }
678
679 /**
680 * Sets the dialog responsible for notifying the user of un-PUK-
681 * blocking - SIM READYing progress, so that we may dismiss it
682 * when we receive a positive result.
683 *
684 * @param dialog indicates the progress dialog informing the user
685 * of the state of the device. Dismissed upon completion of
686 * READYing process
687 */
688 void setPukEntryProgressDialog(ProgressDialog dialog) {
689 mPUKEntryProgressDialog = dialog;
690 }
691
692 ProgressDialog getPUKEntryProgressDialog() {
693 return mPUKEntryProgressDialog;
694 }
695
696 /**
697 * Controls whether or not the screen is allowed to sleep.
698 *
699 * Once sleep is allowed (WakeState is SLEEP), it will rely on the
700 * settings for the poke lock to determine when to timeout and let
701 * the device sleep {@link PhoneGlobals#setScreenTimeout}.
702 *
703 * @param ws tells the device to how to wake.
704 */
705 /* package */ void requestWakeState(WakeState ws) {
706 if (VDBG) Log.d(LOG_TAG, "requestWakeState(" + ws + ")...");
707 synchronized (this) {
708 if (mWakeState != ws) {
709 switch (ws) {
710 case PARTIAL:
711 // acquire the processor wake lock, and release the FULL
712 // lock if it is being held.
713 mPartialWakeLock.acquire();
714 if (mWakeLock.isHeld()) {
715 mWakeLock.release();
716 }
717 break;
718 case FULL:
719 // acquire the full wake lock, and release the PARTIAL
720 // lock if it is being held.
721 mWakeLock.acquire();
722 if (mPartialWakeLock.isHeld()) {
723 mPartialWakeLock.release();
724 }
725 break;
726 case SLEEP:
727 default:
728 // release both the PARTIAL and FULL locks.
729 if (mWakeLock.isHeld()) {
730 mWakeLock.release();
731 }
732 if (mPartialWakeLock.isHeld()) {
733 mPartialWakeLock.release();
734 }
735 break;
736 }
737 mWakeState = ws;
738 }
739 }
740 }
741
742 /**
743 * If we are not currently keeping the screen on, then poke the power
744 * manager to wake up the screen for the user activity timeout duration.
745 */
746 /* package */ void wakeUpScreen() {
747 synchronized (this) {
748 if (mWakeState == WakeState.SLEEP) {
749 if (DBG) Log.d(LOG_TAG, "pulse screen lock");
750 mPowerManager.wakeUp(SystemClock.uptimeMillis());
751 }
752 }
753 }
754
755 /**
756 * Sets the wake state and screen timeout based on the current state
757 * of the phone, and the current state of the in-call UI.
758 *
759 * This method is a "UI Policy" wrapper around
760 * {@link PhoneGlobals#requestWakeState} and {@link PhoneGlobals#setScreenTimeout}.
761 *
762 * It's safe to call this method regardless of the state of the Phone
763 * (e.g. whether or not it's idle), and regardless of the state of the
764 * Phone UI (e.g. whether or not the InCallScreen is active.)
765 */
766 /* package */ void updateWakeState() {
767 PhoneConstants.State state = mCM.getState();
768
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700769 // True if the speakerphone is in use. (If so, we *always* use
770 // the default timeout. Since the user is obviously not holding
771 // the phone up to his/her face, we don't need to worry about
772 // false touches, and thus don't need to turn the screen off so
773 // aggressively.)
774 // Note that we need to make a fresh call to this method any
775 // time the speaker state changes. (That happens in
776 // PhoneUtils.turnOnSpeaker().)
777 boolean isSpeakerInUse = (state == PhoneConstants.State.OFFHOOK) && PhoneUtils.isSpeakerOn(this);
778
779 // TODO (bug 1440854): The screen timeout *might* also need to
780 // depend on the bluetooth state, but this isn't as clear-cut as
781 // the speaker state (since while using BT it's common for the
782 // user to put the phone straight into a pocket, in which case the
783 // timeout should probably still be short.)
784
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700785 // Decide whether to force the screen on or not.
786 //
787 // Force the screen to be on if the phone is ringing or dialing,
788 // or if we're displaying the "Call ended" UI for a connection in
789 // the "disconnected" state.
790 // However, if the phone is disconnected while the user is in the
791 // middle of selecting a quick response message, we should not force
792 // the screen to be on.
793 //
794 boolean isRinging = (state == PhoneConstants.State.RINGING);
795 boolean isDialing = (phone.getForegroundCall().getState() == Call.State.DIALING);
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700796 boolean keepScreenOn = isRinging || isDialing;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700797 // keepScreenOn == true means we'll hold a full wake lock:
798 requestWakeState(keepScreenOn ? WakeState.FULL : WakeState.SLEEP);
799 }
800
801 /**
802 * Manually pokes the PowerManager's userActivity method. Since we
803 * set the {@link WindowManager.LayoutParams#INPUT_FEATURE_DISABLE_USER_ACTIVITY}
804 * flag while the InCallScreen is active when there is no proximity sensor,
805 * we need to do this for touch events that really do count as user activity
806 * (like pressing any onscreen UI elements.)
807 */
808 /* package */ void pokeUserActivity() {
809 if (VDBG) Log.d(LOG_TAG, "pokeUserActivity()...");
810 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
811 }
812
813 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700814 * Notifies the phone app when the phone state changes.
815 *
Santos Cordonfc309812013-08-20 18:33:16 -0700816 * This method will updates various states inside Phone app (e.g. update-lock state, etc.)
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700817 */
818 /* package */ void updatePhoneState(PhoneConstants.State state) {
819 if (state != mLastPhoneState) {
820 mLastPhoneState = state;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700821
822 // Try to acquire or release UpdateLock.
823 //
824 // Watch out: we don't release the lock here when the screen is still in foreground.
825 // At that time InCallScreen will release it on onPause().
826 if (state != PhoneConstants.State.IDLE) {
827 // UpdateLock is a recursive lock, while we may get "acquire" request twice and
828 // "release" request once for a single call (RINGING + OFFHOOK and IDLE).
829 // We need to manually ensure the lock is just acquired once for each (and this
830 // will prevent other possible buggy situations too).
831 if (!mUpdateLock.isHeld()) {
832 mUpdateLock.acquire();
833 }
834 } else {
Jay Shraunera5d13212013-09-19 13:37:43 -0700835 if (mUpdateLock.isHeld()) {
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700836 mUpdateLock.release();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700837 }
838 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700839 }
840 }
841
842 /* package */ PhoneConstants.State getPhoneState() {
843 return mLastPhoneState;
844 }
845
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700846 KeyguardManager getKeyguardManager() {
847 return mKeyguardManager;
848 }
849
850 private void onMMIComplete(AsyncResult r) {
851 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
852 MmiCode mmiCode = (MmiCode) r.result;
853 PhoneUtils.displayMMIComplete(phone, getInstance(), mmiCode, null, null);
854 }
855
856 private void initForNewRadioTechnology() {
857 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
858
859 if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
860 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
861 cdmaPhoneCallState = new CdmaPhoneCallState();
862 cdmaPhoneCallState.CdmaPhoneCallStateInit();
863 }
864 if (TelephonyCapabilities.supportsOtasp(phone)) {
865 //create instances of CDMA OTA data classes
866 if (cdmaOtaProvisionData == null) {
867 cdmaOtaProvisionData = new OtaUtils.CdmaOtaProvisionData();
868 }
869 if (cdmaOtaConfigData == null) {
870 cdmaOtaConfigData = new OtaUtils.CdmaOtaConfigData();
871 }
872 if (cdmaOtaScreenState == null) {
873 cdmaOtaScreenState = new OtaUtils.CdmaOtaScreenState();
874 }
875 if (cdmaOtaInCallScreenUiState == null) {
876 cdmaOtaInCallScreenUiState = new OtaUtils.CdmaOtaInCallScreenUiState();
877 }
878 } else {
879 //Clean up OTA data in GSM/UMTS. It is valid only for CDMA
880 clearOtaState();
881 }
882
883 ringer.updateRingerContextAfterRadioTechnologyChange(this.phone);
884 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
885 callStateMonitor.updateAfterRadioTechnologyChange();
886
887 if (mBluetoothPhone != null) {
888 try {
889 mBluetoothPhone.updateBtHandsfreeAfterRadioTechnologyChange();
890 } catch (RemoteException e) {
891 Log.e(LOG_TAG, Log.getStackTraceString(new Throwable()));
892 }
893 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700894
895 // Update registration for ICC status after radio technology change
896 IccCard sim = phone.getIccCard();
897 if (sim != null) {
898 if (DBG) Log.d(LOG_TAG, "Update registration for ICC status...");
899
900 //Register all events new to the new active phone
901 sim.registerForNetworkLocked(mHandler, EVENT_SIM_NETWORK_LOCKED, null);
902 }
903 }
904
905
906 /**
Santos Cordon593ab382013-08-06 21:58:23 -0700907 * This is called when the wired headset state changes.
908 */
909 @Override
910 public void onWiredHeadsetConnection(boolean pluggedIn) {
911 PhoneConstants.State phoneState = mCM.getState();
912
Santos Cordon593ab382013-08-06 21:58:23 -0700913 // Force TTY state update according to new headset state
914 if (mTtyEnabled) {
915 mHandler.sendMessage(mHandler.obtainMessage(EVENT_TTY_PREFERRED_MODE_CHANGED, 0));
916 }
917 }
918
919 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700920 * Receiver for misc intent broadcasts the Phone app cares about.
921 */
922 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
923 @Override
924 public void onReceive(Context context, Intent intent) {
925 String action = intent.getAction();
926 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
927 boolean enabled = System.getInt(getContentResolver(),
928 System.AIRPLANE_MODE_ON, 0) == 0;
929 phone.setRadioPower(enabled);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700930 } else if (action.equals(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) {
931 if (VDBG) Log.d(LOG_TAG, "mReceiver: ACTION_ANY_DATA_CONNECTION_STATE_CHANGED");
932 if (VDBG) Log.d(LOG_TAG, "- state: " + intent.getStringExtra(PhoneConstants.STATE_KEY));
933 if (VDBG) Log.d(LOG_TAG, "- reason: "
934 + intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY));
935
936 // The "data disconnected due to roaming" notification is shown
937 // if (a) you have the "data roaming" feature turned off, and
938 // (b) you just lost data connectivity because you're roaming.
939 boolean disconnectedDueToRoaming =
940 !phone.getDataRoamingEnabled()
941 && "DISCONNECTED".equals(intent.getStringExtra(PhoneConstants.STATE_KEY))
942 && Phone.REASON_ROAMING_ON.equals(
943 intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY));
944 mHandler.sendEmptyMessage(disconnectedDueToRoaming
945 ? EVENT_DATA_ROAMING_DISCONNECTED
946 : EVENT_DATA_ROAMING_OK);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700947 } else if ((action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) &&
948 (mPUKEntryActivity != null)) {
949 // if an attempt to un-PUK-lock the device was made, while we're
950 // receiving this state change notification, notify the handler.
951 // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has
952 // been attempted.
953 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
954 intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE)));
955 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
956 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
957 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
958 initForNewRadioTechnology();
959 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
960 handleServiceStateChanged(intent);
961 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
962 if (TelephonyCapabilities.supportsEcm(phone)) {
963 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
964 // Start Emergency Callback Mode service
965 if (intent.getBooleanExtra("phoneinECMState", false)) {
966 context.startService(new Intent(context,
967 EmergencyCallbackModeService.class));
968 }
969 } else {
970 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
971 // on a device that doesn't support ECM in the first place.
972 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, "
973 + "but ECM isn't supported for phone: " + phone.getPhoneName());
974 }
975 } else if (action.equals(Intent.ACTION_DOCK_EVENT)) {
976 mDockState = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
977 Intent.EXTRA_DOCK_STATE_UNDOCKED);
978 if (VDBG) Log.d(LOG_TAG, "ACTION_DOCK_EVENT -> mDockState = " + mDockState);
979 mHandler.sendMessage(mHandler.obtainMessage(EVENT_DOCK_STATE_CHANGED, 0));
980 } else if (action.equals(TtyIntent.TTY_PREFERRED_MODE_CHANGE_ACTION)) {
981 mPreferredTtyMode = intent.getIntExtra(TtyIntent.TTY_PREFFERED_MODE,
982 Phone.TTY_MODE_OFF);
983 if (VDBG) Log.d(LOG_TAG, "mReceiver: TTY_PREFERRED_MODE_CHANGE_ACTION");
984 if (VDBG) Log.d(LOG_TAG, " mode: " + mPreferredTtyMode);
985 mHandler.sendMessage(mHandler.obtainMessage(EVENT_TTY_PREFERRED_MODE_CHANGED, 0));
986 } else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
987 int ringerMode = intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE,
988 AudioManager.RINGER_MODE_NORMAL);
989 if (ringerMode == AudioManager.RINGER_MODE_SILENT) {
990 notifier.silenceRinger();
991 }
992 }
993 }
994 }
995
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700996 /**
997 * Accepts broadcast Intents which will be prepared by {@link NotificationMgr} and thus
998 * sent from framework's notification mechanism (which is outside Phone context).
999 * This should be visible from outside, but shouldn't be in "exported" state.
1000 *
1001 * TODO: If possible merge this into PhoneAppBroadcastReceiver.
1002 */
1003 public static class NotificationBroadcastReceiver extends BroadcastReceiver {
1004 @Override
1005 public void onReceive(Context context, Intent intent) {
1006 String action = intent.getAction();
1007 // TODO: use "if (VDBG)" here.
1008 Log.d(LOG_TAG, "Broadcast from Notification: " + action);
1009
1010 if (action.equals(ACTION_HANG_UP_ONGOING_CALL)) {
1011 PhoneUtils.hangup(PhoneGlobals.getInstance().mCM);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001012 } else {
1013 Log.w(LOG_TAG, "Received hang-up request from notification,"
1014 + " but there's no call the system can hang up.");
1015 }
1016 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001017 }
1018
1019 private void handleServiceStateChanged(Intent intent) {
1020 /**
1021 * This used to handle updating EriTextWidgetProvider this routine
1022 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
1023 * be removed. But leaving just in case it might be needed in the near
1024 * future.
1025 */
1026
1027 // If service just returned, start sending out the queued messages
1028 ServiceState ss = ServiceState.newFromBundle(intent.getExtras());
1029
1030 if (ss != null) {
1031 int state = ss.getState();
1032 notificationMgr.updateNetworkSelection(state);
1033 }
1034 }
1035
1036 public boolean isOtaCallInActiveState() {
1037 boolean otaCallActive = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001038 if (VDBG) Log.d(LOG_TAG, "- isOtaCallInActiveState " + otaCallActive);
1039 return otaCallActive;
1040 }
1041
1042 public boolean isOtaCallInEndState() {
1043 boolean otaCallEnded = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001044 if (VDBG) Log.d(LOG_TAG, "- isOtaCallInEndState " + otaCallEnded);
1045 return otaCallEnded;
1046 }
1047
1048 // it is safe to call clearOtaState() even if the InCallScreen isn't active
1049 public void clearOtaState() {
1050 if (DBG) Log.d(LOG_TAG, "- clearOtaState ...");
Jay Shrauner6fe8fd62013-09-16 19:39:30 -07001051 if (otaUtils != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001052 otaUtils.cleanOtaScreen(true);
1053 if (DBG) Log.d(LOG_TAG, " - clearOtaState clears OTA screen");
1054 }
1055 }
1056
1057 // it is safe to call dismissOtaDialogs() even if the InCallScreen isn't active
1058 public void dismissOtaDialogs() {
1059 if (DBG) Log.d(LOG_TAG, "- dismissOtaDialogs ...");
Jay Shrauner6fe8fd62013-09-16 19:39:30 -07001060 if (otaUtils != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001061 otaUtils.dismissAllOtaDialogs();
1062 if (DBG) Log.d(LOG_TAG, " - dismissOtaDialogs clears OTA dialogs");
1063 }
1064 }
1065
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001066 private void handleQueryTTYModeResponse(Message msg) {
1067 AsyncResult ar = (AsyncResult) msg.obj;
1068 if (ar.exception != null) {
1069 if (DBG) Log.d(LOG_TAG, "handleQueryTTYModeResponse: Error getting TTY state.");
1070 } else {
1071 if (DBG) Log.d(LOG_TAG,
1072 "handleQueryTTYModeResponse: TTY enable state successfully queried.");
1073
1074 int ttymode = ((int[]) ar.result)[0];
1075 if (DBG) Log.d(LOG_TAG, "handleQueryTTYModeResponse:ttymode=" + ttymode);
1076
1077 Intent ttyModeChanged = new Intent(TtyIntent.TTY_ENABLED_CHANGE_ACTION);
1078 ttyModeChanged.putExtra("ttyEnabled", ttymode != Phone.TTY_MODE_OFF);
1079 sendBroadcastAsUser(ttyModeChanged, UserHandle.ALL);
1080
1081 String audioTtyMode;
1082 switch (ttymode) {
1083 case Phone.TTY_MODE_FULL:
1084 audioTtyMode = "tty_full";
1085 break;
1086 case Phone.TTY_MODE_VCO:
1087 audioTtyMode = "tty_vco";
1088 break;
1089 case Phone.TTY_MODE_HCO:
1090 audioTtyMode = "tty_hco";
1091 break;
1092 case Phone.TTY_MODE_OFF:
1093 default:
1094 audioTtyMode = "tty_off";
1095 break;
1096 }
1097 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
1098 audioManager.setParameters("tty_mode="+audioTtyMode);
1099 }
1100 }
1101
1102 private void handleSetTTYModeResponse(Message msg) {
1103 AsyncResult ar = (AsyncResult) msg.obj;
1104
1105 if (ar.exception != null) {
1106 if (DBG) Log.d (LOG_TAG,
1107 "handleSetTTYModeResponse: Error setting TTY mode, ar.exception"
1108 + ar.exception);
1109 }
1110 phone.queryTTYMode(mHandler.obtainMessage(EVENT_TTY_MODE_GET));
1111 }
1112
1113 /**
1114 * "Call origin" may be used by Contacts app to specify where the phone call comes from.
1115 * Currently, the only permitted value for this extra is {@link #ALLOWED_EXTRA_CALL_ORIGIN}.
1116 * Any other value will be ignored, to make sure that malicious apps can't trick the in-call
1117 * UI into launching some random other app after a call ends.
1118 *
1119 * TODO: make this more generic. Note that we should let the "origin" specify its package
1120 * while we are now assuming it is "com.android.contacts"
1121 */
1122 public static final String EXTRA_CALL_ORIGIN = "com.android.phone.CALL_ORIGIN";
1123 private static final String DEFAULT_CALL_ORIGIN_PACKAGE = "com.android.dialer";
1124 private static final String ALLOWED_EXTRA_CALL_ORIGIN =
1125 "com.android.dialer.DialtactsActivity";
1126 /**
1127 * Used to determine if the preserved call origin is fresh enough.
1128 */
1129 private static final long CALL_ORIGIN_EXPIRATION_MILLIS = 30 * 1000;
1130
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001131 /** Service connection */
1132 private final ServiceConnection mBluetoothPhoneConnection = new ServiceConnection() {
1133
1134 /** Handle the task of binding the local object to the service */
1135 public void onServiceConnected(ComponentName className, IBinder service) {
1136 Log.i(LOG_TAG, "Headset phone created, binding local service.");
1137 mBluetoothPhone = IBluetoothHeadsetPhone.Stub.asInterface(service);
1138 }
1139
1140 /** Handle the task of cleaning up the local binding */
1141 public void onServiceDisconnected(ComponentName className) {
1142 Log.i(LOG_TAG, "Headset phone disconnected, cleaning local binding.");
1143 mBluetoothPhone = null;
1144 }
1145 };
Santos Cordon83570472013-09-06 15:45:10 -07001146
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001147}