blob: fc08c5f97248da440f98d052c8c09837630c2e76 [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;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070042import android.os.PersistableBundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.os.PowerManager;
44import android.os.RemoteException;
45import android.os.ServiceManager;
46import android.os.SystemClock;
47import android.os.SystemProperties;
48import android.os.UpdateLock;
49import android.os.UserHandle;
50import android.preference.PreferenceManager;
51import android.provider.Settings.System;
Junda Liu12f7d802015-05-01 12:06:44 -070052import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.telephony.ServiceState;
Andrew Lee2fcb6c32014-12-04 14:52:35 -080054import android.telephony.SubscriptionInfo;
Andrew Lee385019f2014-11-24 14:19:50 -080055import android.telephony.SubscriptionManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.util.Log;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057
58import com.android.internal.telephony.Call;
59import com.android.internal.telephony.CallManager;
60import com.android.internal.telephony.IccCard;
61import com.android.internal.telephony.IccCardConstants;
62import com.android.internal.telephony.MmiCode;
63import com.android.internal.telephony.Phone;
64import com.android.internal.telephony.PhoneConstants;
65import com.android.internal.telephony.PhoneFactory;
Andrew Lee385019f2014-11-24 14:19:50 -080066import com.android.internal.telephony.SubscriptionController;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067import com.android.internal.telephony.TelephonyCapabilities;
68import com.android.internal.telephony.TelephonyIntents;
Santos Cordon352ff652014-05-30 01:41:45 -070069import com.android.phone.common.CallLogAsync;
Andrew Leefb7f92e2015-02-26 16:23:32 -080070import com.android.phone.settings.SettingsConstants;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070071import com.android.server.sip.SipService;
Santos Cordon76aaf482015-04-08 10:58:27 -070072import com.android.services.telephony.activation.SimActivationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073
Andrew Lee385019f2014-11-24 14:19:50 -080074import java.util.ArrayList;
75import java.util.List;
76
Santos Cordon7d4ddf62013-07-10 11:58:08 -070077/**
78 * Global state for the telephony subsystem when running in the primary
79 * phone process.
80 */
Sailesh Nepalbf900542014-07-15 16:18:32 -070081public class PhoneGlobals extends ContextWrapper {
Andrew Lee83383e42014-10-31 12:42:28 -070082 public static final String LOG_TAG = "PhoneApp";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070083
84 /**
85 * Phone app-wide debug level:
86 * 0 - no debug logging
87 * 1 - normal debug logging if ro.debuggable is set (which is true in
88 * "eng" and "userdebug" builds but not "user" builds)
89 * 2 - ultra-verbose debug logging
90 *
91 * Most individual classes in the phone app have a local DBG constant,
92 * typically set to
93 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
94 * or else
95 * (PhoneApp.DBG_LEVEL >= 2)
96 * depending on the desired verbosity.
97 *
98 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
99 */
Andrew Lee88b51e22014-10-29 15:48:51 -0700100 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700101
102 private static final boolean DBG =
103 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
104 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
105
106 // Message codes; see mHandler below.
107 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700108 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700109 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
110 private static final int EVENT_DATA_ROAMING_OK = 11;
111 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 12;
112 private static final int EVENT_DOCK_STATE_CHANGED = 13;
Sailesh Nepalbf900542014-07-15 16:18:32 -0700113 private static final int EVENT_START_SIP_SERVICE = 14;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114
115 // The MMI codes are also used by the InCallScreen.
116 public static final int MMI_INITIATE = 51;
117 public static final int MMI_COMPLETE = 52;
118 public static final int MMI_CANCEL = 53;
119 // Don't use message codes larger than 99 here; those are reserved for
120 // the individual Activities of the Phone UI.
121
122 /**
123 * Allowable values for the wake lock code.
124 * SLEEP means the device can be put to sleep.
125 * PARTIAL means wake the processor, but we display can be kept off.
126 * FULL means wake both the processor and the display.
127 */
128 public enum WakeState {
129 SLEEP,
130 PARTIAL,
131 FULL
132 }
133
134 /**
135 * Intent Action used for hanging up the current call from Notification bar. This will
136 * choose first ringing call, first active call, or first background call (typically in
137 * HOLDING state).
138 */
139 public static final String ACTION_HANG_UP_ONGOING_CALL =
140 "com.android.phone.ACTION_HANG_UP_ONGOING_CALL";
141
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142 private static PhoneGlobals sMe;
143
144 // A few important fields we expose to the rest of the package
145 // directly (rather than thru set/get methods) for efficiency.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700146 CallController callController;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700147 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700148 CallNotifier notifier;
149 CallerInfoCache callerInfoCache;
Santos Cordon63a84242013-07-23 13:32:52 -0700150 NotificationMgr notificationMgr;
Andrew Lee9431b832015-03-09 18:46:45 -0700151 public PhoneInterfaceManager phoneMgr;
Santos Cordon76aaf482015-04-08 10:58:27 -0700152 public SimActivationManager simActivationManager;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800153 CarrierConfigLoader configLoader;
Santos Cordon63a84242013-07-23 13:32:52 -0700154
Santos Cordon27a3c1f2013-08-06 07:49:27 -0700155 private BluetoothManager bluetoothManager;
Santos Cordon69a69192013-08-22 14:25:42 -0700156 private CallGatewayManager callGatewayManager;
Santos Cordon63a84242013-07-23 13:32:52 -0700157 private CallStateMonitor callStateMonitor;
Santos Cordon63a84242013-07-23 13:32:52 -0700158
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159 static int mDockState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
160 static boolean sVoiceCapable = true;
161
Santos Cordonc593d002015-06-03 15:41:15 -0700162 // TODO: Remove, no longer used.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700163 CdmaPhoneCallState cdmaPhoneCallState;
164
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165 // The currently-active PUK entry activity and progress dialog.
166 // Normally, these are the Emergency Dialer and the subsequent
167 // progress dialog. null if there is are no such objects in
168 // the foreground.
169 private Activity mPUKEntryActivity;
170 private ProgressDialog mPUKEntryProgressDialog;
171
172 private boolean mIsSimPinEnabled;
173 private String mCachedSimPin;
174
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700175 // True if we are beginning a call, but the phone state has not changed yet
176 private boolean mBeginningCall;
Yorke Lee4d2db1c2014-11-06 11:37:09 -0800177 private boolean mDataDisconnectedDueToRoaming = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700178
179 // Last phone state seen by updatePhoneState()
180 private PhoneConstants.State mLastPhoneState = PhoneConstants.State.IDLE;
181
182 private WakeState mWakeState = WakeState.SLEEP;
183
184 private PowerManager mPowerManager;
185 private IPowerManager mPowerManagerService;
186 private PowerManager.WakeLock mWakeLock;
187 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700188 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700189
190 private UpdateLock mUpdateLock;
191
192 // Broadcast receiver for various intent broadcasts (see onCreate())
193 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
194
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195 /** boolean indicating restoring mute state on InCallScreen.onResume() */
196 private boolean mShouldRestoreMuteOnInCallResume;
197
198 /**
199 * The singleton OtaUtils instance used for OTASP calls.
200 *
201 * The OtaUtils instance is created lazily the first time we need to
202 * make an OTASP call, regardless of whether it's an interactive or
203 * non-interactive OTASP call.
204 */
205 public OtaUtils otaUtils;
206
207 // Following are the CDMA OTA information Objects used during OTA Call.
208 // cdmaOtaProvisionData object store static OTA information that needs
209 // to be maintained even during Slider open/close scenarios.
210 // cdmaOtaConfigData object stores configuration info to control visiblity
211 // of each OTA Screens.
212 // cdmaOtaScreenState object store OTA Screen State information.
213 public OtaUtils.CdmaOtaProvisionData cdmaOtaProvisionData;
214 public OtaUtils.CdmaOtaConfigData cdmaOtaConfigData;
215 public OtaUtils.CdmaOtaScreenState cdmaOtaScreenState;
216 public OtaUtils.CdmaOtaInCallScreenUiState cdmaOtaInCallScreenUiState;
217
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700218 /**
219 * Set the restore mute state flag. Used when we are setting the mute state
220 * OUTSIDE of user interaction {@link PhoneUtils#startNewCall(Phone)}
221 */
222 /*package*/void setRestoreMuteOnInCallResume (boolean mode) {
223 mShouldRestoreMuteOnInCallResume = mode;
224 }
225
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700226 Handler mHandler = new Handler() {
227 @Override
228 public void handleMessage(Message msg) {
229 PhoneConstants.State phoneState;
230 switch (msg.what) {
231 // Starts the SIP service. It's a no-op if SIP API is not supported
232 // on the deivce.
233 // TODO: Having the phone process host the SIP service is only
234 // temporary. Will move it to a persistent communication process
235 // later.
236 case EVENT_START_SIP_SERVICE:
237 SipService.start(getApplicationContext());
238 break;
239
240 // TODO: This event should be handled by the lock screen, just
241 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
242 case EVENT_SIM_NETWORK_LOCKED:
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700243 if (getCarrierConfig().getBoolean(
244 CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700245 // Some products don't have the concept of a "SIM network lock"
246 Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; "
247 + "not showing 'SIM network unlock' PIN entry screen");
248 } else {
249 // Normal case: show the "SIM network unlock" PIN entry screen.
250 // The user won't be able to do anything else until
251 // they enter a valid SIM network PIN.
252 Log.i(LOG_TAG, "show sim depersonal panel");
Tyler Gunn52a37072015-08-24 14:23:19 -0700253 IccNetworkDepersonalizationPanel.showDialog();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700254 }
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 for (Phone phone : PhoneFactory.getPhones()) {
346 mCM.registerPhone(phone);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800347 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348
349 // Create the NotificationMgr singleton, which is used to display
350 // status bar icons and control other status bar behavior.
351 notificationMgr = NotificationMgr.init(this);
352
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700353 mHandler.sendEmptyMessage(EVENT_START_SIP_SERVICE);
354
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700355 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
356 cdmaPhoneCallState = new CdmaPhoneCallState();
357 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359 // before registering for phone state changes
360 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
361 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
362 // lock used to keep the processor awake, when we don't care for the display.
363 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
364 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365
366 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
367
368 // get a handle to the service so that we can use it later when we
369 // want to set the poke lock.
370 mPowerManagerService = IPowerManager.Stub.asInterface(
371 ServiceManager.getService("power"));
372
373 // Get UpdateLock to suppress system-update related events (e.g. dialog show-up)
374 // during phone calls.
375 mUpdateLock = new UpdateLock("phone");
376
377 if (DBG) Log.d(LOG_TAG, "onCreate: mUpdateLock: " + mUpdateLock);
378
379 CallLogger callLogger = new CallLogger(this, new CallLogAsync());
380
Jay Shrauner21a75342013-11-25 16:14:43 -0800381 callGatewayManager = CallGatewayManager.getInstance();
Santos Cordon69a69192013-08-22 14:25:42 -0700382
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383 // Create the CallController singleton, which is the interface
384 // to the telephony layer for user-initiated telephony functionality
385 // (like making outgoing calls.)
Santos Cordon69a69192013-08-22 14:25:42 -0700386 callController = CallController.init(this, callLogger, callGatewayManager);
387
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388 // Create the CallerInfoCache singleton, which remembers custom ring tone and
389 // send-to-voicemail settings.
390 //
391 // The asynchronous caching will start just after this call.
392 callerInfoCache = CallerInfoCache.init(this);
393
394 // Monitors call activity from the telephony layer
395 callStateMonitor = new CallStateMonitor(mCM);
396
Santos Cordon2c2d3cf2013-08-08 03:53:47 -0700397 // Bluetooth manager
Sailesh Nepal23d9ed72014-07-03 09:40:26 -0700398 bluetoothManager = new BluetoothManager();
Santos Cordon2c2d3cf2013-08-08 03:53:47 -0700399
Stuart Scottdcf40a92014-12-09 10:45:01 -0800400 phoneMgr = PhoneInterfaceManager.init(this, PhoneFactory.getDefaultPhone());
Santos Cordon406c0342013-08-28 00:07:47 -0700401
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800402 configLoader = CarrierConfigLoader.init(this);
403
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700404 // Create the CallNotifer singleton, which handles
405 // asynchronous events from the telephony layer (like
406 // launching the incoming-call UI when an incoming call comes
407 // in.)
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800408 notifier = CallNotifier.init(this, callLogger, callStateMonitor, bluetoothManager);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409
Stuart Scottdcf40a92014-12-09 10:45:01 -0800410 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700411
412 // register for MMI/USSD
413 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
414
415 // register connection tracking to PhoneUtils
416 PhoneUtils.initializeConnectionHandler(mCM);
417
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700418 // Register for misc other intent broadcasts.
419 IntentFilter intentFilter =
420 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700421 intentFilter.addAction(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700422 intentFilter.addAction(Intent.ACTION_DOCK_EVENT);
423 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
424 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
425 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
426 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427 registerReceiver(mReceiver, intentFilter);
428
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700429 //set the default values for the preferences in the phone.
430 PreferenceManager.setDefaultValues(this, R.xml.network_setting, false);
431
432 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
433
434 // Make sure the audio mode (along with some
435 // audio-mode-related state of our own) is initialized
436 // correctly, given the current state of the phone.
437 PhoneUtils.setAudioMode(mCM);
438 }
439
Santos Cordon52bc81b2014-10-07 19:55:12 -0700440 cdmaOtaProvisionData = new OtaUtils.CdmaOtaProvisionData();
441 cdmaOtaConfigData = new OtaUtils.CdmaOtaConfigData();
442 cdmaOtaScreenState = new OtaUtils.CdmaOtaScreenState();
443 cdmaOtaInCallScreenUiState = new OtaUtils.CdmaOtaInCallScreenUiState();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444
Santos Cordon76aaf482015-04-08 10:58:27 -0700445 simActivationManager = new SimActivationManager();
446
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700447 // XXX pre-load the SimProvider so that it's ready
448 resolver.getType(Uri.parse("content://icc/adn"));
449
450 // start with the default value to set the mute state.
451 mShouldRestoreMuteOnInCallResume = false;
452
453 // TODO: Register for Cdma Information Records
454 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
455
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700456 // Read HAC settings and configure audio hardware
457 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800458 int hac = android.provider.Settings.System.getInt(
459 getContentResolver(),
460 android.provider.Settings.System.HEARING_AID,
461 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700462 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Andrew Leefb7f92e2015-02-26 16:23:32 -0800463 audioManager.setParameter(SettingsConstants.HAC_KEY,
464 hac == SettingsConstants.HAC_ENABLED
465 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700466 }
Santos Cordonff506f52013-11-21 19:13:19 -0800467 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700468
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700469 /**
470 * Returns the singleton instance of the PhoneApp.
471 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800472 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700473 if (sMe == null) {
474 throw new IllegalStateException("No PhoneGlobals here!");
475 }
476 return sMe;
477 }
478
479 /**
480 * Returns the singleton instance of the PhoneApp if running as the
481 * primary user, otherwise null.
482 */
483 static PhoneGlobals getInstanceIfPrimary() {
484 return sMe;
485 }
486
487 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800488 * Returns the default phone.
489 *
Andrew Lee385019f2014-11-24 14:19:50 -0800490 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700491 */
Andrew Lee83383e42014-10-31 12:42:28 -0700492 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800493 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700494 }
495
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800496 public static Phone getPhone(int subId) {
497 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800498 }
499
Santos Cordon27a3c1f2013-08-06 07:49:27 -0700500 /* package */ BluetoothManager getBluetoothManager() {
501 return bluetoothManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700502 }
503
Santos Cordonde10b752013-09-19 04:11:33 -0700504 /* package */ CallManager getCallManager() {
505 return mCM;
506 }
507
Chris Manton4e9fa912015-06-19 11:26:57 -0700508 public PersistableBundle getCarrierConfig() {
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700509 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubId());
510 }
511
Chris Manton4e9fa912015-06-19 11:26:57 -0700512 public PersistableBundle getCarrierConfigForSubId(int subId) {
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700513 return configLoader.getConfigForSubId(subId);
Junda Liu605148f2015-04-28 15:23:40 -0700514 }
515
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700516 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700517 * Returns PendingIntent for hanging up ongoing phone call. This will typically be used from
518 * Notification context.
519 */
520 /* package */ static PendingIntent createHangUpOngoingCallPendingIntent(Context context) {
521 Intent intent = new Intent(PhoneGlobals.ACTION_HANG_UP_ONGOING_CALL, null,
522 context, NotificationBroadcastReceiver.class);
523 return PendingIntent.getBroadcast(context, 0, intent, 0);
524 }
525
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700526 boolean isSimPinEnabled() {
527 return mIsSimPinEnabled;
528 }
529
530 boolean authenticateAgainstCachedSimPin(String pin) {
531 return (mCachedSimPin != null && mCachedSimPin.equals(pin));
532 }
533
534 void setCachedSimPin(String pin) {
535 mCachedSimPin = pin;
536 }
537
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700538 /**
539 * Handles OTASP-related events from the telephony layer.
540 *
541 * While an OTASP call is active, the CallNotifier forwards
542 * OTASP-related telephony events to this method.
543 */
544 void handleOtaspEvent(Message msg) {
545 if (DBG) Log.d(LOG_TAG, "handleOtaspEvent(message " + msg + ")...");
546
547 if (otaUtils == null) {
548 // We shouldn't be getting OTASP events without ever
549 // having started the OTASP call in the first place!
550 Log.w(LOG_TAG, "handleOtaEvents: got an event but otaUtils is null! "
551 + "message = " + msg);
552 return;
553 }
554
555 otaUtils.onOtaProvisionStatusChanged((AsyncResult) msg.obj);
556 }
557
558 /**
559 * Similarly, handle the disconnect event of an OTASP call
560 * by forwarding it to the OtaUtils instance.
561 */
562 /* package */ void handleOtaspDisconnect() {
563 if (DBG) Log.d(LOG_TAG, "handleOtaspDisconnect()...");
564
565 if (otaUtils == null) {
566 // We shouldn't be getting OTASP events without ever
567 // having started the OTASP call in the first place!
568 Log.w(LOG_TAG, "handleOtaspDisconnect: otaUtils is null!");
569 return;
570 }
571
572 otaUtils.onOtaspDisconnect();
573 }
574
575 /**
576 * Sets the activity responsible for un-PUK-blocking the device
577 * so that we may close it when we receive a positive result.
578 * mPUKEntryActivity is also used to indicate to the device that
579 * we are trying to un-PUK-lock the phone. In other words, iff
580 * it is NOT null, then we are trying to unlock and waiting for
581 * the SIM to move to READY state.
582 *
583 * @param activity is the activity to close when PUK has
584 * finished unlocking. Can be set to null to indicate the unlock
585 * or SIM READYing process is over.
586 */
587 void setPukEntryActivity(Activity activity) {
588 mPUKEntryActivity = activity;
589 }
590
591 Activity getPUKEntryActivity() {
592 return mPUKEntryActivity;
593 }
594
595 /**
596 * Sets the dialog responsible for notifying the user of un-PUK-
597 * blocking - SIM READYing progress, so that we may dismiss it
598 * when we receive a positive result.
599 *
600 * @param dialog indicates the progress dialog informing the user
601 * of the state of the device. Dismissed upon completion of
602 * READYing process
603 */
604 void setPukEntryProgressDialog(ProgressDialog dialog) {
605 mPUKEntryProgressDialog = dialog;
606 }
607
608 ProgressDialog getPUKEntryProgressDialog() {
609 return mPUKEntryProgressDialog;
610 }
611
612 /**
613 * Controls whether or not the screen is allowed to sleep.
614 *
615 * Once sleep is allowed (WakeState is SLEEP), it will rely on the
616 * settings for the poke lock to determine when to timeout and let
617 * the device sleep {@link PhoneGlobals#setScreenTimeout}.
618 *
619 * @param ws tells the device to how to wake.
620 */
621 /* package */ void requestWakeState(WakeState ws) {
622 if (VDBG) Log.d(LOG_TAG, "requestWakeState(" + ws + ")...");
623 synchronized (this) {
624 if (mWakeState != ws) {
625 switch (ws) {
626 case PARTIAL:
627 // acquire the processor wake lock, and release the FULL
628 // lock if it is being held.
629 mPartialWakeLock.acquire();
630 if (mWakeLock.isHeld()) {
631 mWakeLock.release();
632 }
633 break;
634 case FULL:
635 // acquire the full wake lock, and release the PARTIAL
636 // lock if it is being held.
637 mWakeLock.acquire();
638 if (mPartialWakeLock.isHeld()) {
639 mPartialWakeLock.release();
640 }
641 break;
642 case SLEEP:
643 default:
644 // release both the PARTIAL and FULL locks.
645 if (mWakeLock.isHeld()) {
646 mWakeLock.release();
647 }
648 if (mPartialWakeLock.isHeld()) {
649 mPartialWakeLock.release();
650 }
651 break;
652 }
653 mWakeState = ws;
654 }
655 }
656 }
657
658 /**
659 * If we are not currently keeping the screen on, then poke the power
660 * manager to wake up the screen for the user activity timeout duration.
661 */
662 /* package */ void wakeUpScreen() {
663 synchronized (this) {
664 if (mWakeState == WakeState.SLEEP) {
665 if (DBG) Log.d(LOG_TAG, "pulse screen lock");
Dianne Hackborn148769b2015-07-13 17:55:47 -0700666 mPowerManager.wakeUp(SystemClock.uptimeMillis(), "android.phone:WAKE");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700667 }
668 }
669 }
670
671 /**
672 * Sets the wake state and screen timeout based on the current state
673 * of the phone, and the current state of the in-call UI.
674 *
675 * This method is a "UI Policy" wrapper around
676 * {@link PhoneGlobals#requestWakeState} and {@link PhoneGlobals#setScreenTimeout}.
677 *
678 * It's safe to call this method regardless of the state of the Phone
679 * (e.g. whether or not it's idle), and regardless of the state of the
680 * Phone UI (e.g. whether or not the InCallScreen is active.)
681 */
682 /* package */ void updateWakeState() {
683 PhoneConstants.State state = mCM.getState();
684
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700685 // True if the speakerphone is in use. (If so, we *always* use
686 // the default timeout. Since the user is obviously not holding
687 // the phone up to his/her face, we don't need to worry about
688 // false touches, and thus don't need to turn the screen off so
689 // aggressively.)
690 // Note that we need to make a fresh call to this method any
691 // time the speaker state changes. (That happens in
692 // PhoneUtils.turnOnSpeaker().)
693 boolean isSpeakerInUse = (state == PhoneConstants.State.OFFHOOK) && PhoneUtils.isSpeakerOn(this);
694
695 // TODO (bug 1440854): The screen timeout *might* also need to
696 // depend on the bluetooth state, but this isn't as clear-cut as
697 // the speaker state (since while using BT it's common for the
698 // user to put the phone straight into a pocket, in which case the
699 // timeout should probably still be short.)
700
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700701 // Decide whether to force the screen on or not.
702 //
703 // Force the screen to be on if the phone is ringing or dialing,
704 // or if we're displaying the "Call ended" UI for a connection in
705 // the "disconnected" state.
706 // However, if the phone is disconnected while the user is in the
707 // middle of selecting a quick response message, we should not force
708 // the screen to be on.
709 //
710 boolean isRinging = (state == PhoneConstants.State.RINGING);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800711 boolean isDialing = (mCM.getFgPhone().getForegroundCall().getState() == Call.State.DIALING);
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700712 boolean keepScreenOn = isRinging || isDialing;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700713 // keepScreenOn == true means we'll hold a full wake lock:
714 requestWakeState(keepScreenOn ? WakeState.FULL : WakeState.SLEEP);
715 }
716
717 /**
718 * Manually pokes the PowerManager's userActivity method. Since we
719 * set the {@link WindowManager.LayoutParams#INPUT_FEATURE_DISABLE_USER_ACTIVITY}
720 * flag while the InCallScreen is active when there is no proximity sensor,
721 * we need to do this for touch events that really do count as user activity
722 * (like pressing any onscreen UI elements.)
723 */
724 /* package */ void pokeUserActivity() {
725 if (VDBG) Log.d(LOG_TAG, "pokeUserActivity()...");
726 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
727 }
728
729 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700730 * Notifies the phone app when the phone state changes.
731 *
Santos Cordonfc309812013-08-20 18:33:16 -0700732 * This method will updates various states inside Phone app (e.g. update-lock state, etc.)
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700733 */
734 /* package */ void updatePhoneState(PhoneConstants.State state) {
735 if (state != mLastPhoneState) {
736 mLastPhoneState = state;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700737
738 // Try to acquire or release UpdateLock.
739 //
740 // Watch out: we don't release the lock here when the screen is still in foreground.
741 // At that time InCallScreen will release it on onPause().
742 if (state != PhoneConstants.State.IDLE) {
743 // UpdateLock is a recursive lock, while we may get "acquire" request twice and
744 // "release" request once for a single call (RINGING + OFFHOOK and IDLE).
745 // We need to manually ensure the lock is just acquired once for each (and this
746 // will prevent other possible buggy situations too).
747 if (!mUpdateLock.isHeld()) {
748 mUpdateLock.acquire();
749 }
750 } else {
Jay Shraunera5d13212013-09-19 13:37:43 -0700751 if (mUpdateLock.isHeld()) {
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700752 mUpdateLock.release();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700753 }
754 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700755 }
756 }
757
758 /* package */ PhoneConstants.State getPhoneState() {
759 return mLastPhoneState;
760 }
761
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700762 KeyguardManager getKeyguardManager() {
763 return mKeyguardManager;
764 }
765
766 private void onMMIComplete(AsyncResult r) {
767 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
768 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800769 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700770 }
771
Stuart Scottdcf40a92014-12-09 10:45:01 -0800772 private void initForNewRadioTechnology(int phoneId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700773 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
774
Stuart Scottdcf40a92014-12-09 10:45:01 -0800775 final Phone phone = PhoneFactory.getPhone(phoneId);
Santos Cordonc593d002015-06-03 15:41:15 -0700776 if (phone == null || !TelephonyCapabilities.supportsOtasp(phone)) {
777 // Clean up OTA for non-CDMA since it is only valid for CDMA.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700778 clearOtaState();
779 }
780
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700781 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
782 callStateMonitor.updateAfterRadioTechnologyChange();
783
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700784 // Update registration for ICC status after radio technology change
Santos Cordonc593d002015-06-03 15:41:15 -0700785 IccCard sim = phone == null ? null : phone.getIccCard();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700786 if (sim != null) {
787 if (DBG) Log.d(LOG_TAG, "Update registration for ICC status...");
788
789 //Register all events new to the new active phone
790 sim.registerForNetworkLocked(mHandler, EVENT_SIM_NETWORK_LOCKED, null);
791 }
792 }
793
Santos Cordon593ab382013-08-06 21:58:23 -0700794 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700795 * Receiver for misc intent broadcasts the Phone app cares about.
796 */
797 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
798 @Override
799 public void onReceive(Context context, Intent intent) {
800 String action = intent.getAction();
801 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
802 boolean enabled = System.getInt(getContentResolver(),
803 System.AIRPLANE_MODE_ON, 0) == 0;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800804 PhoneUtils.setRadioPower(enabled);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700805 } else if (action.equals(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800806 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
807 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
808 int phoneId = SubscriptionManager.getPhoneId(subId);
809 String state = intent.getStringExtra(PhoneConstants.STATE_KEY);
810 if (VDBG) {
811 Log.d(LOG_TAG, "mReceiver: ACTION_ANY_DATA_CONNECTION_STATE_CHANGED");
812 Log.d(LOG_TAG, "- state: " + state);
813 Log.d(LOG_TAG, "- reason: "
814 + intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY));
815 Log.d(LOG_TAG, "- subId: " + subId);
816 Log.d(LOG_TAG, "- phoneId: " + phoneId);
817 }
818 Phone phone = SubscriptionManager.isValidPhoneId(phoneId) ?
819 PhoneFactory.getPhone(phoneId) : PhoneFactory.getDefaultPhone();
Santos Cordonc593d002015-06-03 15:41:15 -0700820
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700821 // The "data disconnected due to roaming" notification is shown
822 // if (a) you have the "data roaming" feature turned off, and
823 // (b) you just lost data connectivity because you're roaming.
824 boolean disconnectedDueToRoaming =
825 !phone.getDataRoamingEnabled()
Stuart Scottdcf40a92014-12-09 10:45:01 -0800826 && PhoneConstants.DataState.DISCONNECTED.equals(state)
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700827 && Phone.REASON_ROAMING_ON.equals(
828 intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY));
Yorke Lee4d2db1c2014-11-06 11:37:09 -0800829 if (mDataDisconnectedDueToRoaming != disconnectedDueToRoaming) {
830 mDataDisconnectedDueToRoaming = disconnectedDueToRoaming;
831 mHandler.sendEmptyMessage(disconnectedDueToRoaming
832 ? EVENT_DATA_ROAMING_DISCONNECTED : EVENT_DATA_ROAMING_OK);
833 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700834 } else if ((action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) &&
835 (mPUKEntryActivity != null)) {
836 // if an attempt to un-PUK-lock the device was made, while we're
837 // receiving this state change notification, notify the handler.
838 // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has
839 // been attempted.
840 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
841 intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE)));
842 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
843 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800844 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
845 SubscriptionManager.INVALID_PHONE_INDEX);
846 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " (" + phoneId
847 + ") is active.");
848 initForNewRadioTechnology(phoneId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700849 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
850 handleServiceStateChanged(intent);
851 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800852 if (TelephonyCapabilities.supportsEcm(mCM.getFgPhone())) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700853 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
854 // Start Emergency Callback Mode service
855 if (intent.getBooleanExtra("phoneinECMState", false)) {
856 context.startService(new Intent(context,
857 EmergencyCallbackModeService.class));
858 }
859 } else {
860 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
861 // on a device that doesn't support ECM in the first place.
862 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, "
Stuart Scottdcf40a92014-12-09 10:45:01 -0800863 + "but ECM isn't supported for phone: "
864 + mCM.getFgPhone().getPhoneName());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700865 }
866 } else if (action.equals(Intent.ACTION_DOCK_EVENT)) {
867 mDockState = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
868 Intent.EXTRA_DOCK_STATE_UNDOCKED);
869 if (VDBG) Log.d(LOG_TAG, "ACTION_DOCK_EVENT -> mDockState = " + mDockState);
870 mHandler.sendMessage(mHandler.obtainMessage(EVENT_DOCK_STATE_CHANGED, 0));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700871 }
872 }
873 }
874
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700875 /**
876 * Accepts broadcast Intents which will be prepared by {@link NotificationMgr} and thus
877 * sent from framework's notification mechanism (which is outside Phone context).
878 * This should be visible from outside, but shouldn't be in "exported" state.
879 *
880 * TODO: If possible merge this into PhoneAppBroadcastReceiver.
881 */
882 public static class NotificationBroadcastReceiver extends BroadcastReceiver {
883 @Override
884 public void onReceive(Context context, Intent intent) {
885 String action = intent.getAction();
886 // TODO: use "if (VDBG)" here.
887 Log.d(LOG_TAG, "Broadcast from Notification: " + action);
888
889 if (action.equals(ACTION_HANG_UP_ONGOING_CALL)) {
890 PhoneUtils.hangup(PhoneGlobals.getInstance().mCM);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700891 } else {
892 Log.w(LOG_TAG, "Received hang-up request from notification,"
893 + " but there's no call the system can hang up.");
894 }
895 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700896 }
897
898 private void handleServiceStateChanged(Intent intent) {
899 /**
900 * This used to handle updating EriTextWidgetProvider this routine
901 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
902 * be removed. But leaving just in case it might be needed in the near
903 * future.
904 */
905
906 // If service just returned, start sending out the queued messages
Santos Cordonc593d002015-06-03 15:41:15 -0700907 Bundle extras = intent.getExtras();
908 if (extras != null) {
909 ServiceState ss = ServiceState.newFromBundle(extras);
910 if (ss != null) {
911 int state = ss.getState();
912 notificationMgr.updateNetworkSelection(state);
913 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700914 }
915 }
916
917 public boolean isOtaCallInActiveState() {
918 boolean otaCallActive = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700919 if (VDBG) Log.d(LOG_TAG, "- isOtaCallInActiveState " + otaCallActive);
920 return otaCallActive;
921 }
922
923 public boolean isOtaCallInEndState() {
924 boolean otaCallEnded = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700925 if (VDBG) Log.d(LOG_TAG, "- isOtaCallInEndState " + otaCallEnded);
926 return otaCallEnded;
927 }
928
929 // it is safe to call clearOtaState() even if the InCallScreen isn't active
930 public void clearOtaState() {
931 if (DBG) Log.d(LOG_TAG, "- clearOtaState ...");
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700932 if (otaUtils != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700933 otaUtils.cleanOtaScreen(true);
934 if (DBG) Log.d(LOG_TAG, " - clearOtaState clears OTA screen");
935 }
936 }
937
938 // it is safe to call dismissOtaDialogs() even if the InCallScreen isn't active
939 public void dismissOtaDialogs() {
940 if (DBG) Log.d(LOG_TAG, "- dismissOtaDialogs ...");
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700941 if (otaUtils != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700942 otaUtils.dismissAllOtaDialogs();
943 if (DBG) Log.d(LOG_TAG, " - dismissOtaDialogs clears OTA dialogs");
944 }
945 }
946
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700947 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800948 * Triggers a refresh of the message waiting (voicemail) indicator.
949 *
950 * @param subId the subscription id we should refresh the notification for.
951 */
952 public void refreshMwiIndicator(int subId) {
953 notificationMgr.refreshMwi(subId);
954 }
955
956 /**
Nancy Chenbb49d412015-07-23 13:54:16 -0700957 * Dismisses the message waiting (voicemail) indicator.
958 *
959 * @param subId the subscription id we should dismiss the notification for.
960 */
961 public void clearMwiIndicator(int subId) {
962 notificationMgr.updateMwi(subId, false);
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}