blob: c4686db4ce81d8f3465476c9fc65f6396336f810 [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;
Santos Cordon63a84242013-07-23 13:32:52 -0700156 NotificationMgr notificationMgr;
James.cf Linc9f35a42020-01-15 02:35:22 +0800157 TelephonyRcsService mTelephonyRcsService;
Andrew Lee9431b832015-03-09 18:46:45 -0700158 public PhoneInterfaceManager phoneMgr;
James.cf Linaf3183c2019-10-24 00:59:00 +0800159 public ImsRcsController imsRcsController;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800160 CarrierConfigLoader configLoader;
Santos Cordon63a84242013-07-23 13:32:52 -0700161
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530162 private Phone phoneInEcm;
Santos Cordon63a84242013-07-23 13:32:52 -0700163
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700164 static boolean sVoiceCapable = true;
165
Santos Cordonc593d002015-06-03 15:41:15 -0700166 // TODO: Remove, no longer used.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700167 CdmaPhoneCallState cdmaPhoneCallState;
168
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700169 // The currently-active PUK entry activity and progress dialog.
170 // Normally, these are the Emergency Dialer and the subsequent
171 // progress dialog. null if there is are no such objects in
172 // the foreground.
173 private Activity mPUKEntryActivity;
174 private ProgressDialog mPUKEntryProgressDialog;
175
Jordan Liuff2ccd72019-07-23 15:54:41 -0700176 /** @hide */
177 @Retention(RetentionPolicy.SOURCE)
178 @IntDef(prefix = {"ROAMING_NOTIFICATION_"},
179 value = {
180 ROAMING_NOTIFICATION_NO_NOTIFICATION,
181 ROAMING_NOTIFICATION_CONNECTED,
182 ROAMING_NOTIFICATION_DISCONNECTED})
183 public @interface RoamingNotification {}
184
185 private static final int ROAMING_NOTIFICATION_NO_NOTIFICATION = 0;
186 private static final int ROAMING_NOTIFICATION_CONNECTED = 1;
187 private static final int ROAMING_NOTIFICATION_DISCONNECTED = 2;
188
189 @RoamingNotification
190 private int mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
Jack Yu953f9352017-05-18 14:41:06 -0700191
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192 private WakeState mWakeState = WakeState.SLEEP;
193
194 private PowerManager mPowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195 private PowerManager.WakeLock mWakeLock;
196 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198
Jack Yu1a2fc352017-07-14 17:14:37 -0700199 private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
200 private final LocalLog mDataRoamingNotifLog = new LocalLog(50);
201
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700202 // Broadcast receiver for various intent broadcasts (see onCreate())
203 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
Brad Ebinger533c6c12017-08-02 11:38:48 -0700204 // Broadcast receiver for SIP based intents (see onCreate())
Brad Ebinger28626122017-08-10 14:13:35 -0700205 private final SipReceiver mSipReceiver = new SipReceiver();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700206
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700207 private final CarrierVvmPackageInstalledReceiver mCarrierVvmPackageInstalledReceiver =
208 new CarrierVvmPackageInstalledReceiver();
209
Jack Yu1a2fc352017-07-14 17:14:37 -0700210 private final SettingsObserver mSettingsObserver;
211
Nazish Tabassum160d2112019-12-23 17:31:33 +0530212 private static class EventSimStateChangedBag {
213 final int mPhoneId;
214 final String mIccStatus;
215
216 EventSimStateChangedBag(int phoneId, String iccStatus) {
217 mPhoneId = phoneId;
218 mIccStatus = iccStatus;
219 }
220 }
221
Jordan Liu7c105402021-03-24 17:25:46 -0700222 // Some carrier config settings disable the network lock screen, so we call handleSimLock
223 // when either SIM_LOCK or CARRIER_CONFIG changes so that no matter which one happens first,
224 // we still do the right thing
225 private void handleSimLock(int subType, Phone phone) {
226 PersistableBundle cc = getCarrierConfigForSubId(phone.getSubId());
227 if (!CarrierConfigManager.isConfigForIdentifiedCarrier(cc)) {
228 // If we only have the default carrier config just return, to avoid popping up the
229 // the SIM lock screen when it's disabled by the carrier.
230 Log.i(LOG_TAG, "Not showing 'SIM network unlock' screen. Carrier config not loaded");
231 return;
232 }
233 if (cc.getBoolean(CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
234 // Some products don't have the concept of a "SIM network lock"
235 Log.i(LOG_TAG, "Not showing 'SIM network unlock' screen. Disabled by carrier config");
236 return;
237 }
238
239 // if passed in subType is unknown, retrieve it here.
240 if (subType == -1) {
241 final UiccCard uiccCard = phone.getUiccCard();
242 if (uiccCard == null) {
243 Log.e(LOG_TAG,
244 "handleSimLock: uiccCard for phone " + phone.getPhoneId() + " is null");
245 return;
246 }
247 final UiccProfile uiccProfile = uiccCard.getUiccProfile();
248 if (uiccProfile == null) {
249 Log.e(LOG_TAG,
250 "handleSimLock: uiccProfile for phone " + phone.getPhoneId() + " is null");
251 return;
252 }
253 subType = uiccProfile.getApplication(
254 uiccProfile.mCurrentAppType).getPersoSubState().ordinal();
255 }
256 // Normal case: show the "SIM network unlock" PIN entry screen.
257 // The user won't be able to do anything else until
258 // they enter a valid SIM network PIN.
259 Log.i(LOG_TAG, "show sim depersonal panel");
260 IccNetworkDepersonalizationPanel.showDialog(phone, subType);
261 }
262
263 private boolean isSimLocked(Phone phone) {
264 TelephonyManager tm = getSystemService(TelephonyManager.class);
265 return tm.createForSubscriptionId(phone.getSubId()).getSimState()
266 == TelephonyManager.SIM_STATE_NETWORK_LOCKED;
267 }
268
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269 Handler mHandler = new Handler() {
270 @Override
271 public void handleMessage(Message msg) {
272 PhoneConstants.State phoneState;
Jack Yu1a2fc352017-07-14 17:14:37 -0700273 if (VDBG) Log.v(LOG_TAG, "event=" + msg.what);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700274 switch (msg.what) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275 // TODO: This event should be handled by the lock screen, just
276 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
277 case EVENT_SIM_NETWORK_LOCKED:
Jordan Liu7c105402021-03-24 17:25:46 -0700278 int subType = (Integer) ((AsyncResult) msg.obj).result;
279 Phone phone = (Phone) ((AsyncResult) msg.obj).userObj;
280 handleSimLock(subType, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700281 break;
282
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700283 case EVENT_DATA_ROAMING_DISCONNECTED:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700284 notificationMgr.showDataRoamingNotification(msg.arg1, false);
285 break;
286
287 case EVENT_DATA_ROAMING_CONNECTED:
288 notificationMgr.showDataRoamingNotification(msg.arg1, true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700289 break;
290
291 case EVENT_DATA_ROAMING_OK:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700292 notificationMgr.hideDataRoamingNotification();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700293 break;
294
295 case MMI_COMPLETE:
296 onMMIComplete((AsyncResult) msg.obj);
297 break;
298
299 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800300 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700301 break;
302
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700303 case EVENT_SIM_STATE_CHANGED:
304 // Marks the event where the SIM goes into ready state.
305 // Right now, this is only used for the PUK-unlocking
306 // process.
Nazish Tabassum160d2112019-12-23 17:31:33 +0530307 EventSimStateChangedBag bag = (EventSimStateChangedBag)msg.obj;
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700308 if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(bag.mIccStatus)
Nazish Tabassum59126a92020-07-03 21:44:49 +0530309 || IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(bag.mIccStatus)
310 || IccCardConstants.INTENT_VALUE_ICC_NOT_READY.equals(bag.mIccStatus)
311 || IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(bag.mIccStatus)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700312 // when the right event is triggered and there
313 // are UI objects in the foreground, we close
314 // them to display the lock panel.
315 if (mPUKEntryActivity != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700316 Log.i(LOG_TAG, "Dismiss puk entry activity");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700317 mPUKEntryActivity.finish();
318 mPUKEntryActivity = null;
319 }
320 if (mPUKEntryProgressDialog != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700321 Log.i(LOG_TAG, "Dismiss puk progress dialog");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700322 mPUKEntryProgressDialog.dismiss();
323 mPUKEntryProgressDialog = null;
324 }
Nazish Tabassum59126a92020-07-03 21:44:49 +0530325 Log.i(LOG_TAG, "Dismissing depersonal panel" + (bag.mIccStatus));
Nazish Tabassum160d2112019-12-23 17:31:33 +0530326 IccNetworkDepersonalizationPanel.dialogDismiss(bag.mPhoneId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700327 }
328 break;
329
330 case EVENT_UNSOL_CDMA_INFO_RECORD:
331 //TODO: handle message here;
332 break;
Brad Ebinger3fa43462016-04-12 16:06:48 -0700333 case EVENT_RESTART_SIP:
334 // This should only run if the Phone process crashed and was restarted. We do
335 // not want this running if the device is still in the FBE encrypted state.
Brad Ebinger28626122017-08-10 14:13:35 -0700336 // This is the same procedure that is triggered in the SipIncomingCallReceiver
Brad Ebinger3fa43462016-04-12 16:06:48 -0700337 // upon BOOT_COMPLETED.
Meng Wangc04cd2d2019-10-04 12:00:06 -0700338 UserManager userManager =
339 (UserManager) sMe.getSystemService(Context.USER_SERVICE);
Brad Ebinger3fa43462016-04-12 16:06:48 -0700340 if (userManager != null && userManager.isUserUnlocked()) {
341 SipUtil.startSipService();
342 }
343 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700344 case EVENT_DATA_ROAMING_SETTINGS_CHANGED:
345 case EVENT_MOBILE_DATA_SETTINGS_CHANGED:
346 updateDataRoamingStatus();
347 break;
Lei Liu863eac02020-06-24 20:12:55 +0800348 case EVENT_CARRIER_CONFIG_CHANGED:
349 int subId = (Integer) msg.obj;
350 // The voicemail number could be overridden by carrier config, so need to
351 // refresh the message waiting (voicemail) indicator.
352 refreshMwiIndicator(subId);
Jordan Liu7c105402021-03-24 17:25:46 -0700353 phone = getPhone(subId);
354 if (phone != null && isSimLocked(phone)) {
355 // pass in subType=-1 so handleSimLock can find the actual subType if
356 // needed. This is safe as valid values for subType are >= 0
357 handleSimLock(-1, phone);
358 }
Lei Liu863eac02020-06-24 20:12:55 +0800359 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360 }
361 }
362 };
363
364 public PhoneGlobals(Context context) {
365 super(context);
366 sMe = this;
Jack Yu1a2fc352017-07-14 17:14:37 -0700367 mSettingsObserver = new SettingsObserver(context, mHandler);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700368 }
369
370 public void onCreate() {
371 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
372
373 ContentResolver resolver = getContentResolver();
374
375 // Cache the "voice capable" flag.
376 // This flag currently comes from a resource (which is
377 // overrideable on a per-product basis):
Michele87262742020-01-16 12:23:53 -0800378 sVoiceCapable = ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE))
379 .isVoiceCapable();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380 // ...but this might eventually become a PackageManager "system
381 // feature" instead, in which case we'd do something like:
382 // sVoiceCapable =
383 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
384
Stuart Scottdcf40a92014-12-09 10:45:01 -0800385 if (mCM == null) {
Nathan Haroldf9df6ea2019-03-08 11:54:22 -0800386 // Initialize AnomalyReporter early so that it can be used
387 AnomalyReporter.initialize(this);
Nathan Harold0db5c5e2019-01-22 20:18:56 -0800388
Youming Ye47a6adc2018-11-19 15:33:36 -0800389 // Inject telephony component factory if configured using other jars.
390 XmlResourceParser parser = getResources().getXml(R.xml.telephony_injection);
391 TelephonyComponentFactory.getInstance().injectTheComponentFactory(parser);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700392 // Initialize the telephony framework
393 PhoneFactory.makeDefaultPhones(this);
394
Brad Ebinger05f52c22019-12-05 13:03:21 -0800395 // Only bring up ImsResolver if the device supports having an IMS stack.
396 if (getPackageManager().hasSystemFeature(
397 PackageManager.FEATURE_TELEPHONY_IMS)) {
398 // Get the package name of the default IMS implementation.
399 String defaultImsMmtelPackage = getResources().getString(
400 R.string.config_ims_mmtel_package);
401 String defaultImsRcsPackage = getResources().getString(
402 R.string.config_ims_rcs_package);
Brad Ebingerc9c432e2021-05-17 20:54:49 +0000403 ImsResolver.make(this, defaultImsMmtelPackage,
Brad Ebingere3ae65a2020-09-11 12:45:11 -0700404 defaultImsRcsPackage, PhoneFactory.getPhones().length,
405 new ImsFeatureBinderRepository());
Brad Ebingerc9c432e2021-05-17 20:54:49 +0000406 ImsResolver.getInstance().initialize();
Tyler Gunn92479152021-01-20 16:30:10 -0800407
408 // With the IMS phone created, load static config.xml values from the phone process
409 // so that it can be provided to the ImsPhoneCallTracker.
410 for (Phone p : PhoneFactory.getPhones()) {
411 Phone imsPhone = p.getImsPhone();
412 if (imsPhone != null && imsPhone instanceof ImsPhone) {
413 ImsPhone theImsPhone = (ImsPhone) imsPhone;
414 if (theImsPhone.getCallTracker() instanceof ImsPhoneCallTracker) {
415 ImsPhoneCallTracker ict = (ImsPhoneCallTracker)
416 theImsPhone.getCallTracker();
417
418 ImsPhoneCallTracker.Config config = new ImsPhoneCallTracker.Config();
419 config.isD2DCommunicationSupported = getResources().getBoolean(
420 R.bool.config_use_device_to_device_communication);
421 ict.setConfig(config);
422 }
423 }
424 }
Hui Wang068ab862020-10-31 05:12:53 +0000425 RcsProvisioningMonitor.make(this);
Brad Ebinger05f52c22019-12-05 13:03:21 -0800426 }
427
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700428 // Start TelephonyDebugService After the default phone is created.
429 Intent intent = new Intent(this, TelephonyDebugService.class);
430 startService(intent);
431
432 mCM = CallManager.getInstance();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700433
434 // Create the NotificationMgr singleton, which is used to display
435 // status bar icons and control other status bar behavior.
436 notificationMgr = NotificationMgr.init(this);
437
Brad Ebinger3fa43462016-04-12 16:06:48 -0700438 // If PhoneGlobals has crashed and is being restarted, then restart.
439 mHandler.sendEmptyMessage(EVENT_RESTART_SIP);
440
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700441 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
442 cdmaPhoneCallState = new CdmaPhoneCallState();
443 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445 // before registering for phone state changes
446 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
447 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
448 // lock used to keep the processor awake, when we don't care for the display.
449 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
450 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700451
452 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
453
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800454 phoneMgr = PhoneInterfaceManager.init(this);
Santos Cordon406c0342013-08-28 00:07:47 -0700455
James.cf Linaf3183c2019-10-24 00:59:00 +0800456 imsRcsController = ImsRcsController.init(this);
457
James.cf Linc9f35a42020-01-15 02:35:22 +0800458 if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
Brad Ebingera68a4972020-01-30 17:31:23 -0800459 mTelephonyRcsService = new TelephonyRcsService(this,
460 PhoneFactory.getPhones().length);
461 mTelephonyRcsService.initialize();
James.cf Linc9f35a42020-01-15 02:35:22 +0800462 imsRcsController.setRcsService(mTelephonyRcsService);
463 }
464
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800465 configLoader = CarrierConfigLoader.init(this);
466
Jack Yu1a2fc352017-07-14 17:14:37 -0700467 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700468 // asynchronous events from the telephony layer (like
469 // launching the incoming-call UI when an incoming call comes
470 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800471 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700472
Stuart Scottdcf40a92014-12-09 10:45:01 -0800473 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700474
475 // register for MMI/USSD
476 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
477
Qiong Liucc3fe812019-09-23 15:25:44 +0800478 // Initialize cell status using current airplane mode.
Taesu Lee62f826d2020-08-10 16:01:18 +0900479 handleAirplaneModeChange(
480 Settings.Global.getInt(
481 getContentResolver(),
482 Settings.Global.AIRPLANE_MODE_ON,
483 AIRPLANE_OFF)
484 == AIRPLANE_ON);
Qiong Liucc3fe812019-09-23 15:25:44 +0800485
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486 // Register for misc other intent broadcasts.
487 IntentFilter intentFilter =
488 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700489 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
490 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
491 intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
492 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700493 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
494 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700495 registerReceiver(mReceiver, intentFilter);
496
Brad Ebinger533c6c12017-08-02 11:38:48 -0700497 IntentFilter sipIntentFilter = new IntentFilter(Intent.ACTION_BOOT_COMPLETED);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700498 sipIntentFilter.addAction(SipManager.ACTION_SIP_SERVICE_UP);
499 sipIntentFilter.addAction(SipManager.ACTION_SIP_CALL_OPTION_CHANGED);
Grace Jiab95592a2020-01-15 14:12:24 -0800500 sipIntentFilter.addAction(SipManager.ACTION_SIP_REMOVE_PROFILE);
Brad Ebinger28626122017-08-10 14:13:35 -0700501 registerReceiver(mSipReceiver, sipIntentFilter);
Brad Ebinger533c6c12017-08-02 11:38:48 -0700502
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700503 mCarrierVvmPackageInstalledReceiver.register(this);
504
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700505 //set the default values for the preferences in the phone.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700506 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700507 }
508
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700509 // XXX pre-load the SimProvider so that it's ready
510 resolver.getType(Uri.parse("content://icc/adn"));
511
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700512 // TODO: Register for Cdma Information Records
513 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
514
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700515 // Read HAC settings and configure audio hardware
516 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800517 int hac = android.provider.Settings.System.getInt(
518 getContentResolver(),
519 android.provider.Settings.System.HEARING_AID,
520 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700521 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Jordan Liuf71aeef2019-08-21 11:46:09 -0700522 audioManager.setParameters(
523 SettingsConstants.HAC_KEY + "=" + (hac == SettingsConstants.HAC_ENABLED
524 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700525 }
Santos Cordonff506f52013-11-21 19:13:19 -0800526 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700527
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700528 /**
529 * Returns the singleton instance of the PhoneApp.
530 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800531 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700532 if (sMe == null) {
533 throw new IllegalStateException("No PhoneGlobals here!");
534 }
535 return sMe;
536 }
537
538 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800539 * Returns the default phone.
540 *
Andrew Lee385019f2014-11-24 14:19:50 -0800541 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700542 */
Andrew Lee83383e42014-10-31 12:42:28 -0700543 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800544 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700545 }
546
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800547 public static Phone getPhone(int subId) {
548 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800549 }
550
Santos Cordonde10b752013-09-19 04:11:33 -0700551 /* package */ CallManager getCallManager() {
552 return mCM;
553 }
554
Chris Manton4e9fa912015-06-19 11:26:57 -0700555 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800556 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700557 }
558
Chris Manton4e9fa912015-06-19 11:26:57 -0700559 public PersistableBundle getCarrierConfigForSubId(int subId) {
Philip P. Moltmann0079aae2020-03-05 16:24:02 -0800560 return configLoader.getConfigForSubIdWithFeature(subId, getOpPackageName(),
561 getAttributionTag());
Junda Liu605148f2015-04-28 15:23:40 -0700562 }
563
Jack Yu1a2fc352017-07-14 17:14:37 -0700564 private void registerSettingsObserver() {
565 mSettingsObserver.unobserve();
566 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
567 String mobileDataSetting = Settings.Global.MOBILE_DATA;
568 if (TelephonyManager.getDefault().getSimCount() > 1) {
569 int subId = mDefaultDataSubId;
570 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
571 dataRoamingSetting += subId;
572 mobileDataSetting += subId;
573 }
574 }
575
576 // Listen for user data roaming setting changed event
577 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
578 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
579
580 // Listen for mobile data setting changed event
581 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
582 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
583 }
584
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700585 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700586 * Sets the activity responsible for un-PUK-blocking the device
587 * so that we may close it when we receive a positive result.
588 * mPUKEntryActivity is also used to indicate to the device that
589 * we are trying to un-PUK-lock the phone. In other words, iff
590 * it is NOT null, then we are trying to unlock and waiting for
591 * the SIM to move to READY state.
592 *
593 * @param activity is the activity to close when PUK has
594 * finished unlocking. Can be set to null to indicate the unlock
595 * or SIM READYing process is over.
596 */
597 void setPukEntryActivity(Activity activity) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700598 Log.i(LOG_TAG, "setPukEntryActivity - set to " + (activity == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700599 mPUKEntryActivity = activity;
600 }
601
602 Activity getPUKEntryActivity() {
603 return mPUKEntryActivity;
604 }
605
606 /**
607 * Sets the dialog responsible for notifying the user of un-PUK-
608 * blocking - SIM READYing progress, so that we may dismiss it
609 * when we receive a positive result.
610 *
611 * @param dialog indicates the progress dialog informing the user
612 * of the state of the device. Dismissed upon completion of
613 * READYing process
614 */
615 void setPukEntryProgressDialog(ProgressDialog dialog) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700616 Log.i(LOG_TAG, "setPukEntryProgressDialog - set to "
617 + (dialog == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700618 mPUKEntryProgressDialog = dialog;
619 }
620
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700621 KeyguardManager getKeyguardManager() {
622 return mKeyguardManager;
623 }
624
625 private void onMMIComplete(AsyncResult r) {
626 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
627 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800628 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700629 }
630
fionaxu80126972017-02-01 17:01:26 -0800631 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700632 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700633 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700634 }
635
Taesu Lee62f826d2020-08-10 16:01:18 +0900636 private void handleAirplaneModeChange(boolean isAirplaneNewlyOn) {
637 int cellState =
638 Settings.Global.getInt(
639 getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
Chris Mantona09f3632016-02-09 14:48:42 -0800640 switch (cellState) {
641 case PhoneConstants.CELL_OFF_FLAG:
642 // Airplane mode does not affect the cell radio if user
643 // has turned it off.
644 break;
645 case PhoneConstants.CELL_ON_FLAG:
Taesu Lee62f826d2020-08-10 16:01:18 +0900646 maybeTurnCellOff(isAirplaneNewlyOn);
Chris Mantona09f3632016-02-09 14:48:42 -0800647 break;
648 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
Taesu Lee62f826d2020-08-10 16:01:18 +0900649 maybeTurnCellOn(isAirplaneNewlyOn);
Chris Mantona09f3632016-02-09 14:48:42 -0800650 break;
651 }
Hall Liu7f56e1a2019-07-10 14:41:14 -0700652 for (Phone phone : PhoneFactory.getPhones()) {
653 phone.getServiceStateTracker().onAirplaneModeChanged(isAirplaneNewlyOn);
654 }
Chris Mantona09f3632016-02-09 14:48:42 -0800655 }
656
657 /*
658 * Returns true if the radio must be turned off when entering airplane mode.
659 */
Taesu Lee62f826d2020-08-10 16:01:18 +0900660 private boolean isCellOffInAirplaneMode() {
661 String airplaneModeRadios =
662 Settings.Global.getString(
663 getContentResolver(), Settings.Global.AIRPLANE_MODE_RADIOS);
Chris Mantona09f3632016-02-09 14:48:42 -0800664 return airplaneModeRadios == null
665 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
666 }
667
Taesu Lee62f826d2020-08-10 16:01:18 +0900668 private void setRadioPowerOff() {
Chris Mantona09f3632016-02-09 14:48:42 -0800669 Log.i(LOG_TAG, "Turning radio off - airplane");
Taesu Lee62f826d2020-08-10 16:01:18 +0900670 Settings.Global.putInt(
671 getContentResolver(),
672 Settings.Global.CELL_ON,
673 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Chris Mantona09f3632016-02-09 14:48:42 -0800674 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
Taesu Lee62f826d2020-08-10 16:01:18 +0900675 TelephonyProperties.airplane_mode_on(true); // true means int value 1
Chris Mantona09f3632016-02-09 14:48:42 -0800676 PhoneUtils.setRadioPower(false);
677 }
678
Taesu Lee62f826d2020-08-10 16:01:18 +0900679 private void setRadioPowerOn() {
Chris Mantona09f3632016-02-09 14:48:42 -0800680 Log.i(LOG_TAG, "Turning radio on - airplane");
Taesu Lee62f826d2020-08-10 16:01:18 +0900681 Settings.Global.putInt(
682 getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
683 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 1);
Meng Wang61307622019-10-23 14:08:43 -0700684 TelephonyProperties.airplane_mode_on(false); // false means int value 0
Chris Mantona09f3632016-02-09 14:48:42 -0800685 PhoneUtils.setRadioPower(true);
686 }
687
Taesu Lee62f826d2020-08-10 16:01:18 +0900688 private void maybeTurnCellOff(boolean isAirplaneNewlyOn) {
Chris Mantona09f3632016-02-09 14:48:42 -0800689 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700690 // If we are trying to turn off the radio, make sure there are no active
691 // emergency calls. If there are, switch airplane mode back to off.
Taesu Lee62f826d2020-08-10 16:01:18 +0900692 TelecomManager tm = (TelecomManager) getSystemService(TELECOM_SERVICE);
Tyler Gunn900d8fd2018-09-21 09:22:12 -0700693
694 if (tm != null && tm.isInEmergencyCall()) {
Santos Cordone18902f2016-03-22 17:16:04 -0700695 // Switch airplane mode back to off.
Jordan Liu0e819b12019-08-28 15:33:05 -0700696 ConnectivityManager cm =
Taesu Lee62f826d2020-08-10 16:01:18 +0900697 (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
Jordan Liu0e819b12019-08-28 15:33:05 -0700698 cm.setAirplaneMode(false);
Santos Cordone18902f2016-03-22 17:16:04 -0700699 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
700 .show();
701 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Taesu Lee62f826d2020-08-10 16:01:18 +0900702 } else if (isCellOffInAirplaneMode()) {
703 setRadioPowerOff();
Santos Cordone18902f2016-03-22 17:16:04 -0700704 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800705 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700706 }
Chris Mantona09f3632016-02-09 14:48:42 -0800707 }
708 }
709
Taesu Lee62f826d2020-08-10 16:01:18 +0900710 private void maybeTurnCellOn(boolean isAirplaneNewlyOn) {
Chris Mantona09f3632016-02-09 14:48:42 -0800711 if (!isAirplaneNewlyOn) {
Taesu Lee62f826d2020-08-10 16:01:18 +0900712 setRadioPowerOn();
Santos Cordone18902f2016-03-22 17:16:04 -0700713 }
714 }
715
Santos Cordon593ab382013-08-06 21:58:23 -0700716 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700717 * Receiver for misc intent broadcasts the Phone app cares about.
718 */
719 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
720 @Override
721 public void onReceive(Context context, Intent intent) {
722 String action = intent.getAction();
723 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Taesu Lee3dc572b2020-08-07 18:16:22 +0900724 boolean airplaneMode = intent.getBooleanExtra("state", false);
Taesu Lee62f826d2020-08-10 16:01:18 +0900725 handleAirplaneModeChange(airplaneMode);
Amit Mahajanf5d92c82018-11-02 17:44:40 -0700726 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
727 // re-register as it may be a new IccCard
728 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
729 SubscriptionManager.INVALID_PHONE_INDEX);
730 if (SubscriptionManager.isValidPhoneId(phoneId)) {
731 PhoneUtils.unregisterIccStatus(mHandler, phoneId);
732 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED, phoneId);
733 }
Nazish Tabassum160d2112019-12-23 17:31:33 +0530734 String iccStatus = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
735 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
736 new EventSimStateChangedBag(phoneId, iccStatus)));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700737 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
738 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800739 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
740 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700741 } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
742 handleServiceStateChanged(intent);
743 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530744 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530745 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530746 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
747 if (phoneInEcm != null) {
748 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
749 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
750 // Start Emergency Callback Mode service
Daniel Bright30efde42020-01-09 22:11:15 -0800751 if (intent.getBooleanExtra(
752 TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530753 context.startService(new Intent(context,
754 EmergencyCallbackModeService.class));
755 } else {
756 phoneInEcm = null;
757 }
758 } else {
759 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
760 // on a device that doesn't support ECM in the first place.
761 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
762 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
763 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700764 }
765 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530766 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700767 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700768 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
769 // Roaming status could be overridden by carrier config, so we need to update it.
770 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
771 updateDataRoamingStatus();
chen xubaf9fe52019-07-02 17:28:24 -0700772 updateLimitedSimFunctionForDualSim();
Lei Liu863eac02020-06-24 20:12:55 +0800773 int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
774 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
775 if (SubscriptionManager.isValidSubscriptionId(subId)) {
776 mHandler.sendMessage(mHandler.obtainMessage(EVENT_CARRIER_CONFIG_CHANGED,
777 new Integer(subId)));
778 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700779 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
780 // We also need to pay attention when default data subscription changes.
781 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
782 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
783 registerSettingsObserver();
784 Phone phone = getPhone(mDefaultDataSubId);
785 if (phone != null) {
786 updateDataRoamingStatus();
787 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700788 }
789 }
790 }
791
Brad Ebinger28626122017-08-10 14:13:35 -0700792 private class SipReceiver extends BroadcastReceiver {
793
794 @Override
795 public void onReceive(Context context, Intent intent) {
796 String action = intent.getAction();
797
798 SipAccountRegistry sipAccountRegistry = SipAccountRegistry.getInstance();
799 if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
800 SipUtil.startSipService();
801 } else if (action.equals(SipManager.ACTION_SIP_SERVICE_UP)
802 || action.equals(SipManager.ACTION_SIP_CALL_OPTION_CHANGED)) {
803 sipAccountRegistry.setup(context);
Grace Jiab95592a2020-01-15 14:12:24 -0800804 } else if (action.equals(SipManager.ACTION_SIP_REMOVE_PROFILE)) {
Brad Ebinger28626122017-08-10 14:13:35 -0700805 if (DBG) {
806 Log.d(LOG_TAG, "SIP_REMOVE_PHONE "
807 + intent.getStringExtra(SipManager.EXTRA_LOCAL_URI));
808 }
809 sipAccountRegistry.removeSipProfile(intent.getStringExtra(
810 SipManager.EXTRA_LOCAL_URI));
811 } else {
812 if (DBG) Log.d(LOG_TAG, "onReceive, action not processed: " + action);
813 }
814 }
815 }
816
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700817 private void handleServiceStateChanged(Intent intent) {
818 /**
819 * This used to handle updating EriTextWidgetProvider this routine
820 * and and listening for ACTION_SERVICE_STATE_CHANGED intents could
821 * be removed. But leaving just in case it might be needed in the near
822 * future.
823 */
824
Jack Yu1a2fc352017-07-14 17:14:37 -0700825 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700826 // If service just returned, start sending out the queued messages
Santos Cordonc593d002015-06-03 15:41:15 -0700827 Bundle extras = intent.getExtras();
828 if (extras != null) {
829 ServiceState ss = ServiceState.newFromBundle(extras);
830 if (ss != null) {
831 int state = ss.getState();
Jayachandran C2ef9a482017-05-12 22:07:47 -0700832 int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
833 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
834 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -0700835
836 if (VDBG) {
837 Log.v(LOG_TAG, "subId=" + subId + ",mDefaultDataSubId="
838 + mDefaultDataSubId + ",ss roaming=" + ss.getDataRoaming());
839 }
840 if (subId == mDefaultDataSubId) {
841 updateDataRoamingStatus();
842 }
Santos Cordonc593d002015-06-03 15:41:15 -0700843 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700844 }
845 }
846
Jack Yu1a2fc352017-07-14 17:14:37 -0700847 /**
Jordan Liuff2ccd72019-07-23 15:54:41 -0700848 * @return whether or not we should show a notification when connecting to data roaming if the
849 * user has data roaming enabled
850 */
851 private boolean shouldShowDataConnectedRoaming(int subId) {
852 PersistableBundle config = getCarrierConfigForSubId(subId);
853 return config.getBoolean(CarrierConfigManager
854 .KEY_SHOW_DATA_CONNECTED_ROAMING_NOTIFICATION_BOOL);
855 }
856
857 /**
Jack Yu1a2fc352017-07-14 17:14:37 -0700858 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
859 * to notify the user so they can enable it through settings. Vise versa if the condition
860 * changes, we need to dismiss the notification.
861 */
862 private void updateDataRoamingStatus() {
863 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
864 Phone phone = getPhone(mDefaultDataSubId);
865 if (phone == null) {
866 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
867 return;
868 }
869
870 DataConnectionReasons reasons = new DataConnectionReasons();
Jack Yu311536f2018-11-26 11:20:48 -0800871 boolean dataAllowed = phone.isDataAllowed(ApnSetting.TYPE_DEFAULT, reasons);
Jack Yu1a2fc352017-07-14 17:14:37 -0700872 mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons);
873 if (VDBG) Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons);
Jordan Liuff2ccd72019-07-23 15:54:41 -0700874 if (!dataAllowed && reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED)) {
875 // No need to show it again if we never cancelled it explicitly.
876 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_DISCONNECTED) return;
Jack Yu1a2fc352017-07-14 17:14:37 -0700877 // If the only reason of no data is data roaming disabled, then we notify the user
878 // so the user can turn on data roaming.
Jordan Liuff2ccd72019-07-23 15:54:41 -0700879 mPrevRoamingNotification = ROAMING_NOTIFICATION_DISCONNECTED;
Jack Yu1a2fc352017-07-14 17:14:37 -0700880 Log.d(LOG_TAG, "Show roaming disconnected notification");
Jordan Liuff2ccd72019-07-23 15:54:41 -0700881 mDataRoamingNotifLog.log("Show roaming off.");
Pengquan Meng8783d932017-10-16 14:57:40 -0700882 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_DISCONNECTED);
883 msg.arg1 = mDefaultDataSubId;
884 msg.sendToTarget();
Jordan Liuff2ccd72019-07-23 15:54:41 -0700885 } else if (dataAllowed && dataIsNowRoaming(mDefaultDataSubId)
886 && shouldShowDataConnectedRoaming(mDefaultDataSubId)) {
887 // No need to show it again if we never cancelled it explicitly, or carrier config
888 // indicates this is not needed.
889 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_CONNECTED) return;
890 mPrevRoamingNotification = ROAMING_NOTIFICATION_CONNECTED;
891 Log.d(LOG_TAG, "Show roaming connected notification");
892 mDataRoamingNotifLog.log("Show roaming on.");
893 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_CONNECTED);
894 msg.arg1 = mDefaultDataSubId;
895 msg.sendToTarget();
896 } else if (mPrevRoamingNotification != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
897 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
898 // is not the only data disable reason. In this case we dismiss the notification we
899 // showed earlier.
900 mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
901 Log.d(LOG_TAG, "Dismiss roaming notification");
Jack Yu1a2fc352017-07-14 17:14:37 -0700902 mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed + ", reasons=" + reasons);
903 mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
904 }
905 }
906
Jordan Liuff2ccd72019-07-23 15:54:41 -0700907 /**
908 *
909 * @param subId to check roaming on
910 * @return whether we have transitioned to dataRoaming
911 */
912 private boolean dataIsNowRoaming(int subId) {
913 return getPhone(subId).getServiceState().getDataRoaming();
914 }
915
chen xubaf9fe52019-07-02 17:28:24 -0700916 private void updateLimitedSimFunctionForDualSim() {
917 if (DBG) Log.d(LOG_TAG, "updateLimitedSimFunctionForDualSim");
918 // check conditions to display limited SIM function notification under dual SIM
919 SubscriptionManager subMgr = (SubscriptionManager) getSystemService(
920 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
921 List<SubscriptionInfo> subList = subMgr.getActiveSubscriptionInfoList(false);
922 if (subList != null && subList.size() > 1) {
923 CarrierConfigManager configMgr = (CarrierConfigManager)
924 getSystemService(Context.CARRIER_CONFIG_SERVICE);
925 for (SubscriptionInfo info : subList) {
926 PersistableBundle b = configMgr.getConfigForSubId(info.getSubscriptionId());
927 if (b != null) {
928 if (b.getBoolean(CarrierConfigManager
929 .KEY_LIMITED_SIM_FUNCTION_NOTIFICATION_FOR_DSDS_BOOL)) {
930 notificationMgr.showLimitedSimFunctionWarningNotification(
931 info.getSubscriptionId(),
932 info.getDisplayName().toString());
933 } else {
934 notificationMgr.dismissLimitedSimFunctionWarningNotification(
935 info.getSubscriptionId());
936 }
937 }
938 }
939 } else {
940 // cancel notifications for all subs
941 notificationMgr.dismissLimitedSimFunctionWarningNotification(
942 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
943 }
944 notificationMgr.dismissLimitedSimFunctionWarningNotificationForInactiveSubs();
945
946 }
947
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530948 public Phone getPhoneInEcm() {
949 return phoneInEcm;
950 }
951
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700952 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -0800953 * Triggers a refresh of the message waiting (voicemail) indicator.
954 *
955 * @param subId the subscription id we should refresh the notification for.
956 */
957 public void refreshMwiIndicator(int subId) {
958 notificationMgr.refreshMwi(subId);
959 }
960
961 /**
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700962 * Called when the network selection on the subscription {@code subId} is changed by the user.
963 *
964 * @param subId the subscription id.
965 */
966 public void onNetworkSelectionChanged(int subId) {
967 Phone phone = getPhone(subId);
968 if (phone != null) {
969 notificationMgr.updateNetworkSelection(phone.getServiceState().getState(), subId);
970 } else {
971 Log.w(LOG_TAG, "onNetworkSelectionChanged on null phone, subId: " + subId);
972 }
973 }
974
975 /**
James.cf Lin4b784aa2021-01-31 03:25:15 +0800976 * @return whether the device supports RCS User Capability Exchange or not.
977 */
978 public boolean getDeviceUceEnabled() {
979 return (mTelephonyRcsService == null) ? false : mTelephonyRcsService.isDeviceUceEnabled();
980 }
981
982 /**
983 * Set the device supports RCS User Capability Exchange.
984 * @param isEnabled true if the device supports UCE.
985 */
986 public void setDeviceUceEnabled(boolean isEnabled) {
987 if (mTelephonyRcsService != null) {
988 mTelephonyRcsService.setDeviceUceEnabled(isEnabled);
989 }
990 }
991
992 /**
Jack Yu1a2fc352017-07-14 17:14:37 -0700993 * Dump the state of the object, add calls to other objects as desired.
994 *
995 * @param fd File descriptor
996 * @param printWriter Print writer
997 * @param args Arguments
998 */
999 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
1000 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
1001 pw.println("------- PhoneGlobals -------");
1002 pw.increaseIndent();
Jordan Liuff2ccd72019-07-23 15:54:41 -07001003 pw.println("mPrevRoamingNotification=" + mPrevRoamingNotification);
Jack Yu1a2fc352017-07-14 17:14:37 -07001004 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
1005 pw.println("mDataRoamingNotifLog:");
Keun young Parkdebb8532019-05-30 16:35:27 -07001006 pw.println("isSmsCapable=" + TelephonyManager.from(this).isSmsCapable());
Jack Yu1a2fc352017-07-14 17:14:37 -07001007 pw.increaseIndent();
1008 mDataRoamingNotifLog.dump(fd, pw, args);
1009 pw.decreaseIndent();
Brad Ebinger05f52c22019-12-05 13:03:21 -08001010 pw.println("ImsResolver:");
1011 pw.increaseIndent();
1012 try {
Brad Ebingerc9c432e2021-05-17 20:54:49 +00001013 if (ImsResolver.getInstance() != null) ImsResolver.getInstance().dump(fd, pw, args);
Brad Ebinger05f52c22019-12-05 13:03:21 -08001014 } catch (Exception e) {
1015 e.printStackTrace();
1016 }
1017 pw.decreaseIndent();
Brad Ebingera68a4972020-01-30 17:31:23 -08001018 pw.println("RcsService:");
1019 try {
1020 if (mTelephonyRcsService != null) mTelephonyRcsService.dump(fd, pw, args);
1021 } catch (Exception e) {
1022 e.printStackTrace();
1023 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001024 pw.decreaseIndent();
1025 pw.println("------- End PhoneGlobals -------");
1026 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001027}