blob: 8d3027a4cc581f6d8310a7f0a82130bb26f10d0c [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;
Youming Ye47a6adc2018-11-19 15:33:36 -080028import android.content.res.XmlResourceParser;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070029import android.media.AudioManager;
Santos Cordone18902f2016-03-22 17:16:04 -070030import android.net.ConnectivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.net.Uri;
Brad Ebinger533c6c12017-08-02 11:38:48 -070032import android.net.sip.SipManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.os.AsyncResult;
Junda Liu605148f2015-04-28 15:23:40 -070034import android.os.Bundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.os.Handler;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036import android.os.Message;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070037import android.os.PersistableBundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.PowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.os.SystemClock;
40import android.os.SystemProperties;
41import android.os.UpdateLock;
Brad Ebinger3fa43462016-04-12 16:06:48 -070042import android.os.UserManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.preference.PreferenceManager;
Sanket Padawe4c699232016-02-09 11:07:22 -080044import android.provider.Settings;
Tyler Gunn900d8fd2018-09-21 09:22:12 -070045import android.telecom.TelecomManager;
Nathan Haroldf9df6ea2019-03-08 11:54:22 -080046import android.telephony.AnomalyReporter;
Junda Liu12f7d802015-05-01 12:06:44 -070047import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.telephony.ServiceState;
chen xubaf9fe52019-07-02 17:28:24 -070049import android.telephony.SubscriptionInfo;
Andrew Lee385019f2014-11-24 14:19:50 -080050import android.telephony.SubscriptionManager;
Jack Yu1a2fc352017-07-14 17:14:37 -070051import android.telephony.TelephonyManager;
Jack Yu311536f2018-11-26 11:20:48 -080052import android.telephony.data.ApnSetting;
Jack Yu1a2fc352017-07-14 17:14:37 -070053import android.util.LocalLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.util.Log;
Santos Cordone18902f2016-03-22 17:16:04 -070055import android.widget.Toast;
Ta-wei Yenb29425b2016-09-21 17:28:14 -070056
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import com.android.internal.telephony.CallManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import com.android.internal.telephony.IccCardConstants;
59import com.android.internal.telephony.MmiCode;
60import com.android.internal.telephony.Phone;
61import com.android.internal.telephony.PhoneConstants;
62import com.android.internal.telephony.PhoneFactory;
Jack Yu1a2fc352017-07-14 17:14:37 -070063import com.android.internal.telephony.SettingsObserver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import com.android.internal.telephony.TelephonyCapabilities;
Youming Ye47a6adc2018-11-19 15:33:36 -080065import com.android.internal.telephony.TelephonyComponentFactory;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066import com.android.internal.telephony.TelephonyIntents;
Jack Yu1a2fc352017-07-14 17:14:37 -070067import com.android.internal.telephony.dataconnection.DataConnectionReasons;
68import com.android.internal.telephony.dataconnection.DataConnectionReasons.DataDisallowedReasonType;
69import com.android.internal.util.IndentingPrintWriter;
Andrew Leefb7f92e2015-02-26 16:23:32 -080070import com.android.phone.settings.SettingsConstants;
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -070071import com.android.phone.vvm.CarrierVvmPackageInstalledReceiver;
Brad Ebinger28626122017-08-10 14:13:35 -070072import com.android.services.telephony.sip.SipAccountRegistry;
Brad Ebinger3fa43462016-04-12 16:06:48 -070073import com.android.services.telephony.sip.SipUtil;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074
Jack Yu1a2fc352017-07-14 17:14:37 -070075import java.io.FileDescriptor;
76import java.io.PrintWriter;
chen xubaf9fe52019-07-02 17:28:24 -070077import java.util.List;
Jack Yu1a2fc352017-07-14 17:14:37 -070078
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079/**
80 * Global state for the telephony subsystem when running in the primary
81 * phone process.
82 */
Sailesh Nepalbf900542014-07-15 16:18:32 -070083public class PhoneGlobals extends ContextWrapper {
Jack Yu1a2fc352017-07-14 17:14:37 -070084 public static final String LOG_TAG = "PhoneGlobals";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070085
86 /**
87 * Phone app-wide debug level:
88 * 0 - no debug logging
89 * 1 - normal debug logging if ro.debuggable is set (which is true in
90 * "eng" and "userdebug" builds but not "user" builds)
91 * 2 - ultra-verbose debug logging
92 *
93 * Most individual classes in the phone app have a local DBG constant,
94 * typically set to
95 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
96 * or else
97 * (PhoneApp.DBG_LEVEL >= 2)
98 * depending on the desired verbosity.
99 *
100 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
101 */
Andrew Lee88b51e22014-10-29 15:48:51 -0700102 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700103
104 private static final boolean DBG =
105 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
106 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
107
108 // Message codes; see mHandler below.
109 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700110 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
112 private static final int EVENT_DATA_ROAMING_OK = 11;
113 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 12;
Brad Ebinger3fa43462016-04-12 16:06:48 -0700114 private static final int EVENT_RESTART_SIP = 13;
Jack Yu1a2fc352017-07-14 17:14:37 -0700115 private static final int EVENT_DATA_ROAMING_SETTINGS_CHANGED = 14;
116 private static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED = 15;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117
118 // The MMI codes are also used by the InCallScreen.
119 public static final int MMI_INITIATE = 51;
120 public static final int MMI_COMPLETE = 52;
121 public static final int MMI_CANCEL = 53;
122 // Don't use message codes larger than 99 here; those are reserved for
123 // the individual Activities of the Phone UI.
124
Santos Cordone18902f2016-03-22 17:16:04 -0700125 public static final int AIRPLANE_ON = 1;
126 public static final int AIRPLANE_OFF = 0;
127
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128 /**
129 * Allowable values for the wake lock code.
130 * SLEEP means the device can be put to sleep.
131 * PARTIAL means wake the processor, but we display can be kept off.
132 * FULL means wake both the processor and the display.
133 */
134 public enum WakeState {
135 SLEEP,
136 PARTIAL,
137 FULL
138 }
139
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140 private static PhoneGlobals sMe;
141
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700143 CallNotifier notifier;
144 CallerInfoCache callerInfoCache;
Santos Cordon63a84242013-07-23 13:32:52 -0700145 NotificationMgr notificationMgr;
Andrew Lee9431b832015-03-09 18:46:45 -0700146 public PhoneInterfaceManager phoneMgr;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800147 CarrierConfigLoader configLoader;
Santos Cordon63a84242013-07-23 13:32:52 -0700148
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
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700187 Handler mHandler = new Handler() {
188 @Override
189 public void handleMessage(Message msg) {
190 PhoneConstants.State phoneState;
Jack Yu1a2fc352017-07-14 17:14:37 -0700191 if (VDBG) Log.v(LOG_TAG, "event=" + msg.what);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192 switch (msg.what) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193 // TODO: This event should be handled by the lock screen, just
194 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
195 case EVENT_SIM_NETWORK_LOCKED:
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700196 if (getCarrierConfig().getBoolean(
197 CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198 // Some products don't have the concept of a "SIM network lock"
199 Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; "
Eric Erfanian945409f2018-02-21 19:26:15 +0000200 + "not showing 'SIM network unlock' PIN entry screen");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201 } else {
202 // Normal case: show the "SIM network unlock" PIN entry screen.
203 // The user won't be able to do anything else until
204 // they enter a valid SIM network PIN.
205 Log.i(LOG_TAG, "show sim depersonal panel");
Biljana Maneva96291112018-01-30 13:12:59 +0800206 Phone phone = (Phone) ((AsyncResult) msg.obj).userObj;
207 IccNetworkDepersonalizationPanel.showDialog(phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700208 }
209 break;
210
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700211 case EVENT_DATA_ROAMING_DISCONNECTED:
Pengquan Meng8783d932017-10-16 14:57:40 -0700212 notificationMgr.showDataDisconnectedRoaming(msg.arg1);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700213 break;
214
215 case EVENT_DATA_ROAMING_OK:
216 notificationMgr.hideDataDisconnectedRoaming();
217 break;
218
219 case MMI_COMPLETE:
220 onMMIComplete((AsyncResult) msg.obj);
221 break;
222
223 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800224 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700225 break;
226
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700227 case EVENT_SIM_STATE_CHANGED:
228 // Marks the event where the SIM goes into ready state.
229 // Right now, this is only used for the PUK-unlocking
230 // process.
Amit Mahajanc08787c2019-03-26 16:11:55 -0700231 if (msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_READY)
232 || msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_LOADED)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700233 // 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) {
Nathan Haroldf9df6ea2019-03-08 11:54:22 -0800290 // Initialize AnomalyReporter early so that it can be used
291 AnomalyReporter.initialize(this);
Nathan Harold0db5c5e2019-01-22 20:18:56 -0800292
Youming Ye47a6adc2018-11-19 15:33:36 -0800293 // Inject telephony component factory if configured using other jars.
294 XmlResourceParser parser = getResources().getXml(R.xml.telephony_injection);
295 TelephonyComponentFactory.getInstance().injectTheComponentFactory(parser);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700296 // Initialize the telephony framework
297 PhoneFactory.makeDefaultPhones(this);
298
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299 // Start TelephonyDebugService After the default phone is created.
300 Intent intent = new Intent(this, TelephonyDebugService.class);
301 startService(intent);
302
303 mCM = CallManager.getInstance();
Stuart Scottdcf40a92014-12-09 10:45:01 -0800304 for (Phone phone : PhoneFactory.getPhones()) {
305 mCM.registerPhone(phone);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800306 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700307
308 // Create the NotificationMgr singleton, which is used to display
309 // status bar icons and control other status bar behavior.
310 notificationMgr = NotificationMgr.init(this);
311
Brad Ebinger3fa43462016-04-12 16:06:48 -0700312 // If PhoneGlobals has crashed and is being restarted, then restart.
313 mHandler.sendEmptyMessage(EVENT_RESTART_SIP);
314
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700315 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
316 cdmaPhoneCallState = new CdmaPhoneCallState();
317 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700318
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700319 // before registering for phone state changes
320 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
321 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
322 // lock used to keep the processor awake, when we don't care for the display.
323 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
324 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700325
326 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
327
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700328 // Get UpdateLock to suppress system-update related events (e.g. dialog show-up)
329 // during phone calls.
330 mUpdateLock = new UpdateLock("phone");
331
332 if (DBG) Log.d(LOG_TAG, "onCreate: mUpdateLock: " + mUpdateLock);
333
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700334 // Create the CallerInfoCache singleton, which remembers custom ring tone and
335 // send-to-voicemail settings.
336 //
337 // The asynchronous caching will start just after this call.
338 callerInfoCache = CallerInfoCache.init(this);
339
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800340 phoneMgr = PhoneInterfaceManager.init(this);
Santos Cordon406c0342013-08-28 00:07:47 -0700341
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800342 configLoader = CarrierConfigLoader.init(this);
343
Jack Yu1a2fc352017-07-14 17:14:37 -0700344 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700345 // asynchronous events from the telephony layer (like
346 // launching the incoming-call UI when an incoming call comes
347 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800348 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700349
Stuart Scottdcf40a92014-12-09 10:45:01 -0800350 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700351
352 // register for MMI/USSD
353 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
354
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355 // Register for misc other intent broadcasts.
356 IntentFilter intentFilter =
357 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
359 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
360 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
361 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700362 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
363 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700364 registerReceiver(mReceiver, intentFilter);
365
Brad Ebinger533c6c12017-08-02 11:38:48 -0700366 IntentFilter sipIntentFilter = new IntentFilter(Intent.ACTION_BOOT_COMPLETED);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700367 sipIntentFilter.addAction(SipManager.ACTION_SIP_SERVICE_UP);
368 sipIntentFilter.addAction(SipManager.ACTION_SIP_CALL_OPTION_CHANGED);
369 sipIntentFilter.addAction(SipManager.ACTION_SIP_REMOVE_PHONE);
Brad Ebinger28626122017-08-10 14:13:35 -0700370 registerReceiver(mSipReceiver, sipIntentFilter);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700371
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700372 mCarrierVvmPackageInstalledReceiver.register(this);
373
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374 //set the default values for the preferences in the phone.
pkanward702e542017-02-08 15:44:54 -0800375 PreferenceManager.setDefaultValues(this, R.xml.network_setting_fragment, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700376
377 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700378 }
379
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380 // XXX pre-load the SimProvider so that it's ready
381 resolver.getType(Uri.parse("content://icc/adn"));
382
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383 // TODO: Register for Cdma Information Records
384 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
385
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700386 // Read HAC settings and configure audio hardware
387 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800388 int hac = android.provider.Settings.System.getInt(
389 getContentResolver(),
390 android.provider.Settings.System.HEARING_AID,
391 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700392 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Andrew Leefb7f92e2015-02-26 16:23:32 -0800393 audioManager.setParameter(SettingsConstants.HAC_KEY,
394 hac == SettingsConstants.HAC_ENABLED
395 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700396 }
Santos Cordonff506f52013-11-21 19:13:19 -0800397 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700399 /**
400 * Returns the singleton instance of the PhoneApp.
401 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800402 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700403 if (sMe == null) {
404 throw new IllegalStateException("No PhoneGlobals here!");
405 }
406 return sMe;
407 }
408
409 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800410 * Returns the default phone.
411 *
Andrew Lee385019f2014-11-24 14:19:50 -0800412 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413 */
Andrew Lee83383e42014-10-31 12:42:28 -0700414 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800415 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416 }
417
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800418 public static Phone getPhone(int subId) {
419 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800420 }
421
Santos Cordonde10b752013-09-19 04:11:33 -0700422 /* package */ CallManager getCallManager() {
423 return mCM;
424 }
425
Chris Manton4e9fa912015-06-19 11:26:57 -0700426 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800427 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700428 }
429
Chris Manton4e9fa912015-06-19 11:26:57 -0700430 public PersistableBundle getCarrierConfigForSubId(int subId) {
Malcolm Chen6d3d6b32018-03-01 13:58:03 -0800431 return configLoader.getConfigForSubId(subId, getOpPackageName());
Junda Liu605148f2015-04-28 15:23:40 -0700432 }
433
Jack Yu1a2fc352017-07-14 17:14:37 -0700434 private void registerSettingsObserver() {
435 mSettingsObserver.unobserve();
436 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
437 String mobileDataSetting = Settings.Global.MOBILE_DATA;
438 if (TelephonyManager.getDefault().getSimCount() > 1) {
439 int subId = mDefaultDataSubId;
440 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
441 dataRoamingSetting += subId;
442 mobileDataSetting += subId;
443 }
444 }
445
446 // Listen for user data roaming setting changed event
447 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
448 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
449
450 // Listen for mobile data setting changed event
451 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
452 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
453 }
454
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700455 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700456 * Sets the activity responsible for un-PUK-blocking the device
457 * so that we may close it when we receive a positive result.
458 * mPUKEntryActivity is also used to indicate to the device that
459 * we are trying to un-PUK-lock the phone. In other words, iff
460 * it is NOT null, then we are trying to unlock and waiting for
461 * the SIM to move to READY state.
462 *
463 * @param activity is the activity to close when PUK has
464 * finished unlocking. Can be set to null to indicate the unlock
465 * or SIM READYing process is over.
466 */
467 void setPukEntryActivity(Activity activity) {
468 mPUKEntryActivity = activity;
469 }
470
471 Activity getPUKEntryActivity() {
472 return mPUKEntryActivity;
473 }
474
475 /**
476 * Sets the dialog responsible for notifying the user of un-PUK-
477 * blocking - SIM READYing progress, so that we may dismiss it
478 * when we receive a positive result.
479 *
480 * @param dialog indicates the progress dialog informing the user
481 * of the state of the device. Dismissed upon completion of
482 * READYing process
483 */
484 void setPukEntryProgressDialog(ProgressDialog dialog) {
485 mPUKEntryProgressDialog = dialog;
486 }
487
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700488 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700489 * If we are not currently keeping the screen on, then poke the power
490 * manager to wake up the screen for the user activity timeout duration.
491 */
492 /* package */ void wakeUpScreen() {
493 synchronized (this) {
494 if (mWakeState == WakeState.SLEEP) {
495 if (DBG) Log.d(LOG_TAG, "pulse screen lock");
Dianne Hackborn148769b2015-07-13 17:55:47 -0700496 mPowerManager.wakeUp(SystemClock.uptimeMillis(), "android.phone:WAKE");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700497 }
498 }
499 }
500
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700501 KeyguardManager getKeyguardManager() {
502 return mKeyguardManager;
503 }
504
505 private void onMMIComplete(AsyncResult r) {
506 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
507 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800508 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700509 }
510
fionaxu80126972017-02-01 17:01:26 -0800511 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700512 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700513 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700514 }
515
Chris Mantona09f3632016-02-09 14:48:42 -0800516 private void handleAirplaneModeChange(Context context, int newMode) {
517 int cellState = Settings.Global.getInt(context.getContentResolver(),
518 Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
519 boolean isAirplaneNewlyOn = (newMode == 1);
520 switch (cellState) {
521 case PhoneConstants.CELL_OFF_FLAG:
522 // Airplane mode does not affect the cell radio if user
523 // has turned it off.
524 break;
525 case PhoneConstants.CELL_ON_FLAG:
526 maybeTurnCellOff(context, isAirplaneNewlyOn);
527 break;
528 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
529 maybeTurnCellOn(context, isAirplaneNewlyOn);
530 break;
531 }
532 }
533
534 /*
535 * Returns true if the radio must be turned off when entering airplane mode.
536 */
537 private boolean isCellOffInAirplaneMode(Context context) {
538 String airplaneModeRadios = Settings.Global.getString(context.getContentResolver(),
539 Settings.Global.AIRPLANE_MODE_RADIOS);
540 return airplaneModeRadios == null
541 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
542 }
543
544 private void setRadioPowerOff(Context context) {
545 Log.i(LOG_TAG, "Turning radio off - airplane");
546 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
Eric Erfanian945409f2018-02-21 19:26:15 +0000547 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Sooraj Sasindran798bafa2017-04-03 22:49:00 -0700548 SystemProperties.set("persist.radio.airplane_mode_on", "1");
Chris Mantona09f3632016-02-09 14:48:42 -0800549 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
550 PhoneUtils.setRadioPower(false);
551 }
552
553 private void setRadioPowerOn(Context context) {
554 Log.i(LOG_TAG, "Turning radio on - airplane");
555 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
556 PhoneConstants.CELL_ON_FLAG);
557 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT,
558 1);
Sooraj Sasindran798bafa2017-04-03 22:49:00 -0700559 SystemProperties.set("persist.radio.airplane_mode_on", "0");
Chris Mantona09f3632016-02-09 14:48:42 -0800560 PhoneUtils.setRadioPower(true);
561 }
562
563 private void maybeTurnCellOff(Context context, boolean isAirplaneNewlyOn) {
564 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700565 // If we are trying to turn off the radio, make sure there are no active
566 // emergency calls. If there are, switch airplane mode back to off.
Tyler Gunn900d8fd2018-09-21 09:22:12 -0700567 TelecomManager tm = (TelecomManager) context.getSystemService(TELECOM_SERVICE);
568
569 if (tm != null && tm.isInEmergencyCall()) {
Santos Cordone18902f2016-03-22 17:16:04 -0700570 // Switch airplane mode back to off.
571 ConnectivityManager.from(this).setAirplaneMode(false);
572 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
573 .show();
574 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Chris Mantona09f3632016-02-09 14:48:42 -0800575 } else if (isCellOffInAirplaneMode(context)) {
576 setRadioPowerOff(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700577 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800578 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700579 }
Chris Mantona09f3632016-02-09 14:48:42 -0800580 }
581 }
582
583 private void maybeTurnCellOn(Context context, boolean isAirplaneNewlyOn) {
584 if (!isAirplaneNewlyOn) {
585 setRadioPowerOn(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700586 }
587 }
588
Santos Cordon593ab382013-08-06 21:58:23 -0700589 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700590 * Receiver for misc intent broadcasts the Phone app cares about.
591 */
592 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
593 @Override
594 public void onReceive(Context context, Intent intent) {
595 String action = intent.getAction();
596 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Santos Cordone18902f2016-03-22 17:16:04 -0700597 int airplaneMode = Settings.Global.getInt(getContentResolver(),
598 Settings.Global.AIRPLANE_MODE_ON, AIRPLANE_OFF);
599 // Treat any non-OFF values as ON.
600 if (airplaneMode != AIRPLANE_OFF) {
601 airplaneMode = AIRPLANE_ON;
602 }
Chris Mantona09f3632016-02-09 14:48:42 -0800603 handleAirplaneModeChange(context, airplaneMode);
Amit Mahajanf5d92c82018-11-02 17:44:40 -0700604 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
605 // re-register as it may be a new IccCard
606 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
607 SubscriptionManager.INVALID_PHONE_INDEX);
608 if (SubscriptionManager.isValidPhoneId(phoneId)) {
609 PhoneUtils.unregisterIccStatus(mHandler, phoneId);
610 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED, phoneId);
611 }
612 if (mPUKEntryActivity != null) {
613 // if an attempt to un-PUK-lock the device was made, while we're
614 // receiving this state change notification, notify the handler.
615 // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has
616 // been attempted.
617 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
618 intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE)));
619 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700620 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
621 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800622 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
623 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700624 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
625 handleServiceStateChanged(intent);
626 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530627 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530628 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530629 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
630 if (phoneInEcm != null) {
631 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
632 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
633 // Start Emergency Callback Mode service
634 if (intent.getBooleanExtra("phoneinECMState", false)) {
635 context.startService(new Intent(context,
636 EmergencyCallbackModeService.class));
637 } else {
638 phoneInEcm = null;
639 }
640 } else {
641 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
642 // on a device that doesn't support ECM in the first place.
643 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
644 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
645 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700646 }
647 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530648 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700649 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700650 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
651 // Roaming status could be overridden by carrier config, so we need to update it.
652 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
653 updateDataRoamingStatus();
chen xubaf9fe52019-07-02 17:28:24 -0700654 updateLimitedSimFunctionForDualSim();
Jack Yu1a2fc352017-07-14 17:14:37 -0700655 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
656 // We also need to pay attention when default data subscription changes.
657 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
658 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
659 registerSettingsObserver();
660 Phone phone = getPhone(mDefaultDataSubId);
661 if (phone != null) {
662 updateDataRoamingStatus();
663 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700664 }
665 }
666 }
667
Brad Ebinger28626122017-08-10 14:13:35 -0700668 private class SipReceiver extends BroadcastReceiver {
669
670 @Override
671 public void onReceive(Context context, Intent intent) {
672 String action = intent.getAction();
673
674 SipAccountRegistry sipAccountRegistry = SipAccountRegistry.getInstance();
675 if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
676 SipUtil.startSipService();
677 } else if (action.equals(SipManager.ACTION_SIP_SERVICE_UP)
678 || action.equals(SipManager.ACTION_SIP_CALL_OPTION_CHANGED)) {
679 sipAccountRegistry.setup(context);
680 } else if (action.equals(SipManager.ACTION_SIP_REMOVE_PHONE)) {
681 if (DBG) {
682 Log.d(LOG_TAG, "SIP_REMOVE_PHONE "
683 + intent.getStringExtra(SipManager.EXTRA_LOCAL_URI));
684 }
685 sipAccountRegistry.removeSipProfile(intent.getStringExtra(
686 SipManager.EXTRA_LOCAL_URI));
687 } else {
688 if (DBG) Log.d(LOG_TAG, "onReceive, action not processed: " + action);
689 }
690 }
691 }
692
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700693 private void handleServiceStateChanged(Intent intent) {
694 /**
695 * This used to handle updating EriTextWidgetProvider this routine
696 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
697 * be removed. But leaving just in case it might be needed in the near
698 * future.
699 */
700
Jack Yu1a2fc352017-07-14 17:14:37 -0700701 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700702 // If service just returned, start sending out the queued messages
Santos Cordonc593d002015-06-03 15:41:15 -0700703 Bundle extras = intent.getExtras();
704 if (extras != null) {
705 ServiceState ss = ServiceState.newFromBundle(extras);
706 if (ss != null) {
707 int state = ss.getState();
Jayachandran C2ef9a482017-05-12 22:07:47 -0700708 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
709 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
710 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -0700711
712 if (VDBG) {
713 Log.v(LOG_TAG, "subId=" + subId + ",mDefaultDataSubId="
714 + mDefaultDataSubId + ",ss roaming=" + ss.getDataRoaming());
715 }
716 if (subId == mDefaultDataSubId) {
717 updateDataRoamingStatus();
718 }
Santos Cordonc593d002015-06-03 15:41:15 -0700719 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700720 }
721 }
722
Jack Yu1a2fc352017-07-14 17:14:37 -0700723 /**
724 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
725 * to notify the user so they can enable it through settings. Vise versa if the condition
726 * changes, we need to dismiss the notification.
727 */
728 private void updateDataRoamingStatus() {
729 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
730 Phone phone = getPhone(mDefaultDataSubId);
731 if (phone == null) {
732 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
733 return;
734 }
735
736 DataConnectionReasons reasons = new DataConnectionReasons();
Jack Yu311536f2018-11-26 11:20:48 -0800737 boolean dataAllowed = phone.isDataAllowed(ApnSetting.TYPE_DEFAULT, reasons);
Jack Yu1a2fc352017-07-14 17:14:37 -0700738 mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons);
739 if (VDBG) Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons);
740 if (!mNoDataDueToRoaming
741 && !dataAllowed
742 && reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED)) {
743 // If the only reason of no data is data roaming disabled, then we notify the user
744 // so the user can turn on data roaming.
745 mNoDataDueToRoaming = true;
746 Log.d(LOG_TAG, "Show roaming disconnected notification");
747 mDataRoamingNotifLog.log("Show");
Pengquan Meng8783d932017-10-16 14:57:40 -0700748 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_DISCONNECTED);
749 msg.arg1 = mDefaultDataSubId;
750 msg.sendToTarget();
Jack Yu1a2fc352017-07-14 17:14:37 -0700751 } else if (mNoDataDueToRoaming && (dataAllowed
752 || !reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED))) {
753 // Otherwise dismiss the notification we showed earlier.
754 mNoDataDueToRoaming = false;
755 Log.d(LOG_TAG, "Dismiss roaming disconnected notification");
756 mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed + ", reasons=" + reasons);
757 mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
758 }
759 }
760
chen xubaf9fe52019-07-02 17:28:24 -0700761 private void updateLimitedSimFunctionForDualSim() {
762 if (DBG) Log.d(LOG_TAG, "updateLimitedSimFunctionForDualSim");
763 // check conditions to display limited SIM function notification under dual SIM
764 SubscriptionManager subMgr = (SubscriptionManager) getSystemService(
765 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
766 List<SubscriptionInfo> subList = subMgr.getActiveSubscriptionInfoList(false);
767 if (subList != null && subList.size() > 1) {
768 CarrierConfigManager configMgr = (CarrierConfigManager)
769 getSystemService(Context.CARRIER_CONFIG_SERVICE);
770 for (SubscriptionInfo info : subList) {
771 PersistableBundle b = configMgr.getConfigForSubId(info.getSubscriptionId());
772 if (b != null) {
773 if (b.getBoolean(CarrierConfigManager
774 .KEY_LIMITED_SIM_FUNCTION_NOTIFICATION_FOR_DSDS_BOOL)) {
775 notificationMgr.showLimitedSimFunctionWarningNotification(
776 info.getSubscriptionId(),
777 info.getDisplayName().toString());
778 } else {
779 notificationMgr.dismissLimitedSimFunctionWarningNotification(
780 info.getSubscriptionId());
781 }
782 }
783 }
784 } else {
785 // cancel notifications for all subs
786 notificationMgr.dismissLimitedSimFunctionWarningNotification(
787 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
788 }
789 notificationMgr.dismissLimitedSimFunctionWarningNotificationForInactiveSubs();
790
791 }
792
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530793 public Phone getPhoneInEcm() {
794 return phoneInEcm;
795 }
796
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700797 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800798 * Triggers a refresh of the message waiting (voicemail) indicator.
799 *
800 * @param subId the subscription id we should refresh the notification for.
801 */
802 public void refreshMwiIndicator(int subId) {
803 notificationMgr.refreshMwi(subId);
804 }
805
806 /**
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700807 * Called when the network selection on the subscription {@code subId} is changed by the user.
808 *
809 * @param subId the subscription id.
810 */
811 public void onNetworkSelectionChanged(int subId) {
812 Phone phone = getPhone(subId);
813 if (phone != null) {
814 notificationMgr.updateNetworkSelection(phone.getServiceState().getState(), subId);
815 } else {
816 Log.w(LOG_TAG, "onNetworkSelectionChanged on null phone, subId: " + subId);
817 }
818 }
819
820 /**
Jack Yu1a2fc352017-07-14 17:14:37 -0700821 * Dump the state of the object, add calls to other objects as desired.
822 *
823 * @param fd File descriptor
824 * @param printWriter Print writer
825 * @param args Arguments
826 */
827 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
828 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
829 pw.println("------- PhoneGlobals -------");
830 pw.increaseIndent();
831 pw.println("mNoDataDueToRoaming=" + mNoDataDueToRoaming);
832 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
833 pw.println("mDataRoamingNotifLog:");
Keun young Parkdebb8532019-05-30 16:35:27 -0700834 pw.println("isSmsCapable=" + TelephonyManager.from(this).isSmsCapable());
Jack Yu1a2fc352017-07-14 17:14:37 -0700835 pw.increaseIndent();
836 mDataRoamingNotifLog.dump(fd, pw, args);
837 pw.decreaseIndent();
838 pw.decreaseIndent();
839 pw.println("------- End PhoneGlobals -------");
840 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700841}