blob: a3a79452ee2f82d30b6383e2e0d897dc8941bd9c [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 Liuff2ccd72019-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;
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 Liuff2ccd72019-07-23 15:54:41 -070077import java.lang.annotation.Retention;
78import java.lang.annotation.RetentionPolicy;
Jack Yu1a2fc352017-07-14 17:14:37 -070079
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080/**
81 * Global state for the telephony subsystem when running in the primary
82 * phone process.
83 */
Sailesh Nepalbf900542014-07-15 16:18:32 -070084public class PhoneGlobals extends ContextWrapper {
Jack Yu1a2fc352017-07-14 17:14:37 -070085 public static final String LOG_TAG = "PhoneGlobals";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086
87 /**
88 * Phone app-wide debug level:
89 * 0 - no debug logging
90 * 1 - normal debug logging if ro.debuggable is set (which is true in
91 * "eng" and "userdebug" builds but not "user" builds)
92 * 2 - ultra-verbose debug logging
93 *
94 * Most individual classes in the phone app have a local DBG constant,
95 * typically set to
96 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
97 * or else
98 * (PhoneApp.DBG_LEVEL >= 2)
99 * depending on the desired verbosity.
100 *
101 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
102 */
Andrew Lee88b51e22014-10-29 15:48:51 -0700103 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104
105 private static final boolean DBG =
106 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
107 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
108
109 // Message codes; see mHandler below.
110 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700112 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
Jordan Liuff2ccd72019-07-23 15:54:41 -0700113 private static final int EVENT_DATA_ROAMING_CONNECTED = 11;
114 private static final int EVENT_DATA_ROAMING_OK = 12;
115 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 13;
116 private static final int EVENT_RESTART_SIP = 14;
117 private static final int EVENT_DATA_ROAMING_SETTINGS_CHANGED = 15;
118 private static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED = 16;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119
120 // The MMI codes are also used by the InCallScreen.
121 public static final int MMI_INITIATE = 51;
122 public static final int MMI_COMPLETE = 52;
123 public static final int MMI_CANCEL = 53;
124 // Don't use message codes larger than 99 here; those are reserved for
125 // the individual Activities of the Phone UI.
126
Santos Cordone18902f2016-03-22 17:16:04 -0700127 public static final int AIRPLANE_ON = 1;
128 public static final int AIRPLANE_OFF = 0;
129
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130 /**
131 * Allowable values for the wake lock code.
132 * SLEEP means the device can be put to sleep.
133 * PARTIAL means wake the processor, but we display can be kept off.
134 * FULL means wake both the processor and the display.
135 */
136 public enum WakeState {
137 SLEEP,
138 PARTIAL,
139 FULL
140 }
141
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142 private static PhoneGlobals sMe;
143
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700144 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700145 CallNotifier notifier;
146 CallerInfoCache callerInfoCache;
Santos Cordon63a84242013-07-23 13:32:52 -0700147 NotificationMgr notificationMgr;
Andrew Lee9431b832015-03-09 18:46:45 -0700148 public PhoneInterfaceManager phoneMgr;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800149 CarrierConfigLoader configLoader;
Santos Cordon63a84242013-07-23 13:32:52 -0700150
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530151 private Phone phoneInEcm;
Santos Cordon63a84242013-07-23 13:32:52 -0700152
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700153 static boolean sVoiceCapable = true;
154
Santos Cordonc593d002015-06-03 15:41:15 -0700155 // TODO: Remove, no longer used.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700156 CdmaPhoneCallState cdmaPhoneCallState;
157
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700158 // The currently-active PUK entry activity and progress dialog.
159 // Normally, these are the Emergency Dialer and the subsequent
160 // progress dialog. null if there is are no such objects in
161 // the foreground.
162 private Activity mPUKEntryActivity;
163 private ProgressDialog mPUKEntryProgressDialog;
164
Jordan Liuff2ccd72019-07-23 15:54:41 -0700165 /** @hide */
166 @Retention(RetentionPolicy.SOURCE)
167 @IntDef(prefix = {"ROAMING_NOTIFICATION_"},
168 value = {
169 ROAMING_NOTIFICATION_NO_NOTIFICATION,
170 ROAMING_NOTIFICATION_CONNECTED,
171 ROAMING_NOTIFICATION_DISCONNECTED})
172 public @interface RoamingNotification {}
173
174 private static final int ROAMING_NOTIFICATION_NO_NOTIFICATION = 0;
175 private static final int ROAMING_NOTIFICATION_CONNECTED = 1;
176 private static final int ROAMING_NOTIFICATION_DISCONNECTED = 2;
177
178 @RoamingNotification
179 private int mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
Jack Yu953f9352017-05-18 14:41:06 -0700180
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700181 private WakeState mWakeState = WakeState.SLEEP;
182
183 private PowerManager mPowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700184 private PowerManager.WakeLock mWakeLock;
185 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700187
188 private UpdateLock mUpdateLock;
189
Jack Yu1a2fc352017-07-14 17:14:37 -0700190 private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
191 private final LocalLog mDataRoamingNotifLog = new LocalLog(50);
192
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193 // Broadcast receiver for various intent broadcasts (see onCreate())
194 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
Brad Ebinger533c6c12017-08-02 11:38:48 -0700195 // Broadcast receiver for SIP based intents (see onCreate())
Brad Ebinger28626122017-08-10 14:13:35 -0700196 private final SipReceiver mSipReceiver = new SipReceiver();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700198 private final CarrierVvmPackageInstalledReceiver mCarrierVvmPackageInstalledReceiver =
199 new CarrierVvmPackageInstalledReceiver();
200
Jack Yu1a2fc352017-07-14 17:14:37 -0700201 private final SettingsObserver mSettingsObserver;
202
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700203 Handler mHandler = new Handler() {
204 @Override
205 public void handleMessage(Message msg) {
206 PhoneConstants.State phoneState;
Jack Yu1a2fc352017-07-14 17:14:37 -0700207 if (VDBG) Log.v(LOG_TAG, "event=" + msg.what);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700208 switch (msg.what) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700209 // TODO: This event should be handled by the lock screen, just
210 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
211 case EVENT_SIM_NETWORK_LOCKED:
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700212 if (getCarrierConfig().getBoolean(
213 CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700214 // Some products don't have the concept of a "SIM network lock"
215 Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; "
Eric Erfanian945409f2018-02-21 19:26:15 +0000216 + "not showing 'SIM network unlock' PIN entry screen");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700217 } else {
218 // Normal case: show the "SIM network unlock" PIN entry screen.
219 // The user won't be able to do anything else until
220 // they enter a valid SIM network PIN.
221 Log.i(LOG_TAG, "show sim depersonal panel");
Biljana Maneva96291112018-01-30 13:12:59 +0800222 Phone phone = (Phone) ((AsyncResult) msg.obj).userObj;
223 IccNetworkDepersonalizationPanel.showDialog(phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700224 }
225 break;
226
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700227 case EVENT_DATA_ROAMING_DISCONNECTED:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700228 notificationMgr.showDataRoamingNotification(msg.arg1, false);
229 break;
230
231 case EVENT_DATA_ROAMING_CONNECTED:
232 notificationMgr.showDataRoamingNotification(msg.arg1, true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700233 break;
234
235 case EVENT_DATA_ROAMING_OK:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700236 notificationMgr.hideDataRoamingNotification();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700237 break;
238
239 case MMI_COMPLETE:
240 onMMIComplete((AsyncResult) msg.obj);
241 break;
242
243 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800244 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700245 break;
246
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700247 case EVENT_SIM_STATE_CHANGED:
248 // Marks the event where the SIM goes into ready state.
249 // Right now, this is only used for the PUK-unlocking
250 // process.
Amit Mahajanc08787c2019-03-26 16:11:55 -0700251 if (msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_READY)
252 || msg.obj.equals(IccCardConstants.INTENT_VALUE_ICC_LOADED)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700253 // when the right event is triggered and there
254 // are UI objects in the foreground, we close
255 // them to display the lock panel.
256 if (mPUKEntryActivity != null) {
257 mPUKEntryActivity.finish();
258 mPUKEntryActivity = null;
259 }
260 if (mPUKEntryProgressDialog != null) {
261 mPUKEntryProgressDialog.dismiss();
262 mPUKEntryProgressDialog = null;
263 }
264 }
265 break;
266
267 case EVENT_UNSOL_CDMA_INFO_RECORD:
268 //TODO: handle message here;
269 break;
Brad Ebinger3fa43462016-04-12 16:06:48 -0700270 case EVENT_RESTART_SIP:
271 // This should only run if the Phone process crashed and was restarted. We do
272 // not want this running if the device is still in the FBE encrypted state.
Brad Ebinger28626122017-08-10 14:13:35 -0700273 // This is the same procedure that is triggered in the SipIncomingCallReceiver
Brad Ebinger3fa43462016-04-12 16:06:48 -0700274 // upon BOOT_COMPLETED.
275 UserManager userManager = UserManager.get(sMe);
276 if (userManager != null && userManager.isUserUnlocked()) {
277 SipUtil.startSipService();
278 }
279 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700280 case EVENT_DATA_ROAMING_SETTINGS_CHANGED:
281 case EVENT_MOBILE_DATA_SETTINGS_CHANGED:
282 updateDataRoamingStatus();
283 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700284 }
285 }
286 };
287
288 public PhoneGlobals(Context context) {
289 super(context);
290 sMe = this;
Jack Yu1a2fc352017-07-14 17:14:37 -0700291 mSettingsObserver = new SettingsObserver(context, mHandler);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700292 }
293
294 public void onCreate() {
295 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
296
297 ContentResolver resolver = getContentResolver();
298
299 // Cache the "voice capable" flag.
300 // This flag currently comes from a resource (which is
301 // overrideable on a per-product basis):
302 sVoiceCapable =
303 getResources().getBoolean(com.android.internal.R.bool.config_voice_capable);
304 // ...but this might eventually become a PackageManager "system
305 // feature" instead, in which case we'd do something like:
306 // sVoiceCapable =
307 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
308
Stuart Scottdcf40a92014-12-09 10:45:01 -0800309 if (mCM == null) {
Nathan Haroldf9df6ea2019-03-08 11:54:22 -0800310 // Initialize AnomalyReporter early so that it can be used
311 AnomalyReporter.initialize(this);
Nathan Harold0db5c5e2019-01-22 20:18:56 -0800312
Youming Ye47a6adc2018-11-19 15:33:36 -0800313 // Inject telephony component factory if configured using other jars.
314 XmlResourceParser parser = getResources().getXml(R.xml.telephony_injection);
315 TelephonyComponentFactory.getInstance().injectTheComponentFactory(parser);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700316 // Initialize the telephony framework
317 PhoneFactory.makeDefaultPhones(this);
318
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700319 // Start TelephonyDebugService After the default phone is created.
320 Intent intent = new Intent(this, TelephonyDebugService.class);
321 startService(intent);
322
323 mCM = CallManager.getInstance();
Stuart Scottdcf40a92014-12-09 10:45:01 -0800324 for (Phone phone : PhoneFactory.getPhones()) {
325 mCM.registerPhone(phone);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800326 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700327
328 // Create the NotificationMgr singleton, which is used to display
329 // status bar icons and control other status bar behavior.
330 notificationMgr = NotificationMgr.init(this);
331
Brad Ebinger3fa43462016-04-12 16:06:48 -0700332 // If PhoneGlobals has crashed and is being restarted, then restart.
333 mHandler.sendEmptyMessage(EVENT_RESTART_SIP);
334
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700335 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
336 cdmaPhoneCallState = new CdmaPhoneCallState();
337 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700339 // before registering for phone state changes
340 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
341 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
342 // lock used to keep the processor awake, when we don't care for the display.
343 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
344 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700345
346 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
347
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348 // Get UpdateLock to suppress system-update related events (e.g. dialog show-up)
349 // during phone calls.
350 mUpdateLock = new UpdateLock("phone");
351
352 if (DBG) Log.d(LOG_TAG, "onCreate: mUpdateLock: " + mUpdateLock);
353
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354 // Create the CallerInfoCache singleton, which remembers custom ring tone and
355 // send-to-voicemail settings.
356 //
357 // The asynchronous caching will start just after this call.
358 callerInfoCache = CallerInfoCache.init(this);
359
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800360 phoneMgr = PhoneInterfaceManager.init(this);
Santos Cordon406c0342013-08-28 00:07:47 -0700361
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800362 configLoader = CarrierConfigLoader.init(this);
363
Jack Yu1a2fc352017-07-14 17:14:37 -0700364 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365 // asynchronous events from the telephony layer (like
366 // launching the incoming-call UI when an incoming call comes
367 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800368 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369
Stuart Scottdcf40a92014-12-09 10:45:01 -0800370 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371
372 // register for MMI/USSD
373 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
374
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700375 // Register for misc other intent broadcasts.
376 IntentFilter intentFilter =
377 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700378 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
379 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
380 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
381 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700382 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
383 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384 registerReceiver(mReceiver, intentFilter);
385
Brad Ebinger533c6c12017-08-02 11:38:48 -0700386 IntentFilter sipIntentFilter = new IntentFilter(Intent.ACTION_BOOT_COMPLETED);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700387 sipIntentFilter.addAction(SipManager.ACTION_SIP_SERVICE_UP);
388 sipIntentFilter.addAction(SipManager.ACTION_SIP_CALL_OPTION_CHANGED);
389 sipIntentFilter.addAction(SipManager.ACTION_SIP_REMOVE_PHONE);
Brad Ebinger28626122017-08-10 14:13:35 -0700390 registerReceiver(mSipReceiver, sipIntentFilter);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700391
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700392 mCarrierVvmPackageInstalledReceiver.register(this);
393
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394 //set the default values for the preferences in the phone.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700395 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700396 }
397
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398 // XXX pre-load the SimProvider so that it's ready
399 resolver.getType(Uri.parse("content://icc/adn"));
400
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401 // TODO: Register for Cdma Information Records
402 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
403
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700404 // Read HAC settings and configure audio hardware
405 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800406 int hac = android.provider.Settings.System.getInt(
407 getContentResolver(),
408 android.provider.Settings.System.HEARING_AID,
409 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700410 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Jordan Liuf71aeef2019-08-21 11:46:09 -0700411 audioManager.setParameters(
412 SettingsConstants.HAC_KEY + "=" + (hac == SettingsConstants.HAC_ENABLED
413 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700414 }
Santos Cordonff506f52013-11-21 19:13:19 -0800415 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417 /**
418 * Returns the singleton instance of the PhoneApp.
419 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800420 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700421 if (sMe == null) {
422 throw new IllegalStateException("No PhoneGlobals here!");
423 }
424 return sMe;
425 }
426
427 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800428 * Returns the default phone.
429 *
Andrew Lee385019f2014-11-24 14:19:50 -0800430 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700431 */
Andrew Lee83383e42014-10-31 12:42:28 -0700432 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800433 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434 }
435
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800436 public static Phone getPhone(int subId) {
437 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800438 }
439
Santos Cordonde10b752013-09-19 04:11:33 -0700440 /* package */ CallManager getCallManager() {
441 return mCM;
442 }
443
Chris Manton4e9fa912015-06-19 11:26:57 -0700444 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800445 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700446 }
447
Chris Manton4e9fa912015-06-19 11:26:57 -0700448 public PersistableBundle getCarrierConfigForSubId(int subId) {
Malcolm Chen6d3d6b32018-03-01 13:58:03 -0800449 return configLoader.getConfigForSubId(subId, getOpPackageName());
Junda Liu605148f2015-04-28 15:23:40 -0700450 }
451
Jack Yu1a2fc352017-07-14 17:14:37 -0700452 private void registerSettingsObserver() {
453 mSettingsObserver.unobserve();
454 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
455 String mobileDataSetting = Settings.Global.MOBILE_DATA;
456 if (TelephonyManager.getDefault().getSimCount() > 1) {
457 int subId = mDefaultDataSubId;
458 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
459 dataRoamingSetting += subId;
460 mobileDataSetting += subId;
461 }
462 }
463
464 // Listen for user data roaming setting changed event
465 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
466 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
467
468 // Listen for mobile data setting changed event
469 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
470 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
471 }
472
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700473 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700474 * Sets the activity responsible for un-PUK-blocking the device
475 * so that we may close it when we receive a positive result.
476 * mPUKEntryActivity is also used to indicate to the device that
477 * we are trying to un-PUK-lock the phone. In other words, iff
478 * it is NOT null, then we are trying to unlock and waiting for
479 * the SIM to move to READY state.
480 *
481 * @param activity is the activity to close when PUK has
482 * finished unlocking. Can be set to null to indicate the unlock
483 * or SIM READYing process is over.
484 */
485 void setPukEntryActivity(Activity activity) {
486 mPUKEntryActivity = activity;
487 }
488
489 Activity getPUKEntryActivity() {
490 return mPUKEntryActivity;
491 }
492
493 /**
494 * Sets the dialog responsible for notifying the user of un-PUK-
495 * blocking - SIM READYing progress, so that we may dismiss it
496 * when we receive a positive result.
497 *
498 * @param dialog indicates the progress dialog informing the user
499 * of the state of the device. Dismissed upon completion of
500 * READYing process
501 */
502 void setPukEntryProgressDialog(ProgressDialog dialog) {
503 mPUKEntryProgressDialog = dialog;
504 }
505
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700506 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700507 * If we are not currently keeping the screen on, then poke the power
508 * manager to wake up the screen for the user activity timeout duration.
509 */
510 /* package */ void wakeUpScreen() {
511 synchronized (this) {
512 if (mWakeState == WakeState.SLEEP) {
513 if (DBG) Log.d(LOG_TAG, "pulse screen lock");
Dianne Hackborn148769b2015-07-13 17:55:47 -0700514 mPowerManager.wakeUp(SystemClock.uptimeMillis(), "android.phone:WAKE");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700515 }
516 }
517 }
518
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700519 KeyguardManager getKeyguardManager() {
520 return mKeyguardManager;
521 }
522
523 private void onMMIComplete(AsyncResult r) {
524 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
525 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800526 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700527 }
528
fionaxu80126972017-02-01 17:01:26 -0800529 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700530 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700531 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700532 }
533
Chris Mantona09f3632016-02-09 14:48:42 -0800534 private void handleAirplaneModeChange(Context context, int newMode) {
535 int cellState = Settings.Global.getInt(context.getContentResolver(),
536 Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
537 boolean isAirplaneNewlyOn = (newMode == 1);
538 switch (cellState) {
539 case PhoneConstants.CELL_OFF_FLAG:
540 // Airplane mode does not affect the cell radio if user
541 // has turned it off.
542 break;
543 case PhoneConstants.CELL_ON_FLAG:
544 maybeTurnCellOff(context, isAirplaneNewlyOn);
545 break;
546 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
547 maybeTurnCellOn(context, isAirplaneNewlyOn);
548 break;
549 }
Hall Liu7f56e1a2019-07-10 14:41:14 -0700550 for (Phone phone : PhoneFactory.getPhones()) {
551 phone.getServiceStateTracker().onAirplaneModeChanged(isAirplaneNewlyOn);
552 }
Chris Mantona09f3632016-02-09 14:48:42 -0800553 }
554
555 /*
556 * Returns true if the radio must be turned off when entering airplane mode.
557 */
558 private boolean isCellOffInAirplaneMode(Context context) {
559 String airplaneModeRadios = Settings.Global.getString(context.getContentResolver(),
560 Settings.Global.AIRPLANE_MODE_RADIOS);
561 return airplaneModeRadios == null
562 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
563 }
564
565 private void setRadioPowerOff(Context context) {
566 Log.i(LOG_TAG, "Turning radio off - airplane");
567 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
Eric Erfanian945409f2018-02-21 19:26:15 +0000568 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Sooraj Sasindran798bafa2017-04-03 22:49:00 -0700569 SystemProperties.set("persist.radio.airplane_mode_on", "1");
Chris Mantona09f3632016-02-09 14:48:42 -0800570 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
571 PhoneUtils.setRadioPower(false);
572 }
573
574 private void setRadioPowerOn(Context context) {
575 Log.i(LOG_TAG, "Turning radio on - airplane");
576 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
577 PhoneConstants.CELL_ON_FLAG);
578 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT,
579 1);
Sooraj Sasindran798bafa2017-04-03 22:49:00 -0700580 SystemProperties.set("persist.radio.airplane_mode_on", "0");
Chris Mantona09f3632016-02-09 14:48:42 -0800581 PhoneUtils.setRadioPower(true);
582 }
583
584 private void maybeTurnCellOff(Context context, boolean isAirplaneNewlyOn) {
585 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700586 // If we are trying to turn off the radio, make sure there are no active
587 // emergency calls. If there are, switch airplane mode back to off.
Tyler Gunn900d8fd2018-09-21 09:22:12 -0700588 TelecomManager tm = (TelecomManager) context.getSystemService(TELECOM_SERVICE);
589
590 if (tm != null && tm.isInEmergencyCall()) {
Santos Cordone18902f2016-03-22 17:16:04 -0700591 // Switch airplane mode back to off.
592 ConnectivityManager.from(this).setAirplaneMode(false);
593 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
594 .show();
595 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Chris Mantona09f3632016-02-09 14:48:42 -0800596 } else if (isCellOffInAirplaneMode(context)) {
597 setRadioPowerOff(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700598 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800599 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700600 }
Chris Mantona09f3632016-02-09 14:48:42 -0800601 }
602 }
603
604 private void maybeTurnCellOn(Context context, boolean isAirplaneNewlyOn) {
605 if (!isAirplaneNewlyOn) {
606 setRadioPowerOn(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700607 }
608 }
609
Santos Cordon593ab382013-08-06 21:58:23 -0700610 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700611 * Receiver for misc intent broadcasts the Phone app cares about.
612 */
613 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
614 @Override
615 public void onReceive(Context context, Intent intent) {
616 String action = intent.getAction();
617 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Santos Cordone18902f2016-03-22 17:16:04 -0700618 int airplaneMode = Settings.Global.getInt(getContentResolver(),
619 Settings.Global.AIRPLANE_MODE_ON, AIRPLANE_OFF);
620 // Treat any non-OFF values as ON.
621 if (airplaneMode != AIRPLANE_OFF) {
622 airplaneMode = AIRPLANE_ON;
623 }
Chris Mantona09f3632016-02-09 14:48:42 -0800624 handleAirplaneModeChange(context, airplaneMode);
Amit Mahajanf5d92c82018-11-02 17:44:40 -0700625 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
626 // re-register as it may be a new IccCard
627 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
628 SubscriptionManager.INVALID_PHONE_INDEX);
629 if (SubscriptionManager.isValidPhoneId(phoneId)) {
630 PhoneUtils.unregisterIccStatus(mHandler, phoneId);
631 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED, phoneId);
632 }
633 if (mPUKEntryActivity != null) {
634 // if an attempt to un-PUK-lock the device was made, while we're
635 // receiving this state change notification, notify the handler.
636 // NOTE: This is ONLY triggered if an attempt to un-PUK-lock has
637 // been attempted.
638 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
639 intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE)));
640 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700641 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
642 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800643 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
644 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700645 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
646 handleServiceStateChanged(intent);
647 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530648 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530649 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530650 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
651 if (phoneInEcm != null) {
652 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
653 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
654 // Start Emergency Callback Mode service
655 if (intent.getBooleanExtra("phoneinECMState", false)) {
656 context.startService(new Intent(context,
657 EmergencyCallbackModeService.class));
658 } else {
659 phoneInEcm = null;
660 }
661 } else {
662 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
663 // on a device that doesn't support ECM in the first place.
664 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
665 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
666 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700667 }
668 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530669 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700670 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700671 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
672 // Roaming status could be overridden by carrier config, so we need to update it.
673 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
674 updateDataRoamingStatus();
675 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
676 // We also need to pay attention when default data subscription changes.
677 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
678 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
679 registerSettingsObserver();
680 Phone phone = getPhone(mDefaultDataSubId);
681 if (phone != null) {
682 updateDataRoamingStatus();
683 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700684 }
685 }
686 }
687
Brad Ebinger28626122017-08-10 14:13:35 -0700688 private class SipReceiver extends BroadcastReceiver {
689
690 @Override
691 public void onReceive(Context context, Intent intent) {
692 String action = intent.getAction();
693
694 SipAccountRegistry sipAccountRegistry = SipAccountRegistry.getInstance();
695 if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
696 SipUtil.startSipService();
697 } else if (action.equals(SipManager.ACTION_SIP_SERVICE_UP)
698 || action.equals(SipManager.ACTION_SIP_CALL_OPTION_CHANGED)) {
699 sipAccountRegistry.setup(context);
700 } else if (action.equals(SipManager.ACTION_SIP_REMOVE_PHONE)) {
701 if (DBG) {
702 Log.d(LOG_TAG, "SIP_REMOVE_PHONE "
703 + intent.getStringExtra(SipManager.EXTRA_LOCAL_URI));
704 }
705 sipAccountRegistry.removeSipProfile(intent.getStringExtra(
706 SipManager.EXTRA_LOCAL_URI));
707 } else {
708 if (DBG) Log.d(LOG_TAG, "onReceive, action not processed: " + action);
709 }
710 }
711 }
712
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700713 private void handleServiceStateChanged(Intent intent) {
714 /**
715 * This used to handle updating EriTextWidgetProvider this routine
716 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
717 * be removed. But leaving just in case it might be needed in the near
718 * future.
719 */
720
Jack Yu1a2fc352017-07-14 17:14:37 -0700721 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700722 // If service just returned, start sending out the queued messages
Santos Cordonc593d002015-06-03 15:41:15 -0700723 Bundle extras = intent.getExtras();
724 if (extras != null) {
725 ServiceState ss = ServiceState.newFromBundle(extras);
726 if (ss != null) {
727 int state = ss.getState();
Jayachandran C2ef9a482017-05-12 22:07:47 -0700728 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
729 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
730 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -0700731
732 if (VDBG) {
733 Log.v(LOG_TAG, "subId=" + subId + ",mDefaultDataSubId="
734 + mDefaultDataSubId + ",ss roaming=" + ss.getDataRoaming());
735 }
736 if (subId == mDefaultDataSubId) {
737 updateDataRoamingStatus();
738 }
Santos Cordonc593d002015-06-03 15:41:15 -0700739 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700740 }
741 }
742
Jack Yu1a2fc352017-07-14 17:14:37 -0700743 /**
Jordan Liuff2ccd72019-07-23 15:54:41 -0700744 * @return whether or not we should show a notification when connecting to data roaming if the
745 * user has data roaming enabled
746 */
747 private boolean shouldShowDataConnectedRoaming(int subId) {
748 PersistableBundle config = getCarrierConfigForSubId(subId);
749 return config.getBoolean(CarrierConfigManager
750 .KEY_SHOW_DATA_CONNECTED_ROAMING_NOTIFICATION_BOOL);
751 }
752
753 /**
Jack Yu1a2fc352017-07-14 17:14:37 -0700754 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
755 * to notify the user so they can enable it through settings. Vise versa if the condition
756 * changes, we need to dismiss the notification.
757 */
758 private void updateDataRoamingStatus() {
759 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
760 Phone phone = getPhone(mDefaultDataSubId);
761 if (phone == null) {
762 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
763 return;
764 }
765
766 DataConnectionReasons reasons = new DataConnectionReasons();
Jack Yu311536f2018-11-26 11:20:48 -0800767 boolean dataAllowed = phone.isDataAllowed(ApnSetting.TYPE_DEFAULT, reasons);
Jack Yu1a2fc352017-07-14 17:14:37 -0700768 mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons);
769 if (VDBG) Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons);
Jordan Liuff2ccd72019-07-23 15:54:41 -0700770 if (!dataAllowed && reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED)) {
771 // No need to show it again if we never cancelled it explicitly.
772 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_DISCONNECTED) return;
Jack Yu1a2fc352017-07-14 17:14:37 -0700773 // If the only reason of no data is data roaming disabled, then we notify the user
774 // so the user can turn on data roaming.
Jordan Liuff2ccd72019-07-23 15:54:41 -0700775 mPrevRoamingNotification = ROAMING_NOTIFICATION_DISCONNECTED;
Jack Yu1a2fc352017-07-14 17:14:37 -0700776 Log.d(LOG_TAG, "Show roaming disconnected notification");
Jordan Liuff2ccd72019-07-23 15:54:41 -0700777 mDataRoamingNotifLog.log("Show roaming off.");
Pengquan Meng8783d932017-10-16 14:57:40 -0700778 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_DISCONNECTED);
779 msg.arg1 = mDefaultDataSubId;
780 msg.sendToTarget();
Jordan Liuff2ccd72019-07-23 15:54:41 -0700781 } else if (dataAllowed && dataIsNowRoaming(mDefaultDataSubId)
782 && shouldShowDataConnectedRoaming(mDefaultDataSubId)) {
783 // No need to show it again if we never cancelled it explicitly, or carrier config
784 // indicates this is not needed.
785 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_CONNECTED) return;
786 mPrevRoamingNotification = ROAMING_NOTIFICATION_CONNECTED;
787 Log.d(LOG_TAG, "Show roaming connected notification");
788 mDataRoamingNotifLog.log("Show roaming on.");
789 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_CONNECTED);
790 msg.arg1 = mDefaultDataSubId;
791 msg.sendToTarget();
792 } else if (mPrevRoamingNotification != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
793 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
794 // is not the only data disable reason. In this case we dismiss the notification we
795 // showed earlier.
796 mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
797 Log.d(LOG_TAG, "Dismiss roaming notification");
Jack Yu1a2fc352017-07-14 17:14:37 -0700798 mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed + ", reasons=" + reasons);
799 mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
800 }
801 }
802
Jordan Liuff2ccd72019-07-23 15:54:41 -0700803 /**
804 *
805 * @param subId to check roaming on
806 * @return whether we have transitioned to dataRoaming
807 */
808 private boolean dataIsNowRoaming(int subId) {
809 return getPhone(subId).getServiceState().getDataRoaming();
810 }
811
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530812 public Phone getPhoneInEcm() {
813 return phoneInEcm;
814 }
815
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700816 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800817 * Triggers a refresh of the message waiting (voicemail) indicator.
818 *
819 * @param subId the subscription id we should refresh the notification for.
820 */
821 public void refreshMwiIndicator(int subId) {
822 notificationMgr.refreshMwi(subId);
823 }
824
825 /**
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700826 * Called when the network selection on the subscription {@code subId} is changed by the user.
827 *
828 * @param subId the subscription id.
829 */
830 public void onNetworkSelectionChanged(int subId) {
831 Phone phone = getPhone(subId);
832 if (phone != null) {
833 notificationMgr.updateNetworkSelection(phone.getServiceState().getState(), subId);
834 } else {
835 Log.w(LOG_TAG, "onNetworkSelectionChanged on null phone, subId: " + subId);
836 }
837 }
838
839 /**
Jack Yu1a2fc352017-07-14 17:14:37 -0700840 * Dump the state of the object, add calls to other objects as desired.
841 *
842 * @param fd File descriptor
843 * @param printWriter Print writer
844 * @param args Arguments
845 */
846 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
847 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
848 pw.println("------- PhoneGlobals -------");
849 pw.increaseIndent();
Jordan Liuff2ccd72019-07-23 15:54:41 -0700850 pw.println("mPrevRoamingNotification=" + mPrevRoamingNotification);
Jack Yu1a2fc352017-07-14 17:14:37 -0700851 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
852 pw.println("mDataRoamingNotifLog:");
Keun young Parkdebb8532019-05-30 16:35:27 -0700853 pw.println("isSmsCapable=" + TelephonyManager.from(this).isSmsCapable());
Jack Yu1a2fc352017-07-14 17:14:37 -0700854 pw.increaseIndent();
855 mDataRoamingNotifLog.dump(fd, pw, args);
856 pw.decreaseIndent();
857 pw.decreaseIndent();
858 pw.println("------- End PhoneGlobals -------");
859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700860}