blob: 3b9ea035e57a646c7f0098ab68a4e80409897864 [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070021import android.app.ProgressDialog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.content.BroadcastReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070023import android.content.ContentResolver;
24import android.content.Context;
25import android.content.ContextWrapper;
26import android.content.Intent;
27import android.content.IntentFilter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070028import android.media.AudioManager;
Santos Cordone18902f2016-03-22 17:16:04 -070029import android.net.ConnectivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.net.Uri;
31import android.os.AsyncResult;
Junda Liu605148f2015-04-28 15:23:40 -070032import android.os.Bundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.os.Handler;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070034import android.os.Message;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070035import android.os.PersistableBundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036import android.os.PowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.os.SystemClock;
38import android.os.SystemProperties;
39import android.os.UpdateLock;
Brad Ebinger3fa43462016-04-12 16:06:48 -070040import android.os.UserManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.preference.PreferenceManager;
Sanket Padawe4c699232016-02-09 11:07:22 -080042import android.provider.Settings;
Junda Liu12f7d802015-05-01 12:06:44 -070043import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.telephony.ServiceState;
Andrew Lee385019f2014-11-24 14:19:50 -080045import android.telephony.SubscriptionManager;
Jack Yu1a2fc352017-07-14 17:14:37 -070046import android.telephony.TelephonyManager;
47import android.util.LocalLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.util.Log;
Santos Cordone18902f2016-03-22 17:16:04 -070049import android.widget.Toast;
Ta-wei Yenb29425b2016-09-21 17:28:14 -070050
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import com.android.internal.telephony.Call;
52import com.android.internal.telephony.CallManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import com.android.internal.telephony.IccCardConstants;
54import com.android.internal.telephony.MmiCode;
55import com.android.internal.telephony.Phone;
56import com.android.internal.telephony.PhoneConstants;
57import com.android.internal.telephony.PhoneFactory;
Jack Yu1a2fc352017-07-14 17:14:37 -070058import com.android.internal.telephony.SettingsObserver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import com.android.internal.telephony.TelephonyCapabilities;
60import com.android.internal.telephony.TelephonyIntents;
Jack Yu1a2fc352017-07-14 17:14:37 -070061import com.android.internal.telephony.dataconnection.DataConnectionReasons;
62import com.android.internal.telephony.dataconnection.DataConnectionReasons.DataDisallowedReasonType;
63import com.android.internal.util.IndentingPrintWriter;
Santos Cordon352ff652014-05-30 01:41:45 -070064import com.android.phone.common.CallLogAsync;
Andrew Leefb7f92e2015-02-26 16:23:32 -080065import com.android.phone.settings.SettingsConstants;
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -070066import com.android.phone.vvm.CarrierVvmPackageInstalledReceiver;
Brad Ebinger3fa43462016-04-12 16:06:48 -070067import com.android.services.telephony.sip.SipUtil;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068
Jack Yu1a2fc352017-07-14 17:14:37 -070069import java.io.FileDescriptor;
70import java.io.PrintWriter;
71
Santos Cordon7d4ddf62013-07-10 11:58:08 -070072/**
73 * Global state for the telephony subsystem when running in the primary
74 * phone process.
75 */
Sailesh Nepalbf900542014-07-15 16:18:32 -070076public class PhoneGlobals extends ContextWrapper {
Jack Yu1a2fc352017-07-14 17:14:37 -070077 public static final String LOG_TAG = "PhoneGlobals";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070078
79 /**
80 * Phone app-wide debug level:
81 * 0 - no debug logging
82 * 1 - normal debug logging if ro.debuggable is set (which is true in
83 * "eng" and "userdebug" builds but not "user" builds)
84 * 2 - ultra-verbose debug logging
85 *
86 * Most individual classes in the phone app have a local DBG constant,
87 * typically set to
88 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
89 * or else
90 * (PhoneApp.DBG_LEVEL >= 2)
91 * depending on the desired verbosity.
92 *
93 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
94 */
Andrew Lee88b51e22014-10-29 15:48:51 -070095 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070096
97 private static final boolean DBG =
98 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
99 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
100
101 // Message codes; see mHandler below.
102 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700103 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
105 private static final int EVENT_DATA_ROAMING_OK = 11;
106 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 12;
Brad Ebinger3fa43462016-04-12 16:06:48 -0700107 private static final int EVENT_RESTART_SIP = 13;
Jack Yu1a2fc352017-07-14 17:14:37 -0700108 private static final int EVENT_DATA_ROAMING_SETTINGS_CHANGED = 14;
109 private static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED = 15;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700110
111 // The MMI codes are also used by the InCallScreen.
112 public static final int MMI_INITIATE = 51;
113 public static final int MMI_COMPLETE = 52;
114 public static final int MMI_CANCEL = 53;
115 // Don't use message codes larger than 99 here; those are reserved for
116 // the individual Activities of the Phone UI.
117
Santos Cordone18902f2016-03-22 17:16:04 -0700118 public static final int AIRPLANE_ON = 1;
119 public static final int AIRPLANE_OFF = 0;
120
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700121 /**
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
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133 private static PhoneGlobals sMe;
134
135 // A few important fields we expose to the rest of the package
136 // directly (rather than thru set/get methods) for efficiency.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137 CallController callController;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700139 CallNotifier notifier;
140 CallerInfoCache callerInfoCache;
Santos Cordon63a84242013-07-23 13:32:52 -0700141 NotificationMgr notificationMgr;
Andrew Lee9431b832015-03-09 18:46:45 -0700142 public PhoneInterfaceManager phoneMgr;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800143 CarrierConfigLoader configLoader;
Santos Cordon63a84242013-07-23 13:32:52 -0700144
Santos Cordon69a69192013-08-22 14:25:42 -0700145 private CallGatewayManager callGatewayManager;
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530146 private Phone phoneInEcm;
Santos Cordon63a84242013-07-23 13:32:52 -0700147
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700148 static boolean sVoiceCapable = true;
149
Santos Cordonc593d002015-06-03 15:41:15 -0700150 // TODO: Remove, no longer used.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700151 CdmaPhoneCallState cdmaPhoneCallState;
152
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700153 // The currently-active PUK entry activity and progress dialog.
154 // Normally, these are the Emergency Dialer and the subsequent
155 // progress dialog. null if there is are no such objects in
156 // the foreground.
157 private Activity mPUKEntryActivity;
158 private ProgressDialog mPUKEntryProgressDialog;
159
Jack Yu1a2fc352017-07-14 17:14:37 -0700160 private boolean mNoDataDueToRoaming = false;
Jack Yu953f9352017-05-18 14:41:06 -0700161
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162 private WakeState mWakeState = WakeState.SLEEP;
163
164 private PowerManager mPowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165 private PowerManager.WakeLock mWakeLock;
166 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700167 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700168
169 private UpdateLock mUpdateLock;
170
Jack Yu1a2fc352017-07-14 17:14:37 -0700171 private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
172 private final LocalLog mDataRoamingNotifLog = new LocalLog(50);
173
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174 // Broadcast receiver for various intent broadcasts (see onCreate())
175 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
176
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700177 private final CarrierVvmPackageInstalledReceiver mCarrierVvmPackageInstalledReceiver =
178 new CarrierVvmPackageInstalledReceiver();
179
Jack Yu1a2fc352017-07-14 17:14:37 -0700180 private final SettingsObserver mSettingsObserver;
181
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700182 Handler mHandler = new Handler() {
183 @Override
184 public void handleMessage(Message msg) {
185 PhoneConstants.State phoneState;
Jack Yu1a2fc352017-07-14 17:14:37 -0700186 if (VDBG) Log.v(LOG_TAG, "event=" + msg.what);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700187 switch (msg.what) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700188 // TODO: This event should be handled by the lock screen, just
189 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
190 case EVENT_SIM_NETWORK_LOCKED:
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700191 if (getCarrierConfig().getBoolean(
192 CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193 // Some products don't have the concept of a "SIM network lock"
194 Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; "
195 + "not showing 'SIM network unlock' PIN entry screen");
196 } else {
197 // Normal case: show the "SIM network unlock" PIN entry screen.
198 // The user won't be able to do anything else until
199 // they enter a valid SIM network PIN.
200 Log.i(LOG_TAG, "show sim depersonal panel");
Tyler Gunn52a37072015-08-24 14:23:19 -0700201 IccNetworkDepersonalizationPanel.showDialog();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700202 }
203 break;
204
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700205 case EVENT_DATA_ROAMING_DISCONNECTED:
206 notificationMgr.showDataDisconnectedRoaming();
207 break;
208
209 case EVENT_DATA_ROAMING_OK:
210 notificationMgr.hideDataDisconnectedRoaming();
211 break;
212
213 case MMI_COMPLETE:
214 onMMIComplete((AsyncResult) msg.obj);
215 break;
216
217 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800218 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700219 break;
220
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700221 case EVENT_SIM_STATE_CHANGED:
222 // Marks the event where the SIM goes into ready state.
223 // Right now, this is only used for the PUK-unlocking
224 // process.
225 if (msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_READY)) {
226 // when the right event is triggered and there
227 // are UI objects in the foreground, we close
228 // them to display the lock panel.
229 if (mPUKEntryActivity != null) {
230 mPUKEntryActivity.finish();
231 mPUKEntryActivity = null;
232 }
233 if (mPUKEntryProgressDialog != null) {
234 mPUKEntryProgressDialog.dismiss();
235 mPUKEntryProgressDialog = null;
236 }
237 }
238 break;
239
240 case EVENT_UNSOL_CDMA_INFO_RECORD:
241 //TODO: handle message here;
242 break;
Brad Ebinger3fa43462016-04-12 16:06:48 -0700243 case EVENT_RESTART_SIP:
244 // This should only run if the Phone process crashed and was restarted. We do
245 // not want this running if the device is still in the FBE encrypted state.
246 // This is the same procedure that is triggered in the SipBroadcastReceiver
247 // upon BOOT_COMPLETED.
248 UserManager userManager = UserManager.get(sMe);
249 if (userManager != null && userManager.isUserUnlocked()) {
250 SipUtil.startSipService();
251 }
252 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700253 case EVENT_DATA_ROAMING_SETTINGS_CHANGED:
254 case EVENT_MOBILE_DATA_SETTINGS_CHANGED:
255 updateDataRoamingStatus();
256 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700257 }
258 }
259 };
260
261 public PhoneGlobals(Context context) {
262 super(context);
263 sMe = this;
Jack Yu1a2fc352017-07-14 17:14:37 -0700264 mSettingsObserver = new SettingsObserver(context, mHandler);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700265 }
266
267 public void onCreate() {
268 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
269
270 ContentResolver resolver = getContentResolver();
271
272 // Cache the "voice capable" flag.
273 // This flag currently comes from a resource (which is
274 // overrideable on a per-product basis):
275 sVoiceCapable =
276 getResources().getBoolean(com.android.internal.R.bool.config_voice_capable);
277 // ...but this might eventually become a PackageManager "system
278 // feature" instead, in which case we'd do something like:
279 // sVoiceCapable =
280 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
281
Stuart Scottdcf40a92014-12-09 10:45:01 -0800282 if (mCM == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700283 // Initialize the telephony framework
284 PhoneFactory.makeDefaultPhones(this);
285
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700286 // Start TelephonyDebugService After the default phone is created.
287 Intent intent = new Intent(this, TelephonyDebugService.class);
288 startService(intent);
289
290 mCM = CallManager.getInstance();
Stuart Scottdcf40a92014-12-09 10:45:01 -0800291 for (Phone phone : PhoneFactory.getPhones()) {
292 mCM.registerPhone(phone);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800293 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700294
295 // Create the NotificationMgr singleton, which is used to display
296 // status bar icons and control other status bar behavior.
297 notificationMgr = NotificationMgr.init(this);
298
Brad Ebinger3fa43462016-04-12 16:06:48 -0700299 // If PhoneGlobals has crashed and is being restarted, then restart.
300 mHandler.sendEmptyMessage(EVENT_RESTART_SIP);
301
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700302 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
303 cdmaPhoneCallState = new CdmaPhoneCallState();
304 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700305
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700306 // before registering for phone state changes
307 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
308 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
309 // lock used to keep the processor awake, when we don't care for the display.
310 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
311 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700312
313 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
314
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700315 // Get UpdateLock to suppress system-update related events (e.g. dialog show-up)
316 // during phone calls.
317 mUpdateLock = new UpdateLock("phone");
318
319 if (DBG) Log.d(LOG_TAG, "onCreate: mUpdateLock: " + mUpdateLock);
320
321 CallLogger callLogger = new CallLogger(this, new CallLogAsync());
322
Jay Shrauner21a75342013-11-25 16:14:43 -0800323 callGatewayManager = CallGatewayManager.getInstance();
Santos Cordon69a69192013-08-22 14:25:42 -0700324
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700325 // Create the CallController singleton, which is the interface
326 // to the telephony layer for user-initiated telephony functionality
327 // (like making outgoing calls.)
Santos Cordon69a69192013-08-22 14:25:42 -0700328 callController = CallController.init(this, callLogger, callGatewayManager);
329
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700330 // Create the CallerInfoCache singleton, which remembers custom ring tone and
331 // send-to-voicemail settings.
332 //
333 // The asynchronous caching will start just after this call.
334 callerInfoCache = CallerInfoCache.init(this);
335
Stuart Scottdcf40a92014-12-09 10:45:01 -0800336 phoneMgr = PhoneInterfaceManager.init(this, PhoneFactory.getDefaultPhone());
Santos Cordon406c0342013-08-28 00:07:47 -0700337
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800338 configLoader = CarrierConfigLoader.init(this);
339
Jack Yu1a2fc352017-07-14 17:14:37 -0700340 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700341 // asynchronous events from the telephony layer (like
342 // launching the incoming-call UI when an incoming call comes
343 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800344 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700345
Stuart Scottdcf40a92014-12-09 10:45:01 -0800346 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700347
348 // register for MMI/USSD
349 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
350
351 // register connection tracking to PhoneUtils
352 PhoneUtils.initializeConnectionHandler(mCM);
353
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354 // Register for misc other intent broadcasts.
355 IntentFilter intentFilter =
356 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
358 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
359 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
360 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700361 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
362 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700363 registerReceiver(mReceiver, intentFilter);
364
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700365 mCarrierVvmPackageInstalledReceiver.register(this);
366
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367 //set the default values for the preferences in the phone.
pkanward702e542017-02-08 15:44:54 -0800368 PreferenceManager.setDefaultValues(this, R.xml.network_setting_fragment, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369
370 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
371
372 // Make sure the audio mode (along with some
373 // audio-mode-related state of our own) is initialized
374 // correctly, given the current state of the phone.
375 PhoneUtils.setAudioMode(mCM);
376 }
377
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700378 // XXX pre-load the SimProvider so that it's ready
379 resolver.getType(Uri.parse("content://icc/adn"));
380
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 // TODO: Register for Cdma Information Records
382 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
383
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384 // Read HAC settings and configure audio hardware
385 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800386 int hac = android.provider.Settings.System.getInt(
387 getContentResolver(),
388 android.provider.Settings.System.HEARING_AID,
389 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700390 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Andrew Leefb7f92e2015-02-26 16:23:32 -0800391 audioManager.setParameter(SettingsConstants.HAC_KEY,
392 hac == SettingsConstants.HAC_ENABLED
393 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394 }
Santos Cordonff506f52013-11-21 19:13:19 -0800395 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700396
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397 /**
398 * Returns the singleton instance of the PhoneApp.
399 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800400 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401 if (sMe == null) {
402 throw new IllegalStateException("No PhoneGlobals here!");
403 }
404 return sMe;
405 }
406
407 /**
408 * Returns the singleton instance of the PhoneApp if running as the
409 * primary user, otherwise null.
410 */
411 static PhoneGlobals getInstanceIfPrimary() {
412 return sMe;
413 }
414
415 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800416 * Returns the default phone.
417 *
Andrew Lee385019f2014-11-24 14:19:50 -0800418 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700419 */
Andrew Lee83383e42014-10-31 12:42:28 -0700420 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800421 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700422 }
423
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800424 public static Phone getPhone(int subId) {
425 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800426 }
427
Santos Cordonde10b752013-09-19 04:11:33 -0700428 /* package */ CallManager getCallManager() {
429 return mCM;
430 }
431
Chris Manton4e9fa912015-06-19 11:26:57 -0700432 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800433 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700434 }
435
Chris Manton4e9fa912015-06-19 11:26:57 -0700436 public PersistableBundle getCarrierConfigForSubId(int subId) {
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700437 return configLoader.getConfigForSubId(subId);
Junda Liu605148f2015-04-28 15:23:40 -0700438 }
439
Jack Yu1a2fc352017-07-14 17:14:37 -0700440 private void registerSettingsObserver() {
441 mSettingsObserver.unobserve();
442 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
443 String mobileDataSetting = Settings.Global.MOBILE_DATA;
444 if (TelephonyManager.getDefault().getSimCount() > 1) {
445 int subId = mDefaultDataSubId;
446 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
447 dataRoamingSetting += subId;
448 mobileDataSetting += subId;
449 }
450 }
451
452 // Listen for user data roaming setting changed event
453 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
454 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
455
456 // Listen for mobile data setting changed event
457 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
458 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
459 }
460
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700461 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700462 * Sets the activity responsible for un-PUK-blocking the device
463 * so that we may close it when we receive a positive result.
464 * mPUKEntryActivity is also used to indicate to the device that
465 * we are trying to un-PUK-lock the phone. In other words, iff
466 * it is NOT null, then we are trying to unlock and waiting for
467 * the SIM to move to READY state.
468 *
469 * @param activity is the activity to close when PUK has
470 * finished unlocking. Can be set to null to indicate the unlock
471 * or SIM READYing process is over.
472 */
473 void setPukEntryActivity(Activity activity) {
474 mPUKEntryActivity = activity;
475 }
476
477 Activity getPUKEntryActivity() {
478 return mPUKEntryActivity;
479 }
480
481 /**
482 * Sets the dialog responsible for notifying the user of un-PUK-
483 * blocking - SIM READYing progress, so that we may dismiss it
484 * when we receive a positive result.
485 *
486 * @param dialog indicates the progress dialog informing the user
487 * of the state of the device. Dismissed upon completion of
488 * READYing process
489 */
490 void setPukEntryProgressDialog(ProgressDialog dialog) {
491 mPUKEntryProgressDialog = dialog;
492 }
493
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700494 /**
495 * Controls whether or not the screen is allowed to sleep.
496 *
497 * Once sleep is allowed (WakeState is SLEEP), it will rely on the
498 * settings for the poke lock to determine when to timeout and let
499 * the device sleep {@link PhoneGlobals#setScreenTimeout}.
500 *
501 * @param ws tells the device to how to wake.
502 */
503 /* package */ void requestWakeState(WakeState ws) {
504 if (VDBG) Log.d(LOG_TAG, "requestWakeState(" + ws + ")...");
505 synchronized (this) {
506 if (mWakeState != ws) {
507 switch (ws) {
508 case PARTIAL:
509 // acquire the processor wake lock, and release the FULL
510 // lock if it is being held.
511 mPartialWakeLock.acquire();
512 if (mWakeLock.isHeld()) {
513 mWakeLock.release();
514 }
515 break;
516 case FULL:
517 // acquire the full wake lock, and release the PARTIAL
518 // lock if it is being held.
519 mWakeLock.acquire();
520 if (mPartialWakeLock.isHeld()) {
521 mPartialWakeLock.release();
522 }
523 break;
524 case SLEEP:
525 default:
526 // release both the PARTIAL and FULL locks.
527 if (mWakeLock.isHeld()) {
528 mWakeLock.release();
529 }
530 if (mPartialWakeLock.isHeld()) {
531 mPartialWakeLock.release();
532 }
533 break;
534 }
535 mWakeState = ws;
536 }
537 }
538 }
539
540 /**
541 * If we are not currently keeping the screen on, then poke the power
542 * manager to wake up the screen for the user activity timeout duration.
543 */
544 /* package */ void wakeUpScreen() {
545 synchronized (this) {
546 if (mWakeState == WakeState.SLEEP) {
547 if (DBG) Log.d(LOG_TAG, "pulse screen lock");
Dianne Hackborn148769b2015-07-13 17:55:47 -0700548 mPowerManager.wakeUp(SystemClock.uptimeMillis(), "android.phone:WAKE");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700549 }
550 }
551 }
552
553 /**
554 * Sets the wake state and screen timeout based on the current state
555 * of the phone, and the current state of the in-call UI.
556 *
557 * This method is a "UI Policy" wrapper around
558 * {@link PhoneGlobals#requestWakeState} and {@link PhoneGlobals#setScreenTimeout}.
559 *
560 * It's safe to call this method regardless of the state of the Phone
561 * (e.g. whether or not it's idle), and regardless of the state of the
562 * Phone UI (e.g. whether or not the InCallScreen is active.)
563 */
564 /* package */ void updateWakeState() {
565 PhoneConstants.State state = mCM.getState();
566
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700567 // True if the speakerphone is in use. (If so, we *always* use
568 // the default timeout. Since the user is obviously not holding
569 // the phone up to his/her face, we don't need to worry about
570 // false touches, and thus don't need to turn the screen off so
571 // aggressively.)
572 // Note that we need to make a fresh call to this method any
573 // time the speaker state changes. (That happens in
574 // PhoneUtils.turnOnSpeaker().)
575 boolean isSpeakerInUse = (state == PhoneConstants.State.OFFHOOK) && PhoneUtils.isSpeakerOn(this);
576
577 // TODO (bug 1440854): The screen timeout *might* also need to
578 // depend on the bluetooth state, but this isn't as clear-cut as
579 // the speaker state (since while using BT it's common for the
580 // user to put the phone straight into a pocket, in which case the
581 // timeout should probably still be short.)
582
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700583 // Decide whether to force the screen on or not.
584 //
585 // Force the screen to be on if the phone is ringing or dialing,
586 // or if we're displaying the "Call ended" UI for a connection in
587 // the "disconnected" state.
588 // However, if the phone is disconnected while the user is in the
589 // middle of selecting a quick response message, we should not force
590 // the screen to be on.
591 //
592 boolean isRinging = (state == PhoneConstants.State.RINGING);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800593 boolean isDialing = (mCM.getFgPhone().getForegroundCall().getState() == Call.State.DIALING);
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700594 boolean keepScreenOn = isRinging || isDialing;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700595 // keepScreenOn == true means we'll hold a full wake lock:
596 requestWakeState(keepScreenOn ? WakeState.FULL : WakeState.SLEEP);
597 }
598
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700599 KeyguardManager getKeyguardManager() {
600 return mKeyguardManager;
601 }
602
603 private void onMMIComplete(AsyncResult r) {
604 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
605 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800606 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700607 }
608
fionaxu80126972017-02-01 17:01:26 -0800609 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700610 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700611 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700612 }
613
Chris Mantona09f3632016-02-09 14:48:42 -0800614 private void handleAirplaneModeChange(Context context, int newMode) {
615 int cellState = Settings.Global.getInt(context.getContentResolver(),
616 Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
617 boolean isAirplaneNewlyOn = (newMode == 1);
618 switch (cellState) {
619 case PhoneConstants.CELL_OFF_FLAG:
620 // Airplane mode does not affect the cell radio if user
621 // has turned it off.
622 break;
623 case PhoneConstants.CELL_ON_FLAG:
624 maybeTurnCellOff(context, isAirplaneNewlyOn);
625 break;
626 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
627 maybeTurnCellOn(context, isAirplaneNewlyOn);
628 break;
629 }
630 }
631
632 /*
633 * Returns true if the radio must be turned off when entering airplane mode.
634 */
635 private boolean isCellOffInAirplaneMode(Context context) {
636 String airplaneModeRadios = Settings.Global.getString(context.getContentResolver(),
637 Settings.Global.AIRPLANE_MODE_RADIOS);
638 return airplaneModeRadios == null
639 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
640 }
641
642 private void setRadioPowerOff(Context context) {
643 Log.i(LOG_TAG, "Turning radio off - airplane");
644 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
645 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Sooraj Sasindran798bafa2017-04-03 22:49:00 -0700646 SystemProperties.set("persist.radio.airplane_mode_on", "1");
Chris Mantona09f3632016-02-09 14:48:42 -0800647 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
648 PhoneUtils.setRadioPower(false);
649 }
650
651 private void setRadioPowerOn(Context context) {
652 Log.i(LOG_TAG, "Turning radio on - airplane");
653 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
654 PhoneConstants.CELL_ON_FLAG);
655 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT,
656 1);
Sooraj Sasindran798bafa2017-04-03 22:49:00 -0700657 SystemProperties.set("persist.radio.airplane_mode_on", "0");
Chris Mantona09f3632016-02-09 14:48:42 -0800658 PhoneUtils.setRadioPower(true);
659 }
660
661 private void maybeTurnCellOff(Context context, boolean isAirplaneNewlyOn) {
662 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700663 // If we are trying to turn off the radio, make sure there are no active
664 // emergency calls. If there are, switch airplane mode back to off.
665 if (PhoneUtils.isInEmergencyCall(mCM)) {
666 // Switch airplane mode back to off.
667 ConnectivityManager.from(this).setAirplaneMode(false);
668 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
669 .show();
670 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Chris Mantona09f3632016-02-09 14:48:42 -0800671 } else if (isCellOffInAirplaneMode(context)) {
672 setRadioPowerOff(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700673 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800674 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700675 }
Chris Mantona09f3632016-02-09 14:48:42 -0800676 }
677 }
678
679 private void maybeTurnCellOn(Context context, boolean isAirplaneNewlyOn) {
680 if (!isAirplaneNewlyOn) {
681 setRadioPowerOn(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700682 }
683 }
684
Santos Cordon593ab382013-08-06 21:58:23 -0700685 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700686 * Receiver for misc intent broadcasts the Phone app cares about.
687 */
688 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
689 @Override
690 public void onReceive(Context context, Intent intent) {
691 String action = intent.getAction();
692 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Santos Cordone18902f2016-03-22 17:16:04 -0700693 int airplaneMode = Settings.Global.getInt(getContentResolver(),
694 Settings.Global.AIRPLANE_MODE_ON, AIRPLANE_OFF);
695 // Treat any non-OFF values as ON.
696 if (airplaneMode != AIRPLANE_OFF) {
697 airplaneMode = AIRPLANE_ON;
698 }
Chris Mantona09f3632016-02-09 14:48:42 -0800699 handleAirplaneModeChange(context, airplaneMode);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700700 } else if ((action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) &&
701 (mPUKEntryActivity != null)) {
702 // if an attempt to un-PUK-lock the device was made, while we're
703 // receiving this state change notification, notify the handler.
704 // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has
705 // been attempted.
706 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
707 intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE)));
708 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
709 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800710 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
711 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700712 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
713 handleServiceStateChanged(intent);
714 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530715 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530716 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530717 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
718 if (phoneInEcm != null) {
719 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
720 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
721 // Start Emergency Callback Mode service
722 if (intent.getBooleanExtra("phoneinECMState", false)) {
723 context.startService(new Intent(context,
724 EmergencyCallbackModeService.class));
725 } else {
726 phoneInEcm = null;
727 }
728 } else {
729 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
730 // on a device that doesn't support ECM in the first place.
731 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
732 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
733 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700734 }
735 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530736 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700737 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700738 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
739 // Roaming status could be overridden by carrier config, so we need to update it.
740 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
741 updateDataRoamingStatus();
742 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
743 // We also need to pay attention when default data subscription changes.
744 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
745 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
746 registerSettingsObserver();
747 Phone phone = getPhone(mDefaultDataSubId);
748 if (phone != null) {
749 updateDataRoamingStatus();
750 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700751 }
752 }
753 }
754
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700755 private void handleServiceStateChanged(Intent intent) {
756 /**
757 * This used to handle updating EriTextWidgetProvider this routine
758 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
759 * be removed. But leaving just in case it might be needed in the near
760 * future.
761 */
762
Jack Yu1a2fc352017-07-14 17:14:37 -0700763 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700764 // If service just returned, start sending out the queued messages
Santos Cordonc593d002015-06-03 15:41:15 -0700765 Bundle extras = intent.getExtras();
766 if (extras != null) {
767 ServiceState ss = ServiceState.newFromBundle(extras);
768 if (ss != null) {
769 int state = ss.getState();
Jayachandran C2ef9a482017-05-12 22:07:47 -0700770 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
771 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
772 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -0700773
774 if (VDBG) {
775 Log.v(LOG_TAG, "subId=" + subId + ",mDefaultDataSubId="
776 + mDefaultDataSubId + ",ss roaming=" + ss.getDataRoaming());
777 }
778 if (subId == mDefaultDataSubId) {
779 updateDataRoamingStatus();
780 }
Santos Cordonc593d002015-06-03 15:41:15 -0700781 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700782 }
783 }
784
Jack Yu1a2fc352017-07-14 17:14:37 -0700785 /**
786 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
787 * to notify the user so they can enable it through settings. Vise versa if the condition
788 * changes, we need to dismiss the notification.
789 */
790 private void updateDataRoamingStatus() {
791 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
792 Phone phone = getPhone(mDefaultDataSubId);
793 if (phone == null) {
794 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
795 return;
796 }
797
798 DataConnectionReasons reasons = new DataConnectionReasons();
799 boolean dataAllowed = phone.isDataAllowed(reasons);
800 mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons);
801 if (VDBG) Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons);
802 if (!mNoDataDueToRoaming
803 && !dataAllowed
804 && reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED)) {
805 // If the only reason of no data is data roaming disabled, then we notify the user
806 // so the user can turn on data roaming.
807 mNoDataDueToRoaming = true;
808 Log.d(LOG_TAG, "Show roaming disconnected notification");
809 mDataRoamingNotifLog.log("Show");
810 mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_DISCONNECTED);
811 } else if (mNoDataDueToRoaming && (dataAllowed
812 || !reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED))) {
813 // Otherwise dismiss the notification we showed earlier.
814 mNoDataDueToRoaming = false;
815 Log.d(LOG_TAG, "Dismiss roaming disconnected notification");
816 mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed + ", reasons=" + reasons);
817 mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
818 }
819 }
820
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530821 public Phone getPhoneInEcm() {
822 return phoneInEcm;
823 }
824
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700825 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800826 * Triggers a refresh of the message waiting (voicemail) indicator.
827 *
828 * @param subId the subscription id we should refresh the notification for.
829 */
830 public void refreshMwiIndicator(int subId) {
831 notificationMgr.refreshMwi(subId);
832 }
833
834 /**
Nancy Chenbb49d412015-07-23 13:54:16 -0700835 * Dismisses the message waiting (voicemail) indicator.
836 *
837 * @param subId the subscription id we should dismiss the notification for.
838 */
839 public void clearMwiIndicator(int subId) {
Ta-wei Yen63106682016-07-11 14:11:27 -0700840 // Setting voiceMessageCount to 0 will remove the current notification and clear the system
841 // cached value.
Ta-wei Yen7df340d2016-07-25 10:59:53 -0700842 Phone phone = getPhone(subId);
843 if (phone == null) {
844 Log.w(LOG_TAG, "clearMwiIndicator on null phone, subId:" + subId);
845 } else {
846 phone.setVoiceMessageCount(0);
847 }
Nancy Chenbb49d412015-07-23 13:54:16 -0700848 }
Ta-wei Yenb29425b2016-09-21 17:28:14 -0700849
850 /**
851 * Enables or disables the visual voicemail check for message waiting indicator. Default value
852 * is true. MWI is the traditional voicemail notification which should be suppressed if visual
853 * voicemail is active. {@link NotificationMgr#updateMwi(int, boolean, boolean)} currently
854 * checks the {@link android.provider.VoicemailContract.Status#CONFIGURATION_STATE} to suppress
855 * the MWI, but there are several issues. b/31229016 is a bug that when the device boots the
856 * configuration state will be cleared and the MWI for voicemail that arrives when the device
857 * is offline will be cleared, even if the account cannot be activated. A full solution will be
858 * adding a setMwiEnabled() method and stop checking the configuration state, but that is too
859 * risky at this moment. This is a temporary workaround to shut down the configuration state
860 * check if visual voicemail cannot be activated.
861 * <p>TODO(twyen): implement the setMwiEnabled() mentioned above.
862 *
863 * @param subId the account to set the enabled state
864 */
865 public void setShouldCheckVisualVoicemailConfigurationForMwi(int subId, boolean enabled) {
866 notificationMgr.setShouldCheckVisualVoicemailConfigurationForMwi(subId, enabled);
867 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700868
869 /**
870 * Dump the state of the object, add calls to other objects as desired.
871 *
872 * @param fd File descriptor
873 * @param printWriter Print writer
874 * @param args Arguments
875 */
876 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
877 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
878 pw.println("------- PhoneGlobals -------");
879 pw.increaseIndent();
880 pw.println("mNoDataDueToRoaming=" + mNoDataDueToRoaming);
881 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
882 pw.println("mDataRoamingNotifLog:");
883 pw.increaseIndent();
884 mDataRoamingNotifLog.dump(fd, pw, args);
885 pw.decreaseIndent();
886 pw.decreaseIndent();
887 pw.println("------- End PhoneGlobals -------");
888 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700889}