blob: 9953a432610ad06093a35235e2e47cf23a20436d [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;
42import android.os.UpdateLock;
Brad Ebinger3fa43462016-04-12 16:06:48 -070043import android.os.UserManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.preference.PreferenceManager;
Sanket Padawe4c699232016-02-09 11:07:22 -080045import android.provider.Settings;
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;
70import com.android.internal.util.IndentingPrintWriter;
Andrew Leefb7f92e2015-02-26 16:23:32 -080071import com.android.phone.settings.SettingsConstants;
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -070072import com.android.phone.vvm.CarrierVvmPackageInstalledReceiver;
Brad Ebinger28626122017-08-10 14:13:35 -070073import com.android.services.telephony.sip.SipAccountRegistry;
Brad Ebinger3fa43462016-04-12 16:06:48 -070074import com.android.services.telephony.sip.SipUtil;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075
Jack Yu1a2fc352017-07-14 17:14:37 -070076import java.io.FileDescriptor;
77import java.io.PrintWriter;
Jordan Liuc353b162019-07-23 15:54:41 -070078import java.lang.annotation.Retention;
79import java.lang.annotation.RetentionPolicy;
chen xubaf9fe52019-07-02 17:28:24 -070080import java.util.List;
Jack Yu1a2fc352017-07-14 17:14:37 -070081
Santos Cordon7d4ddf62013-07-10 11:58:08 -070082/**
83 * Global state for the telephony subsystem when running in the primary
84 * phone process.
85 */
Sailesh Nepalbf900542014-07-15 16:18:32 -070086public class PhoneGlobals extends ContextWrapper {
Jack Yu1a2fc352017-07-14 17:14:37 -070087 public static final String LOG_TAG = "PhoneGlobals";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088
89 /**
90 * Phone app-wide debug level:
91 * 0 - no debug logging
92 * 1 - normal debug logging if ro.debuggable is set (which is true in
93 * "eng" and "userdebug" builds but not "user" builds)
94 * 2 - ultra-verbose debug logging
95 *
96 * Most individual classes in the phone app have a local DBG constant,
97 * typically set to
98 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
99 * or else
100 * (PhoneApp.DBG_LEVEL >= 2)
101 * depending on the desired verbosity.
102 *
103 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
104 */
Andrew Lee88b51e22014-10-29 15:48:51 -0700105 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106
107 private static final boolean DBG =
108 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
109 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
110
111 // Message codes; see mHandler below.
112 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700113 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
Jordan Liuc353b162019-07-23 15:54:41 -0700115 private static final int EVENT_DATA_ROAMING_CONNECTED = 11;
116 private static final int EVENT_DATA_ROAMING_OK = 12;
117 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 13;
118 private static final int EVENT_RESTART_SIP = 14;
119 private static final int EVENT_DATA_ROAMING_SETTINGS_CHANGED = 15;
120 private static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED = 16;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700121
122 // The MMI codes are also used by the InCallScreen.
123 public static final int MMI_INITIATE = 51;
124 public static final int MMI_COMPLETE = 52;
125 public static final int MMI_CANCEL = 53;
126 // Don't use message codes larger than 99 here; those are reserved for
127 // the individual Activities of the Phone UI.
128
Santos Cordone18902f2016-03-22 17:16:04 -0700129 public static final int AIRPLANE_ON = 1;
130 public static final int AIRPLANE_OFF = 0;
131
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132 /**
133 * Allowable values for the wake lock code.
134 * SLEEP means the device can be put to sleep.
135 * PARTIAL means wake the processor, but we display can be kept off.
136 * FULL means wake both the processor and the display.
137 */
138 public enum WakeState {
139 SLEEP,
140 PARTIAL,
141 FULL
142 }
143
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700144 private static PhoneGlobals sMe;
145
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700146 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700147 CallNotifier notifier;
148 CallerInfoCache callerInfoCache;
Santos Cordon63a84242013-07-23 13:32:52 -0700149 NotificationMgr notificationMgr;
Andrew Lee9431b832015-03-09 18:46:45 -0700150 public PhoneInterfaceManager phoneMgr;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800151 CarrierConfigLoader configLoader;
Santos Cordon63a84242013-07-23 13:32:52 -0700152
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530153 private Phone phoneInEcm;
Santos Cordon63a84242013-07-23 13:32:52 -0700154
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155 static boolean sVoiceCapable = true;
156
Santos Cordonc593d002015-06-03 15:41:15 -0700157 // TODO: Remove, no longer used.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700158 CdmaPhoneCallState cdmaPhoneCallState;
159
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700160 // The currently-active PUK entry activity and progress dialog.
161 // Normally, these are the Emergency Dialer and the subsequent
162 // progress dialog. null if there is are no such objects in
163 // the foreground.
164 private Activity mPUKEntryActivity;
165 private ProgressDialog mPUKEntryProgressDialog;
166
Jordan Liuc353b162019-07-23 15:54:41 -0700167 /** @hide */
168 @Retention(RetentionPolicy.SOURCE)
169 @IntDef(prefix = {"ROAMING_NOTIFICATION_"},
170 value = {
171 ROAMING_NOTIFICATION_NO_NOTIFICATION,
172 ROAMING_NOTIFICATION_CONNECTED,
173 ROAMING_NOTIFICATION_DISCONNECTED})
174 public @interface RoamingNotification {}
175
176 private static final int ROAMING_NOTIFICATION_NO_NOTIFICATION = 0;
177 private static final int ROAMING_NOTIFICATION_CONNECTED = 1;
178 private static final int ROAMING_NOTIFICATION_DISCONNECTED = 2;
179
180 @RoamingNotification
181 private int mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
Jack Yu953f9352017-05-18 14:41:06 -0700182
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700183 private WakeState mWakeState = WakeState.SLEEP;
184
185 private PowerManager mPowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186 private PowerManager.WakeLock mWakeLock;
187 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700188 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700189
190 private UpdateLock mUpdateLock;
191
Jack Yu1a2fc352017-07-14 17:14:37 -0700192 private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
193 private final LocalLog mDataRoamingNotifLog = new LocalLog(50);
194
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195 // Broadcast receiver for various intent broadcasts (see onCreate())
196 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
Brad Ebinger533c6c12017-08-02 11:38:48 -0700197 // Broadcast receiver for SIP based intents (see onCreate())
Brad Ebinger28626122017-08-10 14:13:35 -0700198 private final SipReceiver mSipReceiver = new SipReceiver();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700199
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700200 private final CarrierVvmPackageInstalledReceiver mCarrierVvmPackageInstalledReceiver =
201 new CarrierVvmPackageInstalledReceiver();
202
Jack Yu1a2fc352017-07-14 17:14:37 -0700203 private final SettingsObserver mSettingsObserver;
204
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700205 Handler mHandler = new Handler() {
206 @Override
207 public void handleMessage(Message msg) {
208 PhoneConstants.State phoneState;
Jack Yu1a2fc352017-07-14 17:14:37 -0700209 if (VDBG) Log.v(LOG_TAG, "event=" + msg.what);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700210 switch (msg.what) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700211 // TODO: This event should be handled by the lock screen, just
212 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
213 case EVENT_SIM_NETWORK_LOCKED:
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700214 if (getCarrierConfig().getBoolean(
215 CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700216 // Some products don't have the concept of a "SIM network lock"
217 Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; "
Eric Erfanian945409f2018-02-21 19:26:15 +0000218 + "not showing 'SIM network unlock' PIN entry screen");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700219 } else {
220 // Normal case: show the "SIM network unlock" PIN entry screen.
221 // The user won't be able to do anything else until
222 // they enter a valid SIM network PIN.
223 Log.i(LOG_TAG, "show sim depersonal panel");
Biljana Maneva96291112018-01-30 13:12:59 +0800224 Phone phone = (Phone) ((AsyncResult) msg.obj).userObj;
225 IccNetworkDepersonalizationPanel.showDialog(phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700226 }
227 break;
228
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700229 case EVENT_DATA_ROAMING_DISCONNECTED:
Jordan Liuc353b162019-07-23 15:54:41 -0700230 notificationMgr.showDataRoamingNotification(msg.arg1, false);
231 break;
232
233 case EVENT_DATA_ROAMING_CONNECTED:
234 notificationMgr.showDataRoamingNotification(msg.arg1, true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700235 break;
236
237 case EVENT_DATA_ROAMING_OK:
Jordan Liuc353b162019-07-23 15:54:41 -0700238 notificationMgr.hideDataRoamingNotification();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700239 break;
240
241 case MMI_COMPLETE:
242 onMMIComplete((AsyncResult) msg.obj);
243 break;
244
245 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800246 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700247 break;
248
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249 case EVENT_SIM_STATE_CHANGED:
250 // Marks the event where the SIM goes into ready state.
251 // Right now, this is only used for the PUK-unlocking
252 // process.
Amit Mahajanc08787c2019-03-26 16:11:55 -0700253 if (msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_READY)
254 || msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_LOADED)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700255 // when the right event is triggered and there
256 // are UI objects in the foreground, we close
257 // them to display the lock panel.
258 if (mPUKEntryActivity != null) {
259 mPUKEntryActivity.finish();
260 mPUKEntryActivity = null;
261 }
262 if (mPUKEntryProgressDialog != null) {
263 mPUKEntryProgressDialog.dismiss();
264 mPUKEntryProgressDialog = null;
265 }
266 }
267 break;
268
269 case EVENT_UNSOL_CDMA_INFO_RECORD:
270 //TODO: handle message here;
271 break;
Brad Ebinger3fa43462016-04-12 16:06:48 -0700272 case EVENT_RESTART_SIP:
273 // This should only run if the Phone process crashed and was restarted. We do
274 // not want this running if the device is still in the FBE encrypted state.
Brad Ebinger28626122017-08-10 14:13:35 -0700275 // This is the same procedure that is triggered in the SipIncomingCallReceiver
Brad Ebinger3fa43462016-04-12 16:06:48 -0700276 // upon BOOT_COMPLETED.
277 UserManager userManager = UserManager.get(sMe);
278 if (userManager != null && userManager.isUserUnlocked()) {
279 SipUtil.startSipService();
280 }
281 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700282 case EVENT_DATA_ROAMING_SETTINGS_CHANGED:
283 case EVENT_MOBILE_DATA_SETTINGS_CHANGED:
284 updateDataRoamingStatus();
285 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700286 }
287 }
288 };
289
290 public PhoneGlobals(Context context) {
291 super(context);
292 sMe = this;
Jack Yu1a2fc352017-07-14 17:14:37 -0700293 mSettingsObserver = new SettingsObserver(context, mHandler);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700294 }
295
296 public void onCreate() {
297 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
298
299 ContentResolver resolver = getContentResolver();
300
301 // Cache the "voice capable" flag.
302 // This flag currently comes from a resource (which is
303 // overrideable on a per-product basis):
304 sVoiceCapable =
305 getResources().getBoolean(com.android.internal.R.bool.config_voice_capable);
306 // ...but this might eventually become a PackageManager "system
307 // feature" instead, in which case we'd do something like:
308 // sVoiceCapable =
309 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
310
Stuart Scottdcf40a92014-12-09 10:45:01 -0800311 if (mCM == null) {
Nathan Haroldf9df6ea2019-03-08 11:54:22 -0800312 // Initialize AnomalyReporter early so that it can be used
313 AnomalyReporter.initialize(this);
Nathan Harold0db5c5e2019-01-22 20:18:56 -0800314
Youming Ye47a6adc2018-11-19 15:33:36 -0800315 // Inject telephony component factory if configured using other jars.
316 XmlResourceParser parser = getResources().getXml(R.xml.telephony_injection);
317 TelephonyComponentFactory.getInstance().injectTheComponentFactory(parser);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700318 // Initialize the telephony framework
319 PhoneFactory.makeDefaultPhones(this);
320
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700321 // Start TelephonyDebugService After the default phone is created.
322 Intent intent = new Intent(this, TelephonyDebugService.class);
323 startService(intent);
324
325 mCM = CallManager.getInstance();
Stuart Scottdcf40a92014-12-09 10:45:01 -0800326 for (Phone phone : PhoneFactory.getPhones()) {
327 mCM.registerPhone(phone);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800328 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700329
330 // Create the NotificationMgr singleton, which is used to display
331 // status bar icons and control other status bar behavior.
332 notificationMgr = NotificationMgr.init(this);
333
Brad Ebinger3fa43462016-04-12 16:06:48 -0700334 // If PhoneGlobals has crashed and is being restarted, then restart.
335 mHandler.sendEmptyMessage(EVENT_RESTART_SIP);
336
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700337 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
338 cdmaPhoneCallState = new CdmaPhoneCallState();
339 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700340
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700341 // before registering for phone state changes
342 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
343 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
344 // lock used to keep the processor awake, when we don't care for the display.
345 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
346 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700347
348 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
349
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350 // Get UpdateLock to suppress system-update related events (e.g. dialog show-up)
351 // during phone calls.
352 mUpdateLock = new UpdateLock("phone");
353
354 if (DBG) Log.d(LOG_TAG, "onCreate: mUpdateLock: " + mUpdateLock);
355
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356 // Create the CallerInfoCache singleton, which remembers custom ring tone and
357 // send-to-voicemail settings.
358 //
359 // The asynchronous caching will start just after this call.
360 callerInfoCache = CallerInfoCache.init(this);
361
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800362 phoneMgr = PhoneInterfaceManager.init(this);
Santos Cordon406c0342013-08-28 00:07:47 -0700363
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800364 configLoader = CarrierConfigLoader.init(this);
365
Jack Yu1a2fc352017-07-14 17:14:37 -0700366 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367 // asynchronous events from the telephony layer (like
368 // launching the incoming-call UI when an incoming call comes
369 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800370 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371
Stuart Scottdcf40a92014-12-09 10:45:01 -0800372 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373
374 // register for MMI/USSD
375 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
376
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700377 // Register for misc other intent broadcasts.
378 IntentFilter intentFilter =
379 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
381 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
382 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
383 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700384 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
385 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700386 registerReceiver(mReceiver, intentFilter);
387
Brad Ebinger533c6c12017-08-02 11:38:48 -0700388 IntentFilter sipIntentFilter = new IntentFilter(Intent.ACTION_BOOT_COMPLETED);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700389 sipIntentFilter.addAction(SipManager.ACTION_SIP_SERVICE_UP);
390 sipIntentFilter.addAction(SipManager.ACTION_SIP_CALL_OPTION_CHANGED);
391 sipIntentFilter.addAction(SipManager.ACTION_SIP_REMOVE_PHONE);
Brad Ebinger28626122017-08-10 14:13:35 -0700392 registerReceiver(mSipReceiver, sipIntentFilter);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700393
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700394 mCarrierVvmPackageInstalledReceiver.register(this);
395
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700396 //set the default values for the preferences in the phone.
pkanward702e542017-02-08 15:44:54 -0800397 PreferenceManager.setDefaultValues(this, R.xml.network_setting_fragment, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398
399 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700400 }
401
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700402 // XXX pre-load the SimProvider so that it's ready
403 resolver.getType(Uri.parse("content://icc/adn"));
404
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700405 // TODO: Register for Cdma Information Records
406 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
407
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700408 // Read HAC settings and configure audio hardware
409 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800410 int hac = android.provider.Settings.System.getInt(
411 getContentResolver(),
412 android.provider.Settings.System.HEARING_AID,
413 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700414 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Andrew Leefb7f92e2015-02-26 16:23:32 -0800415 audioManager.setParameter(SettingsConstants.HAC_KEY,
416 hac == SettingsConstants.HAC_ENABLED
417 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700418 }
Santos Cordonff506f52013-11-21 19:13:19 -0800419 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700420
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700421 /**
422 * Returns the singleton instance of the PhoneApp.
423 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800424 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700425 if (sMe == null) {
426 throw new IllegalStateException("No PhoneGlobals here!");
427 }
428 return sMe;
429 }
430
431 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800432 * Returns the default phone.
433 *
Andrew Lee385019f2014-11-24 14:19:50 -0800434 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700435 */
Andrew Lee83383e42014-10-31 12:42:28 -0700436 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800437 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700438 }
439
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800440 public static Phone getPhone(int subId) {
441 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800442 }
443
Santos Cordonde10b752013-09-19 04:11:33 -0700444 /* package */ CallManager getCallManager() {
445 return mCM;
446 }
447
Chris Manton4e9fa912015-06-19 11:26:57 -0700448 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800449 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700450 }
451
Chris Manton4e9fa912015-06-19 11:26:57 -0700452 public PersistableBundle getCarrierConfigForSubId(int subId) {
Malcolm Chen6d3d6b32018-03-01 13:58:03 -0800453 return configLoader.getConfigForSubId(subId, getOpPackageName());
Junda Liu605148f2015-04-28 15:23:40 -0700454 }
455
Jack Yu1a2fc352017-07-14 17:14:37 -0700456 private void registerSettingsObserver() {
457 mSettingsObserver.unobserve();
458 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
459 String mobileDataSetting = Settings.Global.MOBILE_DATA;
460 if (TelephonyManager.getDefault().getSimCount() > 1) {
461 int subId = mDefaultDataSubId;
462 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
463 dataRoamingSetting += subId;
464 mobileDataSetting += subId;
465 }
466 }
467
468 // Listen for user data roaming setting changed event
469 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
470 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
471
472 // Listen for mobile data setting changed event
473 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
474 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
475 }
476
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700477 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700478 * Sets the activity responsible for un-PUK-blocking the device
479 * so that we may close it when we receive a positive result.
480 * mPUKEntryActivity is also used to indicate to the device that
481 * we are trying to un-PUK-lock the phone. In other words, iff
482 * it is NOT null, then we are trying to unlock and waiting for
483 * the SIM to move to READY state.
484 *
485 * @param activity is the activity to close when PUK has
486 * finished unlocking. Can be set to null to indicate the unlock
487 * or SIM READYing process is over.
488 */
489 void setPukEntryActivity(Activity activity) {
490 mPUKEntryActivity = activity;
491 }
492
493 Activity getPUKEntryActivity() {
494 return mPUKEntryActivity;
495 }
496
497 /**
498 * Sets the dialog responsible for notifying the user of un-PUK-
499 * blocking - SIM READYing progress, so that we may dismiss it
500 * when we receive a positive result.
501 *
502 * @param dialog indicates the progress dialog informing the user
503 * of the state of the device. Dismissed upon completion of
504 * READYing process
505 */
506 void setPukEntryProgressDialog(ProgressDialog dialog) {
507 mPUKEntryProgressDialog = dialog;
508 }
509
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700510 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700511 * If we are not currently keeping the screen on, then poke the power
512 * manager to wake up the screen for the user activity timeout duration.
513 */
514 /* package */ void wakeUpScreen() {
515 synchronized (this) {
516 if (mWakeState == WakeState.SLEEP) {
517 if (DBG) Log.d(LOG_TAG, "pulse screen lock");
Dianne Hackborn148769b2015-07-13 17:55:47 -0700518 mPowerManager.wakeUp(SystemClock.uptimeMillis(), "android.phone:WAKE");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700519 }
520 }
521 }
522
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700523 KeyguardManager getKeyguardManager() {
524 return mKeyguardManager;
525 }
526
527 private void onMMIComplete(AsyncResult r) {
528 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
529 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800530 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700531 }
532
fionaxu80126972017-02-01 17:01:26 -0800533 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700534 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700535 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700536 }
537
Chris Mantona09f3632016-02-09 14:48:42 -0800538 private void handleAirplaneModeChange(Context context, int newMode) {
539 int cellState = Settings.Global.getInt(context.getContentResolver(),
540 Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
541 boolean isAirplaneNewlyOn = (newMode == 1);
542 switch (cellState) {
543 case PhoneConstants.CELL_OFF_FLAG:
544 // Airplane mode does not affect the cell radio if user
545 // has turned it off.
546 break;
547 case PhoneConstants.CELL_ON_FLAG:
548 maybeTurnCellOff(context, isAirplaneNewlyOn);
549 break;
550 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
551 maybeTurnCellOn(context, isAirplaneNewlyOn);
552 break;
553 }
554 }
555
556 /*
557 * Returns true if the radio must be turned off when entering airplane mode.
558 */
559 private boolean isCellOffInAirplaneMode(Context context) {
560 String airplaneModeRadios = Settings.Global.getString(context.getContentResolver(),
561 Settings.Global.AIRPLANE_MODE_RADIOS);
562 return airplaneModeRadios == null
563 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
564 }
565
566 private void setRadioPowerOff(Context context) {
567 Log.i(LOG_TAG, "Turning radio off - airplane");
568 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
Eric Erfanian945409f2018-02-21 19:26:15 +0000569 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Sooraj Sasindran798bafa2017-04-03 22:49:00 -0700570 SystemProperties.set("persist.radio.airplane_mode_on", "1");
Chris Mantona09f3632016-02-09 14:48:42 -0800571 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
572 PhoneUtils.setRadioPower(false);
573 }
574
575 private void setRadioPowerOn(Context context) {
576 Log.i(LOG_TAG, "Turning radio on - airplane");
577 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
578 PhoneConstants.CELL_ON_FLAG);
579 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT,
580 1);
Sooraj Sasindran798bafa2017-04-03 22:49:00 -0700581 SystemProperties.set("persist.radio.airplane_mode_on", "0");
Chris Mantona09f3632016-02-09 14:48:42 -0800582 PhoneUtils.setRadioPower(true);
583 }
584
585 private void maybeTurnCellOff(Context context, boolean isAirplaneNewlyOn) {
586 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700587 // If we are trying to turn off the radio, make sure there are no active
588 // emergency calls. If there are, switch airplane mode back to off.
Tyler Gunn900d8fd2018-09-21 09:22:12 -0700589 TelecomManager tm = (TelecomManager) context.getSystemService(TELECOM_SERVICE);
590
591 if (tm != null && tm.isInEmergencyCall()) {
Santos Cordone18902f2016-03-22 17:16:04 -0700592 // Switch airplane mode back to off.
593 ConnectivityManager.from(this).setAirplaneMode(false);
594 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
595 .show();
596 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Chris Mantona09f3632016-02-09 14:48:42 -0800597 } else if (isCellOffInAirplaneMode(context)) {
598 setRadioPowerOff(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700599 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800600 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700601 }
Chris Mantona09f3632016-02-09 14:48:42 -0800602 }
603 }
604
605 private void maybeTurnCellOn(Context context, boolean isAirplaneNewlyOn) {
606 if (!isAirplaneNewlyOn) {
607 setRadioPowerOn(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700608 }
609 }
610
Santos Cordon593ab382013-08-06 21:58:23 -0700611 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700612 * Receiver for misc intent broadcasts the Phone app cares about.
613 */
614 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
615 @Override
616 public void onReceive(Context context, Intent intent) {
617 String action = intent.getAction();
618 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Santos Cordone18902f2016-03-22 17:16:04 -0700619 int airplaneMode = Settings.Global.getInt(getContentResolver(),
620 Settings.Global.AIRPLANE_MODE_ON, AIRPLANE_OFF);
621 // Treat any non-OFF values as ON.
622 if (airplaneMode != AIRPLANE_OFF) {
623 airplaneMode = AIRPLANE_ON;
624 }
Chris Mantona09f3632016-02-09 14:48:42 -0800625 handleAirplaneModeChange(context, airplaneMode);
Amit Mahajanf5d92c82018-11-02 17:44:40 -0700626 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
627 // re-register as it may be a new IccCard
628 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
629 SubscriptionManager.INVALID_PHONE_INDEX);
630 if (SubscriptionManager.isValidPhoneId(phoneId)) {
631 PhoneUtils.unregisterIccStatus(mHandler, phoneId);
632 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED, phoneId);
633 }
634 if (mPUKEntryActivity != null) {
635 // if an attempt to un-PUK-lock the device was made, while we're
636 // receiving this state change notification, notify the handler.
637 // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has
638 // been attempted.
639 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
640 intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE)));
641 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700642 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
643 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800644 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
645 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700646 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
647 handleServiceStateChanged(intent);
648 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530649 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530650 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530651 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
652 if (phoneInEcm != null) {
653 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
654 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
655 // Start Emergency Callback Mode service
656 if (intent.getBooleanExtra("phoneinECMState", false)) {
657 context.startService(new Intent(context,
658 EmergencyCallbackModeService.class));
659 } else {
660 phoneInEcm = null;
661 }
662 } else {
663 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
664 // on a device that doesn't support ECM in the first place.
665 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
666 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
667 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700668 }
669 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530670 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700671 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700672 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
673 // Roaming status could be overridden by carrier config, so we need to update it.
674 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
675 updateDataRoamingStatus();
chen xubaf9fe52019-07-02 17:28:24 -0700676 updateLimitedSimFunctionForDualSim();
Jack Yu1a2fc352017-07-14 17:14:37 -0700677 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
678 // We also need to pay attention when default data subscription changes.
679 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
680 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
681 registerSettingsObserver();
682 Phone phone = getPhone(mDefaultDataSubId);
683 if (phone != null) {
684 updateDataRoamingStatus();
685 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700686 }
687 }
688 }
689
Brad Ebinger28626122017-08-10 14:13:35 -0700690 private class SipReceiver extends BroadcastReceiver {
691
692 @Override
693 public void onReceive(Context context, Intent intent) {
694 String action = intent.getAction();
695
696 SipAccountRegistry sipAccountRegistry = SipAccountRegistry.getInstance();
697 if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
698 SipUtil.startSipService();
699 } else if (action.equals(SipManager.ACTION_SIP_SERVICE_UP)
700 || action.equals(SipManager.ACTION_SIP_CALL_OPTION_CHANGED)) {
701 sipAccountRegistry.setup(context);
702 } else if (action.equals(SipManager.ACTION_SIP_REMOVE_PHONE)) {
703 if (DBG) {
704 Log.d(LOG_TAG, "SIP_REMOVE_PHONE "
705 + intent.getStringExtra(SipManager.EXTRA_LOCAL_URI));
706 }
707 sipAccountRegistry.removeSipProfile(intent.getStringExtra(
708 SipManager.EXTRA_LOCAL_URI));
709 } else {
710 if (DBG) Log.d(LOG_TAG, "onReceive, action not processed: " + action);
711 }
712 }
713 }
714
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700715 private void handleServiceStateChanged(Intent intent) {
716 /**
717 * This used to handle updating EriTextWidgetProvider this routine
718 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
719 * be removed. But leaving just in case it might be needed in the near
720 * future.
721 */
722
Jack Yu1a2fc352017-07-14 17:14:37 -0700723 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700724 // If service just returned, start sending out the queued messages
Santos Cordonc593d002015-06-03 15:41:15 -0700725 Bundle extras = intent.getExtras();
726 if (extras != null) {
727 ServiceState ss = ServiceState.newFromBundle(extras);
728 if (ss != null) {
729 int state = ss.getState();
Jayachandran C2ef9a482017-05-12 22:07:47 -0700730 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
731 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
732 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -0700733
734 if (VDBG) {
735 Log.v(LOG_TAG, "subId=" + subId + ",mDefaultDataSubId="
736 + mDefaultDataSubId + ",ss roaming=" + ss.getDataRoaming());
737 }
738 if (subId == mDefaultDataSubId) {
739 updateDataRoamingStatus();
740 }
Santos Cordonc593d002015-06-03 15:41:15 -0700741 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700742 }
743 }
744
Jack Yu1a2fc352017-07-14 17:14:37 -0700745 /**
Jordan Liuc353b162019-07-23 15:54:41 -0700746 * @return whether or not we should show a notification when connecting to data roaming if the
747 * user has data roaming enabled
748 */
749 private boolean shouldShowDataConnectedRoaming(int subId) {
750 PersistableBundle config = getCarrierConfigForSubId(subId);
751 return config.getBoolean(CarrierConfigManager
752 .KEY_SHOW_DATA_CONNECTED_ROAMING_NOTIFICATION_BOOL);
753 }
754
755 /**
Jack Yu1a2fc352017-07-14 17:14:37 -0700756 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
757 * to notify the user so they can enable it through settings. Vise versa if the condition
758 * changes, we need to dismiss the notification.
759 */
760 private void updateDataRoamingStatus() {
761 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
762 Phone phone = getPhone(mDefaultDataSubId);
763 if (phone == null) {
764 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
765 return;
766 }
767
768 DataConnectionReasons reasons = new DataConnectionReasons();
Jack Yu311536f2018-11-26 11:20:48 -0800769 boolean dataAllowed = phone.isDataAllowed(ApnSetting.TYPE_DEFAULT, reasons);
Jack Yu1a2fc352017-07-14 17:14:37 -0700770 mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons);
771 if (VDBG) Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons);
Jordan Liuc353b162019-07-23 15:54:41 -0700772 if (!dataAllowed && reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED)) {
773 // No need to show it again if we never cancelled it explicitly.
774 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_DISCONNECTED) return;
Jack Yu1a2fc352017-07-14 17:14:37 -0700775 // If the only reason of no data is data roaming disabled, then we notify the user
776 // so the user can turn on data roaming.
Jordan Liuc353b162019-07-23 15:54:41 -0700777 mPrevRoamingNotification = ROAMING_NOTIFICATION_DISCONNECTED;
Jack Yu1a2fc352017-07-14 17:14:37 -0700778 Log.d(LOG_TAG, "Show roaming disconnected notification");
Jordan Liuc353b162019-07-23 15:54:41 -0700779 mDataRoamingNotifLog.log("Show roaming off.");
Pengquan Meng8783d932017-10-16 14:57:40 -0700780 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_DISCONNECTED);
781 msg.arg1 = mDefaultDataSubId;
782 msg.sendToTarget();
Jordan Liuc353b162019-07-23 15:54:41 -0700783 } else if (dataAllowed && dataIsNowRoaming(mDefaultDataSubId)
784 && shouldShowDataConnectedRoaming(mDefaultDataSubId)) {
785 // No need to show it again if we never cancelled it explicitly, or carrier config
786 // indicates this is not needed.
787 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_CONNECTED) return;
788 mPrevRoamingNotification = ROAMING_NOTIFICATION_CONNECTED;
789 Log.d(LOG_TAG, "Show roaming connected notification");
790 mDataRoamingNotifLog.log("Show roaming on.");
791 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_CONNECTED);
792 msg.arg1 = mDefaultDataSubId;
793 msg.sendToTarget();
794 } else if (mPrevRoamingNotification != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
795 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
796 // is not the only data disable reason. In this case we dismiss the notification we
797 // showed earlier.
798 mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
799 Log.d(LOG_TAG, "Dismiss roaming notification");
Jack Yu1a2fc352017-07-14 17:14:37 -0700800 mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed + ", reasons=" + reasons);
801 mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
802 }
803 }
804
Jordan Liuc353b162019-07-23 15:54:41 -0700805 /**
806 *
807 * @param subId to check roaming on
808 * @return whether we have transitioned to dataRoaming
809 */
810 private boolean dataIsNowRoaming(int subId) {
811 return getPhone(subId).getServiceState().getDataRoaming();
812 }
813
chen xubaf9fe52019-07-02 17:28:24 -0700814 private void updateLimitedSimFunctionForDualSim() {
815 if (DBG) Log.d(LOG_TAG, "updateLimitedSimFunctionForDualSim");
816 // check conditions to display limited SIM function notification under dual SIM
817 SubscriptionManager subMgr = (SubscriptionManager) getSystemService(
818 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
819 List<SubscriptionInfo> subList = subMgr.getActiveSubscriptionInfoList(false);
820 if (subList != null && subList.size() > 1) {
821 CarrierConfigManager configMgr = (CarrierConfigManager)
822 getSystemService(Context.CARRIER_CONFIG_SERVICE);
823 for (SubscriptionInfo info : subList) {
824 PersistableBundle b = configMgr.getConfigForSubId(info.getSubscriptionId());
825 if (b != null) {
826 if (b.getBoolean(CarrierConfigManager
827 .KEY_LIMITED_SIM_FUNCTION_NOTIFICATION_FOR_DSDS_BOOL)) {
828 notificationMgr.showLimitedSimFunctionWarningNotification(
829 info.getSubscriptionId(),
830 info.getDisplayName().toString());
831 } else {
832 notificationMgr.dismissLimitedSimFunctionWarningNotification(
833 info.getSubscriptionId());
834 }
835 }
836 }
837 } else {
838 // cancel notifications for all subs
839 notificationMgr.dismissLimitedSimFunctionWarningNotification(
840 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
841 }
842 notificationMgr.dismissLimitedSimFunctionWarningNotificationForInactiveSubs();
843
844 }
845
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530846 public Phone getPhoneInEcm() {
847 return phoneInEcm;
848 }
849
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700850 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800851 * Triggers a refresh of the message waiting (voicemail) indicator.
852 *
853 * @param subId the subscription id we should refresh the notification for.
854 */
855 public void refreshMwiIndicator(int subId) {
856 notificationMgr.refreshMwi(subId);
857 }
858
859 /**
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700860 * Called when the network selection on the subscription {@code subId} is changed by the user.
861 *
862 * @param subId the subscription id.
863 */
864 public void onNetworkSelectionChanged(int subId) {
865 Phone phone = getPhone(subId);
866 if (phone != null) {
867 notificationMgr.updateNetworkSelection(phone.getServiceState().getState(), subId);
868 } else {
869 Log.w(LOG_TAG, "onNetworkSelectionChanged on null phone, subId: " + subId);
870 }
871 }
872
873 /**
Jack Yu1a2fc352017-07-14 17:14:37 -0700874 * Dump the state of the object, add calls to other objects as desired.
875 *
876 * @param fd File descriptor
877 * @param printWriter Print writer
878 * @param args Arguments
879 */
880 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
881 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
882 pw.println("------- PhoneGlobals -------");
883 pw.increaseIndent();
Jordan Liuc353b162019-07-23 15:54:41 -0700884 pw.println("mPrevRoamingNotification=" + mPrevRoamingNotification);
Jack Yu1a2fc352017-07-14 17:14:37 -0700885 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
886 pw.println("mDataRoamingNotifLog:");
Keun young Parkdebb8532019-05-30 16:35:27 -0700887 pw.println("isSmsCapable=" + TelephonyManager.from(this).isSmsCapable());
Jack Yu1a2fc352017-07-14 17:14:37 -0700888 pw.increaseIndent();
889 mDataRoamingNotifLog.dump(fd, pw, args);
890 pw.decreaseIndent();
891 pw.decreaseIndent();
892 pw.println("------- End PhoneGlobals -------");
893 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700894}