blob: 16c6bf7f08a3572407bf74b12313a974a3611b8c [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;
Brad Ebinger533c6c12017-08-02 11:38:48 -070031import android.net.sip.SipManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.os.AsyncResult;
Junda Liu605148f2015-04-28 15:23:40 -070033import android.os.Bundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070034import android.os.Handler;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.os.Message;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070036import android.os.PersistableBundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.os.PowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.SystemClock;
39import android.os.SystemProperties;
40import android.os.UpdateLock;
Brad Ebinger3fa43462016-04-12 16:06:48 -070041import android.os.UserManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.preference.PreferenceManager;
Sanket Padawe4c699232016-02-09 11:07:22 -080043import android.provider.Settings;
Junda Liu12f7d802015-05-01 12:06:44 -070044import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.telephony.ServiceState;
Andrew Lee385019f2014-11-24 14:19:50 -080046import android.telephony.SubscriptionManager;
Jack Yu1a2fc352017-07-14 17:14:37 -070047import android.telephony.TelephonyManager;
48import android.util.LocalLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.util.Log;
Santos Cordone18902f2016-03-22 17:16:04 -070050import android.widget.Toast;
Ta-wei Yenb29425b2016-09-21 17:28:14 -070051
Eric Erfanianc712d4b2018-01-03 16:36:14 -080052import com.android.i18n.phonenumbers.PhoneNumberUtil;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import com.android.internal.telephony.Call;
54import com.android.internal.telephony.CallManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import com.android.internal.telephony.IccCardConstants;
56import com.android.internal.telephony.MmiCode;
57import com.android.internal.telephony.Phone;
58import com.android.internal.telephony.PhoneConstants;
59import com.android.internal.telephony.PhoneFactory;
Jack Yu1a2fc352017-07-14 17:14:37 -070060import com.android.internal.telephony.SettingsObserver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070061import com.android.internal.telephony.TelephonyCapabilities;
62import com.android.internal.telephony.TelephonyIntents;
Jack Yu1a2fc352017-07-14 17:14:37 -070063import com.android.internal.telephony.dataconnection.DataConnectionReasons;
64import com.android.internal.telephony.dataconnection.DataConnectionReasons.DataDisallowedReasonType;
65import com.android.internal.util.IndentingPrintWriter;
Santos Cordon352ff652014-05-30 01:41:45 -070066import com.android.phone.common.CallLogAsync;
Andrew Leefb7f92e2015-02-26 16:23:32 -080067import com.android.phone.settings.SettingsConstants;
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -070068import com.android.phone.vvm.CarrierVvmPackageInstalledReceiver;
Brad Ebinger28626122017-08-10 14:13:35 -070069import com.android.services.telephony.sip.SipAccountRegistry;
Brad Ebinger3fa43462016-04-12 16:06:48 -070070import com.android.services.telephony.sip.SipUtil;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070071
Jack Yu1a2fc352017-07-14 17:14:37 -070072import java.io.FileDescriptor;
73import java.io.PrintWriter;
74
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075/**
76 * Global state for the telephony subsystem when running in the primary
77 * phone process.
78 */
Sailesh Nepalbf900542014-07-15 16:18:32 -070079public class PhoneGlobals extends ContextWrapper {
Jack Yu1a2fc352017-07-14 17:14:37 -070080 public static final String LOG_TAG = "PhoneGlobals";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081
82 /**
83 * Phone app-wide debug level:
84 * 0 - no debug logging
85 * 1 - normal debug logging if ro.debuggable is set (which is true in
86 * "eng" and "userdebug" builds but not "user" builds)
87 * 2 - ultra-verbose debug logging
88 *
89 * Most individual classes in the phone app have a local DBG constant,
90 * typically set to
91 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
92 * or else
93 * (PhoneApp.DBG_LEVEL >= 2)
94 * depending on the desired verbosity.
95 *
96 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
97 */
Andrew Lee88b51e22014-10-29 15:48:51 -070098 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099
100 private static final boolean DBG =
101 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
102 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
103
104 // Message codes; see mHandler below.
105 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
108 private static final int EVENT_DATA_ROAMING_OK = 11;
109 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 12;
Brad Ebinger3fa43462016-04-12 16:06:48 -0700110 private static final int EVENT_RESTART_SIP = 13;
Jack Yu1a2fc352017-07-14 17:14:37 -0700111 private static final int EVENT_DATA_ROAMING_SETTINGS_CHANGED = 14;
112 private static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED = 15;
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
Santos Cordone18902f2016-03-22 17:16:04 -0700121 public static final int AIRPLANE_ON = 1;
122 public static final int AIRPLANE_OFF = 0;
123
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700124 /**
125 * Allowable values for the wake lock code.
126 * SLEEP means the device can be put to sleep.
127 * PARTIAL means wake the processor, but we display can be kept off.
128 * FULL means wake both the processor and the display.
129 */
130 public enum WakeState {
131 SLEEP,
132 PARTIAL,
133 FULL
134 }
135
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136 private static PhoneGlobals sMe;
137
138 // A few important fields we expose to the rest of the package
139 // directly (rather than thru set/get methods) for efficiency.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140 CallController callController;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700142 CallNotifier notifier;
143 CallerInfoCache callerInfoCache;
Santos Cordon63a84242013-07-23 13:32:52 -0700144 NotificationMgr notificationMgr;
Andrew Lee9431b832015-03-09 18:46:45 -0700145 public PhoneInterfaceManager phoneMgr;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800146 CarrierConfigLoader configLoader;
Santos Cordon63a84242013-07-23 13:32:52 -0700147
Santos Cordon69a69192013-08-22 14:25:42 -0700148 private CallGatewayManager callGatewayManager;
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530149 private Phone phoneInEcm;
Santos Cordon63a84242013-07-23 13:32:52 -0700150
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700151 static boolean sVoiceCapable = true;
152
Santos Cordonc593d002015-06-03 15:41:15 -0700153 // TODO: Remove, no longer used.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154 CdmaPhoneCallState cdmaPhoneCallState;
155
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700156 // The currently-active PUK entry activity and progress dialog.
157 // Normally, these are the Emergency Dialer and the subsequent
158 // progress dialog. null if there is are no such objects in
159 // the foreground.
160 private Activity mPUKEntryActivity;
161 private ProgressDialog mPUKEntryProgressDialog;
162
Jack Yu1a2fc352017-07-14 17:14:37 -0700163 private boolean mNoDataDueToRoaming = false;
Jack Yu953f9352017-05-18 14:41:06 -0700164
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165 private WakeState mWakeState = WakeState.SLEEP;
166
167 private PowerManager mPowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700168 private PowerManager.WakeLock mWakeLock;
169 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700170 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171
172 private UpdateLock mUpdateLock;
173
Jack Yu1a2fc352017-07-14 17:14:37 -0700174 private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
175 private final LocalLog mDataRoamingNotifLog = new LocalLog(50);
176
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700177 // Broadcast receiver for various intent broadcasts (see onCreate())
178 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
Brad Ebinger533c6c12017-08-02 11:38:48 -0700179 // Broadcast receiver for SIP based intents (see onCreate())
Brad Ebinger28626122017-08-10 14:13:35 -0700180 private final SipReceiver mSipReceiver = new SipReceiver();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700181
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700182 private final CarrierVvmPackageInstalledReceiver mCarrierVvmPackageInstalledReceiver =
183 new CarrierVvmPackageInstalledReceiver();
184
Jack Yu1a2fc352017-07-14 17:14:37 -0700185 private final SettingsObserver mSettingsObserver;
186
Eric Erfanianc712d4b2018-01-03 16:36:14 -0800187 private final PhoneNumberUtil mPhoneNumberUtil = PhoneNumberUtil.getInstance();
188
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700189 Handler mHandler = new Handler() {
190 @Override
191 public void handleMessage(Message msg) {
192 PhoneConstants.State phoneState;
Jack Yu1a2fc352017-07-14 17:14:37 -0700193 if (VDBG) Log.v(LOG_TAG, "event=" + msg.what);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194 switch (msg.what) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195 // TODO: This event should be handled by the lock screen, just
196 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
197 case EVENT_SIM_NETWORK_LOCKED:
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700198 if (getCarrierConfig().getBoolean(
199 CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700200 // Some products don't have the concept of a "SIM network lock"
201 Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; "
Eric Erfanianc712d4b2018-01-03 16:36:14 -0800202 + "not showing 'SIM network unlock' PIN entry screen");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700203 } else {
204 // Normal case: show the "SIM network unlock" PIN entry screen.
205 // The user won't be able to do anything else until
206 // they enter a valid SIM network PIN.
207 Log.i(LOG_TAG, "show sim depersonal panel");
Tyler Gunn52a37072015-08-24 14:23:19 -0700208 IccNetworkDepersonalizationPanel.showDialog();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700209 }
210 break;
211
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700212 case EVENT_DATA_ROAMING_DISCONNECTED:
Pengquan Meng8783d932017-10-16 14:57:40 -0700213 notificationMgr.showDataDisconnectedRoaming(msg.arg1);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700214 break;
215
216 case EVENT_DATA_ROAMING_OK:
217 notificationMgr.hideDataDisconnectedRoaming();
218 break;
219
220 case MMI_COMPLETE:
221 onMMIComplete((AsyncResult) msg.obj);
222 break;
223
224 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800225 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700226 break;
227
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228 case EVENT_SIM_STATE_CHANGED:
229 // Marks the event where the SIM goes into ready state.
230 // Right now, this is only used for the PUK-unlocking
231 // process.
232 if (msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_READY)) {
233 // when the right event is triggered and there
234 // are UI objects in the foreground, we close
235 // them to display the lock panel.
236 if (mPUKEntryActivity != null) {
237 mPUKEntryActivity.finish();
238 mPUKEntryActivity = null;
239 }
240 if (mPUKEntryProgressDialog != null) {
241 mPUKEntryProgressDialog.dismiss();
242 mPUKEntryProgressDialog = null;
243 }
244 }
245 break;
246
247 case EVENT_UNSOL_CDMA_INFO_RECORD:
248 //TODO: handle message here;
249 break;
Brad Ebinger3fa43462016-04-12 16:06:48 -0700250 case EVENT_RESTART_SIP:
251 // This should only run if the Phone process crashed and was restarted. We do
252 // not want this running if the device is still in the FBE encrypted state.
Brad Ebinger28626122017-08-10 14:13:35 -0700253 // This is the same procedure that is triggered in the SipIncomingCallReceiver
Brad Ebinger3fa43462016-04-12 16:06:48 -0700254 // upon BOOT_COMPLETED.
255 UserManager userManager = UserManager.get(sMe);
256 if (userManager != null && userManager.isUserUnlocked()) {
257 SipUtil.startSipService();
258 }
259 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700260 case EVENT_DATA_ROAMING_SETTINGS_CHANGED:
261 case EVENT_MOBILE_DATA_SETTINGS_CHANGED:
262 updateDataRoamingStatus();
263 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700264 }
265 }
266 };
267
268 public PhoneGlobals(Context context) {
269 super(context);
270 sMe = this;
Jack Yu1a2fc352017-07-14 17:14:37 -0700271 mSettingsObserver = new SettingsObserver(context, mHandler);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700272 }
273
274 public void onCreate() {
275 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
276
277 ContentResolver resolver = getContentResolver();
278
279 // Cache the "voice capable" flag.
280 // This flag currently comes from a resource (which is
281 // overrideable on a per-product basis):
282 sVoiceCapable =
283 getResources().getBoolean(com.android.internal.R.bool.config_voice_capable);
284 // ...but this might eventually become a PackageManager "system
285 // feature" instead, in which case we'd do something like:
286 // sVoiceCapable =
287 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
288
Stuart Scottdcf40a92014-12-09 10:45:01 -0800289 if (mCM == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700290 // Initialize the telephony framework
291 PhoneFactory.makeDefaultPhones(this);
292
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700293 // Start TelephonyDebugService After the default phone is created.
294 Intent intent = new Intent(this, TelephonyDebugService.class);
295 startService(intent);
296
297 mCM = CallManager.getInstance();
Stuart Scottdcf40a92014-12-09 10:45:01 -0800298 for (Phone phone : PhoneFactory.getPhones()) {
299 mCM.registerPhone(phone);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800300 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700301
302 // Create the NotificationMgr singleton, which is used to display
303 // status bar icons and control other status bar behavior.
304 notificationMgr = NotificationMgr.init(this);
305
Brad Ebinger3fa43462016-04-12 16:06:48 -0700306 // If PhoneGlobals has crashed and is being restarted, then restart.
307 mHandler.sendEmptyMessage(EVENT_RESTART_SIP);
308
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700309 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
310 cdmaPhoneCallState = new CdmaPhoneCallState();
311 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700312
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700313 // before registering for phone state changes
314 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
315 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
316 // lock used to keep the processor awake, when we don't care for the display.
317 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
318 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700319
320 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
321
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700322 // Get UpdateLock to suppress system-update related events (e.g. dialog show-up)
323 // during phone calls.
324 mUpdateLock = new UpdateLock("phone");
325
326 if (DBG) Log.d(LOG_TAG, "onCreate: mUpdateLock: " + mUpdateLock);
327
328 CallLogger callLogger = new CallLogger(this, new CallLogAsync());
329
Jay Shrauner21a75342013-11-25 16:14:43 -0800330 callGatewayManager = CallGatewayManager.getInstance();
Santos Cordon69a69192013-08-22 14:25:42 -0700331
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332 // Create the CallController singleton, which is the interface
333 // to the telephony layer for user-initiated telephony functionality
334 // (like making outgoing calls.)
Santos Cordon69a69192013-08-22 14:25:42 -0700335 callController = CallController.init(this, callLogger, callGatewayManager);
336
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700337 // Create the CallerInfoCache singleton, which remembers custom ring tone and
338 // send-to-voicemail settings.
339 //
340 // The asynchronous caching will start just after this call.
341 callerInfoCache = CallerInfoCache.init(this);
342
Stuart Scottdcf40a92014-12-09 10:45:01 -0800343 phoneMgr = PhoneInterfaceManager.init(this, PhoneFactory.getDefaultPhone());
Santos Cordon406c0342013-08-28 00:07:47 -0700344
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800345 configLoader = CarrierConfigLoader.init(this);
346
Jack Yu1a2fc352017-07-14 17:14:37 -0700347 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348 // asynchronous events from the telephony layer (like
349 // launching the incoming-call UI when an incoming call comes
350 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800351 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700352
Stuart Scottdcf40a92014-12-09 10:45:01 -0800353 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354
355 // register for MMI/USSD
356 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
357
358 // register connection tracking to PhoneUtils
359 PhoneUtils.initializeConnectionHandler(mCM);
360
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361 // Register for misc other intent broadcasts.
362 IntentFilter intentFilter =
363 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700364 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
365 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
366 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
367 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700368 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
369 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370 registerReceiver(mReceiver, intentFilter);
371
Brad Ebinger533c6c12017-08-02 11:38:48 -0700372 IntentFilter sipIntentFilter = new IntentFilter(Intent.ACTION_BOOT_COMPLETED);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700373 sipIntentFilter.addAction(SipManager.ACTION_SIP_SERVICE_UP);
374 sipIntentFilter.addAction(SipManager.ACTION_SIP_CALL_OPTION_CHANGED);
375 sipIntentFilter.addAction(SipManager.ACTION_SIP_REMOVE_PHONE);
Brad Ebinger28626122017-08-10 14:13:35 -0700376 registerReceiver(mSipReceiver, sipIntentFilter);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700377
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700378 mCarrierVvmPackageInstalledReceiver.register(this);
379
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380 //set the default values for the preferences in the phone.
pkanward702e542017-02-08 15:44:54 -0800381 PreferenceManager.setDefaultValues(this, R.xml.network_setting_fragment, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382
383 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
384
385 // Make sure the audio mode (along with some
386 // audio-mode-related state of our own) is initialized
387 // correctly, given the current state of the phone.
388 PhoneUtils.setAudioMode(mCM);
389 }
390
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700391 // XXX pre-load the SimProvider so that it's ready
392 resolver.getType(Uri.parse("content://icc/adn"));
393
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394 // TODO: Register for Cdma Information Records
395 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
396
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397 // Read HAC settings and configure audio hardware
398 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800399 int hac = android.provider.Settings.System.getInt(
400 getContentResolver(),
401 android.provider.Settings.System.HEARING_AID,
402 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700403 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Andrew Leefb7f92e2015-02-26 16:23:32 -0800404 audioManager.setParameter(SettingsConstants.HAC_KEY,
405 hac == SettingsConstants.HAC_ENABLED
406 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700407 }
Santos Cordonff506f52013-11-21 19:13:19 -0800408 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700410 /**
411 * Returns the singleton instance of the PhoneApp.
412 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800413 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700414 if (sMe == null) {
415 throw new IllegalStateException("No PhoneGlobals here!");
416 }
417 return sMe;
418 }
419
420 /**
421 * Returns the singleton instance of the PhoneApp if running as the
422 * primary user, otherwise null.
423 */
424 static PhoneGlobals getInstanceIfPrimary() {
425 return sMe;
426 }
427
428 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800429 * Returns the default phone.
430 *
Andrew Lee385019f2014-11-24 14:19:50 -0800431 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700432 */
Andrew Lee83383e42014-10-31 12:42:28 -0700433 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800434 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700435 }
436
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800437 public static Phone getPhone(int subId) {
438 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800439 }
440
Santos Cordonde10b752013-09-19 04:11:33 -0700441 /* package */ CallManager getCallManager() {
442 return mCM;
443 }
444
Eric Erfanianc712d4b2018-01-03 16:36:14 -0800445 public PhoneNumberUtil getPhoneNumberUtil() {
446 return mPhoneNumberUtil;
447 }
448
Chris Manton4e9fa912015-06-19 11:26:57 -0700449 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800450 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700451 }
452
Chris Manton4e9fa912015-06-19 11:26:57 -0700453 public PersistableBundle getCarrierConfigForSubId(int subId) {
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700454 return configLoader.getConfigForSubId(subId);
Junda Liu605148f2015-04-28 15:23:40 -0700455 }
456
Jack Yu1a2fc352017-07-14 17:14:37 -0700457 private void registerSettingsObserver() {
458 mSettingsObserver.unobserve();
459 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
460 String mobileDataSetting = Settings.Global.MOBILE_DATA;
461 if (TelephonyManager.getDefault().getSimCount() > 1) {
462 int subId = mDefaultDataSubId;
463 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
464 dataRoamingSetting += subId;
465 mobileDataSetting += subId;
466 }
467 }
468
469 // Listen for user data roaming setting changed event
470 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
471 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
472
473 // Listen for mobile data setting changed event
474 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
475 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
476 }
477
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700478 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700479 * Sets the activity responsible for un-PUK-blocking the device
480 * so that we may close it when we receive a positive result.
481 * mPUKEntryActivity is also used to indicate to the device that
482 * we are trying to un-PUK-lock the phone. In other words, iff
483 * it is NOT null, then we are trying to unlock and waiting for
484 * the SIM to move to READY state.
485 *
486 * @param activity is the activity to close when PUK has
487 * finished unlocking. Can be set to null to indicate the unlock
488 * or SIM READYing process is over.
489 */
490 void setPukEntryActivity(Activity activity) {
491 mPUKEntryActivity = activity;
492 }
493
494 Activity getPUKEntryActivity() {
495 return mPUKEntryActivity;
496 }
497
498 /**
499 * Sets the dialog responsible for notifying the user of un-PUK-
500 * blocking - SIM READYing progress, so that we may dismiss it
501 * when we receive a positive result.
502 *
503 * @param dialog indicates the progress dialog informing the user
504 * of the state of the device. Dismissed upon completion of
505 * READYing process
506 */
507 void setPukEntryProgressDialog(ProgressDialog dialog) {
508 mPUKEntryProgressDialog = dialog;
509 }
510
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700511 /**
512 * Controls whether or not the screen is allowed to sleep.
513 *
514 * Once sleep is allowed (WakeState is SLEEP), it will rely on the
515 * settings for the poke lock to determine when to timeout and let
516 * the device sleep {@link PhoneGlobals#setScreenTimeout}.
517 *
518 * @param ws tells the device to how to wake.
519 */
520 /* package */ void requestWakeState(WakeState ws) {
521 if (VDBG) Log.d(LOG_TAG, "requestWakeState(" + ws + ")...");
522 synchronized (this) {
523 if (mWakeState != ws) {
524 switch (ws) {
525 case PARTIAL:
526 // acquire the processor wake lock, and release the FULL
527 // lock if it is being held.
528 mPartialWakeLock.acquire();
529 if (mWakeLock.isHeld()) {
530 mWakeLock.release();
531 }
532 break;
533 case FULL:
534 // acquire the full wake lock, and release the PARTIAL
535 // lock if it is being held.
536 mWakeLock.acquire();
537 if (mPartialWakeLock.isHeld()) {
538 mPartialWakeLock.release();
539 }
540 break;
541 case SLEEP:
542 default:
543 // release both the PARTIAL and FULL locks.
544 if (mWakeLock.isHeld()) {
545 mWakeLock.release();
546 }
547 if (mPartialWakeLock.isHeld()) {
548 mPartialWakeLock.release();
549 }
550 break;
551 }
552 mWakeState = ws;
553 }
554 }
555 }
556
557 /**
558 * If we are not currently keeping the screen on, then poke the power
559 * manager to wake up the screen for the user activity timeout duration.
560 */
561 /* package */ void wakeUpScreen() {
562 synchronized (this) {
563 if (mWakeState == WakeState.SLEEP) {
564 if (DBG) Log.d(LOG_TAG, "pulse screen lock");
Dianne Hackborn148769b2015-07-13 17:55:47 -0700565 mPowerManager.wakeUp(SystemClock.uptimeMillis(), "android.phone:WAKE");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700566 }
567 }
568 }
569
570 /**
571 * Sets the wake state and screen timeout based on the current state
572 * of the phone, and the current state of the in-call UI.
573 *
574 * This method is a "UI Policy" wrapper around
575 * {@link PhoneGlobals#requestWakeState} and {@link PhoneGlobals#setScreenTimeout}.
576 *
577 * It's safe to call this method regardless of the state of the Phone
578 * (e.g. whether or not it's idle), and regardless of the state of the
579 * Phone UI (e.g. whether or not the InCallScreen is active.)
580 */
581 /* package */ void updateWakeState() {
582 PhoneConstants.State state = mCM.getState();
583
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700584 // True if the speakerphone is in use. (If so, we *always* use
585 // the default timeout. Since the user is obviously not holding
586 // the phone up to his/her face, we don't need to worry about
587 // false touches, and thus don't need to turn the screen off so
588 // aggressively.)
589 // Note that we need to make a fresh call to this method any
590 // time the speaker state changes. (That happens in
591 // PhoneUtils.turnOnSpeaker().)
592 boolean isSpeakerInUse = (state == PhoneConstants.State.OFFHOOK) && PhoneUtils.isSpeakerOn(this);
593
594 // TODO (bug 1440854): The screen timeout *might* also need to
595 // depend on the bluetooth state, but this isn't as clear-cut as
596 // the speaker state (since while using BT it's common for the
597 // user to put the phone straight into a pocket, in which case the
598 // timeout should probably still be short.)
599
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700600 // Decide whether to force the screen on or not.
601 //
602 // Force the screen to be on if the phone is ringing or dialing,
603 // or if we're displaying the "Call ended" UI for a connection in
604 // the "disconnected" state.
605 // However, if the phone is disconnected while the user is in the
606 // middle of selecting a quick response message, we should not force
607 // the screen to be on.
608 //
609 boolean isRinging = (state == PhoneConstants.State.RINGING);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800610 boolean isDialing = (mCM.getFgPhone().getForegroundCall().getState() == Call.State.DIALING);
Jay Shrauner6fe8fd62013-09-16 19:39:30 -0700611 boolean keepScreenOn = isRinging || isDialing;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700612 // keepScreenOn == true means we'll hold a full wake lock:
613 requestWakeState(keepScreenOn ? WakeState.FULL : WakeState.SLEEP);
614 }
615
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700616 KeyguardManager getKeyguardManager() {
617 return mKeyguardManager;
618 }
619
620 private void onMMIComplete(AsyncResult r) {
621 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
622 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800623 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700624 }
625
fionaxu80126972017-02-01 17:01:26 -0800626 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700627 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700628 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700629 }
630
Chris Mantona09f3632016-02-09 14:48:42 -0800631 private void handleAirplaneModeChange(Context context, int newMode) {
632 int cellState = Settings.Global.getInt(context.getContentResolver(),
633 Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
634 boolean isAirplaneNewlyOn = (newMode == 1);
635 switch (cellState) {
636 case PhoneConstants.CELL_OFF_FLAG:
637 // Airplane mode does not affect the cell radio if user
638 // has turned it off.
639 break;
640 case PhoneConstants.CELL_ON_FLAG:
641 maybeTurnCellOff(context, isAirplaneNewlyOn);
642 break;
643 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
644 maybeTurnCellOn(context, isAirplaneNewlyOn);
645 break;
646 }
647 }
648
649 /*
650 * Returns true if the radio must be turned off when entering airplane mode.
651 */
652 private boolean isCellOffInAirplaneMode(Context context) {
653 String airplaneModeRadios = Settings.Global.getString(context.getContentResolver(),
654 Settings.Global.AIRPLANE_MODE_RADIOS);
655 return airplaneModeRadios == null
656 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
657 }
658
659 private void setRadioPowerOff(Context context) {
660 Log.i(LOG_TAG, "Turning radio off - airplane");
661 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
Eric Erfanianc712d4b2018-01-03 16:36:14 -0800662 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Sooraj Sasindran798bafa2017-04-03 22:49:00 -0700663 SystemProperties.set("persist.radio.airplane_mode_on", "1");
Chris Mantona09f3632016-02-09 14:48:42 -0800664 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
665 PhoneUtils.setRadioPower(false);
666 }
667
668 private void setRadioPowerOn(Context context) {
669 Log.i(LOG_TAG, "Turning radio on - airplane");
670 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
671 PhoneConstants.CELL_ON_FLAG);
672 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT,
673 1);
Sooraj Sasindran798bafa2017-04-03 22:49:00 -0700674 SystemProperties.set("persist.radio.airplane_mode_on", "0");
Chris Mantona09f3632016-02-09 14:48:42 -0800675 PhoneUtils.setRadioPower(true);
676 }
677
678 private void maybeTurnCellOff(Context context, boolean isAirplaneNewlyOn) {
679 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700680 // If we are trying to turn off the radio, make sure there are no active
681 // emergency calls. If there are, switch airplane mode back to off.
682 if (PhoneUtils.isInEmergencyCall(mCM)) {
683 // Switch airplane mode back to off.
684 ConnectivityManager.from(this).setAirplaneMode(false);
685 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
686 .show();
687 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Chris Mantona09f3632016-02-09 14:48:42 -0800688 } else if (isCellOffInAirplaneMode(context)) {
689 setRadioPowerOff(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700690 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800691 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700692 }
Chris Mantona09f3632016-02-09 14:48:42 -0800693 }
694 }
695
696 private void maybeTurnCellOn(Context context, boolean isAirplaneNewlyOn) {
697 if (!isAirplaneNewlyOn) {
698 setRadioPowerOn(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700699 }
700 }
701
Santos Cordon593ab382013-08-06 21:58:23 -0700702 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700703 * Receiver for misc intent broadcasts the Phone app cares about.
704 */
705 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
706 @Override
707 public void onReceive(Context context, Intent intent) {
708 String action = intent.getAction();
709 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Santos Cordone18902f2016-03-22 17:16:04 -0700710 int airplaneMode = Settings.Global.getInt(getContentResolver(),
711 Settings.Global.AIRPLANE_MODE_ON, AIRPLANE_OFF);
712 // Treat any non-OFF values as ON.
713 if (airplaneMode != AIRPLANE_OFF) {
714 airplaneMode = AIRPLANE_ON;
715 }
Chris Mantona09f3632016-02-09 14:48:42 -0800716 handleAirplaneModeChange(context, airplaneMode);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700717 } else if ((action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) &&
718 (mPUKEntryActivity != null)) {
719 // if an attempt to un-PUK-lock the device was made, while we're
720 // receiving this state change notification, notify the handler.
721 // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has
722 // been attempted.
723 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
724 intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE)));
725 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
726 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800727 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
728 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700729 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
730 handleServiceStateChanged(intent);
731 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530732 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530733 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530734 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
735 if (phoneInEcm != null) {
736 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
737 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
738 // Start Emergency Callback Mode service
739 if (intent.getBooleanExtra("phoneinECMState", false)) {
740 context.startService(new Intent(context,
741 EmergencyCallbackModeService.class));
742 } else {
743 phoneInEcm = null;
744 }
745 } else {
746 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
747 // on a device that doesn't support ECM in the first place.
748 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
749 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
750 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700751 }
752 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530753 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700754 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700755 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
756 // Roaming status could be overridden by carrier config, so we need to update it.
757 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
758 updateDataRoamingStatus();
759 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
760 // We also need to pay attention when default data subscription changes.
761 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
762 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
763 registerSettingsObserver();
764 Phone phone = getPhone(mDefaultDataSubId);
765 if (phone != null) {
766 updateDataRoamingStatus();
767 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700768 }
769 }
770 }
771
Brad Ebinger28626122017-08-10 14:13:35 -0700772 private class SipReceiver extends BroadcastReceiver {
773
774 @Override
775 public void onReceive(Context context, Intent intent) {
776 String action = intent.getAction();
777
778 SipAccountRegistry sipAccountRegistry = SipAccountRegistry.getInstance();
779 if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
780 SipUtil.startSipService();
781 } else if (action.equals(SipManager.ACTION_SIP_SERVICE_UP)
782 || action.equals(SipManager.ACTION_SIP_CALL_OPTION_CHANGED)) {
783 sipAccountRegistry.setup(context);
784 } else if (action.equals(SipManager.ACTION_SIP_REMOVE_PHONE)) {
785 if (DBG) {
786 Log.d(LOG_TAG, "SIP_REMOVE_PHONE "
787 + intent.getStringExtra(SipManager.EXTRA_LOCAL_URI));
788 }
789 sipAccountRegistry.removeSipProfile(intent.getStringExtra(
790 SipManager.EXTRA_LOCAL_URI));
791 } else {
792 if (DBG) Log.d(LOG_TAG, "onReceive, action not processed: " + action);
793 }
794 }
795 }
796
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700797 private void handleServiceStateChanged(Intent intent) {
798 /**
799 * This used to handle updating EriTextWidgetProvider this routine
800 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
801 * be removed. But leaving just in case it might be needed in the near
802 * future.
803 */
804
Jack Yu1a2fc352017-07-14 17:14:37 -0700805 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700806 // If service just returned, start sending out the queued messages
Santos Cordonc593d002015-06-03 15:41:15 -0700807 Bundle extras = intent.getExtras();
808 if (extras != null) {
809 ServiceState ss = ServiceState.newFromBundle(extras);
810 if (ss != null) {
811 int state = ss.getState();
Jayachandran C2ef9a482017-05-12 22:07:47 -0700812 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
813 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
814 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -0700815
816 if (VDBG) {
817 Log.v(LOG_TAG, "subId=" + subId + ",mDefaultDataSubId="
818 + mDefaultDataSubId + ",ss roaming=" + ss.getDataRoaming());
819 }
820 if (subId == mDefaultDataSubId) {
821 updateDataRoamingStatus();
822 }
Santos Cordonc593d002015-06-03 15:41:15 -0700823 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700824 }
825 }
826
Jack Yu1a2fc352017-07-14 17:14:37 -0700827 /**
828 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
829 * to notify the user so they can enable it through settings. Vise versa if the condition
830 * changes, we need to dismiss the notification.
831 */
832 private void updateDataRoamingStatus() {
833 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
834 Phone phone = getPhone(mDefaultDataSubId);
835 if (phone == null) {
836 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
837 return;
838 }
839
840 DataConnectionReasons reasons = new DataConnectionReasons();
841 boolean dataAllowed = phone.isDataAllowed(reasons);
842 mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons);
843 if (VDBG) Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons);
844 if (!mNoDataDueToRoaming
845 && !dataAllowed
846 && reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED)) {
847 // If the only reason of no data is data roaming disabled, then we notify the user
848 // so the user can turn on data roaming.
849 mNoDataDueToRoaming = true;
850 Log.d(LOG_TAG, "Show roaming disconnected notification");
851 mDataRoamingNotifLog.log("Show");
Pengquan Meng8783d932017-10-16 14:57:40 -0700852 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_DISCONNECTED);
853 msg.arg1 = mDefaultDataSubId;
854 msg.sendToTarget();
Jack Yu1a2fc352017-07-14 17:14:37 -0700855 } else if (mNoDataDueToRoaming && (dataAllowed
856 || !reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED))) {
857 // Otherwise dismiss the notification we showed earlier.
858 mNoDataDueToRoaming = false;
859 Log.d(LOG_TAG, "Dismiss roaming disconnected notification");
860 mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed + ", reasons=" + reasons);
861 mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
862 }
863 }
864
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530865 public Phone getPhoneInEcm() {
866 return phoneInEcm;
867 }
868
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700869 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800870 * Triggers a refresh of the message waiting (voicemail) indicator.
871 *
872 * @param subId the subscription id we should refresh the notification for.
873 */
874 public void refreshMwiIndicator(int subId) {
875 notificationMgr.refreshMwi(subId);
876 }
877
878 /**
Nancy Chenbb49d412015-07-23 13:54:16 -0700879 * Dismisses the message waiting (voicemail) indicator.
880 *
881 * @param subId the subscription id we should dismiss the notification for.
882 */
883 public void clearMwiIndicator(int subId) {
Ta-wei Yen63106682016-07-11 14:11:27 -0700884 // Setting voiceMessageCount to 0 will remove the current notification and clear the system
885 // cached value.
Ta-wei Yen7df340d2016-07-25 10:59:53 -0700886 Phone phone = getPhone(subId);
887 if (phone == null) {
888 Log.w(LOG_TAG, "clearMwiIndicator on null phone, subId:" + subId);
889 } else {
890 phone.setVoiceMessageCount(0);
891 }
Nancy Chenbb49d412015-07-23 13:54:16 -0700892 }
Ta-wei Yenb29425b2016-09-21 17:28:14 -0700893
894 /**
895 * Enables or disables the visual voicemail check for message waiting indicator. Default value
896 * is true. MWI is the traditional voicemail notification which should be suppressed if visual
897 * voicemail is active. {@link NotificationMgr#updateMwi(int, boolean, boolean)} currently
898 * checks the {@link android.provider.VoicemailContract.Status#CONFIGURATION_STATE} to suppress
899 * the MWI, but there are several issues. b/31229016 is a bug that when the device boots the
900 * configuration state will be cleared and the MWI for voicemail that arrives when the device
901 * is offline will be cleared, even if the account cannot be activated. A full solution will be
902 * adding a setMwiEnabled() method and stop checking the configuration state, but that is too
903 * risky at this moment. This is a temporary workaround to shut down the configuration state
904 * check if visual voicemail cannot be activated.
905 * <p>TODO(twyen): implement the setMwiEnabled() mentioned above.
906 *
907 * @param subId the account to set the enabled state
908 */
909 public void setShouldCheckVisualVoicemailConfigurationForMwi(int subId, boolean enabled) {
910 notificationMgr.setShouldCheckVisualVoicemailConfigurationForMwi(subId, enabled);
911 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700912
913 /**
914 * Dump the state of the object, add calls to other objects as desired.
915 *
916 * @param fd File descriptor
917 * @param printWriter Print writer
918 * @param args Arguments
919 */
920 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
921 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
922 pw.println("------- PhoneGlobals -------");
923 pw.increaseIndent();
924 pw.println("mNoDataDueToRoaming=" + mNoDataDueToRoaming);
925 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
926 pw.println("mDataRoamingNotifLog:");
927 pw.increaseIndent();
928 mDataRoamingNotifLog.dump(fd, pw, args);
929 pw.decreaseIndent();
930 pw.decreaseIndent();
931 pw.println("------- End PhoneGlobals -------");
932 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700933}