blob: 3525ebeb963904c32467945f0af79dd3c513bb7e [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;
34import android.os.AsyncResult;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.os.Handler;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036import android.os.Message;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070037import android.os.PersistableBundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.PowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.preference.PreferenceManager;
Sanket Padawe4c699232016-02-09 11:07:22 -080041import android.provider.Settings;
Meng Wang61307622019-10-23 14:08:43 -070042import android.sysprop.TelephonyProperties;
Tyler Gunn900d8fd2018-09-21 09:22:12 -070043import android.telecom.TelecomManager;
Nathan Haroldf9df6ea2019-03-08 11:54:22 -080044import android.telephony.AnomalyReporter;
Junda Liu12f7d802015-05-01 12:06:44 -070045import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.telephony.ServiceState;
chen xubaf9fe52019-07-02 17:28:24 -070047import android.telephony.SubscriptionInfo;
Andrew Lee385019f2014-11-24 14:19:50 -080048import android.telephony.SubscriptionManager;
Sarah Chin072ffb22022-05-03 17:58:59 -070049import android.telephony.TelephonyCallback;
Hall Liuaa4211e2021-01-20 15:43:39 -080050import android.telephony.TelephonyLocalConnection;
Jack Yu1a2fc352017-07-14 17:14:37 -070051import android.telephony.TelephonyManager;
Ling Ma317906d2022-12-05 15:58:14 -080052import android.util.ArraySet;
Jack Yu1a2fc352017-07-14 17:14:37 -070053import android.util.LocalLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.util.Log;
Santos Cordone18902f2016-03-22 17:16:04 -070055import android.widget.Toast;
Ta-wei Yenb29425b2016-09-21 17:28:14 -070056
Brad Ebingere3ae65a2020-09-11 12:45:11 -070057import com.android.ims.ImsFeatureBinderRepository;
Siim Sammul182d61b2021-05-04 16:01:42 +010058import com.android.internal.os.BinderCallsStats;
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;
Sarah Chin072ffb22022-05-03 17:58:59 -070063import com.android.internal.telephony.PhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import com.android.internal.telephony.PhoneConstants;
65import com.android.internal.telephony.PhoneFactory;
Jack Yu1a2fc352017-07-14 17:14:37 -070066import com.android.internal.telephony.SettingsObserver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067import com.android.internal.telephony.TelephonyCapabilities;
Youming Ye47a6adc2018-11-19 15:33:36 -080068import com.android.internal.telephony.TelephonyComponentFactory;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070069import com.android.internal.telephony.TelephonyIntents;
Jack Yu3e2ac6e2022-03-26 13:59:45 -070070import com.android.internal.telephony.data.DataEvaluation.DataDisallowedReason;
Hwangoo Parkba21cf22022-11-30 14:34:04 +000071import com.android.internal.telephony.domainselection.DomainSelectionResolver;
Daniel Bantab26e96f2022-10-19 23:25:35 +000072import com.android.internal.telephony.emergency.EmergencyStateTracker;
Ling Ma51dd3022023-08-29 11:46:38 -070073import com.android.internal.telephony.flags.FeatureFlagsImpl;
Brad Ebinger05f52c22019-12-05 13:03:21 -080074import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn92479152021-01-20 16:30:10 -080075import com.android.internal.telephony.imsphone.ImsPhone;
76import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000077import com.android.internal.telephony.satellite.SatelliteController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000078import com.android.internal.telephony.uicc.UiccPort;
Jordan Liu06bdef12021-03-24 17:25:46 -070079import com.android.internal.telephony.uicc.UiccProfile;
Jack Yu1a2fc352017-07-14 17:14:37 -070080import com.android.internal.util.IndentingPrintWriter;
Andrew Leefb7f92e2015-02-26 16:23:32 -080081import com.android.phone.settings.SettingsConstants;
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -070082import com.android.phone.vvm.CarrierVvmPackageInstalledReceiver;
Hwangoo Parkba21cf22022-11-30 14:34:04 +000083import com.android.services.telephony.domainselection.TelephonyDomainSelectionService;
James.cf Linc9f35a42020-01-15 02:35:22 +080084import com.android.services.telephony.rcs.TelephonyRcsService;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070085
Jack Yu1a2fc352017-07-14 17:14:37 -070086import java.io.FileDescriptor;
87import java.io.PrintWriter;
Jordan Liuff2ccd72019-07-23 15:54:41 -070088import java.lang.annotation.Retention;
89import java.lang.annotation.RetentionPolicy;
chen xubaf9fe52019-07-02 17:28:24 -070090import java.util.List;
Jack Yu1a2fc352017-07-14 17:14:37 -070091
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092/**
93 * Global state for the telephony subsystem when running in the primary
94 * phone process.
95 */
Sailesh Nepalbf900542014-07-15 16:18:32 -070096public class PhoneGlobals extends ContextWrapper {
Jack Yu1a2fc352017-07-14 17:14:37 -070097 public static final String LOG_TAG = "PhoneGlobals";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070098
99 /**
100 * Phone app-wide debug level:
101 * 0 - no debug logging
102 * 1 - normal debug logging if ro.debuggable is set (which is true in
103 * "eng" and "userdebug" builds but not "user" builds)
104 * 2 - ultra-verbose debug logging
105 *
106 * Most individual classes in the phone app have a local DBG constant,
107 * typically set to
108 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
109 * or else
110 * (PhoneApp.DBG_LEVEL >= 2)
111 * depending on the desired verbosity.
112 *
113 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
114 */
Andrew Lee88b51e22014-10-29 15:48:51 -0700115 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116
117 private static final boolean DBG =
118 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
119 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
120
121 // Message codes; see mHandler below.
122 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700124 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
Jordan Liuff2ccd72019-07-23 15:54:41 -0700125 private static final int EVENT_DATA_ROAMING_CONNECTED = 11;
126 private static final int EVENT_DATA_ROAMING_OK = 12;
127 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 13;
Jordan Liuff2ccd72019-07-23 15:54:41 -0700128 private static final int EVENT_DATA_ROAMING_SETTINGS_CHANGED = 15;
129 private static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED = 16;
Lei Liu863eac02020-06-24 20:12:55 +0800130 private static final int EVENT_CARRIER_CONFIG_CHANGED = 17;
Sarah Chin072ffb22022-05-03 17:58:59 -0700131 private static final int EVENT_MULTI_SIM_CONFIG_CHANGED = 18;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132
133 // The MMI codes are also used by the InCallScreen.
134 public static final int MMI_INITIATE = 51;
135 public static final int MMI_COMPLETE = 52;
136 public static final int MMI_CANCEL = 53;
137 // Don't use message codes larger than 99 here; those are reserved for
138 // the individual Activities of the Phone UI.
139
Santos Cordone18902f2016-03-22 17:16:04 -0700140 public static final int AIRPLANE_ON = 1;
141 public static final int AIRPLANE_OFF = 0;
142
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143 /**
144 * Allowable values for the wake lock code.
145 * SLEEP means the device can be put to sleep.
146 * PARTIAL means wake the processor, but we display can be kept off.
147 * FULL means wake both the processor and the display.
148 */
149 public enum WakeState {
150 SLEEP,
151 PARTIAL,
152 FULL
153 }
154
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155 private static PhoneGlobals sMe;
156
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700158 CallNotifier notifier;
Santos Cordon63a84242013-07-23 13:32:52 -0700159 NotificationMgr notificationMgr;
James.cf Linc9f35a42020-01-15 02:35:22 +0800160 TelephonyRcsService mTelephonyRcsService;
Andrew Lee9431b832015-03-09 18:46:45 -0700161 public PhoneInterfaceManager phoneMgr;
James.cf Linaf3183c2019-10-24 00:59:00 +0800162 public ImsRcsController imsRcsController;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000163 public ImsStateCallbackController mImsStateCallbackController;
joonhunshincffb7fc2021-11-28 07:32:01 +0000164 public ImsProvisioningController mImsProvisioningController;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800165 CarrierConfigLoader configLoader;
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000166 TelephonyDomainSelectionService mDomainSelectionService;
Santos Cordon63a84242013-07-23 13:32:52 -0700167
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530168 private Phone phoneInEcm;
Santos Cordon63a84242013-07-23 13:32:52 -0700169
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700170 static boolean sVoiceCapable = true;
171
Santos Cordonc593d002015-06-03 15:41:15 -0700172 // TODO: Remove, no longer used.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173 CdmaPhoneCallState cdmaPhoneCallState;
174
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700175 // The currently-active PUK entry activity and progress dialog.
176 // Normally, these are the Emergency Dialer and the subsequent
177 // progress dialog. null if there is are no such objects in
178 // the foreground.
179 private Activity mPUKEntryActivity;
180 private ProgressDialog mPUKEntryProgressDialog;
181
Jordan Liuff2ccd72019-07-23 15:54:41 -0700182 /** @hide */
183 @Retention(RetentionPolicy.SOURCE)
sangyun35f23f82023-07-18 01:37:53 +0900184 @IntDef(prefix = {"ROAMING_NOTIFICATION_REASON_"},
185 value = {
186 ROAMING_NOTIFICATION_REASON_DATA_SETTING_CHANGED,
187 ROAMING_NOTIFICATION_REASON_DATA_ROAMING_SETTING_CHANGED,
188 ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED,
189 ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED,
190 ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED})
191 public @interface RoamingNotificationReason {}
192 private static final int ROAMING_NOTIFICATION_REASON_DATA_SETTING_CHANGED = 0;
193 private static final int ROAMING_NOTIFICATION_REASON_DATA_ROAMING_SETTING_CHANGED = 1;
194 private static final int ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED = 2;
195 private static final int ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED = 3;
196 private static final int ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED = 4;
197
198 /** @hide */
199 @Retention(RetentionPolicy.SOURCE)
Jordan Liuff2ccd72019-07-23 15:54:41 -0700200 @IntDef(prefix = {"ROAMING_NOTIFICATION_"},
201 value = {
202 ROAMING_NOTIFICATION_NO_NOTIFICATION,
203 ROAMING_NOTIFICATION_CONNECTED,
204 ROAMING_NOTIFICATION_DISCONNECTED})
205 public @interface RoamingNotification {}
206
207 private static final int ROAMING_NOTIFICATION_NO_NOTIFICATION = 0;
208 private static final int ROAMING_NOTIFICATION_CONNECTED = 1;
209 private static final int ROAMING_NOTIFICATION_DISCONNECTED = 2;
210
211 @RoamingNotification
sangyun35f23f82023-07-18 01:37:53 +0900212 private int mCurrentRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
Jack Yu953f9352017-05-18 14:41:06 -0700213
sangyun35f23f82023-07-18 01:37:53 +0900214 /**
215 * Reasons that have already shown notification to prevent duplicate shows for the same reason.
216 */
217 private ArraySet<String> mShownNotificationReasons = new ArraySet<>();
Ling Ma317906d2022-12-05 15:58:14 -0800218
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700219 private WakeState mWakeState = WakeState.SLEEP;
220
221 private PowerManager mPowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700222 private PowerManager.WakeLock mWakeLock;
223 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700224 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700225
Jack Yu1a2fc352017-07-14 17:14:37 -0700226 private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
227 private final LocalLog mDataRoamingNotifLog = new LocalLog(50);
228
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700229 // Broadcast receiver for various intent broadcasts (see onCreate())
230 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
231
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700232 private final CarrierVvmPackageInstalledReceiver mCarrierVvmPackageInstalledReceiver =
233 new CarrierVvmPackageInstalledReceiver();
234
Jack Yu1a2fc352017-07-14 17:14:37 -0700235 private final SettingsObserver mSettingsObserver;
Siim Sammul182d61b2021-05-04 16:01:42 +0100236 private BinderCallsStats.SettingsObserver mBinderCallsSettingsObserver;
Jack Yu1a2fc352017-07-14 17:14:37 -0700237
Sarah Chin072ffb22022-05-03 17:58:59 -0700238 // Mapping of phone ID to the associated TelephonyCallback. These should be registered without
239 // fine or coarse location since we only use ServiceState for
240 private PhoneAppCallback[] mTelephonyCallbacks;
241
242 private class PhoneAppCallback extends TelephonyCallback implements
243 TelephonyCallback.ServiceStateListener {
244 private final int mSubId;
245
246 PhoneAppCallback(int subId) {
247 mSubId = subId;
248 }
249
250 @Override
251 public void onServiceStateChanged(ServiceState serviceState) {
252 // Note when registering that we should be registering with INCLUDE_LOCATION_DATA_NONE.
253 // PhoneGlobals only uses the state and roaming status, which does not require location.
254 handleServiceStateChanged(serviceState, mSubId);
255 }
256
257 public int getSubId() {
258 return mSubId;
259 }
260 }
261
Nazish Tabassum160d2112019-12-23 17:31:33 +0530262 private static class EventSimStateChangedBag {
263 final int mPhoneId;
264 final String mIccStatus;
265
266 EventSimStateChangedBag(int phoneId, String iccStatus) {
267 mPhoneId = phoneId;
268 mIccStatus = iccStatus;
269 }
270 }
271
Jordan Liu06bdef12021-03-24 17:25:46 -0700272 // Some carrier config settings disable the network lock screen, so we call handleSimLock
273 // when either SIM_LOCK or CARRIER_CONFIG changes so that no matter which one happens first,
274 // we still do the right thing
275 private void handleSimLock(int subType, Phone phone) {
276 PersistableBundle cc = getCarrierConfigForSubId(phone.getSubId());
277 if (!CarrierConfigManager.isConfigForIdentifiedCarrier(cc)) {
278 // If we only have the default carrier config just return, to avoid popping up the
279 // the SIM lock screen when it's disabled by the carrier.
280 Log.i(LOG_TAG, "Not showing 'SIM network unlock' screen. Carrier config not loaded");
281 return;
282 }
283 if (cc.getBoolean(CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
284 // Some products don't have the concept of a "SIM network lock"
285 Log.i(LOG_TAG, "Not showing 'SIM network unlock' screen. Disabled by carrier config");
286 return;
287 }
288
289 // if passed in subType is unknown, retrieve it here.
290 if (subType == -1) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000291 final UiccPort uiccPort = phone.getUiccPort();
292 if (uiccPort == null) {
Jordan Liu06bdef12021-03-24 17:25:46 -0700293 Log.e(LOG_TAG,
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000294 "handleSimLock: uiccPort for phone " + phone.getPhoneId() + " is null");
Jordan Liu06bdef12021-03-24 17:25:46 -0700295 return;
296 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000297 final UiccProfile uiccProfile = uiccPort.getUiccProfile();
Jordan Liu06bdef12021-03-24 17:25:46 -0700298 if (uiccProfile == null) {
299 Log.e(LOG_TAG,
300 "handleSimLock: uiccProfile for phone " + phone.getPhoneId() + " is null");
301 return;
302 }
303 subType = uiccProfile.getApplication(
304 uiccProfile.mCurrentAppType).getPersoSubState().ordinal();
305 }
306 // Normal case: show the "SIM network unlock" PIN entry screen.
307 // The user won't be able to do anything else until
308 // they enter a valid SIM network PIN.
309 Log.i(LOG_TAG, "show sim depersonal panel");
310 IccNetworkDepersonalizationPanel.showDialog(phone, subType);
311 }
312
313 private boolean isSimLocked(Phone phone) {
314 TelephonyManager tm = getSystemService(TelephonyManager.class);
315 return tm.createForSubscriptionId(phone.getSubId()).getSimState()
316 == TelephonyManager.SIM_STATE_NETWORK_LOCKED;
317 }
318
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700319 Handler mHandler = new Handler() {
320 @Override
321 public void handleMessage(Message msg) {
322 PhoneConstants.State phoneState;
Jack Yu1a2fc352017-07-14 17:14:37 -0700323 if (VDBG) Log.v(LOG_TAG, "event=" + msg.what);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700324 switch (msg.what) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700325 // TODO: This event should be handled by the lock screen, just
326 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
327 case EVENT_SIM_NETWORK_LOCKED:
Jordan Liu06bdef12021-03-24 17:25:46 -0700328 int subType = (Integer) ((AsyncResult) msg.obj).result;
329 Phone phone = (Phone) ((AsyncResult) msg.obj).userObj;
330 handleSimLock(subType, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700331 break;
332
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700333 case EVENT_DATA_ROAMING_DISCONNECTED:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700334 notificationMgr.showDataRoamingNotification(msg.arg1, false);
335 break;
336
337 case EVENT_DATA_ROAMING_CONNECTED:
338 notificationMgr.showDataRoamingNotification(msg.arg1, true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700339 break;
340
341 case EVENT_DATA_ROAMING_OK:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700342 notificationMgr.hideDataRoamingNotification();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343 break;
344
345 case MMI_COMPLETE:
346 onMMIComplete((AsyncResult) msg.obj);
347 break;
348
349 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800350 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700351 break;
352
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700353 case EVENT_SIM_STATE_CHANGED:
Nazish Tabassum160d2112019-12-23 17:31:33 +0530354 EventSimStateChangedBag bag = (EventSimStateChangedBag)msg.obj;
Sarah Chin010884c2023-06-14 15:55:08 -0700355 // Dismiss the "No services" notification if the SIM is removed.
356 if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(bag.mIccStatus)) {
357 notificationMgr.dismissNetworkSelectionNotificationForInactiveSubId();
358 }
359
360 // Marks the event where the SIM goes into ready state.
361 // Right now, this is only used for the PUK-unlocking process.
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700362 if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(bag.mIccStatus)
Nazish Tabassum59126a92020-07-03 21:44:49 +0530363 || IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(bag.mIccStatus)
364 || IccCardConstants.INTENT_VALUE_ICC_NOT_READY.equals(bag.mIccStatus)
365 || IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(bag.mIccStatus)) {
Sarah Chin010884c2023-06-14 15:55:08 -0700366 // When the right event is triggered and there are UI objects in the
367 // foreground, we close them to display the lock panel.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700368 if (mPUKEntryActivity != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700369 Log.i(LOG_TAG, "Dismiss puk entry activity");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370 mPUKEntryActivity.finish();
371 mPUKEntryActivity = null;
372 }
373 if (mPUKEntryProgressDialog != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700374 Log.i(LOG_TAG, "Dismiss puk progress dialog");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700375 mPUKEntryProgressDialog.dismiss();
376 mPUKEntryProgressDialog = null;
377 }
Nazish Tabassum59126a92020-07-03 21:44:49 +0530378 Log.i(LOG_TAG, "Dismissing depersonal panel" + (bag.mIccStatus));
Nazish Tabassum160d2112019-12-23 17:31:33 +0530379 IccNetworkDepersonalizationPanel.dialogDismiss(bag.mPhoneId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380 }
381 break;
382
383 case EVENT_UNSOL_CDMA_INFO_RECORD:
384 //TODO: handle message here;
385 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700386 case EVENT_DATA_ROAMING_SETTINGS_CHANGED:
sangyun35f23f82023-07-18 01:37:53 +0900387 updateDataRoamingStatus(
388 ROAMING_NOTIFICATION_REASON_DATA_ROAMING_SETTING_CHANGED);
389 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700390 case EVENT_MOBILE_DATA_SETTINGS_CHANGED:
sangyun35f23f82023-07-18 01:37:53 +0900391 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_DATA_SETTING_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700392 break;
Lei Liu863eac02020-06-24 20:12:55 +0800393 case EVENT_CARRIER_CONFIG_CHANGED:
394 int subId = (Integer) msg.obj;
395 // The voicemail number could be overridden by carrier config, so need to
396 // refresh the message waiting (voicemail) indicator.
397 refreshMwiIndicator(subId);
Jordan Liu06bdef12021-03-24 17:25:46 -0700398 phone = getPhone(subId);
Sarah Chin072ffb22022-05-03 17:58:59 -0700399 if (phone != null) {
400 if (isSimLocked(phone)) {
401 // pass in subType=-1 so handleSimLock can find the actual subType if
402 // needed. This is safe as valid values for subType are >= 0
403 handleSimLock(-1, phone);
404 }
405 TelephonyManager tm = getSystemService(TelephonyManager.class);
406 PhoneAppCallback callback = mTelephonyCallbacks[phone.getPhoneId()];
407 // TODO: We may need to figure out a way to unregister if subId is invalid
408 tm.createForSubscriptionId(callback.getSubId())
409 .unregisterTelephonyCallback(callback);
410 callback = new PhoneAppCallback(subId);
411 tm.createForSubscriptionId(subId).registerTelephonyCallback(
Ling Ma317906d2022-12-05 15:58:14 -0800412 TelephonyManager.INCLUDE_LOCATION_DATA_COARSE, mHandler::post,
Sarah Chin072ffb22022-05-03 17:58:59 -0700413 callback);
414 mTelephonyCallbacks[phone.getPhoneId()] = callback;
415 }
416 break;
417 case EVENT_MULTI_SIM_CONFIG_CHANGED:
418 int activeModems = (int) ((AsyncResult) msg.obj).result;
419 TelephonyManager tm = getSystemService(TelephonyManager.class);
420 // Unregister all previous callbacks
421 for (int phoneId = 0; phoneId < mTelephonyCallbacks.length; phoneId++) {
422 PhoneAppCallback callback = mTelephonyCallbacks[phoneId];
423 if (callback != null) {
424 tm.createForSubscriptionId(callback.getSubId())
425 .unregisterTelephonyCallback(callback);
426 mTelephonyCallbacks[phoneId] = null;
427 }
428 }
429 // Register callbacks for all active modems
430 for (int phoneId = 0; phoneId < activeModems; phoneId++) {
431 int sub = PhoneFactory.getPhone(phoneId).getSubId();
432 PhoneAppCallback callback = new PhoneAppCallback(sub);
433 tm.createForSubscriptionId(sub).registerTelephonyCallback(
434 TelephonyManager.INCLUDE_LOCATION_DATA_NONE, mHandler::post,
435 callback);
436 mTelephonyCallbacks[phoneId] = callback;
Jordan Liu06bdef12021-03-24 17:25:46 -0700437 }
Lei Liu863eac02020-06-24 20:12:55 +0800438 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700439 }
440 }
441 };
442
443 public PhoneGlobals(Context context) {
444 super(context);
445 sMe = this;
Jack Yu1a2fc352017-07-14 17:14:37 -0700446 mSettingsObserver = new SettingsObserver(context, mHandler);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700447 }
448
449 public void onCreate() {
450 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
451
452 ContentResolver resolver = getContentResolver();
453
Hall Liuaa4211e2021-01-20 15:43:39 -0800454 // Initialize the shim from frameworks/opt/telephony into packages/services/Telephony.
455 TelephonyLocalConnection.setInstance(new LocalConnectionImpl(this));
456
Sarah Chin072ffb22022-05-03 17:58:59 -0700457 TelephonyManager tm = getSystemService(TelephonyManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700458 // Cache the "voice capable" flag.
459 // This flag currently comes from a resource (which is
460 // overrideable on a per-product basis):
Sarah Chin072ffb22022-05-03 17:58:59 -0700461 sVoiceCapable = tm.isVoiceCapable();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700462 // ...but this might eventually become a PackageManager "system
463 // feature" instead, in which case we'd do something like:
464 // sVoiceCapable =
465 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
466
Stuart Scottdcf40a92014-12-09 10:45:01 -0800467 if (mCM == null) {
Nathan Haroldf9df6ea2019-03-08 11:54:22 -0800468 // Initialize AnomalyReporter early so that it can be used
469 AnomalyReporter.initialize(this);
Nathan Harold0db5c5e2019-01-22 20:18:56 -0800470
Youming Ye47a6adc2018-11-19 15:33:36 -0800471 // Inject telephony component factory if configured using other jars.
472 XmlResourceParser parser = getResources().getXml(R.xml.telephony_injection);
473 TelephonyComponentFactory.getInstance().injectTheComponentFactory(parser);
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000474
475 // Create DomainSelectionResolver always, but it MUST be initialized only when
476 // the device supports AOSP domain selection architecture and
477 // has new IRadio that supports its related HAL APIs.
478 DomainSelectionResolver.make(this,
479 getResources().getBoolean(R.bool.config_enable_aosp_domain_selection));
480
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700481 // Initialize the telephony framework
Ling Ma51dd3022023-08-29 11:46:38 -0700482 PhoneFactory.makeDefaultPhones(this, new FeatureFlagsImpl());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700483
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000484 // Initialize the DomainSelectionResolver after creating the Phone instance
485 // to check the Radio HAL version.
486 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
487 mDomainSelectionService = new TelephonyDomainSelectionService(this);
488 DomainSelectionResolver.getInstance().initialize(mDomainSelectionService);
Daniel Bantab26e96f2022-10-19 23:25:35 +0000489 // Initialize EmergencyStateTracker if domain selection is supported
490 boolean isSuplDdsSwitchRequiredForEmergencyCall = getResources()
491 .getBoolean(R.bool.config_gnss_supl_requires_default_data_for_emergency);
492 EmergencyStateTracker.make(this, isSuplDdsSwitchRequiredForEmergencyCall);
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000493 }
494
Brad Ebinger05f52c22019-12-05 13:03:21 -0800495 // Only bring up ImsResolver if the device supports having an IMS stack.
496 if (getPackageManager().hasSystemFeature(
497 PackageManager.FEATURE_TELEPHONY_IMS)) {
498 // Get the package name of the default IMS implementation.
499 String defaultImsMmtelPackage = getResources().getString(
500 R.string.config_ims_mmtel_package);
501 String defaultImsRcsPackage = getResources().getString(
502 R.string.config_ims_rcs_package);
Brad Ebingerd1947d82021-05-17 20:54:49 +0000503 ImsResolver.make(this, defaultImsMmtelPackage,
Brad Ebingere3ae65a2020-09-11 12:45:11 -0700504 defaultImsRcsPackage, PhoneFactory.getPhones().length,
505 new ImsFeatureBinderRepository());
Brad Ebingerd1947d82021-05-17 20:54:49 +0000506 ImsResolver.getInstance().initialize();
Tyler Gunn92479152021-01-20 16:30:10 -0800507
508 // With the IMS phone created, load static config.xml values from the phone process
509 // so that it can be provided to the ImsPhoneCallTracker.
510 for (Phone p : PhoneFactory.getPhones()) {
511 Phone imsPhone = p.getImsPhone();
512 if (imsPhone != null && imsPhone instanceof ImsPhone) {
513 ImsPhone theImsPhone = (ImsPhone) imsPhone;
514 if (theImsPhone.getCallTracker() instanceof ImsPhoneCallTracker) {
515 ImsPhoneCallTracker ict = (ImsPhoneCallTracker)
516 theImsPhone.getCallTracker();
517
518 ImsPhoneCallTracker.Config config = new ImsPhoneCallTracker.Config();
519 config.isD2DCommunicationSupported = getResources().getBoolean(
520 R.bool.config_use_device_to_device_communication);
521 ict.setConfig(config);
522 }
523 }
524 }
Hui Wang068ab862020-10-31 05:12:53 +0000525 RcsProvisioningMonitor.make(this);
Brad Ebinger05f52c22019-12-05 13:03:21 -0800526 }
527
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700528 // Start TelephonyDebugService After the default phone is created.
529 Intent intent = new Intent(this, TelephonyDebugService.class);
530 startService(intent);
531
532 mCM = CallManager.getInstance();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700533
534 // Create the NotificationMgr singleton, which is used to display
535 // status bar icons and control other status bar behavior.
536 notificationMgr = NotificationMgr.init(this);
537
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000538 // Create the SatelliteController singleton, which acts as a backend service for
539 // {@link android.telephony.satellite.SatelliteManager}.
540 SatelliteController.make(this);
Sarah Chin5f57c582023-02-14 04:16:10 -0800541
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700542 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
543 cdmaPhoneCallState = new CdmaPhoneCallState();
544 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700545
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700546 // before registering for phone state changes
547 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
548 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
549 // lock used to keep the processor awake, when we don't care for the display.
550 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
551 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700552
553 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
554
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800555 phoneMgr = PhoneInterfaceManager.init(this);
Santos Cordon406c0342013-08-28 00:07:47 -0700556
James.cf Linaf3183c2019-10-24 00:59:00 +0800557 imsRcsController = ImsRcsController.init(this);
558
Brad Ebinger6c53e7f2023-01-27 16:26:44 -0800559 configLoader = CarrierConfigLoader.init(this);
560
James.cf Linc9f35a42020-01-15 02:35:22 +0800561 if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000562 mImsStateCallbackController =
563 ImsStateCallbackController.make(this, PhoneFactory.getPhones().length);
Brad Ebingera68a4972020-01-30 17:31:23 -0800564 mTelephonyRcsService = new TelephonyRcsService(this,
565 PhoneFactory.getPhones().length);
566 mTelephonyRcsService.initialize();
James.cf Linc9f35a42020-01-15 02:35:22 +0800567 imsRcsController.setRcsService(mTelephonyRcsService);
joonhunshincffb7fc2021-11-28 07:32:01 +0000568 mImsProvisioningController =
569 ImsProvisioningController.make(this, PhoneFactory.getPhones().length);
James.cf Linc9f35a42020-01-15 02:35:22 +0800570 }
571
Jack Yu1a2fc352017-07-14 17:14:37 -0700572 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700573 // asynchronous events from the telephony layer (like
574 // launching the incoming-call UI when an incoming call comes
575 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800576 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700577
Stuart Scottdcf40a92014-12-09 10:45:01 -0800578 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700579
580 // register for MMI/USSD
581 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
582
Qiong Liucc3fe812019-09-23 15:25:44 +0800583 // Initialize cell status using current airplane mode.
Taesu Lee62f826d2020-08-10 16:01:18 +0900584 handleAirplaneModeChange(
585 Settings.Global.getInt(
586 getContentResolver(),
587 Settings.Global.AIRPLANE_MODE_ON,
588 AIRPLANE_OFF)
589 == AIRPLANE_ON);
Qiong Liucc3fe812019-09-23 15:25:44 +0800590
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700591 // Register for misc other intent broadcasts.
592 IntentFilter intentFilter =
593 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700594 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
595 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700596 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700597 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
598 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700599 registerReceiver(mReceiver, intentFilter);
sangyundce559b2023-09-11 10:25:55 +0900600 int defaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
601 if (SubscriptionManager.isValidSubscriptionId(defaultDataSubId)) {
602 if (VDBG) Log.v(LOG_TAG, "Loaded initial default data sub: " + defaultDataSubId);
603 mDefaultDataSubId = defaultDataSubId;
604 registerSettingsObserver();
605 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED);
606 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700607
Sarah Chin072ffb22022-05-03 17:58:59 -0700608 PhoneConfigurationManager.registerForMultiSimConfigChange(
609 mHandler, EVENT_MULTI_SIM_CONFIG_CHANGED, null);
610
611 mTelephonyCallbacks = new PhoneAppCallback[tm.getSupportedModemCount()];
Fangyuan Li7f5c2752022-06-29 18:02:31 +0800612 if (tm.getSupportedModemCount() > 0) {
613 for (Phone phone : PhoneFactory.getPhones()) {
614 int subId = phone.getSubId();
615 PhoneAppCallback callback = new PhoneAppCallback(subId);
616 tm.createForSubscriptionId(subId).registerTelephonyCallback(
617 TelephonyManager.INCLUDE_LOCATION_DATA_NONE, mHandler::post, callback);
618 mTelephonyCallbacks[phone.getPhoneId()] = callback;
619 }
Sarah Chin072ffb22022-05-03 17:58:59 -0700620 }
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700621 mCarrierVvmPackageInstalledReceiver.register(this);
622
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700623 //set the default values for the preferences in the phone.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700624 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700625 }
626
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700627 // XXX pre-load the SimProvider so that it's ready
628 resolver.getType(Uri.parse("content://icc/adn"));
629
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700630 // TODO: Register for Cdma Information Records
631 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
632
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700633 // Read HAC settings and configure audio hardware
634 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800635 int hac = android.provider.Settings.System.getInt(
636 getContentResolver(),
637 android.provider.Settings.System.HEARING_AID,
638 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700639 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Jordan Liuf71aeef2019-08-21 11:46:09 -0700640 audioManager.setParameters(
641 SettingsConstants.HAC_KEY + "=" + (hac == SettingsConstants.HAC_ENABLED
642 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700643 }
Siim Sammul182d61b2021-05-04 16:01:42 +0100644
645 // Start tracking Binder latency for the phone process.
646 mBinderCallsSettingsObserver = new BinderCallsStats.SettingsObserver(
647 getApplicationContext(),
Siim Sammula6950092021-06-22 17:14:03 +0100648 new BinderCallsStats(
649 new BinderCallsStats.Injector(),
650 com.android.internal.os.BinderLatencyProto.Dims.TELEPHONY));
Santos Cordonff506f52013-11-21 19:13:19 -0800651 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700652
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700653 /**
654 * Returns the singleton instance of the PhoneApp.
655 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800656 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700657 if (sMe == null) {
658 throw new IllegalStateException("No PhoneGlobals here!");
659 }
660 return sMe;
661 }
662
663 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800664 * Returns the default phone.
665 *
Andrew Lee385019f2014-11-24 14:19:50 -0800666 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700667 */
Andrew Lee83383e42014-10-31 12:42:28 -0700668 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800669 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700670 }
671
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800672 public static Phone getPhone(int subId) {
673 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800674 }
675
Santos Cordonde10b752013-09-19 04:11:33 -0700676 /* package */ CallManager getCallManager() {
677 return mCM;
678 }
679
Chris Manton4e9fa912015-06-19 11:26:57 -0700680 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800681 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700682 }
683
Chris Manton4e9fa912015-06-19 11:26:57 -0700684 public PersistableBundle getCarrierConfigForSubId(int subId) {
Philip P. Moltmann0079aae2020-03-05 16:24:02 -0800685 return configLoader.getConfigForSubIdWithFeature(subId, getOpPackageName(),
686 getAttributionTag());
Junda Liu605148f2015-04-28 15:23:40 -0700687 }
688
Jack Yu1a2fc352017-07-14 17:14:37 -0700689 private void registerSettingsObserver() {
690 mSettingsObserver.unobserve();
691 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
692 String mobileDataSetting = Settings.Global.MOBILE_DATA;
693 if (TelephonyManager.getDefault().getSimCount() > 1) {
694 int subId = mDefaultDataSubId;
695 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
696 dataRoamingSetting += subId;
697 mobileDataSetting += subId;
698 }
699 }
700
701 // Listen for user data roaming setting changed event
702 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
703 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
704
705 // Listen for mobile data setting changed event
706 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
707 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
708 }
709
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700710 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700711 * Sets the activity responsible for un-PUK-blocking the device
712 * so that we may close it when we receive a positive result.
713 * mPUKEntryActivity is also used to indicate to the device that
714 * we are trying to un-PUK-lock the phone. In other words, iff
715 * it is NOT null, then we are trying to unlock and waiting for
716 * the SIM to move to READY state.
717 *
718 * @param activity is the activity to close when PUK has
719 * finished unlocking. Can be set to null to indicate the unlock
720 * or SIM READYing process is over.
721 */
722 void setPukEntryActivity(Activity activity) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700723 Log.i(LOG_TAG, "setPukEntryActivity - set to " + (activity == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700724 mPUKEntryActivity = activity;
725 }
726
727 Activity getPUKEntryActivity() {
728 return mPUKEntryActivity;
729 }
730
731 /**
732 * Sets the dialog responsible for notifying the user of un-PUK-
733 * blocking - SIM READYing progress, so that we may dismiss it
734 * when we receive a positive result.
735 *
736 * @param dialog indicates the progress dialog informing the user
737 * of the state of the device. Dismissed upon completion of
738 * READYing process
739 */
740 void setPukEntryProgressDialog(ProgressDialog dialog) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700741 Log.i(LOG_TAG, "setPukEntryProgressDialog - set to "
742 + (dialog == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700743 mPUKEntryProgressDialog = dialog;
744 }
745
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700746 KeyguardManager getKeyguardManager() {
747 return mKeyguardManager;
748 }
749
750 private void onMMIComplete(AsyncResult r) {
751 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
752 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800753 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700754 }
755
fionaxu80126972017-02-01 17:01:26 -0800756 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700757 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700758 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700759 }
760
Taesu Lee62f826d2020-08-10 16:01:18 +0900761 private void handleAirplaneModeChange(boolean isAirplaneNewlyOn) {
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700762 Log.i(LOG_TAG, "handleAirplaneModeChange: isAirplaneNewlyOn=" + isAirplaneNewlyOn);
Taesu Lee62f826d2020-08-10 16:01:18 +0900763 int cellState =
764 Settings.Global.getInt(
765 getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
Chris Mantona09f3632016-02-09 14:48:42 -0800766 switch (cellState) {
767 case PhoneConstants.CELL_OFF_FLAG:
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700768 // Airplane mode does not affect the cell radio if user has turned it off.
769 Log.i(LOG_TAG, "Ignore airplane mode change due to cell off.");
Chris Mantona09f3632016-02-09 14:48:42 -0800770 break;
771 case PhoneConstants.CELL_ON_FLAG:
Taesu Lee62f826d2020-08-10 16:01:18 +0900772 maybeTurnCellOff(isAirplaneNewlyOn);
Chris Mantona09f3632016-02-09 14:48:42 -0800773 break;
774 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
Taesu Lee62f826d2020-08-10 16:01:18 +0900775 maybeTurnCellOn(isAirplaneNewlyOn);
Chris Mantona09f3632016-02-09 14:48:42 -0800776 break;
777 }
Hall Liu7f56e1a2019-07-10 14:41:14 -0700778 for (Phone phone : PhoneFactory.getPhones()) {
779 phone.getServiceStateTracker().onAirplaneModeChanged(isAirplaneNewlyOn);
780 }
Chris Mantona09f3632016-02-09 14:48:42 -0800781 }
782
783 /*
784 * Returns true if the radio must be turned off when entering airplane mode.
785 */
Taesu Lee62f826d2020-08-10 16:01:18 +0900786 private boolean isCellOffInAirplaneMode() {
787 String airplaneModeRadios =
788 Settings.Global.getString(
789 getContentResolver(), Settings.Global.AIRPLANE_MODE_RADIOS);
Chris Mantona09f3632016-02-09 14:48:42 -0800790 return airplaneModeRadios == null
791 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
792 }
793
Taesu Lee62f826d2020-08-10 16:01:18 +0900794 private void setRadioPowerOff() {
Chris Mantona09f3632016-02-09 14:48:42 -0800795 Log.i(LOG_TAG, "Turning radio off - airplane");
Taesu Lee62f826d2020-08-10 16:01:18 +0900796 Settings.Global.putInt(
797 getContentResolver(),
798 Settings.Global.CELL_ON,
799 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Chris Mantona09f3632016-02-09 14:48:42 -0800800 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
Taesu Lee62f826d2020-08-10 16:01:18 +0900801 TelephonyProperties.airplane_mode_on(true); // true means int value 1
Chris Mantona09f3632016-02-09 14:48:42 -0800802 PhoneUtils.setRadioPower(false);
Ling Ma317906d2022-12-05 15:58:14 -0800803 clearCacheOnRadioOff();
804 }
805
806 /** Clear fields on power off radio **/
807 private void clearCacheOnRadioOff() {
808 // Re-show is-roaming notifications after APM mode
sangyun35f23f82023-07-18 01:37:53 +0900809 mShownNotificationReasons.clear();
Chris Mantona09f3632016-02-09 14:48:42 -0800810 }
811
Taesu Lee62f826d2020-08-10 16:01:18 +0900812 private void setRadioPowerOn() {
Chris Mantona09f3632016-02-09 14:48:42 -0800813 Log.i(LOG_TAG, "Turning radio on - airplane");
Taesu Lee62f826d2020-08-10 16:01:18 +0900814 Settings.Global.putInt(
815 getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
816 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 1);
Meng Wang61307622019-10-23 14:08:43 -0700817 TelephonyProperties.airplane_mode_on(false); // false means int value 0
Chris Mantona09f3632016-02-09 14:48:42 -0800818 PhoneUtils.setRadioPower(true);
819 }
820
Taesu Lee62f826d2020-08-10 16:01:18 +0900821 private void maybeTurnCellOff(boolean isAirplaneNewlyOn) {
Chris Mantona09f3632016-02-09 14:48:42 -0800822 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700823 // If we are trying to turn off the radio, make sure there are no active
824 // emergency calls. If there are, switch airplane mode back to off.
Taesu Lee62f826d2020-08-10 16:01:18 +0900825 TelecomManager tm = (TelecomManager) getSystemService(TELECOM_SERVICE);
Tyler Gunn900d8fd2018-09-21 09:22:12 -0700826
827 if (tm != null && tm.isInEmergencyCall()) {
Santos Cordone18902f2016-03-22 17:16:04 -0700828 // Switch airplane mode back to off.
Jordan Liu0e819b12019-08-28 15:33:05 -0700829 ConnectivityManager cm =
Taesu Lee62f826d2020-08-10 16:01:18 +0900830 (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
Jordan Liu0e819b12019-08-28 15:33:05 -0700831 cm.setAirplaneMode(false);
Santos Cordone18902f2016-03-22 17:16:04 -0700832 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
833 .show();
834 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Taesu Lee62f826d2020-08-10 16:01:18 +0900835 } else if (isCellOffInAirplaneMode()) {
836 setRadioPowerOff();
Santos Cordone18902f2016-03-22 17:16:04 -0700837 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800838 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700839 }
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700840 } else {
841 Log.i(LOG_TAG, "Ignoring airplane mode: not newly on");
Chris Mantona09f3632016-02-09 14:48:42 -0800842 }
843 }
844
Taesu Lee62f826d2020-08-10 16:01:18 +0900845 private void maybeTurnCellOn(boolean isAirplaneNewlyOn) {
Chris Mantona09f3632016-02-09 14:48:42 -0800846 if (!isAirplaneNewlyOn) {
Taesu Lee62f826d2020-08-10 16:01:18 +0900847 setRadioPowerOn();
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700848 } else {
849 Log.i(LOG_TAG, "Ignoring airplane mode off: radio is already on.");
Santos Cordone18902f2016-03-22 17:16:04 -0700850 }
851 }
852
Santos Cordon593ab382013-08-06 21:58:23 -0700853 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700854 * Receiver for misc intent broadcasts the Phone app cares about.
855 */
856 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
857 @Override
858 public void onReceive(Context context, Intent intent) {
859 String action = intent.getAction();
860 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Taesu Lee3dc572b2020-08-07 18:16:22 +0900861 boolean airplaneMode = intent.getBooleanExtra("state", false);
Taesu Lee62f826d2020-08-10 16:01:18 +0900862 handleAirplaneModeChange(airplaneMode);
Amit Mahajanf5d92c82018-11-02 17:44:40 -0700863 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
864 // re-register as it may be a new IccCard
865 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
866 SubscriptionManager.INVALID_PHONE_INDEX);
867 if (SubscriptionManager.isValidPhoneId(phoneId)) {
868 PhoneUtils.unregisterIccStatus(mHandler, phoneId);
869 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED, phoneId);
870 }
Nazish Tabassum160d2112019-12-23 17:31:33 +0530871 String iccStatus = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
872 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
873 new EventSimStateChangedBag(phoneId, iccStatus)));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700874 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
875 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800876 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
877 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700878 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530879 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530880 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530881 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
882 if (phoneInEcm != null) {
883 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
884 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
885 // Start Emergency Callback Mode service
Daniel Bright30efde42020-01-09 22:11:15 -0800886 if (intent.getBooleanExtra(
887 TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530888 context.startService(new Intent(context,
889 EmergencyCallbackModeService.class));
890 } else {
891 phoneInEcm = null;
892 }
893 } else {
894 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
895 // on a device that doesn't support ECM in the first place.
896 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
897 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
898 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700899 }
900 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530901 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700902 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700903 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
904 // Roaming status could be overridden by carrier config, so we need to update it.
905 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
sangyun35f23f82023-07-18 01:37:53 +0900906 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED);
chen xubaf9fe52019-07-02 17:28:24 -0700907 updateLimitedSimFunctionForDualSim();
Lei Liu863eac02020-06-24 20:12:55 +0800908 int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
909 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
910 if (SubscriptionManager.isValidSubscriptionId(subId)) {
911 mHandler.sendMessage(mHandler.obtainMessage(EVENT_CARRIER_CONFIG_CHANGED,
912 new Integer(subId)));
913 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700914 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
915 // We also need to pay attention when default data subscription changes.
916 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
917 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
918 registerSettingsObserver();
919 Phone phone = getPhone(mDefaultDataSubId);
920 if (phone != null) {
sangyun35f23f82023-07-18 01:37:53 +0900921 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700922 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700923 }
924 }
925 }
926
Sarah Chin072ffb22022-05-03 17:58:59 -0700927 private void handleServiceStateChanged(ServiceState serviceState, int subId) {
Jack Yu1a2fc352017-07-14 17:14:37 -0700928 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Sarah Chin072ffb22022-05-03 17:58:59 -0700929 int state = serviceState.getState();
930 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -0700931
Sarah Chin072ffb22022-05-03 17:58:59 -0700932 if (VDBG) {
933 Log.v(LOG_TAG, "subId=" + subId + ", mDefaultDataSubId="
934 + mDefaultDataSubId + ", ss roaming=" + serviceState.getDataRoaming());
935 }
936 if (subId == mDefaultDataSubId) {
sangyun35f23f82023-07-18 01:37:53 +0900937 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700938 }
939 }
940
Jack Yu1a2fc352017-07-14 17:14:37 -0700941 /**
942 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
943 * to notify the user so they can enable it through settings. Vise versa if the condition
944 * changes, we need to dismiss the notification.
sangyun35f23f82023-07-18 01:37:53 +0900945 * @param reason to inform which event is called for notification update.
Jack Yu1a2fc352017-07-14 17:14:37 -0700946 */
sangyun35f23f82023-07-18 01:37:53 +0900947 private void updateDataRoamingStatus(@RoamingNotificationReason int reason) {
Jack Yu1a2fc352017-07-14 17:14:37 -0700948 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
949 Phone phone = getPhone(mDefaultDataSubId);
950 if (phone == null) {
951 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
952 return;
953 }
954
sangyun35f23f82023-07-18 01:37:53 +0900955 ServiceState serviceState = phone.getServiceState();
956 String roamingNumeric = serviceState.getOperatorNumeric();
957 String roamingNumericReason = "RoamingNumeric=" + roamingNumeric;
958 String callingReason = "CallingReason=" + reason;
959 boolean dataIsNowRoaming = serviceState.getDataRoaming();
Jack Yu3e2ac6e2022-03-26 13:59:45 -0700960 boolean dataAllowed;
961 boolean notAllowedDueToRoamingOff;
Sarah Chine04784a2022-10-31 20:32:34 -0700962 List<DataDisallowedReason> reasons = phone.getDataNetworkController()
963 .getInternetDataDisallowedReasons();
Jack Yu7968c6d2022-07-31 00:43:21 -0700964 dataAllowed = reasons.isEmpty();
965 notAllowedDueToRoamingOff = (reasons.size() == 1
966 && reasons.contains(DataDisallowedReason.ROAMING_DISABLED));
sangyun35f23f82023-07-18 01:37:53 +0900967 StringBuilder sb = new StringBuilder("updateDataRoamingStatus");
968 sb.append(" dataAllowed=").append(dataAllowed);
969 sb.append(", reasons=").append(reasons);
970 sb.append(", dataIsNowRoaming=").append(dataIsNowRoaming);
971 sb.append(", ").append(roamingNumericReason);
972 sb.append(", ").append(callingReason);
973 mDataRoamingNotifLog.log(sb.toString());
Ling Ma317906d2022-12-05 15:58:14 -0800974 if (VDBG) {
sangyun35f23f82023-07-18 01:37:53 +0900975 Log.v(LOG_TAG, sb.toString());
Ling Ma317906d2022-12-05 15:58:14 -0800976 }
Jack Yu3e2ac6e2022-03-26 13:59:45 -0700977
sangyun35f23f82023-07-18 01:37:53 +0900978 // Determine if a given roaming numeric has never been shown.
979 boolean shownInThisNumeric = false;
980 if (reason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED
981 || reason == ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED) {
982 shownInThisNumeric = mShownNotificationReasons.contains(roamingNumericReason);
983 }
984 // Determine if a notification has never been shown by given calling reason.
985 boolean shownForThisReason = mShownNotificationReasons.contains(callingReason);
986
Jack Yu3e2ac6e2022-03-26 13:59:45 -0700987 if (!dataAllowed && notAllowedDueToRoamingOff) {
sangyun35f23f82023-07-18 01:37:53 +0900988 if (!shownInThisNumeric && roamingNumeric != null) {
989 mShownNotificationReasons.add(roamingNumericReason);
990 }
991 if (!shownForThisReason
992 && reason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED) {
993 mShownNotificationReasons.add(callingReason);
Ling Ma4e15c322022-12-07 11:20:53 -0800994 }
Jordan Liuff2ccd72019-07-23 15:54:41 -0700995 // No need to show it again if we never cancelled it explicitly.
sangyun35f23f82023-07-18 01:37:53 +0900996 if (getCurrentRoamingNotification() == ROAMING_NOTIFICATION_DISCONNECTED) {
997 return;
998 }
999
Jack Yu1a2fc352017-07-14 17:14:37 -07001000 // If the only reason of no data is data roaming disabled, then we notify the user
1001 // so the user can turn on data roaming.
sangyun35f23f82023-07-18 01:37:53 +09001002 if (!shownInThisNumeric && !shownForThisReason) {
1003 updateDataRoamingNotification(ROAMING_NOTIFICATION_DISCONNECTED);
1004 } else {
1005 // Don't show roaming notification if we've already shown for this MccMnc
1006 Log.d(LOG_TAG, "Skip roaming disconnected notification since already"
1007 + " shownInThisNumeric=" + shownInThisNumeric
1008 + " shownForThisReason=" + shownForThisReason);
1009 // Dismiss notification if the other notification is shown.
1010 if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
1011 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
1012 }
1013 }
1014 } else if (dataAllowed && dataIsNowRoaming) {
1015 if (!shownInThisNumeric && roamingNumeric != null) {
1016 mShownNotificationReasons.add(roamingNumericReason);
1017 }
1018 if (!shownForThisReason
1019 && reason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED) {
1020 mShownNotificationReasons.add(callingReason);
1021 }
Ling Ma4e15c322022-12-07 11:20:53 -08001022 boolean isShowRoamingNotificationEnabled = getCarrierConfigForSubId(mDefaultDataSubId)
1023 .getBoolean(CarrierConfigManager
1024 .KEY_SHOW_DATA_CONNECTED_ROAMING_NOTIFICATION_BOOL);
sangyun35f23f82023-07-18 01:37:53 +09001025 // No need to show it again if we never cancelled it explicitly.
1026 if (getCurrentRoamingNotification() == ROAMING_NOTIFICATION_CONNECTED) {
Ling Ma4e15c322022-12-07 11:20:53 -08001027 return;
1028 }
sangyun35f23f82023-07-18 01:37:53 +09001029
1030 // Inform users that roaming charges may apply.
1031 if (!shownInThisNumeric && !shownForThisReason && isShowRoamingNotificationEnabled) {
1032 updateDataRoamingNotification(ROAMING_NOTIFICATION_CONNECTED);
1033 } else {
1034 // Don't show roaming notification if we've already shown for this MccMnc or
1035 // disabled from carrier config.
1036 Log.d(LOG_TAG, "Skip roaming connected notification since already"
1037 + " shownInThisNumeric:" + shownInThisNumeric
1038 + " shownForThisReason:" + shownForThisReason
1039 + " isShowRoamingNotificationEnabled:" + isShowRoamingNotificationEnabled);
1040 // Dismiss notification if the other notification is shown.
1041 if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
1042 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
1043 }
1044 }
1045 } else if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
Jordan Liuff2ccd72019-07-23 15:54:41 -07001046 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
1047 // is not the only data disable reason. In this case we dismiss the notification we
1048 // showed earlier.
sangyun35f23f82023-07-18 01:37:53 +09001049 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
Jack Yu1a2fc352017-07-14 17:14:37 -07001050 }
1051 }
1052
sangyun35f23f82023-07-18 01:37:53 +09001053 private void updateDataRoamingNotification(@RoamingNotification int roamingNotification) {
1054 int event;
1055 switch (roamingNotification) {
1056 case ROAMING_NOTIFICATION_NO_NOTIFICATION:
1057 Log.d(LOG_TAG, "Dismiss roaming notification");
1058 mDataRoamingNotifLog.log("Hide roaming.");
1059 event = EVENT_DATA_ROAMING_OK;
1060 break;
1061 case ROAMING_NOTIFICATION_CONNECTED:
1062 Log.d(LOG_TAG, "Show roaming connected notification");
1063 mDataRoamingNotifLog.log("Show roaming on.");
1064 event = EVENT_DATA_ROAMING_CONNECTED;
1065 break;
1066 case ROAMING_NOTIFICATION_DISCONNECTED:
1067 Log.d(LOG_TAG, "Show roaming disconnected notification");
1068 mDataRoamingNotifLog.log("Show roaming off.");
1069 event = EVENT_DATA_ROAMING_DISCONNECTED;
1070 break;
1071 default:
1072 Log.d(LOG_TAG, "Should never reach here.");
1073 mDataRoamingNotifLog.log("Should never reach here.");
1074 return;
1075 }
1076 mCurrentRoamingNotification = roamingNotification;
1077 mHandler.obtainMessage(event, mDefaultDataSubId, 0).sendToTarget();
1078 }
1079
1080 private @RoamingNotification int getCurrentRoamingNotification() {
1081 return mCurrentRoamingNotification;
1082 }
1083
Jordan Liuff2ccd72019-07-23 15:54:41 -07001084 /**
1085 *
1086 * @param subId to check roaming on
1087 * @return whether we have transitioned to dataRoaming
1088 */
1089 private boolean dataIsNowRoaming(int subId) {
Sarah Chine04784a2022-10-31 20:32:34 -07001090 return getPhone(subId).getServiceState().getDataRoaming();
Jordan Liuff2ccd72019-07-23 15:54:41 -07001091 }
1092
chen xubaf9fe52019-07-02 17:28:24 -07001093 private void updateLimitedSimFunctionForDualSim() {
1094 if (DBG) Log.d(LOG_TAG, "updateLimitedSimFunctionForDualSim");
1095 // check conditions to display limited SIM function notification under dual SIM
1096 SubscriptionManager subMgr = (SubscriptionManager) getSystemService(
1097 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
1098 List<SubscriptionInfo> subList = subMgr.getActiveSubscriptionInfoList(false);
1099 if (subList != null && subList.size() > 1) {
1100 CarrierConfigManager configMgr = (CarrierConfigManager)
1101 getSystemService(Context.CARRIER_CONFIG_SERVICE);
1102 for (SubscriptionInfo info : subList) {
1103 PersistableBundle b = configMgr.getConfigForSubId(info.getSubscriptionId());
1104 if (b != null) {
1105 if (b.getBoolean(CarrierConfigManager
1106 .KEY_LIMITED_SIM_FUNCTION_NOTIFICATION_FOR_DSDS_BOOL)) {
1107 notificationMgr.showLimitedSimFunctionWarningNotification(
1108 info.getSubscriptionId(),
1109 info.getDisplayName().toString());
1110 } else {
1111 notificationMgr.dismissLimitedSimFunctionWarningNotification(
1112 info.getSubscriptionId());
1113 }
1114 }
1115 }
1116 } else {
1117 // cancel notifications for all subs
1118 notificationMgr.dismissLimitedSimFunctionWarningNotification(
1119 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1120 }
1121 notificationMgr.dismissLimitedSimFunctionWarningNotificationForInactiveSubs();
1122
1123 }
1124
Sandeep Kuntade73a6a2014-10-15 18:45:56 +05301125 public Phone getPhoneInEcm() {
1126 return phoneInEcm;
1127 }
1128
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001129 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -08001130 * Triggers a refresh of the message waiting (voicemail) indicator.
1131 *
1132 * @param subId the subscription id we should refresh the notification for.
1133 */
1134 public void refreshMwiIndicator(int subId) {
1135 notificationMgr.refreshMwi(subId);
1136 }
1137
1138 /**
Pengquan Mengdd9ac822018-09-20 15:25:35 -07001139 * Called when the network selection on the subscription {@code subId} is changed by the user.
1140 *
1141 * @param subId the subscription id.
1142 */
1143 public void onNetworkSelectionChanged(int subId) {
1144 Phone phone = getPhone(subId);
1145 if (phone != null) {
1146 notificationMgr.updateNetworkSelection(phone.getServiceState().getState(), subId);
1147 } else {
1148 Log.w(LOG_TAG, "onNetworkSelectionChanged on null phone, subId: " + subId);
1149 }
1150 }
1151
1152 /**
James.cf Lin4b784aa2021-01-31 03:25:15 +08001153 * @return whether the device supports RCS User Capability Exchange or not.
1154 */
1155 public boolean getDeviceUceEnabled() {
1156 return (mTelephonyRcsService == null) ? false : mTelephonyRcsService.isDeviceUceEnabled();
1157 }
1158
1159 /**
1160 * Set the device supports RCS User Capability Exchange.
1161 * @param isEnabled true if the device supports UCE.
1162 */
1163 public void setDeviceUceEnabled(boolean isEnabled) {
1164 if (mTelephonyRcsService != null) {
1165 mTelephonyRcsService.setDeviceUceEnabled(isEnabled);
1166 }
1167 }
1168
1169 /**
Jack Yu1a2fc352017-07-14 17:14:37 -07001170 * Dump the state of the object, add calls to other objects as desired.
1171 *
1172 * @param fd File descriptor
1173 * @param printWriter Print writer
1174 * @param args Arguments
1175 */
1176 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
1177 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
1178 pw.println("------- PhoneGlobals -------");
1179 pw.increaseIndent();
sangyun35f23f82023-07-18 01:37:53 +09001180 pw.println("mCurrentRoamingNotification=" + mCurrentRoamingNotification);
Jack Yu1a2fc352017-07-14 17:14:37 -07001181 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
Keun young Parkdebb8532019-05-30 16:35:27 -07001182 pw.println("isSmsCapable=" + TelephonyManager.from(this).isSmsCapable());
sangyun35f23f82023-07-18 01:37:53 +09001183 pw.println("mDataRoamingNotifLog:");
Jack Yu1a2fc352017-07-14 17:14:37 -07001184 pw.increaseIndent();
1185 mDataRoamingNotifLog.dump(fd, pw, args);
1186 pw.decreaseIndent();
Brad Ebinger05f52c22019-12-05 13:03:21 -08001187 pw.println("ImsResolver:");
1188 pw.increaseIndent();
1189 try {
Brad Ebingerd1947d82021-05-17 20:54:49 +00001190 if (ImsResolver.getInstance() != null) ImsResolver.getInstance().dump(fd, pw, args);
Brad Ebinger05f52c22019-12-05 13:03:21 -08001191 } catch (Exception e) {
1192 e.printStackTrace();
1193 }
1194 pw.decreaseIndent();
Brad Ebingera68a4972020-01-30 17:31:23 -08001195 pw.println("RcsService:");
1196 try {
1197 if (mTelephonyRcsService != null) mTelephonyRcsService.dump(fd, pw, args);
1198 } catch (Exception e) {
1199 e.printStackTrace();
1200 }
Hunsuk Choi89bd22c2021-11-01 13:04:54 +00001201 pw.println("ImsStateCallbackController:");
1202 try {
1203 if (mImsStateCallbackController != null) mImsStateCallbackController.dump(pw);
1204 } catch (Exception e) {
1205 e.printStackTrace();
1206 }
Hwangoo Parkba21cf22022-11-30 14:34:04 +00001207 pw.println("DomainSelectionResolver:");
1208 pw.increaseIndent();
1209 try {
1210 if (DomainSelectionResolver.getInstance() != null) {
1211 DomainSelectionResolver.getInstance().dump(fd, pw, args);
1212 }
1213 } catch (Exception e) {
1214 e.printStackTrace();
1215 }
1216 pw.decreaseIndent();
1217 if (mDomainSelectionService != null) {
1218 mDomainSelectionService.dump(fd, pw, args);
1219 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001220 pw.decreaseIndent();
sangyun35f23f82023-07-18 01:37:53 +09001221 pw.println("mShownNotificationReasons=" + mShownNotificationReasons);
Jack Yu1a2fc352017-07-14 17:14:37 -07001222 pw.println("------- End PhoneGlobals -------");
1223 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001224}