blob: 810ccdf344c1f839e0470dd1cb92a7bfd52cbccf [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
Jordan Liuc353b162019-07-23 15:54:41 -070019import android.annotation.IntDef;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070020import android.app.Activity;
21import android.app.KeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.ProgressDialog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070023import android.content.BroadcastReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.content.ContentResolver;
25import android.content.Context;
26import android.content.ContextWrapper;
27import android.content.Intent;
28import android.content.IntentFilter;
Brad Ebinger24c29992019-12-05 13:03:21 -080029import android.content.pm.PackageManager;
Youming Ye47a6adc2018-11-19 15:33:36 -080030import android.content.res.XmlResourceParser;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.media.AudioManager;
Santos Cordone18902f2016-03-22 17:16:04 -070032import android.net.ConnectivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.net.Uri;
Brad Ebinger533c6c12017-08-02 11:38:48 -070034import android.net.sip.SipManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.os.AsyncResult;
Junda Liu605148f2015-04-28 15:23:40 -070036import android.os.Bundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.os.Handler;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.Message;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070039import android.os.PersistableBundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.os.PowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.SystemProperties;
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;
Meng Wang4c5f4f22019-10-23 14:08:43 -070045import android.sysprop.TelephonyProperties;
Tyler Gunn900d8fd2018-09-21 09:22:12 -070046import android.telecom.TelecomManager;
Nathan Haroldf9df6ea2019-03-08 11:54:22 -080047import android.telephony.AnomalyReporter;
Junda Liu12f7d802015-05-01 12:06:44 -070048import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.telephony.ServiceState;
chen xubaf9fe52019-07-02 17:28:24 -070050import android.telephony.SubscriptionInfo;
Andrew Lee385019f2014-11-24 14:19:50 -080051import android.telephony.SubscriptionManager;
Jack Yu1a2fc352017-07-14 17:14:37 -070052import android.telephony.TelephonyManager;
Jack Yu311536f2018-11-26 11:20:48 -080053import android.telephony.data.ApnSetting;
Jack Yu1a2fc352017-07-14 17:14:37 -070054import android.util.LocalLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.util.Log;
Santos Cordone18902f2016-03-22 17:16:04 -070056import android.widget.Toast;
Ta-wei Yenb29425b2016-09-21 17:28:14 -070057
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import com.android.internal.telephony.CallManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import com.android.internal.telephony.IccCardConstants;
60import com.android.internal.telephony.MmiCode;
61import com.android.internal.telephony.Phone;
62import com.android.internal.telephony.PhoneConstants;
63import com.android.internal.telephony.PhoneFactory;
Jack Yu1a2fc352017-07-14 17:14:37 -070064import com.android.internal.telephony.SettingsObserver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import com.android.internal.telephony.TelephonyCapabilities;
Youming Ye47a6adc2018-11-19 15:33:36 -080066import com.android.internal.telephony.TelephonyComponentFactory;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067import com.android.internal.telephony.TelephonyIntents;
Jack Yu1a2fc352017-07-14 17:14:37 -070068import com.android.internal.telephony.dataconnection.DataConnectionReasons;
69import com.android.internal.telephony.dataconnection.DataConnectionReasons.DataDisallowedReasonType;
Brad Ebinger24c29992019-12-05 13:03:21 -080070import com.android.internal.telephony.ims.ImsResolver;
Jack Yu1a2fc352017-07-14 17:14:37 -070071import com.android.internal.util.IndentingPrintWriter;
Andrew Leefb7f92e2015-02-26 16:23:32 -080072import com.android.phone.settings.SettingsConstants;
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -070073import com.android.phone.vvm.CarrierVvmPackageInstalledReceiver;
James.cf Linc9f35a42020-01-15 02:35:22 +080074import com.android.services.telephony.rcs.TelephonyRcsService;
Brad Ebinger28626122017-08-10 14:13:35 -070075import com.android.services.telephony.sip.SipAccountRegistry;
Brad Ebinger3fa43462016-04-12 16:06:48 -070076import com.android.services.telephony.sip.SipUtil;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070077
Jack Yu1a2fc352017-07-14 17:14:37 -070078import java.io.FileDescriptor;
79import java.io.PrintWriter;
Jordan Liuc353b162019-07-23 15:54:41 -070080import java.lang.annotation.Retention;
81import java.lang.annotation.RetentionPolicy;
chen xubaf9fe52019-07-02 17:28:24 -070082import java.util.List;
Jack Yu1a2fc352017-07-14 17:14:37 -070083
Santos Cordon7d4ddf62013-07-10 11:58:08 -070084/**
85 * Global state for the telephony subsystem when running in the primary
86 * phone process.
87 */
Sailesh Nepalbf900542014-07-15 16:18:32 -070088public class PhoneGlobals extends ContextWrapper {
Jack Yu1a2fc352017-07-14 17:14:37 -070089 public static final String LOG_TAG = "PhoneGlobals";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090
91 /**
92 * Phone app-wide debug level:
93 * 0 - no debug logging
94 * 1 - normal debug logging if ro.debuggable is set (which is true in
95 * "eng" and "userdebug" builds but not "user" builds)
96 * 2 - ultra-verbose debug logging
97 *
98 * Most individual classes in the phone app have a local DBG constant,
99 * typically set to
100 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
101 * or else
102 * (PhoneApp.DBG_LEVEL >= 2)
103 * depending on the desired verbosity.
104 *
105 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
106 */
Andrew Lee88b51e22014-10-29 15:48:51 -0700107 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700108
109 private static final boolean DBG =
110 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
111 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
112
113 // Message codes; see mHandler below.
114 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
Jordan Liuc353b162019-07-23 15:54:41 -0700117 private static final int EVENT_DATA_ROAMING_CONNECTED = 11;
118 private static final int EVENT_DATA_ROAMING_OK = 12;
119 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 13;
120 private static final int EVENT_RESTART_SIP = 14;
121 private static final int EVENT_DATA_ROAMING_SETTINGS_CHANGED = 15;
122 private static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED = 16;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123
124 // The MMI codes are also used by the InCallScreen.
125 public static final int MMI_INITIATE = 51;
126 public static final int MMI_COMPLETE = 52;
127 public static final int MMI_CANCEL = 53;
128 // Don't use message codes larger than 99 here; those are reserved for
129 // the individual Activities of the Phone UI.
130
Santos Cordone18902f2016-03-22 17:16:04 -0700131 public static final int AIRPLANE_ON = 1;
132 public static final int AIRPLANE_OFF = 0;
133
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134 /**
135 * Allowable values for the wake lock code.
136 * SLEEP means the device can be put to sleep.
137 * PARTIAL means wake the processor, but we display can be kept off.
138 * FULL means wake both the processor and the display.
139 */
140 public enum WakeState {
141 SLEEP,
142 PARTIAL,
143 FULL
144 }
145
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700146 private static PhoneGlobals sMe;
147
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700148 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700149 CallNotifier notifier;
150 CallerInfoCache callerInfoCache;
Santos Cordon63a84242013-07-23 13:32:52 -0700151 NotificationMgr notificationMgr;
Brad Ebinger24c29992019-12-05 13:03:21 -0800152 ImsResolver mImsResolver;
James.cf Linc9f35a42020-01-15 02:35:22 +0800153 TelephonyRcsService mTelephonyRcsService;
Andrew Lee9431b832015-03-09 18:46:45 -0700154 public PhoneInterfaceManager phoneMgr;
James.cf Linaf3183c2019-10-24 00:59:00 +0800155 public ImsRcsController imsRcsController;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800156 CarrierConfigLoader configLoader;
Santos Cordon63a84242013-07-23 13:32:52 -0700157
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530158 private Phone phoneInEcm;
Santos Cordon63a84242013-07-23 13:32:52 -0700159
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700160 static boolean sVoiceCapable = true;
161
Santos Cordonc593d002015-06-03 15:41:15 -0700162 // TODO: Remove, no longer used.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700163 CdmaPhoneCallState cdmaPhoneCallState;
164
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165 // The currently-active PUK entry activity and progress dialog.
166 // Normally, these are the Emergency Dialer and the subsequent
167 // progress dialog. null if there is are no such objects in
168 // the foreground.
169 private Activity mPUKEntryActivity;
170 private ProgressDialog mPUKEntryProgressDialog;
171
Jordan Liuc353b162019-07-23 15:54:41 -0700172 /** @hide */
173 @Retention(RetentionPolicy.SOURCE)
174 @IntDef(prefix = {"ROAMING_NOTIFICATION_"},
175 value = {
176 ROAMING_NOTIFICATION_NO_NOTIFICATION,
177 ROAMING_NOTIFICATION_CONNECTED,
178 ROAMING_NOTIFICATION_DISCONNECTED})
179 public @interface RoamingNotification {}
180
181 private static final int ROAMING_NOTIFICATION_NO_NOTIFICATION = 0;
182 private static final int ROAMING_NOTIFICATION_CONNECTED = 1;
183 private static final int ROAMING_NOTIFICATION_DISCONNECTED = 2;
184
185 @RoamingNotification
186 private int mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
Jack Yu953f9352017-05-18 14:41:06 -0700187
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700188 private WakeState mWakeState = WakeState.SLEEP;
189
190 private PowerManager mPowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700191 private PowerManager.WakeLock mWakeLock;
192 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194
Jack Yu1a2fc352017-07-14 17:14:37 -0700195 private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
196 private final LocalLog mDataRoamingNotifLog = new LocalLog(50);
197
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198 // Broadcast receiver for various intent broadcasts (see onCreate())
199 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
Brad Ebinger533c6c12017-08-02 11:38:48 -0700200 // Broadcast receiver for SIP based intents (see onCreate())
Brad Ebinger28626122017-08-10 14:13:35 -0700201 private final SipReceiver mSipReceiver = new SipReceiver();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700202
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700203 private final CarrierVvmPackageInstalledReceiver mCarrierVvmPackageInstalledReceiver =
204 new CarrierVvmPackageInstalledReceiver();
205
Jack Yu1a2fc352017-07-14 17:14:37 -0700206 private final SettingsObserver mSettingsObserver;
207
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700208 Handler mHandler = new Handler() {
209 @Override
210 public void handleMessage(Message msg) {
211 PhoneConstants.State phoneState;
Jack Yu1a2fc352017-07-14 17:14:37 -0700212 if (VDBG) Log.v(LOG_TAG, "event=" + msg.what);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700213 switch (msg.what) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700214 // TODO: This event should be handled by the lock screen, just
215 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
216 case EVENT_SIM_NETWORK_LOCKED:
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700217 if (getCarrierConfig().getBoolean(
218 CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700219 // Some products don't have the concept of a "SIM network lock"
220 Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; "
Eric Erfanian945409f2018-02-21 19:26:15 +0000221 + "not showing 'SIM network unlock' PIN entry screen");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700222 } else {
223 // Normal case: show the "SIM network unlock" PIN entry screen.
224 // The user won't be able to do anything else until
225 // they enter a valid SIM network PIN.
226 Log.i(LOG_TAG, "show sim depersonal panel");
Biljana Maneva96291112018-01-30 13:12:59 +0800227 Phone phone = (Phone) ((AsyncResult) msg.obj).userObj;
228 IccNetworkDepersonalizationPanel.showDialog(phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700229 }
230 break;
231
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700232 case EVENT_DATA_ROAMING_DISCONNECTED:
Jordan Liuc353b162019-07-23 15:54:41 -0700233 notificationMgr.showDataRoamingNotification(msg.arg1, false);
234 break;
235
236 case EVENT_DATA_ROAMING_CONNECTED:
237 notificationMgr.showDataRoamingNotification(msg.arg1, true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700238 break;
239
240 case EVENT_DATA_ROAMING_OK:
Jordan Liuc353b162019-07-23 15:54:41 -0700241 notificationMgr.hideDataRoamingNotification();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700242 break;
243
244 case MMI_COMPLETE:
245 onMMIComplete((AsyncResult) msg.obj);
246 break;
247
248 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800249 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700250 break;
251
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700252 case EVENT_SIM_STATE_CHANGED:
253 // Marks the event where the SIM goes into ready state.
254 // Right now, this is only used for the PUK-unlocking
255 // process.
Amit Mahajanc08787c2019-03-26 16:11:55 -0700256 if (msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_READY)
257 || msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_LOADED)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700258 // when the right event is triggered and there
259 // are UI objects in the foreground, we close
260 // them to display the lock panel.
261 if (mPUKEntryActivity != null) {
262 mPUKEntryActivity.finish();
263 mPUKEntryActivity = null;
264 }
265 if (mPUKEntryProgressDialog != null) {
266 mPUKEntryProgressDialog.dismiss();
267 mPUKEntryProgressDialog = null;
268 }
269 }
270 break;
271
272 case EVENT_UNSOL_CDMA_INFO_RECORD:
273 //TODO: handle message here;
274 break;
Brad Ebinger3fa43462016-04-12 16:06:48 -0700275 case EVENT_RESTART_SIP:
276 // This should only run if the Phone process crashed and was restarted. We do
277 // not want this running if the device is still in the FBE encrypted state.
Brad Ebinger28626122017-08-10 14:13:35 -0700278 // This is the same procedure that is triggered in the SipIncomingCallReceiver
Brad Ebinger3fa43462016-04-12 16:06:48 -0700279 // upon BOOT_COMPLETED.
Meng Wanga4b29e12019-10-04 12:00:06 -0700280 UserManager userManager =
281 (UserManager) sMe.getSystemService(Context.USER_SERVICE);
Brad Ebinger3fa43462016-04-12 16:06:48 -0700282 if (userManager != null && userManager.isUserUnlocked()) {
283 SipUtil.startSipService();
284 }
285 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700286 case EVENT_DATA_ROAMING_SETTINGS_CHANGED:
287 case EVENT_MOBILE_DATA_SETTINGS_CHANGED:
288 updateDataRoamingStatus();
289 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700290 }
291 }
292 };
293
294 public PhoneGlobals(Context context) {
295 super(context);
296 sMe = this;
Jack Yu1a2fc352017-07-14 17:14:37 -0700297 mSettingsObserver = new SettingsObserver(context, mHandler);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700298 }
299
300 public void onCreate() {
301 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
302
303 ContentResolver resolver = getContentResolver();
304
305 // Cache the "voice capable" flag.
306 // This flag currently comes from a resource (which is
307 // overrideable on a per-product basis):
Michele87262742020-01-16 12:23:53 -0800308 sVoiceCapable = ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE))
309 .isVoiceCapable();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700310 // ...but this might eventually become a PackageManager "system
311 // feature" instead, in which case we'd do something like:
312 // sVoiceCapable =
313 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
314
Stuart Scottdcf40a92014-12-09 10:45:01 -0800315 if (mCM == null) {
Nathan Haroldf9df6ea2019-03-08 11:54:22 -0800316 // Initialize AnomalyReporter early so that it can be used
317 AnomalyReporter.initialize(this);
Nathan Harold0db5c5e2019-01-22 20:18:56 -0800318
Youming Ye47a6adc2018-11-19 15:33:36 -0800319 // Inject telephony component factory if configured using other jars.
320 XmlResourceParser parser = getResources().getXml(R.xml.telephony_injection);
321 TelephonyComponentFactory.getInstance().injectTheComponentFactory(parser);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700322 // Initialize the telephony framework
323 PhoneFactory.makeDefaultPhones(this);
324
Brad Ebinger24c29992019-12-05 13:03:21 -0800325 // Only bring up ImsResolver if the device supports having an IMS stack.
326 if (getPackageManager().hasSystemFeature(
327 PackageManager.FEATURE_TELEPHONY_IMS)) {
328 // Get the package name of the default IMS implementation.
329 String defaultImsMmtelPackage = getResources().getString(
330 R.string.config_ims_mmtel_package);
331 String defaultImsRcsPackage = getResources().getString(
332 R.string.config_ims_rcs_package);
333 mImsResolver = new ImsResolver(this, defaultImsMmtelPackage,
334 defaultImsRcsPackage, PhoneFactory.getPhones().length);
335 mImsResolver.initialize();
336 }
337
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338 // Start TelephonyDebugService After the default phone is created.
339 Intent intent = new Intent(this, TelephonyDebugService.class);
340 startService(intent);
341
342 mCM = CallManager.getInstance();
Stuart Scottdcf40a92014-12-09 10:45:01 -0800343 for (Phone phone : PhoneFactory.getPhones()) {
344 mCM.registerPhone(phone);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800345 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700346
347 // Create the NotificationMgr singleton, which is used to display
348 // status bar icons and control other status bar behavior.
349 notificationMgr = NotificationMgr.init(this);
350
Brad Ebinger3fa43462016-04-12 16:06:48 -0700351 // If PhoneGlobals has crashed and is being restarted, then restart.
352 mHandler.sendEmptyMessage(EVENT_RESTART_SIP);
353
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700354 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
355 cdmaPhoneCallState = new CdmaPhoneCallState();
356 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358 // before registering for phone state changes
359 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
360 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
361 // lock used to keep the processor awake, when we don't care for the display.
362 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
363 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700364
365 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
366
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367 // Create the CallerInfoCache singleton, which remembers custom ring tone and
368 // send-to-voicemail settings.
369 //
370 // The asynchronous caching will start just after this call.
371 callerInfoCache = CallerInfoCache.init(this);
372
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800373 phoneMgr = PhoneInterfaceManager.init(this);
Santos Cordon406c0342013-08-28 00:07:47 -0700374
James.cf Linaf3183c2019-10-24 00:59:00 +0800375 imsRcsController = ImsRcsController.init(this);
376
James.cf Linc9f35a42020-01-15 02:35:22 +0800377 if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
Brad Ebingera68a4972020-01-30 17:31:23 -0800378 mTelephonyRcsService = new TelephonyRcsService(this,
379 PhoneFactory.getPhones().length);
380 mTelephonyRcsService.initialize();
James.cf Linc9f35a42020-01-15 02:35:22 +0800381 imsRcsController.setRcsService(mTelephonyRcsService);
382 }
383
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800384 configLoader = CarrierConfigLoader.init(this);
385
Jack Yu1a2fc352017-07-14 17:14:37 -0700386 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700387 // asynchronous events from the telephony layer (like
388 // launching the incoming-call UI when an incoming call comes
389 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800390 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700391
Stuart Scottdcf40a92014-12-09 10:45:01 -0800392 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700393
394 // register for MMI/USSD
395 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
396
Qiong Liucc3fe812019-09-23 15:25:44 +0800397 // Initialize cell status using current airplane mode.
398 handleAirplaneModeChange(this, Settings.Global.getInt(getContentResolver(),
399 Settings.Global.AIRPLANE_MODE_ON, AIRPLANE_OFF));
400
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401 // Register for misc other intent broadcasts.
402 IntentFilter intentFilter =
403 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700404 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
405 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
406 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
407 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700408 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
409 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700410 registerReceiver(mReceiver, intentFilter);
411
Brad Ebinger533c6c12017-08-02 11:38:48 -0700412 IntentFilter sipIntentFilter = new IntentFilter(Intent.ACTION_BOOT_COMPLETED);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700413 sipIntentFilter.addAction(SipManager.ACTION_SIP_SERVICE_UP);
414 sipIntentFilter.addAction(SipManager.ACTION_SIP_CALL_OPTION_CHANGED);
Grace Jiab95592a2020-01-15 14:12:24 -0800415 sipIntentFilter.addAction(SipManager.ACTION_SIP_REMOVE_PROFILE);
Brad Ebinger28626122017-08-10 14:13:35 -0700416 registerReceiver(mSipReceiver, sipIntentFilter);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700417
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700418 mCarrierVvmPackageInstalledReceiver.register(this);
419
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700420 //set the default values for the preferences in the phone.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700421 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700422 }
423
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424 // XXX pre-load the SimProvider so that it's ready
425 resolver.getType(Uri.parse("content://icc/adn"));
426
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427 // TODO: Register for Cdma Information Records
428 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
429
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700430 // Read HAC settings and configure audio hardware
431 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800432 int hac = android.provider.Settings.System.getInt(
433 getContentResolver(),
434 android.provider.Settings.System.HEARING_AID,
435 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700436 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Jordan Liu71bfa4c2019-08-21 11:46:09 -0700437 audioManager.setParameters(
438 SettingsConstants.HAC_KEY + "=" + (hac == SettingsConstants.HAC_ENABLED
439 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700440 }
Santos Cordonff506f52013-11-21 19:13:19 -0800441 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700442
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700443 /**
444 * Returns the singleton instance of the PhoneApp.
445 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800446 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700447 if (sMe == null) {
448 throw new IllegalStateException("No PhoneGlobals here!");
449 }
450 return sMe;
451 }
452
453 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800454 * Returns the default phone.
455 *
Andrew Lee385019f2014-11-24 14:19:50 -0800456 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457 */
Andrew Lee83383e42014-10-31 12:42:28 -0700458 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800459 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700460 }
461
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800462 public static Phone getPhone(int subId) {
463 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800464 }
465
Brad Ebinger24c29992019-12-05 13:03:21 -0800466 public ImsResolver getImsResolver() {
467 return mImsResolver;
468 }
469
Santos Cordonde10b752013-09-19 04:11:33 -0700470 /* package */ CallManager getCallManager() {
471 return mCM;
472 }
473
Chris Manton4e9fa912015-06-19 11:26:57 -0700474 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800475 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700476 }
477
Chris Manton4e9fa912015-06-19 11:26:57 -0700478 public PersistableBundle getCarrierConfigForSubId(int subId) {
Philip P. Moltmann0079aae2020-03-05 16:24:02 -0800479 return configLoader.getConfigForSubIdWithFeature(subId, getOpPackageName(),
480 getAttributionTag());
Junda Liu605148f2015-04-28 15:23:40 -0700481 }
482
Jack Yu1a2fc352017-07-14 17:14:37 -0700483 private void registerSettingsObserver() {
484 mSettingsObserver.unobserve();
485 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
486 String mobileDataSetting = Settings.Global.MOBILE_DATA;
487 if (TelephonyManager.getDefault().getSimCount() > 1) {
488 int subId = mDefaultDataSubId;
489 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
490 dataRoamingSetting += subId;
491 mobileDataSetting += subId;
492 }
493 }
494
495 // Listen for user data roaming setting changed event
496 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
497 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
498
499 // Listen for mobile data setting changed event
500 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
501 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
502 }
503
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700504 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700505 * Sets the activity responsible for un-PUK-blocking the device
506 * so that we may close it when we receive a positive result.
507 * mPUKEntryActivity is also used to indicate to the device that
508 * we are trying to un-PUK-lock the phone. In other words, iff
509 * it is NOT null, then we are trying to unlock and waiting for
510 * the SIM to move to READY state.
511 *
512 * @param activity is the activity to close when PUK has
513 * finished unlocking. Can be set to null to indicate the unlock
514 * or SIM READYing process is over.
515 */
516 void setPukEntryActivity(Activity activity) {
517 mPUKEntryActivity = activity;
518 }
519
520 Activity getPUKEntryActivity() {
521 return mPUKEntryActivity;
522 }
523
524 /**
525 * Sets the dialog responsible for notifying the user of un-PUK-
526 * blocking - SIM READYing progress, so that we may dismiss it
527 * when we receive a positive result.
528 *
529 * @param dialog indicates the progress dialog informing the user
530 * of the state of the device. Dismissed upon completion of
531 * READYing process
532 */
533 void setPukEntryProgressDialog(ProgressDialog dialog) {
534 mPUKEntryProgressDialog = dialog;
535 }
536
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700537 KeyguardManager getKeyguardManager() {
538 return mKeyguardManager;
539 }
540
541 private void onMMIComplete(AsyncResult r) {
542 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
543 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800544 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700545 }
546
fionaxu80126972017-02-01 17:01:26 -0800547 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700548 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700549 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700550 }
551
Chris Mantona09f3632016-02-09 14:48:42 -0800552 private void handleAirplaneModeChange(Context context, int newMode) {
553 int cellState = Settings.Global.getInt(context.getContentResolver(),
554 Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
555 boolean isAirplaneNewlyOn = (newMode == 1);
556 switch (cellState) {
557 case PhoneConstants.CELL_OFF_FLAG:
558 // Airplane mode does not affect the cell radio if user
559 // has turned it off.
560 break;
561 case PhoneConstants.CELL_ON_FLAG:
562 maybeTurnCellOff(context, isAirplaneNewlyOn);
563 break;
564 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
565 maybeTurnCellOn(context, isAirplaneNewlyOn);
566 break;
567 }
Hall Liu7f56e1a2019-07-10 14:41:14 -0700568 for (Phone phone : PhoneFactory.getPhones()) {
569 phone.getServiceStateTracker().onAirplaneModeChanged(isAirplaneNewlyOn);
570 }
Chris Mantona09f3632016-02-09 14:48:42 -0800571 }
572
573 /*
574 * Returns true if the radio must be turned off when entering airplane mode.
575 */
576 private boolean isCellOffInAirplaneMode(Context context) {
577 String airplaneModeRadios = Settings.Global.getString(context.getContentResolver(),
578 Settings.Global.AIRPLANE_MODE_RADIOS);
579 return airplaneModeRadios == null
580 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
581 }
582
583 private void setRadioPowerOff(Context context) {
584 Log.i(LOG_TAG, "Turning radio off - airplane");
585 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
Eric Erfanian945409f2018-02-21 19:26:15 +0000586 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Meng Wang4c5f4f22019-10-23 14:08:43 -0700587 TelephonyProperties.airplane_mode_on(true); // true means int value 1
Chris Mantona09f3632016-02-09 14:48:42 -0800588 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
589 PhoneUtils.setRadioPower(false);
590 }
591
592 private void setRadioPowerOn(Context context) {
593 Log.i(LOG_TAG, "Turning radio on - airplane");
594 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
595 PhoneConstants.CELL_ON_FLAG);
596 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT,
597 1);
Meng Wang4c5f4f22019-10-23 14:08:43 -0700598 TelephonyProperties.airplane_mode_on(false); // false means int value 0
Chris Mantona09f3632016-02-09 14:48:42 -0800599 PhoneUtils.setRadioPower(true);
600 }
601
602 private void maybeTurnCellOff(Context context, boolean isAirplaneNewlyOn) {
603 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700604 // If we are trying to turn off the radio, make sure there are no active
605 // emergency calls. If there are, switch airplane mode back to off.
Tyler Gunn900d8fd2018-09-21 09:22:12 -0700606 TelecomManager tm = (TelecomManager) context.getSystemService(TELECOM_SERVICE);
607
608 if (tm != null && tm.isInEmergencyCall()) {
Santos Cordone18902f2016-03-22 17:16:04 -0700609 // Switch airplane mode back to off.
Jordan Liua55aaaa2019-08-28 15:33:05 -0700610 ConnectivityManager cm =
611 (ConnectivityManager) context.getSystemService(CONNECTIVITY_SERVICE);
612 cm.setAirplaneMode(false);
Santos Cordone18902f2016-03-22 17:16:04 -0700613 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
614 .show();
615 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Chris Mantona09f3632016-02-09 14:48:42 -0800616 } else if (isCellOffInAirplaneMode(context)) {
617 setRadioPowerOff(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700618 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800619 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700620 }
Chris Mantona09f3632016-02-09 14:48:42 -0800621 }
622 }
623
624 private void maybeTurnCellOn(Context context, boolean isAirplaneNewlyOn) {
625 if (!isAirplaneNewlyOn) {
626 setRadioPowerOn(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700627 }
628 }
629
Santos Cordon593ab382013-08-06 21:58:23 -0700630 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700631 * Receiver for misc intent broadcasts the Phone app cares about.
632 */
633 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
634 @Override
635 public void onReceive(Context context, Intent intent) {
636 String action = intent.getAction();
637 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Santos Cordone18902f2016-03-22 17:16:04 -0700638 int airplaneMode = Settings.Global.getInt(getContentResolver(),
639 Settings.Global.AIRPLANE_MODE_ON, AIRPLANE_OFF);
640 // Treat any non-OFF values as ON.
641 if (airplaneMode != AIRPLANE_OFF) {
642 airplaneMode = AIRPLANE_ON;
643 }
Chris Mantona09f3632016-02-09 14:48:42 -0800644 handleAirplaneModeChange(context, airplaneMode);
Amit Mahajanf5d92c82018-11-02 17:44:40 -0700645 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
646 // re-register as it may be a new IccCard
647 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
648 SubscriptionManager.INVALID_PHONE_INDEX);
649 if (SubscriptionManager.isValidPhoneId(phoneId)) {
650 PhoneUtils.unregisterIccStatus(mHandler, phoneId);
651 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED, phoneId);
652 }
653 if (mPUKEntryActivity != null) {
654 // if an attempt to un-PUK-lock the device was made, while we're
655 // receiving this state change notification, notify the handler.
656 // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has
657 // been attempted.
658 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
659 intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE)));
660 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700661 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
662 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800663 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
664 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700665 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
666 handleServiceStateChanged(intent);
667 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530668 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530669 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530670 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
671 if (phoneInEcm != null) {
672 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
673 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
674 // Start Emergency Callback Mode service
Daniel Brightd24bee42020-01-09 22:11:15 -0800675 if (intent.getBooleanExtra(
676 TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530677 context.startService(new Intent(context,
678 EmergencyCallbackModeService.class));
679 } else {
680 phoneInEcm = null;
681 }
682 } else {
683 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
684 // on a device that doesn't support ECM in the first place.
685 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
686 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
687 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700688 }
689 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530690 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700691 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700692 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
693 // Roaming status could be overridden by carrier config, so we need to update it.
694 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
695 updateDataRoamingStatus();
chen xubaf9fe52019-07-02 17:28:24 -0700696 updateLimitedSimFunctionForDualSim();
Jack Yu1a2fc352017-07-14 17:14:37 -0700697 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
698 // We also need to pay attention when default data subscription changes.
699 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
700 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
701 registerSettingsObserver();
702 Phone phone = getPhone(mDefaultDataSubId);
703 if (phone != null) {
704 updateDataRoamingStatus();
705 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700706 }
707 }
708 }
709
Brad Ebinger28626122017-08-10 14:13:35 -0700710 private class SipReceiver extends BroadcastReceiver {
711
712 @Override
713 public void onReceive(Context context, Intent intent) {
714 String action = intent.getAction();
715
716 SipAccountRegistry sipAccountRegistry = SipAccountRegistry.getInstance();
717 if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
718 SipUtil.startSipService();
719 } else if (action.equals(SipManager.ACTION_SIP_SERVICE_UP)
720 || action.equals(SipManager.ACTION_SIP_CALL_OPTION_CHANGED)) {
721 sipAccountRegistry.setup(context);
Grace Jiab95592a2020-01-15 14:12:24 -0800722 } else if (action.equals(SipManager.ACTION_SIP_REMOVE_PROFILE)) {
Brad Ebinger28626122017-08-10 14:13:35 -0700723 if (DBG) {
724 Log.d(LOG_TAG, "SIP_REMOVE_PHONE "
725 + intent.getStringExtra(SipManager.EXTRA_LOCAL_URI));
726 }
727 sipAccountRegistry.removeSipProfile(intent.getStringExtra(
728 SipManager.EXTRA_LOCAL_URI));
729 } else {
730 if (DBG) Log.d(LOG_TAG, "onReceive, action not processed: " + action);
731 }
732 }
733 }
734
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700735 private void handleServiceStateChanged(Intent intent) {
736 /**
737 * This used to handle updating EriTextWidgetProvider this routine
738 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
739 * be removed. But leaving just in case it might be needed in the near
740 * future.
741 */
742
Jack Yu1a2fc352017-07-14 17:14:37 -0700743 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700744 // If service just returned, start sending out the queued messages
Santos Cordonc593d002015-06-03 15:41:15 -0700745 Bundle extras = intent.getExtras();
746 if (extras != null) {
747 ServiceState ss = ServiceState.newFromBundle(extras);
748 if (ss != null) {
749 int state = ss.getState();
Jayachandran C2ef9a482017-05-12 22:07:47 -0700750 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
751 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
752 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -0700753
754 if (VDBG) {
755 Log.v(LOG_TAG, "subId=" + subId + ",mDefaultDataSubId="
756 + mDefaultDataSubId + ",ss roaming=" + ss.getDataRoaming());
757 }
758 if (subId == mDefaultDataSubId) {
759 updateDataRoamingStatus();
760 }
Santos Cordonc593d002015-06-03 15:41:15 -0700761 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700762 }
763 }
764
Jack Yu1a2fc352017-07-14 17:14:37 -0700765 /**
Jordan Liuc353b162019-07-23 15:54:41 -0700766 * @return whether or not we should show a notification when connecting to data roaming if the
767 * user has data roaming enabled
768 */
769 private boolean shouldShowDataConnectedRoaming(int subId) {
770 PersistableBundle config = getCarrierConfigForSubId(subId);
771 return config.getBoolean(CarrierConfigManager
772 .KEY_SHOW_DATA_CONNECTED_ROAMING_NOTIFICATION_BOOL);
773 }
774
775 /**
Jack Yu1a2fc352017-07-14 17:14:37 -0700776 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
777 * to notify the user so they can enable it through settings. Vise versa if the condition
778 * changes, we need to dismiss the notification.
779 */
780 private void updateDataRoamingStatus() {
781 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
782 Phone phone = getPhone(mDefaultDataSubId);
783 if (phone == null) {
784 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
785 return;
786 }
787
788 DataConnectionReasons reasons = new DataConnectionReasons();
Jack Yu311536f2018-11-26 11:20:48 -0800789 boolean dataAllowed = phone.isDataAllowed(ApnSetting.TYPE_DEFAULT, reasons);
Jack Yu1a2fc352017-07-14 17:14:37 -0700790 mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons);
791 if (VDBG) Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons);
Jordan Liuc353b162019-07-23 15:54:41 -0700792 if (!dataAllowed && reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED)) {
793 // No need to show it again if we never cancelled it explicitly.
794 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_DISCONNECTED) return;
Jack Yu1a2fc352017-07-14 17:14:37 -0700795 // If the only reason of no data is data roaming disabled, then we notify the user
796 // so the user can turn on data roaming.
Jordan Liuc353b162019-07-23 15:54:41 -0700797 mPrevRoamingNotification = ROAMING_NOTIFICATION_DISCONNECTED;
Jack Yu1a2fc352017-07-14 17:14:37 -0700798 Log.d(LOG_TAG, "Show roaming disconnected notification");
Jordan Liuc353b162019-07-23 15:54:41 -0700799 mDataRoamingNotifLog.log("Show roaming off.");
Pengquan Meng8783d932017-10-16 14:57:40 -0700800 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_DISCONNECTED);
801 msg.arg1 = mDefaultDataSubId;
802 msg.sendToTarget();
Jordan Liuc353b162019-07-23 15:54:41 -0700803 } else if (dataAllowed && dataIsNowRoaming(mDefaultDataSubId)
804 && shouldShowDataConnectedRoaming(mDefaultDataSubId)) {
805 // No need to show it again if we never cancelled it explicitly, or carrier config
806 // indicates this is not needed.
807 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_CONNECTED) return;
808 mPrevRoamingNotification = ROAMING_NOTIFICATION_CONNECTED;
809 Log.d(LOG_TAG, "Show roaming connected notification");
810 mDataRoamingNotifLog.log("Show roaming on.");
811 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_CONNECTED);
812 msg.arg1 = mDefaultDataSubId;
813 msg.sendToTarget();
814 } else if (mPrevRoamingNotification != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
815 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
816 // is not the only data disable reason. In this case we dismiss the notification we
817 // showed earlier.
818 mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
819 Log.d(LOG_TAG, "Dismiss roaming notification");
Jack Yu1a2fc352017-07-14 17:14:37 -0700820 mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed + ", reasons=" + reasons);
821 mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
822 }
823 }
824
Jordan Liuc353b162019-07-23 15:54:41 -0700825 /**
826 *
827 * @param subId to check roaming on
828 * @return whether we have transitioned to dataRoaming
829 */
830 private boolean dataIsNowRoaming(int subId) {
831 return getPhone(subId).getServiceState().getDataRoaming();
832 }
833
chen xubaf9fe52019-07-02 17:28:24 -0700834 private void updateLimitedSimFunctionForDualSim() {
835 if (DBG) Log.d(LOG_TAG, "updateLimitedSimFunctionForDualSim");
836 // check conditions to display limited SIM function notification under dual SIM
837 SubscriptionManager subMgr = (SubscriptionManager) getSystemService(
838 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
839 List<SubscriptionInfo> subList = subMgr.getActiveSubscriptionInfoList(false);
840 if (subList != null && subList.size() > 1) {
841 CarrierConfigManager configMgr = (CarrierConfigManager)
842 getSystemService(Context.CARRIER_CONFIG_SERVICE);
843 for (SubscriptionInfo info : subList) {
844 PersistableBundle b = configMgr.getConfigForSubId(info.getSubscriptionId());
845 if (b != null) {
846 if (b.getBoolean(CarrierConfigManager
847 .KEY_LIMITED_SIM_FUNCTION_NOTIFICATION_FOR_DSDS_BOOL)) {
848 notificationMgr.showLimitedSimFunctionWarningNotification(
849 info.getSubscriptionId(),
850 info.getDisplayName().toString());
851 } else {
852 notificationMgr.dismissLimitedSimFunctionWarningNotification(
853 info.getSubscriptionId());
854 }
855 }
856 }
857 } else {
858 // cancel notifications for all subs
859 notificationMgr.dismissLimitedSimFunctionWarningNotification(
860 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
861 }
862 notificationMgr.dismissLimitedSimFunctionWarningNotificationForInactiveSubs();
863
864 }
865
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530866 public Phone getPhoneInEcm() {
867 return phoneInEcm;
868 }
869
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700870 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800871 * Triggers a refresh of the message waiting (voicemail) indicator.
872 *
873 * @param subId the subscription id we should refresh the notification for.
874 */
875 public void refreshMwiIndicator(int subId) {
876 notificationMgr.refreshMwi(subId);
877 }
878
879 /**
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700880 * Called when the network selection on the subscription {@code subId} is changed by the user.
881 *
882 * @param subId the subscription id.
883 */
884 public void onNetworkSelectionChanged(int subId) {
885 Phone phone = getPhone(subId);
886 if (phone != null) {
887 notificationMgr.updateNetworkSelection(phone.getServiceState().getState(), subId);
888 } else {
889 Log.w(LOG_TAG, "onNetworkSelectionChanged on null phone, subId: " + subId);
890 }
891 }
892
893 /**
Jack Yu1a2fc352017-07-14 17:14:37 -0700894 * Dump the state of the object, add calls to other objects as desired.
895 *
896 * @param fd File descriptor
897 * @param printWriter Print writer
898 * @param args Arguments
899 */
900 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
901 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
902 pw.println("------- PhoneGlobals -------");
903 pw.increaseIndent();
Jordan Liuc353b162019-07-23 15:54:41 -0700904 pw.println("mPrevRoamingNotification=" + mPrevRoamingNotification);
Jack Yu1a2fc352017-07-14 17:14:37 -0700905 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
906 pw.println("mDataRoamingNotifLog:");
Keun young Parkdebb8532019-05-30 16:35:27 -0700907 pw.println("isSmsCapable=" + TelephonyManager.from(this).isSmsCapable());
Jack Yu1a2fc352017-07-14 17:14:37 -0700908 pw.increaseIndent();
909 mDataRoamingNotifLog.dump(fd, pw, args);
910 pw.decreaseIndent();
Brad Ebinger24c29992019-12-05 13:03:21 -0800911 pw.println("ImsResolver:");
912 pw.increaseIndent();
913 try {
914 if (mImsResolver != null) mImsResolver.dump(fd, pw, args);
915 } catch (Exception e) {
916 e.printStackTrace();
917 }
918 pw.decreaseIndent();
Brad Ebingera68a4972020-01-30 17:31:23 -0800919 pw.println("RcsService:");
920 try {
921 if (mTelephonyRcsService != null) mTelephonyRcsService.dump(fd, pw, args);
922 } catch (Exception e) {
923 e.printStackTrace();
924 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700925 pw.decreaseIndent();
926 pw.println("------- End PhoneGlobals -------");
927 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700928}