blob: 54943abe4249739f00bcbe950d282afae35e224a [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;
Tyler Gunn92479152021-01-20 16:30:10 -080072import com.android.internal.telephony.imsphone.ImsPhone;
73import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Jordan Liu7c105402021-03-24 17:25:46 -070074import com.android.internal.telephony.uicc.UiccCard;
75import com.android.internal.telephony.uicc.UiccProfile;
Jack Yu1a2fc352017-07-14 17:14:37 -070076import com.android.internal.util.IndentingPrintWriter;
Andrew Leefb7f92e2015-02-26 16:23:32 -080077import com.android.phone.settings.SettingsConstants;
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -070078import com.android.phone.vvm.CarrierVvmPackageInstalledReceiver;
James.cf Linc9f35a42020-01-15 02:35:22 +080079import com.android.services.telephony.rcs.TelephonyRcsService;
Brad Ebinger28626122017-08-10 14:13:35 -070080import com.android.services.telephony.sip.SipAccountRegistry;
Brad Ebinger3fa43462016-04-12 16:06:48 -070081import com.android.services.telephony.sip.SipUtil;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070082
Jack Yu1a2fc352017-07-14 17:14:37 -070083import java.io.FileDescriptor;
84import java.io.PrintWriter;
Jordan Liuff2ccd72019-07-23 15:54:41 -070085import java.lang.annotation.Retention;
86import java.lang.annotation.RetentionPolicy;
chen xubaf9fe52019-07-02 17:28:24 -070087import java.util.List;
Jack Yu1a2fc352017-07-14 17:14:37 -070088
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089/**
90 * Global state for the telephony subsystem when running in the primary
91 * phone process.
92 */
Sailesh Nepalbf900542014-07-15 16:18:32 -070093public class PhoneGlobals extends ContextWrapper {
Jack Yu1a2fc352017-07-14 17:14:37 -070094 public static final String LOG_TAG = "PhoneGlobals";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095
96 /**
97 * Phone app-wide debug level:
98 * 0 - no debug logging
99 * 1 - normal debug logging if ro.debuggable is set (which is true in
100 * "eng" and "userdebug" builds but not "user" builds)
101 * 2 - ultra-verbose debug logging
102 *
103 * Most individual classes in the phone app have a local DBG constant,
104 * typically set to
105 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
106 * or else
107 * (PhoneApp.DBG_LEVEL >= 2)
108 * depending on the desired verbosity.
109 *
110 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
111 */
Andrew Lee88b51e22014-10-29 15:48:51 -0700112 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700113
114 private static final boolean DBG =
115 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
116 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
117
118 // Message codes; see mHandler below.
119 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700121 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
Jordan Liuff2ccd72019-07-23 15:54:41 -0700122 private static final int EVENT_DATA_ROAMING_CONNECTED = 11;
123 private static final int EVENT_DATA_ROAMING_OK = 12;
124 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 13;
125 private static final int EVENT_RESTART_SIP = 14;
126 private static final int EVENT_DATA_ROAMING_SETTINGS_CHANGED = 15;
127 private static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED = 16;
Lei Liu863eac02020-06-24 20:12:55 +0800128 private static final int EVENT_CARRIER_CONFIG_CHANGED = 17;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129
130 // The MMI codes are also used by the InCallScreen.
131 public static final int MMI_INITIATE = 51;
132 public static final int MMI_COMPLETE = 52;
133 public static final int MMI_CANCEL = 53;
134 // Don't use message codes larger than 99 here; those are reserved for
135 // the individual Activities of the Phone UI.
136
Santos Cordone18902f2016-03-22 17:16:04 -0700137 public static final int AIRPLANE_ON = 1;
138 public static final int AIRPLANE_OFF = 0;
139
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140 /**
141 * Allowable values for the wake lock code.
142 * SLEEP means the device can be put to sleep.
143 * PARTIAL means wake the processor, but we display can be kept off.
144 * FULL means wake both the processor and the display.
145 */
146 public enum WakeState {
147 SLEEP,
148 PARTIAL,
149 FULL
150 }
151
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700152 private static PhoneGlobals sMe;
153
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700155 CallNotifier notifier;
156 CallerInfoCache callerInfoCache;
Santos Cordon63a84242013-07-23 13:32:52 -0700157 NotificationMgr notificationMgr;
James.cf Linc9f35a42020-01-15 02:35:22 +0800158 TelephonyRcsService mTelephonyRcsService;
Andrew Lee9431b832015-03-09 18:46:45 -0700159 public PhoneInterfaceManager phoneMgr;
James.cf Linaf3183c2019-10-24 00:59:00 +0800160 public ImsRcsController imsRcsController;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800161 CarrierConfigLoader configLoader;
Santos Cordon63a84242013-07-23 13:32:52 -0700162
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530163 private Phone phoneInEcm;
Santos Cordon63a84242013-07-23 13:32:52 -0700164
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165 static boolean sVoiceCapable = true;
166
Santos Cordonc593d002015-06-03 15:41:15 -0700167 // TODO: Remove, no longer used.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700168 CdmaPhoneCallState cdmaPhoneCallState;
169
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700170 // The currently-active PUK entry activity and progress dialog.
171 // Normally, these are the Emergency Dialer and the subsequent
172 // progress dialog. null if there is are no such objects in
173 // the foreground.
174 private Activity mPUKEntryActivity;
175 private ProgressDialog mPUKEntryProgressDialog;
176
Jordan Liuff2ccd72019-07-23 15:54:41 -0700177 /** @hide */
178 @Retention(RetentionPolicy.SOURCE)
179 @IntDef(prefix = {"ROAMING_NOTIFICATION_"},
180 value = {
181 ROAMING_NOTIFICATION_NO_NOTIFICATION,
182 ROAMING_NOTIFICATION_CONNECTED,
183 ROAMING_NOTIFICATION_DISCONNECTED})
184 public @interface RoamingNotification {}
185
186 private static final int ROAMING_NOTIFICATION_NO_NOTIFICATION = 0;
187 private static final int ROAMING_NOTIFICATION_CONNECTED = 1;
188 private static final int ROAMING_NOTIFICATION_DISCONNECTED = 2;
189
190 @RoamingNotification
191 private int mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
Jack Yu953f9352017-05-18 14:41:06 -0700192
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193 private WakeState mWakeState = WakeState.SLEEP;
194
195 private PowerManager mPowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196 private PowerManager.WakeLock mWakeLock;
197 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700199
Jack Yu1a2fc352017-07-14 17:14:37 -0700200 private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
201 private final LocalLog mDataRoamingNotifLog = new LocalLog(50);
202
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700203 // Broadcast receiver for various intent broadcasts (see onCreate())
204 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
Brad Ebinger533c6c12017-08-02 11:38:48 -0700205 // Broadcast receiver for SIP based intents (see onCreate())
Brad Ebinger28626122017-08-10 14:13:35 -0700206 private final SipReceiver mSipReceiver = new SipReceiver();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700207
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700208 private final CarrierVvmPackageInstalledReceiver mCarrierVvmPackageInstalledReceiver =
209 new CarrierVvmPackageInstalledReceiver();
210
Jack Yu1a2fc352017-07-14 17:14:37 -0700211 private final SettingsObserver mSettingsObserver;
212
Nazish Tabassum160d2112019-12-23 17:31:33 +0530213 private static class EventSimStateChangedBag {
214 final int mPhoneId;
215 final String mIccStatus;
216
217 EventSimStateChangedBag(int phoneId, String iccStatus) {
218 mPhoneId = phoneId;
219 mIccStatus = iccStatus;
220 }
221 }
222
Jordan Liu7c105402021-03-24 17:25:46 -0700223 // Some carrier config settings disable the network lock screen, so we call handleSimLock
224 // when either SIM_LOCK or CARRIER_CONFIG changes so that no matter which one happens first,
225 // we still do the right thing
226 private void handleSimLock(int subType, Phone phone) {
227 PersistableBundle cc = getCarrierConfigForSubId(phone.getSubId());
228 if (!CarrierConfigManager.isConfigForIdentifiedCarrier(cc)) {
229 // If we only have the default carrier config just return, to avoid popping up the
230 // the SIM lock screen when it's disabled by the carrier.
231 Log.i(LOG_TAG, "Not showing 'SIM network unlock' screen. Carrier config not loaded");
232 return;
233 }
234 if (cc.getBoolean(CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
235 // Some products don't have the concept of a "SIM network lock"
236 Log.i(LOG_TAG, "Not showing 'SIM network unlock' screen. Disabled by carrier config");
237 return;
238 }
239
240 // if passed in subType is unknown, retrieve it here.
241 if (subType == -1) {
242 final UiccCard uiccCard = phone.getUiccCard();
243 if (uiccCard == null) {
244 Log.e(LOG_TAG,
245 "handleSimLock: uiccCard for phone " + phone.getPhoneId() + " is null");
246 return;
247 }
248 final UiccProfile uiccProfile = uiccCard.getUiccProfile();
249 if (uiccProfile == null) {
250 Log.e(LOG_TAG,
251 "handleSimLock: uiccProfile for phone " + phone.getPhoneId() + " is null");
252 return;
253 }
254 subType = uiccProfile.getApplication(
255 uiccProfile.mCurrentAppType).getPersoSubState().ordinal();
256 }
257 // Normal case: show the "SIM network unlock" PIN entry screen.
258 // The user won't be able to do anything else until
259 // they enter a valid SIM network PIN.
260 Log.i(LOG_TAG, "show sim depersonal panel");
261 IccNetworkDepersonalizationPanel.showDialog(phone, subType);
262 }
263
264 private boolean isSimLocked(Phone phone) {
265 TelephonyManager tm = getSystemService(TelephonyManager.class);
266 return tm.createForSubscriptionId(phone.getSubId()).getSimState()
267 == TelephonyManager.SIM_STATE_NETWORK_LOCKED;
268 }
269
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700270 Handler mHandler = new Handler() {
271 @Override
272 public void handleMessage(Message msg) {
273 PhoneConstants.State phoneState;
Jack Yu1a2fc352017-07-14 17:14:37 -0700274 if (VDBG) Log.v(LOG_TAG, "event=" + msg.what);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275 switch (msg.what) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700276 // TODO: This event should be handled by the lock screen, just
277 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
278 case EVENT_SIM_NETWORK_LOCKED:
Jordan Liu7c105402021-03-24 17:25:46 -0700279 int subType = (Integer) ((AsyncResult) msg.obj).result;
280 Phone phone = (Phone) ((AsyncResult) msg.obj).userObj;
281 handleSimLock(subType, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700282 break;
283
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700284 case EVENT_DATA_ROAMING_DISCONNECTED:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700285 notificationMgr.showDataRoamingNotification(msg.arg1, false);
286 break;
287
288 case EVENT_DATA_ROAMING_CONNECTED:
289 notificationMgr.showDataRoamingNotification(msg.arg1, true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700290 break;
291
292 case EVENT_DATA_ROAMING_OK:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700293 notificationMgr.hideDataRoamingNotification();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700294 break;
295
296 case MMI_COMPLETE:
297 onMMIComplete((AsyncResult) msg.obj);
298 break;
299
300 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800301 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700302 break;
303
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700304 case EVENT_SIM_STATE_CHANGED:
305 // Marks the event where the SIM goes into ready state.
306 // Right now, this is only used for the PUK-unlocking
307 // process.
Nazish Tabassum160d2112019-12-23 17:31:33 +0530308 EventSimStateChangedBag bag = (EventSimStateChangedBag)msg.obj;
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700309 if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(bag.mIccStatus)
Nazish Tabassum59126a92020-07-03 21:44:49 +0530310 || IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(bag.mIccStatus)
311 || IccCardConstants.INTENT_VALUE_ICC_NOT_READY.equals(bag.mIccStatus)
312 || IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(bag.mIccStatus)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700313 // when the right event is triggered and there
314 // are UI objects in the foreground, we close
315 // them to display the lock panel.
316 if (mPUKEntryActivity != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700317 Log.i(LOG_TAG, "Dismiss puk entry activity");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700318 mPUKEntryActivity.finish();
319 mPUKEntryActivity = null;
320 }
321 if (mPUKEntryProgressDialog != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700322 Log.i(LOG_TAG, "Dismiss puk progress dialog");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700323 mPUKEntryProgressDialog.dismiss();
324 mPUKEntryProgressDialog = null;
325 }
Nazish Tabassum59126a92020-07-03 21:44:49 +0530326 Log.i(LOG_TAG, "Dismissing depersonal panel" + (bag.mIccStatus));
Nazish Tabassum160d2112019-12-23 17:31:33 +0530327 IccNetworkDepersonalizationPanel.dialogDismiss(bag.mPhoneId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700328 }
329 break;
330
331 case EVENT_UNSOL_CDMA_INFO_RECORD:
332 //TODO: handle message here;
333 break;
Brad Ebinger3fa43462016-04-12 16:06:48 -0700334 case EVENT_RESTART_SIP:
335 // This should only run if the Phone process crashed and was restarted. We do
336 // not want this running if the device is still in the FBE encrypted state.
Brad Ebinger28626122017-08-10 14:13:35 -0700337 // This is the same procedure that is triggered in the SipIncomingCallReceiver
Brad Ebinger3fa43462016-04-12 16:06:48 -0700338 // upon BOOT_COMPLETED.
Meng Wangc04cd2d2019-10-04 12:00:06 -0700339 UserManager userManager =
340 (UserManager) sMe.getSystemService(Context.USER_SERVICE);
Brad Ebinger3fa43462016-04-12 16:06:48 -0700341 if (userManager != null && userManager.isUserUnlocked()) {
342 SipUtil.startSipService();
343 }
344 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700345 case EVENT_DATA_ROAMING_SETTINGS_CHANGED:
346 case EVENT_MOBILE_DATA_SETTINGS_CHANGED:
347 updateDataRoamingStatus();
348 break;
Lei Liu863eac02020-06-24 20:12:55 +0800349 case EVENT_CARRIER_CONFIG_CHANGED:
350 int subId = (Integer) msg.obj;
351 // The voicemail number could be overridden by carrier config, so need to
352 // refresh the message waiting (voicemail) indicator.
353 refreshMwiIndicator(subId);
Jordan Liu7c105402021-03-24 17:25:46 -0700354 phone = getPhone(subId);
355 if (phone != null && isSimLocked(phone)) {
356 // pass in subType=-1 so handleSimLock can find the actual subType if
357 // needed. This is safe as valid values for subType are >= 0
358 handleSimLock(-1, phone);
359 }
Lei Liu863eac02020-06-24 20:12:55 +0800360 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361 }
362 }
363 };
364
365 public PhoneGlobals(Context context) {
366 super(context);
367 sMe = this;
Jack Yu1a2fc352017-07-14 17:14:37 -0700368 mSettingsObserver = new SettingsObserver(context, mHandler);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369 }
370
371 public void onCreate() {
372 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
373
374 ContentResolver resolver = getContentResolver();
375
376 // Cache the "voice capable" flag.
377 // This flag currently comes from a resource (which is
378 // overrideable on a per-product basis):
Michele87262742020-01-16 12:23:53 -0800379 sVoiceCapable = ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE))
380 .isVoiceCapable();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 // ...but this might eventually become a PackageManager "system
382 // feature" instead, in which case we'd do something like:
383 // sVoiceCapable =
384 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
385
Stuart Scottdcf40a92014-12-09 10:45:01 -0800386 if (mCM == null) {
Nathan Haroldf9df6ea2019-03-08 11:54:22 -0800387 // Initialize AnomalyReporter early so that it can be used
388 AnomalyReporter.initialize(this);
Nathan Harold0db5c5e2019-01-22 20:18:56 -0800389
Youming Ye47a6adc2018-11-19 15:33:36 -0800390 // Inject telephony component factory if configured using other jars.
391 XmlResourceParser parser = getResources().getXml(R.xml.telephony_injection);
392 TelephonyComponentFactory.getInstance().injectTheComponentFactory(parser);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700393 // Initialize the telephony framework
394 PhoneFactory.makeDefaultPhones(this);
395
Brad Ebinger05f52c22019-12-05 13:03:21 -0800396 // Only bring up ImsResolver if the device supports having an IMS stack.
397 if (getPackageManager().hasSystemFeature(
398 PackageManager.FEATURE_TELEPHONY_IMS)) {
399 // Get the package name of the default IMS implementation.
400 String defaultImsMmtelPackage = getResources().getString(
401 R.string.config_ims_mmtel_package);
402 String defaultImsRcsPackage = getResources().getString(
403 R.string.config_ims_rcs_package);
Brad Ebingerc9c432e2021-05-17 20:54:49 +0000404 ImsResolver.make(this, defaultImsMmtelPackage,
Brad Ebingere3ae65a2020-09-11 12:45:11 -0700405 defaultImsRcsPackage, PhoneFactory.getPhones().length,
406 new ImsFeatureBinderRepository());
Brad Ebingerc9c432e2021-05-17 20:54:49 +0000407 ImsResolver.getInstance().initialize();
Tyler Gunn92479152021-01-20 16:30:10 -0800408
409 // With the IMS phone created, load static config.xml values from the phone process
410 // so that it can be provided to the ImsPhoneCallTracker.
411 for (Phone p : PhoneFactory.getPhones()) {
412 Phone imsPhone = p.getImsPhone();
413 if (imsPhone != null && imsPhone instanceof ImsPhone) {
414 ImsPhone theImsPhone = (ImsPhone) imsPhone;
415 if (theImsPhone.getCallTracker() instanceof ImsPhoneCallTracker) {
416 ImsPhoneCallTracker ict = (ImsPhoneCallTracker)
417 theImsPhone.getCallTracker();
418
419 ImsPhoneCallTracker.Config config = new ImsPhoneCallTracker.Config();
420 config.isD2DCommunicationSupported = getResources().getBoolean(
421 R.bool.config_use_device_to_device_communication);
422 ict.setConfig(config);
423 }
424 }
425 }
Hui Wang068ab862020-10-31 05:12:53 +0000426 RcsProvisioningMonitor.make(this);
Brad Ebinger05f52c22019-12-05 13:03:21 -0800427 }
428
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700429 // Start TelephonyDebugService After the default phone is created.
430 Intent intent = new Intent(this, TelephonyDebugService.class);
431 startService(intent);
432
433 mCM = CallManager.getInstance();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434
435 // Create the NotificationMgr singleton, which is used to display
436 // status bar icons and control other status bar behavior.
437 notificationMgr = NotificationMgr.init(this);
438
Brad Ebinger3fa43462016-04-12 16:06:48 -0700439 // If PhoneGlobals has crashed and is being restarted, then restart.
440 mHandler.sendEmptyMessage(EVENT_RESTART_SIP);
441
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700442 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
443 cdmaPhoneCallState = new CdmaPhoneCallState();
444 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700446 // before registering for phone state changes
447 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
448 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
449 // lock used to keep the processor awake, when we don't care for the display.
450 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
451 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700452
453 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
454
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700455 // Create the CallerInfoCache singleton, which remembers custom ring tone and
456 // send-to-voicemail settings.
457 //
458 // The asynchronous caching will start just after this call.
459 callerInfoCache = CallerInfoCache.init(this);
460
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800461 phoneMgr = PhoneInterfaceManager.init(this);
Santos Cordon406c0342013-08-28 00:07:47 -0700462
James.cf Linaf3183c2019-10-24 00:59:00 +0800463 imsRcsController = ImsRcsController.init(this);
464
James.cf Linc9f35a42020-01-15 02:35:22 +0800465 if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
Brad Ebingera68a4972020-01-30 17:31:23 -0800466 mTelephonyRcsService = new TelephonyRcsService(this,
467 PhoneFactory.getPhones().length);
468 mTelephonyRcsService.initialize();
James.cf Linc9f35a42020-01-15 02:35:22 +0800469 imsRcsController.setRcsService(mTelephonyRcsService);
470 }
471
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800472 configLoader = CarrierConfigLoader.init(this);
473
Jack Yu1a2fc352017-07-14 17:14:37 -0700474 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700475 // asynchronous events from the telephony layer (like
476 // launching the incoming-call UI when an incoming call comes
477 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800478 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700479
Stuart Scottdcf40a92014-12-09 10:45:01 -0800480 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700481
482 // register for MMI/USSD
483 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
484
Qiong Liucc3fe812019-09-23 15:25:44 +0800485 // Initialize cell status using current airplane mode.
486 handleAirplaneModeChange(this, Settings.Global.getInt(getContentResolver(),
487 Settings.Global.AIRPLANE_MODE_ON, AIRPLANE_OFF));
488
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700489 // Register for misc other intent broadcasts.
490 IntentFilter intentFilter =
491 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700492 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
493 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
494 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
495 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700496 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
497 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700498 registerReceiver(mReceiver, intentFilter);
499
Brad Ebinger533c6c12017-08-02 11:38:48 -0700500 IntentFilter sipIntentFilter = new IntentFilter(Intent.ACTION_BOOT_COMPLETED);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700501 sipIntentFilter.addAction(SipManager.ACTION_SIP_SERVICE_UP);
502 sipIntentFilter.addAction(SipManager.ACTION_SIP_CALL_OPTION_CHANGED);
Grace Jiab95592a2020-01-15 14:12:24 -0800503 sipIntentFilter.addAction(SipManager.ACTION_SIP_REMOVE_PROFILE);
Brad Ebinger28626122017-08-10 14:13:35 -0700504 registerReceiver(mSipReceiver, sipIntentFilter);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700505
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700506 mCarrierVvmPackageInstalledReceiver.register(this);
507
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700508 //set the default values for the preferences in the phone.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700509 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700510 }
511
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700512 // XXX pre-load the SimProvider so that it's ready
513 resolver.getType(Uri.parse("content://icc/adn"));
514
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700515 // TODO: Register for Cdma Information Records
516 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
517
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700518 // Read HAC settings and configure audio hardware
519 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800520 int hac = android.provider.Settings.System.getInt(
521 getContentResolver(),
522 android.provider.Settings.System.HEARING_AID,
523 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700524 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Jordan Liuf71aeef2019-08-21 11:46:09 -0700525 audioManager.setParameters(
526 SettingsConstants.HAC_KEY + "=" + (hac == SettingsConstants.HAC_ENABLED
527 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700528 }
Santos Cordonff506f52013-11-21 19:13:19 -0800529 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700530
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700531 /**
532 * Returns the singleton instance of the PhoneApp.
533 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800534 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700535 if (sMe == null) {
536 throw new IllegalStateException("No PhoneGlobals here!");
537 }
538 return sMe;
539 }
540
541 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800542 * Returns the default phone.
543 *
Andrew Lee385019f2014-11-24 14:19:50 -0800544 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700545 */
Andrew Lee83383e42014-10-31 12:42:28 -0700546 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800547 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700548 }
549
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800550 public static Phone getPhone(int subId) {
551 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800552 }
553
Santos Cordonde10b752013-09-19 04:11:33 -0700554 /* package */ CallManager getCallManager() {
555 return mCM;
556 }
557
Chris Manton4e9fa912015-06-19 11:26:57 -0700558 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800559 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700560 }
561
Chris Manton4e9fa912015-06-19 11:26:57 -0700562 public PersistableBundle getCarrierConfigForSubId(int subId) {
Philip P. Moltmann0079aae2020-03-05 16:24:02 -0800563 return configLoader.getConfigForSubIdWithFeature(subId, getOpPackageName(),
564 getAttributionTag());
Junda Liu605148f2015-04-28 15:23:40 -0700565 }
566
Jack Yu1a2fc352017-07-14 17:14:37 -0700567 private void registerSettingsObserver() {
568 mSettingsObserver.unobserve();
569 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
570 String mobileDataSetting = Settings.Global.MOBILE_DATA;
571 if (TelephonyManager.getDefault().getSimCount() > 1) {
572 int subId = mDefaultDataSubId;
573 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
574 dataRoamingSetting += subId;
575 mobileDataSetting += subId;
576 }
577 }
578
579 // Listen for user data roaming setting changed event
580 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
581 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
582
583 // Listen for mobile data setting changed event
584 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
585 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
586 }
587
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700588 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700589 * Sets the activity responsible for un-PUK-blocking the device
590 * so that we may close it when we receive a positive result.
591 * mPUKEntryActivity is also used to indicate to the device that
592 * we are trying to un-PUK-lock the phone. In other words, iff
593 * it is NOT null, then we are trying to unlock and waiting for
594 * the SIM to move to READY state.
595 *
596 * @param activity is the activity to close when PUK has
597 * finished unlocking. Can be set to null to indicate the unlock
598 * or SIM READYing process is over.
599 */
600 void setPukEntryActivity(Activity activity) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700601 Log.i(LOG_TAG, "setPukEntryActivity - set to " + (activity == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700602 mPUKEntryActivity = activity;
603 }
604
605 Activity getPUKEntryActivity() {
606 return mPUKEntryActivity;
607 }
608
609 /**
610 * Sets the dialog responsible for notifying the user of un-PUK-
611 * blocking - SIM READYing progress, so that we may dismiss it
612 * when we receive a positive result.
613 *
614 * @param dialog indicates the progress dialog informing the user
615 * of the state of the device. Dismissed upon completion of
616 * READYing process
617 */
618 void setPukEntryProgressDialog(ProgressDialog dialog) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700619 Log.i(LOG_TAG, "setPukEntryProgressDialog - set to "
620 + (dialog == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700621 mPUKEntryProgressDialog = dialog;
622 }
623
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700624 KeyguardManager getKeyguardManager() {
625 return mKeyguardManager;
626 }
627
628 private void onMMIComplete(AsyncResult r) {
629 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
630 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800631 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700632 }
633
fionaxu80126972017-02-01 17:01:26 -0800634 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700635 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700636 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700637 }
638
Chris Mantona09f3632016-02-09 14:48:42 -0800639 private void handleAirplaneModeChange(Context context, int newMode) {
640 int cellState = Settings.Global.getInt(context.getContentResolver(),
641 Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
642 boolean isAirplaneNewlyOn = (newMode == 1);
643 switch (cellState) {
644 case PhoneConstants.CELL_OFF_FLAG:
645 // Airplane mode does not affect the cell radio if user
646 // has turned it off.
647 break;
648 case PhoneConstants.CELL_ON_FLAG:
649 maybeTurnCellOff(context, isAirplaneNewlyOn);
650 break;
651 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
652 maybeTurnCellOn(context, isAirplaneNewlyOn);
653 break;
654 }
Hall Liu7f56e1a2019-07-10 14:41:14 -0700655 for (Phone phone : PhoneFactory.getPhones()) {
656 phone.getServiceStateTracker().onAirplaneModeChanged(isAirplaneNewlyOn);
657 }
Chris Mantona09f3632016-02-09 14:48:42 -0800658 }
659
660 /*
661 * Returns true if the radio must be turned off when entering airplane mode.
662 */
663 private boolean isCellOffInAirplaneMode(Context context) {
664 String airplaneModeRadios = Settings.Global.getString(context.getContentResolver(),
665 Settings.Global.AIRPLANE_MODE_RADIOS);
666 return airplaneModeRadios == null
667 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
668 }
669
670 private void setRadioPowerOff(Context context) {
671 Log.i(LOG_TAG, "Turning radio off - airplane");
672 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
Eric Erfanian945409f2018-02-21 19:26:15 +0000673 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Meng Wang61307622019-10-23 14:08:43 -0700674 TelephonyProperties.airplane_mode_on(true); // true means int value 1
Chris Mantona09f3632016-02-09 14:48:42 -0800675 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
676 PhoneUtils.setRadioPower(false);
677 }
678
679 private void setRadioPowerOn(Context context) {
680 Log.i(LOG_TAG, "Turning radio on - airplane");
681 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
682 PhoneConstants.CELL_ON_FLAG);
683 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT,
684 1);
Meng Wang61307622019-10-23 14:08:43 -0700685 TelephonyProperties.airplane_mode_on(false); // false means int value 0
Chris Mantona09f3632016-02-09 14:48:42 -0800686 PhoneUtils.setRadioPower(true);
687 }
688
689 private void maybeTurnCellOff(Context context, boolean isAirplaneNewlyOn) {
690 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700691 // If we are trying to turn off the radio, make sure there are no active
692 // emergency calls. If there are, switch airplane mode back to off.
Tyler Gunn900d8fd2018-09-21 09:22:12 -0700693 TelecomManager tm = (TelecomManager) context.getSystemService(TELECOM_SERVICE);
694
695 if (tm != null && tm.isInEmergencyCall()) {
Santos Cordone18902f2016-03-22 17:16:04 -0700696 // Switch airplane mode back to off.
Jordan Liu0e819b12019-08-28 15:33:05 -0700697 ConnectivityManager cm =
698 (ConnectivityManager) context.getSystemService(CONNECTIVITY_SERVICE);
699 cm.setAirplaneMode(false);
Santos Cordone18902f2016-03-22 17:16:04 -0700700 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
701 .show();
702 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Chris Mantona09f3632016-02-09 14:48:42 -0800703 } else if (isCellOffInAirplaneMode(context)) {
704 setRadioPowerOff(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700705 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800706 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700707 }
Chris Mantona09f3632016-02-09 14:48:42 -0800708 }
709 }
710
711 private void maybeTurnCellOn(Context context, boolean isAirplaneNewlyOn) {
712 if (!isAirplaneNewlyOn) {
713 setRadioPowerOn(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700714 }
715 }
716
Santos Cordon593ab382013-08-06 21:58:23 -0700717 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700718 * Receiver for misc intent broadcasts the Phone app cares about.
719 */
720 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
721 @Override
722 public void onReceive(Context context, Intent intent) {
723 String action = intent.getAction();
724 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Santos Cordone18902f2016-03-22 17:16:04 -0700725 int airplaneMode = Settings.Global.getInt(getContentResolver(),
726 Settings.Global.AIRPLANE_MODE_ON, AIRPLANE_OFF);
727 // Treat any non-OFF values as ON.
728 if (airplaneMode != AIRPLANE_OFF) {
729 airplaneMode = AIRPLANE_ON;
730 }
Chris Mantona09f3632016-02-09 14:48:42 -0800731 handleAirplaneModeChange(context, airplaneMode);
Amit Mahajanf5d92c82018-11-02 17:44:40 -0700732 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
733 // re-register as it may be a new IccCard
734 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
735 SubscriptionManager.INVALID_PHONE_INDEX);
736 if (SubscriptionManager.isValidPhoneId(phoneId)) {
737 PhoneUtils.unregisterIccStatus(mHandler, phoneId);
738 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED, phoneId);
739 }
Nazish Tabassum160d2112019-12-23 17:31:33 +0530740 String iccStatus = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
741 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
742 new EventSimStateChangedBag(phoneId, iccStatus)));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700743 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
744 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800745 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
746 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700747 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
748 handleServiceStateChanged(intent);
749 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530750 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530751 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530752 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
753 if (phoneInEcm != null) {
754 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
755 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
756 // Start Emergency Callback Mode service
Daniel Bright30efde42020-01-09 22:11:15 -0800757 if (intent.getBooleanExtra(
758 TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530759 context.startService(new Intent(context,
760 EmergencyCallbackModeService.class));
761 } else {
762 phoneInEcm = null;
763 }
764 } else {
765 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
766 // on a device that doesn't support ECM in the first place.
767 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
768 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
769 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700770 }
771 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530772 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700773 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700774 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
775 // Roaming status could be overridden by carrier config, so we need to update it.
776 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
777 updateDataRoamingStatus();
chen xubaf9fe52019-07-02 17:28:24 -0700778 updateLimitedSimFunctionForDualSim();
Lei Liu863eac02020-06-24 20:12:55 +0800779 int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
780 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
781 if (SubscriptionManager.isValidSubscriptionId(subId)) {
782 mHandler.sendMessage(mHandler.obtainMessage(EVENT_CARRIER_CONFIG_CHANGED,
783 new Integer(subId)));
784 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700785 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
786 // We also need to pay attention when default data subscription changes.
787 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
788 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
789 registerSettingsObserver();
790 Phone phone = getPhone(mDefaultDataSubId);
791 if (phone != null) {
792 updateDataRoamingStatus();
793 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700794 }
795 }
796 }
797
Brad Ebinger28626122017-08-10 14:13:35 -0700798 private class SipReceiver extends BroadcastReceiver {
799
800 @Override
801 public void onReceive(Context context, Intent intent) {
802 String action = intent.getAction();
803
804 SipAccountRegistry sipAccountRegistry = SipAccountRegistry.getInstance();
805 if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
806 SipUtil.startSipService();
807 } else if (action.equals(SipManager.ACTION_SIP_SERVICE_UP)
808 || action.equals(SipManager.ACTION_SIP_CALL_OPTION_CHANGED)) {
809 sipAccountRegistry.setup(context);
Grace Jiab95592a2020-01-15 14:12:24 -0800810 } else if (action.equals(SipManager.ACTION_SIP_REMOVE_PROFILE)) {
Brad Ebinger28626122017-08-10 14:13:35 -0700811 if (DBG) {
812 Log.d(LOG_TAG, "SIP_REMOVE_PHONE "
813 + intent.getStringExtra(SipManager.EXTRA_LOCAL_URI));
814 }
815 sipAccountRegistry.removeSipProfile(intent.getStringExtra(
816 SipManager.EXTRA_LOCAL_URI));
817 } else {
818 if (DBG) Log.d(LOG_TAG, "onReceive, action not processed: " + action);
819 }
820 }
821 }
822
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700823 private void handleServiceStateChanged(Intent intent) {
824 /**
825 * This used to handle updating EriTextWidgetProvider this routine
826 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
827 * be removed. But leaving just in case it might be needed in the near
828 * future.
829 */
830
Jack Yu1a2fc352017-07-14 17:14:37 -0700831 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700832 // If service just returned, start sending out the queued messages
Santos Cordonc593d002015-06-03 15:41:15 -0700833 Bundle extras = intent.getExtras();
834 if (extras != null) {
835 ServiceState ss = ServiceState.newFromBundle(extras);
836 if (ss != null) {
837 int state = ss.getState();
Jayachandran C2ef9a482017-05-12 22:07:47 -0700838 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
839 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
840 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -0700841
842 if (VDBG) {
843 Log.v(LOG_TAG, "subId=" + subId + ",mDefaultDataSubId="
844 + mDefaultDataSubId + ",ss roaming=" + ss.getDataRoaming());
845 }
846 if (subId == mDefaultDataSubId) {
847 updateDataRoamingStatus();
848 }
Santos Cordonc593d002015-06-03 15:41:15 -0700849 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700850 }
851 }
852
Jack Yu1a2fc352017-07-14 17:14:37 -0700853 /**
Jordan Liuff2ccd72019-07-23 15:54:41 -0700854 * @return whether or not we should show a notification when connecting to data roaming if the
855 * user has data roaming enabled
856 */
857 private boolean shouldShowDataConnectedRoaming(int subId) {
858 PersistableBundle config = getCarrierConfigForSubId(subId);
859 return config.getBoolean(CarrierConfigManager
860 .KEY_SHOW_DATA_CONNECTED_ROAMING_NOTIFICATION_BOOL);
861 }
862
863 /**
Jack Yu1a2fc352017-07-14 17:14:37 -0700864 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
865 * to notify the user so they can enable it through settings. Vise versa if the condition
866 * changes, we need to dismiss the notification.
867 */
868 private void updateDataRoamingStatus() {
869 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
870 Phone phone = getPhone(mDefaultDataSubId);
871 if (phone == null) {
872 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
873 return;
874 }
875
876 DataConnectionReasons reasons = new DataConnectionReasons();
Jack Yu311536f2018-11-26 11:20:48 -0800877 boolean dataAllowed = phone.isDataAllowed(ApnSetting.TYPE_DEFAULT, reasons);
Jack Yu1a2fc352017-07-14 17:14:37 -0700878 mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons);
879 if (VDBG) Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons);
Jordan Liuff2ccd72019-07-23 15:54:41 -0700880 if (!dataAllowed && reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED)) {
881 // No need to show it again if we never cancelled it explicitly.
882 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_DISCONNECTED) return;
Jack Yu1a2fc352017-07-14 17:14:37 -0700883 // If the only reason of no data is data roaming disabled, then we notify the user
884 // so the user can turn on data roaming.
Jordan Liuff2ccd72019-07-23 15:54:41 -0700885 mPrevRoamingNotification = ROAMING_NOTIFICATION_DISCONNECTED;
Jack Yu1a2fc352017-07-14 17:14:37 -0700886 Log.d(LOG_TAG, "Show roaming disconnected notification");
Jordan Liuff2ccd72019-07-23 15:54:41 -0700887 mDataRoamingNotifLog.log("Show roaming off.");
Pengquan Meng8783d932017-10-16 14:57:40 -0700888 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_DISCONNECTED);
889 msg.arg1 = mDefaultDataSubId;
890 msg.sendToTarget();
Jordan Liuff2ccd72019-07-23 15:54:41 -0700891 } else if (dataAllowed && dataIsNowRoaming(mDefaultDataSubId)
892 && shouldShowDataConnectedRoaming(mDefaultDataSubId)) {
893 // No need to show it again if we never cancelled it explicitly, or carrier config
894 // indicates this is not needed.
895 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_CONNECTED) return;
896 mPrevRoamingNotification = ROAMING_NOTIFICATION_CONNECTED;
897 Log.d(LOG_TAG, "Show roaming connected notification");
898 mDataRoamingNotifLog.log("Show roaming on.");
899 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_CONNECTED);
900 msg.arg1 = mDefaultDataSubId;
901 msg.sendToTarget();
902 } else if (mPrevRoamingNotification != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
903 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
904 // is not the only data disable reason. In this case we dismiss the notification we
905 // showed earlier.
906 mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
907 Log.d(LOG_TAG, "Dismiss roaming notification");
Jack Yu1a2fc352017-07-14 17:14:37 -0700908 mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed + ", reasons=" + reasons);
909 mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
910 }
911 }
912
Jordan Liuff2ccd72019-07-23 15:54:41 -0700913 /**
914 *
915 * @param subId to check roaming on
916 * @return whether we have transitioned to dataRoaming
917 */
918 private boolean dataIsNowRoaming(int subId) {
919 return getPhone(subId).getServiceState().getDataRoaming();
920 }
921
chen xubaf9fe52019-07-02 17:28:24 -0700922 private void updateLimitedSimFunctionForDualSim() {
923 if (DBG) Log.d(LOG_TAG, "updateLimitedSimFunctionForDualSim");
924 // check conditions to display limited SIM function notification under dual SIM
925 SubscriptionManager subMgr = (SubscriptionManager) getSystemService(
926 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
927 List<SubscriptionInfo> subList = subMgr.getActiveSubscriptionInfoList(false);
928 if (subList != null && subList.size() > 1) {
929 CarrierConfigManager configMgr = (CarrierConfigManager)
930 getSystemService(Context.CARRIER_CONFIG_SERVICE);
931 for (SubscriptionInfo info : subList) {
932 PersistableBundle b = configMgr.getConfigForSubId(info.getSubscriptionId());
933 if (b != null) {
934 if (b.getBoolean(CarrierConfigManager
935 .KEY_LIMITED_SIM_FUNCTION_NOTIFICATION_FOR_DSDS_BOOL)) {
936 notificationMgr.showLimitedSimFunctionWarningNotification(
937 info.getSubscriptionId(),
938 info.getDisplayName().toString());
939 } else {
940 notificationMgr.dismissLimitedSimFunctionWarningNotification(
941 info.getSubscriptionId());
942 }
943 }
944 }
945 } else {
946 // cancel notifications for all subs
947 notificationMgr.dismissLimitedSimFunctionWarningNotification(
948 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
949 }
950 notificationMgr.dismissLimitedSimFunctionWarningNotificationForInactiveSubs();
951
952 }
953
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530954 public Phone getPhoneInEcm() {
955 return phoneInEcm;
956 }
957
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700958 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800959 * Triggers a refresh of the message waiting (voicemail) indicator.
960 *
961 * @param subId the subscription id we should refresh the notification for.
962 */
963 public void refreshMwiIndicator(int subId) {
964 notificationMgr.refreshMwi(subId);
965 }
966
967 /**
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700968 * Called when the network selection on the subscription {@code subId} is changed by the user.
969 *
970 * @param subId the subscription id.
971 */
972 public void onNetworkSelectionChanged(int subId) {
973 Phone phone = getPhone(subId);
974 if (phone != null) {
975 notificationMgr.updateNetworkSelection(phone.getServiceState().getState(), subId);
976 } else {
977 Log.w(LOG_TAG, "onNetworkSelectionChanged on null phone, subId: " + subId);
978 }
979 }
980
981 /**
James.cf Lin4b784aa2021-01-31 03:25:15 +0800982 * @return whether the device supports RCS User Capability Exchange or not.
983 */
984 public boolean getDeviceUceEnabled() {
985 return (mTelephonyRcsService == null) ? false : mTelephonyRcsService.isDeviceUceEnabled();
986 }
987
988 /**
989 * Set the device supports RCS User Capability Exchange.
990 * @param isEnabled true if the device supports UCE.
991 */
992 public void setDeviceUceEnabled(boolean isEnabled) {
993 if (mTelephonyRcsService != null) {
994 mTelephonyRcsService.setDeviceUceEnabled(isEnabled);
995 }
996 }
997
998 /**
Jack Yu1a2fc352017-07-14 17:14:37 -0700999 * Dump the state of the object, add calls to other objects as desired.
1000 *
1001 * @param fd File descriptor
1002 * @param printWriter Print writer
1003 * @param args Arguments
1004 */
1005 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
1006 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
1007 pw.println("------- PhoneGlobals -------");
1008 pw.increaseIndent();
Jordan Liuff2ccd72019-07-23 15:54:41 -07001009 pw.println("mPrevRoamingNotification=" + mPrevRoamingNotification);
Jack Yu1a2fc352017-07-14 17:14:37 -07001010 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
1011 pw.println("mDataRoamingNotifLog:");
Keun young Parkdebb8532019-05-30 16:35:27 -07001012 pw.println("isSmsCapable=" + TelephonyManager.from(this).isSmsCapable());
Jack Yu1a2fc352017-07-14 17:14:37 -07001013 pw.increaseIndent();
1014 mDataRoamingNotifLog.dump(fd, pw, args);
1015 pw.decreaseIndent();
Brad Ebinger05f52c22019-12-05 13:03:21 -08001016 pw.println("ImsResolver:");
1017 pw.increaseIndent();
1018 try {
Brad Ebingerc9c432e2021-05-17 20:54:49 +00001019 if (ImsResolver.getInstance() != null) ImsResolver.getInstance().dump(fd, pw, args);
Brad Ebinger05f52c22019-12-05 13:03:21 -08001020 } catch (Exception e) {
1021 e.printStackTrace();
1022 }
1023 pw.decreaseIndent();
Brad Ebingera68a4972020-01-30 17:31:23 -08001024 pw.println("RcsService:");
1025 try {
1026 if (mTelephonyRcsService != null) mTelephonyRcsService.dump(fd, pw, args);
1027 } catch (Exception e) {
1028 e.printStackTrace();
1029 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001030 pw.decreaseIndent();
1031 pw.println("------- End PhoneGlobals -------");
1032 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001033}