blob: c6081b1713ee56ccb2a9f408892d116b56b9be41 [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;
Bryce Lee5ccda612015-12-04 15:44:16 -0800112 private static final int EVENT_START_SIP_SERVICE = 13;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700113
114 // The MMI codes are also used by the InCallScreen.
115 public static final int MMI_INITIATE = 51;
116 public static final int MMI_COMPLETE = 52;
117 public static final int MMI_CANCEL = 53;
118 // Don't use message codes larger than 99 here; those are reserved for
119 // the individual Activities of the Phone UI.
120
121 /**
122 * Allowable values for the wake lock code.
123 * SLEEP means the device can be put to sleep.
124 * PARTIAL means wake the processor, but we display can be kept off.
125 * FULL means wake both the processor and the display.
126 */
127 public enum WakeState {
128 SLEEP,
129 PARTIAL,
130 FULL
131 }
132
133 /**
134 * Intent Action used for hanging up the current call from Notification bar. This will
135 * choose first ringing call, first active call, or first background call (typically in
136 * HOLDING state).
137 */
138 public static final String ACTION_HANG_UP_ONGOING_CALL =
139 "com.android.phone.ACTION_HANG_UP_ONGOING_CALL";
140
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141 private static PhoneGlobals sMe;
142
143 // A few important fields we expose to the rest of the package
144 // directly (rather than thru set/get methods) for efficiency.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700145 CallController callController;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700146 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700147 CallNotifier notifier;
148 CallerInfoCache callerInfoCache;
Santos Cordon63a84242013-07-23 13:32:52 -0700149 NotificationMgr notificationMgr;
Andrew Lee9431b832015-03-09 18:46:45 -0700150 public PhoneInterfaceManager phoneMgr;
Santos Cordon76aaf482015-04-08 10:58:27 -0700151 public SimActivationManager simActivationManager;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800152 CarrierConfigLoader configLoader;
Santos Cordon63a84242013-07-23 13:32:52 -0700153
Santos Cordon69a69192013-08-22 14:25:42 -0700154 private CallGatewayManager callGatewayManager;
Santos Cordon63a84242013-07-23 13:32:52 -0700155 private CallStateMonitor callStateMonitor;
Santos Cordon63a84242013-07-23 13:32:52 -0700156
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157 static boolean sVoiceCapable = true;
158
Santos Cordonc593d002015-06-03 15:41:15 -0700159 // TODO: Remove, no longer used.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700160 CdmaPhoneCallState cdmaPhoneCallState;
161
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162 // The currently-active PUK entry activity and progress dialog.
163 // Normally, these are the Emergency Dialer and the subsequent
164 // progress dialog. null if there is are no such objects in
165 // the foreground.
166 private Activity mPUKEntryActivity;
167 private ProgressDialog mPUKEntryProgressDialog;
168
169 private boolean mIsSimPinEnabled;
170 private String mCachedSimPin;
171
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172 // True if we are beginning a call, but the phone state has not changed yet
173 private boolean mBeginningCall;
Yorke Lee4d2db1c2014-11-06 11:37:09 -0800174 private boolean mDataDisconnectedDueToRoaming = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700175
176 // Last phone state seen by updatePhoneState()
177 private PhoneConstants.State mLastPhoneState = PhoneConstants.State.IDLE;
178
179 private WakeState mWakeState = WakeState.SLEEP;
180
181 private PowerManager mPowerManager;
182 private IPowerManager mPowerManagerService;
183 private PowerManager.WakeLock mWakeLock;
184 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186
187 private UpdateLock mUpdateLock;
188
189 // Broadcast receiver for various intent broadcasts (see onCreate())
190 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
191
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192 /** boolean indicating restoring mute state on InCallScreen.onResume() */
193 private boolean mShouldRestoreMuteOnInCallResume;
194
195 /**
196 * The singleton OtaUtils instance used for OTASP calls.
197 *
198 * The OtaUtils instance is created lazily the first time we need to
199 * make an OTASP call, regardless of whether it's an interactive or
200 * non-interactive OTASP call.
201 */
202 public OtaUtils otaUtils;
203
204 // Following are the CDMA OTA information Objects used during OTA Call.
205 // cdmaOtaProvisionData object store static OTA information that needs
206 // to be maintained even during Slider open/close scenarios.
207 // cdmaOtaConfigData object stores configuration info to control visiblity
208 // of each OTA Screens.
209 // cdmaOtaScreenState object store OTA Screen State information.
210 public OtaUtils.CdmaOtaProvisionData cdmaOtaProvisionData;
211 public OtaUtils.CdmaOtaConfigData cdmaOtaConfigData;
212 public OtaUtils.CdmaOtaScreenState cdmaOtaScreenState;
213 public OtaUtils.CdmaOtaInCallScreenUiState cdmaOtaInCallScreenUiState;
214
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700215 /**
216 * Set the restore mute state flag. Used when we are setting the mute state
217 * OUTSIDE of user interaction {@link PhoneUtils#startNewCall(Phone)}
218 */
219 /*package*/void setRestoreMuteOnInCallResume (boolean mode) {
220 mShouldRestoreMuteOnInCallResume = mode;
221 }
222
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700223 Handler mHandler = new Handler() {
224 @Override
225 public void handleMessage(Message msg) {
226 PhoneConstants.State phoneState;
227 switch (msg.what) {
228 // Starts the SIP service. It's a no-op if SIP API is not supported
229 // on the deivce.
230 // TODO: Having the phone process host the SIP service is only
231 // temporary. Will move it to a persistent communication process
232 // later.
233 case EVENT_START_SIP_SERVICE:
234 SipService.start(getApplicationContext());
235 break;
236
237 // TODO: This event should be handled by the lock screen, just
238 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
239 case EVENT_SIM_NETWORK_LOCKED:
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700240 if (getCarrierConfig().getBoolean(
241 CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700242 // Some products don't have the concept of a "SIM network lock"
243 Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; "
244 + "not showing 'SIM network unlock' PIN entry screen");
245 } else {
246 // Normal case: show the "SIM network unlock" PIN entry screen.
247 // The user won't be able to do anything else until
248 // they enter a valid SIM network PIN.
249 Log.i(LOG_TAG, "show sim depersonal panel");
Tyler Gunn52a37072015-08-24 14:23:19 -0700250 IccNetworkDepersonalizationPanel.showDialog();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700251 }
252 break;
253
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700254 case EVENT_DATA_ROAMING_DISCONNECTED:
255 notificationMgr.showDataDisconnectedRoaming();
256 break;
257
258 case EVENT_DATA_ROAMING_OK:
259 notificationMgr.hideDataDisconnectedRoaming();
260 break;
261
262 case MMI_COMPLETE:
263 onMMIComplete((AsyncResult) msg.obj);
264 break;
265
266 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800267 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700268 break;
269
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700270 case EVENT_SIM_STATE_CHANGED:
271 // Marks the event where the SIM goes into ready state.
272 // Right now, this is only used for the PUK-unlocking
273 // process.
274 if (msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_READY)) {
275 // when the right event is triggered and there
276 // are UI objects in the foreground, we close
277 // them to display the lock panel.
278 if (mPUKEntryActivity != null) {
279 mPUKEntryActivity.finish();
280 mPUKEntryActivity = null;
281 }
282 if (mPUKEntryProgressDialog != null) {
283 mPUKEntryProgressDialog.dismiss();
284 mPUKEntryProgressDialog = null;
285 }
286 }
287 break;
288
289 case EVENT_UNSOL_CDMA_INFO_RECORD:
290 //TODO: handle message here;
291 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700292 }
293 }
294 };
295
296 public PhoneGlobals(Context context) {
297 super(context);
298 sMe = this;
299 }
300
301 public void onCreate() {
302 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
303
304 ContentResolver resolver = getContentResolver();
305
306 // Cache the "voice capable" flag.
307 // This flag currently comes from a resource (which is
308 // overrideable on a per-product basis):
309 sVoiceCapable =
310 getResources().getBoolean(com.android.internal.R.bool.config_voice_capable);
311 // ...but this might eventually become a PackageManager "system
312 // feature" instead, in which case we'd do something like:
313 // sVoiceCapable =
314 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
315
Stuart Scottdcf40a92014-12-09 10:45:01 -0800316 if (mCM == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700317 // Initialize the telephony framework
318 PhoneFactory.makeDefaultPhones(this);
319
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700320 // Start TelephonyDebugService After the default phone is created.
321 Intent intent = new Intent(this, TelephonyDebugService.class);
322 startService(intent);
323
324 mCM = CallManager.getInstance();
Stuart Scottdcf40a92014-12-09 10:45:01 -0800325 for (Phone phone : PhoneFactory.getPhones()) {
326 mCM.registerPhone(phone);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800327 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700328
329 // Create the NotificationMgr singleton, which is used to display
330 // status bar icons and control other status bar behavior.
331 notificationMgr = NotificationMgr.init(this);
332
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700333 mHandler.sendEmptyMessage(EVENT_START_SIP_SERVICE);
334
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700335 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
336 cdmaPhoneCallState = new CdmaPhoneCallState();
337 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700339 // before registering for phone state changes
340 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
341 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
342 // lock used to keep the processor awake, when we don't care for the display.
343 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
344 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700345
346 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
347
348 // get a handle to the service so that we can use it later when we
349 // want to set the poke lock.
350 mPowerManagerService = IPowerManager.Stub.asInterface(
351 ServiceManager.getService("power"));
352
353 // Get UpdateLock to suppress system-update related events (e.g. dialog show-up)
354 // during phone calls.
355 mUpdateLock = new UpdateLock("phone");
356
357 if (DBG) Log.d(LOG_TAG, "onCreate: mUpdateLock: " + mUpdateLock);
358
359 CallLogger callLogger = new CallLogger(this, new CallLogAsync());
360
Jay Shrauner21a75342013-11-25 16:14:43 -0800361 callGatewayManager = CallGatewayManager.getInstance();
Santos Cordon69a69192013-08-22 14:25:42 -0700362
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700363 // Create the CallController singleton, which is the interface
364 // to the telephony layer for user-initiated telephony functionality
365 // (like making outgoing calls.)
Santos Cordon69a69192013-08-22 14:25:42 -0700366 callController = CallController.init(this, callLogger, callGatewayManager);
367
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700368 // Create the CallerInfoCache singleton, which remembers custom ring tone and
369 // send-to-voicemail settings.
370 //
371 // The asynchronous caching will start just after this call.
372 callerInfoCache = CallerInfoCache.init(this);
373
374 // Monitors call activity from the telephony layer
375 callStateMonitor = new CallStateMonitor(mCM);
376
Stuart Scottdcf40a92014-12-09 10:45:01 -0800377 phoneMgr = PhoneInterfaceManager.init(this, PhoneFactory.getDefaultPhone());
Santos Cordon406c0342013-08-28 00:07:47 -0700378
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800379 configLoader = CarrierConfigLoader.init(this);
380
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 // Create the CallNotifer singleton, which handles
382 // asynchronous events from the telephony layer (like
383 // launching the incoming-call UI when an incoming call comes
384 // in.)
Bryce Lee5ccda612015-12-04 15:44:16 -0800385 notifier = CallNotifier.init(this, callLogger, callStateMonitor);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700386
Stuart Scottdcf40a92014-12-09 10:45:01 -0800387 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388
389 // register for MMI/USSD
390 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
391
392 // register connection tracking to PhoneUtils
393 PhoneUtils.initializeConnectionHandler(mCM);
394
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700395 // Register for misc other intent broadcasts.
396 IntentFilter intentFilter =
397 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398 intentFilter.addAction(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700399 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
400 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
401 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
402 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700403 registerReceiver(mReceiver, intentFilter);
404
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700405 //set the default values for the preferences in the phone.
406 PreferenceManager.setDefaultValues(this, R.xml.network_setting, false);
407
408 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
409
410 // Make sure the audio mode (along with some
411 // audio-mode-related state of our own) is initialized
412 // correctly, given the current state of the phone.
413 PhoneUtils.setAudioMode(mCM);
414 }
415
Santos Cordon52bc81b2014-10-07 19:55:12 -0700416 cdmaOtaProvisionData = new OtaUtils.CdmaOtaProvisionData();
417 cdmaOtaConfigData = new OtaUtils.CdmaOtaConfigData();
418 cdmaOtaScreenState = new OtaUtils.CdmaOtaScreenState();
419 cdmaOtaInCallScreenUiState = new OtaUtils.CdmaOtaInCallScreenUiState();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700420
Santos Cordon76aaf482015-04-08 10:58:27 -0700421 simActivationManager = new SimActivationManager();
422
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423 // XXX pre-load the SimProvider so that it's ready
424 resolver.getType(Uri.parse("content://icc/adn"));
425
426 // start with the default value to set the mute state.
427 mShouldRestoreMuteOnInCallResume = false;
428
429 // TODO: Register for Cdma Information Records
430 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
431
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700432 // Read HAC settings and configure audio hardware
433 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800434 int hac = android.provider.Settings.System.getInt(
435 getContentResolver(),
436 android.provider.Settings.System.HEARING_AID,
437 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700438 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Andrew Leefb7f92e2015-02-26 16:23:32 -0800439 audioManager.setParameter(SettingsConstants.HAC_KEY,
440 hac == SettingsConstants.HAC_ENABLED
441 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700442 }
Santos Cordonff506f52013-11-21 19:13:19 -0800443 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445 /**
446 * Returns the singleton instance of the PhoneApp.
447 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800448 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449 if (sMe == null) {
450 throw new IllegalStateException("No PhoneGlobals here!");
451 }
452 return sMe;
453 }
454
455 /**
456 * Returns the singleton instance of the PhoneApp if running as the
457 * primary user, otherwise null.
458 */
459 static PhoneGlobals getInstanceIfPrimary() {
460 return sMe;
461 }
462
463 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800464 * Returns the default phone.
465 *
Andrew Lee385019f2014-11-24 14:19:50 -0800466 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700467 */
Andrew Lee83383e42014-10-31 12:42:28 -0700468 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800469 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700470 }
471
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800472 public static Phone getPhone(int subId) {
473 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800474 }
475
Santos Cordonde10b752013-09-19 04:11:33 -0700476 /* package */ CallManager getCallManager() {
477 return mCM;
478 }
479
Chris Manton4e9fa912015-06-19 11:26:57 -0700480 public PersistableBundle getCarrierConfig() {
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700481 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubId());
482 }
483
Chris Manton4e9fa912015-06-19 11:26:57 -0700484 public PersistableBundle getCarrierConfigForSubId(int subId) {
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700485 return configLoader.getConfigForSubId(subId);
Junda Liu605148f2015-04-28 15:23:40 -0700486 }
487
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700488 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700489 * Returns PendingIntent for hanging up ongoing phone call. This will typically be used from
490 * Notification context.
491 */
492 /* package */ static PendingIntent createHangUpOngoingCallPendingIntent(Context context) {
493 Intent intent = new Intent(PhoneGlobals.ACTION_HANG_UP_ONGOING_CALL, null,
494 context, NotificationBroadcastReceiver.class);
495 return PendingIntent.getBroadcast(context, 0, intent, 0);
496 }
497
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700498 boolean isSimPinEnabled() {
499 return mIsSimPinEnabled;
500 }
501
502 boolean authenticateAgainstCachedSimPin(String pin) {
503 return (mCachedSimPin != null && mCachedSimPin.equals(pin));
504 }
505
506 void setCachedSimPin(String pin) {
507 mCachedSimPin = pin;
508 }
509
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700510 /**
511 * Handles OTASP-related events from the telephony layer.
512 *
513 * While an OTASP call is active, the CallNotifier forwards
514 * OTASP-related telephony events to this method.
515 */
516 void handleOtaspEvent(Message msg) {
517 if (DBG) Log.d(LOG_TAG, "handleOtaspEvent(message " + msg + ")...");
518
519 if (otaUtils == null) {
520 // We shouldn't be getting OTASP events without ever
521 // having started the OTASP call in the first place!
522 Log.w(LOG_TAG, "handleOtaEvents: got an event but otaUtils is null! "
523 + "message = " + msg);
524 return;
525 }
526
527 otaUtils.onOtaProvisionStatusChanged((AsyncResult) msg.obj);
528 }
529
530 /**
531 * Similarly, handle the disconnect event of an OTASP call
532 * by forwarding it to the OtaUtils instance.
533 */
534 /* package */ void handleOtaspDisconnect() {
535 if (DBG) Log.d(LOG_TAG, "handleOtaspDisconnect()...");
536
537 if (otaUtils == null) {
538 // We shouldn't be getting OTASP events without ever
539 // having started the OTASP call in the first place!
540 Log.w(LOG_TAG, "handleOtaspDisconnect: otaUtils is null!");
541 return;
542 }
543
544 otaUtils.onOtaspDisconnect();
545 }
546
547 /**
548 * Sets the activity responsible for un-PUK-blocking the device
549 * so that we may close it when we receive a positive result.
550 * mPUKEntryActivity is also used to indicate to the device that
551 * we are trying to un-PUK-lock the phone. In other words, iff
552 * it is NOT null, then we are trying to unlock and waiting for
553 * the SIM to move to READY state.
554 *
555 * @param activity is the activity to close when PUK has
556 * finished unlocking. Can be set to null to indicate the unlock
557 * or SIM READYing process is over.
558 */
559 void setPukEntryActivity(Activity activity) {
560 mPUKEntryActivity = activity;
561 }
562
563 Activity getPUKEntryActivity() {
564 return mPUKEntryActivity;
565 }
566
567 /**
568 * Sets the dialog responsible for notifying the user of un-PUK-
569 * blocking - SIM READYing progress, so that we may dismiss it
570 * when we receive a positive result.
571 *
572 * @param dialog indicates the progress dialog informing the user
573 * of the state of the device. Dismissed upon completion of
574 * READYing process
575 */
576 void setPukEntryProgressDialog(ProgressDialog dialog) {
577 mPUKEntryProgressDialog = dialog;
578 }
579
580 ProgressDialog getPUKEntryProgressDialog() {
581 return mPUKEntryProgressDialog;
582 }
583
584 /**
585 * Controls whether or not the screen is allowed to sleep.
586 *
587 * Once sleep is allowed (WakeState is SLEEP), it will rely on the
588 * settings for the poke lock to determine when to timeout and let
589 * the device sleep {@link PhoneGlobals#setScreenTimeout}.
590 *
591 * @param ws tells the device to how to wake.
592 */
593 /* package */ void requestWakeState(WakeState ws) {
594 if (VDBG) Log.d(LOG_TAG, "requestWakeState(" + ws + ")...");
595 synchronized (this) {
596 if (mWakeState != ws) {
597 switch (ws) {
598 case PARTIAL:
599 // acquire the processor wake lock, and release the FULL
600 // lock if it is being held.
601 mPartialWakeLock.acquire();
602 if (mWakeLock.isHeld()) {
603 mWakeLock.release();
604 }
605 break;
606 case FULL:
607 // acquire the full wake lock, and release the PARTIAL
608 // lock if it is being held.
609 mWakeLock.acquire();
610 if (mPartialWakeLock.isHeld()) {
611 mPartialWakeLock.release();
612 }
613 break;
614 case SLEEP:
615 default:
616 // release both the PARTIAL and FULL locks.
617 if (mWakeLock.isHeld()) {
618 mWakeLock.release();
619 }
620 if (mPartialWakeLock.isHeld()) {
621 mPartialWakeLock.release();
622 }
623 break;
624 }
625 mWakeState = ws;
626 }
627 }
628 }
629
630 /**
631 * If we are not currently keeping the screen on, then poke the power
632 * manager to wake up the screen for the user activity timeout duration.
633 */
634 /* package */ void wakeUpScreen() {
635 synchronized (this) {
636 if (mWakeState == WakeState.SLEEP) {
637 if (DBG) Log.d(LOG_TAG, "pulse screen lock");
Dianne Hackborn148769b2015-07-13 17:55:47 -0700638 mPowerManager.wakeUp(SystemClock.uptimeMillis(), "android.phone:WAKE");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700639 }
640 }
641 }
642
643 /**
644 * Sets the wake state and screen timeout based on the current state
645 * of the phone, and the current state of the in-call UI.
646 *
647 * This method is a "UI Policy" wrapper around
648 * {@link PhoneGlobals#requestWakeState} and {@link PhoneGlobals#setScreenTimeout}.
649 *
650 * It's safe to call this method regardless of the state of the Phone
651 * (e.g. whether or not it's idle), and regardless of the state of the
652 * Phone UI (e.g. whether or not the InCallScreen is active.)
653 */
654 /* package */ void updateWakeState() {
655 PhoneConstants.State state = mCM.getState();
656
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700657 // True if the speakerphone is in use. (If so, we *always* use
658 // the default timeout. Since the user is obviously not holding
659 // the phone up to his/her face, we don't need to worry about
660 // false touches, and thus don't need to turn the screen off so
661 // aggressively.)
662 // Note that we need to make a fresh call to this method any
663 // time the speaker state changes. (That happens in
664 // PhoneUtils.turnOnSpeaker().)
665 boolean isSpeakerInUse = (state == PhoneConstants.State.OFFHOOK) && PhoneUtils.isSpeakerOn(this);
666
667 // TODO (bug 1440854): The screen timeout *might* also need to
668 // depend on the bluetooth state, but this isn't as clear-cut as
669 // the speaker state (since while using BT it's common for the
670 // user to put the phone straight into a pocket, in which case the
671 // timeout should probably still be short.)
672
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700673 // Decide whether to force the screen on or not.
674 //
675 // Force the screen to be on if the phone is ringing or dialing,
676 // or if we're displaying the "Call ended" UI for a connection in
677 // the "disconnected" state.
678 // However, if the phone is disconnected while the user is in the
679 // middle of selecting a quick response message, we should not force
680 // the screen to be on.
681 //
682 boolean isRinging = (state == PhoneConstants.State.RINGING);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800683 boolean isDialing = (mCM.getFgPhone().getForegroundCall().getState() == Call.State.DIALING);
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700684 boolean keepScreenOn = isRinging || isDialing;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700685 // keepScreenOn == true means we'll hold a full wake lock:
686 requestWakeState(keepScreenOn ? WakeState.FULL : WakeState.SLEEP);
687 }
688
689 /**
690 * Manually pokes the PowerManager's userActivity method. Since we
691 * set the {@link WindowManager.LayoutParams#INPUT_FEATURE_DISABLE_USER_ACTIVITY}
692 * flag while the InCallScreen is active when there is no proximity sensor,
693 * we need to do this for touch events that really do count as user activity
694 * (like pressing any onscreen UI elements.)
695 */
696 /* package */ void pokeUserActivity() {
697 if (VDBG) Log.d(LOG_TAG, "pokeUserActivity()...");
698 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
699 }
700
701 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700702 * Notifies the phone app when the phone state changes.
703 *
Santos Cordonfc309812013-08-20 18:33:16 -0700704 * This method will updates various states inside Phone app (e.g. update-lock state, etc.)
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700705 */
706 /* package */ void updatePhoneState(PhoneConstants.State state) {
707 if (state != mLastPhoneState) {
708 mLastPhoneState = state;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700709
710 // Try to acquire or release UpdateLock.
711 //
712 // Watch out: we don't release the lock here when the screen is still in foreground.
713 // At that time InCallScreen will release it on onPause().
714 if (state != PhoneConstants.State.IDLE) {
715 // UpdateLock is a recursive lock, while we may get "acquire" request twice and
716 // "release" request once for a single call (RINGING + OFFHOOK and IDLE).
717 // We need to manually ensure the lock is just acquired once for each (and this
718 // will prevent other possible buggy situations too).
719 if (!mUpdateLock.isHeld()) {
720 mUpdateLock.acquire();
721 }
722 } else {
Jay Shraunera5d13212013-09-19 13:37:43 -0700723 if (mUpdateLock.isHeld()) {
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700724 mUpdateLock.release();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700725 }
726 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700727 }
728 }
729
730 /* package */ PhoneConstants.State getPhoneState() {
731 return mLastPhoneState;
732 }
733
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700734 KeyguardManager getKeyguardManager() {
735 return mKeyguardManager;
736 }
737
738 private void onMMIComplete(AsyncResult r) {
739 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
740 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800741 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700742 }
743
Stuart Scottdcf40a92014-12-09 10:45:01 -0800744 private void initForNewRadioTechnology(int phoneId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700745 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
746
Stuart Scottdcf40a92014-12-09 10:45:01 -0800747 final Phone phone = PhoneFactory.getPhone(phoneId);
Santos Cordonc593d002015-06-03 15:41:15 -0700748 if (phone == null || !TelephonyCapabilities.supportsOtasp(phone)) {
749 // Clean up OTA for non-CDMA since it is only valid for CDMA.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700750 clearOtaState();
751 }
752
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700753 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
754 callStateMonitor.updateAfterRadioTechnologyChange();
755
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700756 // Update registration for ICC status after radio technology change
Santos Cordonc593d002015-06-03 15:41:15 -0700757 IccCard sim = phone == null ? null : phone.getIccCard();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700758 if (sim != null) {
759 if (DBG) Log.d(LOG_TAG, "Update registration for ICC status...");
760
761 //Register all events new to the new active phone
762 sim.registerForNetworkLocked(mHandler, EVENT_SIM_NETWORK_LOCKED, null);
763 }
764 }
765
Santos Cordon593ab382013-08-06 21:58:23 -0700766 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700767 * Receiver for misc intent broadcasts the Phone app cares about.
768 */
769 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
770 @Override
771 public void onReceive(Context context, Intent intent) {
772 String action = intent.getAction();
773 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
774 boolean enabled = System.getInt(getContentResolver(),
775 System.AIRPLANE_MODE_ON, 0) == 0;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800776 PhoneUtils.setRadioPower(enabled);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700777 } else if (action.equals(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800778 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
779 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
780 int phoneId = SubscriptionManager.getPhoneId(subId);
781 String state = intent.getStringExtra(PhoneConstants.STATE_KEY);
782 if (VDBG) {
783 Log.d(LOG_TAG, "mReceiver: ACTION_ANY_DATA_CONNECTION_STATE_CHANGED");
784 Log.d(LOG_TAG, "- state: " + state);
785 Log.d(LOG_TAG, "- reason: "
786 + intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY));
787 Log.d(LOG_TAG, "- subId: " + subId);
788 Log.d(LOG_TAG, "- phoneId: " + phoneId);
789 }
790 Phone phone = SubscriptionManager.isValidPhoneId(phoneId) ?
791 PhoneFactory.getPhone(phoneId) : PhoneFactory.getDefaultPhone();
Santos Cordonc593d002015-06-03 15:41:15 -0700792
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700793 // The "data disconnected due to roaming" notification is shown
794 // if (a) you have the "data roaming" feature turned off, and
795 // (b) you just lost data connectivity because you're roaming.
796 boolean disconnectedDueToRoaming =
797 !phone.getDataRoamingEnabled()
Stuart Scottdcf40a92014-12-09 10:45:01 -0800798 && PhoneConstants.DataState.DISCONNECTED.equals(state)
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700799 && Phone.REASON_ROAMING_ON.equals(
800 intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY));
Yorke Lee4d2db1c2014-11-06 11:37:09 -0800801 if (mDataDisconnectedDueToRoaming != disconnectedDueToRoaming) {
802 mDataDisconnectedDueToRoaming = disconnectedDueToRoaming;
803 mHandler.sendEmptyMessage(disconnectedDueToRoaming
804 ? EVENT_DATA_ROAMING_DISCONNECTED : EVENT_DATA_ROAMING_OK);
805 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700806 } else if ((action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) &&
807 (mPUKEntryActivity != null)) {
808 // if an attempt to un-PUK-lock the device was made, while we're
809 // receiving this state change notification, notify the handler.
810 // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has
811 // been attempted.
812 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
813 intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE)));
814 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
815 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800816 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
817 SubscriptionManager.INVALID_PHONE_INDEX);
818 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " (" + phoneId
819 + ") is active.");
820 initForNewRadioTechnology(phoneId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700821 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
822 handleServiceStateChanged(intent);
823 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800824 if (TelephonyCapabilities.supportsEcm(mCM.getFgPhone())) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700825 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
826 // Start Emergency Callback Mode service
827 if (intent.getBooleanExtra("phoneinECMState", false)) {
828 context.startService(new Intent(context,
829 EmergencyCallbackModeService.class));
830 }
831 } else {
832 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
833 // on a device that doesn't support ECM in the first place.
834 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, "
Stuart Scottdcf40a92014-12-09 10:45:01 -0800835 + "but ECM isn't supported for phone: "
836 + mCM.getFgPhone().getPhoneName());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700837 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700838 }
839 }
840 }
841
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700842 /**
843 * Accepts broadcast Intents which will be prepared by {@link NotificationMgr} and thus
844 * sent from framework's notification mechanism (which is outside Phone context).
845 * This should be visible from outside, but shouldn't be in "exported" state.
846 *
847 * TODO: If possible merge this into PhoneAppBroadcastReceiver.
848 */
849 public static class NotificationBroadcastReceiver extends BroadcastReceiver {
850 @Override
851 public void onReceive(Context context, Intent intent) {
852 String action = intent.getAction();
853 // TODO: use "if (VDBG)" here.
854 Log.d(LOG_TAG, "Broadcast from Notification: " + action);
855
856 if (action.equals(ACTION_HANG_UP_ONGOING_CALL)) {
857 PhoneUtils.hangup(PhoneGlobals.getInstance().mCM);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700858 } else {
859 Log.w(LOG_TAG, "Received hang-up request from notification,"
860 + " but there's no call the system can hang up.");
861 }
862 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700863 }
864
865 private void handleServiceStateChanged(Intent intent) {
866 /**
867 * This used to handle updating EriTextWidgetProvider this routine
868 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
869 * be removed. But leaving just in case it might be needed in the near
870 * future.
871 */
872
873 // If service just returned, start sending out the queued messages
Santos Cordonc593d002015-06-03 15:41:15 -0700874 Bundle extras = intent.getExtras();
875 if (extras != null) {
876 ServiceState ss = ServiceState.newFromBundle(extras);
877 if (ss != null) {
878 int state = ss.getState();
879 notificationMgr.updateNetworkSelection(state);
880 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700881 }
882 }
883
884 public boolean isOtaCallInActiveState() {
885 boolean otaCallActive = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700886 if (VDBG) Log.d(LOG_TAG, "- isOtaCallInActiveState " + otaCallActive);
887 return otaCallActive;
888 }
889
890 public boolean isOtaCallInEndState() {
891 boolean otaCallEnded = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700892 if (VDBG) Log.d(LOG_TAG, "- isOtaCallInEndState " + otaCallEnded);
893 return otaCallEnded;
894 }
895
896 // it is safe to call clearOtaState() even if the InCallScreen isn't active
897 public void clearOtaState() {
898 if (DBG) Log.d(LOG_TAG, "- clearOtaState ...");
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700899 if (otaUtils != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700900 otaUtils.cleanOtaScreen(true);
901 if (DBG) Log.d(LOG_TAG, " - clearOtaState clears OTA screen");
902 }
903 }
904
905 // it is safe to call dismissOtaDialogs() even if the InCallScreen isn't active
906 public void dismissOtaDialogs() {
907 if (DBG) Log.d(LOG_TAG, "- dismissOtaDialogs ...");
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700908 if (otaUtils != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700909 otaUtils.dismissAllOtaDialogs();
910 if (DBG) Log.d(LOG_TAG, " - dismissOtaDialogs clears OTA dialogs");
911 }
912 }
913
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700914 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800915 * Triggers a refresh of the message waiting (voicemail) indicator.
916 *
917 * @param subId the subscription id we should refresh the notification for.
918 */
919 public void refreshMwiIndicator(int subId) {
920 notificationMgr.refreshMwi(subId);
921 }
922
923 /**
Nancy Chenbb49d412015-07-23 13:54:16 -0700924 * Dismisses the message waiting (voicemail) indicator.
925 *
926 * @param subId the subscription id we should dismiss the notification for.
927 */
928 public void clearMwiIndicator(int subId) {
929 notificationMgr.updateMwi(subId, false);
930 }
931
932 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700933 * "Call origin" may be used by Contacts app to specify where the phone call comes from.
934 * Currently, the only permitted value for this extra is {@link #ALLOWED_EXTRA_CALL_ORIGIN}.
935 * Any other value will be ignored, to make sure that malicious apps can't trick the in-call
936 * UI into launching some random other app after a call ends.
937 *
938 * TODO: make this more generic. Note that we should let the "origin" specify its package
939 * while we are now assuming it is "com.android.contacts"
940 */
941 public static final String EXTRA_CALL_ORIGIN = "com.android.phone.CALL_ORIGIN";
942 private static final String DEFAULT_CALL_ORIGIN_PACKAGE = "com.android.dialer";
943 private static final String ALLOWED_EXTRA_CALL_ORIGIN =
944 "com.android.dialer.DialtactsActivity";
945 /**
946 * Used to determine if the preserved call origin is fresh enough.
947 */
948 private static final long CALL_ORIGIN_EXPIRATION_MILLIS = 30 * 1000;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700949}