blob: 8094812fcc97218c33c95c8b96a59c6e6fcb2422 [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;
Youming Ye47a6adc2018-11-19 15:33:36 -080029import android.content.res.XmlResourceParser;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.media.AudioManager;
Santos Cordone18902f2016-03-22 17:16:04 -070031import android.net.ConnectivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.net.Uri;
Brad Ebinger533c6c12017-08-02 11:38:48 -070033import android.net.sip.SipManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070034import android.os.AsyncResult;
Junda Liu605148f2015-04-28 15:23:40 -070035import android.os.Bundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036import android.os.Handler;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.os.Message;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070038import android.os.PersistableBundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.os.PowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.os.SystemClock;
41import 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;
Tyler Gunn900d8fd2018-09-21 09:22:12 -070045import android.telecom.TelecomManager;
Nathan Haroldf9df6ea2019-03-08 11:54:22 -080046import android.telephony.AnomalyReporter;
Junda Liu12f7d802015-05-01 12:06:44 -070047import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.telephony.ServiceState;
chen xubaf9fe52019-07-02 17:28:24 -070049import android.telephony.SubscriptionInfo;
Andrew Lee385019f2014-11-24 14:19:50 -080050import android.telephony.SubscriptionManager;
Jack Yu1a2fc352017-07-14 17:14:37 -070051import android.telephony.TelephonyManager;
Jack Yu311536f2018-11-26 11:20:48 -080052import android.telephony.data.ApnSetting;
Jack Yu1a2fc352017-07-14 17:14:37 -070053import android.util.LocalLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.util.Log;
Santos Cordone18902f2016-03-22 17:16:04 -070055import android.widget.Toast;
Ta-wei Yenb29425b2016-09-21 17:28:14 -070056
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import com.android.internal.telephony.CallManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import com.android.internal.telephony.IccCardConstants;
59import com.android.internal.telephony.MmiCode;
60import com.android.internal.telephony.Phone;
61import com.android.internal.telephony.PhoneConstants;
62import com.android.internal.telephony.PhoneFactory;
Jack Yu1a2fc352017-07-14 17:14:37 -070063import com.android.internal.telephony.SettingsObserver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import com.android.internal.telephony.TelephonyCapabilities;
Youming Ye47a6adc2018-11-19 15:33:36 -080065import com.android.internal.telephony.TelephonyComponentFactory;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066import com.android.internal.telephony.TelephonyIntents;
Jack Yu1a2fc352017-07-14 17:14:37 -070067import com.android.internal.telephony.dataconnection.DataConnectionReasons;
68import com.android.internal.telephony.dataconnection.DataConnectionReasons.DataDisallowedReasonType;
69import com.android.internal.util.IndentingPrintWriter;
Andrew Leefb7f92e2015-02-26 16:23:32 -080070import com.android.phone.settings.SettingsConstants;
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -070071import com.android.phone.vvm.CarrierVvmPackageInstalledReceiver;
Brad Ebinger28626122017-08-10 14:13:35 -070072import com.android.services.telephony.sip.SipAccountRegistry;
Brad Ebinger3fa43462016-04-12 16:06:48 -070073import com.android.services.telephony.sip.SipUtil;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074
Jack Yu1a2fc352017-07-14 17:14:37 -070075import java.io.FileDescriptor;
76import java.io.PrintWriter;
Jordan Liuc353b162019-07-23 15:54:41 -070077import java.lang.annotation.Retention;
78import java.lang.annotation.RetentionPolicy;
chen xubaf9fe52019-07-02 17:28:24 -070079import java.util.List;
Jack Yu1a2fc352017-07-14 17:14:37 -070080
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081/**
82 * Global state for the telephony subsystem when running in the primary
83 * phone process.
84 */
Sailesh Nepalbf900542014-07-15 16:18:32 -070085public class PhoneGlobals extends ContextWrapper {
Jack Yu1a2fc352017-07-14 17:14:37 -070086 public static final String LOG_TAG = "PhoneGlobals";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087
88 /**
89 * Phone app-wide debug level:
90 * 0 - no debug logging
91 * 1 - normal debug logging if ro.debuggable is set (which is true in
92 * "eng" and "userdebug" builds but not "user" builds)
93 * 2 - ultra-verbose debug logging
94 *
95 * Most individual classes in the phone app have a local DBG constant,
96 * typically set to
97 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
98 * or else
99 * (PhoneApp.DBG_LEVEL >= 2)
100 * depending on the desired verbosity.
101 *
102 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
103 */
Andrew Lee88b51e22014-10-29 15:48:51 -0700104 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700105
106 private static final boolean DBG =
107 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
108 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
109
110 // Message codes; see mHandler below.
111 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700112 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700113 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
Jordan Liuc353b162019-07-23 15:54:41 -0700114 private static final int EVENT_DATA_ROAMING_CONNECTED = 11;
115 private static final int EVENT_DATA_ROAMING_OK = 12;
116 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 13;
117 private static final int EVENT_RESTART_SIP = 14;
118 private static final int EVENT_DATA_ROAMING_SETTINGS_CHANGED = 15;
119 private static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED = 16;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120
121 // The MMI codes are also used by the InCallScreen.
122 public static final int MMI_INITIATE = 51;
123 public static final int MMI_COMPLETE = 52;
124 public static final int MMI_CANCEL = 53;
125 // Don't use message codes larger than 99 here; those are reserved for
126 // the individual Activities of the Phone UI.
127
Santos Cordone18902f2016-03-22 17:16:04 -0700128 public static final int AIRPLANE_ON = 1;
129 public static final int AIRPLANE_OFF = 0;
130
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131 /**
132 * Allowable values for the wake lock code.
133 * SLEEP means the device can be put to sleep.
134 * PARTIAL means wake the processor, but we display can be kept off.
135 * FULL means wake both the processor and the display.
136 */
137 public enum WakeState {
138 SLEEP,
139 PARTIAL,
140 FULL
141 }
142
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143 private static PhoneGlobals sMe;
144
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700145 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700146 CallNotifier notifier;
147 CallerInfoCache callerInfoCache;
Santos Cordon63a84242013-07-23 13:32:52 -0700148 NotificationMgr notificationMgr;
Andrew Lee9431b832015-03-09 18:46:45 -0700149 public PhoneInterfaceManager phoneMgr;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800150 CarrierConfigLoader configLoader;
Santos Cordon63a84242013-07-23 13:32:52 -0700151
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530152 private Phone phoneInEcm;
Santos Cordon63a84242013-07-23 13:32:52 -0700153
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154 static boolean sVoiceCapable = true;
155
Santos Cordonc593d002015-06-03 15:41:15 -0700156 // TODO: Remove, no longer used.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157 CdmaPhoneCallState cdmaPhoneCallState;
158
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159 // The currently-active PUK entry activity and progress dialog.
160 // Normally, these are the Emergency Dialer and the subsequent
161 // progress dialog. null if there is are no such objects in
162 // the foreground.
163 private Activity mPUKEntryActivity;
164 private ProgressDialog mPUKEntryProgressDialog;
165
Jordan Liuc353b162019-07-23 15:54:41 -0700166 /** @hide */
167 @Retention(RetentionPolicy.SOURCE)
168 @IntDef(prefix = {"ROAMING_NOTIFICATION_"},
169 value = {
170 ROAMING_NOTIFICATION_NO_NOTIFICATION,
171 ROAMING_NOTIFICATION_CONNECTED,
172 ROAMING_NOTIFICATION_DISCONNECTED})
173 public @interface RoamingNotification {}
174
175 private static final int ROAMING_NOTIFICATION_NO_NOTIFICATION = 0;
176 private static final int ROAMING_NOTIFICATION_CONNECTED = 1;
177 private static final int ROAMING_NOTIFICATION_DISCONNECTED = 2;
178
179 @RoamingNotification
180 private int mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
Jack Yu953f9352017-05-18 14:41:06 -0700181
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700182 private WakeState mWakeState = WakeState.SLEEP;
183
184 private PowerManager mPowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185 private PowerManager.WakeLock mWakeLock;
186 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700187 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700188
Jack Yu1a2fc352017-07-14 17:14:37 -0700189 private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
190 private final LocalLog mDataRoamingNotifLog = new LocalLog(50);
191
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192 // Broadcast receiver for various intent broadcasts (see onCreate())
193 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
Brad Ebinger533c6c12017-08-02 11:38:48 -0700194 // Broadcast receiver for SIP based intents (see onCreate())
Brad Ebinger28626122017-08-10 14:13:35 -0700195 private final SipReceiver mSipReceiver = new SipReceiver();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700197 private final CarrierVvmPackageInstalledReceiver mCarrierVvmPackageInstalledReceiver =
198 new CarrierVvmPackageInstalledReceiver();
199
Jack Yu1a2fc352017-07-14 17:14:37 -0700200 private final SettingsObserver mSettingsObserver;
201
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700202 Handler mHandler = new Handler() {
203 @Override
204 public void handleMessage(Message msg) {
205 PhoneConstants.State phoneState;
Jack Yu1a2fc352017-07-14 17:14:37 -0700206 if (VDBG) Log.v(LOG_TAG, "event=" + msg.what);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700207 switch (msg.what) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700208 // TODO: This event should be handled by the lock screen, just
209 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
210 case EVENT_SIM_NETWORK_LOCKED:
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700211 if (getCarrierConfig().getBoolean(
212 CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700213 // Some products don't have the concept of a "SIM network lock"
214 Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; "
Eric Erfanian945409f2018-02-21 19:26:15 +0000215 + "not showing 'SIM network unlock' PIN entry screen");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700216 } else {
217 // Normal case: show the "SIM network unlock" PIN entry screen.
218 // The user won't be able to do anything else until
219 // they enter a valid SIM network PIN.
220 Log.i(LOG_TAG, "show sim depersonal panel");
Biljana Maneva96291112018-01-30 13:12:59 +0800221 Phone phone = (Phone) ((AsyncResult) msg.obj).userObj;
222 IccNetworkDepersonalizationPanel.showDialog(phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700223 }
224 break;
225
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700226 case EVENT_DATA_ROAMING_DISCONNECTED:
Jordan Liuc353b162019-07-23 15:54:41 -0700227 notificationMgr.showDataRoamingNotification(msg.arg1, false);
228 break;
229
230 case EVENT_DATA_ROAMING_CONNECTED:
231 notificationMgr.showDataRoamingNotification(msg.arg1, true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700232 break;
233
234 case EVENT_DATA_ROAMING_OK:
Jordan Liuc353b162019-07-23 15:54:41 -0700235 notificationMgr.hideDataRoamingNotification();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700236 break;
237
238 case MMI_COMPLETE:
239 onMMIComplete((AsyncResult) msg.obj);
240 break;
241
242 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800243 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700244 break;
245
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700246 case EVENT_SIM_STATE_CHANGED:
247 // Marks the event where the SIM goes into ready state.
248 // Right now, this is only used for the PUK-unlocking
249 // process.
Amit Mahajanc08787c2019-03-26 16:11:55 -0700250 if (msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_READY)
251 || msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_LOADED)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700252 // when the right event is triggered and there
253 // are UI objects in the foreground, we close
254 // them to display the lock panel.
255 if (mPUKEntryActivity != null) {
256 mPUKEntryActivity.finish();
257 mPUKEntryActivity = null;
258 }
259 if (mPUKEntryProgressDialog != null) {
260 mPUKEntryProgressDialog.dismiss();
261 mPUKEntryProgressDialog = null;
262 }
263 }
264 break;
265
266 case EVENT_UNSOL_CDMA_INFO_RECORD:
267 //TODO: handle message here;
268 break;
Brad Ebinger3fa43462016-04-12 16:06:48 -0700269 case EVENT_RESTART_SIP:
270 // This should only run if the Phone process crashed and was restarted. We do
271 // not want this running if the device is still in the FBE encrypted state.
Brad Ebinger28626122017-08-10 14:13:35 -0700272 // This is the same procedure that is triggered in the SipIncomingCallReceiver
Brad Ebinger3fa43462016-04-12 16:06:48 -0700273 // upon BOOT_COMPLETED.
274 UserManager userManager = UserManager.get(sMe);
275 if (userManager != null && userManager.isUserUnlocked()) {
276 SipUtil.startSipService();
277 }
278 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700279 case EVENT_DATA_ROAMING_SETTINGS_CHANGED:
280 case EVENT_MOBILE_DATA_SETTINGS_CHANGED:
281 updateDataRoamingStatus();
282 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700283 }
284 }
285 };
286
287 public PhoneGlobals(Context context) {
288 super(context);
289 sMe = this;
Jack Yu1a2fc352017-07-14 17:14:37 -0700290 mSettingsObserver = new SettingsObserver(context, mHandler);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700291 }
292
293 public void onCreate() {
294 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
295
296 ContentResolver resolver = getContentResolver();
297
298 // Cache the "voice capable" flag.
299 // This flag currently comes from a resource (which is
300 // overrideable on a per-product basis):
301 sVoiceCapable =
302 getResources().getBoolean(com.android.internal.R.bool.config_voice_capable);
303 // ...but this might eventually become a PackageManager "system
304 // feature" instead, in which case we'd do something like:
305 // sVoiceCapable =
306 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
307
Stuart Scottdcf40a92014-12-09 10:45:01 -0800308 if (mCM == null) {
Nathan Haroldf9df6ea2019-03-08 11:54:22 -0800309 // Initialize AnomalyReporter early so that it can be used
310 AnomalyReporter.initialize(this);
Nathan Harold0db5c5e2019-01-22 20:18:56 -0800311
Youming Ye47a6adc2018-11-19 15:33:36 -0800312 // Inject telephony component factory if configured using other jars.
313 XmlResourceParser parser = getResources().getXml(R.xml.telephony_injection);
314 TelephonyComponentFactory.getInstance().injectTheComponentFactory(parser);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700315 // Initialize the telephony framework
316 PhoneFactory.makeDefaultPhones(this);
317
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700318 // Start TelephonyDebugService After the default phone is created.
319 Intent intent = new Intent(this, TelephonyDebugService.class);
320 startService(intent);
321
322 mCM = CallManager.getInstance();
Stuart Scottdcf40a92014-12-09 10:45:01 -0800323 for (Phone phone : PhoneFactory.getPhones()) {
324 mCM.registerPhone(phone);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800325 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700326
327 // Create the NotificationMgr singleton, which is used to display
328 // status bar icons and control other status bar behavior.
329 notificationMgr = NotificationMgr.init(this);
330
Brad Ebinger3fa43462016-04-12 16:06:48 -0700331 // If PhoneGlobals has crashed and is being restarted, then restart.
332 mHandler.sendEmptyMessage(EVENT_RESTART_SIP);
333
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700334 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
335 cdmaPhoneCallState = new CdmaPhoneCallState();
336 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700337
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338 // before registering for phone state changes
339 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
340 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
341 // lock used to keep the processor awake, when we don't care for the display.
342 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
343 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344
345 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
346
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700347 // Create the CallerInfoCache singleton, which remembers custom ring tone and
348 // send-to-voicemail settings.
349 //
350 // The asynchronous caching will start just after this call.
351 callerInfoCache = CallerInfoCache.init(this);
352
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800353 phoneMgr = PhoneInterfaceManager.init(this);
Santos Cordon406c0342013-08-28 00:07:47 -0700354
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800355 configLoader = CarrierConfigLoader.init(this);
356
Jack Yu1a2fc352017-07-14 17:14:37 -0700357 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358 // asynchronous events from the telephony layer (like
359 // launching the incoming-call UI when an incoming call comes
360 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800361 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362
Stuart Scottdcf40a92014-12-09 10:45:01 -0800363 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700364
365 // register for MMI/USSD
366 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
367
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700368 // Register for misc other intent broadcasts.
369 IntentFilter intentFilter =
370 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
372 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
373 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
374 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700375 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
376 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700377 registerReceiver(mReceiver, intentFilter);
378
Brad Ebinger533c6c12017-08-02 11:38:48 -0700379 IntentFilter sipIntentFilter = new IntentFilter(Intent.ACTION_BOOT_COMPLETED);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700380 sipIntentFilter.addAction(SipManager.ACTION_SIP_SERVICE_UP);
381 sipIntentFilter.addAction(SipManager.ACTION_SIP_CALL_OPTION_CHANGED);
382 sipIntentFilter.addAction(SipManager.ACTION_SIP_REMOVE_PHONE);
Brad Ebinger28626122017-08-10 14:13:35 -0700383 registerReceiver(mSipReceiver, sipIntentFilter);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700384
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700385 mCarrierVvmPackageInstalledReceiver.register(this);
386
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700387 //set the default values for the preferences in the phone.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700389 }
390
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700391 // XXX pre-load the SimProvider so that it's ready
392 resolver.getType(Uri.parse("content://icc/adn"));
393
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394 // TODO: Register for Cdma Information Records
395 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
396
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397 // Read HAC settings and configure audio hardware
398 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800399 int hac = android.provider.Settings.System.getInt(
400 getContentResolver(),
401 android.provider.Settings.System.HEARING_AID,
402 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700403 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Jordan Liu71bfa4c2019-08-21 11:46:09 -0700404 audioManager.setParameters(
405 SettingsConstants.HAC_KEY + "=" + (hac == SettingsConstants.HAC_ENABLED
406 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700407 }
Santos Cordonff506f52013-11-21 19:13:19 -0800408 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700410 /**
411 * Returns the singleton instance of the PhoneApp.
412 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800413 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700414 if (sMe == null) {
415 throw new IllegalStateException("No PhoneGlobals here!");
416 }
417 return sMe;
418 }
419
420 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800421 * Returns the default phone.
422 *
Andrew Lee385019f2014-11-24 14:19:50 -0800423 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424 */
Andrew Lee83383e42014-10-31 12:42:28 -0700425 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800426 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427 }
428
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800429 public static Phone getPhone(int subId) {
430 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800431 }
432
Santos Cordonde10b752013-09-19 04:11:33 -0700433 /* package */ CallManager getCallManager() {
434 return mCM;
435 }
436
Chris Manton4e9fa912015-06-19 11:26:57 -0700437 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800438 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700439 }
440
Chris Manton4e9fa912015-06-19 11:26:57 -0700441 public PersistableBundle getCarrierConfigForSubId(int subId) {
Malcolm Chen6d3d6b32018-03-01 13:58:03 -0800442 return configLoader.getConfigForSubId(subId, getOpPackageName());
Junda Liu605148f2015-04-28 15:23:40 -0700443 }
444
Jack Yu1a2fc352017-07-14 17:14:37 -0700445 private void registerSettingsObserver() {
446 mSettingsObserver.unobserve();
447 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
448 String mobileDataSetting = Settings.Global.MOBILE_DATA;
449 if (TelephonyManager.getDefault().getSimCount() > 1) {
450 int subId = mDefaultDataSubId;
451 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
452 dataRoamingSetting += subId;
453 mobileDataSetting += subId;
454 }
455 }
456
457 // Listen for user data roaming setting changed event
458 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
459 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
460
461 // Listen for mobile data setting changed event
462 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
463 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
464 }
465
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700466 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700467 * Sets the activity responsible for un-PUK-blocking the device
468 * so that we may close it when we receive a positive result.
469 * mPUKEntryActivity is also used to indicate to the device that
470 * we are trying to un-PUK-lock the phone. In other words, iff
471 * it is NOT null, then we are trying to unlock and waiting for
472 * the SIM to move to READY state.
473 *
474 * @param activity is the activity to close when PUK has
475 * finished unlocking. Can be set to null to indicate the unlock
476 * or SIM READYing process is over.
477 */
478 void setPukEntryActivity(Activity activity) {
479 mPUKEntryActivity = activity;
480 }
481
482 Activity getPUKEntryActivity() {
483 return mPUKEntryActivity;
484 }
485
486 /**
487 * Sets the dialog responsible for notifying the user of un-PUK-
488 * blocking - SIM READYing progress, so that we may dismiss it
489 * when we receive a positive result.
490 *
491 * @param dialog indicates the progress dialog informing the user
492 * of the state of the device. Dismissed upon completion of
493 * READYing process
494 */
495 void setPukEntryProgressDialog(ProgressDialog dialog) {
496 mPUKEntryProgressDialog = dialog;
497 }
498
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700499 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700500 * If we are not currently keeping the screen on, then poke the power
501 * manager to wake up the screen for the user activity timeout duration.
502 */
503 /* package */ void wakeUpScreen() {
504 synchronized (this) {
505 if (mWakeState == WakeState.SLEEP) {
506 if (DBG) Log.d(LOG_TAG, "pulse screen lock");
Dianne Hackborn148769b2015-07-13 17:55:47 -0700507 mPowerManager.wakeUp(SystemClock.uptimeMillis(), "android.phone:WAKE");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700508 }
509 }
510 }
511
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700512 KeyguardManager getKeyguardManager() {
513 return mKeyguardManager;
514 }
515
516 private void onMMIComplete(AsyncResult r) {
517 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
518 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800519 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700520 }
521
fionaxu80126972017-02-01 17:01:26 -0800522 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700523 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700524 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700525 }
526
Chris Mantona09f3632016-02-09 14:48:42 -0800527 private void handleAirplaneModeChange(Context context, int newMode) {
528 int cellState = Settings.Global.getInt(context.getContentResolver(),
529 Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
530 boolean isAirplaneNewlyOn = (newMode == 1);
531 switch (cellState) {
532 case PhoneConstants.CELL_OFF_FLAG:
533 // Airplane mode does not affect the cell radio if user
534 // has turned it off.
535 break;
536 case PhoneConstants.CELL_ON_FLAG:
537 maybeTurnCellOff(context, isAirplaneNewlyOn);
538 break;
539 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
540 maybeTurnCellOn(context, isAirplaneNewlyOn);
541 break;
542 }
Hall Liu7f56e1a2019-07-10 14:41:14 -0700543 for (Phone phone : PhoneFactory.getPhones()) {
544 phone.getServiceStateTracker().onAirplaneModeChanged(isAirplaneNewlyOn);
545 }
Chris Mantona09f3632016-02-09 14:48:42 -0800546 }
547
548 /*
549 * Returns true if the radio must be turned off when entering airplane mode.
550 */
551 private boolean isCellOffInAirplaneMode(Context context) {
552 String airplaneModeRadios = Settings.Global.getString(context.getContentResolver(),
553 Settings.Global.AIRPLANE_MODE_RADIOS);
554 return airplaneModeRadios == null
555 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
556 }
557
558 private void setRadioPowerOff(Context context) {
559 Log.i(LOG_TAG, "Turning radio off - airplane");
560 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
Eric Erfanian945409f2018-02-21 19:26:15 +0000561 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Sooraj Sasindran798bafa2017-04-03 22:49:00 -0700562 SystemProperties.set("persist.radio.airplane_mode_on", "1");
Chris Mantona09f3632016-02-09 14:48:42 -0800563 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
564 PhoneUtils.setRadioPower(false);
565 }
566
567 private void setRadioPowerOn(Context context) {
568 Log.i(LOG_TAG, "Turning radio on - airplane");
569 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
570 PhoneConstants.CELL_ON_FLAG);
571 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT,
572 1);
Sooraj Sasindran798bafa2017-04-03 22:49:00 -0700573 SystemProperties.set("persist.radio.airplane_mode_on", "0");
Chris Mantona09f3632016-02-09 14:48:42 -0800574 PhoneUtils.setRadioPower(true);
575 }
576
577 private void maybeTurnCellOff(Context context, boolean isAirplaneNewlyOn) {
578 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700579 // If we are trying to turn off the radio, make sure there are no active
580 // emergency calls. If there are, switch airplane mode back to off.
Tyler Gunn900d8fd2018-09-21 09:22:12 -0700581 TelecomManager tm = (TelecomManager) context.getSystemService(TELECOM_SERVICE);
582
583 if (tm != null && tm.isInEmergencyCall()) {
Santos Cordone18902f2016-03-22 17:16:04 -0700584 // Switch airplane mode back to off.
Jordan Liua55aaaa2019-08-28 15:33:05 -0700585 ConnectivityManager cm =
586 (ConnectivityManager) context.getSystemService(CONNECTIVITY_SERVICE);
587 cm.setAirplaneMode(false);
Santos Cordone18902f2016-03-22 17:16:04 -0700588 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
589 .show();
590 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Chris Mantona09f3632016-02-09 14:48:42 -0800591 } else if (isCellOffInAirplaneMode(context)) {
592 setRadioPowerOff(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700593 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800594 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700595 }
Chris Mantona09f3632016-02-09 14:48:42 -0800596 }
597 }
598
599 private void maybeTurnCellOn(Context context, boolean isAirplaneNewlyOn) {
600 if (!isAirplaneNewlyOn) {
601 setRadioPowerOn(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700602 }
603 }
604
Santos Cordon593ab382013-08-06 21:58:23 -0700605 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700606 * Receiver for misc intent broadcasts the Phone app cares about.
607 */
608 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
609 @Override
610 public void onReceive(Context context, Intent intent) {
611 String action = intent.getAction();
612 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Santos Cordone18902f2016-03-22 17:16:04 -0700613 int airplaneMode = Settings.Global.getInt(getContentResolver(),
614 Settings.Global.AIRPLANE_MODE_ON, AIRPLANE_OFF);
615 // Treat any non-OFF values as ON.
616 if (airplaneMode != AIRPLANE_OFF) {
617 airplaneMode = AIRPLANE_ON;
618 }
Chris Mantona09f3632016-02-09 14:48:42 -0800619 handleAirplaneModeChange(context, airplaneMode);
Amit Mahajanf5d92c82018-11-02 17:44:40 -0700620 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
621 // re-register as it may be a new IccCard
622 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
623 SubscriptionManager.INVALID_PHONE_INDEX);
624 if (SubscriptionManager.isValidPhoneId(phoneId)) {
625 PhoneUtils.unregisterIccStatus(mHandler, phoneId);
626 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED, phoneId);
627 }
628 if (mPUKEntryActivity != null) {
629 // if an attempt to un-PUK-lock the device was made, while we're
630 // receiving this state change notification, notify the handler.
631 // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has
632 // been attempted.
633 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
634 intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE)));
635 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700636 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
637 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800638 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
639 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700640 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
641 handleServiceStateChanged(intent);
642 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530643 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530644 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530645 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
646 if (phoneInEcm != null) {
647 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
648 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
649 // Start Emergency Callback Mode service
650 if (intent.getBooleanExtra("phoneinECMState", false)) {
651 context.startService(new Intent(context,
652 EmergencyCallbackModeService.class));
653 } else {
654 phoneInEcm = null;
655 }
656 } else {
657 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
658 // on a device that doesn't support ECM in the first place.
659 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
660 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
661 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700662 }
663 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530664 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700665 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700666 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
667 // Roaming status could be overridden by carrier config, so we need to update it.
668 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
669 updateDataRoamingStatus();
chen xubaf9fe52019-07-02 17:28:24 -0700670 updateLimitedSimFunctionForDualSim();
Jack Yu1a2fc352017-07-14 17:14:37 -0700671 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
672 // We also need to pay attention when default data subscription changes.
673 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
674 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
675 registerSettingsObserver();
676 Phone phone = getPhone(mDefaultDataSubId);
677 if (phone != null) {
678 updateDataRoamingStatus();
679 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700680 }
681 }
682 }
683
Brad Ebinger28626122017-08-10 14:13:35 -0700684 private class SipReceiver extends BroadcastReceiver {
685
686 @Override
687 public void onReceive(Context context, Intent intent) {
688 String action = intent.getAction();
689
690 SipAccountRegistry sipAccountRegistry = SipAccountRegistry.getInstance();
691 if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
692 SipUtil.startSipService();
693 } else if (action.equals(SipManager.ACTION_SIP_SERVICE_UP)
694 || action.equals(SipManager.ACTION_SIP_CALL_OPTION_CHANGED)) {
695 sipAccountRegistry.setup(context);
696 } else if (action.equals(SipManager.ACTION_SIP_REMOVE_PHONE)) {
697 if (DBG) {
698 Log.d(LOG_TAG, "SIP_REMOVE_PHONE "
699 + intent.getStringExtra(SipManager.EXTRA_LOCAL_URI));
700 }
701 sipAccountRegistry.removeSipProfile(intent.getStringExtra(
702 SipManager.EXTRA_LOCAL_URI));
703 } else {
704 if (DBG) Log.d(LOG_TAG, "onReceive, action not processed: " + action);
705 }
706 }
707 }
708
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700709 private void handleServiceStateChanged(Intent intent) {
710 /**
711 * This used to handle updating EriTextWidgetProvider this routine
712 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
713 * be removed. But leaving just in case it might be needed in the near
714 * future.
715 */
716
Jack Yu1a2fc352017-07-14 17:14:37 -0700717 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700718 // If service just returned, start sending out the queued messages
Santos Cordonc593d002015-06-03 15:41:15 -0700719 Bundle extras = intent.getExtras();
720 if (extras != null) {
721 ServiceState ss = ServiceState.newFromBundle(extras);
722 if (ss != null) {
723 int state = ss.getState();
Jayachandran C2ef9a482017-05-12 22:07:47 -0700724 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
725 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
726 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -0700727
728 if (VDBG) {
729 Log.v(LOG_TAG, "subId=" + subId + ",mDefaultDataSubId="
730 + mDefaultDataSubId + ",ss roaming=" + ss.getDataRoaming());
731 }
732 if (subId == mDefaultDataSubId) {
733 updateDataRoamingStatus();
734 }
Santos Cordonc593d002015-06-03 15:41:15 -0700735 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700736 }
737 }
738
Jack Yu1a2fc352017-07-14 17:14:37 -0700739 /**
Jordan Liuc353b162019-07-23 15:54:41 -0700740 * @return whether or not we should show a notification when connecting to data roaming if the
741 * user has data roaming enabled
742 */
743 private boolean shouldShowDataConnectedRoaming(int subId) {
744 PersistableBundle config = getCarrierConfigForSubId(subId);
745 return config.getBoolean(CarrierConfigManager
746 .KEY_SHOW_DATA_CONNECTED_ROAMING_NOTIFICATION_BOOL);
747 }
748
749 /**
Jack Yu1a2fc352017-07-14 17:14:37 -0700750 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
751 * to notify the user so they can enable it through settings. Vise versa if the condition
752 * changes, we need to dismiss the notification.
753 */
754 private void updateDataRoamingStatus() {
755 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
756 Phone phone = getPhone(mDefaultDataSubId);
757 if (phone == null) {
758 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
759 return;
760 }
761
762 DataConnectionReasons reasons = new DataConnectionReasons();
Jack Yu311536f2018-11-26 11:20:48 -0800763 boolean dataAllowed = phone.isDataAllowed(ApnSetting.TYPE_DEFAULT, reasons);
Jack Yu1a2fc352017-07-14 17:14:37 -0700764 mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons);
765 if (VDBG) Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons);
Jordan Liuc353b162019-07-23 15:54:41 -0700766 if (!dataAllowed && reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED)) {
767 // No need to show it again if we never cancelled it explicitly.
768 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_DISCONNECTED) return;
Jack Yu1a2fc352017-07-14 17:14:37 -0700769 // If the only reason of no data is data roaming disabled, then we notify the user
770 // so the user can turn on data roaming.
Jordan Liuc353b162019-07-23 15:54:41 -0700771 mPrevRoamingNotification = ROAMING_NOTIFICATION_DISCONNECTED;
Jack Yu1a2fc352017-07-14 17:14:37 -0700772 Log.d(LOG_TAG, "Show roaming disconnected notification");
Jordan Liuc353b162019-07-23 15:54:41 -0700773 mDataRoamingNotifLog.log("Show roaming off.");
Pengquan Meng8783d932017-10-16 14:57:40 -0700774 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_DISCONNECTED);
775 msg.arg1 = mDefaultDataSubId;
776 msg.sendToTarget();
Jordan Liuc353b162019-07-23 15:54:41 -0700777 } else if (dataAllowed && dataIsNowRoaming(mDefaultDataSubId)
778 && shouldShowDataConnectedRoaming(mDefaultDataSubId)) {
779 // No need to show it again if we never cancelled it explicitly, or carrier config
780 // indicates this is not needed.
781 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_CONNECTED) return;
782 mPrevRoamingNotification = ROAMING_NOTIFICATION_CONNECTED;
783 Log.d(LOG_TAG, "Show roaming connected notification");
784 mDataRoamingNotifLog.log("Show roaming on.");
785 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_CONNECTED);
786 msg.arg1 = mDefaultDataSubId;
787 msg.sendToTarget();
788 } else if (mPrevRoamingNotification != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
789 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
790 // is not the only data disable reason. In this case we dismiss the notification we
791 // showed earlier.
792 mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
793 Log.d(LOG_TAG, "Dismiss roaming notification");
Jack Yu1a2fc352017-07-14 17:14:37 -0700794 mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed + ", reasons=" + reasons);
795 mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
796 }
797 }
798
Jordan Liuc353b162019-07-23 15:54:41 -0700799 /**
800 *
801 * @param subId to check roaming on
802 * @return whether we have transitioned to dataRoaming
803 */
804 private boolean dataIsNowRoaming(int subId) {
805 return getPhone(subId).getServiceState().getDataRoaming();
806 }
807
chen xubaf9fe52019-07-02 17:28:24 -0700808 private void updateLimitedSimFunctionForDualSim() {
809 if (DBG) Log.d(LOG_TAG, "updateLimitedSimFunctionForDualSim");
810 // check conditions to display limited SIM function notification under dual SIM
811 SubscriptionManager subMgr = (SubscriptionManager) getSystemService(
812 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
813 List<SubscriptionInfo> subList = subMgr.getActiveSubscriptionInfoList(false);
814 if (subList != null && subList.size() > 1) {
815 CarrierConfigManager configMgr = (CarrierConfigManager)
816 getSystemService(Context.CARRIER_CONFIG_SERVICE);
817 for (SubscriptionInfo info : subList) {
818 PersistableBundle b = configMgr.getConfigForSubId(info.getSubscriptionId());
819 if (b != null) {
820 if (b.getBoolean(CarrierConfigManager
821 .KEY_LIMITED_SIM_FUNCTION_NOTIFICATION_FOR_DSDS_BOOL)) {
822 notificationMgr.showLimitedSimFunctionWarningNotification(
823 info.getSubscriptionId(),
824 info.getDisplayName().toString());
825 } else {
826 notificationMgr.dismissLimitedSimFunctionWarningNotification(
827 info.getSubscriptionId());
828 }
829 }
830 }
831 } else {
832 // cancel notifications for all subs
833 notificationMgr.dismissLimitedSimFunctionWarningNotification(
834 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
835 }
836 notificationMgr.dismissLimitedSimFunctionWarningNotificationForInactiveSubs();
837
838 }
839
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530840 public Phone getPhoneInEcm() {
841 return phoneInEcm;
842 }
843
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700844 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800845 * Triggers a refresh of the message waiting (voicemail) indicator.
846 *
847 * @param subId the subscription id we should refresh the notification for.
848 */
849 public void refreshMwiIndicator(int subId) {
850 notificationMgr.refreshMwi(subId);
851 }
852
853 /**
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700854 * Called when the network selection on the subscription {@code subId} is changed by the user.
855 *
856 * @param subId the subscription id.
857 */
858 public void onNetworkSelectionChanged(int subId) {
859 Phone phone = getPhone(subId);
860 if (phone != null) {
861 notificationMgr.updateNetworkSelection(phone.getServiceState().getState(), subId);
862 } else {
863 Log.w(LOG_TAG, "onNetworkSelectionChanged on null phone, subId: " + subId);
864 }
865 }
866
867 /**
Jack Yu1a2fc352017-07-14 17:14:37 -0700868 * Dump the state of the object, add calls to other objects as desired.
869 *
870 * @param fd File descriptor
871 * @param printWriter Print writer
872 * @param args Arguments
873 */
874 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
875 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
876 pw.println("------- PhoneGlobals -------");
877 pw.increaseIndent();
Jordan Liuc353b162019-07-23 15:54:41 -0700878 pw.println("mPrevRoamingNotification=" + mPrevRoamingNotification);
Jack Yu1a2fc352017-07-14 17:14:37 -0700879 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
880 pw.println("mDataRoamingNotifLog:");
Keun young Parkdebb8532019-05-30 16:35:27 -0700881 pw.println("isSmsCapable=" + TelephonyManager.from(this).isSmsCapable());
Jack Yu1a2fc352017-07-14 17:14:37 -0700882 pw.increaseIndent();
883 mDataRoamingNotifLog.dump(fd, pw, args);
884 pw.decreaseIndent();
885 pw.decreaseIndent();
886 pw.println("------- End PhoneGlobals -------");
887 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700888}