blob: fcef594f9215d7917cc8889598168398766cf6d6 [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() {
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700515 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubId());
516 }
517
518 /* package */ Bundle getCarrierConfigForSubId(int subId) {
519 return configLoader.getConfigForSubId(subId);
Junda Liu605148f2015-04-28 15:23:40 -0700520 }
521
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700522 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700523 * Returns PendingIntent for hanging up ongoing phone call. This will typically be used from
524 * Notification context.
525 */
526 /* package */ static PendingIntent createHangUpOngoingCallPendingIntent(Context context) {
527 Intent intent = new Intent(PhoneGlobals.ACTION_HANG_UP_ONGOING_CALL, null,
528 context, NotificationBroadcastReceiver.class);
529 return PendingIntent.getBroadcast(context, 0, intent, 0);
530 }
531
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700532 boolean isSimPinEnabled() {
533 return mIsSimPinEnabled;
534 }
535
536 boolean authenticateAgainstCachedSimPin(String pin) {
537 return (mCachedSimPin != null && mCachedSimPin.equals(pin));
538 }
539
540 void setCachedSimPin(String pin) {
541 mCachedSimPin = pin;
542 }
543
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700544 /**
545 * Handles OTASP-related events from the telephony layer.
546 *
547 * While an OTASP call is active, the CallNotifier forwards
548 * OTASP-related telephony events to this method.
549 */
550 void handleOtaspEvent(Message msg) {
551 if (DBG) Log.d(LOG_TAG, "handleOtaspEvent(message " + msg + ")...");
552
553 if (otaUtils == null) {
554 // We shouldn't be getting OTASP events without ever
555 // having started the OTASP call in the first place!
556 Log.w(LOG_TAG, "handleOtaEvents: got an event but otaUtils is null! "
557 + "message = " + msg);
558 return;
559 }
560
561 otaUtils.onOtaProvisionStatusChanged((AsyncResult) msg.obj);
562 }
563
564 /**
565 * Similarly, handle the disconnect event of an OTASP call
566 * by forwarding it to the OtaUtils instance.
567 */
568 /* package */ void handleOtaspDisconnect() {
569 if (DBG) Log.d(LOG_TAG, "handleOtaspDisconnect()...");
570
571 if (otaUtils == null) {
572 // We shouldn't be getting OTASP events without ever
573 // having started the OTASP call in the first place!
574 Log.w(LOG_TAG, "handleOtaspDisconnect: otaUtils is null!");
575 return;
576 }
577
578 otaUtils.onOtaspDisconnect();
579 }
580
581 /**
582 * Sets the activity responsible for un-PUK-blocking the device
583 * so that we may close it when we receive a positive result.
584 * mPUKEntryActivity is also used to indicate to the device that
585 * we are trying to un-PUK-lock the phone. In other words, iff
586 * it is NOT null, then we are trying to unlock and waiting for
587 * the SIM to move to READY state.
588 *
589 * @param activity is the activity to close when PUK has
590 * finished unlocking. Can be set to null to indicate the unlock
591 * or SIM READYing process is over.
592 */
593 void setPukEntryActivity(Activity activity) {
594 mPUKEntryActivity = activity;
595 }
596
597 Activity getPUKEntryActivity() {
598 return mPUKEntryActivity;
599 }
600
601 /**
602 * Sets the dialog responsible for notifying the user of un-PUK-
603 * blocking - SIM READYing progress, so that we may dismiss it
604 * when we receive a positive result.
605 *
606 * @param dialog indicates the progress dialog informing the user
607 * of the state of the device. Dismissed upon completion of
608 * READYing process
609 */
610 void setPukEntryProgressDialog(ProgressDialog dialog) {
611 mPUKEntryProgressDialog = dialog;
612 }
613
614 ProgressDialog getPUKEntryProgressDialog() {
615 return mPUKEntryProgressDialog;
616 }
617
618 /**
619 * Controls whether or not the screen is allowed to sleep.
620 *
621 * Once sleep is allowed (WakeState is SLEEP), it will rely on the
622 * settings for the poke lock to determine when to timeout and let
623 * the device sleep {@link PhoneGlobals#setScreenTimeout}.
624 *
625 * @param ws tells the device to how to wake.
626 */
627 /* package */ void requestWakeState(WakeState ws) {
628 if (VDBG) Log.d(LOG_TAG, "requestWakeState(" + ws + ")...");
629 synchronized (this) {
630 if (mWakeState != ws) {
631 switch (ws) {
632 case PARTIAL:
633 // acquire the processor wake lock, and release the FULL
634 // lock if it is being held.
635 mPartialWakeLock.acquire();
636 if (mWakeLock.isHeld()) {
637 mWakeLock.release();
638 }
639 break;
640 case FULL:
641 // acquire the full wake lock, and release the PARTIAL
642 // lock if it is being held.
643 mWakeLock.acquire();
644 if (mPartialWakeLock.isHeld()) {
645 mPartialWakeLock.release();
646 }
647 break;
648 case SLEEP:
649 default:
650 // release both the PARTIAL and FULL locks.
651 if (mWakeLock.isHeld()) {
652 mWakeLock.release();
653 }
654 if (mPartialWakeLock.isHeld()) {
655 mPartialWakeLock.release();
656 }
657 break;
658 }
659 mWakeState = ws;
660 }
661 }
662 }
663
664 /**
665 * If we are not currently keeping the screen on, then poke the power
666 * manager to wake up the screen for the user activity timeout duration.
667 */
668 /* package */ void wakeUpScreen() {
669 synchronized (this) {
670 if (mWakeState == WakeState.SLEEP) {
671 if (DBG) Log.d(LOG_TAG, "pulse screen lock");
672 mPowerManager.wakeUp(SystemClock.uptimeMillis());
673 }
674 }
675 }
676
677 /**
678 * Sets the wake state and screen timeout based on the current state
679 * of the phone, and the current state of the in-call UI.
680 *
681 * This method is a "UI Policy" wrapper around
682 * {@link PhoneGlobals#requestWakeState} and {@link PhoneGlobals#setScreenTimeout}.
683 *
684 * It's safe to call this method regardless of the state of the Phone
685 * (e.g. whether or not it's idle), and regardless of the state of the
686 * Phone UI (e.g. whether or not the InCallScreen is active.)
687 */
688 /* package */ void updateWakeState() {
689 PhoneConstants.State state = mCM.getState();
690
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700691 // True if the speakerphone is in use. (If so, we *always* use
692 // the default timeout. Since the user is obviously not holding
693 // the phone up to his/her face, we don't need to worry about
694 // false touches, and thus don't need to turn the screen off so
695 // aggressively.)
696 // Note that we need to make a fresh call to this method any
697 // time the speaker state changes. (That happens in
698 // PhoneUtils.turnOnSpeaker().)
699 boolean isSpeakerInUse = (state == PhoneConstants.State.OFFHOOK) && PhoneUtils.isSpeakerOn(this);
700
701 // TODO (bug 1440854): The screen timeout *might* also need to
702 // depend on the bluetooth state, but this isn't as clear-cut as
703 // the speaker state (since while using BT it's common for the
704 // user to put the phone straight into a pocket, in which case the
705 // timeout should probably still be short.)
706
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700707 // Decide whether to force the screen on or not.
708 //
709 // Force the screen to be on if the phone is ringing or dialing,
710 // or if we're displaying the "Call ended" UI for a connection in
711 // the "disconnected" state.
712 // However, if the phone is disconnected while the user is in the
713 // middle of selecting a quick response message, we should not force
714 // the screen to be on.
715 //
716 boolean isRinging = (state == PhoneConstants.State.RINGING);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800717 boolean isDialing = (mCM.getFgPhone().getForegroundCall().getState() == Call.State.DIALING);
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700718 boolean keepScreenOn = isRinging || isDialing;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700719 // keepScreenOn == true means we'll hold a full wake lock:
720 requestWakeState(keepScreenOn ? WakeState.FULL : WakeState.SLEEP);
721 }
722
723 /**
724 * Manually pokes the PowerManager's userActivity method. Since we
725 * set the {@link WindowManager.LayoutParams#INPUT_FEATURE_DISABLE_USER_ACTIVITY}
726 * flag while the InCallScreen is active when there is no proximity sensor,
727 * we need to do this for touch events that really do count as user activity
728 * (like pressing any onscreen UI elements.)
729 */
730 /* package */ void pokeUserActivity() {
731 if (VDBG) Log.d(LOG_TAG, "pokeUserActivity()...");
732 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
733 }
734
735 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700736 * Notifies the phone app when the phone state changes.
737 *
Santos Cordonfc309812013-08-20 18:33:16 -0700738 * This method will updates various states inside Phone app (e.g. update-lock state, etc.)
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700739 */
740 /* package */ void updatePhoneState(PhoneConstants.State state) {
741 if (state != mLastPhoneState) {
742 mLastPhoneState = state;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700743
744 // Try to acquire or release UpdateLock.
745 //
746 // Watch out: we don't release the lock here when the screen is still in foreground.
747 // At that time InCallScreen will release it on onPause().
748 if (state != PhoneConstants.State.IDLE) {
749 // UpdateLock is a recursive lock, while we may get "acquire" request twice and
750 // "release" request once for a single call (RINGING + OFFHOOK and IDLE).
751 // We need to manually ensure the lock is just acquired once for each (and this
752 // will prevent other possible buggy situations too).
753 if (!mUpdateLock.isHeld()) {
754 mUpdateLock.acquire();
755 }
756 } else {
Jay Shraunera5d13212013-09-19 13:37:43 -0700757 if (mUpdateLock.isHeld()) {
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700758 mUpdateLock.release();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700759 }
760 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700761 }
762 }
763
764 /* package */ PhoneConstants.State getPhoneState() {
765 return mLastPhoneState;
766 }
767
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700768 KeyguardManager getKeyguardManager() {
769 return mKeyguardManager;
770 }
771
772 private void onMMIComplete(AsyncResult r) {
773 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
774 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800775 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700776 }
777
Stuart Scottdcf40a92014-12-09 10:45:01 -0800778 private void initForNewRadioTechnology(int phoneId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700779 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
780
Stuart Scottdcf40a92014-12-09 10:45:01 -0800781 final Phone phone = PhoneFactory.getPhone(phoneId);
782
783 if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700784 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
785 cdmaPhoneCallState = new CdmaPhoneCallState();
786 cdmaPhoneCallState.CdmaPhoneCallStateInit();
787 }
Santos Cordon52bc81b2014-10-07 19:55:12 -0700788 if (!TelephonyCapabilities.supportsOtasp(phone)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700789 //Clean up OTA data in GSM/UMTS. It is valid only for CDMA
790 clearOtaState();
791 }
792
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700793 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
794 callStateMonitor.updateAfterRadioTechnologyChange();
795
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700796 // Update registration for ICC status after radio technology change
797 IccCard sim = phone.getIccCard();
798 if (sim != null) {
799 if (DBG) Log.d(LOG_TAG, "Update registration for ICC status...");
800
801 //Register all events new to the new active phone
802 sim.registerForNetworkLocked(mHandler, EVENT_SIM_NETWORK_LOCKED, null);
803 }
804 }
805
Santos Cordon593ab382013-08-06 21:58:23 -0700806 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700807 * Receiver for misc intent broadcasts the Phone app cares about.
808 */
809 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
810 @Override
811 public void onReceive(Context context, Intent intent) {
812 String action = intent.getAction();
813 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
814 boolean enabled = System.getInt(getContentResolver(),
815 System.AIRPLANE_MODE_ON, 0) == 0;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800816 PhoneUtils.setRadioPower(enabled);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700817 } else if (action.equals(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800818 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
819 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
820 int phoneId = SubscriptionManager.getPhoneId(subId);
821 String state = intent.getStringExtra(PhoneConstants.STATE_KEY);
822 if (VDBG) {
823 Log.d(LOG_TAG, "mReceiver: ACTION_ANY_DATA_CONNECTION_STATE_CHANGED");
824 Log.d(LOG_TAG, "- state: " + state);
825 Log.d(LOG_TAG, "- reason: "
826 + intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY));
827 Log.d(LOG_TAG, "- subId: " + subId);
828 Log.d(LOG_TAG, "- phoneId: " + phoneId);
829 }
830 Phone phone = SubscriptionManager.isValidPhoneId(phoneId) ?
831 PhoneFactory.getPhone(phoneId) : PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700832 // The "data disconnected due to roaming" notification is shown
833 // if (a) you have the "data roaming" feature turned off, and
834 // (b) you just lost data connectivity because you're roaming.
835 boolean disconnectedDueToRoaming =
836 !phone.getDataRoamingEnabled()
Stuart Scottdcf40a92014-12-09 10:45:01 -0800837 && PhoneConstants.DataState.DISCONNECTED.equals(state)
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700838 && Phone.REASON_ROAMING_ON.equals(
839 intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY));
Yorke Lee4d2db1c2014-11-06 11:37:09 -0800840 if (mDataDisconnectedDueToRoaming != disconnectedDueToRoaming) {
841 mDataDisconnectedDueToRoaming = disconnectedDueToRoaming;
842 mHandler.sendEmptyMessage(disconnectedDueToRoaming
843 ? EVENT_DATA_ROAMING_DISCONNECTED : EVENT_DATA_ROAMING_OK);
844 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700845 } else if ((action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) &&
846 (mPUKEntryActivity != null)) {
847 // if an attempt to un-PUK-lock the device was made, while we're
848 // receiving this state change notification, notify the handler.
849 // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has
850 // been attempted.
851 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
852 intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE)));
853 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
854 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800855 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
856 SubscriptionManager.INVALID_PHONE_INDEX);
857 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " (" + phoneId
858 + ") is active.");
859 initForNewRadioTechnology(phoneId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700860 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
861 handleServiceStateChanged(intent);
862 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800863 if (TelephonyCapabilities.supportsEcm(mCM.getFgPhone())) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700864 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
865 // Start Emergency Callback Mode service
866 if (intent.getBooleanExtra("phoneinECMState", false)) {
867 context.startService(new Intent(context,
868 EmergencyCallbackModeService.class));
869 }
870 } else {
871 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
872 // on a device that doesn't support ECM in the first place.
873 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, "
Stuart Scottdcf40a92014-12-09 10:45:01 -0800874 + "but ECM isn't supported for phone: "
875 + mCM.getFgPhone().getPhoneName());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700876 }
877 } else if (action.equals(Intent.ACTION_DOCK_EVENT)) {
878 mDockState = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
879 Intent.EXTRA_DOCK_STATE_UNDOCKED);
880 if (VDBG) Log.d(LOG_TAG, "ACTION_DOCK_EVENT -> mDockState = " + mDockState);
881 mHandler.sendMessage(mHandler.obtainMessage(EVENT_DOCK_STATE_CHANGED, 0));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700882 }
883 }
884 }
885
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700886 /**
887 * Accepts broadcast Intents which will be prepared by {@link NotificationMgr} and thus
888 * sent from framework's notification mechanism (which is outside Phone context).
889 * This should be visible from outside, but shouldn't be in "exported" state.
890 *
891 * TODO: If possible merge this into PhoneAppBroadcastReceiver.
892 */
893 public static class NotificationBroadcastReceiver extends BroadcastReceiver {
894 @Override
895 public void onReceive(Context context, Intent intent) {
896 String action = intent.getAction();
897 // TODO: use "if (VDBG)" here.
898 Log.d(LOG_TAG, "Broadcast from Notification: " + action);
899
900 if (action.equals(ACTION_HANG_UP_ONGOING_CALL)) {
901 PhoneUtils.hangup(PhoneGlobals.getInstance().mCM);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700902 } else {
903 Log.w(LOG_TAG, "Received hang-up request from notification,"
904 + " but there's no call the system can hang up.");
905 }
906 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700907 }
908
909 private void handleServiceStateChanged(Intent intent) {
910 /**
911 * This used to handle updating EriTextWidgetProvider this routine
912 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
913 * be removed. But leaving just in case it might be needed in the near
914 * future.
915 */
916
917 // If service just returned, start sending out the queued messages
918 ServiceState ss = ServiceState.newFromBundle(intent.getExtras());
919
920 if (ss != null) {
921 int state = ss.getState();
922 notificationMgr.updateNetworkSelection(state);
923 }
924 }
925
926 public boolean isOtaCallInActiveState() {
927 boolean otaCallActive = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700928 if (VDBG) Log.d(LOG_TAG, "- isOtaCallInActiveState " + otaCallActive);
929 return otaCallActive;
930 }
931
932 public boolean isOtaCallInEndState() {
933 boolean otaCallEnded = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700934 if (VDBG) Log.d(LOG_TAG, "- isOtaCallInEndState " + otaCallEnded);
935 return otaCallEnded;
936 }
937
938 // it is safe to call clearOtaState() even if the InCallScreen isn't active
939 public void clearOtaState() {
940 if (DBG) Log.d(LOG_TAG, "- clearOtaState ...");
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700941 if (otaUtils != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700942 otaUtils.cleanOtaScreen(true);
943 if (DBG) Log.d(LOG_TAG, " - clearOtaState clears OTA screen");
944 }
945 }
946
947 // it is safe to call dismissOtaDialogs() even if the InCallScreen isn't active
948 public void dismissOtaDialogs() {
949 if (DBG) Log.d(LOG_TAG, "- dismissOtaDialogs ...");
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700950 if (otaUtils != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700951 otaUtils.dismissAllOtaDialogs();
952 if (DBG) Log.d(LOG_TAG, " - dismissOtaDialogs clears OTA dialogs");
953 }
954 }
955
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700956 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800957 * Triggers a refresh of the message waiting (voicemail) indicator.
958 *
959 * @param subId the subscription id we should refresh the notification for.
960 */
961 public void refreshMwiIndicator(int subId) {
962 notificationMgr.refreshMwi(subId);
963 }
964
965 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700966 * "Call origin" may be used by Contacts app to specify where the phone call comes from.
967 * Currently, the only permitted value for this extra is {@link #ALLOWED_EXTRA_CALL_ORIGIN}.
968 * Any other value will be ignored, to make sure that malicious apps can't trick the in-call
969 * UI into launching some random other app after a call ends.
970 *
971 * TODO: make this more generic. Note that we should let the "origin" specify its package
972 * while we are now assuming it is "com.android.contacts"
973 */
974 public static final String EXTRA_CALL_ORIGIN = "com.android.phone.CALL_ORIGIN";
975 private static final String DEFAULT_CALL_ORIGIN_PACKAGE = "com.android.dialer";
976 private static final String ALLOWED_EXTRA_CALL_ORIGIN =
977 "com.android.dialer.DialtactsActivity";
978 /**
979 * Used to determine if the preserved call origin is fresh enough.
980 */
981 private static final long CALL_ORIGIN_EXPIRATION_MILLIS = 30 * 1000;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700982}