blob: 315929bb4627cfd46403b6b10155eb8f8e73a854 [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");
253 IccNetworkDepersonalizationPanel ndpPanel =
254 new IccNetworkDepersonalizationPanel(PhoneGlobals.getInstance());
255 ndpPanel.show();
256 }
257 break;
258
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700259 case EVENT_DATA_ROAMING_DISCONNECTED:
260 notificationMgr.showDataDisconnectedRoaming();
261 break;
262
263 case EVENT_DATA_ROAMING_OK:
264 notificationMgr.hideDataDisconnectedRoaming();
265 break;
266
267 case MMI_COMPLETE:
268 onMMIComplete((AsyncResult) msg.obj);
269 break;
270
271 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800272 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700273 break;
274
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275 case EVENT_SIM_STATE_CHANGED:
276 // Marks the event where the SIM goes into ready state.
277 // Right now, this is only used for the PUK-unlocking
278 // process.
279 if (msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_READY)) {
280 // when the right event is triggered and there
281 // are UI objects in the foreground, we close
282 // them to display the lock panel.
283 if (mPUKEntryActivity != null) {
284 mPUKEntryActivity.finish();
285 mPUKEntryActivity = null;
286 }
287 if (mPUKEntryProgressDialog != null) {
288 mPUKEntryProgressDialog.dismiss();
289 mPUKEntryProgressDialog = null;
290 }
291 }
292 break;
293
294 case EVENT_UNSOL_CDMA_INFO_RECORD:
295 //TODO: handle message here;
296 break;
297
298 case EVENT_DOCK_STATE_CHANGED:
299 // If the phone is docked/undocked during a call, and no wired or BT headset
300 // is connected: turn on/off the speaker accordingly.
301 boolean inDockMode = false;
302 if (mDockState != Intent.EXTRA_DOCK_STATE_UNDOCKED) {
303 inDockMode = true;
304 }
305 if (VDBG) Log.d(LOG_TAG, "received EVENT_DOCK_STATE_CHANGED. Phone inDock = "
306 + inDockMode);
307
308 phoneState = mCM.getState();
309 if (phoneState == PhoneConstants.State.OFFHOOK &&
Santos Cordon593ab382013-08-06 21:58:23 -0700310 !bluetoothManager.isBluetoothHeadsetAudioOn()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700311 PhoneUtils.turnOnSpeaker(getApplicationContext(), inDockMode, true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700312 }
313 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700314 }
315 }
316 };
317
318 public PhoneGlobals(Context context) {
319 super(context);
320 sMe = this;
321 }
322
323 public void onCreate() {
324 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
325
326 ContentResolver resolver = getContentResolver();
327
328 // Cache the "voice capable" flag.
329 // This flag currently comes from a resource (which is
330 // overrideable on a per-product basis):
331 sVoiceCapable =
332 getResources().getBoolean(com.android.internal.R.bool.config_voice_capable);
333 // ...but this might eventually become a PackageManager "system
334 // feature" instead, in which case we'd do something like:
335 // sVoiceCapable =
336 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
337
Stuart Scottdcf40a92014-12-09 10:45:01 -0800338 if (mCM == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700339 // Initialize the telephony framework
340 PhoneFactory.makeDefaultPhones(this);
341
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342 // Start TelephonyDebugService After the default phone is created.
343 Intent intent = new Intent(this, TelephonyDebugService.class);
344 startService(intent);
345
346 mCM = CallManager.getInstance();
Stuart Scottdcf40a92014-12-09 10:45:01 -0800347 for (Phone phone : PhoneFactory.getPhones()) {
348 mCM.registerPhone(phone);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800349 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350
351 // Create the NotificationMgr singleton, which is used to display
352 // status bar icons and control other status bar behavior.
353 notificationMgr = NotificationMgr.init(this);
354
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355 mHandler.sendEmptyMessage(EVENT_START_SIP_SERVICE);
356
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700357 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
358 cdmaPhoneCallState = new CdmaPhoneCallState();
359 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361 // before registering for phone state changes
362 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
363 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
364 // lock used to keep the processor awake, when we don't care for the display.
365 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
366 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367
368 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
369
370 // get a handle to the service so that we can use it later when we
371 // want to set the poke lock.
372 mPowerManagerService = IPowerManager.Stub.asInterface(
373 ServiceManager.getService("power"));
374
375 // Get UpdateLock to suppress system-update related events (e.g. dialog show-up)
376 // during phone calls.
377 mUpdateLock = new UpdateLock("phone");
378
379 if (DBG) Log.d(LOG_TAG, "onCreate: mUpdateLock: " + mUpdateLock);
380
381 CallLogger callLogger = new CallLogger(this, new CallLogAsync());
382
Jay Shrauner21a75342013-11-25 16:14:43 -0800383 callGatewayManager = CallGatewayManager.getInstance();
Santos Cordon69a69192013-08-22 14:25:42 -0700384
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700385 // Create the CallController singleton, which is the interface
386 // to the telephony layer for user-initiated telephony functionality
387 // (like making outgoing calls.)
Santos Cordon69a69192013-08-22 14:25:42 -0700388 callController = CallController.init(this, callLogger, callGatewayManager);
389
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700390 // Create the CallerInfoCache singleton, which remembers custom ring tone and
391 // send-to-voicemail settings.
392 //
393 // The asynchronous caching will start just after this call.
394 callerInfoCache = CallerInfoCache.init(this);
395
396 // Monitors call activity from the telephony layer
397 callStateMonitor = new CallStateMonitor(mCM);
398
Santos Cordon2c2d3cf2013-08-08 03:53:47 -0700399 // Bluetooth manager
Sailesh Nepal23d9ed72014-07-03 09:40:26 -0700400 bluetoothManager = new BluetoothManager();
Santos Cordon2c2d3cf2013-08-08 03:53:47 -0700401
Stuart Scottdcf40a92014-12-09 10:45:01 -0800402 phoneMgr = PhoneInterfaceManager.init(this, PhoneFactory.getDefaultPhone());
Santos Cordon406c0342013-08-28 00:07:47 -0700403
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800404 configLoader = CarrierConfigLoader.init(this);
405
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700406 // Create the CallNotifer singleton, which handles
407 // asynchronous events from the telephony layer (like
408 // launching the incoming-call UI when an incoming call comes
409 // in.)
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800410 notifier = CallNotifier.init(this, callLogger, callStateMonitor, bluetoothManager);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700411
Stuart Scottdcf40a92014-12-09 10:45:01 -0800412 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413
414 // register for MMI/USSD
415 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
416
417 // register connection tracking to PhoneUtils
418 PhoneUtils.initializeConnectionHandler(mCM);
419
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700420 // Register for misc other intent broadcasts.
421 IntentFilter intentFilter =
422 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423 intentFilter.addAction(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424 intentFilter.addAction(Intent.ACTION_DOCK_EVENT);
425 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
426 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
427 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
428 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700429 registerReceiver(mReceiver, intentFilter);
430
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700431 //set the default values for the preferences in the phone.
432 PreferenceManager.setDefaultValues(this, R.xml.network_setting, false);
433
434 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
435
436 // Make sure the audio mode (along with some
437 // audio-mode-related state of our own) is initialized
438 // correctly, given the current state of the phone.
439 PhoneUtils.setAudioMode(mCM);
440 }
441
Santos Cordon52bc81b2014-10-07 19:55:12 -0700442 cdmaOtaProvisionData = new OtaUtils.CdmaOtaProvisionData();
443 cdmaOtaConfigData = new OtaUtils.CdmaOtaConfigData();
444 cdmaOtaScreenState = new OtaUtils.CdmaOtaScreenState();
445 cdmaOtaInCallScreenUiState = new OtaUtils.CdmaOtaInCallScreenUiState();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700446
Santos Cordon76aaf482015-04-08 10:58:27 -0700447 simActivationManager = new SimActivationManager();
448
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449 // XXX pre-load the SimProvider so that it's ready
450 resolver.getType(Uri.parse("content://icc/adn"));
451
452 // start with the default value to set the mute state.
453 mShouldRestoreMuteOnInCallResume = false;
454
455 // TODO: Register for Cdma Information Records
456 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
457
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700458 // Read HAC settings and configure audio hardware
459 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800460 int hac = android.provider.Settings.System.getInt(
461 getContentResolver(),
462 android.provider.Settings.System.HEARING_AID,
463 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700464 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Andrew Leefb7f92e2015-02-26 16:23:32 -0800465 audioManager.setParameter(SettingsConstants.HAC_KEY,
466 hac == SettingsConstants.HAC_ENABLED
467 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700468 }
Santos Cordonff506f52013-11-21 19:13:19 -0800469 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700470
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700471 /**
472 * Returns the singleton instance of the PhoneApp.
473 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800474 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700475 if (sMe == null) {
476 throw new IllegalStateException("No PhoneGlobals here!");
477 }
478 return sMe;
479 }
480
481 /**
482 * Returns the singleton instance of the PhoneApp if running as the
483 * primary user, otherwise null.
484 */
485 static PhoneGlobals getInstanceIfPrimary() {
486 return sMe;
487 }
488
489 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800490 * Returns the default phone.
491 *
Andrew Lee385019f2014-11-24 14:19:50 -0800492 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700493 */
Andrew Lee83383e42014-10-31 12:42:28 -0700494 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800495 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700496 }
497
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800498 public static Phone getPhone(int subId) {
499 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800500 }
501
Santos Cordon27a3c1f2013-08-06 07:49:27 -0700502 /* package */ BluetoothManager getBluetoothManager() {
503 return bluetoothManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700504 }
505
Santos Cordonde10b752013-09-19 04:11:33 -0700506 /* package */ CallManager getCallManager() {
507 return mCM;
508 }
509
Chris Manton4e9fa912015-06-19 11:26:57 -0700510 public PersistableBundle getCarrierConfig() {
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700511 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubId());
512 }
513
Chris Manton4e9fa912015-06-19 11:26:57 -0700514 public PersistableBundle getCarrierConfigForSubId(int subId) {
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700515 return configLoader.getConfigForSubId(subId);
Junda Liu605148f2015-04-28 15:23:40 -0700516 }
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");
Dianne Hackborn148769b2015-07-13 17:55:47 -0700668 mPowerManager.wakeUp(SystemClock.uptimeMillis(), "android.phone:WAKE");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700669 }
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);
Santos Cordonc593d002015-06-03 15:41:15 -0700778 if (phone == null || !TelephonyCapabilities.supportsOtasp(phone)) {
779 // Clean up OTA for non-CDMA since it is only valid for CDMA.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700780 clearOtaState();
781 }
782
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700783 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
784 callStateMonitor.updateAfterRadioTechnologyChange();
785
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700786 // Update registration for ICC status after radio technology change
Santos Cordonc593d002015-06-03 15:41:15 -0700787 IccCard sim = phone == null ? null : phone.getIccCard();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700788 if (sim != null) {
789 if (DBG) Log.d(LOG_TAG, "Update registration for ICC status...");
790
791 //Register all events new to the new active phone
792 sim.registerForNetworkLocked(mHandler, EVENT_SIM_NETWORK_LOCKED, null);
793 }
794 }
795
Santos Cordon593ab382013-08-06 21:58:23 -0700796 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700797 * Receiver for misc intent broadcasts the Phone app cares about.
798 */
799 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
800 @Override
801 public void onReceive(Context context, Intent intent) {
802 String action = intent.getAction();
803 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
804 boolean enabled = System.getInt(getContentResolver(),
805 System.AIRPLANE_MODE_ON, 0) == 0;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800806 PhoneUtils.setRadioPower(enabled);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700807 } else if (action.equals(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800808 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
809 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
810 int phoneId = SubscriptionManager.getPhoneId(subId);
811 String state = intent.getStringExtra(PhoneConstants.STATE_KEY);
812 if (VDBG) {
813 Log.d(LOG_TAG, "mReceiver: ACTION_ANY_DATA_CONNECTION_STATE_CHANGED");
814 Log.d(LOG_TAG, "- state: " + state);
815 Log.d(LOG_TAG, "- reason: "
816 + intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY));
817 Log.d(LOG_TAG, "- subId: " + subId);
818 Log.d(LOG_TAG, "- phoneId: " + phoneId);
819 }
820 Phone phone = SubscriptionManager.isValidPhoneId(phoneId) ?
821 PhoneFactory.getPhone(phoneId) : PhoneFactory.getDefaultPhone();
Santos Cordonc593d002015-06-03 15:41:15 -0700822
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700823 // The "data disconnected due to roaming" notification is shown
824 // if (a) you have the "data roaming" feature turned off, and
825 // (b) you just lost data connectivity because you're roaming.
826 boolean disconnectedDueToRoaming =
827 !phone.getDataRoamingEnabled()
Stuart Scottdcf40a92014-12-09 10:45:01 -0800828 && PhoneConstants.DataState.DISCONNECTED.equals(state)
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700829 && Phone.REASON_ROAMING_ON.equals(
830 intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY));
Yorke Lee4d2db1c2014-11-06 11:37:09 -0800831 if (mDataDisconnectedDueToRoaming != disconnectedDueToRoaming) {
832 mDataDisconnectedDueToRoaming = disconnectedDueToRoaming;
833 mHandler.sendEmptyMessage(disconnectedDueToRoaming
834 ? EVENT_DATA_ROAMING_DISCONNECTED : EVENT_DATA_ROAMING_OK);
835 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700836 } else if ((action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) &&
837 (mPUKEntryActivity != null)) {
838 // if an attempt to un-PUK-lock the device was made, while we're
839 // receiving this state change notification, notify the handler.
840 // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has
841 // been attempted.
842 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
843 intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE)));
844 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
845 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800846 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
847 SubscriptionManager.INVALID_PHONE_INDEX);
848 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " (" + phoneId
849 + ") is active.");
850 initForNewRadioTechnology(phoneId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700851 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
852 handleServiceStateChanged(intent);
853 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800854 if (TelephonyCapabilities.supportsEcm(mCM.getFgPhone())) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700855 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
856 // Start Emergency Callback Mode service
857 if (intent.getBooleanExtra("phoneinECMState", false)) {
858 context.startService(new Intent(context,
859 EmergencyCallbackModeService.class));
860 }
861 } else {
862 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
863 // on a device that doesn't support ECM in the first place.
864 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, "
Stuart Scottdcf40a92014-12-09 10:45:01 -0800865 + "but ECM isn't supported for phone: "
866 + mCM.getFgPhone().getPhoneName());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700867 }
868 } else if (action.equals(Intent.ACTION_DOCK_EVENT)) {
869 mDockState = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
870 Intent.EXTRA_DOCK_STATE_UNDOCKED);
871 if (VDBG) Log.d(LOG_TAG, "ACTION_DOCK_EVENT -> mDockState = " + mDockState);
872 mHandler.sendMessage(mHandler.obtainMessage(EVENT_DOCK_STATE_CHANGED, 0));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700873 }
874 }
875 }
876
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700877 /**
878 * Accepts broadcast Intents which will be prepared by {@link NotificationMgr} and thus
879 * sent from framework's notification mechanism (which is outside Phone context).
880 * This should be visible from outside, but shouldn't be in "exported" state.
881 *
882 * TODO: If possible merge this into PhoneAppBroadcastReceiver.
883 */
884 public static class NotificationBroadcastReceiver extends BroadcastReceiver {
885 @Override
886 public void onReceive(Context context, Intent intent) {
887 String action = intent.getAction();
888 // TODO: use "if (VDBG)" here.
889 Log.d(LOG_TAG, "Broadcast from Notification: " + action);
890
891 if (action.equals(ACTION_HANG_UP_ONGOING_CALL)) {
892 PhoneUtils.hangup(PhoneGlobals.getInstance().mCM);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700893 } else {
894 Log.w(LOG_TAG, "Received hang-up request from notification,"
895 + " but there's no call the system can hang up.");
896 }
897 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700898 }
899
900 private void handleServiceStateChanged(Intent intent) {
901 /**
902 * This used to handle updating EriTextWidgetProvider this routine
903 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
904 * be removed. But leaving just in case it might be needed in the near
905 * future.
906 */
907
908 // If service just returned, start sending out the queued messages
Santos Cordonc593d002015-06-03 15:41:15 -0700909 Bundle extras = intent.getExtras();
910 if (extras != null) {
911 ServiceState ss = ServiceState.newFromBundle(extras);
912 if (ss != null) {
913 int state = ss.getState();
914 notificationMgr.updateNetworkSelection(state);
915 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700916 }
917 }
918
919 public boolean isOtaCallInActiveState() {
920 boolean otaCallActive = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700921 if (VDBG) Log.d(LOG_TAG, "- isOtaCallInActiveState " + otaCallActive);
922 return otaCallActive;
923 }
924
925 public boolean isOtaCallInEndState() {
926 boolean otaCallEnded = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700927 if (VDBG) Log.d(LOG_TAG, "- isOtaCallInEndState " + otaCallEnded);
928 return otaCallEnded;
929 }
930
931 // it is safe to call clearOtaState() even if the InCallScreen isn't active
932 public void clearOtaState() {
933 if (DBG) Log.d(LOG_TAG, "- clearOtaState ...");
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700934 if (otaUtils != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700935 otaUtils.cleanOtaScreen(true);
936 if (DBG) Log.d(LOG_TAG, " - clearOtaState clears OTA screen");
937 }
938 }
939
940 // it is safe to call dismissOtaDialogs() even if the InCallScreen isn't active
941 public void dismissOtaDialogs() {
942 if (DBG) Log.d(LOG_TAG, "- dismissOtaDialogs ...");
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700943 if (otaUtils != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700944 otaUtils.dismissAllOtaDialogs();
945 if (DBG) Log.d(LOG_TAG, " - dismissOtaDialogs clears OTA dialogs");
946 }
947 }
948
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700949 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800950 * Triggers a refresh of the message waiting (voicemail) indicator.
951 *
952 * @param subId the subscription id we should refresh the notification for.
953 */
954 public void refreshMwiIndicator(int subId) {
955 notificationMgr.refreshMwi(subId);
956 }
957
958 /**
Nancy Chenbb49d412015-07-23 13:54:16 -0700959 * Dismisses the message waiting (voicemail) indicator.
960 *
961 * @param subId the subscription id we should dismiss the notification for.
962 */
963 public void clearMwiIndicator(int subId) {
964 notificationMgr.updateMwi(subId, false);
965 }
966
967 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700968 * "Call origin" may be used by Contacts app to specify where the phone call comes from.
969 * Currently, the only permitted value for this extra is {@link #ALLOWED_EXTRA_CALL_ORIGIN}.
970 * Any other value will be ignored, to make sure that malicious apps can't trick the in-call
971 * UI into launching some random other app after a call ends.
972 *
973 * TODO: make this more generic. Note that we should let the "origin" specify its package
974 * while we are now assuming it is "com.android.contacts"
975 */
976 public static final String EXTRA_CALL_ORIGIN = "com.android.phone.CALL_ORIGIN";
977 private static final String DEFAULT_CALL_ORIGIN_PACKAGE = "com.android.dialer";
978 private static final String ALLOWED_EXTRA_CALL_ORIGIN =
979 "com.android.dialer.DialtactsActivity";
980 /**
981 * Used to determine if the preserved call origin is fresh enough.
982 */
983 private static final long CALL_ORIGIN_EXPIRATION_MILLIS = 30 * 1000;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700984}