blob: 98bb7667b0f2d075e5442f0f7635992835797fc1 [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;
Brad Ebinger05f52c22019-12-05 13:03:21 -080029import android.content.pm.PackageManager;
Youming Ye47a6adc2018-11-19 15:33:36 -080030import android.content.res.XmlResourceParser;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.media.AudioManager;
Santos Cordone18902f2016-03-22 17:16:04 -070032import android.net.ConnectivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.net.Uri;
Brad Ebinger533c6c12017-08-02 11:38:48 -070034import android.net.sip.SipManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.os.AsyncResult;
Junda Liu605148f2015-04-28 15:23:40 -070036import android.os.Bundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.os.Handler;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.Message;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070039import android.os.PersistableBundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.os.PowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.SystemProperties;
Brad Ebinger3fa43462016-04-12 16:06:48 -070042import android.os.UserManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.preference.PreferenceManager;
Sanket Padawe4c699232016-02-09 11:07:22 -080044import android.provider.Settings;
Meng Wang61307622019-10-23 14:08:43 -070045import android.sysprop.TelephonyProperties;
Tyler Gunn900d8fd2018-09-21 09:22:12 -070046import android.telecom.TelecomManager;
Nathan Haroldf9df6ea2019-03-08 11:54:22 -080047import android.telephony.AnomalyReporter;
Junda Liu12f7d802015-05-01 12:06:44 -070048import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.telephony.ServiceState;
chen xubaf9fe52019-07-02 17:28:24 -070050import android.telephony.SubscriptionInfo;
Andrew Lee385019f2014-11-24 14:19:50 -080051import android.telephony.SubscriptionManager;
Jack Yu1a2fc352017-07-14 17:14:37 -070052import android.telephony.TelephonyManager;
Jack Yu311536f2018-11-26 11:20:48 -080053import android.telephony.data.ApnSetting;
Jack Yu1a2fc352017-07-14 17:14:37 -070054import android.util.LocalLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.util.Log;
Santos Cordone18902f2016-03-22 17:16:04 -070056import android.widget.Toast;
Ta-wei Yenb29425b2016-09-21 17:28:14 -070057
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import com.android.internal.telephony.CallManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import com.android.internal.telephony.IccCardConstants;
60import com.android.internal.telephony.MmiCode;
61import com.android.internal.telephony.Phone;
62import com.android.internal.telephony.PhoneConstants;
63import com.android.internal.telephony.PhoneFactory;
Jack Yu1a2fc352017-07-14 17:14:37 -070064import com.android.internal.telephony.SettingsObserver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import com.android.internal.telephony.TelephonyCapabilities;
Youming Ye47a6adc2018-11-19 15:33:36 -080066import com.android.internal.telephony.TelephonyComponentFactory;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067import com.android.internal.telephony.TelephonyIntents;
Jack Yu1a2fc352017-07-14 17:14:37 -070068import com.android.internal.telephony.dataconnection.DataConnectionReasons;
69import com.android.internal.telephony.dataconnection.DataConnectionReasons.DataDisallowedReasonType;
Brad Ebinger05f52c22019-12-05 13:03:21 -080070import com.android.internal.telephony.ims.ImsResolver;
Jack Yu1a2fc352017-07-14 17:14:37 -070071import com.android.internal.util.IndentingPrintWriter;
Andrew Leefb7f92e2015-02-26 16:23:32 -080072import com.android.phone.settings.SettingsConstants;
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -070073import com.android.phone.vvm.CarrierVvmPackageInstalledReceiver;
James.cf Linc9f35a42020-01-15 02:35:22 +080074import com.android.services.telephony.rcs.TelephonyRcsService;
Brad Ebinger28626122017-08-10 14:13:35 -070075import com.android.services.telephony.sip.SipAccountRegistry;
Brad Ebinger3fa43462016-04-12 16:06:48 -070076import com.android.services.telephony.sip.SipUtil;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070077
Jack Yu1a2fc352017-07-14 17:14:37 -070078import java.io.FileDescriptor;
79import java.io.PrintWriter;
Jordan Liuff2ccd72019-07-23 15:54:41 -070080import java.lang.annotation.Retention;
81import java.lang.annotation.RetentionPolicy;
chen xubaf9fe52019-07-02 17:28:24 -070082import java.util.List;
Jack Yu1a2fc352017-07-14 17:14:37 -070083
Santos Cordon7d4ddf62013-07-10 11:58:08 -070084/**
85 * Global state for the telephony subsystem when running in the primary
86 * phone process.
87 */
Sailesh Nepalbf900542014-07-15 16:18:32 -070088public class PhoneGlobals extends ContextWrapper {
Jack Yu1a2fc352017-07-14 17:14:37 -070089 public static final String LOG_TAG = "PhoneGlobals";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090
91 /**
92 * Phone app-wide debug level:
93 * 0 - no debug logging
94 * 1 - normal debug logging if ro.debuggable is set (which is true in
95 * "eng" and "userdebug" builds but not "user" builds)
96 * 2 - ultra-verbose debug logging
97 *
98 * Most individual classes in the phone app have a local DBG constant,
99 * typically set to
100 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
101 * or else
102 * (PhoneApp.DBG_LEVEL >= 2)
103 * depending on the desired verbosity.
104 *
105 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
106 */
Andrew Lee88b51e22014-10-29 15:48:51 -0700107 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700108
109 private static final boolean DBG =
110 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
111 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
112
113 // Message codes; see mHandler below.
114 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
Jordan Liuff2ccd72019-07-23 15:54:41 -0700117 private static final int EVENT_DATA_ROAMING_CONNECTED = 11;
118 private static final int EVENT_DATA_ROAMING_OK = 12;
119 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 13;
120 private static final int EVENT_RESTART_SIP = 14;
121 private static final int EVENT_DATA_ROAMING_SETTINGS_CHANGED = 15;
122 private static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED = 16;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123
124 // The MMI codes are also used by the InCallScreen.
125 public static final int MMI_INITIATE = 51;
126 public static final int MMI_COMPLETE = 52;
127 public static final int MMI_CANCEL = 53;
128 // Don't use message codes larger than 99 here; those are reserved for
129 // the individual Activities of the Phone UI.
130
Santos Cordone18902f2016-03-22 17:16:04 -0700131 public static final int AIRPLANE_ON = 1;
132 public static final int AIRPLANE_OFF = 0;
133
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134 /**
135 * Allowable values for the wake lock code.
136 * SLEEP means the device can be put to sleep.
137 * PARTIAL means wake the processor, but we display can be kept off.
138 * FULL means wake both the processor and the display.
139 */
140 public enum WakeState {
141 SLEEP,
142 PARTIAL,
143 FULL
144 }
145
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700146 private static PhoneGlobals sMe;
147
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700148 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700149 CallNotifier notifier;
150 CallerInfoCache callerInfoCache;
Santos Cordon63a84242013-07-23 13:32:52 -0700151 NotificationMgr notificationMgr;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800152 ImsResolver mImsResolver;
James.cf Linc9f35a42020-01-15 02:35:22 +0800153 TelephonyRcsService mTelephonyRcsService;
Andrew Lee9431b832015-03-09 18:46:45 -0700154 public PhoneInterfaceManager phoneMgr;
James.cf Linaf3183c2019-10-24 00:59:00 +0800155 public ImsRcsController imsRcsController;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800156 CarrierConfigLoader configLoader;
Santos Cordon63a84242013-07-23 13:32:52 -0700157
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530158 private Phone phoneInEcm;
Santos Cordon63a84242013-07-23 13:32:52 -0700159
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700160 static boolean sVoiceCapable = true;
161
Santos Cordonc593d002015-06-03 15:41:15 -0700162 // TODO: Remove, no longer used.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700163 CdmaPhoneCallState cdmaPhoneCallState;
164
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165 // The currently-active PUK entry activity and progress dialog.
166 // Normally, these are the Emergency Dialer and the subsequent
167 // progress dialog. null if there is are no such objects in
168 // the foreground.
169 private Activity mPUKEntryActivity;
170 private ProgressDialog mPUKEntryProgressDialog;
171
Jordan Liuff2ccd72019-07-23 15:54:41 -0700172 /** @hide */
173 @Retention(RetentionPolicy.SOURCE)
174 @IntDef(prefix = {"ROAMING_NOTIFICATION_"},
175 value = {
176 ROAMING_NOTIFICATION_NO_NOTIFICATION,
177 ROAMING_NOTIFICATION_CONNECTED,
178 ROAMING_NOTIFICATION_DISCONNECTED})
179 public @interface RoamingNotification {}
180
181 private static final int ROAMING_NOTIFICATION_NO_NOTIFICATION = 0;
182 private static final int ROAMING_NOTIFICATION_CONNECTED = 1;
183 private static final int ROAMING_NOTIFICATION_DISCONNECTED = 2;
184
185 @RoamingNotification
186 private int mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
Jack Yu953f9352017-05-18 14:41:06 -0700187
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700188 private WakeState mWakeState = WakeState.SLEEP;
189
190 private PowerManager mPowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700191 private PowerManager.WakeLock mWakeLock;
192 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194
Jack Yu1a2fc352017-07-14 17:14:37 -0700195 private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
196 private final LocalLog mDataRoamingNotifLog = new LocalLog(50);
197
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198 // Broadcast receiver for various intent broadcasts (see onCreate())
199 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
Brad Ebinger533c6c12017-08-02 11:38:48 -0700200 // Broadcast receiver for SIP based intents (see onCreate())
Brad Ebinger28626122017-08-10 14:13:35 -0700201 private final SipReceiver mSipReceiver = new SipReceiver();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700202
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700203 private final CarrierVvmPackageInstalledReceiver mCarrierVvmPackageInstalledReceiver =
204 new CarrierVvmPackageInstalledReceiver();
205
Jack Yu1a2fc352017-07-14 17:14:37 -0700206 private final SettingsObserver mSettingsObserver;
207
Nazish Tabassum160d2112019-12-23 17:31:33 +0530208 private static class EventSimStateChangedBag {
209 final int mPhoneId;
210 final String mIccStatus;
211
212 EventSimStateChangedBag(int phoneId, String iccStatus) {
213 mPhoneId = phoneId;
214 mIccStatus = iccStatus;
215 }
216 }
217
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700218 Handler mHandler = new Handler() {
219 @Override
220 public void handleMessage(Message msg) {
221 PhoneConstants.State phoneState;
Jack Yu1a2fc352017-07-14 17:14:37 -0700222 if (VDBG) Log.v(LOG_TAG, "event=" + msg.what);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700223 switch (msg.what) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700224 // TODO: This event should be handled by the lock screen, just
225 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
226 case EVENT_SIM_NETWORK_LOCKED:
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700227 if (getCarrierConfig().getBoolean(
228 CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700229 // Some products don't have the concept of a "SIM network lock"
230 Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; "
Eric Erfanian945409f2018-02-21 19:26:15 +0000231 + "not showing 'SIM network unlock' PIN entry screen");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700232 } else {
233 // Normal case: show the "SIM network unlock" PIN entry screen.
234 // The user won't be able to do anything else until
235 // they enter a valid SIM network PIN.
236 Log.i(LOG_TAG, "show sim depersonal panel");
Biljana Maneva96291112018-01-30 13:12:59 +0800237 Phone phone = (Phone) ((AsyncResult) msg.obj).userObj;
Nazish Tabassum160d2112019-12-23 17:31:33 +0530238 int subType = (Integer)((AsyncResult)msg.obj).result;
239 IccNetworkDepersonalizationPanel.showDialog(phone, subType);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700240 }
241 break;
242
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700243 case EVENT_DATA_ROAMING_DISCONNECTED:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700244 notificationMgr.showDataRoamingNotification(msg.arg1, false);
245 break;
246
247 case EVENT_DATA_ROAMING_CONNECTED:
248 notificationMgr.showDataRoamingNotification(msg.arg1, true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249 break;
250
251 case EVENT_DATA_ROAMING_OK:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700252 notificationMgr.hideDataRoamingNotification();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700253 break;
254
255 case MMI_COMPLETE:
256 onMMIComplete((AsyncResult) msg.obj);
257 break;
258
259 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800260 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700261 break;
262
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700263 case EVENT_SIM_STATE_CHANGED:
264 // Marks the event where the SIM goes into ready state.
265 // Right now, this is only used for the PUK-unlocking
266 // process.
Nazish Tabassum160d2112019-12-23 17:31:33 +0530267 EventSimStateChangedBag bag = (EventSimStateChangedBag)msg.obj;
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700268 if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(bag.mIccStatus)
269 || IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(bag.mIccStatus)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700270 // when the right event is triggered and there
271 // are UI objects in the foreground, we close
272 // them to display the lock panel.
273 if (mPUKEntryActivity != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700274 Log.i(LOG_TAG, "Dismiss puk entry activity");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275 mPUKEntryActivity.finish();
276 mPUKEntryActivity = null;
277 }
278 if (mPUKEntryProgressDialog != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700279 Log.i(LOG_TAG, "Dismiss puk progress dialog");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700280 mPUKEntryProgressDialog.dismiss();
281 mPUKEntryProgressDialog = null;
282 }
Nazish Tabassum160d2112019-12-23 17:31:33 +0530283 Log.i(LOG_TAG, "Dismissing depersonal panel");
284 IccNetworkDepersonalizationPanel.dialogDismiss(bag.mPhoneId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700285 }
286 break;
287
288 case EVENT_UNSOL_CDMA_INFO_RECORD:
289 //TODO: handle message here;
290 break;
Brad Ebinger3fa43462016-04-12 16:06:48 -0700291 case EVENT_RESTART_SIP:
292 // This should only run if the Phone process crashed and was restarted. We do
293 // not want this running if the device is still in the FBE encrypted state.
Brad Ebinger28626122017-08-10 14:13:35 -0700294 // This is the same procedure that is triggered in the SipIncomingCallReceiver
Brad Ebinger3fa43462016-04-12 16:06:48 -0700295 // upon BOOT_COMPLETED.
Meng Wangc04cd2d2019-10-04 12:00:06 -0700296 UserManager userManager =
297 (UserManager) sMe.getSystemService(Context.USER_SERVICE);
Brad Ebinger3fa43462016-04-12 16:06:48 -0700298 if (userManager != null && userManager.isUserUnlocked()) {
299 SipUtil.startSipService();
300 }
301 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700302 case EVENT_DATA_ROAMING_SETTINGS_CHANGED:
303 case EVENT_MOBILE_DATA_SETTINGS_CHANGED:
304 updateDataRoamingStatus();
305 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700306 }
307 }
308 };
309
310 public PhoneGlobals(Context context) {
311 super(context);
312 sMe = this;
Jack Yu1a2fc352017-07-14 17:14:37 -0700313 mSettingsObserver = new SettingsObserver(context, mHandler);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700314 }
315
316 public void onCreate() {
317 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
318
319 ContentResolver resolver = getContentResolver();
320
321 // Cache the "voice capable" flag.
322 // This flag currently comes from a resource (which is
323 // overrideable on a per-product basis):
Michele87262742020-01-16 12:23:53 -0800324 sVoiceCapable = ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE))
325 .isVoiceCapable();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700326 // ...but this might eventually become a PackageManager "system
327 // feature" instead, in which case we'd do something like:
328 // sVoiceCapable =
329 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
330
Stuart Scottdcf40a92014-12-09 10:45:01 -0800331 if (mCM == null) {
Nathan Haroldf9df6ea2019-03-08 11:54:22 -0800332 // Initialize AnomalyReporter early so that it can be used
333 AnomalyReporter.initialize(this);
Nathan Harold0db5c5e2019-01-22 20:18:56 -0800334
Youming Ye47a6adc2018-11-19 15:33:36 -0800335 // Inject telephony component factory if configured using other jars.
336 XmlResourceParser parser = getResources().getXml(R.xml.telephony_injection);
337 TelephonyComponentFactory.getInstance().injectTheComponentFactory(parser);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338 // Initialize the telephony framework
339 PhoneFactory.makeDefaultPhones(this);
340
Brad Ebinger05f52c22019-12-05 13:03:21 -0800341 // Only bring up ImsResolver if the device supports having an IMS stack.
342 if (getPackageManager().hasSystemFeature(
343 PackageManager.FEATURE_TELEPHONY_IMS)) {
344 // Get the package name of the default IMS implementation.
345 String defaultImsMmtelPackage = getResources().getString(
346 R.string.config_ims_mmtel_package);
347 String defaultImsRcsPackage = getResources().getString(
348 R.string.config_ims_rcs_package);
349 mImsResolver = new ImsResolver(this, defaultImsMmtelPackage,
350 defaultImsRcsPackage, PhoneFactory.getPhones().length);
351 mImsResolver.initialize();
352 }
353
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354 // Start TelephonyDebugService After the default phone is created.
355 Intent intent = new Intent(this, TelephonyDebugService.class);
356 startService(intent);
357
358 mCM = CallManager.getInstance();
Stuart Scottdcf40a92014-12-09 10:45:01 -0800359 for (Phone phone : PhoneFactory.getPhones()) {
360 mCM.registerPhone(phone);
Stuart Scottdcf40a92014-12-09 10:45:01 -0800361 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362
363 // Create the NotificationMgr singleton, which is used to display
364 // status bar icons and control other status bar behavior.
365 notificationMgr = NotificationMgr.init(this);
366
Brad Ebinger3fa43462016-04-12 16:06:48 -0700367 // If PhoneGlobals has crashed and is being restarted, then restart.
368 mHandler.sendEmptyMessage(EVENT_RESTART_SIP);
369
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700370 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
371 cdmaPhoneCallState = new CdmaPhoneCallState();
372 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374 // before registering for phone state changes
375 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
376 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
377 // lock used to keep the processor awake, when we don't care for the display.
378 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
379 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380
381 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
382
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383 // Create the CallerInfoCache singleton, which remembers custom ring tone and
384 // send-to-voicemail settings.
385 //
386 // The asynchronous caching will start just after this call.
387 callerInfoCache = CallerInfoCache.init(this);
388
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800389 phoneMgr = PhoneInterfaceManager.init(this);
Santos Cordon406c0342013-08-28 00:07:47 -0700390
James.cf Linaf3183c2019-10-24 00:59:00 +0800391 imsRcsController = ImsRcsController.init(this);
392
James.cf Linc9f35a42020-01-15 02:35:22 +0800393 if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
Brad Ebingera68a4972020-01-30 17:31:23 -0800394 mTelephonyRcsService = new TelephonyRcsService(this,
395 PhoneFactory.getPhones().length);
396 mTelephonyRcsService.initialize();
James.cf Linc9f35a42020-01-15 02:35:22 +0800397 imsRcsController.setRcsService(mTelephonyRcsService);
398 }
399
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800400 configLoader = CarrierConfigLoader.init(this);
401
Jack Yu1a2fc352017-07-14 17:14:37 -0700402 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700403 // asynchronous events from the telephony layer (like
404 // launching the incoming-call UI when an incoming call comes
405 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800406 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700407
Stuart Scottdcf40a92014-12-09 10:45:01 -0800408 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409
410 // register for MMI/USSD
411 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
412
Qiong Liucc3fe812019-09-23 15:25:44 +0800413 // Initialize cell status using current airplane mode.
414 handleAirplaneModeChange(this, Settings.Global.getInt(getContentResolver(),
415 Settings.Global.AIRPLANE_MODE_ON, AIRPLANE_OFF));
416
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417 // Register for misc other intent broadcasts.
418 IntentFilter intentFilter =
419 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700420 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
421 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
422 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
423 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700424 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
425 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700426 registerReceiver(mReceiver, intentFilter);
427
Brad Ebinger533c6c12017-08-02 11:38:48 -0700428 IntentFilter sipIntentFilter = new IntentFilter(Intent.ACTION_BOOT_COMPLETED);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700429 sipIntentFilter.addAction(SipManager.ACTION_SIP_SERVICE_UP);
430 sipIntentFilter.addAction(SipManager.ACTION_SIP_CALL_OPTION_CHANGED);
Grace Jiab95592a2020-01-15 14:12:24 -0800431 sipIntentFilter.addAction(SipManager.ACTION_SIP_REMOVE_PROFILE);
Brad Ebinger28626122017-08-10 14:13:35 -0700432 registerReceiver(mSipReceiver, sipIntentFilter);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700433
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700434 mCarrierVvmPackageInstalledReceiver.register(this);
435
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700436 //set the default values for the preferences in the phone.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700437 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700438 }
439
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700440 // XXX pre-load the SimProvider so that it's ready
441 resolver.getType(Uri.parse("content://icc/adn"));
442
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700443 // TODO: Register for Cdma Information Records
444 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
445
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700446 // Read HAC settings and configure audio hardware
447 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800448 int hac = android.provider.Settings.System.getInt(
449 getContentResolver(),
450 android.provider.Settings.System.HEARING_AID,
451 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700452 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Jordan Liuf71aeef2019-08-21 11:46:09 -0700453 audioManager.setParameters(
454 SettingsConstants.HAC_KEY + "=" + (hac == SettingsConstants.HAC_ENABLED
455 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700456 }
Santos Cordonff506f52013-11-21 19:13:19 -0800457 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700458
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700459 /**
460 * Returns the singleton instance of the PhoneApp.
461 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800462 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700463 if (sMe == null) {
464 throw new IllegalStateException("No PhoneGlobals here!");
465 }
466 return sMe;
467 }
468
469 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800470 * Returns the default phone.
471 *
Andrew Lee385019f2014-11-24 14:19:50 -0800472 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700473 */
Andrew Lee83383e42014-10-31 12:42:28 -0700474 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800475 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700476 }
477
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800478 public static Phone getPhone(int subId) {
479 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800480 }
481
Brad Ebinger05f52c22019-12-05 13:03:21 -0800482 public ImsResolver getImsResolver() {
483 return mImsResolver;
484 }
485
Santos Cordonde10b752013-09-19 04:11:33 -0700486 /* package */ CallManager getCallManager() {
487 return mCM;
488 }
489
Chris Manton4e9fa912015-06-19 11:26:57 -0700490 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800491 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700492 }
493
Chris Manton4e9fa912015-06-19 11:26:57 -0700494 public PersistableBundle getCarrierConfigForSubId(int subId) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -0800495 return configLoader.getConfigForSubIdWithFeature(subId, getOpPackageName(), null);
Junda Liu605148f2015-04-28 15:23:40 -0700496 }
497
Jack Yu1a2fc352017-07-14 17:14:37 -0700498 private void registerSettingsObserver() {
499 mSettingsObserver.unobserve();
500 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
501 String mobileDataSetting = Settings.Global.MOBILE_DATA;
502 if (TelephonyManager.getDefault().getSimCount() > 1) {
503 int subId = mDefaultDataSubId;
504 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
505 dataRoamingSetting += subId;
506 mobileDataSetting += subId;
507 }
508 }
509
510 // Listen for user data roaming setting changed event
511 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
512 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
513
514 // Listen for mobile data setting changed event
515 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
516 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
517 }
518
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700519 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700520 * Sets the activity responsible for un-PUK-blocking the device
521 * so that we may close it when we receive a positive result.
522 * mPUKEntryActivity is also used to indicate to the device that
523 * we are trying to un-PUK-lock the phone. In other words, iff
524 * it is NOT null, then we are trying to unlock and waiting for
525 * the SIM to move to READY state.
526 *
527 * @param activity is the activity to close when PUK has
528 * finished unlocking. Can be set to null to indicate the unlock
529 * or SIM READYing process is over.
530 */
531 void setPukEntryActivity(Activity activity) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700532 Log.i(LOG_TAG, "setPukEntryActivity - set to " + (activity == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700533 mPUKEntryActivity = activity;
534 }
535
536 Activity getPUKEntryActivity() {
537 return mPUKEntryActivity;
538 }
539
540 /**
541 * Sets the dialog responsible for notifying the user of un-PUK-
542 * blocking - SIM READYing progress, so that we may dismiss it
543 * when we receive a positive result.
544 *
545 * @param dialog indicates the progress dialog informing the user
546 * of the state of the device. Dismissed upon completion of
547 * READYing process
548 */
549 void setPukEntryProgressDialog(ProgressDialog dialog) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700550 Log.i(LOG_TAG, "setPukEntryProgressDialog - set to "
551 + (dialog == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700552 mPUKEntryProgressDialog = dialog;
553 }
554
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700555 KeyguardManager getKeyguardManager() {
556 return mKeyguardManager;
557 }
558
559 private void onMMIComplete(AsyncResult r) {
560 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
561 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800562 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700563 }
564
fionaxu80126972017-02-01 17:01:26 -0800565 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700566 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700567 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700568 }
569
Chris Mantona09f3632016-02-09 14:48:42 -0800570 private void handleAirplaneModeChange(Context context, int newMode) {
571 int cellState = Settings.Global.getInt(context.getContentResolver(),
572 Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
573 boolean isAirplaneNewlyOn = (newMode == 1);
574 switch (cellState) {
575 case PhoneConstants.CELL_OFF_FLAG:
576 // Airplane mode does not affect the cell radio if user
577 // has turned it off.
578 break;
579 case PhoneConstants.CELL_ON_FLAG:
580 maybeTurnCellOff(context, isAirplaneNewlyOn);
581 break;
582 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
583 maybeTurnCellOn(context, isAirplaneNewlyOn);
584 break;
585 }
Hall Liu7f56e1a2019-07-10 14:41:14 -0700586 for (Phone phone : PhoneFactory.getPhones()) {
587 phone.getServiceStateTracker().onAirplaneModeChanged(isAirplaneNewlyOn);
588 }
Chris Mantona09f3632016-02-09 14:48:42 -0800589 }
590
591 /*
592 * Returns true if the radio must be turned off when entering airplane mode.
593 */
594 private boolean isCellOffInAirplaneMode(Context context) {
595 String airplaneModeRadios = Settings.Global.getString(context.getContentResolver(),
596 Settings.Global.AIRPLANE_MODE_RADIOS);
597 return airplaneModeRadios == null
598 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
599 }
600
601 private void setRadioPowerOff(Context context) {
602 Log.i(LOG_TAG, "Turning radio off - airplane");
603 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
Eric Erfanian945409f2018-02-21 19:26:15 +0000604 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Meng Wang61307622019-10-23 14:08:43 -0700605 TelephonyProperties.airplane_mode_on(true); // true means int value 1
Chris Mantona09f3632016-02-09 14:48:42 -0800606 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
607 PhoneUtils.setRadioPower(false);
608 }
609
610 private void setRadioPowerOn(Context context) {
611 Log.i(LOG_TAG, "Turning radio on - airplane");
612 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
613 PhoneConstants.CELL_ON_FLAG);
614 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT,
615 1);
Meng Wang61307622019-10-23 14:08:43 -0700616 TelephonyProperties.airplane_mode_on(false); // false means int value 0
Chris Mantona09f3632016-02-09 14:48:42 -0800617 PhoneUtils.setRadioPower(true);
618 }
619
620 private void maybeTurnCellOff(Context context, boolean isAirplaneNewlyOn) {
621 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700622 // If we are trying to turn off the radio, make sure there are no active
623 // emergency calls. If there are, switch airplane mode back to off.
Tyler Gunn900d8fd2018-09-21 09:22:12 -0700624 TelecomManager tm = (TelecomManager) context.getSystemService(TELECOM_SERVICE);
625
626 if (tm != null && tm.isInEmergencyCall()) {
Santos Cordone18902f2016-03-22 17:16:04 -0700627 // Switch airplane mode back to off.
Jordan Liu0e819b12019-08-28 15:33:05 -0700628 ConnectivityManager cm =
629 (ConnectivityManager) context.getSystemService(CONNECTIVITY_SERVICE);
630 cm.setAirplaneMode(false);
Santos Cordone18902f2016-03-22 17:16:04 -0700631 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
632 .show();
633 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Chris Mantona09f3632016-02-09 14:48:42 -0800634 } else if (isCellOffInAirplaneMode(context)) {
635 setRadioPowerOff(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700636 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800637 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700638 }
Chris Mantona09f3632016-02-09 14:48:42 -0800639 }
640 }
641
642 private void maybeTurnCellOn(Context context, boolean isAirplaneNewlyOn) {
643 if (!isAirplaneNewlyOn) {
644 setRadioPowerOn(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700645 }
646 }
647
Santos Cordon593ab382013-08-06 21:58:23 -0700648 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700649 * Receiver for misc intent broadcasts the Phone app cares about.
650 */
651 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
652 @Override
653 public void onReceive(Context context, Intent intent) {
654 String action = intent.getAction();
655 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Santos Cordone18902f2016-03-22 17:16:04 -0700656 int airplaneMode = Settings.Global.getInt(getContentResolver(),
657 Settings.Global.AIRPLANE_MODE_ON, AIRPLANE_OFF);
658 // Treat any non-OFF values as ON.
659 if (airplaneMode != AIRPLANE_OFF) {
660 airplaneMode = AIRPLANE_ON;
661 }
Chris Mantona09f3632016-02-09 14:48:42 -0800662 handleAirplaneModeChange(context, airplaneMode);
Amit Mahajanf5d92c82018-11-02 17:44:40 -0700663 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
664 // re-register as it may be a new IccCard
665 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
666 SubscriptionManager.INVALID_PHONE_INDEX);
667 if (SubscriptionManager.isValidPhoneId(phoneId)) {
668 PhoneUtils.unregisterIccStatus(mHandler, phoneId);
669 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED, phoneId);
670 }
Nazish Tabassum160d2112019-12-23 17:31:33 +0530671 String iccStatus = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
672 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
673 new EventSimStateChangedBag(phoneId, iccStatus)));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700674 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
675 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800676 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
677 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700678 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
679 handleServiceStateChanged(intent);
680 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530681 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530682 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530683 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
684 if (phoneInEcm != null) {
685 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
686 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
687 // Start Emergency Callback Mode service
Daniel Bright30efde42020-01-09 22:11:15 -0800688 if (intent.getBooleanExtra(
689 TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530690 context.startService(new Intent(context,
691 EmergencyCallbackModeService.class));
692 } else {
693 phoneInEcm = null;
694 }
695 } else {
696 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
697 // on a device that doesn't support ECM in the first place.
698 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
699 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
700 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700701 }
702 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530703 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700704 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700705 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
706 // Roaming status could be overridden by carrier config, so we need to update it.
707 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
708 updateDataRoamingStatus();
chen xubaf9fe52019-07-02 17:28:24 -0700709 updateLimitedSimFunctionForDualSim();
Jack Yu1a2fc352017-07-14 17:14:37 -0700710 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
711 // We also need to pay attention when default data subscription changes.
712 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
713 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
714 registerSettingsObserver();
715 Phone phone = getPhone(mDefaultDataSubId);
716 if (phone != null) {
717 updateDataRoamingStatus();
718 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700719 }
720 }
721 }
722
Brad Ebinger28626122017-08-10 14:13:35 -0700723 private class SipReceiver extends BroadcastReceiver {
724
725 @Override
726 public void onReceive(Context context, Intent intent) {
727 String action = intent.getAction();
728
729 SipAccountRegistry sipAccountRegistry = SipAccountRegistry.getInstance();
730 if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
731 SipUtil.startSipService();
732 } else if (action.equals(SipManager.ACTION_SIP_SERVICE_UP)
733 || action.equals(SipManager.ACTION_SIP_CALL_OPTION_CHANGED)) {
734 sipAccountRegistry.setup(context);
Grace Jiab95592a2020-01-15 14:12:24 -0800735 } else if (action.equals(SipManager.ACTION_SIP_REMOVE_PROFILE)) {
Brad Ebinger28626122017-08-10 14:13:35 -0700736 if (DBG) {
737 Log.d(LOG_TAG, "SIP_REMOVE_PHONE "
738 + intent.getStringExtra(SipManager.EXTRA_LOCAL_URI));
739 }
740 sipAccountRegistry.removeSipProfile(intent.getStringExtra(
741 SipManager.EXTRA_LOCAL_URI));
742 } else {
743 if (DBG) Log.d(LOG_TAG, "onReceive, action not processed: " + action);
744 }
745 }
746 }
747
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700748 private void handleServiceStateChanged(Intent intent) {
749 /**
750 * This used to handle updating EriTextWidgetProvider this routine
751 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
752 * be removed. But leaving just in case it might be needed in the near
753 * future.
754 */
755
Jack Yu1a2fc352017-07-14 17:14:37 -0700756 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700757 // If service just returned, start sending out the queued messages
Santos Cordonc593d002015-06-03 15:41:15 -0700758 Bundle extras = intent.getExtras();
759 if (extras != null) {
760 ServiceState ss = ServiceState.newFromBundle(extras);
761 if (ss != null) {
762 int state = ss.getState();
Jayachandran C2ef9a482017-05-12 22:07:47 -0700763 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
764 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
765 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -0700766
767 if (VDBG) {
768 Log.v(LOG_TAG, "subId=" + subId + ",mDefaultDataSubId="
769 + mDefaultDataSubId + ",ss roaming=" + ss.getDataRoaming());
770 }
771 if (subId == mDefaultDataSubId) {
772 updateDataRoamingStatus();
773 }
Santos Cordonc593d002015-06-03 15:41:15 -0700774 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700775 }
776 }
777
Jack Yu1a2fc352017-07-14 17:14:37 -0700778 /**
Jordan Liuff2ccd72019-07-23 15:54:41 -0700779 * @return whether or not we should show a notification when connecting to data roaming if the
780 * user has data roaming enabled
781 */
782 private boolean shouldShowDataConnectedRoaming(int subId) {
783 PersistableBundle config = getCarrierConfigForSubId(subId);
784 return config.getBoolean(CarrierConfigManager
785 .KEY_SHOW_DATA_CONNECTED_ROAMING_NOTIFICATION_BOOL);
786 }
787
788 /**
Jack Yu1a2fc352017-07-14 17:14:37 -0700789 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
790 * to notify the user so they can enable it through settings. Vise versa if the condition
791 * changes, we need to dismiss the notification.
792 */
793 private void updateDataRoamingStatus() {
794 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
795 Phone phone = getPhone(mDefaultDataSubId);
796 if (phone == null) {
797 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
798 return;
799 }
800
801 DataConnectionReasons reasons = new DataConnectionReasons();
Jack Yu311536f2018-11-26 11:20:48 -0800802 boolean dataAllowed = phone.isDataAllowed(ApnSetting.TYPE_DEFAULT, reasons);
Jack Yu1a2fc352017-07-14 17:14:37 -0700803 mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons);
804 if (VDBG) Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons);
Jordan Liuff2ccd72019-07-23 15:54:41 -0700805 if (!dataAllowed && reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED)) {
806 // No need to show it again if we never cancelled it explicitly.
807 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_DISCONNECTED) return;
Jack Yu1a2fc352017-07-14 17:14:37 -0700808 // If the only reason of no data is data roaming disabled, then we notify the user
809 // so the user can turn on data roaming.
Jordan Liuff2ccd72019-07-23 15:54:41 -0700810 mPrevRoamingNotification = ROAMING_NOTIFICATION_DISCONNECTED;
Jack Yu1a2fc352017-07-14 17:14:37 -0700811 Log.d(LOG_TAG, "Show roaming disconnected notification");
Jordan Liuff2ccd72019-07-23 15:54:41 -0700812 mDataRoamingNotifLog.log("Show roaming off.");
Pengquan Meng8783d932017-10-16 14:57:40 -0700813 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_DISCONNECTED);
814 msg.arg1 = mDefaultDataSubId;
815 msg.sendToTarget();
Jordan Liuff2ccd72019-07-23 15:54:41 -0700816 } else if (dataAllowed && dataIsNowRoaming(mDefaultDataSubId)
817 && shouldShowDataConnectedRoaming(mDefaultDataSubId)) {
818 // No need to show it again if we never cancelled it explicitly, or carrier config
819 // indicates this is not needed.
820 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_CONNECTED) return;
821 mPrevRoamingNotification = ROAMING_NOTIFICATION_CONNECTED;
822 Log.d(LOG_TAG, "Show roaming connected notification");
823 mDataRoamingNotifLog.log("Show roaming on.");
824 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_CONNECTED);
825 msg.arg1 = mDefaultDataSubId;
826 msg.sendToTarget();
827 } else if (mPrevRoamingNotification != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
828 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
829 // is not the only data disable reason. In this case we dismiss the notification we
830 // showed earlier.
831 mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
832 Log.d(LOG_TAG, "Dismiss roaming notification");
Jack Yu1a2fc352017-07-14 17:14:37 -0700833 mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed + ", reasons=" + reasons);
834 mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
835 }
836 }
837
Jordan Liuff2ccd72019-07-23 15:54:41 -0700838 /**
839 *
840 * @param subId to check roaming on
841 * @return whether we have transitioned to dataRoaming
842 */
843 private boolean dataIsNowRoaming(int subId) {
844 return getPhone(subId).getServiceState().getDataRoaming();
845 }
846
chen xubaf9fe52019-07-02 17:28:24 -0700847 private void updateLimitedSimFunctionForDualSim() {
848 if (DBG) Log.d(LOG_TAG, "updateLimitedSimFunctionForDualSim");
849 // check conditions to display limited SIM function notification under dual SIM
850 SubscriptionManager subMgr = (SubscriptionManager) getSystemService(
851 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
852 List<SubscriptionInfo> subList = subMgr.getActiveSubscriptionInfoList(false);
853 if (subList != null && subList.size() > 1) {
854 CarrierConfigManager configMgr = (CarrierConfigManager)
855 getSystemService(Context.CARRIER_CONFIG_SERVICE);
856 for (SubscriptionInfo info : subList) {
857 PersistableBundle b = configMgr.getConfigForSubId(info.getSubscriptionId());
858 if (b != null) {
859 if (b.getBoolean(CarrierConfigManager
860 .KEY_LIMITED_SIM_FUNCTION_NOTIFICATION_FOR_DSDS_BOOL)) {
861 notificationMgr.showLimitedSimFunctionWarningNotification(
862 info.getSubscriptionId(),
863 info.getDisplayName().toString());
864 } else {
865 notificationMgr.dismissLimitedSimFunctionWarningNotification(
866 info.getSubscriptionId());
867 }
868 }
869 }
870 } else {
871 // cancel notifications for all subs
872 notificationMgr.dismissLimitedSimFunctionWarningNotification(
873 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
874 }
875 notificationMgr.dismissLimitedSimFunctionWarningNotificationForInactiveSubs();
876
877 }
878
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530879 public Phone getPhoneInEcm() {
880 return phoneInEcm;
881 }
882
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700883 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800884 * Triggers a refresh of the message waiting (voicemail) indicator.
885 *
886 * @param subId the subscription id we should refresh the notification for.
887 */
888 public void refreshMwiIndicator(int subId) {
889 notificationMgr.refreshMwi(subId);
890 }
891
892 /**
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700893 * Called when the network selection on the subscription {@code subId} is changed by the user.
894 *
895 * @param subId the subscription id.
896 */
897 public void onNetworkSelectionChanged(int subId) {
898 Phone phone = getPhone(subId);
899 if (phone != null) {
900 notificationMgr.updateNetworkSelection(phone.getServiceState().getState(), subId);
901 } else {
902 Log.w(LOG_TAG, "onNetworkSelectionChanged on null phone, subId: " + subId);
903 }
904 }
905
906 /**
Jack Yu1a2fc352017-07-14 17:14:37 -0700907 * Dump the state of the object, add calls to other objects as desired.
908 *
909 * @param fd File descriptor
910 * @param printWriter Print writer
911 * @param args Arguments
912 */
913 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
914 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
915 pw.println("------- PhoneGlobals -------");
916 pw.increaseIndent();
Jordan Liuff2ccd72019-07-23 15:54:41 -0700917 pw.println("mPrevRoamingNotification=" + mPrevRoamingNotification);
Jack Yu1a2fc352017-07-14 17:14:37 -0700918 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
919 pw.println("mDataRoamingNotifLog:");
Keun young Parkdebb8532019-05-30 16:35:27 -0700920 pw.println("isSmsCapable=" + TelephonyManager.from(this).isSmsCapable());
Jack Yu1a2fc352017-07-14 17:14:37 -0700921 pw.increaseIndent();
922 mDataRoamingNotifLog.dump(fd, pw, args);
923 pw.decreaseIndent();
Brad Ebinger05f52c22019-12-05 13:03:21 -0800924 pw.println("ImsResolver:");
925 pw.increaseIndent();
926 try {
927 if (mImsResolver != null) mImsResolver.dump(fd, pw, args);
928 } catch (Exception e) {
929 e.printStackTrace();
930 }
931 pw.decreaseIndent();
Brad Ebingera68a4972020-01-30 17:31:23 -0800932 pw.println("RcsService:");
933 try {
934 if (mTelephonyRcsService != null) mTelephonyRcsService.dump(fd, pw, args);
935 } catch (Exception e) {
936 e.printStackTrace();
937 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700938 pw.decreaseIndent();
939 pw.println("------- End PhoneGlobals -------");
940 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700941}