blob: 7f1e60de70f475a2b5efe596cfbf24488661a9b6 [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;
Brad Ebinger28626122017-08-10 14:13:35 -070074import com.android.services.telephony.sip.SipAccountRegistry;
Brad Ebinger3fa43462016-04-12 16:06:48 -070075import com.android.services.telephony.sip.SipUtil;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070076
Jack Yu1a2fc352017-07-14 17:14:37 -070077import java.io.FileDescriptor;
78import java.io.PrintWriter;
Jordan Liuc353b162019-07-23 15:54:41 -070079import java.lang.annotation.Retention;
80import java.lang.annotation.RetentionPolicy;
chen xubaf9fe52019-07-02 17:28:24 -070081import java.util.List;
Jack Yu1a2fc352017-07-14 17:14:37 -070082
Santos Cordon7d4ddf62013-07-10 11:58:08 -070083/**
84 * Global state for the telephony subsystem when running in the primary
85 * phone process.
86 */
Sailesh Nepalbf900542014-07-15 16:18:32 -070087public class PhoneGlobals extends ContextWrapper {
Jack Yu1a2fc352017-07-14 17:14:37 -070088 public static final String LOG_TAG = "PhoneGlobals";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089
90 /**
91 * Phone app-wide debug level:
92 * 0 - no debug logging
93 * 1 - normal debug logging if ro.debuggable is set (which is true in
94 * "eng" and "userdebug" builds but not "user" builds)
95 * 2 - ultra-verbose debug logging
96 *
97 * Most individual classes in the phone app have a local DBG constant,
98 * typically set to
99 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
100 * or else
101 * (PhoneApp.DBG_LEVEL >= 2)
102 * depending on the desired verbosity.
103 *
104 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
105 */
Andrew Lee88b51e22014-10-29 15:48:51 -0700106 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107
108 private static final boolean DBG =
109 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
110 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
111
112 // Message codes; see mHandler below.
113 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
Jordan Liuc353b162019-07-23 15:54:41 -0700116 private static final int EVENT_DATA_ROAMING_CONNECTED = 11;
117 private static final int EVENT_DATA_ROAMING_OK = 12;
118 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 13;
119 private static final int EVENT_RESTART_SIP = 14;
120 private static final int EVENT_DATA_ROAMING_SETTINGS_CHANGED = 15;
121 private static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED = 16;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700122
123 // The MMI codes are also used by the InCallScreen.
124 public static final int MMI_INITIATE = 51;
125 public static final int MMI_COMPLETE = 52;
126 public static final int MMI_CANCEL = 53;
127 // Don't use message codes larger than 99 here; those are reserved for
128 // the individual Activities of the Phone UI.
129
Santos Cordone18902f2016-03-22 17:16:04 -0700130 public static final int AIRPLANE_ON = 1;
131 public static final int AIRPLANE_OFF = 0;
132
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133 /**
134 * Allowable values for the wake lock code.
135 * SLEEP means the device can be put to sleep.
136 * PARTIAL means wake the processor, but we display can be kept off.
137 * FULL means wake both the processor and the display.
138 */
139 public enum WakeState {
140 SLEEP,
141 PARTIAL,
142 FULL
143 }
144
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700145 private static PhoneGlobals sMe;
146
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700147 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700148 CallNotifier notifier;
149 CallerInfoCache callerInfoCache;
Santos Cordon63a84242013-07-23 13:32:52 -0700150 NotificationMgr notificationMgr;
Brad Ebinger24c29992019-12-05 13:03:21 -0800151 ImsResolver mImsResolver;
Andrew Lee9431b832015-03-09 18:46:45 -0700152 public PhoneInterfaceManager phoneMgr;
James.cf Linaf3183c2019-10-24 00:59:00 +0800153 public ImsRcsController imsRcsController;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800154 CarrierConfigLoader configLoader;
Santos Cordon63a84242013-07-23 13:32:52 -0700155
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530156 private Phone phoneInEcm;
Santos Cordon63a84242013-07-23 13:32:52 -0700157
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700158 static boolean sVoiceCapable = true;
159
Santos Cordonc593d002015-06-03 15:41:15 -0700160 // TODO: Remove, no longer used.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700161 CdmaPhoneCallState cdmaPhoneCallState;
162
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700163 // The currently-active PUK entry activity and progress dialog.
164 // Normally, these are the Emergency Dialer and the subsequent
165 // progress dialog. null if there is are no such objects in
166 // the foreground.
167 private Activity mPUKEntryActivity;
168 private ProgressDialog mPUKEntryProgressDialog;
169
Jordan Liuc353b162019-07-23 15:54:41 -0700170 /** @hide */
171 @Retention(RetentionPolicy.SOURCE)
172 @IntDef(prefix = {"ROAMING_NOTIFICATION_"},
173 value = {
174 ROAMING_NOTIFICATION_NO_NOTIFICATION,
175 ROAMING_NOTIFICATION_CONNECTED,
176 ROAMING_NOTIFICATION_DISCONNECTED})
177 public @interface RoamingNotification {}
178
179 private static final int ROAMING_NOTIFICATION_NO_NOTIFICATION = 0;
180 private static final int ROAMING_NOTIFICATION_CONNECTED = 1;
181 private static final int ROAMING_NOTIFICATION_DISCONNECTED = 2;
182
183 @RoamingNotification
184 private int mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
Jack Yu953f9352017-05-18 14:41:06 -0700185
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186 private WakeState mWakeState = WakeState.SLEEP;
187
188 private PowerManager mPowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700189 private PowerManager.WakeLock mWakeLock;
190 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700191 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192
Jack Yu1a2fc352017-07-14 17:14:37 -0700193 private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
194 private final LocalLog mDataRoamingNotifLog = new LocalLog(50);
195
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196 // Broadcast receiver for various intent broadcasts (see onCreate())
197 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
Brad Ebinger533c6c12017-08-02 11:38:48 -0700198 // Broadcast receiver for SIP based intents (see onCreate())
Brad Ebinger28626122017-08-10 14:13:35 -0700199 private final SipReceiver mSipReceiver = new SipReceiver();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700200
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700201 private final CarrierVvmPackageInstalledReceiver mCarrierVvmPackageInstalledReceiver =
202 new CarrierVvmPackageInstalledReceiver();
203
Jack Yu1a2fc352017-07-14 17:14:37 -0700204 private final SettingsObserver mSettingsObserver;
205
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700206 Handler mHandler = new Handler() {
207 @Override
208 public void handleMessage(Message msg) {
209 PhoneConstants.State phoneState;
Jack Yu1a2fc352017-07-14 17:14:37 -0700210 if (VDBG) Log.v(LOG_TAG, "event=" + msg.what);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700211 switch (msg.what) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700212 // TODO: This event should be handled by the lock screen, just
213 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
214 case EVENT_SIM_NETWORK_LOCKED:
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700215 if (getCarrierConfig().getBoolean(
216 CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700217 // Some products don't have the concept of a "SIM network lock"
218 Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; "
Eric Erfanian945409f2018-02-21 19:26:15 +0000219 + "not showing 'SIM network unlock' PIN entry screen");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700220 } else {
221 // Normal case: show the "SIM network unlock" PIN entry screen.
222 // The user won't be able to do anything else until
223 // they enter a valid SIM network PIN.
224 Log.i(LOG_TAG, "show sim depersonal panel");
Biljana Maneva96291112018-01-30 13:12:59 +0800225 Phone phone = (Phone) ((AsyncResult) msg.obj).userObj;
226 IccNetworkDepersonalizationPanel.showDialog(phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700227 }
228 break;
229
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700230 case EVENT_DATA_ROAMING_DISCONNECTED:
Jordan Liuc353b162019-07-23 15:54:41 -0700231 notificationMgr.showDataRoamingNotification(msg.arg1, false);
232 break;
233
234 case EVENT_DATA_ROAMING_CONNECTED:
235 notificationMgr.showDataRoamingNotification(msg.arg1, true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700236 break;
237
238 case EVENT_DATA_ROAMING_OK:
Jordan Liuc353b162019-07-23 15:54:41 -0700239 notificationMgr.hideDataRoamingNotification();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700240 break;
241
242 case MMI_COMPLETE:
243 onMMIComplete((AsyncResult) msg.obj);
244 break;
245
246 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800247 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700248 break;
249
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700250 case EVENT_SIM_STATE_CHANGED:
251 // Marks the event where the SIM goes into ready state.
252 // Right now, this is only used for the PUK-unlocking
253 // process.
Amit Mahajanc08787c2019-03-26 16:11:55 -0700254 if (msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_READY)
255 || msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_LOADED)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700256 // when the right event is triggered and there
257 // are UI objects in the foreground, we close
258 // them to display the lock panel.
259 if (mPUKEntryActivity != null) {
260 mPUKEntryActivity.finish();
261 mPUKEntryActivity = null;
262 }
263 if (mPUKEntryProgressDialog != null) {
264 mPUKEntryProgressDialog.dismiss();
265 mPUKEntryProgressDialog = null;
266 }
267 }
268 break;
269
270 case EVENT_UNSOL_CDMA_INFO_RECORD:
271 //TODO: handle message here;
272 break;
Brad Ebinger3fa43462016-04-12 16:06:48 -0700273 case EVENT_RESTART_SIP:
274 // This should only run if the Phone process crashed and was restarted. We do
275 // not want this running if the device is still in the FBE encrypted state.
Brad Ebinger28626122017-08-10 14:13:35 -0700276 // This is the same procedure that is triggered in the SipIncomingCallReceiver
Brad Ebinger3fa43462016-04-12 16:06:48 -0700277 // upon BOOT_COMPLETED.
Meng Wanga4b29e12019-10-04 12:00:06 -0700278 UserManager userManager =
279 (UserManager) sMe.getSystemService(Context.USER_SERVICE);
Brad Ebinger3fa43462016-04-12 16:06:48 -0700280 if (userManager != null && userManager.isUserUnlocked()) {
281 SipUtil.startSipService();
282 }
283 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700284 case EVENT_DATA_ROAMING_SETTINGS_CHANGED:
285 case EVENT_MOBILE_DATA_SETTINGS_CHANGED:
286 updateDataRoamingStatus();
287 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700288 }
289 }
290 };
291
292 public PhoneGlobals(Context context) {
293 super(context);
294 sMe = this;
Jack Yu1a2fc352017-07-14 17:14:37 -0700295 mSettingsObserver = new SettingsObserver(context, mHandler);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700296 }
297
298 public void onCreate() {
299 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
300
301 ContentResolver resolver = getContentResolver();
302
303 // Cache the "voice capable" flag.
304 // This flag currently comes from a resource (which is
305 // overrideable on a per-product basis):
306 sVoiceCapable =
307 getResources().getBoolean(com.android.internal.R.bool.config_voice_capable);
308 // ...but this might eventually become a PackageManager "system
309 // feature" instead, in which case we'd do something like:
310 // sVoiceCapable =
311 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
312
Stuart Scottdcf40a92014-12-09 10:45:01 -0800313 if (mCM == null) {
Nathan Haroldf9df6ea2019-03-08 11:54:22 -0800314 // Initialize AnomalyReporter early so that it can be used
315 AnomalyReporter.initialize(this);
Nathan Harold0db5c5e2019-01-22 20:18:56 -0800316
Youming Ye47a6adc2018-11-19 15:33:36 -0800317 // Inject telephony component factory if configured using other jars.
318 XmlResourceParser parser = getResources().getXml(R.xml.telephony_injection);
319 TelephonyComponentFactory.getInstance().injectTheComponentFactory(parser);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700320 // Initialize the telephony framework
321 PhoneFactory.makeDefaultPhones(this);
322
Brad Ebinger24c29992019-12-05 13:03:21 -0800323 // Only bring up ImsResolver if the device supports having an IMS stack.
324 if (getPackageManager().hasSystemFeature(
325 PackageManager.FEATURE_TELEPHONY_IMS)) {
326 // Get the package name of the default IMS implementation.
327 String defaultImsMmtelPackage = getResources().getString(
328 R.string.config_ims_mmtel_package);
329 String defaultImsRcsPackage = getResources().getString(
330 R.string.config_ims_rcs_package);
331 mImsResolver = new ImsResolver(this, defaultImsMmtelPackage,
332 defaultImsRcsPackage, PhoneFactory.getPhones().length);
333 mImsResolver.initialize();
334 }
335
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700336 // Start TelephonyDebugService After the default phone is created.
337 Intent intent = new Intent(this, TelephonyDebugService.class);
338 startService(intent);
339
340 mCM = CallManager.getInstance();
Stuart Scottdcf40a92014-12-09 10:45:01 -0800341 for (Phone phone : PhoneFactory.getPhones()) {
342 mCM.registerPhone(phone);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800343 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344
345 // Create the NotificationMgr singleton, which is used to display
346 // status bar icons and control other status bar behavior.
347 notificationMgr = NotificationMgr.init(this);
348
Brad Ebinger3fa43462016-04-12 16:06:48 -0700349 // If PhoneGlobals has crashed and is being restarted, then restart.
350 mHandler.sendEmptyMessage(EVENT_RESTART_SIP);
351
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700352 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
353 cdmaPhoneCallState = new CdmaPhoneCallState();
354 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356 // before registering for phone state changes
357 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
358 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
359 // lock used to keep the processor awake, when we don't care for the display.
360 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
361 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362
363 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
364
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365 // Create the CallerInfoCache singleton, which remembers custom ring tone and
366 // send-to-voicemail settings.
367 //
368 // The asynchronous caching will start just after this call.
369 callerInfoCache = CallerInfoCache.init(this);
370
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800371 phoneMgr = PhoneInterfaceManager.init(this);
Santos Cordon406c0342013-08-28 00:07:47 -0700372
James.cf Linaf3183c2019-10-24 00:59:00 +0800373 imsRcsController = ImsRcsController.init(this);
374
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800375 configLoader = CarrierConfigLoader.init(this);
376
Jack Yu1a2fc352017-07-14 17:14:37 -0700377 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700378 // asynchronous events from the telephony layer (like
379 // launching the incoming-call UI when an incoming call comes
380 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800381 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382
Stuart Scottdcf40a92014-12-09 10:45:01 -0800383 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384
385 // register for MMI/USSD
386 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
387
Qiong Liucc3fe812019-09-23 15:25:44 +0800388 // Initialize cell status using current airplane mode.
389 handleAirplaneModeChange(this, Settings.Global.getInt(getContentResolver(),
390 Settings.Global.AIRPLANE_MODE_ON, AIRPLANE_OFF));
391
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700392 // Register for misc other intent broadcasts.
393 IntentFilter intentFilter =
394 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700395 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
396 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
397 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
398 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700399 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
400 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401 registerReceiver(mReceiver, intentFilter);
402
Brad Ebinger533c6c12017-08-02 11:38:48 -0700403 IntentFilter sipIntentFilter = new IntentFilter(Intent.ACTION_BOOT_COMPLETED);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700404 sipIntentFilter.addAction(SipManager.ACTION_SIP_SERVICE_UP);
405 sipIntentFilter.addAction(SipManager.ACTION_SIP_CALL_OPTION_CHANGED);
406 sipIntentFilter.addAction(SipManager.ACTION_SIP_REMOVE_PHONE);
Brad Ebinger28626122017-08-10 14:13:35 -0700407 registerReceiver(mSipReceiver, sipIntentFilter);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700408
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700409 mCarrierVvmPackageInstalledReceiver.register(this);
410
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700411 //set the default values for the preferences in the phone.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700412 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413 }
414
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415 // XXX pre-load the SimProvider so that it's ready
416 resolver.getType(Uri.parse("content://icc/adn"));
417
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700418 // TODO: Register for Cdma Information Records
419 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
420
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700421 // Read HAC settings and configure audio hardware
422 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800423 int hac = android.provider.Settings.System.getInt(
424 getContentResolver(),
425 android.provider.Settings.System.HEARING_AID,
426 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Jordan Liu71bfa4c2019-08-21 11:46:09 -0700428 audioManager.setParameters(
429 SettingsConstants.HAC_KEY + "=" + (hac == SettingsConstants.HAC_ENABLED
430 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700431 }
Santos Cordonff506f52013-11-21 19:13:19 -0800432 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700433
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434 /**
435 * Returns the singleton instance of the PhoneApp.
436 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800437 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700438 if (sMe == null) {
439 throw new IllegalStateException("No PhoneGlobals here!");
440 }
441 return sMe;
442 }
443
444 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800445 * Returns the default phone.
446 *
Andrew Lee385019f2014-11-24 14:19:50 -0800447 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448 */
Andrew Lee83383e42014-10-31 12:42:28 -0700449 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800450 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700451 }
452
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800453 public static Phone getPhone(int subId) {
454 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800455 }
456
Brad Ebinger24c29992019-12-05 13:03:21 -0800457 public ImsResolver getImsResolver() {
458 return mImsResolver;
459 }
460
Santos Cordonde10b752013-09-19 04:11:33 -0700461 /* package */ CallManager getCallManager() {
462 return mCM;
463 }
464
Chris Manton4e9fa912015-06-19 11:26:57 -0700465 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800466 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700467 }
468
Chris Manton4e9fa912015-06-19 11:26:57 -0700469 public PersistableBundle getCarrierConfigForSubId(int subId) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -0700470 return configLoader.getConfigForSubIdWithFeature(subId, getOpPackageName(), getFeatureId());
Junda Liu605148f2015-04-28 15:23:40 -0700471 }
472
Jack Yu1a2fc352017-07-14 17:14:37 -0700473 private void registerSettingsObserver() {
474 mSettingsObserver.unobserve();
475 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
476 String mobileDataSetting = Settings.Global.MOBILE_DATA;
477 if (TelephonyManager.getDefault().getSimCount() > 1) {
478 int subId = mDefaultDataSubId;
479 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
480 dataRoamingSetting += subId;
481 mobileDataSetting += subId;
482 }
483 }
484
485 // Listen for user data roaming setting changed event
486 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
487 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
488
489 // Listen for mobile data setting changed event
490 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
491 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
492 }
493
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700494 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700495 * Sets the activity responsible for un-PUK-blocking the device
496 * so that we may close it when we receive a positive result.
497 * mPUKEntryActivity is also used to indicate to the device that
498 * we are trying to un-PUK-lock the phone. In other words, iff
499 * it is NOT null, then we are trying to unlock and waiting for
500 * the SIM to move to READY state.
501 *
502 * @param activity is the activity to close when PUK has
503 * finished unlocking. Can be set to null to indicate the unlock
504 * or SIM READYing process is over.
505 */
506 void setPukEntryActivity(Activity activity) {
507 mPUKEntryActivity = activity;
508 }
509
510 Activity getPUKEntryActivity() {
511 return mPUKEntryActivity;
512 }
513
514 /**
515 * Sets the dialog responsible for notifying the user of un-PUK-
516 * blocking - SIM READYing progress, so that we may dismiss it
517 * when we receive a positive result.
518 *
519 * @param dialog indicates the progress dialog informing the user
520 * of the state of the device. Dismissed upon completion of
521 * READYing process
522 */
523 void setPukEntryProgressDialog(ProgressDialog dialog) {
524 mPUKEntryProgressDialog = dialog;
525 }
526
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700527 KeyguardManager getKeyguardManager() {
528 return mKeyguardManager;
529 }
530
531 private void onMMIComplete(AsyncResult r) {
532 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
533 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800534 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700535 }
536
fionaxu80126972017-02-01 17:01:26 -0800537 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700538 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700539 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700540 }
541
Chris Mantona09f3632016-02-09 14:48:42 -0800542 private void handleAirplaneModeChange(Context context, int newMode) {
543 int cellState = Settings.Global.getInt(context.getContentResolver(),
544 Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
545 boolean isAirplaneNewlyOn = (newMode == 1);
546 switch (cellState) {
547 case PhoneConstants.CELL_OFF_FLAG:
548 // Airplane mode does not affect the cell radio if user
549 // has turned it off.
550 break;
551 case PhoneConstants.CELL_ON_FLAG:
552 maybeTurnCellOff(context, isAirplaneNewlyOn);
553 break;
554 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
555 maybeTurnCellOn(context, isAirplaneNewlyOn);
556 break;
557 }
Hall Liu7f56e1a2019-07-10 14:41:14 -0700558 for (Phone phone : PhoneFactory.getPhones()) {
559 phone.getServiceStateTracker().onAirplaneModeChanged(isAirplaneNewlyOn);
560 }
Chris Mantona09f3632016-02-09 14:48:42 -0800561 }
562
563 /*
564 * Returns true if the radio must be turned off when entering airplane mode.
565 */
566 private boolean isCellOffInAirplaneMode(Context context) {
567 String airplaneModeRadios = Settings.Global.getString(context.getContentResolver(),
568 Settings.Global.AIRPLANE_MODE_RADIOS);
569 return airplaneModeRadios == null
570 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
571 }
572
573 private void setRadioPowerOff(Context context) {
574 Log.i(LOG_TAG, "Turning radio off - airplane");
575 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
Eric Erfanian945409f2018-02-21 19:26:15 +0000576 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Meng Wang4c5f4f22019-10-23 14:08:43 -0700577 TelephonyProperties.airplane_mode_on(true); // true means int value 1
Chris Mantona09f3632016-02-09 14:48:42 -0800578 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
579 PhoneUtils.setRadioPower(false);
580 }
581
582 private void setRadioPowerOn(Context context) {
583 Log.i(LOG_TAG, "Turning radio on - airplane");
584 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
585 PhoneConstants.CELL_ON_FLAG);
586 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT,
587 1);
Meng Wang4c5f4f22019-10-23 14:08:43 -0700588 TelephonyProperties.airplane_mode_on(false); // false means int value 0
Chris Mantona09f3632016-02-09 14:48:42 -0800589 PhoneUtils.setRadioPower(true);
590 }
591
592 private void maybeTurnCellOff(Context context, boolean isAirplaneNewlyOn) {
593 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700594 // If we are trying to turn off the radio, make sure there are no active
595 // emergency calls. If there are, switch airplane mode back to off.
Tyler Gunn900d8fd2018-09-21 09:22:12 -0700596 TelecomManager tm = (TelecomManager) context.getSystemService(TELECOM_SERVICE);
597
598 if (tm != null && tm.isInEmergencyCall()) {
Santos Cordone18902f2016-03-22 17:16:04 -0700599 // Switch airplane mode back to off.
Jordan Liua55aaaa2019-08-28 15:33:05 -0700600 ConnectivityManager cm =
601 (ConnectivityManager) context.getSystemService(CONNECTIVITY_SERVICE);
602 cm.setAirplaneMode(false);
Santos Cordone18902f2016-03-22 17:16:04 -0700603 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
604 .show();
605 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Chris Mantona09f3632016-02-09 14:48:42 -0800606 } else if (isCellOffInAirplaneMode(context)) {
607 setRadioPowerOff(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700608 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800609 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700610 }
Chris Mantona09f3632016-02-09 14:48:42 -0800611 }
612 }
613
614 private void maybeTurnCellOn(Context context, boolean isAirplaneNewlyOn) {
615 if (!isAirplaneNewlyOn) {
616 setRadioPowerOn(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700617 }
618 }
619
Santos Cordon593ab382013-08-06 21:58:23 -0700620 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700621 * Receiver for misc intent broadcasts the Phone app cares about.
622 */
623 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
624 @Override
625 public void onReceive(Context context, Intent intent) {
626 String action = intent.getAction();
627 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Santos Cordone18902f2016-03-22 17:16:04 -0700628 int airplaneMode = Settings.Global.getInt(getContentResolver(),
629 Settings.Global.AIRPLANE_MODE_ON, AIRPLANE_OFF);
630 // Treat any non-OFF values as ON.
631 if (airplaneMode != AIRPLANE_OFF) {
632 airplaneMode = AIRPLANE_ON;
633 }
Chris Mantona09f3632016-02-09 14:48:42 -0800634 handleAirplaneModeChange(context, airplaneMode);
Amit Mahajanf5d92c82018-11-02 17:44:40 -0700635 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
636 // re-register as it may be a new IccCard
637 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
638 SubscriptionManager.INVALID_PHONE_INDEX);
639 if (SubscriptionManager.isValidPhoneId(phoneId)) {
640 PhoneUtils.unregisterIccStatus(mHandler, phoneId);
641 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED, phoneId);
642 }
643 if (mPUKEntryActivity != null) {
644 // if an attempt to un-PUK-lock the device was made, while we're
645 // receiving this state change notification, notify the handler.
646 // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has
647 // been attempted.
648 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
649 intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE)));
650 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700651 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
652 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800653 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
654 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700655 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
656 handleServiceStateChanged(intent);
657 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530658 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530659 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530660 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
661 if (phoneInEcm != null) {
662 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
663 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
664 // Start Emergency Callback Mode service
Daniel Brightd24bee42020-01-09 22:11:15 -0800665 if (intent.getBooleanExtra(
666 TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530667 context.startService(new Intent(context,
668 EmergencyCallbackModeService.class));
669 } else {
670 phoneInEcm = null;
671 }
672 } else {
673 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
674 // on a device that doesn't support ECM in the first place.
675 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
676 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
677 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700678 }
679 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530680 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700681 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700682 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
683 // Roaming status could be overridden by carrier config, so we need to update it.
684 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
685 updateDataRoamingStatus();
chen xubaf9fe52019-07-02 17:28:24 -0700686 updateLimitedSimFunctionForDualSim();
Jack Yu1a2fc352017-07-14 17:14:37 -0700687 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
688 // We also need to pay attention when default data subscription changes.
689 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
690 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
691 registerSettingsObserver();
692 Phone phone = getPhone(mDefaultDataSubId);
693 if (phone != null) {
694 updateDataRoamingStatus();
695 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700696 }
697 }
698 }
699
Brad Ebinger28626122017-08-10 14:13:35 -0700700 private class SipReceiver extends BroadcastReceiver {
701
702 @Override
703 public void onReceive(Context context, Intent intent) {
704 String action = intent.getAction();
705
706 SipAccountRegistry sipAccountRegistry = SipAccountRegistry.getInstance();
707 if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
708 SipUtil.startSipService();
709 } else if (action.equals(SipManager.ACTION_SIP_SERVICE_UP)
710 || action.equals(SipManager.ACTION_SIP_CALL_OPTION_CHANGED)) {
711 sipAccountRegistry.setup(context);
712 } else if (action.equals(SipManager.ACTION_SIP_REMOVE_PHONE)) {
713 if (DBG) {
714 Log.d(LOG_TAG, "SIP_REMOVE_PHONE "
715 + intent.getStringExtra(SipManager.EXTRA_LOCAL_URI));
716 }
717 sipAccountRegistry.removeSipProfile(intent.getStringExtra(
718 SipManager.EXTRA_LOCAL_URI));
719 } else {
720 if (DBG) Log.d(LOG_TAG, "onReceive, action not processed: " + action);
721 }
722 }
723 }
724
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700725 private void handleServiceStateChanged(Intent intent) {
726 /**
727 * This used to handle updating EriTextWidgetProvider this routine
728 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
729 * be removed. But leaving just in case it might be needed in the near
730 * future.
731 */
732
Jack Yu1a2fc352017-07-14 17:14:37 -0700733 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700734 // If service just returned, start sending out the queued messages
Santos Cordonc593d002015-06-03 15:41:15 -0700735 Bundle extras = intent.getExtras();
736 if (extras != null) {
737 ServiceState ss = ServiceState.newFromBundle(extras);
738 if (ss != null) {
739 int state = ss.getState();
Jayachandran C2ef9a482017-05-12 22:07:47 -0700740 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
741 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
742 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -0700743
744 if (VDBG) {
745 Log.v(LOG_TAG, "subId=" + subId + ",mDefaultDataSubId="
746 + mDefaultDataSubId + ",ss roaming=" + ss.getDataRoaming());
747 }
748 if (subId == mDefaultDataSubId) {
749 updateDataRoamingStatus();
750 }
Santos Cordonc593d002015-06-03 15:41:15 -0700751 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700752 }
753 }
754
Jack Yu1a2fc352017-07-14 17:14:37 -0700755 /**
Jordan Liuc353b162019-07-23 15:54:41 -0700756 * @return whether or not we should show a notification when connecting to data roaming if the
757 * user has data roaming enabled
758 */
759 private boolean shouldShowDataConnectedRoaming(int subId) {
760 PersistableBundle config = getCarrierConfigForSubId(subId);
761 return config.getBoolean(CarrierConfigManager
762 .KEY_SHOW_DATA_CONNECTED_ROAMING_NOTIFICATION_BOOL);
763 }
764
765 /**
Jack Yu1a2fc352017-07-14 17:14:37 -0700766 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
767 * to notify the user so they can enable it through settings. Vise versa if the condition
768 * changes, we need to dismiss the notification.
769 */
770 private void updateDataRoamingStatus() {
771 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
772 Phone phone = getPhone(mDefaultDataSubId);
773 if (phone == null) {
774 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
775 return;
776 }
777
778 DataConnectionReasons reasons = new DataConnectionReasons();
Jack Yu311536f2018-11-26 11:20:48 -0800779 boolean dataAllowed = phone.isDataAllowed(ApnSetting.TYPE_DEFAULT, reasons);
Jack Yu1a2fc352017-07-14 17:14:37 -0700780 mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons);
781 if (VDBG) Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons);
Jordan Liuc353b162019-07-23 15:54:41 -0700782 if (!dataAllowed && reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED)) {
783 // No need to show it again if we never cancelled it explicitly.
784 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_DISCONNECTED) return;
Jack Yu1a2fc352017-07-14 17:14:37 -0700785 // If the only reason of no data is data roaming disabled, then we notify the user
786 // so the user can turn on data roaming.
Jordan Liuc353b162019-07-23 15:54:41 -0700787 mPrevRoamingNotification = ROAMING_NOTIFICATION_DISCONNECTED;
Jack Yu1a2fc352017-07-14 17:14:37 -0700788 Log.d(LOG_TAG, "Show roaming disconnected notification");
Jordan Liuc353b162019-07-23 15:54:41 -0700789 mDataRoamingNotifLog.log("Show roaming off.");
Pengquan Meng8783d932017-10-16 14:57:40 -0700790 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_DISCONNECTED);
791 msg.arg1 = mDefaultDataSubId;
792 msg.sendToTarget();
Jordan Liuc353b162019-07-23 15:54:41 -0700793 } else if (dataAllowed && dataIsNowRoaming(mDefaultDataSubId)
794 && shouldShowDataConnectedRoaming(mDefaultDataSubId)) {
795 // No need to show it again if we never cancelled it explicitly, or carrier config
796 // indicates this is not needed.
797 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_CONNECTED) return;
798 mPrevRoamingNotification = ROAMING_NOTIFICATION_CONNECTED;
799 Log.d(LOG_TAG, "Show roaming connected notification");
800 mDataRoamingNotifLog.log("Show roaming on.");
801 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_CONNECTED);
802 msg.arg1 = mDefaultDataSubId;
803 msg.sendToTarget();
804 } else if (mPrevRoamingNotification != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
805 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
806 // is not the only data disable reason. In this case we dismiss the notification we
807 // showed earlier.
808 mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
809 Log.d(LOG_TAG, "Dismiss roaming notification");
Jack Yu1a2fc352017-07-14 17:14:37 -0700810 mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed + ", reasons=" + reasons);
811 mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
812 }
813 }
814
Jordan Liuc353b162019-07-23 15:54:41 -0700815 /**
816 *
817 * @param subId to check roaming on
818 * @return whether we have transitioned to dataRoaming
819 */
820 private boolean dataIsNowRoaming(int subId) {
821 return getPhone(subId).getServiceState().getDataRoaming();
822 }
823
chen xubaf9fe52019-07-02 17:28:24 -0700824 private void updateLimitedSimFunctionForDualSim() {
825 if (DBG) Log.d(LOG_TAG, "updateLimitedSimFunctionForDualSim");
826 // check conditions to display limited SIM function notification under dual SIM
827 SubscriptionManager subMgr = (SubscriptionManager) getSystemService(
828 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
829 List<SubscriptionInfo> subList = subMgr.getActiveSubscriptionInfoList(false);
830 if (subList != null && subList.size() > 1) {
831 CarrierConfigManager configMgr = (CarrierConfigManager)
832 getSystemService(Context.CARRIER_CONFIG_SERVICE);
833 for (SubscriptionInfo info : subList) {
834 PersistableBundle b = configMgr.getConfigForSubId(info.getSubscriptionId());
835 if (b != null) {
836 if (b.getBoolean(CarrierConfigManager
837 .KEY_LIMITED_SIM_FUNCTION_NOTIFICATION_FOR_DSDS_BOOL)) {
838 notificationMgr.showLimitedSimFunctionWarningNotification(
839 info.getSubscriptionId(),
840 info.getDisplayName().toString());
841 } else {
842 notificationMgr.dismissLimitedSimFunctionWarningNotification(
843 info.getSubscriptionId());
844 }
845 }
846 }
847 } else {
848 // cancel notifications for all subs
849 notificationMgr.dismissLimitedSimFunctionWarningNotification(
850 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
851 }
852 notificationMgr.dismissLimitedSimFunctionWarningNotificationForInactiveSubs();
853
854 }
855
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530856 public Phone getPhoneInEcm() {
857 return phoneInEcm;
858 }
859
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700860 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800861 * Triggers a refresh of the message waiting (voicemail) indicator.
862 *
863 * @param subId the subscription id we should refresh the notification for.
864 */
865 public void refreshMwiIndicator(int subId) {
866 notificationMgr.refreshMwi(subId);
867 }
868
869 /**
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700870 * Called when the network selection on the subscription {@code subId} is changed by the user.
871 *
872 * @param subId the subscription id.
873 */
874 public void onNetworkSelectionChanged(int subId) {
875 Phone phone = getPhone(subId);
876 if (phone != null) {
877 notificationMgr.updateNetworkSelection(phone.getServiceState().getState(), subId);
878 } else {
879 Log.w(LOG_TAG, "onNetworkSelectionChanged on null phone, subId: " + subId);
880 }
881 }
882
883 /**
Jack Yu1a2fc352017-07-14 17:14:37 -0700884 * Dump the state of the object, add calls to other objects as desired.
885 *
886 * @param fd File descriptor
887 * @param printWriter Print writer
888 * @param args Arguments
889 */
890 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
891 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
892 pw.println("------- PhoneGlobals -------");
893 pw.increaseIndent();
Jordan Liuc353b162019-07-23 15:54:41 -0700894 pw.println("mPrevRoamingNotification=" + mPrevRoamingNotification);
Jack Yu1a2fc352017-07-14 17:14:37 -0700895 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
896 pw.println("mDataRoamingNotifLog:");
Keun young Parkdebb8532019-05-30 16:35:27 -0700897 pw.println("isSmsCapable=" + TelephonyManager.from(this).isSmsCapable());
Jack Yu1a2fc352017-07-14 17:14:37 -0700898 pw.increaseIndent();
899 mDataRoamingNotifLog.dump(fd, pw, args);
900 pw.decreaseIndent();
Brad Ebinger24c29992019-12-05 13:03:21 -0800901 pw.println("ImsResolver:");
902 pw.increaseIndent();
903 try {
904 if (mImsResolver != null) mImsResolver.dump(fd, pw, args);
905 } catch (Exception e) {
906 e.printStackTrace();
907 }
908 pw.decreaseIndent();
Jack Yu1a2fc352017-07-14 17:14:37 -0700909 pw.decreaseIndent();
910 pw.println("------- End PhoneGlobals -------");
911 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700912}