blob: d066de2b374f55f8da5fcefdd1520ebba49859cd [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;
Junda Liu605148f2015-04-28 15:23:40 -070037import android.os.Bundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.Handler;
39import android.os.IBinder;
40import android.os.IPowerManager;
41import android.os.Message;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070042import android.os.PersistableBundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.os.PowerManager;
44import android.os.RemoteException;
45import android.os.ServiceManager;
46import android.os.SystemClock;
47import android.os.SystemProperties;
48import android.os.UpdateLock;
49import android.os.UserHandle;
50import android.preference.PreferenceManager;
51import android.provider.Settings.System;
Junda Liu12f7d802015-05-01 12:06:44 -070052import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.telephony.ServiceState;
Andrew Lee2fcb6c32014-12-04 14:52:35 -080054import android.telephony.SubscriptionInfo;
Andrew Lee385019f2014-11-24 14:19:50 -080055import android.telephony.SubscriptionManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.util.Log;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057
58import com.android.internal.telephony.Call;
59import com.android.internal.telephony.CallManager;
60import com.android.internal.telephony.IccCard;
61import com.android.internal.telephony.IccCardConstants;
62import com.android.internal.telephony.MmiCode;
63import com.android.internal.telephony.Phone;
64import com.android.internal.telephony.PhoneConstants;
65import com.android.internal.telephony.PhoneFactory;
Andrew Lee385019f2014-11-24 14:19:50 -080066import com.android.internal.telephony.SubscriptionController;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067import com.android.internal.telephony.TelephonyCapabilities;
68import com.android.internal.telephony.TelephonyIntents;
Santos Cordon352ff652014-05-30 01:41:45 -070069import com.android.phone.common.CallLogAsync;
Andrew Leefb7f92e2015-02-26 16:23:32 -080070import com.android.phone.settings.SettingsConstants;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070071import com.android.server.sip.SipService;
Santos Cordon76aaf482015-04-08 10:58:27 -070072import com.android.services.telephony.activation.SimActivationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073
Andrew Lee385019f2014-11-24 14:19:50 -080074import java.util.ArrayList;
75import java.util.List;
76
Santos Cordon7d4ddf62013-07-10 11:58:08 -070077/**
78 * Global state for the telephony subsystem when running in the primary
79 * phone process.
80 */
Sailesh Nepalbf900542014-07-15 16:18:32 -070081public class PhoneGlobals extends ContextWrapper {
Andrew Lee83383e42014-10-31 12:42:28 -070082 public static final String LOG_TAG = "PhoneApp";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070083
84 /**
85 * Phone app-wide debug level:
86 * 0 - no debug logging
87 * 1 - normal debug logging if ro.debuggable is set (which is true in
88 * "eng" and "userdebug" builds but not "user" builds)
89 * 2 - ultra-verbose debug logging
90 *
91 * Most individual classes in the phone app have a local DBG constant,
92 * typically set to
93 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
94 * or else
95 * (PhoneApp.DBG_LEVEL >= 2)
96 * depending on the desired verbosity.
97 *
98 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
99 */
Andrew Lee88b51e22014-10-29 15:48:51 -0700100 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700101
102 private static final boolean DBG =
103 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
104 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
105
106 // Message codes; see mHandler below.
107 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700108 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700109 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
110 private static final int EVENT_DATA_ROAMING_OK = 11;
111 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 12;
112 private static final int EVENT_DOCK_STATE_CHANGED = 13;
Sailesh Nepalbf900542014-07-15 16:18:32 -0700113 private static final int EVENT_START_SIP_SERVICE = 14;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114
115 // The MMI codes are also used by the InCallScreen.
116 public static final int MMI_INITIATE = 51;
117 public static final int MMI_COMPLETE = 52;
118 public static final int MMI_CANCEL = 53;
119 // Don't use message codes larger than 99 here; those are reserved for
120 // the individual Activities of the Phone UI.
121
122 /**
123 * Allowable values for the wake lock code.
124 * SLEEP means the device can be put to sleep.
125 * PARTIAL means wake the processor, but we display can be kept off.
126 * FULL means wake both the processor and the display.
127 */
128 public enum WakeState {
129 SLEEP,
130 PARTIAL,
131 FULL
132 }
133
134 /**
135 * Intent Action used for hanging up the current call from Notification bar. This will
136 * choose first ringing call, first active call, or first background call (typically in
137 * HOLDING state).
138 */
139 public static final String ACTION_HANG_UP_ONGOING_CALL =
140 "com.android.phone.ACTION_HANG_UP_ONGOING_CALL";
141
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142 private static PhoneGlobals sMe;
143
144 // A few important fields we expose to the rest of the package
145 // directly (rather than thru set/get methods) for efficiency.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700146 CallController callController;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700147 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700148 CallNotifier notifier;
149 CallerInfoCache callerInfoCache;
Santos Cordon63a84242013-07-23 13:32:52 -0700150 NotificationMgr notificationMgr;
Andrew Lee9431b832015-03-09 18:46:45 -0700151 public PhoneInterfaceManager phoneMgr;
Santos Cordon76aaf482015-04-08 10:58:27 -0700152 public SimActivationManager simActivationManager;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800153 CarrierConfigLoader configLoader;
Santos Cordon63a84242013-07-23 13:32:52 -0700154
Santos Cordon27a3c1f2013-08-06 07:49:27 -0700155 private BluetoothManager bluetoothManager;
Santos Cordon69a69192013-08-22 14:25:42 -0700156 private CallGatewayManager callGatewayManager;
Santos Cordon63a84242013-07-23 13:32:52 -0700157 private CallStateMonitor callStateMonitor;
Santos Cordon63a84242013-07-23 13:32:52 -0700158
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159 static int mDockState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
160 static boolean sVoiceCapable = true;
161
Santos Cordonc593d002015-06-03 15:41:15 -0700162 // TODO: Remove, no longer used.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700163 CdmaPhoneCallState cdmaPhoneCallState;
164
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165 // The currently-active PUK entry activity and progress dialog.
166 // Normally, these are the Emergency Dialer and the subsequent
167 // progress dialog. null if there is are no such objects in
168 // the foreground.
169 private Activity mPUKEntryActivity;
170 private ProgressDialog mPUKEntryProgressDialog;
171
172 private boolean mIsSimPinEnabled;
173 private String mCachedSimPin;
174
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700175 // True if we are beginning a call, but the phone state has not changed yet
176 private boolean mBeginningCall;
Yorke Lee4d2db1c2014-11-06 11:37:09 -0800177 private boolean mDataDisconnectedDueToRoaming = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700178
179 // Last phone state seen by updatePhoneState()
180 private PhoneConstants.State mLastPhoneState = PhoneConstants.State.IDLE;
181
182 private WakeState mWakeState = WakeState.SLEEP;
183
184 private PowerManager mPowerManager;
185 private IPowerManager mPowerManagerService;
186 private PowerManager.WakeLock mWakeLock;
187 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700188 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700189
190 private UpdateLock mUpdateLock;
191
192 // Broadcast receiver for various intent broadcasts (see onCreate())
193 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
194
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195 /** boolean indicating restoring mute state on InCallScreen.onResume() */
196 private boolean mShouldRestoreMuteOnInCallResume;
197
198 /**
199 * The singleton OtaUtils instance used for OTASP calls.
200 *
201 * The OtaUtils instance is created lazily the first time we need to
202 * make an OTASP call, regardless of whether it's an interactive or
203 * non-interactive OTASP call.
204 */
205 public OtaUtils otaUtils;
206
207 // Following are the CDMA OTA information Objects used during OTA Call.
208 // cdmaOtaProvisionData object store static OTA information that needs
209 // to be maintained even during Slider open/close scenarios.
210 // cdmaOtaConfigData object stores configuration info to control visiblity
211 // of each OTA Screens.
212 // cdmaOtaScreenState object store OTA Screen State information.
213 public OtaUtils.CdmaOtaProvisionData cdmaOtaProvisionData;
214 public OtaUtils.CdmaOtaConfigData cdmaOtaConfigData;
215 public OtaUtils.CdmaOtaScreenState cdmaOtaScreenState;
216 public OtaUtils.CdmaOtaInCallScreenUiState cdmaOtaInCallScreenUiState;
217
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700218 /**
219 * Set the restore mute state flag. Used when we are setting the mute state
220 * OUTSIDE of user interaction {@link PhoneUtils#startNewCall(Phone)}
221 */
222 /*package*/void setRestoreMuteOnInCallResume (boolean mode) {
223 mShouldRestoreMuteOnInCallResume = mode;
224 }
225
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700226 Handler mHandler = new Handler() {
227 @Override
228 public void handleMessage(Message msg) {
229 PhoneConstants.State phoneState;
230 switch (msg.what) {
231 // Starts the SIP service. It's a no-op if SIP API is not supported
232 // on the deivce.
233 // TODO: Having the phone process host the SIP service is only
234 // temporary. Will move it to a persistent communication process
235 // later.
236 case EVENT_START_SIP_SERVICE:
237 SipService.start(getApplicationContext());
238 break;
239
240 // TODO: This event should be handled by the lock screen, just
241 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
242 case EVENT_SIM_NETWORK_LOCKED:
Junda Liu12f7d802015-05-01 12:06:44 -0700243 if (getCarrierConfig().getBoolean(CarrierConfigManager.BOOL_IGNORE_SIM_NETWORK_LOCKED_EVENTS)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700244 // Some products don't have the concept of a "SIM network lock"
245 Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; "
246 + "not showing 'SIM network unlock' PIN entry screen");
247 } else {
248 // Normal case: show the "SIM network unlock" PIN entry screen.
249 // The user won't be able to do anything else until
250 // they enter a valid SIM network PIN.
251 Log.i(LOG_TAG, "show sim depersonal panel");
252 IccNetworkDepersonalizationPanel ndpPanel =
253 new IccNetworkDepersonalizationPanel(PhoneGlobals.getInstance());
254 ndpPanel.show();
255 }
256 break;
257
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700258 case EVENT_DATA_ROAMING_DISCONNECTED:
259 notificationMgr.showDataDisconnectedRoaming();
260 break;
261
262 case EVENT_DATA_ROAMING_OK:
263 notificationMgr.hideDataDisconnectedRoaming();
264 break;
265
266 case MMI_COMPLETE:
267 onMMIComplete((AsyncResult) msg.obj);
268 break;
269
270 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800271 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700272 break;
273
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700274 case EVENT_SIM_STATE_CHANGED:
275 // Marks the event where the SIM goes into ready state.
276 // Right now, this is only used for the PUK-unlocking
277 // process.
278 if (msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_READY)) {
279 // when the right event is triggered and there
280 // are UI objects in the foreground, we close
281 // them to display the lock panel.
282 if (mPUKEntryActivity != null) {
283 mPUKEntryActivity.finish();
284 mPUKEntryActivity = null;
285 }
286 if (mPUKEntryProgressDialog != null) {
287 mPUKEntryProgressDialog.dismiss();
288 mPUKEntryProgressDialog = null;
289 }
290 }
291 break;
292
293 case EVENT_UNSOL_CDMA_INFO_RECORD:
294 //TODO: handle message here;
295 break;
296
297 case EVENT_DOCK_STATE_CHANGED:
298 // If the phone is docked/undocked during a call, and no wired or BT headset
299 // is connected: turn on/off the speaker accordingly.
300 boolean inDockMode = false;
301 if (mDockState != Intent.EXTRA_DOCK_STATE_UNDOCKED) {
302 inDockMode = true;
303 }
304 if (VDBG) Log.d(LOG_TAG, "received EVENT_DOCK_STATE_CHANGED. Phone inDock = "
305 + inDockMode);
306
307 phoneState = mCM.getState();
308 if (phoneState == PhoneConstants.State.OFFHOOK &&
Santos Cordon593ab382013-08-06 21:58:23 -0700309 !bluetoothManager.isBluetoothHeadsetAudioOn()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700310 PhoneUtils.turnOnSpeaker(getApplicationContext(), inDockMode, true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700311 }
312 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700313 }
314 }
315 };
316
317 public PhoneGlobals(Context context) {
318 super(context);
319 sMe = this;
320 }
321
322 public void onCreate() {
323 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
324
325 ContentResolver resolver = getContentResolver();
326
327 // Cache the "voice capable" flag.
328 // This flag currently comes from a resource (which is
329 // overrideable on a per-product basis):
330 sVoiceCapable =
331 getResources().getBoolean(com.android.internal.R.bool.config_voice_capable);
332 // ...but this might eventually become a PackageManager "system
333 // feature" instead, in which case we'd do something like:
334 // sVoiceCapable =
335 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
336
Stuart Scottdcf40a92014-12-09 10:45:01 -0800337 if (mCM == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338 // Initialize the telephony framework
339 PhoneFactory.makeDefaultPhones(this);
340
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700341 // Start TelephonyDebugService After the default phone is created.
342 Intent intent = new Intent(this, TelephonyDebugService.class);
343 startService(intent);
344
345 mCM = CallManager.getInstance();
Stuart Scottdcf40a92014-12-09 10:45:01 -0800346 boolean hasCdmaPhoneType = false;
347 for (Phone phone : PhoneFactory.getPhones()) {
348 mCM.registerPhone(phone);
349 if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
350 hasCdmaPhoneType = true;
351 }
352 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700353
354 // Create the NotificationMgr singleton, which is used to display
355 // status bar icons and control other status bar behavior.
356 notificationMgr = NotificationMgr.init(this);
357
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358 mHandler.sendEmptyMessage(EVENT_START_SIP_SERVICE);
359
Stuart Scottdcf40a92014-12-09 10:45:01 -0800360 if (hasCdmaPhoneType) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
362 cdmaPhoneCallState = new CdmaPhoneCallState();
363 cdmaPhoneCallState.CdmaPhoneCallStateInit();
364 }
365
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366 // before registering for phone state changes
367 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
368 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
369 // lock used to keep the processor awake, when we don't care for the display.
370 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
371 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372
373 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
374
375 // get a handle to the service so that we can use it later when we
376 // want to set the poke lock.
377 mPowerManagerService = IPowerManager.Stub.asInterface(
378 ServiceManager.getService("power"));
379
380 // Get UpdateLock to suppress system-update related events (e.g. dialog show-up)
381 // during phone calls.
382 mUpdateLock = new UpdateLock("phone");
383
384 if (DBG) Log.d(LOG_TAG, "onCreate: mUpdateLock: " + mUpdateLock);
385
386 CallLogger callLogger = new CallLogger(this, new CallLogAsync());
387
Jay Shrauner21a75342013-11-25 16:14:43 -0800388 callGatewayManager = CallGatewayManager.getInstance();
Santos Cordon69a69192013-08-22 14:25:42 -0700389
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700390 // Create the CallController singleton, which is the interface
391 // to the telephony layer for user-initiated telephony functionality
392 // (like making outgoing calls.)
Santos Cordon69a69192013-08-22 14:25:42 -0700393 callController = CallController.init(this, callLogger, callGatewayManager);
394
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700395 // Create the CallerInfoCache singleton, which remembers custom ring tone and
396 // send-to-voicemail settings.
397 //
398 // The asynchronous caching will start just after this call.
399 callerInfoCache = CallerInfoCache.init(this);
400
401 // Monitors call activity from the telephony layer
402 callStateMonitor = new CallStateMonitor(mCM);
403
Santos Cordon2c2d3cf2013-08-08 03:53:47 -0700404 // Bluetooth manager
Sailesh Nepal23d9ed72014-07-03 09:40:26 -0700405 bluetoothManager = new BluetoothManager();
Santos Cordon2c2d3cf2013-08-08 03:53:47 -0700406
Stuart Scottdcf40a92014-12-09 10:45:01 -0800407 phoneMgr = PhoneInterfaceManager.init(this, PhoneFactory.getDefaultPhone());
Santos Cordon406c0342013-08-28 00:07:47 -0700408
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800409 configLoader = CarrierConfigLoader.init(this);
410
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700411 // Create the CallNotifer singleton, which handles
412 // asynchronous events from the telephony layer (like
413 // launching the incoming-call UI when an incoming call comes
414 // in.)
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800415 notifier = CallNotifier.init(this, callLogger, callStateMonitor, bluetoothManager);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416
Stuart Scottdcf40a92014-12-09 10:45:01 -0800417 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700418
419 // register for MMI/USSD
420 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
421
422 // register connection tracking to PhoneUtils
423 PhoneUtils.initializeConnectionHandler(mCM);
424
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700425 // Register for misc other intent broadcasts.
426 IntentFilter intentFilter =
427 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700428 intentFilter.addAction(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700429 intentFilter.addAction(Intent.ACTION_DOCK_EVENT);
430 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
431 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
432 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
433 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434 registerReceiver(mReceiver, intentFilter);
435
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700436 //set the default values for the preferences in the phone.
437 PreferenceManager.setDefaultValues(this, R.xml.network_setting, false);
438
439 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
440
441 // Make sure the audio mode (along with some
442 // audio-mode-related state of our own) is initialized
443 // correctly, given the current state of the phone.
444 PhoneUtils.setAudioMode(mCM);
445 }
446
Santos Cordon52bc81b2014-10-07 19:55:12 -0700447 cdmaOtaProvisionData = new OtaUtils.CdmaOtaProvisionData();
448 cdmaOtaConfigData = new OtaUtils.CdmaOtaConfigData();
449 cdmaOtaScreenState = new OtaUtils.CdmaOtaScreenState();
450 cdmaOtaInCallScreenUiState = new OtaUtils.CdmaOtaInCallScreenUiState();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700451
Santos Cordon76aaf482015-04-08 10:58:27 -0700452 simActivationManager = new SimActivationManager();
453
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700454 // XXX pre-load the SimProvider so that it's ready
455 resolver.getType(Uri.parse("content://icc/adn"));
456
457 // start with the default value to set the mute state.
458 mShouldRestoreMuteOnInCallResume = false;
459
460 // TODO: Register for Cdma Information Records
461 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
462
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700463 // Read HAC settings and configure audio hardware
464 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800465 int hac = android.provider.Settings.System.getInt(
466 getContentResolver(),
467 android.provider.Settings.System.HEARING_AID,
468 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700469 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Andrew Leefb7f92e2015-02-26 16:23:32 -0800470 audioManager.setParameter(SettingsConstants.HAC_KEY,
471 hac == SettingsConstants.HAC_ENABLED
472 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700473 }
Santos Cordonff506f52013-11-21 19:13:19 -0800474 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700475
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700476 /**
477 * Returns the singleton instance of the PhoneApp.
478 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800479 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700480 if (sMe == null) {
481 throw new IllegalStateException("No PhoneGlobals here!");
482 }
483 return sMe;
484 }
485
486 /**
487 * Returns the singleton instance of the PhoneApp if running as the
488 * primary user, otherwise null.
489 */
490 static PhoneGlobals getInstanceIfPrimary() {
491 return sMe;
492 }
493
494 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800495 * Returns the default phone.
496 *
Andrew Lee385019f2014-11-24 14:19:50 -0800497 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700498 */
Andrew Lee83383e42014-10-31 12:42:28 -0700499 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800500 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700501 }
502
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800503 public static Phone getPhone(int subId) {
504 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800505 }
506
Santos Cordon27a3c1f2013-08-06 07:49:27 -0700507 /* package */ BluetoothManager getBluetoothManager() {
508 return bluetoothManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700509 }
510
Santos Cordonde10b752013-09-19 04:11:33 -0700511 /* package */ CallManager getCallManager() {
512 return mCM;
513 }
514
Jonathan Basseric31f1f32015-05-12 10:13:03 -0700515 /* package */ PersistableBundle getCarrierConfig() {
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700516 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubId());
517 }
518
Jonathan Basseric31f1f32015-05-12 10:13:03 -0700519 /* package */ PersistableBundle getCarrierConfigForSubId(int subId) {
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700520 return configLoader.getConfigForSubId(subId);
Junda Liu605148f2015-04-28 15:23:40 -0700521 }
522
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700523 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700524 * Returns PendingIntent for hanging up ongoing phone call. This will typically be used from
525 * Notification context.
526 */
527 /* package */ static PendingIntent createHangUpOngoingCallPendingIntent(Context context) {
528 Intent intent = new Intent(PhoneGlobals.ACTION_HANG_UP_ONGOING_CALL, null,
529 context, NotificationBroadcastReceiver.class);
530 return PendingIntent.getBroadcast(context, 0, intent, 0);
531 }
532
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700533 boolean isSimPinEnabled() {
534 return mIsSimPinEnabled;
535 }
536
537 boolean authenticateAgainstCachedSimPin(String pin) {
538 return (mCachedSimPin != null && mCachedSimPin.equals(pin));
539 }
540
541 void setCachedSimPin(String pin) {
542 mCachedSimPin = pin;
543 }
544
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700545 /**
546 * Handles OTASP-related events from the telephony layer.
547 *
548 * While an OTASP call is active, the CallNotifier forwards
549 * OTASP-related telephony events to this method.
550 */
551 void handleOtaspEvent(Message msg) {
552 if (DBG) Log.d(LOG_TAG, "handleOtaspEvent(message " + msg + ")...");
553
554 if (otaUtils == null) {
555 // We shouldn't be getting OTASP events without ever
556 // having started the OTASP call in the first place!
557 Log.w(LOG_TAG, "handleOtaEvents: got an event but otaUtils is null! "
558 + "message = " + msg);
559 return;
560 }
561
562 otaUtils.onOtaProvisionStatusChanged((AsyncResult) msg.obj);
563 }
564
565 /**
566 * Similarly, handle the disconnect event of an OTASP call
567 * by forwarding it to the OtaUtils instance.
568 */
569 /* package */ void handleOtaspDisconnect() {
570 if (DBG) Log.d(LOG_TAG, "handleOtaspDisconnect()...");
571
572 if (otaUtils == null) {
573 // We shouldn't be getting OTASP events without ever
574 // having started the OTASP call in the first place!
575 Log.w(LOG_TAG, "handleOtaspDisconnect: otaUtils is null!");
576 return;
577 }
578
579 otaUtils.onOtaspDisconnect();
580 }
581
582 /**
583 * Sets the activity responsible for un-PUK-blocking the device
584 * so that we may close it when we receive a positive result.
585 * mPUKEntryActivity is also used to indicate to the device that
586 * we are trying to un-PUK-lock the phone. In other words, iff
587 * it is NOT null, then we are trying to unlock and waiting for
588 * the SIM to move to READY state.
589 *
590 * @param activity is the activity to close when PUK has
591 * finished unlocking. Can be set to null to indicate the unlock
592 * or SIM READYing process is over.
593 */
594 void setPukEntryActivity(Activity activity) {
595 mPUKEntryActivity = activity;
596 }
597
598 Activity getPUKEntryActivity() {
599 return mPUKEntryActivity;
600 }
601
602 /**
603 * Sets the dialog responsible for notifying the user of un-PUK-
604 * blocking - SIM READYing progress, so that we may dismiss it
605 * when we receive a positive result.
606 *
607 * @param dialog indicates the progress dialog informing the user
608 * of the state of the device. Dismissed upon completion of
609 * READYing process
610 */
611 void setPukEntryProgressDialog(ProgressDialog dialog) {
612 mPUKEntryProgressDialog = dialog;
613 }
614
615 ProgressDialog getPUKEntryProgressDialog() {
616 return mPUKEntryProgressDialog;
617 }
618
619 /**
620 * Controls whether or not the screen is allowed to sleep.
621 *
622 * Once sleep is allowed (WakeState is SLEEP), it will rely on the
623 * settings for the poke lock to determine when to timeout and let
624 * the device sleep {@link PhoneGlobals#setScreenTimeout}.
625 *
626 * @param ws tells the device to how to wake.
627 */
628 /* package */ void requestWakeState(WakeState ws) {
629 if (VDBG) Log.d(LOG_TAG, "requestWakeState(" + ws + ")...");
630 synchronized (this) {
631 if (mWakeState != ws) {
632 switch (ws) {
633 case PARTIAL:
634 // acquire the processor wake lock, and release the FULL
635 // lock if it is being held.
636 mPartialWakeLock.acquire();
637 if (mWakeLock.isHeld()) {
638 mWakeLock.release();
639 }
640 break;
641 case FULL:
642 // acquire the full wake lock, and release the PARTIAL
643 // lock if it is being held.
644 mWakeLock.acquire();
645 if (mPartialWakeLock.isHeld()) {
646 mPartialWakeLock.release();
647 }
648 break;
649 case SLEEP:
650 default:
651 // release both the PARTIAL and FULL locks.
652 if (mWakeLock.isHeld()) {
653 mWakeLock.release();
654 }
655 if (mPartialWakeLock.isHeld()) {
656 mPartialWakeLock.release();
657 }
658 break;
659 }
660 mWakeState = ws;
661 }
662 }
663 }
664
665 /**
666 * If we are not currently keeping the screen on, then poke the power
667 * manager to wake up the screen for the user activity timeout duration.
668 */
669 /* package */ void wakeUpScreen() {
670 synchronized (this) {
671 if (mWakeState == WakeState.SLEEP) {
672 if (DBG) Log.d(LOG_TAG, "pulse screen lock");
673 mPowerManager.wakeUp(SystemClock.uptimeMillis());
674 }
675 }
676 }
677
678 /**
679 * Sets the wake state and screen timeout based on the current state
680 * of the phone, and the current state of the in-call UI.
681 *
682 * This method is a "UI Policy" wrapper around
683 * {@link PhoneGlobals#requestWakeState} and {@link PhoneGlobals#setScreenTimeout}.
684 *
685 * It's safe to call this method regardless of the state of the Phone
686 * (e.g. whether or not it's idle), and regardless of the state of the
687 * Phone UI (e.g. whether or not the InCallScreen is active.)
688 */
689 /* package */ void updateWakeState() {
690 PhoneConstants.State state = mCM.getState();
691
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700692 // True if the speakerphone is in use. (If so, we *always* use
693 // the default timeout. Since the user is obviously not holding
694 // the phone up to his/her face, we don't need to worry about
695 // false touches, and thus don't need to turn the screen off so
696 // aggressively.)
697 // Note that we need to make a fresh call to this method any
698 // time the speaker state changes. (That happens in
699 // PhoneUtils.turnOnSpeaker().)
700 boolean isSpeakerInUse = (state == PhoneConstants.State.OFFHOOK) && PhoneUtils.isSpeakerOn(this);
701
702 // TODO (bug 1440854): The screen timeout *might* also need to
703 // depend on the bluetooth state, but this isn't as clear-cut as
704 // the speaker state (since while using BT it's common for the
705 // user to put the phone straight into a pocket, in which case the
706 // timeout should probably still be short.)
707
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700708 // Decide whether to force the screen on or not.
709 //
710 // Force the screen to be on if the phone is ringing or dialing,
711 // or if we're displaying the "Call ended" UI for a connection in
712 // the "disconnected" state.
713 // However, if the phone is disconnected while the user is in the
714 // middle of selecting a quick response message, we should not force
715 // the screen to be on.
716 //
717 boolean isRinging = (state == PhoneConstants.State.RINGING);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800718 boolean isDialing = (mCM.getFgPhone().getForegroundCall().getState() == Call.State.DIALING);
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700719 boolean keepScreenOn = isRinging || isDialing;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700720 // keepScreenOn == true means we'll hold a full wake lock:
721 requestWakeState(keepScreenOn ? WakeState.FULL : WakeState.SLEEP);
722 }
723
724 /**
725 * Manually pokes the PowerManager's userActivity method. Since we
726 * set the {@link WindowManager.LayoutParams#INPUT_FEATURE_DISABLE_USER_ACTIVITY}
727 * flag while the InCallScreen is active when there is no proximity sensor,
728 * we need to do this for touch events that really do count as user activity
729 * (like pressing any onscreen UI elements.)
730 */
731 /* package */ void pokeUserActivity() {
732 if (VDBG) Log.d(LOG_TAG, "pokeUserActivity()...");
733 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
734 }
735
736 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700737 * Notifies the phone app when the phone state changes.
738 *
Santos Cordonfc309812013-08-20 18:33:16 -0700739 * This method will updates various states inside Phone app (e.g. update-lock state, etc.)
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700740 */
741 /* package */ void updatePhoneState(PhoneConstants.State state) {
742 if (state != mLastPhoneState) {
743 mLastPhoneState = state;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700744
745 // Try to acquire or release UpdateLock.
746 //
747 // Watch out: we don't release the lock here when the screen is still in foreground.
748 // At that time InCallScreen will release it on onPause().
749 if (state != PhoneConstants.State.IDLE) {
750 // UpdateLock is a recursive lock, while we may get "acquire" request twice and
751 // "release" request once for a single call (RINGING + OFFHOOK and IDLE).
752 // We need to manually ensure the lock is just acquired once for each (and this
753 // will prevent other possible buggy situations too).
754 if (!mUpdateLock.isHeld()) {
755 mUpdateLock.acquire();
756 }
757 } else {
Jay Shraunera5d13212013-09-19 13:37:43 -0700758 if (mUpdateLock.isHeld()) {
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700759 mUpdateLock.release();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700760 }
761 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700762 }
763 }
764
765 /* package */ PhoneConstants.State getPhoneState() {
766 return mLastPhoneState;
767 }
768
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700769 KeyguardManager getKeyguardManager() {
770 return mKeyguardManager;
771 }
772
773 private void onMMIComplete(AsyncResult r) {
774 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
775 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800776 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700777 }
778
Stuart Scottdcf40a92014-12-09 10:45:01 -0800779 private void initForNewRadioTechnology(int phoneId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700780 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
781
Stuart Scottdcf40a92014-12-09 10:45:01 -0800782 final Phone phone = PhoneFactory.getPhone(phoneId);
Santos Cordonc593d002015-06-03 15:41:15 -0700783 if (phone == null || !TelephonyCapabilities.supportsOtasp(phone)) {
784 // Clean up OTA for non-CDMA since it is only valid for CDMA.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700785 clearOtaState();
786 }
787
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700788 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
789 callStateMonitor.updateAfterRadioTechnologyChange();
790
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700791 // Update registration for ICC status after radio technology change
Santos Cordonc593d002015-06-03 15:41:15 -0700792 IccCard sim = phone == null ? null : phone.getIccCard();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700793 if (sim != null) {
794 if (DBG) Log.d(LOG_TAG, "Update registration for ICC status...");
795
796 //Register all events new to the new active phone
797 sim.registerForNetworkLocked(mHandler, EVENT_SIM_NETWORK_LOCKED, null);
798 }
799 }
800
Santos Cordon593ab382013-08-06 21:58:23 -0700801 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700802 * Receiver for misc intent broadcasts the Phone app cares about.
803 */
804 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
805 @Override
806 public void onReceive(Context context, Intent intent) {
807 String action = intent.getAction();
808 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
809 boolean enabled = System.getInt(getContentResolver(),
810 System.AIRPLANE_MODE_ON, 0) == 0;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800811 PhoneUtils.setRadioPower(enabled);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700812 } else if (action.equals(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800813 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
814 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
815 int phoneId = SubscriptionManager.getPhoneId(subId);
816 String state = intent.getStringExtra(PhoneConstants.STATE_KEY);
817 if (VDBG) {
818 Log.d(LOG_TAG, "mReceiver: ACTION_ANY_DATA_CONNECTION_STATE_CHANGED");
819 Log.d(LOG_TAG, "- state: " + state);
820 Log.d(LOG_TAG, "- reason: "
821 + intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY));
822 Log.d(LOG_TAG, "- subId: " + subId);
823 Log.d(LOG_TAG, "- phoneId: " + phoneId);
824 }
825 Phone phone = SubscriptionManager.isValidPhoneId(phoneId) ?
826 PhoneFactory.getPhone(phoneId) : PhoneFactory.getDefaultPhone();
Santos Cordonc593d002015-06-03 15:41:15 -0700827
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700828 // The "data disconnected due to roaming" notification is shown
829 // if (a) you have the "data roaming" feature turned off, and
830 // (b) you just lost data connectivity because you're roaming.
831 boolean disconnectedDueToRoaming =
832 !phone.getDataRoamingEnabled()
Stuart Scottdcf40a92014-12-09 10:45:01 -0800833 && PhoneConstants.DataState.DISCONNECTED.equals(state)
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700834 && Phone.REASON_ROAMING_ON.equals(
835 intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY));
Yorke Lee4d2db1c2014-11-06 11:37:09 -0800836 if (mDataDisconnectedDueToRoaming != disconnectedDueToRoaming) {
837 mDataDisconnectedDueToRoaming = disconnectedDueToRoaming;
838 mHandler.sendEmptyMessage(disconnectedDueToRoaming
839 ? EVENT_DATA_ROAMING_DISCONNECTED : EVENT_DATA_ROAMING_OK);
840 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700841 } else if ((action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) &&
842 (mPUKEntryActivity != null)) {
843 // if an attempt to un-PUK-lock the device was made, while we're
844 // receiving this state change notification, notify the handler.
845 // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has
846 // been attempted.
847 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
848 intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE)));
849 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
850 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800851 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
852 SubscriptionManager.INVALID_PHONE_INDEX);
853 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " (" + phoneId
854 + ") is active.");
855 initForNewRadioTechnology(phoneId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700856 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
857 handleServiceStateChanged(intent);
858 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800859 if (TelephonyCapabilities.supportsEcm(mCM.getFgPhone())) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700860 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
861 // Start Emergency Callback Mode service
862 if (intent.getBooleanExtra("phoneinECMState", false)) {
863 context.startService(new Intent(context,
864 EmergencyCallbackModeService.class));
865 }
866 } else {
867 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
868 // on a device that doesn't support ECM in the first place.
869 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, "
Stuart Scottdcf40a92014-12-09 10:45:01 -0800870 + "but ECM isn't supported for phone: "
871 + mCM.getFgPhone().getPhoneName());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700872 }
873 } else if (action.equals(Intent.ACTION_DOCK_EVENT)) {
874 mDockState = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
875 Intent.EXTRA_DOCK_STATE_UNDOCKED);
876 if (VDBG) Log.d(LOG_TAG, "ACTION_DOCK_EVENT -> mDockState = " + mDockState);
877 mHandler.sendMessage(mHandler.obtainMessage(EVENT_DOCK_STATE_CHANGED, 0));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700878 }
879 }
880 }
881
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700882 /**
883 * Accepts broadcast Intents which will be prepared by {@link NotificationMgr} and thus
884 * sent from framework's notification mechanism (which is outside Phone context).
885 * This should be visible from outside, but shouldn't be in "exported" state.
886 *
887 * TODO: If possible merge this into PhoneAppBroadcastReceiver.
888 */
889 public static class NotificationBroadcastReceiver extends BroadcastReceiver {
890 @Override
891 public void onReceive(Context context, Intent intent) {
892 String action = intent.getAction();
893 // TODO: use "if (VDBG)" here.
894 Log.d(LOG_TAG, "Broadcast from Notification: " + action);
895
896 if (action.equals(ACTION_HANG_UP_ONGOING_CALL)) {
897 PhoneUtils.hangup(PhoneGlobals.getInstance().mCM);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700898 } else {
899 Log.w(LOG_TAG, "Received hang-up request from notification,"
900 + " but there's no call the system can hang up.");
901 }
902 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700903 }
904
905 private void handleServiceStateChanged(Intent intent) {
906 /**
907 * This used to handle updating EriTextWidgetProvider this routine
908 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
909 * be removed. But leaving just in case it might be needed in the near
910 * future.
911 */
912
913 // If service just returned, start sending out the queued messages
Santos Cordonc593d002015-06-03 15:41:15 -0700914 Bundle extras = intent.getExtras();
915 if (extras != null) {
916 ServiceState ss = ServiceState.newFromBundle(extras);
917 if (ss != null) {
918 int state = ss.getState();
919 notificationMgr.updateNetworkSelection(state);
920 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700921 }
922 }
923
924 public boolean isOtaCallInActiveState() {
925 boolean otaCallActive = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700926 if (VDBG) Log.d(LOG_TAG, "- isOtaCallInActiveState " + otaCallActive);
927 return otaCallActive;
928 }
929
930 public boolean isOtaCallInEndState() {
931 boolean otaCallEnded = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700932 if (VDBG) Log.d(LOG_TAG, "- isOtaCallInEndState " + otaCallEnded);
933 return otaCallEnded;
934 }
935
936 // it is safe to call clearOtaState() even if the InCallScreen isn't active
937 public void clearOtaState() {
938 if (DBG) Log.d(LOG_TAG, "- clearOtaState ...");
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700939 if (otaUtils != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700940 otaUtils.cleanOtaScreen(true);
941 if (DBG) Log.d(LOG_TAG, " - clearOtaState clears OTA screen");
942 }
943 }
944
945 // it is safe to call dismissOtaDialogs() even if the InCallScreen isn't active
946 public void dismissOtaDialogs() {
947 if (DBG) Log.d(LOG_TAG, "- dismissOtaDialogs ...");
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700948 if (otaUtils != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700949 otaUtils.dismissAllOtaDialogs();
950 if (DBG) Log.d(LOG_TAG, " - dismissOtaDialogs clears OTA dialogs");
951 }
952 }
953
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700954 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800955 * Triggers a refresh of the message waiting (voicemail) indicator.
956 *
957 * @param subId the subscription id we should refresh the notification for.
958 */
959 public void refreshMwiIndicator(int subId) {
960 notificationMgr.refreshMwi(subId);
961 }
962
963 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700964 * "Call origin" may be used by Contacts app to specify where the phone call comes from.
965 * Currently, the only permitted value for this extra is {@link #ALLOWED_EXTRA_CALL_ORIGIN}.
966 * Any other value will be ignored, to make sure that malicious apps can't trick the in-call
967 * UI into launching some random other app after a call ends.
968 *
969 * TODO: make this more generic. Note that we should let the "origin" specify its package
970 * while we are now assuming it is "com.android.contacts"
971 */
972 public static final String EXTRA_CALL_ORIGIN = "com.android.phone.CALL_ORIGIN";
973 private static final String DEFAULT_CALL_ORIGIN_PACKAGE = "com.android.dialer";
974 private static final String ALLOWED_EXTRA_CALL_ORIGIN =
975 "com.android.dialer.DialtactsActivity";
976 /**
977 * Used to determine if the preserved call origin is fresh enough.
978 */
979 private static final long CALL_ORIGIN_EXPIRATION_MILLIS = 30 * 1000;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700980}