blob: e71d1fb885b5f66b4540693aab96b29ede98ed32 [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;
Junda Liu12f7d802015-05-01 12:06:44 -070051import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.telephony.ServiceState;
Andrew Lee2fcb6c32014-12-04 14:52:35 -080053import android.telephony.SubscriptionInfo;
Andrew Lee385019f2014-11-24 14:19:50 -080054import android.telephony.SubscriptionManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.util.Log;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056
57import com.android.internal.telephony.Call;
58import com.android.internal.telephony.CallManager;
59import com.android.internal.telephony.IccCard;
60import com.android.internal.telephony.IccCardConstants;
61import com.android.internal.telephony.MmiCode;
62import com.android.internal.telephony.Phone;
63import com.android.internal.telephony.PhoneConstants;
64import com.android.internal.telephony.PhoneFactory;
Andrew Lee385019f2014-11-24 14:19:50 -080065import com.android.internal.telephony.SubscriptionController;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066import com.android.internal.telephony.TelephonyCapabilities;
67import com.android.internal.telephony.TelephonyIntents;
Santos Cordon352ff652014-05-30 01:41:45 -070068import com.android.phone.common.CallLogAsync;
Andrew Leefb7f92e2015-02-26 16:23:32 -080069import com.android.phone.settings.SettingsConstants;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070import com.android.server.sip.SipService;
Santos Cordon76aaf482015-04-08 10:58:27 -070071import com.android.services.telephony.activation.SimActivationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070072
Andrew Lee385019f2014-11-24 14:19:50 -080073import java.util.ArrayList;
74import java.util.List;
75
Santos Cordon7d4ddf62013-07-10 11:58:08 -070076/**
77 * Global state for the telephony subsystem when running in the primary
78 * phone process.
79 */
Sailesh Nepalbf900542014-07-15 16:18:32 -070080public class PhoneGlobals extends ContextWrapper {
Andrew Lee83383e42014-10-31 12:42:28 -070081 public static final String LOG_TAG = "PhoneApp";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070082
83 /**
84 * Phone app-wide debug level:
85 * 0 - no debug logging
86 * 1 - normal debug logging if ro.debuggable is set (which is true in
87 * "eng" and "userdebug" builds but not "user" builds)
88 * 2 - ultra-verbose debug logging
89 *
90 * Most individual classes in the phone app have a local DBG constant,
91 * typically set to
92 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
93 * or else
94 * (PhoneApp.DBG_LEVEL >= 2)
95 * depending on the desired verbosity.
96 *
97 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
98 */
Andrew Lee88b51e22014-10-29 15:48:51 -070099 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700100
101 private static final boolean DBG =
102 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
103 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
104
105 // Message codes; see mHandler below.
106 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700108 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
109 private static final int EVENT_DATA_ROAMING_OK = 11;
110 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 12;
111 private static final int EVENT_DOCK_STATE_CHANGED = 13;
Sailesh Nepalbf900542014-07-15 16:18:32 -0700112 private static final int EVENT_START_SIP_SERVICE = 14;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700113
114 // The MMI codes are also used by the InCallScreen.
115 public static final int MMI_INITIATE = 51;
116 public static final int MMI_COMPLETE = 52;
117 public static final int MMI_CANCEL = 53;
118 // Don't use message codes larger than 99 here; those are reserved for
119 // the individual Activities of the Phone UI.
120
121 /**
122 * Allowable values for the wake lock code.
123 * SLEEP means the device can be put to sleep.
124 * PARTIAL means wake the processor, but we display can be kept off.
125 * FULL means wake both the processor and the display.
126 */
127 public enum WakeState {
128 SLEEP,
129 PARTIAL,
130 FULL
131 }
132
133 /**
134 * Intent Action used for hanging up the current call from Notification bar. This will
135 * choose first ringing call, first active call, or first background call (typically in
136 * HOLDING state).
137 */
138 public static final String ACTION_HANG_UP_ONGOING_CALL =
139 "com.android.phone.ACTION_HANG_UP_ONGOING_CALL";
140
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141 private static PhoneGlobals sMe;
142
143 // A few important fields we expose to the rest of the package
144 // directly (rather than thru set/get methods) for efficiency.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700145 CallController callController;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700146 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700147 CallNotifier notifier;
148 CallerInfoCache callerInfoCache;
Santos Cordon63a84242013-07-23 13:32:52 -0700149 NotificationMgr notificationMgr;
Andrew Lee9431b832015-03-09 18:46:45 -0700150 public PhoneInterfaceManager phoneMgr;
Santos Cordon76aaf482015-04-08 10:58:27 -0700151 public SimActivationManager simActivationManager;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800152 CarrierConfigLoader configLoader;
Santos Cordon63a84242013-07-23 13:32:52 -0700153
Santos Cordon27a3c1f2013-08-06 07:49:27 -0700154 private BluetoothManager bluetoothManager;
Santos Cordon69a69192013-08-22 14:25:42 -0700155 private CallGatewayManager callGatewayManager;
Santos Cordon63a84242013-07-23 13:32:52 -0700156 private CallStateMonitor callStateMonitor;
Santos Cordon63a84242013-07-23 13:32:52 -0700157
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700158 static int mDockState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
159 static boolean sVoiceCapable = true;
160
161 // Internal PhoneApp Call state tracker
162 CdmaPhoneCallState cdmaPhoneCallState;
163
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700164 // The currently-active PUK entry activity and progress dialog.
165 // Normally, these are the Emergency Dialer and the subsequent
166 // progress dialog. null if there is are no such objects in
167 // the foreground.
168 private Activity mPUKEntryActivity;
169 private ProgressDialog mPUKEntryProgressDialog;
170
171 private boolean mIsSimPinEnabled;
172 private String mCachedSimPin;
173
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174 // True if we are beginning a call, but the phone state has not changed yet
175 private boolean mBeginningCall;
Yorke Lee4d2db1c2014-11-06 11:37:09 -0800176 private boolean mDataDisconnectedDueToRoaming = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700177
178 // Last phone state seen by updatePhoneState()
179 private PhoneConstants.State mLastPhoneState = PhoneConstants.State.IDLE;
180
181 private WakeState mWakeState = WakeState.SLEEP;
182
183 private PowerManager mPowerManager;
184 private IPowerManager mPowerManagerService;
185 private PowerManager.WakeLock mWakeLock;
186 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700187 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700188
189 private UpdateLock mUpdateLock;
190
191 // Broadcast receiver for various intent broadcasts (see onCreate())
192 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
193
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194 /** boolean indicating restoring mute state on InCallScreen.onResume() */
195 private boolean mShouldRestoreMuteOnInCallResume;
196
197 /**
198 * The singleton OtaUtils instance used for OTASP calls.
199 *
200 * The OtaUtils instance is created lazily the first time we need to
201 * make an OTASP call, regardless of whether it's an interactive or
202 * non-interactive OTASP call.
203 */
204 public OtaUtils otaUtils;
205
206 // Following are the CDMA OTA information Objects used during OTA Call.
207 // cdmaOtaProvisionData object store static OTA information that needs
208 // to be maintained even during Slider open/close scenarios.
209 // cdmaOtaConfigData object stores configuration info to control visiblity
210 // of each OTA Screens.
211 // cdmaOtaScreenState object store OTA Screen State information.
212 public OtaUtils.CdmaOtaProvisionData cdmaOtaProvisionData;
213 public OtaUtils.CdmaOtaConfigData cdmaOtaConfigData;
214 public OtaUtils.CdmaOtaScreenState cdmaOtaScreenState;
215 public OtaUtils.CdmaOtaInCallScreenUiState cdmaOtaInCallScreenUiState;
216
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700217 /**
218 * Set the restore mute state flag. Used when we are setting the mute state
219 * OUTSIDE of user interaction {@link PhoneUtils#startNewCall(Phone)}
220 */
221 /*package*/void setRestoreMuteOnInCallResume (boolean mode) {
222 mShouldRestoreMuteOnInCallResume = mode;
223 }
224
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700225 Handler mHandler = new Handler() {
226 @Override
227 public void handleMessage(Message msg) {
228 PhoneConstants.State phoneState;
229 switch (msg.what) {
230 // Starts the SIP service. It's a no-op if SIP API is not supported
231 // on the deivce.
232 // TODO: Having the phone process host the SIP service is only
233 // temporary. Will move it to a persistent communication process
234 // later.
235 case EVENT_START_SIP_SERVICE:
236 SipService.start(getApplicationContext());
237 break;
238
239 // TODO: This event should be handled by the lock screen, just
240 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
241 case EVENT_SIM_NETWORK_LOCKED:
Junda Liu12f7d802015-05-01 12:06:44 -0700242 if (getCarrierConfig().getBoolean(CarrierConfigManager.BOOL_IGNORE_SIM_NETWORK_LOCKED_EVENTS)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700243 // Some products don't have the concept of a "SIM network lock"
244 Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; "
245 + "not showing 'SIM network unlock' PIN entry screen");
246 } else {
247 // Normal case: show the "SIM network unlock" PIN entry screen.
248 // The user won't be able to do anything else until
249 // they enter a valid SIM network PIN.
250 Log.i(LOG_TAG, "show sim depersonal panel");
251 IccNetworkDepersonalizationPanel ndpPanel =
252 new IccNetworkDepersonalizationPanel(PhoneGlobals.getInstance());
253 ndpPanel.show();
254 }
255 break;
256
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700257 case EVENT_DATA_ROAMING_DISCONNECTED:
258 notificationMgr.showDataDisconnectedRoaming();
259 break;
260
261 case EVENT_DATA_ROAMING_OK:
262 notificationMgr.hideDataDisconnectedRoaming();
263 break;
264
265 case MMI_COMPLETE:
266 onMMIComplete((AsyncResult) msg.obj);
267 break;
268
269 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800270 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700271 break;
272
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700273 case EVENT_SIM_STATE_CHANGED:
274 // Marks the event where the SIM goes into ready state.
275 // Right now, this is only used for the PUK-unlocking
276 // process.
277 if (msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_READY)) {
278 // when the right event is triggered and there
279 // are UI objects in the foreground, we close
280 // them to display the lock panel.
281 if (mPUKEntryActivity != null) {
282 mPUKEntryActivity.finish();
283 mPUKEntryActivity = null;
284 }
285 if (mPUKEntryProgressDialog != null) {
286 mPUKEntryProgressDialog.dismiss();
287 mPUKEntryProgressDialog = null;
288 }
289 }
290 break;
291
292 case EVENT_UNSOL_CDMA_INFO_RECORD:
293 //TODO: handle message here;
294 break;
295
296 case EVENT_DOCK_STATE_CHANGED:
297 // If the phone is docked/undocked during a call, and no wired or BT headset
298 // is connected: turn on/off the speaker accordingly.
299 boolean inDockMode = false;
300 if (mDockState != Intent.EXTRA_DOCK_STATE_UNDOCKED) {
301 inDockMode = true;
302 }
303 if (VDBG) Log.d(LOG_TAG, "received EVENT_DOCK_STATE_CHANGED. Phone inDock = "
304 + inDockMode);
305
306 phoneState = mCM.getState();
307 if (phoneState == PhoneConstants.State.OFFHOOK &&
Santos Cordon593ab382013-08-06 21:58:23 -0700308 !bluetoothManager.isBluetoothHeadsetAudioOn()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700309 PhoneUtils.turnOnSpeaker(getApplicationContext(), inDockMode, true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700310 }
311 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700312 }
313 }
314 };
315
316 public PhoneGlobals(Context context) {
317 super(context);
318 sMe = this;
319 }
320
321 public void onCreate() {
322 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
323
324 ContentResolver resolver = getContentResolver();
325
326 // Cache the "voice capable" flag.
327 // This flag currently comes from a resource (which is
328 // overrideable on a per-product basis):
329 sVoiceCapable =
330 getResources().getBoolean(com.android.internal.R.bool.config_voice_capable);
331 // ...but this might eventually become a PackageManager "system
332 // feature" instead, in which case we'd do something like:
333 // sVoiceCapable =
334 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
335
Stuart Scottdcf40a92014-12-09 10:45:01 -0800336 if (mCM == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700337 // Initialize the telephony framework
338 PhoneFactory.makeDefaultPhones(this);
339
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700340 // Start TelephonyDebugService After the default phone is created.
341 Intent intent = new Intent(this, TelephonyDebugService.class);
342 startService(intent);
343
344 mCM = CallManager.getInstance();
Stuart Scottdcf40a92014-12-09 10:45:01 -0800345 boolean hasCdmaPhoneType = false;
346 for (Phone phone : PhoneFactory.getPhones()) {
347 mCM.registerPhone(phone);
348 if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
349 hasCdmaPhoneType = true;
350 }
351 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700352
353 // Create the NotificationMgr singleton, which is used to display
354 // status bar icons and control other status bar behavior.
355 notificationMgr = NotificationMgr.init(this);
356
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357 mHandler.sendEmptyMessage(EVENT_START_SIP_SERVICE);
358
Stuart Scottdcf40a92014-12-09 10:45:01 -0800359 if (hasCdmaPhoneType) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
361 cdmaPhoneCallState = new CdmaPhoneCallState();
362 cdmaPhoneCallState.CdmaPhoneCallStateInit();
363 }
364
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365 // before registering for phone state changes
366 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
367 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
368 // lock used to keep the processor awake, when we don't care for the display.
369 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
370 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371
372 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
373
374 // get a handle to the service so that we can use it later when we
375 // want to set the poke lock.
376 mPowerManagerService = IPowerManager.Stub.asInterface(
377 ServiceManager.getService("power"));
378
379 // Get UpdateLock to suppress system-update related events (e.g. dialog show-up)
380 // during phone calls.
381 mUpdateLock = new UpdateLock("phone");
382
383 if (DBG) Log.d(LOG_TAG, "onCreate: mUpdateLock: " + mUpdateLock);
384
385 CallLogger callLogger = new CallLogger(this, new CallLogAsync());
386
Jay Shrauner21a75342013-11-25 16:14:43 -0800387 callGatewayManager = CallGatewayManager.getInstance();
Santos Cordon69a69192013-08-22 14:25:42 -0700388
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700389 // Create the CallController singleton, which is the interface
390 // to the telephony layer for user-initiated telephony functionality
391 // (like making outgoing calls.)
Santos Cordon69a69192013-08-22 14:25:42 -0700392 callController = CallController.init(this, callLogger, callGatewayManager);
393
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394 // Create the CallerInfoCache singleton, which remembers custom ring tone and
395 // send-to-voicemail settings.
396 //
397 // The asynchronous caching will start just after this call.
398 callerInfoCache = CallerInfoCache.init(this);
399
400 // Monitors call activity from the telephony layer
401 callStateMonitor = new CallStateMonitor(mCM);
402
Santos Cordon2c2d3cf2013-08-08 03:53:47 -0700403 // Bluetooth manager
Sailesh Nepal23d9ed72014-07-03 09:40:26 -0700404 bluetoothManager = new BluetoothManager();
Santos Cordon2c2d3cf2013-08-08 03:53:47 -0700405
Stuart Scottdcf40a92014-12-09 10:45:01 -0800406 phoneMgr = PhoneInterfaceManager.init(this, PhoneFactory.getDefaultPhone());
Santos Cordon406c0342013-08-28 00:07:47 -0700407
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800408 configLoader = CarrierConfigLoader.init(this);
409
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700410 // Create the CallNotifer singleton, which handles
411 // asynchronous events from the telephony layer (like
412 // launching the incoming-call UI when an incoming call comes
413 // in.)
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800414 notifier = CallNotifier.init(this, callLogger, callStateMonitor, bluetoothManager);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415
Stuart Scottdcf40a92014-12-09 10:45:01 -0800416 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417
418 // register for MMI/USSD
419 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
420
421 // register connection tracking to PhoneUtils
422 PhoneUtils.initializeConnectionHandler(mCM);
423
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424 // Register for misc other intent broadcasts.
425 IntentFilter intentFilter =
426 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427 intentFilter.addAction(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700428 intentFilter.addAction(Intent.ACTION_DOCK_EVENT);
429 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
430 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
431 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
432 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700433 registerReceiver(mReceiver, intentFilter);
434
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700435 //set the default values for the preferences in the phone.
436 PreferenceManager.setDefaultValues(this, R.xml.network_setting, false);
437
438 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
439
440 // Make sure the audio mode (along with some
441 // audio-mode-related state of our own) is initialized
442 // correctly, given the current state of the phone.
443 PhoneUtils.setAudioMode(mCM);
444 }
445
Santos Cordon52bc81b2014-10-07 19:55:12 -0700446 cdmaOtaProvisionData = new OtaUtils.CdmaOtaProvisionData();
447 cdmaOtaConfigData = new OtaUtils.CdmaOtaConfigData();
448 cdmaOtaScreenState = new OtaUtils.CdmaOtaScreenState();
449 cdmaOtaInCallScreenUiState = new OtaUtils.CdmaOtaInCallScreenUiState();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700450
Santos Cordon76aaf482015-04-08 10:58:27 -0700451 simActivationManager = new SimActivationManager();
452
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700453 // XXX pre-load the SimProvider so that it's ready
454 resolver.getType(Uri.parse("content://icc/adn"));
455
456 // start with the default value to set the mute state.
457 mShouldRestoreMuteOnInCallResume = false;
458
459 // TODO: Register for Cdma Information Records
460 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
461
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700462 // Read HAC settings and configure audio hardware
463 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800464 int hac = android.provider.Settings.System.getInt(
465 getContentResolver(),
466 android.provider.Settings.System.HEARING_AID,
467 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700468 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Andrew Leefb7f92e2015-02-26 16:23:32 -0800469 audioManager.setParameter(SettingsConstants.HAC_KEY,
470 hac == SettingsConstants.HAC_ENABLED
471 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700472 }
Santos Cordonff506f52013-11-21 19:13:19 -0800473 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700474
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700475 /**
476 * Returns the singleton instance of the PhoneApp.
477 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800478 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700479 if (sMe == null) {
480 throw new IllegalStateException("No PhoneGlobals here!");
481 }
482 return sMe;
483 }
484
485 /**
486 * Returns the singleton instance of the PhoneApp if running as the
487 * primary user, otherwise null.
488 */
489 static PhoneGlobals getInstanceIfPrimary() {
490 return sMe;
491 }
492
493 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800494 * Returns the default phone.
495 *
Andrew Lee385019f2014-11-24 14:19:50 -0800496 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700497 */
Andrew Lee83383e42014-10-31 12:42:28 -0700498 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800499 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700500 }
501
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800502 public static Phone getPhone(int subId) {
503 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800504 }
505
Santos Cordon27a3c1f2013-08-06 07:49:27 -0700506 /* package */ BluetoothManager getBluetoothManager() {
507 return bluetoothManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700508 }
509
Santos Cordonde10b752013-09-19 04:11:33 -0700510 /* package */ CallManager getCallManager() {
511 return mCM;
512 }
513
Junda Liu605148f2015-04-28 15:23:40 -0700514 /* package */ Bundle getCarrierConfig() {
515 return configLoader.getConfigForSubId(SubscriptionManager.getDefaultSubId());
516 }
517
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700518 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700519 * Returns PendingIntent for hanging up ongoing phone call. This will typically be used from
520 * Notification context.
521 */
522 /* package */ static PendingIntent createHangUpOngoingCallPendingIntent(Context context) {
523 Intent intent = new Intent(PhoneGlobals.ACTION_HANG_UP_ONGOING_CALL, null,
524 context, NotificationBroadcastReceiver.class);
525 return PendingIntent.getBroadcast(context, 0, intent, 0);
526 }
527
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700528 boolean isSimPinEnabled() {
529 return mIsSimPinEnabled;
530 }
531
532 boolean authenticateAgainstCachedSimPin(String pin) {
533 return (mCachedSimPin != null && mCachedSimPin.equals(pin));
534 }
535
536 void setCachedSimPin(String pin) {
537 mCachedSimPin = pin;
538 }
539
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700540 /**
541 * Handles OTASP-related events from the telephony layer.
542 *
543 * While an OTASP call is active, the CallNotifier forwards
544 * OTASP-related telephony events to this method.
545 */
546 void handleOtaspEvent(Message msg) {
547 if (DBG) Log.d(LOG_TAG, "handleOtaspEvent(message " + msg + ")...");
548
549 if (otaUtils == null) {
550 // We shouldn't be getting OTASP events without ever
551 // having started the OTASP call in the first place!
552 Log.w(LOG_TAG, "handleOtaEvents: got an event but otaUtils is null! "
553 + "message = " + msg);
554 return;
555 }
556
557 otaUtils.onOtaProvisionStatusChanged((AsyncResult) msg.obj);
558 }
559
560 /**
561 * Similarly, handle the disconnect event of an OTASP call
562 * by forwarding it to the OtaUtils instance.
563 */
564 /* package */ void handleOtaspDisconnect() {
565 if (DBG) Log.d(LOG_TAG, "handleOtaspDisconnect()...");
566
567 if (otaUtils == null) {
568 // We shouldn't be getting OTASP events without ever
569 // having started the OTASP call in the first place!
570 Log.w(LOG_TAG, "handleOtaspDisconnect: otaUtils is null!");
571 return;
572 }
573
574 otaUtils.onOtaspDisconnect();
575 }
576
577 /**
578 * Sets the activity responsible for un-PUK-blocking the device
579 * so that we may close it when we receive a positive result.
580 * mPUKEntryActivity is also used to indicate to the device that
581 * we are trying to un-PUK-lock the phone. In other words, iff
582 * it is NOT null, then we are trying to unlock and waiting for
583 * the SIM to move to READY state.
584 *
585 * @param activity is the activity to close when PUK has
586 * finished unlocking. Can be set to null to indicate the unlock
587 * or SIM READYing process is over.
588 */
589 void setPukEntryActivity(Activity activity) {
590 mPUKEntryActivity = activity;
591 }
592
593 Activity getPUKEntryActivity() {
594 return mPUKEntryActivity;
595 }
596
597 /**
598 * Sets the dialog responsible for notifying the user of un-PUK-
599 * blocking - SIM READYing progress, so that we may dismiss it
600 * when we receive a positive result.
601 *
602 * @param dialog indicates the progress dialog informing the user
603 * of the state of the device. Dismissed upon completion of
604 * READYing process
605 */
606 void setPukEntryProgressDialog(ProgressDialog dialog) {
607 mPUKEntryProgressDialog = dialog;
608 }
609
610 ProgressDialog getPUKEntryProgressDialog() {
611 return mPUKEntryProgressDialog;
612 }
613
614 /**
615 * Controls whether or not the screen is allowed to sleep.
616 *
617 * Once sleep is allowed (WakeState is SLEEP), it will rely on the
618 * settings for the poke lock to determine when to timeout and let
619 * the device sleep {@link PhoneGlobals#setScreenTimeout}.
620 *
621 * @param ws tells the device to how to wake.
622 */
623 /* package */ void requestWakeState(WakeState ws) {
624 if (VDBG) Log.d(LOG_TAG, "requestWakeState(" + ws + ")...");
625 synchronized (this) {
626 if (mWakeState != ws) {
627 switch (ws) {
628 case PARTIAL:
629 // acquire the processor wake lock, and release the FULL
630 // lock if it is being held.
631 mPartialWakeLock.acquire();
632 if (mWakeLock.isHeld()) {
633 mWakeLock.release();
634 }
635 break;
636 case FULL:
637 // acquire the full wake lock, and release the PARTIAL
638 // lock if it is being held.
639 mWakeLock.acquire();
640 if (mPartialWakeLock.isHeld()) {
641 mPartialWakeLock.release();
642 }
643 break;
644 case SLEEP:
645 default:
646 // release both the PARTIAL and FULL locks.
647 if (mWakeLock.isHeld()) {
648 mWakeLock.release();
649 }
650 if (mPartialWakeLock.isHeld()) {
651 mPartialWakeLock.release();
652 }
653 break;
654 }
655 mWakeState = ws;
656 }
657 }
658 }
659
660 /**
661 * If we are not currently keeping the screen on, then poke the power
662 * manager to wake up the screen for the user activity timeout duration.
663 */
664 /* package */ void wakeUpScreen() {
665 synchronized (this) {
666 if (mWakeState == WakeState.SLEEP) {
667 if (DBG) Log.d(LOG_TAG, "pulse screen lock");
668 mPowerManager.wakeUp(SystemClock.uptimeMillis());
669 }
670 }
671 }
672
673 /**
674 * Sets the wake state and screen timeout based on the current state
675 * of the phone, and the current state of the in-call UI.
676 *
677 * This method is a "UI Policy" wrapper around
678 * {@link PhoneGlobals#requestWakeState} and {@link PhoneGlobals#setScreenTimeout}.
679 *
680 * It's safe to call this method regardless of the state of the Phone
681 * (e.g. whether or not it's idle), and regardless of the state of the
682 * Phone UI (e.g. whether or not the InCallScreen is active.)
683 */
684 /* package */ void updateWakeState() {
685 PhoneConstants.State state = mCM.getState();
686
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700687 // True if the speakerphone is in use. (If so, we *always* use
688 // the default timeout. Since the user is obviously not holding
689 // the phone up to his/her face, we don't need to worry about
690 // false touches, and thus don't need to turn the screen off so
691 // aggressively.)
692 // Note that we need to make a fresh call to this method any
693 // time the speaker state changes. (That happens in
694 // PhoneUtils.turnOnSpeaker().)
695 boolean isSpeakerInUse = (state == PhoneConstants.State.OFFHOOK) && PhoneUtils.isSpeakerOn(this);
696
697 // TODO (bug 1440854): The screen timeout *might* also need to
698 // depend on the bluetooth state, but this isn't as clear-cut as
699 // the speaker state (since while using BT it's common for the
700 // user to put the phone straight into a pocket, in which case the
701 // timeout should probably still be short.)
702
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700703 // Decide whether to force the screen on or not.
704 //
705 // Force the screen to be on if the phone is ringing or dialing,
706 // or if we're displaying the "Call ended" UI for a connection in
707 // the "disconnected" state.
708 // However, if the phone is disconnected while the user is in the
709 // middle of selecting a quick response message, we should not force
710 // the screen to be on.
711 //
712 boolean isRinging = (state == PhoneConstants.State.RINGING);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800713 boolean isDialing = (mCM.getFgPhone().getForegroundCall().getState() == Call.State.DIALING);
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700714 boolean keepScreenOn = isRinging || isDialing;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700715 // keepScreenOn == true means we'll hold a full wake lock:
716 requestWakeState(keepScreenOn ? WakeState.FULL : WakeState.SLEEP);
717 }
718
719 /**
720 * Manually pokes the PowerManager's userActivity method. Since we
721 * set the {@link WindowManager.LayoutParams#INPUT_FEATURE_DISABLE_USER_ACTIVITY}
722 * flag while the InCallScreen is active when there is no proximity sensor,
723 * we need to do this for touch events that really do count as user activity
724 * (like pressing any onscreen UI elements.)
725 */
726 /* package */ void pokeUserActivity() {
727 if (VDBG) Log.d(LOG_TAG, "pokeUserActivity()...");
728 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
729 }
730
731 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700732 * Notifies the phone app when the phone state changes.
733 *
Santos Cordonfc309812013-08-20 18:33:16 -0700734 * This method will updates various states inside Phone app (e.g. update-lock state, etc.)
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700735 */
736 /* package */ void updatePhoneState(PhoneConstants.State state) {
737 if (state != mLastPhoneState) {
738 mLastPhoneState = state;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700739
740 // Try to acquire or release UpdateLock.
741 //
742 // Watch out: we don't release the lock here when the screen is still in foreground.
743 // At that time InCallScreen will release it on onPause().
744 if (state != PhoneConstants.State.IDLE) {
745 // UpdateLock is a recursive lock, while we may get "acquire" request twice and
746 // "release" request once for a single call (RINGING + OFFHOOK and IDLE).
747 // We need to manually ensure the lock is just acquired once for each (and this
748 // will prevent other possible buggy situations too).
749 if (!mUpdateLock.isHeld()) {
750 mUpdateLock.acquire();
751 }
752 } else {
Jay Shraunera5d13212013-09-19 13:37:43 -0700753 if (mUpdateLock.isHeld()) {
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700754 mUpdateLock.release();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700755 }
756 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700757 }
758 }
759
760 /* package */ PhoneConstants.State getPhoneState() {
761 return mLastPhoneState;
762 }
763
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700764 KeyguardManager getKeyguardManager() {
765 return mKeyguardManager;
766 }
767
768 private void onMMIComplete(AsyncResult r) {
769 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
770 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800771 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700772 }
773
Stuart Scottdcf40a92014-12-09 10:45:01 -0800774 private void initForNewRadioTechnology(int phoneId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700775 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
776
Stuart Scottdcf40a92014-12-09 10:45:01 -0800777 final Phone phone = PhoneFactory.getPhone(phoneId);
778
779 if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700780 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
781 cdmaPhoneCallState = new CdmaPhoneCallState();
782 cdmaPhoneCallState.CdmaPhoneCallStateInit();
783 }
Santos Cordon52bc81b2014-10-07 19:55:12 -0700784 if (!TelephonyCapabilities.supportsOtasp(phone)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700785 //Clean up OTA data in GSM/UMTS. It is valid only for CDMA
786 clearOtaState();
787 }
788
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700789 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
790 callStateMonitor.updateAfterRadioTechnologyChange();
791
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700792 // Update registration for ICC status after radio technology change
793 IccCard sim = phone.getIccCard();
794 if (sim != null) {
795 if (DBG) Log.d(LOG_TAG, "Update registration for ICC status...");
796
797 //Register all events new to the new active phone
798 sim.registerForNetworkLocked(mHandler, EVENT_SIM_NETWORK_LOCKED, null);
799 }
800 }
801
Santos Cordon593ab382013-08-06 21:58:23 -0700802 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700803 * Receiver for misc intent broadcasts the Phone app cares about.
804 */
805 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
806 @Override
807 public void onReceive(Context context, Intent intent) {
808 String action = intent.getAction();
809 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
810 boolean enabled = System.getInt(getContentResolver(),
811 System.AIRPLANE_MODE_ON, 0) == 0;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800812 PhoneUtils.setRadioPower(enabled);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700813 } else if (action.equals(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800814 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
815 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
816 int phoneId = SubscriptionManager.getPhoneId(subId);
817 String state = intent.getStringExtra(PhoneConstants.STATE_KEY);
818 if (VDBG) {
819 Log.d(LOG_TAG, "mReceiver: ACTION_ANY_DATA_CONNECTION_STATE_CHANGED");
820 Log.d(LOG_TAG, "- state: " + state);
821 Log.d(LOG_TAG, "- reason: "
822 + intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY));
823 Log.d(LOG_TAG, "- subId: " + subId);
824 Log.d(LOG_TAG, "- phoneId: " + phoneId);
825 }
826 Phone phone = SubscriptionManager.isValidPhoneId(phoneId) ?
827 PhoneFactory.getPhone(phoneId) : PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700828 // The "data disconnected due to roaming" notification is shown
829 // if (a) you have the "data roaming" feature turned off, and
830 // (b) you just lost data connectivity because you're roaming.
831 boolean disconnectedDueToRoaming =
832 !phone.getDataRoamingEnabled()
Stuart Scottdcf40a92014-12-09 10:45:01 -0800833 && PhoneConstants.DataState.DISCONNECTED.equals(state)
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700834 && Phone.REASON_ROAMING_ON.equals(
835 intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY));
Yorke Lee4d2db1c2014-11-06 11:37:09 -0800836 if (mDataDisconnectedDueToRoaming != disconnectedDueToRoaming) {
837 mDataDisconnectedDueToRoaming = disconnectedDueToRoaming;
838 mHandler.sendEmptyMessage(disconnectedDueToRoaming
839 ? EVENT_DATA_ROAMING_DISCONNECTED : EVENT_DATA_ROAMING_OK);
840 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700841 } else if ((action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) &&
842 (mPUKEntryActivity != null)) {
843 // if an attempt to un-PUK-lock the device was made, while we're
844 // receiving this state change notification, notify the handler.
845 // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has
846 // been attempted.
847 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
848 intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE)));
849 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
850 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800851 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
852 SubscriptionManager.INVALID_PHONE_INDEX);
853 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " (" + phoneId
854 + ") is active.");
855 initForNewRadioTechnology(phoneId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700856 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
857 handleServiceStateChanged(intent);
858 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800859 if (TelephonyCapabilities.supportsEcm(mCM.getFgPhone())) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700860 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
861 // Start Emergency Callback Mode service
862 if (intent.getBooleanExtra("phoneinECMState", false)) {
863 context.startService(new Intent(context,
864 EmergencyCallbackModeService.class));
865 }
866 } else {
867 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
868 // on a device that doesn't support ECM in the first place.
869 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, "
Stuart Scottdcf40a92014-12-09 10:45:01 -0800870 + "but ECM isn't supported for phone: "
871 + mCM.getFgPhone().getPhoneName());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700872 }
873 } else if (action.equals(Intent.ACTION_DOCK_EVENT)) {
874 mDockState = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
875 Intent.EXTRA_DOCK_STATE_UNDOCKED);
876 if (VDBG) Log.d(LOG_TAG, "ACTION_DOCK_EVENT -> mDockState = " + mDockState);
877 mHandler.sendMessage(mHandler.obtainMessage(EVENT_DOCK_STATE_CHANGED, 0));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700878 }
879 }
880 }
881
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700882 /**
883 * Accepts broadcast Intents which will be prepared by {@link NotificationMgr} and thus
884 * sent from framework's notification mechanism (which is outside Phone context).
885 * This should be visible from outside, but shouldn't be in "exported" state.
886 *
887 * TODO: If possible merge this into PhoneAppBroadcastReceiver.
888 */
889 public static class NotificationBroadcastReceiver extends BroadcastReceiver {
890 @Override
891 public void onReceive(Context context, Intent intent) {
892 String action = intent.getAction();
893 // TODO: use "if (VDBG)" here.
894 Log.d(LOG_TAG, "Broadcast from Notification: " + action);
895
896 if (action.equals(ACTION_HANG_UP_ONGOING_CALL)) {
897 PhoneUtils.hangup(PhoneGlobals.getInstance().mCM);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700898 } else {
899 Log.w(LOG_TAG, "Received hang-up request from notification,"
900 + " but there's no call the system can hang up.");
901 }
902 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700903 }
904
905 private void handleServiceStateChanged(Intent intent) {
906 /**
907 * This used to handle updating EriTextWidgetProvider this routine
908 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
909 * be removed. But leaving just in case it might be needed in the near
910 * future.
911 */
912
913 // If service just returned, start sending out the queued messages
914 ServiceState ss = ServiceState.newFromBundle(intent.getExtras());
915
916 if (ss != null) {
917 int state = ss.getState();
918 notificationMgr.updateNetworkSelection(state);
919 }
920 }
921
922 public boolean isOtaCallInActiveState() {
923 boolean otaCallActive = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700924 if (VDBG) Log.d(LOG_TAG, "- isOtaCallInActiveState " + otaCallActive);
925 return otaCallActive;
926 }
927
928 public boolean isOtaCallInEndState() {
929 boolean otaCallEnded = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700930 if (VDBG) Log.d(LOG_TAG, "- isOtaCallInEndState " + otaCallEnded);
931 return otaCallEnded;
932 }
933
934 // it is safe to call clearOtaState() even if the InCallScreen isn't active
935 public void clearOtaState() {
936 if (DBG) Log.d(LOG_TAG, "- clearOtaState ...");
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700937 if (otaUtils != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700938 otaUtils.cleanOtaScreen(true);
939 if (DBG) Log.d(LOG_TAG, " - clearOtaState clears OTA screen");
940 }
941 }
942
943 // it is safe to call dismissOtaDialogs() even if the InCallScreen isn't active
944 public void dismissOtaDialogs() {
945 if (DBG) Log.d(LOG_TAG, "- dismissOtaDialogs ...");
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700946 if (otaUtils != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700947 otaUtils.dismissAllOtaDialogs();
948 if (DBG) Log.d(LOG_TAG, " - dismissOtaDialogs clears OTA dialogs");
949 }
950 }
951
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700952 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800953 * Triggers a refresh of the message waiting (voicemail) indicator.
954 *
955 * @param subId the subscription id we should refresh the notification for.
956 */
957 public void refreshMwiIndicator(int subId) {
958 notificationMgr.refreshMwi(subId);
959 }
960
961 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700962 * "Call origin" may be used by Contacts app to specify where the phone call comes from.
963 * Currently, the only permitted value for this extra is {@link #ALLOWED_EXTRA_CALL_ORIGIN}.
964 * Any other value will be ignored, to make sure that malicious apps can't trick the in-call
965 * UI into launching some random other app after a call ends.
966 *
967 * TODO: make this more generic. Note that we should let the "origin" specify its package
968 * while we are now assuming it is "com.android.contacts"
969 */
970 public static final String EXTRA_CALL_ORIGIN = "com.android.phone.CALL_ORIGIN";
971 private static final String DEFAULT_CALL_ORIGIN_PACKAGE = "com.android.dialer";
972 private static final String ALLOWED_EXTRA_CALL_ORIGIN =
973 "com.android.dialer.DialtactsActivity";
974 /**
975 * Used to determine if the preserved call origin is fresh enough.
976 */
977 private static final long CALL_ORIGIN_EXPIRATION_MILLIS = 30 * 1000;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700978}