blob: 97eb5f536da03fa0cc52ef18bc87f6216ed1e149 [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;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800158 ImsResolver mImsResolver;
James.cf Linc9f35a42020-01-15 02:35:22 +0800159 TelephonyRcsService mTelephonyRcsService;
Andrew Lee9431b832015-03-09 18:46:45 -0700160 public PhoneInterfaceManager phoneMgr;
James.cf Linaf3183c2019-10-24 00:59:00 +0800161 public ImsRcsController imsRcsController;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800162 CarrierConfigLoader configLoader;
Santos Cordon63a84242013-07-23 13:32:52 -0700163
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530164 private Phone phoneInEcm;
Santos Cordon63a84242013-07-23 13:32:52 -0700165
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700166 static boolean sVoiceCapable = true;
167
Santos Cordonc593d002015-06-03 15:41:15 -0700168 // TODO: Remove, no longer used.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700169 CdmaPhoneCallState cdmaPhoneCallState;
170
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171 // The currently-active PUK entry activity and progress dialog.
172 // Normally, these are the Emergency Dialer and the subsequent
173 // progress dialog. null if there is are no such objects in
174 // the foreground.
175 private Activity mPUKEntryActivity;
176 private ProgressDialog mPUKEntryProgressDialog;
177
Jordan Liuff2ccd72019-07-23 15:54:41 -0700178 /** @hide */
179 @Retention(RetentionPolicy.SOURCE)
180 @IntDef(prefix = {"ROAMING_NOTIFICATION_"},
181 value = {
182 ROAMING_NOTIFICATION_NO_NOTIFICATION,
183 ROAMING_NOTIFICATION_CONNECTED,
184 ROAMING_NOTIFICATION_DISCONNECTED})
185 public @interface RoamingNotification {}
186
187 private static final int ROAMING_NOTIFICATION_NO_NOTIFICATION = 0;
188 private static final int ROAMING_NOTIFICATION_CONNECTED = 1;
189 private static final int ROAMING_NOTIFICATION_DISCONNECTED = 2;
190
191 @RoamingNotification
192 private int mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
Jack Yu953f9352017-05-18 14:41:06 -0700193
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194 private WakeState mWakeState = WakeState.SLEEP;
195
196 private PowerManager mPowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197 private PowerManager.WakeLock mWakeLock;
198 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700199 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700200
Jack Yu1a2fc352017-07-14 17:14:37 -0700201 private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
202 private final LocalLog mDataRoamingNotifLog = new LocalLog(50);
203
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700204 // Broadcast receiver for various intent broadcasts (see onCreate())
205 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
Brad Ebinger533c6c12017-08-02 11:38:48 -0700206 // Broadcast receiver for SIP based intents (see onCreate())
Brad Ebinger28626122017-08-10 14:13:35 -0700207 private final SipReceiver mSipReceiver = new SipReceiver();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700208
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700209 private final CarrierVvmPackageInstalledReceiver mCarrierVvmPackageInstalledReceiver =
210 new CarrierVvmPackageInstalledReceiver();
211
Jack Yu1a2fc352017-07-14 17:14:37 -0700212 private final SettingsObserver mSettingsObserver;
213
Nazish Tabassum160d2112019-12-23 17:31:33 +0530214 private static class EventSimStateChangedBag {
215 final int mPhoneId;
216 final String mIccStatus;
217
218 EventSimStateChangedBag(int phoneId, String iccStatus) {
219 mPhoneId = phoneId;
220 mIccStatus = iccStatus;
221 }
222 }
223
Jordan Liu7c105402021-03-24 17:25:46 -0700224 // Some carrier config settings disable the network lock screen, so we call handleSimLock
225 // when either SIM_LOCK or CARRIER_CONFIG changes so that no matter which one happens first,
226 // we still do the right thing
227 private void handleSimLock(int subType, Phone phone) {
228 PersistableBundle cc = getCarrierConfigForSubId(phone.getSubId());
229 if (!CarrierConfigManager.isConfigForIdentifiedCarrier(cc)) {
230 // If we only have the default carrier config just return, to avoid popping up the
231 // the SIM lock screen when it's disabled by the carrier.
232 Log.i(LOG_TAG, "Not showing 'SIM network unlock' screen. Carrier config not loaded");
233 return;
234 }
235 if (cc.getBoolean(CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
236 // Some products don't have the concept of a "SIM network lock"
237 Log.i(LOG_TAG, "Not showing 'SIM network unlock' screen. Disabled by carrier config");
238 return;
239 }
240
241 // if passed in subType is unknown, retrieve it here.
242 if (subType == -1) {
243 final UiccCard uiccCard = phone.getUiccCard();
244 if (uiccCard == null) {
245 Log.e(LOG_TAG,
246 "handleSimLock: uiccCard for phone " + phone.getPhoneId() + " is null");
247 return;
248 }
249 final UiccProfile uiccProfile = uiccCard.getUiccProfile();
250 if (uiccProfile == null) {
251 Log.e(LOG_TAG,
252 "handleSimLock: uiccProfile for phone " + phone.getPhoneId() + " is null");
253 return;
254 }
255 subType = uiccProfile.getApplication(
256 uiccProfile.mCurrentAppType).getPersoSubState().ordinal();
257 }
258 // Normal case: show the "SIM network unlock" PIN entry screen.
259 // The user won't be able to do anything else until
260 // they enter a valid SIM network PIN.
261 Log.i(LOG_TAG, "show sim depersonal panel");
262 IccNetworkDepersonalizationPanel.showDialog(phone, subType);
263 }
264
265 private boolean isSimLocked(Phone phone) {
266 TelephonyManager tm = getSystemService(TelephonyManager.class);
267 return tm.createForSubscriptionId(phone.getSubId()).getSimState()
268 == TelephonyManager.SIM_STATE_NETWORK_LOCKED;
269 }
270
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700271 Handler mHandler = new Handler() {
272 @Override
273 public void handleMessage(Message msg) {
274 PhoneConstants.State phoneState;
Jack Yu1a2fc352017-07-14 17:14:37 -0700275 if (VDBG) Log.v(LOG_TAG, "event=" + msg.what);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700276 switch (msg.what) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700277 // TODO: This event should be handled by the lock screen, just
278 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
279 case EVENT_SIM_NETWORK_LOCKED:
Jordan Liu7c105402021-03-24 17:25:46 -0700280 int subType = (Integer) ((AsyncResult) msg.obj).result;
281 Phone phone = (Phone) ((AsyncResult) msg.obj).userObj;
282 handleSimLock(subType, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700283 break;
284
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700285 case EVENT_DATA_ROAMING_DISCONNECTED:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700286 notificationMgr.showDataRoamingNotification(msg.arg1, false);
287 break;
288
289 case EVENT_DATA_ROAMING_CONNECTED:
290 notificationMgr.showDataRoamingNotification(msg.arg1, true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700291 break;
292
293 case EVENT_DATA_ROAMING_OK:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700294 notificationMgr.hideDataRoamingNotification();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700295 break;
296
297 case MMI_COMPLETE:
298 onMMIComplete((AsyncResult) msg.obj);
299 break;
300
301 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800302 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700303 break;
304
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700305 case EVENT_SIM_STATE_CHANGED:
306 // Marks the event where the SIM goes into ready state.
307 // Right now, this is only used for the PUK-unlocking
308 // process.
Nazish Tabassum160d2112019-12-23 17:31:33 +0530309 EventSimStateChangedBag bag = (EventSimStateChangedBag)msg.obj;
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700310 if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(bag.mIccStatus)
Nazish Tabassum59126a92020-07-03 21:44:49 +0530311 || IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(bag.mIccStatus)
312 || IccCardConstants.INTENT_VALUE_ICC_NOT_READY.equals(bag.mIccStatus)
313 || IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(bag.mIccStatus)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700314 // when the right event is triggered and there
315 // are UI objects in the foreground, we close
316 // them to display the lock panel.
317 if (mPUKEntryActivity != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700318 Log.i(LOG_TAG, "Dismiss puk entry activity");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700319 mPUKEntryActivity.finish();
320 mPUKEntryActivity = null;
321 }
322 if (mPUKEntryProgressDialog != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700323 Log.i(LOG_TAG, "Dismiss puk progress dialog");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700324 mPUKEntryProgressDialog.dismiss();
325 mPUKEntryProgressDialog = null;
326 }
Nazish Tabassum59126a92020-07-03 21:44:49 +0530327 Log.i(LOG_TAG, "Dismissing depersonal panel" + (bag.mIccStatus));
Nazish Tabassum160d2112019-12-23 17:31:33 +0530328 IccNetworkDepersonalizationPanel.dialogDismiss(bag.mPhoneId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700329 }
330 break;
331
332 case EVENT_UNSOL_CDMA_INFO_RECORD:
333 //TODO: handle message here;
334 break;
Brad Ebinger3fa43462016-04-12 16:06:48 -0700335 case EVENT_RESTART_SIP:
336 // This should only run if the Phone process crashed and was restarted. We do
337 // not want this running if the device is still in the FBE encrypted state.
Brad Ebinger28626122017-08-10 14:13:35 -0700338 // This is the same procedure that is triggered in the SipIncomingCallReceiver
Brad Ebinger3fa43462016-04-12 16:06:48 -0700339 // upon BOOT_COMPLETED.
Meng Wangc04cd2d2019-10-04 12:00:06 -0700340 UserManager userManager =
341 (UserManager) sMe.getSystemService(Context.USER_SERVICE);
Brad Ebinger3fa43462016-04-12 16:06:48 -0700342 if (userManager != null && userManager.isUserUnlocked()) {
343 SipUtil.startSipService();
344 }
345 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700346 case EVENT_DATA_ROAMING_SETTINGS_CHANGED:
347 case EVENT_MOBILE_DATA_SETTINGS_CHANGED:
348 updateDataRoamingStatus();
349 break;
Lei Liu863eac02020-06-24 20:12:55 +0800350 case EVENT_CARRIER_CONFIG_CHANGED:
351 int subId = (Integer) msg.obj;
352 // The voicemail number could be overridden by carrier config, so need to
353 // refresh the message waiting (voicemail) indicator.
354 refreshMwiIndicator(subId);
Jordan Liu7c105402021-03-24 17:25:46 -0700355 phone = getPhone(subId);
356 if (phone != null && isSimLocked(phone)) {
357 // pass in subType=-1 so handleSimLock can find the actual subType if
358 // needed. This is safe as valid values for subType are >= 0
359 handleSimLock(-1, phone);
360 }
Lei Liu863eac02020-06-24 20:12:55 +0800361 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362 }
363 }
364 };
365
366 public PhoneGlobals(Context context) {
367 super(context);
368 sMe = this;
Jack Yu1a2fc352017-07-14 17:14:37 -0700369 mSettingsObserver = new SettingsObserver(context, mHandler);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370 }
371
372 public void onCreate() {
373 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
374
375 ContentResolver resolver = getContentResolver();
376
377 // Cache the "voice capable" flag.
378 // This flag currently comes from a resource (which is
379 // overrideable on a per-product basis):
Michele87262742020-01-16 12:23:53 -0800380 sVoiceCapable = ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE))
381 .isVoiceCapable();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382 // ...but this might eventually become a PackageManager "system
383 // feature" instead, in which case we'd do something like:
384 // sVoiceCapable =
385 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
386
Stuart Scottdcf40a92014-12-09 10:45:01 -0800387 if (mCM == null) {
Nathan Haroldf9df6ea2019-03-08 11:54:22 -0800388 // Initialize AnomalyReporter early so that it can be used
389 AnomalyReporter.initialize(this);
Nathan Harold0db5c5e2019-01-22 20:18:56 -0800390
Youming Ye47a6adc2018-11-19 15:33:36 -0800391 // Inject telephony component factory if configured using other jars.
392 XmlResourceParser parser = getResources().getXml(R.xml.telephony_injection);
393 TelephonyComponentFactory.getInstance().injectTheComponentFactory(parser);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394 // Initialize the telephony framework
395 PhoneFactory.makeDefaultPhones(this);
396
Brad Ebinger05f52c22019-12-05 13:03:21 -0800397 // Only bring up ImsResolver if the device supports having an IMS stack.
398 if (getPackageManager().hasSystemFeature(
399 PackageManager.FEATURE_TELEPHONY_IMS)) {
400 // Get the package name of the default IMS implementation.
401 String defaultImsMmtelPackage = getResources().getString(
402 R.string.config_ims_mmtel_package);
403 String defaultImsRcsPackage = getResources().getString(
404 R.string.config_ims_rcs_package);
405 mImsResolver = new ImsResolver(this, defaultImsMmtelPackage,
Brad Ebingere3ae65a2020-09-11 12:45:11 -0700406 defaultImsRcsPackage, PhoneFactory.getPhones().length,
407 new ImsFeatureBinderRepository());
Brad Ebinger05f52c22019-12-05 13:03:21 -0800408 mImsResolver.initialize();
Tyler Gunn92479152021-01-20 16:30:10 -0800409
410 // With the IMS phone created, load static config.xml values from the phone process
411 // so that it can be provided to the ImsPhoneCallTracker.
412 for (Phone p : PhoneFactory.getPhones()) {
413 Phone imsPhone = p.getImsPhone();
414 if (imsPhone != null && imsPhone instanceof ImsPhone) {
415 ImsPhone theImsPhone = (ImsPhone) imsPhone;
416 if (theImsPhone.getCallTracker() instanceof ImsPhoneCallTracker) {
417 ImsPhoneCallTracker ict = (ImsPhoneCallTracker)
418 theImsPhone.getCallTracker();
419
420 ImsPhoneCallTracker.Config config = new ImsPhoneCallTracker.Config();
421 config.isD2DCommunicationSupported = getResources().getBoolean(
422 R.bool.config_use_device_to_device_communication);
423 ict.setConfig(config);
424 }
425 }
426 }
Hui Wang068ab862020-10-31 05:12:53 +0000427 RcsProvisioningMonitor.make(this);
Brad Ebinger05f52c22019-12-05 13:03:21 -0800428 }
429
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700430 // Start TelephonyDebugService After the default phone is created.
431 Intent intent = new Intent(this, TelephonyDebugService.class);
432 startService(intent);
433
434 mCM = CallManager.getInstance();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700435
436 // Create the NotificationMgr singleton, which is used to display
437 // status bar icons and control other status bar behavior.
438 notificationMgr = NotificationMgr.init(this);
439
Brad Ebinger3fa43462016-04-12 16:06:48 -0700440 // If PhoneGlobals has crashed and is being restarted, then restart.
441 mHandler.sendEmptyMessage(EVENT_RESTART_SIP);
442
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700443 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
444 cdmaPhoneCallState = new CdmaPhoneCallState();
445 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700446
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700447 // before registering for phone state changes
448 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
449 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
450 // lock used to keep the processor awake, when we don't care for the display.
451 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
452 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700453
454 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
455
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700456 // Create the CallerInfoCache singleton, which remembers custom ring tone and
457 // send-to-voicemail settings.
458 //
459 // The asynchronous caching will start just after this call.
460 callerInfoCache = CallerInfoCache.init(this);
461
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800462 phoneMgr = PhoneInterfaceManager.init(this);
Santos Cordon406c0342013-08-28 00:07:47 -0700463
James.cf Linaf3183c2019-10-24 00:59:00 +0800464 imsRcsController = ImsRcsController.init(this);
465
James.cf Linc9f35a42020-01-15 02:35:22 +0800466 if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
Brad Ebingera68a4972020-01-30 17:31:23 -0800467 mTelephonyRcsService = new TelephonyRcsService(this,
468 PhoneFactory.getPhones().length);
469 mTelephonyRcsService.initialize();
James.cf Linc9f35a42020-01-15 02:35:22 +0800470 imsRcsController.setRcsService(mTelephonyRcsService);
471 }
472
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800473 configLoader = CarrierConfigLoader.init(this);
474
Jack Yu1a2fc352017-07-14 17:14:37 -0700475 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700476 // asynchronous events from the telephony layer (like
477 // launching the incoming-call UI when an incoming call comes
478 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800479 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700480
Stuart Scottdcf40a92014-12-09 10:45:01 -0800481 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700482
483 // register for MMI/USSD
484 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
485
Qiong Liucc3fe812019-09-23 15:25:44 +0800486 // Initialize cell status using current airplane mode.
487 handleAirplaneModeChange(this, Settings.Global.getInt(getContentResolver(),
488 Settings.Global.AIRPLANE_MODE_ON, AIRPLANE_OFF));
489
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700490 // Register for misc other intent broadcasts.
491 IntentFilter intentFilter =
492 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700493 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
494 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
495 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
496 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700497 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
498 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700499 registerReceiver(mReceiver, intentFilter);
500
Brad Ebinger533c6c12017-08-02 11:38:48 -0700501 IntentFilter sipIntentFilter = new IntentFilter(Intent.ACTION_BOOT_COMPLETED);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700502 sipIntentFilter.addAction(SipManager.ACTION_SIP_SERVICE_UP);
503 sipIntentFilter.addAction(SipManager.ACTION_SIP_CALL_OPTION_CHANGED);
Grace Jiab95592a2020-01-15 14:12:24 -0800504 sipIntentFilter.addAction(SipManager.ACTION_SIP_REMOVE_PROFILE);
Brad Ebinger28626122017-08-10 14:13:35 -0700505 registerReceiver(mSipReceiver, sipIntentFilter);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700506
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700507 mCarrierVvmPackageInstalledReceiver.register(this);
508
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700509 //set the default values for the preferences in the phone.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700510 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700511 }
512
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700513 // XXX pre-load the SimProvider so that it's ready
514 resolver.getType(Uri.parse("content://icc/adn"));
515
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700516 // TODO: Register for Cdma Information Records
517 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
518
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700519 // Read HAC settings and configure audio hardware
520 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800521 int hac = android.provider.Settings.System.getInt(
522 getContentResolver(),
523 android.provider.Settings.System.HEARING_AID,
524 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700525 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Jordan Liuf71aeef2019-08-21 11:46:09 -0700526 audioManager.setParameters(
527 SettingsConstants.HAC_KEY + "=" + (hac == SettingsConstants.HAC_ENABLED
528 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700529 }
Santos Cordonff506f52013-11-21 19:13:19 -0800530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700531
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700532 /**
533 * Returns the singleton instance of the PhoneApp.
534 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800535 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700536 if (sMe == null) {
537 throw new IllegalStateException("No PhoneGlobals here!");
538 }
539 return sMe;
540 }
541
542 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800543 * Returns the default phone.
544 *
Andrew Lee385019f2014-11-24 14:19:50 -0800545 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700546 */
Andrew Lee83383e42014-10-31 12:42:28 -0700547 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800548 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700549 }
550
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800551 public static Phone getPhone(int subId) {
552 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800553 }
554
Brad Ebinger05f52c22019-12-05 13:03:21 -0800555 public ImsResolver getImsResolver() {
556 return mImsResolver;
557 }
558
Santos Cordonde10b752013-09-19 04:11:33 -0700559 /* package */ CallManager getCallManager() {
560 return mCM;
561 }
562
Chris Manton4e9fa912015-06-19 11:26:57 -0700563 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800564 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700565 }
566
Chris Manton4e9fa912015-06-19 11:26:57 -0700567 public PersistableBundle getCarrierConfigForSubId(int subId) {
Philip P. Moltmann0079aae2020-03-05 16:24:02 -0800568 return configLoader.getConfigForSubIdWithFeature(subId, getOpPackageName(),
569 getAttributionTag());
Junda Liu605148f2015-04-28 15:23:40 -0700570 }
571
Jack Yu1a2fc352017-07-14 17:14:37 -0700572 private void registerSettingsObserver() {
573 mSettingsObserver.unobserve();
574 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
575 String mobileDataSetting = Settings.Global.MOBILE_DATA;
576 if (TelephonyManager.getDefault().getSimCount() > 1) {
577 int subId = mDefaultDataSubId;
578 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
579 dataRoamingSetting += subId;
580 mobileDataSetting += subId;
581 }
582 }
583
584 // Listen for user data roaming setting changed event
585 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
586 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
587
588 // Listen for mobile data setting changed event
589 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
590 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
591 }
592
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700593 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700594 * Sets the activity responsible for un-PUK-blocking the device
595 * so that we may close it when we receive a positive result.
596 * mPUKEntryActivity is also used to indicate to the device that
597 * we are trying to un-PUK-lock the phone. In other words, iff
598 * it is NOT null, then we are trying to unlock and waiting for
599 * the SIM to move to READY state.
600 *
601 * @param activity is the activity to close when PUK has
602 * finished unlocking. Can be set to null to indicate the unlock
603 * or SIM READYing process is over.
604 */
605 void setPukEntryActivity(Activity activity) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700606 Log.i(LOG_TAG, "setPukEntryActivity - set to " + (activity == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700607 mPUKEntryActivity = activity;
608 }
609
610 Activity getPUKEntryActivity() {
611 return mPUKEntryActivity;
612 }
613
614 /**
615 * Sets the dialog responsible for notifying the user of un-PUK-
616 * blocking - SIM READYing progress, so that we may dismiss it
617 * when we receive a positive result.
618 *
619 * @param dialog indicates the progress dialog informing the user
620 * of the state of the device. Dismissed upon completion of
621 * READYing process
622 */
623 void setPukEntryProgressDialog(ProgressDialog dialog) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700624 Log.i(LOG_TAG, "setPukEntryProgressDialog - set to "
625 + (dialog == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700626 mPUKEntryProgressDialog = dialog;
627 }
628
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700629 KeyguardManager getKeyguardManager() {
630 return mKeyguardManager;
631 }
632
633 private void onMMIComplete(AsyncResult r) {
634 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
635 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800636 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700637 }
638
fionaxu80126972017-02-01 17:01:26 -0800639 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700640 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700641 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700642 }
643
Chris Mantona09f3632016-02-09 14:48:42 -0800644 private void handleAirplaneModeChange(Context context, int newMode) {
645 int cellState = Settings.Global.getInt(context.getContentResolver(),
646 Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
647 boolean isAirplaneNewlyOn = (newMode == 1);
648 switch (cellState) {
649 case PhoneConstants.CELL_OFF_FLAG:
650 // Airplane mode does not affect the cell radio if user
651 // has turned it off.
652 break;
653 case PhoneConstants.CELL_ON_FLAG:
654 maybeTurnCellOff(context, isAirplaneNewlyOn);
655 break;
656 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
657 maybeTurnCellOn(context, isAirplaneNewlyOn);
658 break;
659 }
Hall Liu7f56e1a2019-07-10 14:41:14 -0700660 for (Phone phone : PhoneFactory.getPhones()) {
661 phone.getServiceStateTracker().onAirplaneModeChanged(isAirplaneNewlyOn);
662 }
Chris Mantona09f3632016-02-09 14:48:42 -0800663 }
664
665 /*
666 * Returns true if the radio must be turned off when entering airplane mode.
667 */
668 private boolean isCellOffInAirplaneMode(Context context) {
669 String airplaneModeRadios = Settings.Global.getString(context.getContentResolver(),
670 Settings.Global.AIRPLANE_MODE_RADIOS);
671 return airplaneModeRadios == null
672 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
673 }
674
675 private void setRadioPowerOff(Context context) {
676 Log.i(LOG_TAG, "Turning radio off - airplane");
677 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
Eric Erfanian945409f2018-02-21 19:26:15 +0000678 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Meng Wang61307622019-10-23 14:08:43 -0700679 TelephonyProperties.airplane_mode_on(true); // true means int value 1
Chris Mantona09f3632016-02-09 14:48:42 -0800680 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
681 PhoneUtils.setRadioPower(false);
682 }
683
684 private void setRadioPowerOn(Context context) {
685 Log.i(LOG_TAG, "Turning radio on - airplane");
686 Settings.Global.putInt(context.getContentResolver(), Settings.Global.CELL_ON,
687 PhoneConstants.CELL_ON_FLAG);
688 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT,
689 1);
Meng Wang61307622019-10-23 14:08:43 -0700690 TelephonyProperties.airplane_mode_on(false); // false means int value 0
Chris Mantona09f3632016-02-09 14:48:42 -0800691 PhoneUtils.setRadioPower(true);
692 }
693
694 private void maybeTurnCellOff(Context context, boolean isAirplaneNewlyOn) {
695 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700696 // If we are trying to turn off the radio, make sure there are no active
697 // emergency calls. If there are, switch airplane mode back to off.
Tyler Gunn900d8fd2018-09-21 09:22:12 -0700698 TelecomManager tm = (TelecomManager) context.getSystemService(TELECOM_SERVICE);
699
700 if (tm != null && tm.isInEmergencyCall()) {
Santos Cordone18902f2016-03-22 17:16:04 -0700701 // Switch airplane mode back to off.
Jordan Liu0e819b12019-08-28 15:33:05 -0700702 ConnectivityManager cm =
703 (ConnectivityManager) context.getSystemService(CONNECTIVITY_SERVICE);
704 cm.setAirplaneMode(false);
Santos Cordone18902f2016-03-22 17:16:04 -0700705 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
706 .show();
707 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Chris Mantona09f3632016-02-09 14:48:42 -0800708 } else if (isCellOffInAirplaneMode(context)) {
709 setRadioPowerOff(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700710 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800711 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700712 }
Chris Mantona09f3632016-02-09 14:48:42 -0800713 }
714 }
715
716 private void maybeTurnCellOn(Context context, boolean isAirplaneNewlyOn) {
717 if (!isAirplaneNewlyOn) {
718 setRadioPowerOn(context);
Santos Cordone18902f2016-03-22 17:16:04 -0700719 }
720 }
721
Santos Cordon593ab382013-08-06 21:58:23 -0700722 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700723 * Receiver for misc intent broadcasts the Phone app cares about.
724 */
725 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
726 @Override
727 public void onReceive(Context context, Intent intent) {
728 String action = intent.getAction();
729 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Santos Cordone18902f2016-03-22 17:16:04 -0700730 int airplaneMode = Settings.Global.getInt(getContentResolver(),
731 Settings.Global.AIRPLANE_MODE_ON, AIRPLANE_OFF);
732 // Treat any non-OFF values as ON.
733 if (airplaneMode != AIRPLANE_OFF) {
734 airplaneMode = AIRPLANE_ON;
735 }
Chris Mantona09f3632016-02-09 14:48:42 -0800736 handleAirplaneModeChange(context, airplaneMode);
Amit Mahajanf5d92c82018-11-02 17:44:40 -0700737 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
738 // re-register as it may be a new IccCard
739 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
740 SubscriptionManager.INVALID_PHONE_INDEX);
741 if (SubscriptionManager.isValidPhoneId(phoneId)) {
742 PhoneUtils.unregisterIccStatus(mHandler, phoneId);
743 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED, phoneId);
744 }
Nazish Tabassum160d2112019-12-23 17:31:33 +0530745 String iccStatus = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
746 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
747 new EventSimStateChangedBag(phoneId, iccStatus)));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700748 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
749 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800750 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
751 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700752 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
753 handleServiceStateChanged(intent);
754 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530755 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530756 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530757 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
758 if (phoneInEcm != null) {
759 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
760 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
761 // Start Emergency Callback Mode service
Daniel Bright30efde42020-01-09 22:11:15 -0800762 if (intent.getBooleanExtra(
763 TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530764 context.startService(new Intent(context,
765 EmergencyCallbackModeService.class));
766 } else {
767 phoneInEcm = null;
768 }
769 } else {
770 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
771 // on a device that doesn't support ECM in the first place.
772 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
773 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
774 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700775 }
776 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530777 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700778 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700779 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
780 // Roaming status could be overridden by carrier config, so we need to update it.
781 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
782 updateDataRoamingStatus();
chen xubaf9fe52019-07-02 17:28:24 -0700783 updateLimitedSimFunctionForDualSim();
Lei Liu863eac02020-06-24 20:12:55 +0800784 int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
785 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
786 if (SubscriptionManager.isValidSubscriptionId(subId)) {
787 mHandler.sendMessage(mHandler.obtainMessage(EVENT_CARRIER_CONFIG_CHANGED,
788 new Integer(subId)));
789 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700790 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
791 // We also need to pay attention when default data subscription changes.
792 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
793 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
794 registerSettingsObserver();
795 Phone phone = getPhone(mDefaultDataSubId);
796 if (phone != null) {
797 updateDataRoamingStatus();
798 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700799 }
800 }
801 }
802
Brad Ebinger28626122017-08-10 14:13:35 -0700803 private class SipReceiver extends BroadcastReceiver {
804
805 @Override
806 public void onReceive(Context context, Intent intent) {
807 String action = intent.getAction();
808
809 SipAccountRegistry sipAccountRegistry = SipAccountRegistry.getInstance();
810 if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
811 SipUtil.startSipService();
812 } else if (action.equals(SipManager.ACTION_SIP_SERVICE_UP)
813 || action.equals(SipManager.ACTION_SIP_CALL_OPTION_CHANGED)) {
814 sipAccountRegistry.setup(context);
Grace Jiab95592a2020-01-15 14:12:24 -0800815 } else if (action.equals(SipManager.ACTION_SIP_REMOVE_PROFILE)) {
Brad Ebinger28626122017-08-10 14:13:35 -0700816 if (DBG) {
817 Log.d(LOG_TAG, "SIP_REMOVE_PHONE "
818 + intent.getStringExtra(SipManager.EXTRA_LOCAL_URI));
819 }
820 sipAccountRegistry.removeSipProfile(intent.getStringExtra(
821 SipManager.EXTRA_LOCAL_URI));
822 } else {
823 if (DBG) Log.d(LOG_TAG, "onReceive, action not processed: " + action);
824 }
825 }
826 }
827
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700828 private void handleServiceStateChanged(Intent intent) {
829 /**
830 * This used to handle updating EriTextWidgetProvider this routine
831 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
832 * be removed. But leaving just in case it might be needed in the near
833 * future.
834 */
835
Jack Yu1a2fc352017-07-14 17:14:37 -0700836 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700837 // If service just returned, start sending out the queued messages
Santos Cordonc593d002015-06-03 15:41:15 -0700838 Bundle extras = intent.getExtras();
839 if (extras != null) {
840 ServiceState ss = ServiceState.newFromBundle(extras);
841 if (ss != null) {
842 int state = ss.getState();
Jayachandran C2ef9a482017-05-12 22:07:47 -0700843 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
844 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
845 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -0700846
847 if (VDBG) {
848 Log.v(LOG_TAG, "subId=" + subId + ",mDefaultDataSubId="
849 + mDefaultDataSubId + ",ss roaming=" + ss.getDataRoaming());
850 }
851 if (subId == mDefaultDataSubId) {
852 updateDataRoamingStatus();
853 }
Santos Cordonc593d002015-06-03 15:41:15 -0700854 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700855 }
856 }
857
Jack Yu1a2fc352017-07-14 17:14:37 -0700858 /**
Jordan Liuff2ccd72019-07-23 15:54:41 -0700859 * @return whether or not we should show a notification when connecting to data roaming if the
860 * user has data roaming enabled
861 */
862 private boolean shouldShowDataConnectedRoaming(int subId) {
863 PersistableBundle config = getCarrierConfigForSubId(subId);
864 return config.getBoolean(CarrierConfigManager
865 .KEY_SHOW_DATA_CONNECTED_ROAMING_NOTIFICATION_BOOL);
866 }
867
868 /**
Jack Yu1a2fc352017-07-14 17:14:37 -0700869 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
870 * to notify the user so they can enable it through settings. Vise versa if the condition
871 * changes, we need to dismiss the notification.
872 */
873 private void updateDataRoamingStatus() {
874 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
875 Phone phone = getPhone(mDefaultDataSubId);
876 if (phone == null) {
877 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
878 return;
879 }
880
881 DataConnectionReasons reasons = new DataConnectionReasons();
Jack Yu311536f2018-11-26 11:20:48 -0800882 boolean dataAllowed = phone.isDataAllowed(ApnSetting.TYPE_DEFAULT, reasons);
Jack Yu1a2fc352017-07-14 17:14:37 -0700883 mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons);
884 if (VDBG) Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons);
Jordan Liuff2ccd72019-07-23 15:54:41 -0700885 if (!dataAllowed && reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED)) {
886 // No need to show it again if we never cancelled it explicitly.
887 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_DISCONNECTED) return;
Jack Yu1a2fc352017-07-14 17:14:37 -0700888 // If the only reason of no data is data roaming disabled, then we notify the user
889 // so the user can turn on data roaming.
Jordan Liuff2ccd72019-07-23 15:54:41 -0700890 mPrevRoamingNotification = ROAMING_NOTIFICATION_DISCONNECTED;
Jack Yu1a2fc352017-07-14 17:14:37 -0700891 Log.d(LOG_TAG, "Show roaming disconnected notification");
Jordan Liuff2ccd72019-07-23 15:54:41 -0700892 mDataRoamingNotifLog.log("Show roaming off.");
Pengquan Meng8783d932017-10-16 14:57:40 -0700893 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_DISCONNECTED);
894 msg.arg1 = mDefaultDataSubId;
895 msg.sendToTarget();
Jordan Liuff2ccd72019-07-23 15:54:41 -0700896 } else if (dataAllowed && dataIsNowRoaming(mDefaultDataSubId)
897 && shouldShowDataConnectedRoaming(mDefaultDataSubId)) {
898 // No need to show it again if we never cancelled it explicitly, or carrier config
899 // indicates this is not needed.
900 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_CONNECTED) return;
901 mPrevRoamingNotification = ROAMING_NOTIFICATION_CONNECTED;
902 Log.d(LOG_TAG, "Show roaming connected notification");
903 mDataRoamingNotifLog.log("Show roaming on.");
904 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_CONNECTED);
905 msg.arg1 = mDefaultDataSubId;
906 msg.sendToTarget();
907 } else if (mPrevRoamingNotification != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
908 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
909 // is not the only data disable reason. In this case we dismiss the notification we
910 // showed earlier.
911 mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
912 Log.d(LOG_TAG, "Dismiss roaming notification");
Jack Yu1a2fc352017-07-14 17:14:37 -0700913 mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed + ", reasons=" + reasons);
914 mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
915 }
916 }
917
Jordan Liuff2ccd72019-07-23 15:54:41 -0700918 /**
919 *
920 * @param subId to check roaming on
921 * @return whether we have transitioned to dataRoaming
922 */
923 private boolean dataIsNowRoaming(int subId) {
924 return getPhone(subId).getServiceState().getDataRoaming();
925 }
926
chen xubaf9fe52019-07-02 17:28:24 -0700927 private void updateLimitedSimFunctionForDualSim() {
928 if (DBG) Log.d(LOG_TAG, "updateLimitedSimFunctionForDualSim");
929 // check conditions to display limited SIM function notification under dual SIM
930 SubscriptionManager subMgr = (SubscriptionManager) getSystemService(
931 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
932 List<SubscriptionInfo> subList = subMgr.getActiveSubscriptionInfoList(false);
933 if (subList != null && subList.size() > 1) {
934 CarrierConfigManager configMgr = (CarrierConfigManager)
935 getSystemService(Context.CARRIER_CONFIG_SERVICE);
936 for (SubscriptionInfo info : subList) {
937 PersistableBundle b = configMgr.getConfigForSubId(info.getSubscriptionId());
938 if (b != null) {
939 if (b.getBoolean(CarrierConfigManager
940 .KEY_LIMITED_SIM_FUNCTION_NOTIFICATION_FOR_DSDS_BOOL)) {
941 notificationMgr.showLimitedSimFunctionWarningNotification(
942 info.getSubscriptionId(),
943 info.getDisplayName().toString());
944 } else {
945 notificationMgr.dismissLimitedSimFunctionWarningNotification(
946 info.getSubscriptionId());
947 }
948 }
949 }
950 } else {
951 // cancel notifications for all subs
952 notificationMgr.dismissLimitedSimFunctionWarningNotification(
953 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
954 }
955 notificationMgr.dismissLimitedSimFunctionWarningNotificationForInactiveSubs();
956
957 }
958
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530959 public Phone getPhoneInEcm() {
960 return phoneInEcm;
961 }
962
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700963 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800964 * Triggers a refresh of the message waiting (voicemail) indicator.
965 *
966 * @param subId the subscription id we should refresh the notification for.
967 */
968 public void refreshMwiIndicator(int subId) {
969 notificationMgr.refreshMwi(subId);
970 }
971
972 /**
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700973 * Called when the network selection on the subscription {@code subId} is changed by the user.
974 *
975 * @param subId the subscription id.
976 */
977 public void onNetworkSelectionChanged(int subId) {
978 Phone phone = getPhone(subId);
979 if (phone != null) {
980 notificationMgr.updateNetworkSelection(phone.getServiceState().getState(), subId);
981 } else {
982 Log.w(LOG_TAG, "onNetworkSelectionChanged on null phone, subId: " + subId);
983 }
984 }
985
986 /**
James.cf Lin4b784aa2021-01-31 03:25:15 +0800987 * @return whether the device supports RCS User Capability Exchange or not.
988 */
989 public boolean getDeviceUceEnabled() {
990 return (mTelephonyRcsService == null) ? false : mTelephonyRcsService.isDeviceUceEnabled();
991 }
992
993 /**
994 * Set the device supports RCS User Capability Exchange.
995 * @param isEnabled true if the device supports UCE.
996 */
997 public void setDeviceUceEnabled(boolean isEnabled) {
998 if (mTelephonyRcsService != null) {
999 mTelephonyRcsService.setDeviceUceEnabled(isEnabled);
1000 }
1001 }
1002
1003 /**
Jack Yu1a2fc352017-07-14 17:14:37 -07001004 * Dump the state of the object, add calls to other objects as desired.
1005 *
1006 * @param fd File descriptor
1007 * @param printWriter Print writer
1008 * @param args Arguments
1009 */
1010 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
1011 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
1012 pw.println("------- PhoneGlobals -------");
1013 pw.increaseIndent();
Jordan Liuff2ccd72019-07-23 15:54:41 -07001014 pw.println("mPrevRoamingNotification=" + mPrevRoamingNotification);
Jack Yu1a2fc352017-07-14 17:14:37 -07001015 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
1016 pw.println("mDataRoamingNotifLog:");
Keun young Parkdebb8532019-05-30 16:35:27 -07001017 pw.println("isSmsCapable=" + TelephonyManager.from(this).isSmsCapable());
Jack Yu1a2fc352017-07-14 17:14:37 -07001018 pw.increaseIndent();
1019 mDataRoamingNotifLog.dump(fd, pw, args);
1020 pw.decreaseIndent();
Brad Ebinger05f52c22019-12-05 13:03:21 -08001021 pw.println("ImsResolver:");
1022 pw.increaseIndent();
1023 try {
1024 if (mImsResolver != null) mImsResolver.dump(fd, pw, args);
1025 } catch (Exception e) {
1026 e.printStackTrace();
1027 }
1028 pw.decreaseIndent();
Brad Ebingera68a4972020-01-30 17:31:23 -08001029 pw.println("RcsService:");
1030 try {
1031 if (mTelephonyRcsService != null) mTelephonyRcsService.dump(fd, pw, args);
1032 } catch (Exception e) {
1033 e.printStackTrace();
1034 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001035 pw.decreaseIndent();
1036 pw.println("------- End PhoneGlobals -------");
1037 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001038}