blob: 48b2bf9f548a039f36e8087ae39d9953b8c7b2d9 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
19import android.app.Activity;
20import android.app.KeyguardManager;
21import android.app.PendingIntent;
22import android.app.ProgressDialog;
Yorke Leeca6ec3b2013-08-29 14:21:43 -070023import android.app.TaskStackBuilder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.bluetooth.BluetoothAdapter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.bluetooth.IBluetoothHeadsetPhone;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070026import android.content.BroadcastReceiver;
27import android.content.ComponentName;
28import android.content.ContentResolver;
29import android.content.Context;
30import android.content.ContextWrapper;
31import android.content.Intent;
32import android.content.IntentFilter;
33import android.content.ServiceConnection;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070034import android.media.AudioManager;
35import android.net.Uri;
36import android.os.AsyncResult;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.os.Handler;
38import android.os.IBinder;
39import android.os.IPowerManager;
40import android.os.Message;
41import android.os.PowerManager;
42import android.os.RemoteException;
43import android.os.ServiceManager;
44import android.os.SystemClock;
45import android.os.SystemProperties;
46import android.os.UpdateLock;
47import android.os.UserHandle;
48import android.preference.PreferenceManager;
49import android.provider.Settings.System;
50import android.telephony.ServiceState;
Andrew Lee2fcb6c32014-12-04 14:52:35 -080051import android.telephony.SubscriptionInfo;
Andrew Lee385019f2014-11-24 14:19:50 -080052import android.telephony.SubscriptionManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.util.Log;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054
55import com.android.internal.telephony.Call;
56import com.android.internal.telephony.CallManager;
57import com.android.internal.telephony.IccCard;
58import com.android.internal.telephony.IccCardConstants;
59import com.android.internal.telephony.MmiCode;
60import com.android.internal.telephony.Phone;
61import com.android.internal.telephony.PhoneConstants;
62import com.android.internal.telephony.PhoneFactory;
Andrew Lee385019f2014-11-24 14:19:50 -080063import com.android.internal.telephony.SubscriptionController;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import com.android.internal.telephony.TelephonyCapabilities;
65import com.android.internal.telephony.TelephonyIntents;
Santos Cordon352ff652014-05-30 01:41:45 -070066import com.android.phone.common.CallLogAsync;
Andrew Leefb7f92e2015-02-26 16:23:32 -080067import com.android.phone.settings.SettingsConstants;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068import com.android.server.sip.SipService;
Santos Cordon76aaf482015-04-08 10:58:27 -070069import com.android.services.telephony.activation.SimActivationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070
Andrew Lee385019f2014-11-24 14:19:50 -080071import java.util.ArrayList;
72import java.util.List;
73
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074/**
75 * Global state for the telephony subsystem when running in the primary
76 * phone process.
77 */
Sailesh Nepalbf900542014-07-15 16:18:32 -070078public class PhoneGlobals extends ContextWrapper {
Andrew Lee83383e42014-10-31 12:42:28 -070079 public static final String LOG_TAG = "PhoneApp";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080
81 /**
82 * Phone app-wide debug level:
83 * 0 - no debug logging
84 * 1 - normal debug logging if ro.debuggable is set (which is true in
85 * "eng" and "userdebug" builds but not "user" builds)
86 * 2 - ultra-verbose debug logging
87 *
88 * Most individual classes in the phone app have a local DBG constant,
89 * typically set to
90 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
91 * or else
92 * (PhoneApp.DBG_LEVEL >= 2)
93 * depending on the desired verbosity.
94 *
95 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
96 */
Andrew Lee88b51e22014-10-29 15:48:51 -070097 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070098
99 private static final boolean DBG =
100 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
101 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
102
103 // Message codes; see mHandler below.
104 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700105 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
107 private static final int EVENT_DATA_ROAMING_OK = 11;
108 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 12;
109 private static final int EVENT_DOCK_STATE_CHANGED = 13;
Sailesh Nepalbf900542014-07-15 16:18:32 -0700110 private static final int EVENT_START_SIP_SERVICE = 14;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111
112 // The MMI codes are also used by the InCallScreen.
113 public static final int MMI_INITIATE = 51;
114 public static final int MMI_COMPLETE = 52;
115 public static final int MMI_CANCEL = 53;
116 // Don't use message codes larger than 99 here; those are reserved for
117 // the individual Activities of the Phone UI.
118
119 /**
120 * Allowable values for the wake lock code.
121 * SLEEP means the device can be put to sleep.
122 * PARTIAL means wake the processor, but we display can be kept off.
123 * FULL means wake both the processor and the display.
124 */
125 public enum WakeState {
126 SLEEP,
127 PARTIAL,
128 FULL
129 }
130
131 /**
132 * Intent Action used for hanging up the current call from Notification bar. This will
133 * choose first ringing call, first active call, or first background call (typically in
134 * HOLDING state).
135 */
136 public static final String ACTION_HANG_UP_ONGOING_CALL =
137 "com.android.phone.ACTION_HANG_UP_ONGOING_CALL";
138
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139 private static PhoneGlobals sMe;
140
141 // A few important fields we expose to the rest of the package
142 // directly (rather than thru set/get methods) for efficiency.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143 CallController callController;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700144 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700145 CallNotifier notifier;
146 CallerInfoCache callerInfoCache;
Santos Cordon63a84242013-07-23 13:32:52 -0700147 NotificationMgr notificationMgr;
Andrew Lee9431b832015-03-09 18:46:45 -0700148 public PhoneInterfaceManager phoneMgr;
Santos Cordon76aaf482015-04-08 10:58:27 -0700149 public SimActivationManager simActivationManager;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800150 CarrierConfigLoader configLoader;
Santos Cordon63a84242013-07-23 13:32:52 -0700151
Santos Cordon27a3c1f2013-08-06 07:49:27 -0700152 private BluetoothManager bluetoothManager;
Santos Cordon69a69192013-08-22 14:25:42 -0700153 private CallGatewayManager callGatewayManager;
Santos Cordon63a84242013-07-23 13:32:52 -0700154 private CallStateMonitor callStateMonitor;
Santos Cordon63a84242013-07-23 13:32:52 -0700155
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700156 static int mDockState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
157 static boolean sVoiceCapable = true;
158
159 // Internal PhoneApp Call state tracker
160 CdmaPhoneCallState cdmaPhoneCallState;
161
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162 // The currently-active PUK entry activity and progress dialog.
163 // Normally, these are the Emergency Dialer and the subsequent
164 // progress dialog. null if there is are no such objects in
165 // the foreground.
166 private Activity mPUKEntryActivity;
167 private ProgressDialog mPUKEntryProgressDialog;
168
169 private boolean mIsSimPinEnabled;
170 private String mCachedSimPin;
171
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172 // True if we are beginning a call, but the phone state has not changed yet
173 private boolean mBeginningCall;
Yorke Lee4d2db1c2014-11-06 11:37:09 -0800174 private boolean mDataDisconnectedDueToRoaming = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700175
176 // Last phone state seen by updatePhoneState()
177 private PhoneConstants.State mLastPhoneState = PhoneConstants.State.IDLE;
178
179 private WakeState mWakeState = WakeState.SLEEP;
180
181 private PowerManager mPowerManager;
182 private IPowerManager mPowerManagerService;
183 private PowerManager.WakeLock mWakeLock;
184 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186
187 private UpdateLock mUpdateLock;
188
189 // Broadcast receiver for various intent broadcasts (see onCreate())
190 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
191
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192 /** boolean indicating restoring mute state on InCallScreen.onResume() */
193 private boolean mShouldRestoreMuteOnInCallResume;
194
195 /**
196 * The singleton OtaUtils instance used for OTASP calls.
197 *
198 * The OtaUtils instance is created lazily the first time we need to
199 * make an OTASP call, regardless of whether it's an interactive or
200 * non-interactive OTASP call.
201 */
202 public OtaUtils otaUtils;
203
204 // Following are the CDMA OTA information Objects used during OTA Call.
205 // cdmaOtaProvisionData object store static OTA information that needs
206 // to be maintained even during Slider open/close scenarios.
207 // cdmaOtaConfigData object stores configuration info to control visiblity
208 // of each OTA Screens.
209 // cdmaOtaScreenState object store OTA Screen State information.
210 public OtaUtils.CdmaOtaProvisionData cdmaOtaProvisionData;
211 public OtaUtils.CdmaOtaConfigData cdmaOtaConfigData;
212 public OtaUtils.CdmaOtaScreenState cdmaOtaScreenState;
213 public OtaUtils.CdmaOtaInCallScreenUiState cdmaOtaInCallScreenUiState;
214
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700215 /**
216 * Set the restore mute state flag. Used when we are setting the mute state
217 * OUTSIDE of user interaction {@link PhoneUtils#startNewCall(Phone)}
218 */
219 /*package*/void setRestoreMuteOnInCallResume (boolean mode) {
220 mShouldRestoreMuteOnInCallResume = mode;
221 }
222
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700223 Handler mHandler = new Handler() {
224 @Override
225 public void handleMessage(Message msg) {
226 PhoneConstants.State phoneState;
227 switch (msg.what) {
228 // Starts the SIP service. It's a no-op if SIP API is not supported
229 // on the deivce.
230 // TODO: Having the phone process host the SIP service is only
231 // temporary. Will move it to a persistent communication process
232 // later.
233 case EVENT_START_SIP_SERVICE:
234 SipService.start(getApplicationContext());
235 break;
236
237 // TODO: This event should be handled by the lock screen, just
238 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
239 case EVENT_SIM_NETWORK_LOCKED:
240 if (getResources().getBoolean(R.bool.ignore_sim_network_locked_events)) {
241 // Some products don't have the concept of a "SIM network lock"
242 Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; "
243 + "not showing 'SIM network unlock' PIN entry screen");
244 } else {
245 // Normal case: show the "SIM network unlock" PIN entry screen.
246 // The user won't be able to do anything else until
247 // they enter a valid SIM network PIN.
248 Log.i(LOG_TAG, "show sim depersonal panel");
249 IccNetworkDepersonalizationPanel ndpPanel =
250 new IccNetworkDepersonalizationPanel(PhoneGlobals.getInstance());
251 ndpPanel.show();
252 }
253 break;
254
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700255 case EVENT_DATA_ROAMING_DISCONNECTED:
256 notificationMgr.showDataDisconnectedRoaming();
257 break;
258
259 case EVENT_DATA_ROAMING_OK:
260 notificationMgr.hideDataDisconnectedRoaming();
261 break;
262
263 case MMI_COMPLETE:
264 onMMIComplete((AsyncResult) msg.obj);
265 break;
266
267 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800268 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269 break;
270
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700271 case EVENT_SIM_STATE_CHANGED:
272 // Marks the event where the SIM goes into ready state.
273 // Right now, this is only used for the PUK-unlocking
274 // process.
275 if (msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_READY)) {
276 // when the right event is triggered and there
277 // are UI objects in the foreground, we close
278 // them to display the lock panel.
279 if (mPUKEntryActivity != null) {
280 mPUKEntryActivity.finish();
281 mPUKEntryActivity = null;
282 }
283 if (mPUKEntryProgressDialog != null) {
284 mPUKEntryProgressDialog.dismiss();
285 mPUKEntryProgressDialog = null;
286 }
287 }
288 break;
289
290 case EVENT_UNSOL_CDMA_INFO_RECORD:
291 //TODO: handle message here;
292 break;
293
294 case EVENT_DOCK_STATE_CHANGED:
295 // If the phone is docked/undocked during a call, and no wired or BT headset
296 // is connected: turn on/off the speaker accordingly.
297 boolean inDockMode = false;
298 if (mDockState != Intent.EXTRA_DOCK_STATE_UNDOCKED) {
299 inDockMode = true;
300 }
301 if (VDBG) Log.d(LOG_TAG, "received EVENT_DOCK_STATE_CHANGED. Phone inDock = "
302 + inDockMode);
303
304 phoneState = mCM.getState();
305 if (phoneState == PhoneConstants.State.OFFHOOK &&
Santos Cordon593ab382013-08-06 21:58:23 -0700306 !bluetoothManager.isBluetoothHeadsetAudioOn()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700307 PhoneUtils.turnOnSpeaker(getApplicationContext(), inDockMode, true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700308 }
309 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700310 }
311 }
312 };
313
314 public PhoneGlobals(Context context) {
315 super(context);
316 sMe = this;
317 }
318
319 public void onCreate() {
320 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
321
322 ContentResolver resolver = getContentResolver();
323
324 // Cache the "voice capable" flag.
325 // This flag currently comes from a resource (which is
326 // overrideable on a per-product basis):
327 sVoiceCapable =
328 getResources().getBoolean(com.android.internal.R.bool.config_voice_capable);
329 // ...but this might eventually become a PackageManager "system
330 // feature" instead, in which case we'd do something like:
331 // sVoiceCapable =
332 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
333
Stuart Scottdcf40a92014-12-09 10:45:01 -0800334 if (mCM == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700335 // Initialize the telephony framework
336 PhoneFactory.makeDefaultPhones(this);
337
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338 // Start TelephonyDebugService After the default phone is created.
339 Intent intent = new Intent(this, TelephonyDebugService.class);
340 startService(intent);
341
342 mCM = CallManager.getInstance();
Stuart Scottdcf40a92014-12-09 10:45:01 -0800343 boolean hasCdmaPhoneType = false;
344 for (Phone phone : PhoneFactory.getPhones()) {
345 mCM.registerPhone(phone);
346 if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
347 hasCdmaPhoneType = true;
348 }
349 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350
351 // Create the NotificationMgr singleton, which is used to display
352 // status bar icons and control other status bar behavior.
353 notificationMgr = NotificationMgr.init(this);
354
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355 mHandler.sendEmptyMessage(EVENT_START_SIP_SERVICE);
356
Stuart Scottdcf40a92014-12-09 10:45:01 -0800357 if (hasCdmaPhoneType) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
359 cdmaPhoneCallState = new CdmaPhoneCallState();
360 cdmaPhoneCallState.CdmaPhoneCallStateInit();
361 }
362
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700363 // before registering for phone state changes
364 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
365 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
366 // lock used to keep the processor awake, when we don't care for the display.
367 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
368 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369
370 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
371
372 // get a handle to the service so that we can use it later when we
373 // want to set the poke lock.
374 mPowerManagerService = IPowerManager.Stub.asInterface(
375 ServiceManager.getService("power"));
376
377 // Get UpdateLock to suppress system-update related events (e.g. dialog show-up)
378 // during phone calls.
379 mUpdateLock = new UpdateLock("phone");
380
381 if (DBG) Log.d(LOG_TAG, "onCreate: mUpdateLock: " + mUpdateLock);
382
383 CallLogger callLogger = new CallLogger(this, new CallLogAsync());
384
Jay Shrauner21a75342013-11-25 16:14:43 -0800385 callGatewayManager = CallGatewayManager.getInstance();
Santos Cordon69a69192013-08-22 14:25:42 -0700386
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700387 // Create the CallController singleton, which is the interface
388 // to the telephony layer for user-initiated telephony functionality
389 // (like making outgoing calls.)
Santos Cordon69a69192013-08-22 14:25:42 -0700390 callController = CallController.init(this, callLogger, callGatewayManager);
391
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700392 // Create the CallerInfoCache singleton, which remembers custom ring tone and
393 // send-to-voicemail settings.
394 //
395 // The asynchronous caching will start just after this call.
396 callerInfoCache = CallerInfoCache.init(this);
397
398 // Monitors call activity from the telephony layer
399 callStateMonitor = new CallStateMonitor(mCM);
400
Santos Cordon2c2d3cf2013-08-08 03:53:47 -0700401 // Bluetooth manager
Sailesh Nepal23d9ed72014-07-03 09:40:26 -0700402 bluetoothManager = new BluetoothManager();
Santos Cordon2c2d3cf2013-08-08 03:53:47 -0700403
Stuart Scottdcf40a92014-12-09 10:45:01 -0800404 phoneMgr = PhoneInterfaceManager.init(this, PhoneFactory.getDefaultPhone());
Santos Cordon406c0342013-08-28 00:07:47 -0700405
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800406 configLoader = CarrierConfigLoader.init(this);
407
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700408 // Create the CallNotifer singleton, which handles
409 // asynchronous events from the telephony layer (like
410 // launching the incoming-call UI when an incoming call comes
411 // in.)
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800412 notifier = CallNotifier.init(this, callLogger, callStateMonitor, bluetoothManager);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413
Stuart Scottdcf40a92014-12-09 10:45:01 -0800414 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415
416 // register for MMI/USSD
417 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
418
419 // register connection tracking to PhoneUtils
420 PhoneUtils.initializeConnectionHandler(mCM);
421
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700422 // Register for misc other intent broadcasts.
423 IntentFilter intentFilter =
424 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700425 intentFilter.addAction(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700426 intentFilter.addAction(Intent.ACTION_DOCK_EVENT);
427 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
428 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
429 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
430 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700431 registerReceiver(mReceiver, intentFilter);
432
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700433 //set the default values for the preferences in the phone.
434 PreferenceManager.setDefaultValues(this, R.xml.network_setting, false);
435
436 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
437
438 // Make sure the audio mode (along with some
439 // audio-mode-related state of our own) is initialized
440 // correctly, given the current state of the phone.
441 PhoneUtils.setAudioMode(mCM);
442 }
443
Santos Cordon52bc81b2014-10-07 19:55:12 -0700444 cdmaOtaProvisionData = new OtaUtils.CdmaOtaProvisionData();
445 cdmaOtaConfigData = new OtaUtils.CdmaOtaConfigData();
446 cdmaOtaScreenState = new OtaUtils.CdmaOtaScreenState();
447 cdmaOtaInCallScreenUiState = new OtaUtils.CdmaOtaInCallScreenUiState();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448
Santos Cordon76aaf482015-04-08 10:58:27 -0700449 simActivationManager = new SimActivationManager();
450
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700451 // XXX pre-load the SimProvider so that it's ready
452 resolver.getType(Uri.parse("content://icc/adn"));
453
454 // start with the default value to set the mute state.
455 mShouldRestoreMuteOnInCallResume = false;
456
457 // TODO: Register for Cdma Information Records
458 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
459
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700460 // Read HAC settings and configure audio hardware
461 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800462 int hac = android.provider.Settings.System.getInt(
463 getContentResolver(),
464 android.provider.Settings.System.HEARING_AID,
465 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700466 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Andrew Leefb7f92e2015-02-26 16:23:32 -0800467 audioManager.setParameter(SettingsConstants.HAC_KEY,
468 hac == SettingsConstants.HAC_ENABLED
469 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700470 }
Santos Cordonff506f52013-11-21 19:13:19 -0800471 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700472
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700473 /**
474 * Returns the singleton instance of the PhoneApp.
475 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800476 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700477 if (sMe == null) {
478 throw new IllegalStateException("No PhoneGlobals here!");
479 }
480 return sMe;
481 }
482
483 /**
484 * Returns the singleton instance of the PhoneApp if running as the
485 * primary user, otherwise null.
486 */
487 static PhoneGlobals getInstanceIfPrimary() {
488 return sMe;
489 }
490
491 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800492 * Returns the default phone.
493 *
Andrew Lee385019f2014-11-24 14:19:50 -0800494 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700495 */
Andrew Lee83383e42014-10-31 12:42:28 -0700496 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800497 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700498 }
499
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800500 public static Phone getPhone(int subId) {
501 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800502 }
503
Santos Cordon27a3c1f2013-08-06 07:49:27 -0700504 /* package */ BluetoothManager getBluetoothManager() {
505 return bluetoothManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700506 }
507
Santos Cordonde10b752013-09-19 04:11:33 -0700508 /* package */ CallManager getCallManager() {
509 return mCM;
510 }
511
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700512 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700513 * Returns PendingIntent for hanging up ongoing phone call. This will typically be used from
514 * Notification context.
515 */
516 /* package */ static PendingIntent createHangUpOngoingCallPendingIntent(Context context) {
517 Intent intent = new Intent(PhoneGlobals.ACTION_HANG_UP_ONGOING_CALL, null,
518 context, NotificationBroadcastReceiver.class);
519 return PendingIntent.getBroadcast(context, 0, intent, 0);
520 }
521
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700522 boolean isSimPinEnabled() {
523 return mIsSimPinEnabled;
524 }
525
526 boolean authenticateAgainstCachedSimPin(String pin) {
527 return (mCachedSimPin != null && mCachedSimPin.equals(pin));
528 }
529
530 void setCachedSimPin(String pin) {
531 mCachedSimPin = pin;
532 }
533
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700534 /**
535 * Handles OTASP-related events from the telephony layer.
536 *
537 * While an OTASP call is active, the CallNotifier forwards
538 * OTASP-related telephony events to this method.
539 */
540 void handleOtaspEvent(Message msg) {
541 if (DBG) Log.d(LOG_TAG, "handleOtaspEvent(message " + msg + ")...");
542
543 if (otaUtils == null) {
544 // We shouldn't be getting OTASP events without ever
545 // having started the OTASP call in the first place!
546 Log.w(LOG_TAG, "handleOtaEvents: got an event but otaUtils is null! "
547 + "message = " + msg);
548 return;
549 }
550
551 otaUtils.onOtaProvisionStatusChanged((AsyncResult) msg.obj);
552 }
553
554 /**
555 * Similarly, handle the disconnect event of an OTASP call
556 * by forwarding it to the OtaUtils instance.
557 */
558 /* package */ void handleOtaspDisconnect() {
559 if (DBG) Log.d(LOG_TAG, "handleOtaspDisconnect()...");
560
561 if (otaUtils == null) {
562 // We shouldn't be getting OTASP events without ever
563 // having started the OTASP call in the first place!
564 Log.w(LOG_TAG, "handleOtaspDisconnect: otaUtils is null!");
565 return;
566 }
567
568 otaUtils.onOtaspDisconnect();
569 }
570
571 /**
572 * Sets the activity responsible for un-PUK-blocking the device
573 * so that we may close it when we receive a positive result.
574 * mPUKEntryActivity is also used to indicate to the device that
575 * we are trying to un-PUK-lock the phone. In other words, iff
576 * it is NOT null, then we are trying to unlock and waiting for
577 * the SIM to move to READY state.
578 *
579 * @param activity is the activity to close when PUK has
580 * finished unlocking. Can be set to null to indicate the unlock
581 * or SIM READYing process is over.
582 */
583 void setPukEntryActivity(Activity activity) {
584 mPUKEntryActivity = activity;
585 }
586
587 Activity getPUKEntryActivity() {
588 return mPUKEntryActivity;
589 }
590
591 /**
592 * Sets the dialog responsible for notifying the user of un-PUK-
593 * blocking - SIM READYing progress, so that we may dismiss it
594 * when we receive a positive result.
595 *
596 * @param dialog indicates the progress dialog informing the user
597 * of the state of the device. Dismissed upon completion of
598 * READYing process
599 */
600 void setPukEntryProgressDialog(ProgressDialog dialog) {
601 mPUKEntryProgressDialog = dialog;
602 }
603
604 ProgressDialog getPUKEntryProgressDialog() {
605 return mPUKEntryProgressDialog;
606 }
607
608 /**
609 * Controls whether or not the screen is allowed to sleep.
610 *
611 * Once sleep is allowed (WakeState is SLEEP), it will rely on the
612 * settings for the poke lock to determine when to timeout and let
613 * the device sleep {@link PhoneGlobals#setScreenTimeout}.
614 *
615 * @param ws tells the device to how to wake.
616 */
617 /* package */ void requestWakeState(WakeState ws) {
618 if (VDBG) Log.d(LOG_TAG, "requestWakeState(" + ws + ")...");
619 synchronized (this) {
620 if (mWakeState != ws) {
621 switch (ws) {
622 case PARTIAL:
623 // acquire the processor wake lock, and release the FULL
624 // lock if it is being held.
625 mPartialWakeLock.acquire();
626 if (mWakeLock.isHeld()) {
627 mWakeLock.release();
628 }
629 break;
630 case FULL:
631 // acquire the full wake lock, and release the PARTIAL
632 // lock if it is being held.
633 mWakeLock.acquire();
634 if (mPartialWakeLock.isHeld()) {
635 mPartialWakeLock.release();
636 }
637 break;
638 case SLEEP:
639 default:
640 // release both the PARTIAL and FULL locks.
641 if (mWakeLock.isHeld()) {
642 mWakeLock.release();
643 }
644 if (mPartialWakeLock.isHeld()) {
645 mPartialWakeLock.release();
646 }
647 break;
648 }
649 mWakeState = ws;
650 }
651 }
652 }
653
654 /**
655 * If we are not currently keeping the screen on, then poke the power
656 * manager to wake up the screen for the user activity timeout duration.
657 */
658 /* package */ void wakeUpScreen() {
659 synchronized (this) {
660 if (mWakeState == WakeState.SLEEP) {
661 if (DBG) Log.d(LOG_TAG, "pulse screen lock");
662 mPowerManager.wakeUp(SystemClock.uptimeMillis());
663 }
664 }
665 }
666
667 /**
668 * Sets the wake state and screen timeout based on the current state
669 * of the phone, and the current state of the in-call UI.
670 *
671 * This method is a "UI Policy" wrapper around
672 * {@link PhoneGlobals#requestWakeState} and {@link PhoneGlobals#setScreenTimeout}.
673 *
674 * It's safe to call this method regardless of the state of the Phone
675 * (e.g. whether or not it's idle), and regardless of the state of the
676 * Phone UI (e.g. whether or not the InCallScreen is active.)
677 */
678 /* package */ void updateWakeState() {
679 PhoneConstants.State state = mCM.getState();
680
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700681 // True if the speakerphone is in use. (If so, we *always* use
682 // the default timeout. Since the user is obviously not holding
683 // the phone up to his/her face, we don't need to worry about
684 // false touches, and thus don't need to turn the screen off so
685 // aggressively.)
686 // Note that we need to make a fresh call to this method any
687 // time the speaker state changes. (That happens in
688 // PhoneUtils.turnOnSpeaker().)
689 boolean isSpeakerInUse = (state == PhoneConstants.State.OFFHOOK) && PhoneUtils.isSpeakerOn(this);
690
691 // TODO (bug 1440854): The screen timeout *might* also need to
692 // depend on the bluetooth state, but this isn't as clear-cut as
693 // the speaker state (since while using BT it's common for the
694 // user to put the phone straight into a pocket, in which case the
695 // timeout should probably still be short.)
696
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700697 // Decide whether to force the screen on or not.
698 //
699 // Force the screen to be on if the phone is ringing or dialing,
700 // or if we're displaying the "Call ended" UI for a connection in
701 // the "disconnected" state.
702 // However, if the phone is disconnected while the user is in the
703 // middle of selecting a quick response message, we should not force
704 // the screen to be on.
705 //
706 boolean isRinging = (state == PhoneConstants.State.RINGING);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800707 boolean isDialing = (mCM.getFgPhone().getForegroundCall().getState() == Call.State.DIALING);
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700708 boolean keepScreenOn = isRinging || isDialing;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700709 // keepScreenOn == true means we'll hold a full wake lock:
710 requestWakeState(keepScreenOn ? WakeState.FULL : WakeState.SLEEP);
711 }
712
713 /**
714 * Manually pokes the PowerManager's userActivity method. Since we
715 * set the {@link WindowManager.LayoutParams#INPUT_FEATURE_DISABLE_USER_ACTIVITY}
716 * flag while the InCallScreen is active when there is no proximity sensor,
717 * we need to do this for touch events that really do count as user activity
718 * (like pressing any onscreen UI elements.)
719 */
720 /* package */ void pokeUserActivity() {
721 if (VDBG) Log.d(LOG_TAG, "pokeUserActivity()...");
722 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
723 }
724
725 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700726 * Notifies the phone app when the phone state changes.
727 *
Santos Cordonfc309812013-08-20 18:33:16 -0700728 * This method will updates various states inside Phone app (e.g. update-lock state, etc.)
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700729 */
730 /* package */ void updatePhoneState(PhoneConstants.State state) {
731 if (state != mLastPhoneState) {
732 mLastPhoneState = state;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700733
734 // Try to acquire or release UpdateLock.
735 //
736 // Watch out: we don't release the lock here when the screen is still in foreground.
737 // At that time InCallScreen will release it on onPause().
738 if (state != PhoneConstants.State.IDLE) {
739 // UpdateLock is a recursive lock, while we may get "acquire" request twice and
740 // "release" request once for a single call (RINGING + OFFHOOK and IDLE).
741 // We need to manually ensure the lock is just acquired once for each (and this
742 // will prevent other possible buggy situations too).
743 if (!mUpdateLock.isHeld()) {
744 mUpdateLock.acquire();
745 }
746 } else {
Jay Shraunera5d13212013-09-19 13:37:43 -0700747 if (mUpdateLock.isHeld()) {
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700748 mUpdateLock.release();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700749 }
750 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700751 }
752 }
753
754 /* package */ PhoneConstants.State getPhoneState() {
755 return mLastPhoneState;
756 }
757
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700758 KeyguardManager getKeyguardManager() {
759 return mKeyguardManager;
760 }
761
762 private void onMMIComplete(AsyncResult r) {
763 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
764 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800765 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700766 }
767
Stuart Scottdcf40a92014-12-09 10:45:01 -0800768 private void initForNewRadioTechnology(int phoneId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700769 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
770
Stuart Scottdcf40a92014-12-09 10:45:01 -0800771 final Phone phone = PhoneFactory.getPhone(phoneId);
772
773 if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700774 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
775 cdmaPhoneCallState = new CdmaPhoneCallState();
776 cdmaPhoneCallState.CdmaPhoneCallStateInit();
777 }
Santos Cordon52bc81b2014-10-07 19:55:12 -0700778 if (!TelephonyCapabilities.supportsOtasp(phone)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700779 //Clean up OTA data in GSM/UMTS. It is valid only for CDMA
780 clearOtaState();
781 }
782
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700783 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
784 callStateMonitor.updateAfterRadioTechnologyChange();
785
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700786 // Update registration for ICC status after radio technology change
787 IccCard sim = phone.getIccCard();
788 if (sim != null) {
789 if (DBG) Log.d(LOG_TAG, "Update registration for ICC status...");
790
791 //Register all events new to the new active phone
792 sim.registerForNetworkLocked(mHandler, EVENT_SIM_NETWORK_LOCKED, null);
793 }
794 }
795
Santos Cordon593ab382013-08-06 21:58:23 -0700796 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700797 * Receiver for misc intent broadcasts the Phone app cares about.
798 */
799 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
800 @Override
801 public void onReceive(Context context, Intent intent) {
802 String action = intent.getAction();
803 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
804 boolean enabled = System.getInt(getContentResolver(),
805 System.AIRPLANE_MODE_ON, 0) == 0;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800806 PhoneUtils.setRadioPower(enabled);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700807 } else if (action.equals(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800808 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
809 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
810 int phoneId = SubscriptionManager.getPhoneId(subId);
811 String state = intent.getStringExtra(PhoneConstants.STATE_KEY);
812 if (VDBG) {
813 Log.d(LOG_TAG, "mReceiver: ACTION_ANY_DATA_CONNECTION_STATE_CHANGED");
814 Log.d(LOG_TAG, "- state: " + state);
815 Log.d(LOG_TAG, "- reason: "
816 + intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY));
817 Log.d(LOG_TAG, "- subId: " + subId);
818 Log.d(LOG_TAG, "- phoneId: " + phoneId);
819 }
820 Phone phone = SubscriptionManager.isValidPhoneId(phoneId) ?
821 PhoneFactory.getPhone(phoneId) : PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700822 // The "data disconnected due to roaming" notification is shown
823 // if (a) you have the "data roaming" feature turned off, and
824 // (b) you just lost data connectivity because you're roaming.
825 boolean disconnectedDueToRoaming =
826 !phone.getDataRoamingEnabled()
Stuart Scottdcf40a92014-12-09 10:45:01 -0800827 && PhoneConstants.DataState.DISCONNECTED.equals(state)
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700828 && Phone.REASON_ROAMING_ON.equals(
829 intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY));
Yorke Lee4d2db1c2014-11-06 11:37:09 -0800830 if (mDataDisconnectedDueToRoaming != disconnectedDueToRoaming) {
831 mDataDisconnectedDueToRoaming = disconnectedDueToRoaming;
832 mHandler.sendEmptyMessage(disconnectedDueToRoaming
833 ? EVENT_DATA_ROAMING_DISCONNECTED : EVENT_DATA_ROAMING_OK);
834 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700835 } else if ((action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) &&
836 (mPUKEntryActivity != null)) {
837 // if an attempt to un-PUK-lock the device was made, while we're
838 // receiving this state change notification, notify the handler.
839 // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has
840 // been attempted.
841 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
842 intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE)));
843 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
844 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800845 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
846 SubscriptionManager.INVALID_PHONE_INDEX);
847 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " (" + phoneId
848 + ") is active.");
849 initForNewRadioTechnology(phoneId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700850 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
851 handleServiceStateChanged(intent);
852 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800853 if (TelephonyCapabilities.supportsEcm(mCM.getFgPhone())) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700854 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
855 // Start Emergency Callback Mode service
856 if (intent.getBooleanExtra("phoneinECMState", false)) {
857 context.startService(new Intent(context,
858 EmergencyCallbackModeService.class));
859 }
860 } else {
861 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
862 // on a device that doesn't support ECM in the first place.
863 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, "
Stuart Scottdcf40a92014-12-09 10:45:01 -0800864 + "but ECM isn't supported for phone: "
865 + mCM.getFgPhone().getPhoneName());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700866 }
867 } else if (action.equals(Intent.ACTION_DOCK_EVENT)) {
868 mDockState = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
869 Intent.EXTRA_DOCK_STATE_UNDOCKED);
870 if (VDBG) Log.d(LOG_TAG, "ACTION_DOCK_EVENT -> mDockState = " + mDockState);
871 mHandler.sendMessage(mHandler.obtainMessage(EVENT_DOCK_STATE_CHANGED, 0));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700872 }
873 }
874 }
875
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700876 /**
877 * Accepts broadcast Intents which will be prepared by {@link NotificationMgr} and thus
878 * sent from framework's notification mechanism (which is outside Phone context).
879 * This should be visible from outside, but shouldn't be in "exported" state.
880 *
881 * TODO: If possible merge this into PhoneAppBroadcastReceiver.
882 */
883 public static class NotificationBroadcastReceiver extends BroadcastReceiver {
884 @Override
885 public void onReceive(Context context, Intent intent) {
886 String action = intent.getAction();
887 // TODO: use "if (VDBG)" here.
888 Log.d(LOG_TAG, "Broadcast from Notification: " + action);
889
890 if (action.equals(ACTION_HANG_UP_ONGOING_CALL)) {
891 PhoneUtils.hangup(PhoneGlobals.getInstance().mCM);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700892 } else {
893 Log.w(LOG_TAG, "Received hang-up request from notification,"
894 + " but there's no call the system can hang up.");
895 }
896 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700897 }
898
899 private void handleServiceStateChanged(Intent intent) {
900 /**
901 * This used to handle updating EriTextWidgetProvider this routine
902 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
903 * be removed. But leaving just in case it might be needed in the near
904 * future.
905 */
906
907 // If service just returned, start sending out the queued messages
908 ServiceState ss = ServiceState.newFromBundle(intent.getExtras());
909
910 if (ss != null) {
911 int state = ss.getState();
912 notificationMgr.updateNetworkSelection(state);
913 }
914 }
915
916 public boolean isOtaCallInActiveState() {
917 boolean otaCallActive = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700918 if (VDBG) Log.d(LOG_TAG, "- isOtaCallInActiveState " + otaCallActive);
919 return otaCallActive;
920 }
921
922 public boolean isOtaCallInEndState() {
923 boolean otaCallEnded = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700924 if (VDBG) Log.d(LOG_TAG, "- isOtaCallInEndState " + otaCallEnded);
925 return otaCallEnded;
926 }
927
928 // it is safe to call clearOtaState() even if the InCallScreen isn't active
929 public void clearOtaState() {
930 if (DBG) Log.d(LOG_TAG, "- clearOtaState ...");
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700931 if (otaUtils != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700932 otaUtils.cleanOtaScreen(true);
933 if (DBG) Log.d(LOG_TAG, " - clearOtaState clears OTA screen");
934 }
935 }
936
937 // it is safe to call dismissOtaDialogs() even if the InCallScreen isn't active
938 public void dismissOtaDialogs() {
939 if (DBG) Log.d(LOG_TAG, "- dismissOtaDialogs ...");
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700940 if (otaUtils != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700941 otaUtils.dismissAllOtaDialogs();
942 if (DBG) Log.d(LOG_TAG, " - dismissOtaDialogs clears OTA dialogs");
943 }
944 }
945
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700946 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800947 * Triggers a refresh of the message waiting (voicemail) indicator.
948 *
949 * @param subId the subscription id we should refresh the notification for.
950 */
951 public void refreshMwiIndicator(int subId) {
952 notificationMgr.refreshMwi(subId);
953 }
954
955 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700956 * "Call origin" may be used by Contacts app to specify where the phone call comes from.
957 * Currently, the only permitted value for this extra is {@link #ALLOWED_EXTRA_CALL_ORIGIN}.
958 * Any other value will be ignored, to make sure that malicious apps can't trick the in-call
959 * UI into launching some random other app after a call ends.
960 *
961 * TODO: make this more generic. Note that we should let the "origin" specify its package
962 * while we are now assuming it is "com.android.contacts"
963 */
964 public static final String EXTRA_CALL_ORIGIN = "com.android.phone.CALL_ORIGIN";
965 private static final String DEFAULT_CALL_ORIGIN_PACKAGE = "com.android.dialer";
966 private static final String ALLOWED_EXTRA_CALL_ORIGIN =
967 "com.android.dialer.DialtactsActivity";
968 /**
969 * Used to determine if the preserved call origin is fresh enough.
970 */
971 private static final long CALL_ORIGIN_EXPIRATION_MILLIS = 30 * 1000;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700972}