blob: b9313404ddff18792e3ae9c69dc9e3fe136db7dd [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() {
514 return configLoader.getConfigForSubId(SubscriptionManager.getDefaultSubId());
515 }
516
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700517 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700518 * Returns PendingIntent for hanging up ongoing phone call. This will typically be used from
519 * Notification context.
520 */
521 /* package */ static PendingIntent createHangUpOngoingCallPendingIntent(Context context) {
522 Intent intent = new Intent(PhoneGlobals.ACTION_HANG_UP_ONGOING_CALL, null,
523 context, NotificationBroadcastReceiver.class);
524 return PendingIntent.getBroadcast(context, 0, intent, 0);
525 }
526
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700527 boolean isSimPinEnabled() {
528 return mIsSimPinEnabled;
529 }
530
531 boolean authenticateAgainstCachedSimPin(String pin) {
532 return (mCachedSimPin != null && mCachedSimPin.equals(pin));
533 }
534
535 void setCachedSimPin(String pin) {
536 mCachedSimPin = pin;
537 }
538
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700539 /**
540 * Handles OTASP-related events from the telephony layer.
541 *
542 * While an OTASP call is active, the CallNotifier forwards
543 * OTASP-related telephony events to this method.
544 */
545 void handleOtaspEvent(Message msg) {
546 if (DBG) Log.d(LOG_TAG, "handleOtaspEvent(message " + msg + ")...");
547
548 if (otaUtils == null) {
549 // We shouldn't be getting OTASP events without ever
550 // having started the OTASP call in the first place!
551 Log.w(LOG_TAG, "handleOtaEvents: got an event but otaUtils is null! "
552 + "message = " + msg);
553 return;
554 }
555
556 otaUtils.onOtaProvisionStatusChanged((AsyncResult) msg.obj);
557 }
558
559 /**
560 * Similarly, handle the disconnect event of an OTASP call
561 * by forwarding it to the OtaUtils instance.
562 */
563 /* package */ void handleOtaspDisconnect() {
564 if (DBG) Log.d(LOG_TAG, "handleOtaspDisconnect()...");
565
566 if (otaUtils == null) {
567 // We shouldn't be getting OTASP events without ever
568 // having started the OTASP call in the first place!
569 Log.w(LOG_TAG, "handleOtaspDisconnect: otaUtils is null!");
570 return;
571 }
572
573 otaUtils.onOtaspDisconnect();
574 }
575
576 /**
577 * Sets the activity responsible for un-PUK-blocking the device
578 * so that we may close it when we receive a positive result.
579 * mPUKEntryActivity is also used to indicate to the device that
580 * we are trying to un-PUK-lock the phone. In other words, iff
581 * it is NOT null, then we are trying to unlock and waiting for
582 * the SIM to move to READY state.
583 *
584 * @param activity is the activity to close when PUK has
585 * finished unlocking. Can be set to null to indicate the unlock
586 * or SIM READYing process is over.
587 */
588 void setPukEntryActivity(Activity activity) {
589 mPUKEntryActivity = activity;
590 }
591
592 Activity getPUKEntryActivity() {
593 return mPUKEntryActivity;
594 }
595
596 /**
597 * Sets the dialog responsible for notifying the user of un-PUK-
598 * blocking - SIM READYing progress, so that we may dismiss it
599 * when we receive a positive result.
600 *
601 * @param dialog indicates the progress dialog informing the user
602 * of the state of the device. Dismissed upon completion of
603 * READYing process
604 */
605 void setPukEntryProgressDialog(ProgressDialog dialog) {
606 mPUKEntryProgressDialog = dialog;
607 }
608
609 ProgressDialog getPUKEntryProgressDialog() {
610 return mPUKEntryProgressDialog;
611 }
612
613 /**
614 * Controls whether or not the screen is allowed to sleep.
615 *
616 * Once sleep is allowed (WakeState is SLEEP), it will rely on the
617 * settings for the poke lock to determine when to timeout and let
618 * the device sleep {@link PhoneGlobals#setScreenTimeout}.
619 *
620 * @param ws tells the device to how to wake.
621 */
622 /* package */ void requestWakeState(WakeState ws) {
623 if (VDBG) Log.d(LOG_TAG, "requestWakeState(" + ws + ")...");
624 synchronized (this) {
625 if (mWakeState != ws) {
626 switch (ws) {
627 case PARTIAL:
628 // acquire the processor wake lock, and release the FULL
629 // lock if it is being held.
630 mPartialWakeLock.acquire();
631 if (mWakeLock.isHeld()) {
632 mWakeLock.release();
633 }
634 break;
635 case FULL:
636 // acquire the full wake lock, and release the PARTIAL
637 // lock if it is being held.
638 mWakeLock.acquire();
639 if (mPartialWakeLock.isHeld()) {
640 mPartialWakeLock.release();
641 }
642 break;
643 case SLEEP:
644 default:
645 // release both the PARTIAL and FULL locks.
646 if (mWakeLock.isHeld()) {
647 mWakeLock.release();
648 }
649 if (mPartialWakeLock.isHeld()) {
650 mPartialWakeLock.release();
651 }
652 break;
653 }
654 mWakeState = ws;
655 }
656 }
657 }
658
659 /**
660 * If we are not currently keeping the screen on, then poke the power
661 * manager to wake up the screen for the user activity timeout duration.
662 */
663 /* package */ void wakeUpScreen() {
664 synchronized (this) {
665 if (mWakeState == WakeState.SLEEP) {
666 if (DBG) Log.d(LOG_TAG, "pulse screen lock");
667 mPowerManager.wakeUp(SystemClock.uptimeMillis());
668 }
669 }
670 }
671
672 /**
673 * Sets the wake state and screen timeout based on the current state
674 * of the phone, and the current state of the in-call UI.
675 *
676 * This method is a "UI Policy" wrapper around
677 * {@link PhoneGlobals#requestWakeState} and {@link PhoneGlobals#setScreenTimeout}.
678 *
679 * It's safe to call this method regardless of the state of the Phone
680 * (e.g. whether or not it's idle), and regardless of the state of the
681 * Phone UI (e.g. whether or not the InCallScreen is active.)
682 */
683 /* package */ void updateWakeState() {
684 PhoneConstants.State state = mCM.getState();
685
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700686 // True if the speakerphone is in use. (If so, we *always* use
687 // the default timeout. Since the user is obviously not holding
688 // the phone up to his/her face, we don't need to worry about
689 // false touches, and thus don't need to turn the screen off so
690 // aggressively.)
691 // Note that we need to make a fresh call to this method any
692 // time the speaker state changes. (That happens in
693 // PhoneUtils.turnOnSpeaker().)
694 boolean isSpeakerInUse = (state == PhoneConstants.State.OFFHOOK) && PhoneUtils.isSpeakerOn(this);
695
696 // TODO (bug 1440854): The screen timeout *might* also need to
697 // depend on the bluetooth state, but this isn't as clear-cut as
698 // the speaker state (since while using BT it's common for the
699 // user to put the phone straight into a pocket, in which case the
700 // timeout should probably still be short.)
701
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700702 // Decide whether to force the screen on or not.
703 //
704 // Force the screen to be on if the phone is ringing or dialing,
705 // or if we're displaying the "Call ended" UI for a connection in
706 // the "disconnected" state.
707 // However, if the phone is disconnected while the user is in the
708 // middle of selecting a quick response message, we should not force
709 // the screen to be on.
710 //
711 boolean isRinging = (state == PhoneConstants.State.RINGING);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800712 boolean isDialing = (mCM.getFgPhone().getForegroundCall().getState() == Call.State.DIALING);
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700713 boolean keepScreenOn = isRinging || isDialing;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700714 // keepScreenOn == true means we'll hold a full wake lock:
715 requestWakeState(keepScreenOn ? WakeState.FULL : WakeState.SLEEP);
716 }
717
718 /**
719 * Manually pokes the PowerManager's userActivity method. Since we
720 * set the {@link WindowManager.LayoutParams#INPUT_FEATURE_DISABLE_USER_ACTIVITY}
721 * flag while the InCallScreen is active when there is no proximity sensor,
722 * we need to do this for touch events that really do count as user activity
723 * (like pressing any onscreen UI elements.)
724 */
725 /* package */ void pokeUserActivity() {
726 if (VDBG) Log.d(LOG_TAG, "pokeUserActivity()...");
727 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
728 }
729
730 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700731 * Notifies the phone app when the phone state changes.
732 *
Santos Cordonfc309812013-08-20 18:33:16 -0700733 * This method will updates various states inside Phone app (e.g. update-lock state, etc.)
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700734 */
735 /* package */ void updatePhoneState(PhoneConstants.State state) {
736 if (state != mLastPhoneState) {
737 mLastPhoneState = state;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700738
739 // Try to acquire or release UpdateLock.
740 //
741 // Watch out: we don't release the lock here when the screen is still in foreground.
742 // At that time InCallScreen will release it on onPause().
743 if (state != PhoneConstants.State.IDLE) {
744 // UpdateLock is a recursive lock, while we may get "acquire" request twice and
745 // "release" request once for a single call (RINGING + OFFHOOK and IDLE).
746 // We need to manually ensure the lock is just acquired once for each (and this
747 // will prevent other possible buggy situations too).
748 if (!mUpdateLock.isHeld()) {
749 mUpdateLock.acquire();
750 }
751 } else {
Jay Shraunera5d13212013-09-19 13:37:43 -0700752 if (mUpdateLock.isHeld()) {
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700753 mUpdateLock.release();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700754 }
755 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700756 }
757 }
758
759 /* package */ PhoneConstants.State getPhoneState() {
760 return mLastPhoneState;
761 }
762
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700763 KeyguardManager getKeyguardManager() {
764 return mKeyguardManager;
765 }
766
767 private void onMMIComplete(AsyncResult r) {
768 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
769 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800770 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700771 }
772
Stuart Scottdcf40a92014-12-09 10:45:01 -0800773 private void initForNewRadioTechnology(int phoneId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700774 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
775
Stuart Scottdcf40a92014-12-09 10:45:01 -0800776 final Phone phone = PhoneFactory.getPhone(phoneId);
777
778 if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700779 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
780 cdmaPhoneCallState = new CdmaPhoneCallState();
781 cdmaPhoneCallState.CdmaPhoneCallStateInit();
782 }
Santos Cordon52bc81b2014-10-07 19:55:12 -0700783 if (!TelephonyCapabilities.supportsOtasp(phone)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700784 //Clean up OTA data in GSM/UMTS. It is valid only for CDMA
785 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
792 IccCard sim = phone.getIccCard();
793 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 Cordon7d4ddf62013-07-10 11:58:08 -0700827 // The "data disconnected due to roaming" notification is shown
828 // if (a) you have the "data roaming" feature turned off, and
829 // (b) you just lost data connectivity because you're roaming.
830 boolean disconnectedDueToRoaming =
831 !phone.getDataRoamingEnabled()
Stuart Scottdcf40a92014-12-09 10:45:01 -0800832 && PhoneConstants.DataState.DISCONNECTED.equals(state)
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700833 && Phone.REASON_ROAMING_ON.equals(
834 intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY));
Yorke Lee4d2db1c2014-11-06 11:37:09 -0800835 if (mDataDisconnectedDueToRoaming != disconnectedDueToRoaming) {
836 mDataDisconnectedDueToRoaming = disconnectedDueToRoaming;
837 mHandler.sendEmptyMessage(disconnectedDueToRoaming
838 ? EVENT_DATA_ROAMING_DISCONNECTED : EVENT_DATA_ROAMING_OK);
839 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700840 } else if ((action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) &&
841 (mPUKEntryActivity != null)) {
842 // if an attempt to un-PUK-lock the device was made, while we're
843 // receiving this state change notification, notify the handler.
844 // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has
845 // been attempted.
846 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
847 intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE)));
848 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
849 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800850 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
851 SubscriptionManager.INVALID_PHONE_INDEX);
852 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " (" + phoneId
853 + ") is active.");
854 initForNewRadioTechnology(phoneId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700855 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
856 handleServiceStateChanged(intent);
857 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800858 if (TelephonyCapabilities.supportsEcm(mCM.getFgPhone())) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700859 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
860 // Start Emergency Callback Mode service
861 if (intent.getBooleanExtra("phoneinECMState", false)) {
862 context.startService(new Intent(context,
863 EmergencyCallbackModeService.class));
864 }
865 } else {
866 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
867 // on a device that doesn't support ECM in the first place.
868 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, "
Stuart Scottdcf40a92014-12-09 10:45:01 -0800869 + "but ECM isn't supported for phone: "
870 + mCM.getFgPhone().getPhoneName());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700871 }
872 } else if (action.equals(Intent.ACTION_DOCK_EVENT)) {
873 mDockState = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
874 Intent.EXTRA_DOCK_STATE_UNDOCKED);
875 if (VDBG) Log.d(LOG_TAG, "ACTION_DOCK_EVENT -> mDockState = " + mDockState);
876 mHandler.sendMessage(mHandler.obtainMessage(EVENT_DOCK_STATE_CHANGED, 0));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700877 }
878 }
879 }
880
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700881 /**
882 * Accepts broadcast Intents which will be prepared by {@link NotificationMgr} and thus
883 * sent from framework's notification mechanism (which is outside Phone context).
884 * This should be visible from outside, but shouldn't be in "exported" state.
885 *
886 * TODO: If possible merge this into PhoneAppBroadcastReceiver.
887 */
888 public static class NotificationBroadcastReceiver extends BroadcastReceiver {
889 @Override
890 public void onReceive(Context context, Intent intent) {
891 String action = intent.getAction();
892 // TODO: use "if (VDBG)" here.
893 Log.d(LOG_TAG, "Broadcast from Notification: " + action);
894
895 if (action.equals(ACTION_HANG_UP_ONGOING_CALL)) {
896 PhoneUtils.hangup(PhoneGlobals.getInstance().mCM);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700897 } else {
898 Log.w(LOG_TAG, "Received hang-up request from notification,"
899 + " but there's no call the system can hang up.");
900 }
901 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700902 }
903
904 private void handleServiceStateChanged(Intent intent) {
905 /**
906 * This used to handle updating EriTextWidgetProvider this routine
907 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
908 * be removed. But leaving just in case it might be needed in the near
909 * future.
910 */
911
912 // If service just returned, start sending out the queued messages
913 ServiceState ss = ServiceState.newFromBundle(intent.getExtras());
914
915 if (ss != null) {
916 int state = ss.getState();
917 notificationMgr.updateNetworkSelection(state);
918 }
919 }
920
921 public boolean isOtaCallInActiveState() {
922 boolean otaCallActive = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700923 if (VDBG) Log.d(LOG_TAG, "- isOtaCallInActiveState " + otaCallActive);
924 return otaCallActive;
925 }
926
927 public boolean isOtaCallInEndState() {
928 boolean otaCallEnded = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700929 if (VDBG) Log.d(LOG_TAG, "- isOtaCallInEndState " + otaCallEnded);
930 return otaCallEnded;
931 }
932
933 // it is safe to call clearOtaState() even if the InCallScreen isn't active
934 public void clearOtaState() {
935 if (DBG) Log.d(LOG_TAG, "- clearOtaState ...");
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700936 if (otaUtils != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700937 otaUtils.cleanOtaScreen(true);
938 if (DBG) Log.d(LOG_TAG, " - clearOtaState clears OTA screen");
939 }
940 }
941
942 // it is safe to call dismissOtaDialogs() even if the InCallScreen isn't active
943 public void dismissOtaDialogs() {
944 if (DBG) Log.d(LOG_TAG, "- dismissOtaDialogs ...");
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700945 if (otaUtils != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700946 otaUtils.dismissAllOtaDialogs();
947 if (DBG) Log.d(LOG_TAG, " - dismissOtaDialogs clears OTA dialogs");
948 }
949 }
950
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700951 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800952 * Triggers a refresh of the message waiting (voicemail) indicator.
953 *
954 * @param subId the subscription id we should refresh the notification for.
955 */
956 public void refreshMwiIndicator(int subId) {
957 notificationMgr.refreshMwi(subId);
958 }
959
960 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700961 * "Call origin" may be used by Contacts app to specify where the phone call comes from.
962 * Currently, the only permitted value for this extra is {@link #ALLOWED_EXTRA_CALL_ORIGIN}.
963 * Any other value will be ignored, to make sure that malicious apps can't trick the in-call
964 * UI into launching some random other app after a call ends.
965 *
966 * TODO: make this more generic. Note that we should let the "origin" specify its package
967 * while we are now assuming it is "com.android.contacts"
968 */
969 public static final String EXTRA_CALL_ORIGIN = "com.android.phone.CALL_ORIGIN";
970 private static final String DEFAULT_CALL_ORIGIN_PACKAGE = "com.android.dialer";
971 private static final String ALLOWED_EXTRA_CALL_ORIGIN =
972 "com.android.dialer.DialtactsActivity";
973 /**
974 * Used to determine if the preserved call origin is fresh enough.
975 */
976 private static final long CALL_ORIGIN_EXPIRATION_MILLIS = 30 * 1000;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700977}