blob: 9f14a93bfee14499f034893e05e760f4ea739927 [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;
42import android.os.PowerManager;
43import android.os.RemoteException;
44import android.os.ServiceManager;
45import android.os.SystemClock;
46import android.os.SystemProperties;
47import android.os.UpdateLock;
48import android.os.UserHandle;
49import android.preference.PreferenceManager;
50import android.provider.Settings.System;
51import android.telephony.ServiceState;
Andrew Lee2fcb6c32014-12-04 14:52:35 -080052import android.telephony.SubscriptionInfo;
Andrew Lee385019f2014-11-24 14:19:50 -080053import android.telephony.SubscriptionManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.util.Log;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055
56import com.android.internal.telephony.Call;
57import com.android.internal.telephony.CallManager;
58import com.android.internal.telephony.IccCard;
59import com.android.internal.telephony.IccCardConstants;
60import com.android.internal.telephony.MmiCode;
61import com.android.internal.telephony.Phone;
62import com.android.internal.telephony.PhoneConstants;
63import com.android.internal.telephony.PhoneFactory;
Andrew Lee385019f2014-11-24 14:19:50 -080064import com.android.internal.telephony.SubscriptionController;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import com.android.internal.telephony.TelephonyCapabilities;
66import com.android.internal.telephony.TelephonyIntents;
Santos Cordon352ff652014-05-30 01:41:45 -070067import com.android.phone.common.CallLogAsync;
Andrew Leefb7f92e2015-02-26 16:23:32 -080068import com.android.phone.settings.SettingsConstants;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070069import com.android.server.sip.SipService;
Santos Cordon76aaf482015-04-08 10:58:27 -070070import com.android.services.telephony.activation.SimActivationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070071
Andrew Lee385019f2014-11-24 14:19:50 -080072import java.util.ArrayList;
73import java.util.List;
74
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075/**
76 * Global state for the telephony subsystem when running in the primary
77 * phone process.
78 */
Sailesh Nepalbf900542014-07-15 16:18:32 -070079public class PhoneGlobals extends ContextWrapper {
Andrew Lee83383e42014-10-31 12:42:28 -070080 public static final String LOG_TAG = "PhoneApp";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081
82 /**
83 * Phone app-wide debug level:
84 * 0 - no debug logging
85 * 1 - normal debug logging if ro.debuggable is set (which is true in
86 * "eng" and "userdebug" builds but not "user" builds)
87 * 2 - ultra-verbose debug logging
88 *
89 * Most individual classes in the phone app have a local DBG constant,
90 * typically set to
91 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
92 * or else
93 * (PhoneApp.DBG_LEVEL >= 2)
94 * depending on the desired verbosity.
95 *
96 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
97 */
Andrew Lee88b51e22014-10-29 15:48:51 -070098 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099
100 private static final boolean DBG =
101 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
102 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
103
104 // Message codes; see mHandler below.
105 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
108 private static final int EVENT_DATA_ROAMING_OK = 11;
109 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 12;
110 private static final int EVENT_DOCK_STATE_CHANGED = 13;
Sailesh Nepalbf900542014-07-15 16:18:32 -0700111 private static final int EVENT_START_SIP_SERVICE = 14;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700112
113 // The MMI codes are also used by the InCallScreen.
114 public static final int MMI_INITIATE = 51;
115 public static final int MMI_COMPLETE = 52;
116 public static final int MMI_CANCEL = 53;
117 // Don't use message codes larger than 99 here; those are reserved for
118 // the individual Activities of the Phone UI.
119
120 /**
121 * Allowable values for the wake lock code.
122 * SLEEP means the device can be put to sleep.
123 * PARTIAL means wake the processor, but we display can be kept off.
124 * FULL means wake both the processor and the display.
125 */
126 public enum WakeState {
127 SLEEP,
128 PARTIAL,
129 FULL
130 }
131
132 /**
133 * Intent Action used for hanging up the current call from Notification bar. This will
134 * choose first ringing call, first active call, or first background call (typically in
135 * HOLDING state).
136 */
137 public static final String ACTION_HANG_UP_ONGOING_CALL =
138 "com.android.phone.ACTION_HANG_UP_ONGOING_CALL";
139
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140 private static PhoneGlobals sMe;
141
142 // A few important fields we expose to the rest of the package
143 // directly (rather than thru set/get methods) for efficiency.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700144 CallController callController;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700145 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700146 CallNotifier notifier;
147 CallerInfoCache callerInfoCache;
Santos Cordon63a84242013-07-23 13:32:52 -0700148 NotificationMgr notificationMgr;
Andrew Lee9431b832015-03-09 18:46:45 -0700149 public PhoneInterfaceManager phoneMgr;
Santos Cordon76aaf482015-04-08 10:58:27 -0700150 public SimActivationManager simActivationManager;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800151 CarrierConfigLoader configLoader;
Santos Cordon63a84242013-07-23 13:32:52 -0700152
Santos Cordon27a3c1f2013-08-06 07:49:27 -0700153 private BluetoothManager bluetoothManager;
Santos Cordon69a69192013-08-22 14:25:42 -0700154 private CallGatewayManager callGatewayManager;
Santos Cordon63a84242013-07-23 13:32:52 -0700155 private CallStateMonitor callStateMonitor;
Santos Cordon63a84242013-07-23 13:32:52 -0700156
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157 static int mDockState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
158 static boolean sVoiceCapable = true;
159
160 // Internal PhoneApp Call state tracker
161 CdmaPhoneCallState cdmaPhoneCallState;
162
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700163 // The currently-active PUK entry activity and progress dialog.
164 // Normally, these are the Emergency Dialer and the subsequent
165 // progress dialog. null if there is are no such objects in
166 // the foreground.
167 private Activity mPUKEntryActivity;
168 private ProgressDialog mPUKEntryProgressDialog;
169
170 private boolean mIsSimPinEnabled;
171 private String mCachedSimPin;
172
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173 // True if we are beginning a call, but the phone state has not changed yet
174 private boolean mBeginningCall;
Yorke Lee4d2db1c2014-11-06 11:37:09 -0800175 private boolean mDataDisconnectedDueToRoaming = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700176
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
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700216 /**
217 * Set the restore mute state flag. Used when we are setting the mute state
218 * OUTSIDE of user interaction {@link PhoneUtils#startNewCall(Phone)}
219 */
220 /*package*/void setRestoreMuteOnInCallResume (boolean mode) {
221 mShouldRestoreMuteOnInCallResume = mode;
222 }
223
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700224 Handler mHandler = new Handler() {
225 @Override
226 public void handleMessage(Message msg) {
227 PhoneConstants.State phoneState;
228 switch (msg.what) {
229 // Starts the SIP service. It's a no-op if SIP API is not supported
230 // on the deivce.
231 // TODO: Having the phone process host the SIP service is only
232 // temporary. Will move it to a persistent communication process
233 // later.
234 case EVENT_START_SIP_SERVICE:
235 SipService.start(getApplicationContext());
236 break;
237
238 // TODO: This event should be handled by the lock screen, just
239 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
240 case EVENT_SIM_NETWORK_LOCKED:
241 if (getResources().getBoolean(R.bool.ignore_sim_network_locked_events)) {
242 // Some products don't have the concept of a "SIM network lock"
243 Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; "
244 + "not showing 'SIM network unlock' PIN entry screen");
245 } else {
246 // Normal case: show the "SIM network unlock" PIN entry screen.
247 // The user won't be able to do anything else until
248 // they enter a valid SIM network PIN.
249 Log.i(LOG_TAG, "show sim depersonal panel");
250 IccNetworkDepersonalizationPanel ndpPanel =
251 new IccNetworkDepersonalizationPanel(PhoneGlobals.getInstance());
252 ndpPanel.show();
253 }
254 break;
255
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700256 case EVENT_DATA_ROAMING_DISCONNECTED:
257 notificationMgr.showDataDisconnectedRoaming();
258 break;
259
260 case EVENT_DATA_ROAMING_OK:
261 notificationMgr.hideDataDisconnectedRoaming();
262 break;
263
264 case MMI_COMPLETE:
265 onMMIComplete((AsyncResult) msg.obj);
266 break;
267
268 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800269 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700270 break;
271
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700272 case EVENT_SIM_STATE_CHANGED:
273 // Marks the event where the SIM goes into ready state.
274 // Right now, this is only used for the PUK-unlocking
275 // process.
276 if (msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_READY)) {
277 // when the right event is triggered and there
278 // are UI objects in the foreground, we close
279 // them to display the lock panel.
280 if (mPUKEntryActivity != null) {
281 mPUKEntryActivity.finish();
282 mPUKEntryActivity = null;
283 }
284 if (mPUKEntryProgressDialog != null) {
285 mPUKEntryProgressDialog.dismiss();
286 mPUKEntryProgressDialog = null;
287 }
288 }
289 break;
290
291 case EVENT_UNSOL_CDMA_INFO_RECORD:
292 //TODO: handle message here;
293 break;
294
295 case EVENT_DOCK_STATE_CHANGED:
296 // If the phone is docked/undocked during a call, and no wired or BT headset
297 // is connected: turn on/off the speaker accordingly.
298 boolean inDockMode = false;
299 if (mDockState != Intent.EXTRA_DOCK_STATE_UNDOCKED) {
300 inDockMode = true;
301 }
302 if (VDBG) Log.d(LOG_TAG, "received EVENT_DOCK_STATE_CHANGED. Phone inDock = "
303 + inDockMode);
304
305 phoneState = mCM.getState();
306 if (phoneState == PhoneConstants.State.OFFHOOK &&
Santos Cordon593ab382013-08-06 21:58:23 -0700307 !bluetoothManager.isBluetoothHeadsetAudioOn()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700308 PhoneUtils.turnOnSpeaker(getApplicationContext(), inDockMode, true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700309 }
310 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700311 }
312 }
313 };
314
315 public PhoneGlobals(Context context) {
316 super(context);
317 sMe = this;
318 }
319
320 public void onCreate() {
321 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
322
323 ContentResolver resolver = getContentResolver();
324
325 // Cache the "voice capable" flag.
326 // This flag currently comes from a resource (which is
327 // overrideable on a per-product basis):
328 sVoiceCapable =
329 getResources().getBoolean(com.android.internal.R.bool.config_voice_capable);
330 // ...but this might eventually become a PackageManager "system
331 // feature" instead, in which case we'd do something like:
332 // sVoiceCapable =
333 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
334
Stuart Scottdcf40a92014-12-09 10:45:01 -0800335 if (mCM == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700336 // Initialize the telephony framework
337 PhoneFactory.makeDefaultPhones(this);
338
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700339 // Start TelephonyDebugService After the default phone is created.
340 Intent intent = new Intent(this, TelephonyDebugService.class);
341 startService(intent);
342
343 mCM = CallManager.getInstance();
Stuart Scottdcf40a92014-12-09 10:45:01 -0800344 boolean hasCdmaPhoneType = false;
345 for (Phone phone : PhoneFactory.getPhones()) {
346 mCM.registerPhone(phone);
347 if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
348 hasCdmaPhoneType = true;
349 }
350 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700351
352 // Create the NotificationMgr singleton, which is used to display
353 // status bar icons and control other status bar behavior.
354 notificationMgr = NotificationMgr.init(this);
355
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356 mHandler.sendEmptyMessage(EVENT_START_SIP_SERVICE);
357
Stuart Scottdcf40a92014-12-09 10:45:01 -0800358 if (hasCdmaPhoneType) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
360 cdmaPhoneCallState = new CdmaPhoneCallState();
361 cdmaPhoneCallState.CdmaPhoneCallStateInit();
362 }
363
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700364 // before registering for phone state changes
365 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
366 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
367 // lock used to keep the processor awake, when we don't care for the display.
368 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
369 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370
371 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
372
373 // get a handle to the service so that we can use it later when we
374 // want to set the poke lock.
375 mPowerManagerService = IPowerManager.Stub.asInterface(
376 ServiceManager.getService("power"));
377
378 // Get UpdateLock to suppress system-update related events (e.g. dialog show-up)
379 // during phone calls.
380 mUpdateLock = new UpdateLock("phone");
381
382 if (DBG) Log.d(LOG_TAG, "onCreate: mUpdateLock: " + mUpdateLock);
383
384 CallLogger callLogger = new CallLogger(this, new CallLogAsync());
385
Jay Shrauner21a75342013-11-25 16:14:43 -0800386 callGatewayManager = CallGatewayManager.getInstance();
Santos Cordon69a69192013-08-22 14:25:42 -0700387
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388 // Create the CallController singleton, which is the interface
389 // to the telephony layer for user-initiated telephony functionality
390 // (like making outgoing calls.)
Santos Cordon69a69192013-08-22 14:25:42 -0700391 callController = CallController.init(this, callLogger, callGatewayManager);
392
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700393 // Create the CallerInfoCache singleton, which remembers custom ring tone and
394 // send-to-voicemail settings.
395 //
396 // The asynchronous caching will start just after this call.
397 callerInfoCache = CallerInfoCache.init(this);
398
399 // Monitors call activity from the telephony layer
400 callStateMonitor = new CallStateMonitor(mCM);
401
Santos Cordon2c2d3cf2013-08-08 03:53:47 -0700402 // Bluetooth manager
Sailesh Nepal23d9ed72014-07-03 09:40:26 -0700403 bluetoothManager = new BluetoothManager();
Santos Cordon2c2d3cf2013-08-08 03:53:47 -0700404
Stuart Scottdcf40a92014-12-09 10:45:01 -0800405 phoneMgr = PhoneInterfaceManager.init(this, PhoneFactory.getDefaultPhone());
Santos Cordon406c0342013-08-28 00:07:47 -0700406
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800407 configLoader = CarrierConfigLoader.init(this);
408
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409 // Create the CallNotifer singleton, which handles
410 // asynchronous events from the telephony layer (like
411 // launching the incoming-call UI when an incoming call comes
412 // in.)
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800413 notifier = CallNotifier.init(this, callLogger, callStateMonitor, bluetoothManager);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700414
Stuart Scottdcf40a92014-12-09 10:45:01 -0800415 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416
417 // register for MMI/USSD
418 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
419
420 // register connection tracking to PhoneUtils
421 PhoneUtils.initializeConnectionHandler(mCM);
422
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423 // Register for misc other intent broadcasts.
424 IntentFilter intentFilter =
425 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700426 intentFilter.addAction(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427 intentFilter.addAction(Intent.ACTION_DOCK_EVENT);
428 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
429 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
430 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
431 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700432 registerReceiver(mReceiver, intentFilter);
433
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434 //set the default values for the preferences in the phone.
435 PreferenceManager.setDefaultValues(this, R.xml.network_setting, false);
436
437 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
438
439 // Make sure the audio mode (along with some
440 // audio-mode-related state of our own) is initialized
441 // correctly, given the current state of the phone.
442 PhoneUtils.setAudioMode(mCM);
443 }
444
Santos Cordon52bc81b2014-10-07 19:55:12 -0700445 cdmaOtaProvisionData = new OtaUtils.CdmaOtaProvisionData();
446 cdmaOtaConfigData = new OtaUtils.CdmaOtaConfigData();
447 cdmaOtaScreenState = new OtaUtils.CdmaOtaScreenState();
448 cdmaOtaInCallScreenUiState = new OtaUtils.CdmaOtaInCallScreenUiState();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449
Santos Cordon76aaf482015-04-08 10:58:27 -0700450 simActivationManager = new SimActivationManager();
451
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700452 // XXX pre-load the SimProvider so that it's ready
453 resolver.getType(Uri.parse("content://icc/adn"));
454
455 // start with the default value to set the mute state.
456 mShouldRestoreMuteOnInCallResume = false;
457
458 // TODO: Register for Cdma Information Records
459 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
460
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700461 // Read HAC settings and configure audio hardware
462 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800463 int hac = android.provider.Settings.System.getInt(
464 getContentResolver(),
465 android.provider.Settings.System.HEARING_AID,
466 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700467 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Andrew Leefb7f92e2015-02-26 16:23:32 -0800468 audioManager.setParameter(SettingsConstants.HAC_KEY,
469 hac == SettingsConstants.HAC_ENABLED
470 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700471 }
Santos Cordonff506f52013-11-21 19:13:19 -0800472 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700473
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700474 /**
475 * Returns the singleton instance of the PhoneApp.
476 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800477 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700478 if (sMe == null) {
479 throw new IllegalStateException("No PhoneGlobals here!");
480 }
481 return sMe;
482 }
483
484 /**
485 * Returns the singleton instance of the PhoneApp if running as the
486 * primary user, otherwise null.
487 */
488 static PhoneGlobals getInstanceIfPrimary() {
489 return sMe;
490 }
491
492 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800493 * Returns the default phone.
494 *
Andrew Lee385019f2014-11-24 14:19:50 -0800495 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700496 */
Andrew Lee83383e42014-10-31 12:42:28 -0700497 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800498 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700499 }
500
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800501 public static Phone getPhone(int subId) {
502 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800503 }
504
Santos Cordon27a3c1f2013-08-06 07:49:27 -0700505 /* package */ BluetoothManager getBluetoothManager() {
506 return bluetoothManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700507 }
508
Santos Cordonde10b752013-09-19 04:11:33 -0700509 /* package */ CallManager getCallManager() {
510 return mCM;
511 }
512
Junda Liu605148f2015-04-28 15:23:40 -0700513 /* package */ Bundle getCarrierConfig() {
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700514 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubId());
515 }
516
517 /* package */ Bundle getCarrierConfigForSubId(int subId) {
518 return configLoader.getConfigForSubId(subId);
Junda Liu605148f2015-04-28 15:23:40 -0700519 }
520
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700521 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700522 * Returns PendingIntent for hanging up ongoing phone call. This will typically be used from
523 * Notification context.
524 */
525 /* package */ static PendingIntent createHangUpOngoingCallPendingIntent(Context context) {
526 Intent intent = new Intent(PhoneGlobals.ACTION_HANG_UP_ONGOING_CALL, null,
527 context, NotificationBroadcastReceiver.class);
528 return PendingIntent.getBroadcast(context, 0, intent, 0);
529 }
530
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700531 boolean isSimPinEnabled() {
532 return mIsSimPinEnabled;
533 }
534
535 boolean authenticateAgainstCachedSimPin(String pin) {
536 return (mCachedSimPin != null && mCachedSimPin.equals(pin));
537 }
538
539 void setCachedSimPin(String pin) {
540 mCachedSimPin = pin;
541 }
542
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700543 /**
544 * Handles OTASP-related events from the telephony layer.
545 *
546 * While an OTASP call is active, the CallNotifier forwards
547 * OTASP-related telephony events to this method.
548 */
549 void handleOtaspEvent(Message msg) {
550 if (DBG) Log.d(LOG_TAG, "handleOtaspEvent(message " + msg + ")...");
551
552 if (otaUtils == null) {
553 // We shouldn't be getting OTASP events without ever
554 // having started the OTASP call in the first place!
555 Log.w(LOG_TAG, "handleOtaEvents: got an event but otaUtils is null! "
556 + "message = " + msg);
557 return;
558 }
559
560 otaUtils.onOtaProvisionStatusChanged((AsyncResult) msg.obj);
561 }
562
563 /**
564 * Similarly, handle the disconnect event of an OTASP call
565 * by forwarding it to the OtaUtils instance.
566 */
567 /* package */ void handleOtaspDisconnect() {
568 if (DBG) Log.d(LOG_TAG, "handleOtaspDisconnect()...");
569
570 if (otaUtils == null) {
571 // We shouldn't be getting OTASP events without ever
572 // having started the OTASP call in the first place!
573 Log.w(LOG_TAG, "handleOtaspDisconnect: otaUtils is null!");
574 return;
575 }
576
577 otaUtils.onOtaspDisconnect();
578 }
579
580 /**
581 * Sets the activity responsible for un-PUK-blocking the device
582 * so that we may close it when we receive a positive result.
583 * mPUKEntryActivity is also used to indicate to the device that
584 * we are trying to un-PUK-lock the phone. In other words, iff
585 * it is NOT null, then we are trying to unlock and waiting for
586 * the SIM to move to READY state.
587 *
588 * @param activity is the activity to close when PUK has
589 * finished unlocking. Can be set to null to indicate the unlock
590 * or SIM READYing process is over.
591 */
592 void setPukEntryActivity(Activity activity) {
593 mPUKEntryActivity = activity;
594 }
595
596 Activity getPUKEntryActivity() {
597 return mPUKEntryActivity;
598 }
599
600 /**
601 * Sets the dialog responsible for notifying the user of un-PUK-
602 * blocking - SIM READYing progress, so that we may dismiss it
603 * when we receive a positive result.
604 *
605 * @param dialog indicates the progress dialog informing the user
606 * of the state of the device. Dismissed upon completion of
607 * READYing process
608 */
609 void setPukEntryProgressDialog(ProgressDialog dialog) {
610 mPUKEntryProgressDialog = dialog;
611 }
612
613 ProgressDialog getPUKEntryProgressDialog() {
614 return mPUKEntryProgressDialog;
615 }
616
617 /**
618 * Controls whether or not the screen is allowed to sleep.
619 *
620 * Once sleep is allowed (WakeState is SLEEP), it will rely on the
621 * settings for the poke lock to determine when to timeout and let
622 * the device sleep {@link PhoneGlobals#setScreenTimeout}.
623 *
624 * @param ws tells the device to how to wake.
625 */
626 /* package */ void requestWakeState(WakeState ws) {
627 if (VDBG) Log.d(LOG_TAG, "requestWakeState(" + ws + ")...");
628 synchronized (this) {
629 if (mWakeState != ws) {
630 switch (ws) {
631 case PARTIAL:
632 // acquire the processor wake lock, and release the FULL
633 // lock if it is being held.
634 mPartialWakeLock.acquire();
635 if (mWakeLock.isHeld()) {
636 mWakeLock.release();
637 }
638 break;
639 case FULL:
640 // acquire the full wake lock, and release the PARTIAL
641 // lock if it is being held.
642 mWakeLock.acquire();
643 if (mPartialWakeLock.isHeld()) {
644 mPartialWakeLock.release();
645 }
646 break;
647 case SLEEP:
648 default:
649 // release both the PARTIAL and FULL locks.
650 if (mWakeLock.isHeld()) {
651 mWakeLock.release();
652 }
653 if (mPartialWakeLock.isHeld()) {
654 mPartialWakeLock.release();
655 }
656 break;
657 }
658 mWakeState = ws;
659 }
660 }
661 }
662
663 /**
664 * If we are not currently keeping the screen on, then poke the power
665 * manager to wake up the screen for the user activity timeout duration.
666 */
667 /* package */ void wakeUpScreen() {
668 synchronized (this) {
669 if (mWakeState == WakeState.SLEEP) {
670 if (DBG) Log.d(LOG_TAG, "pulse screen lock");
671 mPowerManager.wakeUp(SystemClock.uptimeMillis());
672 }
673 }
674 }
675
676 /**
677 * Sets the wake state and screen timeout based on the current state
678 * of the phone, and the current state of the in-call UI.
679 *
680 * This method is a "UI Policy" wrapper around
681 * {@link PhoneGlobals#requestWakeState} and {@link PhoneGlobals#setScreenTimeout}.
682 *
683 * It's safe to call this method regardless of the state of the Phone
684 * (e.g. whether or not it's idle), and regardless of the state of the
685 * Phone UI (e.g. whether or not the InCallScreen is active.)
686 */
687 /* package */ void updateWakeState() {
688 PhoneConstants.State state = mCM.getState();
689
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700690 // True if the speakerphone is in use. (If so, we *always* use
691 // the default timeout. Since the user is obviously not holding
692 // the phone up to his/her face, we don't need to worry about
693 // false touches, and thus don't need to turn the screen off so
694 // aggressively.)
695 // Note that we need to make a fresh call to this method any
696 // time the speaker state changes. (That happens in
697 // PhoneUtils.turnOnSpeaker().)
698 boolean isSpeakerInUse = (state == PhoneConstants.State.OFFHOOK) && PhoneUtils.isSpeakerOn(this);
699
700 // TODO (bug 1440854): The screen timeout *might* also need to
701 // depend on the bluetooth state, but this isn't as clear-cut as
702 // the speaker state (since while using BT it's common for the
703 // user to put the phone straight into a pocket, in which case the
704 // timeout should probably still be short.)
705
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700706 // Decide whether to force the screen on or not.
707 //
708 // Force the screen to be on if the phone is ringing or dialing,
709 // or if we're displaying the "Call ended" UI for a connection in
710 // the "disconnected" state.
711 // However, if the phone is disconnected while the user is in the
712 // middle of selecting a quick response message, we should not force
713 // the screen to be on.
714 //
715 boolean isRinging = (state == PhoneConstants.State.RINGING);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800716 boolean isDialing = (mCM.getFgPhone().getForegroundCall().getState() == Call.State.DIALING);
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700717 boolean keepScreenOn = isRinging || isDialing;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700718 // keepScreenOn == true means we'll hold a full wake lock:
719 requestWakeState(keepScreenOn ? WakeState.FULL : WakeState.SLEEP);
720 }
721
722 /**
723 * Manually pokes the PowerManager's userActivity method. Since we
724 * set the {@link WindowManager.LayoutParams#INPUT_FEATURE_DISABLE_USER_ACTIVITY}
725 * flag while the InCallScreen is active when there is no proximity sensor,
726 * we need to do this for touch events that really do count as user activity
727 * (like pressing any onscreen UI elements.)
728 */
729 /* package */ void pokeUserActivity() {
730 if (VDBG) Log.d(LOG_TAG, "pokeUserActivity()...");
731 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
732 }
733
734 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700735 * Notifies the phone app when the phone state changes.
736 *
Santos Cordonfc309812013-08-20 18:33:16 -0700737 * This method will updates various states inside Phone app (e.g. update-lock state, etc.)
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700738 */
739 /* package */ void updatePhoneState(PhoneConstants.State state) {
740 if (state != mLastPhoneState) {
741 mLastPhoneState = state;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700742
743 // Try to acquire or release UpdateLock.
744 //
745 // Watch out: we don't release the lock here when the screen is still in foreground.
746 // At that time InCallScreen will release it on onPause().
747 if (state != PhoneConstants.State.IDLE) {
748 // UpdateLock is a recursive lock, while we may get "acquire" request twice and
749 // "release" request once for a single call (RINGING + OFFHOOK and IDLE).
750 // We need to manually ensure the lock is just acquired once for each (and this
751 // will prevent other possible buggy situations too).
752 if (!mUpdateLock.isHeld()) {
753 mUpdateLock.acquire();
754 }
755 } else {
Jay Shraunera5d13212013-09-19 13:37:43 -0700756 if (mUpdateLock.isHeld()) {
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700757 mUpdateLock.release();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700758 }
759 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700760 }
761 }
762
763 /* package */ PhoneConstants.State getPhoneState() {
764 return mLastPhoneState;
765 }
766
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700767 KeyguardManager getKeyguardManager() {
768 return mKeyguardManager;
769 }
770
771 private void onMMIComplete(AsyncResult r) {
772 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
773 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800774 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700775 }
776
Stuart Scottdcf40a92014-12-09 10:45:01 -0800777 private void initForNewRadioTechnology(int phoneId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700778 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
779
Stuart Scottdcf40a92014-12-09 10:45:01 -0800780 final Phone phone = PhoneFactory.getPhone(phoneId);
781
782 if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700783 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
784 cdmaPhoneCallState = new CdmaPhoneCallState();
785 cdmaPhoneCallState.CdmaPhoneCallStateInit();
786 }
Santos Cordon52bc81b2014-10-07 19:55:12 -0700787 if (!TelephonyCapabilities.supportsOtasp(phone)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700788 //Clean up OTA data in GSM/UMTS. It is valid only for CDMA
789 clearOtaState();
790 }
791
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700792 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
793 callStateMonitor.updateAfterRadioTechnologyChange();
794
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700795 // Update registration for ICC status after radio technology change
796 IccCard sim = phone.getIccCard();
797 if (sim != null) {
798 if (DBG) Log.d(LOG_TAG, "Update registration for ICC status...");
799
800 //Register all events new to the new active phone
801 sim.registerForNetworkLocked(mHandler, EVENT_SIM_NETWORK_LOCKED, null);
802 }
803 }
804
Santos Cordon593ab382013-08-06 21:58:23 -0700805 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700806 * Receiver for misc intent broadcasts the Phone app cares about.
807 */
808 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
809 @Override
810 public void onReceive(Context context, Intent intent) {
811 String action = intent.getAction();
812 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
813 boolean enabled = System.getInt(getContentResolver(),
814 System.AIRPLANE_MODE_ON, 0) == 0;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800815 PhoneUtils.setRadioPower(enabled);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700816 } else if (action.equals(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800817 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
818 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
819 int phoneId = SubscriptionManager.getPhoneId(subId);
820 String state = intent.getStringExtra(PhoneConstants.STATE_KEY);
821 if (VDBG) {
822 Log.d(LOG_TAG, "mReceiver: ACTION_ANY_DATA_CONNECTION_STATE_CHANGED");
823 Log.d(LOG_TAG, "- state: " + state);
824 Log.d(LOG_TAG, "- reason: "
825 + intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY));
826 Log.d(LOG_TAG, "- subId: " + subId);
827 Log.d(LOG_TAG, "- phoneId: " + phoneId);
828 }
829 Phone phone = SubscriptionManager.isValidPhoneId(phoneId) ?
830 PhoneFactory.getPhone(phoneId) : PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700831 // The "data disconnected due to roaming" notification is shown
832 // if (a) you have the "data roaming" feature turned off, and
833 // (b) you just lost data connectivity because you're roaming.
834 boolean disconnectedDueToRoaming =
835 !phone.getDataRoamingEnabled()
Stuart Scottdcf40a92014-12-09 10:45:01 -0800836 && PhoneConstants.DataState.DISCONNECTED.equals(state)
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700837 && Phone.REASON_ROAMING_ON.equals(
838 intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY));
Yorke Lee4d2db1c2014-11-06 11:37:09 -0800839 if (mDataDisconnectedDueToRoaming != disconnectedDueToRoaming) {
840 mDataDisconnectedDueToRoaming = disconnectedDueToRoaming;
841 mHandler.sendEmptyMessage(disconnectedDueToRoaming
842 ? EVENT_DATA_ROAMING_DISCONNECTED : EVENT_DATA_ROAMING_OK);
843 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700844 } else if ((action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) &&
845 (mPUKEntryActivity != null)) {
846 // if an attempt to un-PUK-lock the device was made, while we're
847 // receiving this state change notification, notify the handler.
848 // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has
849 // been attempted.
850 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
851 intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE)));
852 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
853 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800854 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
855 SubscriptionManager.INVALID_PHONE_INDEX);
856 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " (" + phoneId
857 + ") is active.");
858 initForNewRadioTechnology(phoneId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700859 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
860 handleServiceStateChanged(intent);
861 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800862 if (TelephonyCapabilities.supportsEcm(mCM.getFgPhone())) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700863 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
864 // Start Emergency Callback Mode service
865 if (intent.getBooleanExtra("phoneinECMState", false)) {
866 context.startService(new Intent(context,
867 EmergencyCallbackModeService.class));
868 }
869 } else {
870 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
871 // on a device that doesn't support ECM in the first place.
872 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, "
Stuart Scottdcf40a92014-12-09 10:45:01 -0800873 + "but ECM isn't supported for phone: "
874 + mCM.getFgPhone().getPhoneName());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700875 }
876 } else if (action.equals(Intent.ACTION_DOCK_EVENT)) {
877 mDockState = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
878 Intent.EXTRA_DOCK_STATE_UNDOCKED);
879 if (VDBG) Log.d(LOG_TAG, "ACTION_DOCK_EVENT -> mDockState = " + mDockState);
880 mHandler.sendMessage(mHandler.obtainMessage(EVENT_DOCK_STATE_CHANGED, 0));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700881 }
882 }
883 }
884
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700885 /**
886 * Accepts broadcast Intents which will be prepared by {@link NotificationMgr} and thus
887 * sent from framework's notification mechanism (which is outside Phone context).
888 * This should be visible from outside, but shouldn't be in "exported" state.
889 *
890 * TODO: If possible merge this into PhoneAppBroadcastReceiver.
891 */
892 public static class NotificationBroadcastReceiver extends BroadcastReceiver {
893 @Override
894 public void onReceive(Context context, Intent intent) {
895 String action = intent.getAction();
896 // TODO: use "if (VDBG)" here.
897 Log.d(LOG_TAG, "Broadcast from Notification: " + action);
898
899 if (action.equals(ACTION_HANG_UP_ONGOING_CALL)) {
900 PhoneUtils.hangup(PhoneGlobals.getInstance().mCM);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700901 } else {
902 Log.w(LOG_TAG, "Received hang-up request from notification,"
903 + " but there's no call the system can hang up.");
904 }
905 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700906 }
907
908 private void handleServiceStateChanged(Intent intent) {
909 /**
910 * This used to handle updating EriTextWidgetProvider this routine
911 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
912 * be removed. But leaving just in case it might be needed in the near
913 * future.
914 */
915
916 // If service just returned, start sending out the queued messages
917 ServiceState ss = ServiceState.newFromBundle(intent.getExtras());
918
919 if (ss != null) {
920 int state = ss.getState();
921 notificationMgr.updateNetworkSelection(state);
922 }
923 }
924
925 public boolean isOtaCallInActiveState() {
926 boolean otaCallActive = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700927 if (VDBG) Log.d(LOG_TAG, "- isOtaCallInActiveState " + otaCallActive);
928 return otaCallActive;
929 }
930
931 public boolean isOtaCallInEndState() {
932 boolean otaCallEnded = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700933 if (VDBG) Log.d(LOG_TAG, "- isOtaCallInEndState " + otaCallEnded);
934 return otaCallEnded;
935 }
936
937 // it is safe to call clearOtaState() even if the InCallScreen isn't active
938 public void clearOtaState() {
939 if (DBG) Log.d(LOG_TAG, "- clearOtaState ...");
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700940 if (otaUtils != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700941 otaUtils.cleanOtaScreen(true);
942 if (DBG) Log.d(LOG_TAG, " - clearOtaState clears OTA screen");
943 }
944 }
945
946 // it is safe to call dismissOtaDialogs() even if the InCallScreen isn't active
947 public void dismissOtaDialogs() {
948 if (DBG) Log.d(LOG_TAG, "- dismissOtaDialogs ...");
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700949 if (otaUtils != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700950 otaUtils.dismissAllOtaDialogs();
951 if (DBG) Log.d(LOG_TAG, " - dismissOtaDialogs clears OTA dialogs");
952 }
953 }
954
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700955 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800956 * Triggers a refresh of the message waiting (voicemail) indicator.
957 *
958 * @param subId the subscription id we should refresh the notification for.
959 */
960 public void refreshMwiIndicator(int subId) {
961 notificationMgr.refreshMwi(subId);
962 }
963
964 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700965 * "Call origin" may be used by Contacts app to specify where the phone call comes from.
966 * Currently, the only permitted value for this extra is {@link #ALLOWED_EXTRA_CALL_ORIGIN}.
967 * Any other value will be ignored, to make sure that malicious apps can't trick the in-call
968 * UI into launching some random other app after a call ends.
969 *
970 * TODO: make this more generic. Note that we should let the "origin" specify its package
971 * while we are now assuming it is "com.android.contacts"
972 */
973 public static final String EXTRA_CALL_ORIGIN = "com.android.phone.CALL_ORIGIN";
974 private static final String DEFAULT_CALL_ORIGIN_PACKAGE = "com.android.dialer";
975 private static final String ALLOWED_EXTRA_CALL_ORIGIN =
976 "com.android.dialer.DialtactsActivity";
977 /**
978 * Used to determine if the preserved call origin is fresh enough.
979 */
980 private static final long CALL_ORIGIN_EXPIRATION_MILLIS = 30 * 1000;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700981}