blob: 03d5afe384c2608a36bbfb5e2a4c74715081651e [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
Brad Ebingere3ae65a2020-09-11 12:45:11 -070058import com.android.ims.ImsFeatureBinderRepository;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import com.android.internal.telephony.CallManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import com.android.internal.telephony.IccCardConstants;
61import com.android.internal.telephony.MmiCode;
62import com.android.internal.telephony.Phone;
63import com.android.internal.telephony.PhoneConstants;
64import com.android.internal.telephony.PhoneFactory;
Jack Yu1a2fc352017-07-14 17:14:37 -070065import com.android.internal.telephony.SettingsObserver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066import com.android.internal.telephony.TelephonyCapabilities;
Youming Ye47a6adc2018-11-19 15:33:36 -080067import com.android.internal.telephony.TelephonyComponentFactory;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068import com.android.internal.telephony.TelephonyIntents;
Jack Yu1a2fc352017-07-14 17:14:37 -070069import com.android.internal.telephony.dataconnection.DataConnectionReasons;
70import com.android.internal.telephony.dataconnection.DataConnectionReasons.DataDisallowedReasonType;
Brad Ebinger05f52c22019-12-05 13:03:21 -080071import com.android.internal.telephony.ims.ImsResolver;
Jack Yu1a2fc352017-07-14 17:14:37 -070072import com.android.internal.util.IndentingPrintWriter;
Andrew Leefb7f92e2015-02-26 16:23:32 -080073import com.android.phone.settings.SettingsConstants;
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -070074import com.android.phone.vvm.CarrierVvmPackageInstalledReceiver;
James.cf Linc9f35a42020-01-15 02:35:22 +080075import com.android.services.telephony.rcs.TelephonyRcsService;
Brad Ebinger28626122017-08-10 14:13:35 -070076import com.android.services.telephony.sip.SipAccountRegistry;
Brad Ebinger3fa43462016-04-12 16:06:48 -070077import com.android.services.telephony.sip.SipUtil;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070078
Jack Yu1a2fc352017-07-14 17:14:37 -070079import java.io.FileDescriptor;
80import java.io.PrintWriter;
Jordan Liuff2ccd72019-07-23 15:54:41 -070081import java.lang.annotation.Retention;
82import java.lang.annotation.RetentionPolicy;
chen xubaf9fe52019-07-02 17:28:24 -070083import java.util.List;
Jack Yu1a2fc352017-07-14 17:14:37 -070084
Santos Cordon7d4ddf62013-07-10 11:58:08 -070085/**
86 * Global state for the telephony subsystem when running in the primary
87 * phone process.
88 */
Sailesh Nepalbf900542014-07-15 16:18:32 -070089public class PhoneGlobals extends ContextWrapper {
Jack Yu1a2fc352017-07-14 17:14:37 -070090 public static final String LOG_TAG = "PhoneGlobals";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091
92 /**
93 * Phone app-wide debug level:
94 * 0 - no debug logging
95 * 1 - normal debug logging if ro.debuggable is set (which is true in
96 * "eng" and "userdebug" builds but not "user" builds)
97 * 2 - ultra-verbose debug logging
98 *
99 * Most individual classes in the phone app have a local DBG constant,
100 * typically set to
101 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
102 * or else
103 * (PhoneApp.DBG_LEVEL >= 2)
104 * depending on the desired verbosity.
105 *
106 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
107 */
Andrew Lee88b51e22014-10-29 15:48:51 -0700108 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700109
110 private static final boolean DBG =
111 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
112 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
113
114 // Message codes; see mHandler below.
115 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
Jordan Liuff2ccd72019-07-23 15:54:41 -0700118 private static final int EVENT_DATA_ROAMING_CONNECTED = 11;
119 private static final int EVENT_DATA_ROAMING_OK = 12;
120 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 13;
121 private static final int EVENT_RESTART_SIP = 14;
122 private static final int EVENT_DATA_ROAMING_SETTINGS_CHANGED = 15;
123 private static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED = 16;
Lei Liu863eac02020-06-24 20:12:55 +0800124 private static final int EVENT_CARRIER_CONFIG_CHANGED = 17;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700125
126 // The MMI codes are also used by the InCallScreen.
127 public static final int MMI_INITIATE = 51;
128 public static final int MMI_COMPLETE = 52;
129 public static final int MMI_CANCEL = 53;
130 // Don't use message codes larger than 99 here; those are reserved for
131 // the individual Activities of the Phone UI.
132
Santos Cordone18902f2016-03-22 17:16:04 -0700133 public static final int AIRPLANE_ON = 1;
134 public static final int AIRPLANE_OFF = 0;
135
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136 /**
137 * Allowable values for the wake lock code.
138 * SLEEP means the device can be put to sleep.
139 * PARTIAL means wake the processor, but we display can be kept off.
140 * FULL means wake both the processor and the display.
141 */
142 public enum WakeState {
143 SLEEP,
144 PARTIAL,
145 FULL
146 }
147
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700148 private static PhoneGlobals sMe;
149
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700150 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700151 CallNotifier notifier;
152 CallerInfoCache callerInfoCache;
Santos Cordon63a84242013-07-23 13:32:52 -0700153 NotificationMgr notificationMgr;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800154 ImsResolver mImsResolver;
James.cf Linc9f35a42020-01-15 02:35:22 +0800155 TelephonyRcsService mTelephonyRcsService;
Andrew Lee9431b832015-03-09 18:46:45 -0700156 public PhoneInterfaceManager phoneMgr;
James.cf Linaf3183c2019-10-24 00:59:00 +0800157 public ImsRcsController imsRcsController;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800158 CarrierConfigLoader configLoader;
Santos Cordon63a84242013-07-23 13:32:52 -0700159
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530160 private Phone phoneInEcm;
Santos Cordon63a84242013-07-23 13:32:52 -0700161
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162 static boolean sVoiceCapable = true;
163
Santos Cordonc593d002015-06-03 15:41:15 -0700164 // TODO: Remove, no longer used.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165 CdmaPhoneCallState cdmaPhoneCallState;
166
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700167 // The currently-active PUK entry activity and progress dialog.
168 // Normally, these are the Emergency Dialer and the subsequent
169 // progress dialog. null if there is are no such objects in
170 // the foreground.
171 private Activity mPUKEntryActivity;
172 private ProgressDialog mPUKEntryProgressDialog;
173
Jordan Liuff2ccd72019-07-23 15:54:41 -0700174 /** @hide */
175 @Retention(RetentionPolicy.SOURCE)
176 @IntDef(prefix = {"ROAMING_NOTIFICATION_"},
177 value = {
178 ROAMING_NOTIFICATION_NO_NOTIFICATION,
179 ROAMING_NOTIFICATION_CONNECTED,
180 ROAMING_NOTIFICATION_DISCONNECTED})
181 public @interface RoamingNotification {}
182
183 private static final int ROAMING_NOTIFICATION_NO_NOTIFICATION = 0;
184 private static final int ROAMING_NOTIFICATION_CONNECTED = 1;
185 private static final int ROAMING_NOTIFICATION_DISCONNECTED = 2;
186
187 @RoamingNotification
188 private int mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
Jack Yu953f9352017-05-18 14:41:06 -0700189
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700190 private WakeState mWakeState = WakeState.SLEEP;
191
192 private PowerManager mPowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193 private PowerManager.WakeLock mWakeLock;
194 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196
Jack Yu1a2fc352017-07-14 17:14:37 -0700197 private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
198 private final LocalLog mDataRoamingNotifLog = new LocalLog(50);
199
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700200 // Broadcast receiver for various intent broadcasts (see onCreate())
201 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
Brad Ebinger533c6c12017-08-02 11:38:48 -0700202 // Broadcast receiver for SIP based intents (see onCreate())
Brad Ebinger28626122017-08-10 14:13:35 -0700203 private final SipReceiver mSipReceiver = new SipReceiver();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700204
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700205 private final CarrierVvmPackageInstalledReceiver mCarrierVvmPackageInstalledReceiver =
206 new CarrierVvmPackageInstalledReceiver();
207
Jack Yu1a2fc352017-07-14 17:14:37 -0700208 private final SettingsObserver mSettingsObserver;
209
Nazish Tabassum160d2112019-12-23 17:31:33 +0530210 private static class EventSimStateChangedBag {
211 final int mPhoneId;
212 final String mIccStatus;
213
214 EventSimStateChangedBag(int phoneId, String iccStatus) {
215 mPhoneId = phoneId;
216 mIccStatus = iccStatus;
217 }
218 }
219
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700220 Handler mHandler = new Handler() {
221 @Override
222 public void handleMessage(Message msg) {
223 PhoneConstants.State phoneState;
Jack Yu1a2fc352017-07-14 17:14:37 -0700224 if (VDBG) Log.v(LOG_TAG, "event=" + msg.what);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700225 switch (msg.what) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700226 // TODO: This event should be handled by the lock screen, just
227 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
228 case EVENT_SIM_NETWORK_LOCKED:
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700229 if (getCarrierConfig().getBoolean(
230 CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700231 // Some products don't have the concept of a "SIM network lock"
232 Log.i(LOG_TAG, "Ignoring EVENT_SIM_NETWORK_LOCKED event; "
Eric Erfanian945409f2018-02-21 19:26:15 +0000233 + "not showing 'SIM network unlock' PIN entry screen");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700234 } else {
235 // Normal case: show the "SIM network unlock" PIN entry screen.
236 // The user won't be able to do anything else until
237 // they enter a valid SIM network PIN.
238 Log.i(LOG_TAG, "show sim depersonal panel");
Biljana Maneva96291112018-01-30 13:12:59 +0800239 Phone phone = (Phone) ((AsyncResult) msg.obj).userObj;
Nazish Tabassum160d2112019-12-23 17:31:33 +0530240 int subType = (Integer)((AsyncResult)msg.obj).result;
241 IccNetworkDepersonalizationPanel.showDialog(phone, subType);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700242 }
243 break;
244
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700245 case EVENT_DATA_ROAMING_DISCONNECTED:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700246 notificationMgr.showDataRoamingNotification(msg.arg1, false);
247 break;
248
249 case EVENT_DATA_ROAMING_CONNECTED:
250 notificationMgr.showDataRoamingNotification(msg.arg1, true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700251 break;
252
253 case EVENT_DATA_ROAMING_OK:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700254 notificationMgr.hideDataRoamingNotification();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700255 break;
256
257 case MMI_COMPLETE:
258 onMMIComplete((AsyncResult) msg.obj);
259 break;
260
261 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800262 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700263 break;
264
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700265 case EVENT_SIM_STATE_CHANGED:
266 // Marks the event where the SIM goes into ready state.
267 // Right now, this is only used for the PUK-unlocking
268 // process.
Nazish Tabassum160d2112019-12-23 17:31:33 +0530269 EventSimStateChangedBag bag = (EventSimStateChangedBag)msg.obj;
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700270 if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(bag.mIccStatus)
Nazish Tabassum59126a92020-07-03 21:44:49 +0530271 || IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(bag.mIccStatus)
272 || IccCardConstants.INTENT_VALUE_ICC_NOT_READY.equals(bag.mIccStatus)
273 || IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(bag.mIccStatus)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700274 // when the right event is triggered and there
275 // are UI objects in the foreground, we close
276 // them to display the lock panel.
277 if (mPUKEntryActivity != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700278 Log.i(LOG_TAG, "Dismiss puk entry activity");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700279 mPUKEntryActivity.finish();
280 mPUKEntryActivity = null;
281 }
282 if (mPUKEntryProgressDialog != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700283 Log.i(LOG_TAG, "Dismiss puk progress dialog");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700284 mPUKEntryProgressDialog.dismiss();
285 mPUKEntryProgressDialog = null;
286 }
Nazish Tabassum59126a92020-07-03 21:44:49 +0530287 Log.i(LOG_TAG, "Dismissing depersonal panel" + (bag.mIccStatus));
Nazish Tabassum160d2112019-12-23 17:31:33 +0530288 IccNetworkDepersonalizationPanel.dialogDismiss(bag.mPhoneId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700289 }
290 break;
291
292 case EVENT_UNSOL_CDMA_INFO_RECORD:
293 //TODO: handle message here;
294 break;
Brad Ebinger3fa43462016-04-12 16:06:48 -0700295 case EVENT_RESTART_SIP:
296 // This should only run if the Phone process crashed and was restarted. We do
297 // not want this running if the device is still in the FBE encrypted state.
Brad Ebinger28626122017-08-10 14:13:35 -0700298 // This is the same procedure that is triggered in the SipIncomingCallReceiver
Brad Ebinger3fa43462016-04-12 16:06:48 -0700299 // upon BOOT_COMPLETED.
Meng Wangc04cd2d2019-10-04 12:00:06 -0700300 UserManager userManager =
301 (UserManager) sMe.getSystemService(Context.USER_SERVICE);
Brad Ebinger3fa43462016-04-12 16:06:48 -0700302 if (userManager != null && userManager.isUserUnlocked()) {
303 SipUtil.startSipService();
304 }
305 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700306 case EVENT_DATA_ROAMING_SETTINGS_CHANGED:
307 case EVENT_MOBILE_DATA_SETTINGS_CHANGED:
308 updateDataRoamingStatus();
309 break;
Lei Liu863eac02020-06-24 20:12:55 +0800310 case EVENT_CARRIER_CONFIG_CHANGED:
311 int subId = (Integer) msg.obj;
312 // The voicemail number could be overridden by carrier config, so need to
313 // refresh the message waiting (voicemail) indicator.
314 refreshMwiIndicator(subId);
315 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700316 }
317 }
318 };
319
320 public PhoneGlobals(Context context) {
321 super(context);
322 sMe = this;
Jack Yu1a2fc352017-07-14 17:14:37 -0700323 mSettingsObserver = new SettingsObserver(context, mHandler);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700324 }
325
326 public void onCreate() {
327 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
328
329 ContentResolver resolver = getContentResolver();
330
331 // Cache the "voice capable" flag.
332 // This flag currently comes from a resource (which is
333 // overrideable on a per-product basis):
Michele87262742020-01-16 12:23:53 -0800334 sVoiceCapable = ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE))
335 .isVoiceCapable();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700336 // ...but this might eventually become a PackageManager "system
337 // feature" instead, in which case we'd do something like:
338 // sVoiceCapable =
339 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
340
Stuart Scottdcf40a92014-12-09 10:45:01 -0800341 if (mCM == null) {
Nathan Haroldf9df6ea2019-03-08 11:54:22 -0800342 // Initialize AnomalyReporter early so that it can be used
343 AnomalyReporter.initialize(this);
Nathan Harold0db5c5e2019-01-22 20:18:56 -0800344
Youming Ye47a6adc2018-11-19 15:33:36 -0800345 // Inject telephony component factory if configured using other jars.
346 XmlResourceParser parser = getResources().getXml(R.xml.telephony_injection);
347 TelephonyComponentFactory.getInstance().injectTheComponentFactory(parser);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348 // Initialize the telephony framework
349 PhoneFactory.makeDefaultPhones(this);
350
Brad Ebinger05f52c22019-12-05 13:03:21 -0800351 // Only bring up ImsResolver if the device supports having an IMS stack.
352 if (getPackageManager().hasSystemFeature(
353 PackageManager.FEATURE_TELEPHONY_IMS)) {
354 // Get the package name of the default IMS implementation.
355 String defaultImsMmtelPackage = getResources().getString(
356 R.string.config_ims_mmtel_package);
357 String defaultImsRcsPackage = getResources().getString(
358 R.string.config_ims_rcs_package);
359 mImsResolver = new ImsResolver(this, defaultImsMmtelPackage,
Brad Ebingere3ae65a2020-09-11 12:45:11 -0700360 defaultImsRcsPackage, PhoneFactory.getPhones().length,
361 new ImsFeatureBinderRepository());
Brad Ebinger05f52c22019-12-05 13:03:21 -0800362 mImsResolver.initialize();
363 }
364
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365 // Start TelephonyDebugService After the default phone is created.
366 Intent intent = new Intent(this, TelephonyDebugService.class);
367 startService(intent);
368
369 mCM = CallManager.getInstance();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370
371 // Create the NotificationMgr singleton, which is used to display
372 // status bar icons and control other status bar behavior.
373 notificationMgr = NotificationMgr.init(this);
374
Brad Ebinger3fa43462016-04-12 16:06:48 -0700375 // If PhoneGlobals has crashed and is being restarted, then restart.
376 mHandler.sendEmptyMessage(EVENT_RESTART_SIP);
377
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700378 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
379 cdmaPhoneCallState = new CdmaPhoneCallState();
380 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382 // before registering for phone state changes
383 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
384 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
385 // lock used to keep the processor awake, when we don't care for the display.
386 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
387 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388
389 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
390
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700391 // Create the CallerInfoCache singleton, which remembers custom ring tone and
392 // send-to-voicemail settings.
393 //
394 // The asynchronous caching will start just after this call.
395 callerInfoCache = CallerInfoCache.init(this);
396
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800397 phoneMgr = PhoneInterfaceManager.init(this);
Santos Cordon406c0342013-08-28 00:07:47 -0700398
James.cf Linaf3183c2019-10-24 00:59:00 +0800399 imsRcsController = ImsRcsController.init(this);
400
James.cf Linc9f35a42020-01-15 02:35:22 +0800401 if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
Brad Ebingera68a4972020-01-30 17:31:23 -0800402 mTelephonyRcsService = new TelephonyRcsService(this,
403 PhoneFactory.getPhones().length);
404 mTelephonyRcsService.initialize();
James.cf Linc9f35a42020-01-15 02:35:22 +0800405 imsRcsController.setRcsService(mTelephonyRcsService);
406 }
407
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800408 configLoader = CarrierConfigLoader.init(this);
409
Jack Yu1a2fc352017-07-14 17:14:37 -0700410 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700411 // asynchronous events from the telephony layer (like
412 // launching the incoming-call UI when an incoming call comes
413 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800414 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415
Stuart Scottdcf40a92014-12-09 10:45:01 -0800416 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417
418 // register for MMI/USSD
419 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
420
Qiong Liucc3fe812019-09-23 15:25:44 +0800421 // Initialize cell status using current airplane mode.
422 handleAirplaneModeChange(this, Settings.Global.getInt(getContentResolver(),
423 Settings.Global.AIRPLANE_MODE_ON, AIRPLANE_OFF));
424
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700425 // Register for misc other intent broadcasts.
426 IntentFilter intentFilter =
427 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700428 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
429 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
430 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
431 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700432 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
433 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434 registerReceiver(mReceiver, intentFilter);
435
Brad Ebinger533c6c12017-08-02 11:38:48 -0700436 IntentFilter sipIntentFilter = new IntentFilter(Intent.ACTION_BOOT_COMPLETED);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700437 sipIntentFilter.addAction(SipManager.ACTION_SIP_SERVICE_UP);
438 sipIntentFilter.addAction(SipManager.ACTION_SIP_CALL_OPTION_CHANGED);
Grace Jiab95592a2020-01-15 14:12:24 -0800439 sipIntentFilter.addAction(SipManager.ACTION_SIP_REMOVE_PROFILE);
Brad Ebinger28626122017-08-10 14:13:35 -0700440 registerReceiver(mSipReceiver, sipIntentFilter);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700441
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700442 mCarrierVvmPackageInstalledReceiver.register(this);
443
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444 //set the default values for the preferences in the phone.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700446 }
447
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448 // XXX pre-load the SimProvider so that it's ready
449 resolver.getType(Uri.parse("content://icc/adn"));
450
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700451 // TODO: Register for Cdma Information Records
452 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
453
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700454 // Read HAC settings and configure audio hardware
455 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800456 int hac = android.provider.Settings.System.getInt(
457 getContentResolver(),
458 android.provider.Settings.System.HEARING_AID,
459 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700460 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Jordan Liuf71aeef2019-08-21 11:46:09 -0700461 audioManager.setParameters(
462 SettingsConstants.HAC_KEY + "=" + (hac == SettingsConstants.HAC_ENABLED
463 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700464 }
Santos Cordonff506f52013-11-21 19:13:19 -0800465 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700466
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700467 /**
468 * Returns the singleton instance of the PhoneApp.
469 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800470 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700471 if (sMe == null) {
472 throw new IllegalStateException("No PhoneGlobals here!");
473 }
474 return sMe;
475 }
476
477 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800478 * Returns the default phone.
479 *
Andrew Lee385019f2014-11-24 14:19:50 -0800480 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700481 */
Andrew Lee83383e42014-10-31 12:42:28 -0700482 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800483 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700484 }
485
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800486 public static Phone getPhone(int subId) {
487 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800488 }
489
Brad Ebinger05f52c22019-12-05 13:03:21 -0800490 public ImsResolver getImsResolver() {
491 return mImsResolver;
492 }
493
Santos Cordonde10b752013-09-19 04:11:33 -0700494 /* package */ CallManager getCallManager() {
495 return mCM;
496 }
497
Chris Manton4e9fa912015-06-19 11:26:57 -0700498 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800499 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700500 }
501
Chris Manton4e9fa912015-06-19 11:26:57 -0700502 public PersistableBundle getCarrierConfigForSubId(int subId) {
Philip P. Moltmann0079aae2020-03-05 16:24:02 -0800503 return configLoader.getConfigForSubIdWithFeature(subId, getOpPackageName(),
504 getAttributionTag());
Junda Liu605148f2015-04-28 15:23:40 -0700505 }
506
Jack Yu1a2fc352017-07-14 17:14:37 -0700507 private void registerSettingsObserver() {
508 mSettingsObserver.unobserve();
509 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
510 String mobileDataSetting = Settings.Global.MOBILE_DATA;
511 if (TelephonyManager.getDefault().getSimCount() > 1) {
512 int subId = mDefaultDataSubId;
513 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
514 dataRoamingSetting += subId;
515 mobileDataSetting += subId;
516 }
517 }
518
519 // Listen for user data roaming setting changed event
520 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
521 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
522
523 // Listen for mobile data setting changed event
524 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
525 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
526 }
527
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700528 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700529 * Sets the activity responsible for un-PUK-blocking the device
530 * so that we may close it when we receive a positive result.
531 * mPUKEntryActivity is also used to indicate to the device that
532 * we are trying to un-PUK-lock the phone. In other words, iff
533 * it is NOT null, then we are trying to unlock and waiting for
534 * the SIM to move to READY state.
535 *
536 * @param activity is the activity to close when PUK has
537 * finished unlocking. Can be set to null to indicate the unlock
538 * or SIM READYing process is over.
539 */
540 void setPukEntryActivity(Activity activity) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700541 Log.i(LOG_TAG, "setPukEntryActivity - set to " + (activity == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700542 mPUKEntryActivity = activity;
543 }
544
545 Activity getPUKEntryActivity() {
546 return mPUKEntryActivity;
547 }
548
549 /**
550 * Sets the dialog responsible for notifying the user of un-PUK-
551 * blocking - SIM READYing progress, so that we may dismiss it
552 * when we receive a positive result.
553 *
554 * @param dialog indicates the progress dialog informing the user
555 * of the state of the device. Dismissed upon completion of
556 * READYing process
557 */
558 void setPukEntryProgressDialog(ProgressDialog dialog) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700559 Log.i(LOG_TAG, "setPukEntryProgressDialog - set to "
560 + (dialog == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700561 mPUKEntryProgressDialog = dialog;
562 }
563
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700564 KeyguardManager getKeyguardManager() {
565 return mKeyguardManager;
566 }
567
568 private void onMMIComplete(AsyncResult r) {
569 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
570 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800571 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700572 }
573
fionaxu80126972017-02-01 17:01:26 -0800574 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700575 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700576 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700577 }
578
Chris Mantona09f3632016-02-09 14:48:42 -0800579 private void handleAirplaneModeChange(Context context, int newMode) {
580 int cellState = Settings.Global.getInt(context.getContentResolver(),
581 Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
582 boolean isAirplaneNewlyOn = (newMode == 1);
583 switch (cellState) {
584 case PhoneConstants.CELL_OFF_FLAG:
585 // Airplane mode does not affect the cell radio if user
586 // has turned it off.
587 break;
588 case PhoneConstants.CELL_ON_FLAG:
589 maybeTurnCellOff(context, isAirplaneNewlyOn);
590 break;
591 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
592 maybeTurnCellOn(context, isAirplaneNewlyOn);
593 break;
594 }
Hall Liu7f56e1a2019-07-10 14:41:14 -0700595 for (Phone phone : PhoneFactory.getPhones()) {
596 phone.getServiceStateTracker().onAirplaneModeChanged(isAirplaneNewlyOn);
597 }
Chris Mantona09f3632016-02-09 14:48:42 -0800598 }
599
600 /*
601 * Returns true if the radio must be turned off when entering airplane mode.
602 */
603 private boolean isCellOffInAirplaneMode(Context context) {
604 String airplaneModeRadios = Settings.Global.getString(context.getContentResolver(),
605 Settings.Global.AIRPLANE_MODE_RADIOS);
606 return airplaneModeRadios == null
607 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
608 }
609
610 private void setRadioPowerOff(Context context) {
611 Log.i(LOG_TAG, "Turning radio off - airplane");
612 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
Eric Erfanian945409f2018-02-21 19:26:15 +0000613 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Meng Wang61307622019-10-23 14:08:43 -0700614 TelephonyProperties.airplane_mode_on(true); // true means int value 1
Chris Mantona09f3632016-02-09 14:48:42 -0800615 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
616 PhoneUtils.setRadioPower(false);
617 }
618
619 private void setRadioPowerOn(Context context) {
620 Log.i(LOG_TAG, "Turning radio on - airplane");
621 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
622 PhoneConstants.CELL_ON_FLAG);
623 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT,
624 1);
Meng Wang61307622019-10-23 14:08:43 -0700625 TelephonyProperties.airplane_mode_on(false); // false means int value 0
Chris Mantona09f3632016-02-09 14:48:42 -0800626 PhoneUtils.setRadioPower(true);
627 }
628
629 private void maybeTurnCellOff(Context context, boolean isAirplaneNewlyOn) {
630 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700631 // If we are trying to turn off the radio, make sure there are no active
632 // emergency calls. If there are, switch airplane mode back to off.
Tyler Gunn900d8fd2018-09-21 09:22:12 -0700633 TelecomManager tm = (TelecomManager) context.getSystemService(TELECOM_SERVICE);
634
635 if (tm != null && tm.isInEmergencyCall()) {
Santos Cordone18902f2016-03-22 17:16:04 -0700636 // Switch airplane mode back to off.
Jordan Liu0e819b12019-08-28 15:33:05 -0700637 ConnectivityManager cm =
638 (ConnectivityManager) context.getSystemService(CONNECTIVITY_SERVICE);
639 cm.setAirplaneMode(false);
Santos Cordone18902f2016-03-22 17:16:04 -0700640 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
641 .show();
642 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Chris Mantona09f3632016-02-09 14:48:42 -0800643 } else if (isCellOffInAirplaneMode(context)) {
644 setRadioPowerOff(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700645 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800646 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700647 }
Chris Mantona09f3632016-02-09 14:48:42 -0800648 }
649 }
650
651 private void maybeTurnCellOn(Context context, boolean isAirplaneNewlyOn) {
652 if (!isAirplaneNewlyOn) {
653 setRadioPowerOn(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700654 }
655 }
656
Santos Cordon593ab382013-08-06 21:58:23 -0700657 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700658 * Receiver for misc intent broadcasts the Phone app cares about.
659 */
660 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
661 @Override
662 public void onReceive(Context context, Intent intent) {
663 String action = intent.getAction();
664 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Santos Cordone18902f2016-03-22 17:16:04 -0700665 int airplaneMode = Settings.Global.getInt(getContentResolver(),
666 Settings.Global.AIRPLANE_MODE_ON, AIRPLANE_OFF);
667 // Treat any non-OFF values as ON.
668 if (airplaneMode != AIRPLANE_OFF) {
669 airplaneMode = AIRPLANE_ON;
670 }
Chris Mantona09f3632016-02-09 14:48:42 -0800671 handleAirplaneModeChange(context, airplaneMode);
Amit Mahajanf5d92c82018-11-02 17:44:40 -0700672 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
673 // re-register as it may be a new IccCard
674 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
675 SubscriptionManager.INVALID_PHONE_INDEX);
676 if (SubscriptionManager.isValidPhoneId(phoneId)) {
677 PhoneUtils.unregisterIccStatus(mHandler, phoneId);
678 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED, phoneId);
679 }
Nazish Tabassum160d2112019-12-23 17:31:33 +0530680 String iccStatus = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
681 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
682 new EventSimStateChangedBag(phoneId, iccStatus)));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700683 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
684 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800685 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
686 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700687 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
688 handleServiceStateChanged(intent);
689 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530690 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530691 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530692 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
693 if (phoneInEcm != null) {
694 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
695 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
696 // Start Emergency Callback Mode service
Daniel Bright30efde42020-01-09 22:11:15 -0800697 if (intent.getBooleanExtra(
698 TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530699 context.startService(new Intent(context,
700 EmergencyCallbackModeService.class));
701 } else {
702 phoneInEcm = null;
703 }
704 } else {
705 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
706 // on a device that doesn't support ECM in the first place.
707 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
708 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
709 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700710 }
711 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530712 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700713 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700714 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
715 // Roaming status could be overridden by carrier config, so we need to update it.
716 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
717 updateDataRoamingStatus();
chen xubaf9fe52019-07-02 17:28:24 -0700718 updateLimitedSimFunctionForDualSim();
Lei Liu863eac02020-06-24 20:12:55 +0800719 int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
720 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
721 if (SubscriptionManager.isValidSubscriptionId(subId)) {
722 mHandler.sendMessage(mHandler.obtainMessage(EVENT_CARRIER_CONFIG_CHANGED,
723 new Integer(subId)));
724 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700725 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
726 // We also need to pay attention when default data subscription changes.
727 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
728 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
729 registerSettingsObserver();
730 Phone phone = getPhone(mDefaultDataSubId);
731 if (phone != null) {
732 updateDataRoamingStatus();
733 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700734 }
735 }
736 }
737
Brad Ebinger28626122017-08-10 14:13:35 -0700738 private class SipReceiver extends BroadcastReceiver {
739
740 @Override
741 public void onReceive(Context context, Intent intent) {
742 String action = intent.getAction();
743
744 SipAccountRegistry sipAccountRegistry = SipAccountRegistry.getInstance();
745 if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
746 SipUtil.startSipService();
747 } else if (action.equals(SipManager.ACTION_SIP_SERVICE_UP)
748 || action.equals(SipManager.ACTION_SIP_CALL_OPTION_CHANGED)) {
749 sipAccountRegistry.setup(context);
Grace Jiab95592a2020-01-15 14:12:24 -0800750 } else if (action.equals(SipManager.ACTION_SIP_REMOVE_PROFILE)) {
Brad Ebinger28626122017-08-10 14:13:35 -0700751 if (DBG) {
752 Log.d(LOG_TAG, "SIP_REMOVE_PHONE "
753 + intent.getStringExtra(SipManager.EXTRA_LOCAL_URI));
754 }
755 sipAccountRegistry.removeSipProfile(intent.getStringExtra(
756 SipManager.EXTRA_LOCAL_URI));
757 } else {
758 if (DBG) Log.d(LOG_TAG, "onReceive, action not processed: " + action);
759 }
760 }
761 }
762
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700763 private void handleServiceStateChanged(Intent intent) {
764 /**
765 * This used to handle updating EriTextWidgetProvider this routine
766 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
767 * be removed. But leaving just in case it might be needed in the near
768 * future.
769 */
770
Jack Yu1a2fc352017-07-14 17:14:37 -0700771 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700772 // If service just returned, start sending out the queued messages
Santos Cordonc593d002015-06-03 15:41:15 -0700773 Bundle extras = intent.getExtras();
774 if (extras != null) {
775 ServiceState ss = ServiceState.newFromBundle(extras);
776 if (ss != null) {
777 int state = ss.getState();
Jayachandran C2ef9a482017-05-12 22:07:47 -0700778 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
779 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
780 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -0700781
782 if (VDBG) {
783 Log.v(LOG_TAG, "subId=" + subId + ",mDefaultDataSubId="
784 + mDefaultDataSubId + ",ss roaming=" + ss.getDataRoaming());
785 }
786 if (subId == mDefaultDataSubId) {
787 updateDataRoamingStatus();
788 }
Santos Cordonc593d002015-06-03 15:41:15 -0700789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700790 }
791 }
792
Jack Yu1a2fc352017-07-14 17:14:37 -0700793 /**
Jordan Liuff2ccd72019-07-23 15:54:41 -0700794 * @return whether or not we should show a notification when connecting to data roaming if the
795 * user has data roaming enabled
796 */
797 private boolean shouldShowDataConnectedRoaming(int subId) {
798 PersistableBundle config = getCarrierConfigForSubId(subId);
799 return config.getBoolean(CarrierConfigManager
800 .KEY_SHOW_DATA_CONNECTED_ROAMING_NOTIFICATION_BOOL);
801 }
802
803 /**
Jack Yu1a2fc352017-07-14 17:14:37 -0700804 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
805 * to notify the user so they can enable it through settings. Vise versa if the condition
806 * changes, we need to dismiss the notification.
807 */
808 private void updateDataRoamingStatus() {
809 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
810 Phone phone = getPhone(mDefaultDataSubId);
811 if (phone == null) {
812 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
813 return;
814 }
815
816 DataConnectionReasons reasons = new DataConnectionReasons();
Jack Yu311536f2018-11-26 11:20:48 -0800817 boolean dataAllowed = phone.isDataAllowed(ApnSetting.TYPE_DEFAULT, reasons);
Jack Yu1a2fc352017-07-14 17:14:37 -0700818 mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons);
819 if (VDBG) Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons);
Jordan Liuff2ccd72019-07-23 15:54:41 -0700820 if (!dataAllowed && reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED)) {
821 // No need to show it again if we never cancelled it explicitly.
822 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_DISCONNECTED) return;
Jack Yu1a2fc352017-07-14 17:14:37 -0700823 // If the only reason of no data is data roaming disabled, then we notify the user
824 // so the user can turn on data roaming.
Jordan Liuff2ccd72019-07-23 15:54:41 -0700825 mPrevRoamingNotification = ROAMING_NOTIFICATION_DISCONNECTED;
Jack Yu1a2fc352017-07-14 17:14:37 -0700826 Log.d(LOG_TAG, "Show roaming disconnected notification");
Jordan Liuff2ccd72019-07-23 15:54:41 -0700827 mDataRoamingNotifLog.log("Show roaming off.");
Pengquan Meng8783d932017-10-16 14:57:40 -0700828 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_DISCONNECTED);
829 msg.arg1 = mDefaultDataSubId;
830 msg.sendToTarget();
Jordan Liuff2ccd72019-07-23 15:54:41 -0700831 } else if (dataAllowed && dataIsNowRoaming(mDefaultDataSubId)
832 && shouldShowDataConnectedRoaming(mDefaultDataSubId)) {
833 // No need to show it again if we never cancelled it explicitly, or carrier config
834 // indicates this is not needed.
835 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_CONNECTED) return;
836 mPrevRoamingNotification = ROAMING_NOTIFICATION_CONNECTED;
837 Log.d(LOG_TAG, "Show roaming connected notification");
838 mDataRoamingNotifLog.log("Show roaming on.");
839 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_CONNECTED);
840 msg.arg1 = mDefaultDataSubId;
841 msg.sendToTarget();
842 } else if (mPrevRoamingNotification != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
843 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
844 // is not the only data disable reason. In this case we dismiss the notification we
845 // showed earlier.
846 mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
847 Log.d(LOG_TAG, "Dismiss roaming notification");
Jack Yu1a2fc352017-07-14 17:14:37 -0700848 mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed + ", reasons=" + reasons);
849 mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
850 }
851 }
852
Jordan Liuff2ccd72019-07-23 15:54:41 -0700853 /**
854 *
855 * @param subId to check roaming on
856 * @return whether we have transitioned to dataRoaming
857 */
858 private boolean dataIsNowRoaming(int subId) {
859 return getPhone(subId).getServiceState().getDataRoaming();
860 }
861
chen xubaf9fe52019-07-02 17:28:24 -0700862 private void updateLimitedSimFunctionForDualSim() {
863 if (DBG) Log.d(LOG_TAG, "updateLimitedSimFunctionForDualSim");
864 // check conditions to display limited SIM function notification under dual SIM
865 SubscriptionManager subMgr = (SubscriptionManager) getSystemService(
866 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
867 List<SubscriptionInfo> subList = subMgr.getActiveSubscriptionInfoList(false);
868 if (subList != null && subList.size() > 1) {
869 CarrierConfigManager configMgr = (CarrierConfigManager)
870 getSystemService(Context.CARRIER_CONFIG_SERVICE);
871 for (SubscriptionInfo info : subList) {
872 PersistableBundle b = configMgr.getConfigForSubId(info.getSubscriptionId());
873 if (b != null) {
874 if (b.getBoolean(CarrierConfigManager
875 .KEY_LIMITED_SIM_FUNCTION_NOTIFICATION_FOR_DSDS_BOOL)) {
876 notificationMgr.showLimitedSimFunctionWarningNotification(
877 info.getSubscriptionId(),
878 info.getDisplayName().toString());
879 } else {
880 notificationMgr.dismissLimitedSimFunctionWarningNotification(
881 info.getSubscriptionId());
882 }
883 }
884 }
885 } else {
886 // cancel notifications for all subs
887 notificationMgr.dismissLimitedSimFunctionWarningNotification(
888 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
889 }
890 notificationMgr.dismissLimitedSimFunctionWarningNotificationForInactiveSubs();
891
892 }
893
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530894 public Phone getPhoneInEcm() {
895 return phoneInEcm;
896 }
897
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700898 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800899 * Triggers a refresh of the message waiting (voicemail) indicator.
900 *
901 * @param subId the subscription id we should refresh the notification for.
902 */
903 public void refreshMwiIndicator(int subId) {
904 notificationMgr.refreshMwi(subId);
905 }
906
907 /**
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700908 * Called when the network selection on the subscription {@code subId} is changed by the user.
909 *
910 * @param subId the subscription id.
911 */
912 public void onNetworkSelectionChanged(int subId) {
913 Phone phone = getPhone(subId);
914 if (phone != null) {
915 notificationMgr.updateNetworkSelection(phone.getServiceState().getState(), subId);
916 } else {
917 Log.w(LOG_TAG, "onNetworkSelectionChanged on null phone, subId: " + subId);
918 }
919 }
920
921 /**
Jack Yu1a2fc352017-07-14 17:14:37 -0700922 * Dump the state of the object, add calls to other objects as desired.
923 *
924 * @param fd File descriptor
925 * @param printWriter Print writer
926 * @param args Arguments
927 */
928 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
929 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
930 pw.println("------- PhoneGlobals -------");
931 pw.increaseIndent();
Jordan Liuff2ccd72019-07-23 15:54:41 -0700932 pw.println("mPrevRoamingNotification=" + mPrevRoamingNotification);
Jack Yu1a2fc352017-07-14 17:14:37 -0700933 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
934 pw.println("mDataRoamingNotifLog:");
Keun young Parkdebb8532019-05-30 16:35:27 -0700935 pw.println("isSmsCapable=" + TelephonyManager.from(this).isSmsCapable());
Jack Yu1a2fc352017-07-14 17:14:37 -0700936 pw.increaseIndent();
937 mDataRoamingNotifLog.dump(fd, pw, args);
938 pw.decreaseIndent();
Brad Ebinger05f52c22019-12-05 13:03:21 -0800939 pw.println("ImsResolver:");
940 pw.increaseIndent();
941 try {
942 if (mImsResolver != null) mImsResolver.dump(fd, pw, args);
943 } catch (Exception e) {
944 e.printStackTrace();
945 }
946 pw.decreaseIndent();
Brad Ebingera68a4972020-01-30 17:31:23 -0800947 pw.println("RcsService:");
948 try {
949 if (mTelephonyRcsService != null) mTelephonyRcsService.dump(fd, pw, args);
950 } catch (Exception e) {
951 e.printStackTrace();
952 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700953 pw.decreaseIndent();
954 pw.println("------- End PhoneGlobals -------");
955 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700956}