blob: ddd0d09a243e07b9ccb845e272f9aa8ce324a511 [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;
sangyun1c1918a2023-11-13 22:37:50 +090020import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070021import android.app.Activity;
22import android.app.KeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070023import android.app.ProgressDialog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.content.BroadcastReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.ContentResolver;
26import android.content.Context;
27import android.content.ContextWrapper;
28import android.content.Intent;
29import android.content.IntentFilter;
Brad Ebinger05f52c22019-12-05 13:03:21 -080030import android.content.pm.PackageManager;
Youming Ye47a6adc2018-11-19 15:33:36 -080031import android.content.res.XmlResourceParser;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.media.AudioManager;
Santos Cordone18902f2016-03-22 17:16:04 -070033import android.net.ConnectivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070034import android.net.Uri;
35import android.os.AsyncResult;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036import android.os.Handler;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.os.Message;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070038import android.os.PersistableBundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.os.PowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.preference.PreferenceManager;
Sanket Padawe4c699232016-02-09 11:07:22 -080042import android.provider.Settings;
Meng Wang61307622019-10-23 14:08:43 -070043import android.sysprop.TelephonyProperties;
Tyler Gunn900d8fd2018-09-21 09:22:12 -070044import android.telecom.TelecomManager;
Nathan Haroldf9df6ea2019-03-08 11:54:22 -080045import android.telephony.AnomalyReporter;
Junda Liu12f7d802015-05-01 12:06:44 -070046import android.telephony.CarrierConfigManager;
Aishwarya Mallampati05483bf2024-10-08 21:42:52 +000047import android.telephony.NetworkRegistrationInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.telephony.ServiceState;
chen xubaf9fe52019-07-02 17:28:24 -070049import android.telephony.SubscriptionInfo;
Andrew Lee385019f2014-11-24 14:19:50 -080050import android.telephony.SubscriptionManager;
Sarah Chin072ffb22022-05-03 17:58:59 -070051import android.telephony.TelephonyCallback;
Hall Liuaa4211e2021-01-20 15:43:39 -080052import android.telephony.TelephonyLocalConnection;
Jack Yu1a2fc352017-07-14 17:14:37 -070053import android.telephony.TelephonyManager;
Sarah Chin37b39072023-11-05 13:28:21 -080054import android.text.TextUtils;
Ling Ma317906d2022-12-05 15:58:14 -080055import android.util.ArraySet;
Jack Yu1a2fc352017-07-14 17:14:37 -070056import android.util.LocalLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.util.Log;
Santos Cordone18902f2016-03-22 17:16:04 -070058import android.widget.Toast;
Ta-wei Yenb29425b2016-09-21 17:28:14 -070059
Brad Ebingere3ae65a2020-09-11 12:45:11 -070060import com.android.ims.ImsFeatureBinderRepository;
Siim Sammul182d61b2021-05-04 16:01:42 +010061import com.android.internal.os.BinderCallsStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070062import com.android.internal.telephony.CallManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063import com.android.internal.telephony.IccCardConstants;
64import com.android.internal.telephony.MmiCode;
65import com.android.internal.telephony.Phone;
Sarah Chin072ffb22022-05-03 17:58:59 -070066import com.android.internal.telephony.PhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067import com.android.internal.telephony.PhoneConstants;
68import com.android.internal.telephony.PhoneFactory;
Jack Yu1a2fc352017-07-14 17:14:37 -070069import com.android.internal.telephony.SettingsObserver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070import com.android.internal.telephony.TelephonyCapabilities;
Youming Ye47a6adc2018-11-19 15:33:36 -080071import com.android.internal.telephony.TelephonyComponentFactory;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070072import com.android.internal.telephony.TelephonyIntents;
Jack Yu3e2ac6e2022-03-26 13:59:45 -070073import com.android.internal.telephony.data.DataEvaluation.DataDisallowedReason;
Hwangoo Parkba21cf22022-11-30 14:34:04 +000074import com.android.internal.telephony.domainselection.DomainSelectionResolver;
Daniel Bantab26e96f2022-10-19 23:25:35 +000075import com.android.internal.telephony.emergency.EmergencyStateTracker;
Thomas Nguyen090fb002023-09-11 17:35:30 -070076import com.android.internal.telephony.flags.FeatureFlags;
Ling Ma51dd3022023-08-29 11:46:38 -070077import com.android.internal.telephony.flags.FeatureFlagsImpl;
Brad Ebinger05f52c22019-12-05 13:03:21 -080078import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn92479152021-01-20 16:30:10 -080079import com.android.internal.telephony.imsphone.ImsPhone;
80import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000081import com.android.internal.telephony.satellite.SatelliteController;
Nagendra Prasad Nagarle Basavarajuf668eda2024-02-15 15:02:57 +000082import com.android.internal.telephony.subscription.SubscriptionManagerService;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000083import com.android.internal.telephony.uicc.UiccPort;
Jordan Liu06bdef12021-03-24 17:25:46 -070084import com.android.internal.telephony.uicc.UiccProfile;
Jack Yu1a2fc352017-07-14 17:14:37 -070085import com.android.internal.util.IndentingPrintWriter;
Andrew Leefb7f92e2015-02-26 16:23:32 -080086import com.android.phone.settings.SettingsConstants;
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -070087import com.android.phone.vvm.CarrierVvmPackageInstalledReceiver;
Hunsuk Choic2e3fbc2024-05-10 05:05:17 +000088import com.android.services.telephony.domainselection.DynamicRoutingController;
James.cf Linc9f35a42020-01-15 02:35:22 +080089import com.android.services.telephony.rcs.TelephonyRcsService;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090
Jack Yu1a2fc352017-07-14 17:14:37 -070091import java.io.FileDescriptor;
92import java.io.PrintWriter;
Jordan Liuff2ccd72019-07-23 15:54:41 -070093import java.lang.annotation.Retention;
94import java.lang.annotation.RetentionPolicy;
chen xubaf9fe52019-07-02 17:28:24 -070095import java.util.List;
sangyund2cfeaa2024-03-31 12:20:40 +090096import java.util.concurrent.atomic.AtomicBoolean;
Jack Yu1a2fc352017-07-14 17:14:37 -070097
Santos Cordon7d4ddf62013-07-10 11:58:08 -070098/**
99 * Global state for the telephony subsystem when running in the primary
100 * phone process.
101 */
Sailesh Nepalbf900542014-07-15 16:18:32 -0700102public class PhoneGlobals extends ContextWrapper {
Jack Yu1a2fc352017-07-14 17:14:37 -0700103 public static final String LOG_TAG = "PhoneGlobals";
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104
105 /**
106 * Phone app-wide debug level:
107 * 0 - no debug logging
108 * 1 - normal debug logging if ro.debuggable is set (which is true in
109 * "eng" and "userdebug" builds but not "user" builds)
110 * 2 - ultra-verbose debug logging
111 *
112 * Most individual classes in the phone app have a local DBG constant,
113 * typically set to
114 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
115 * or else
116 * (PhoneApp.DBG_LEVEL >= 2)
117 * depending on the desired verbosity.
118 *
119 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
120 */
Andrew Lee88b51e22014-10-29 15:48:51 -0700121 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700122
123 private static final boolean DBG =
124 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
125 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
126
127 // Message codes; see mHandler below.
128 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
Jordan Liuff2ccd72019-07-23 15:54:41 -0700131 private static final int EVENT_DATA_ROAMING_CONNECTED = 11;
132 private static final int EVENT_DATA_ROAMING_OK = 12;
133 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 13;
Jordan Liuff2ccd72019-07-23 15:54:41 -0700134 private static final int EVENT_DATA_ROAMING_SETTINGS_CHANGED = 15;
135 private static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED = 16;
Lei Liu863eac02020-06-24 20:12:55 +0800136 private static final int EVENT_CARRIER_CONFIG_CHANGED = 17;
Sarah Chin072ffb22022-05-03 17:58:59 -0700137 private static final int EVENT_MULTI_SIM_CONFIG_CHANGED = 18;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138
139 // The MMI codes are also used by the InCallScreen.
140 public static final int MMI_INITIATE = 51;
141 public static final int MMI_COMPLETE = 52;
142 public static final int MMI_CANCEL = 53;
143 // Don't use message codes larger than 99 here; those are reserved for
144 // the individual Activities of the Phone UI.
145
Santos Cordone18902f2016-03-22 17:16:04 -0700146 public static final int AIRPLANE_ON = 1;
147 public static final int AIRPLANE_OFF = 0;
148
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149 /**
150 * Allowable values for the wake lock code.
151 * SLEEP means the device can be put to sleep.
152 * PARTIAL means wake the processor, but we display can be kept off.
153 * FULL means wake both the processor and the display.
154 */
155 public enum WakeState {
156 SLEEP,
157 PARTIAL,
158 FULL
159 }
160
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700161 private static PhoneGlobals sMe;
162
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700163 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700164 CallNotifier notifier;
Santos Cordon63a84242013-07-23 13:32:52 -0700165 NotificationMgr notificationMgr;
James.cf Linc9f35a42020-01-15 02:35:22 +0800166 TelephonyRcsService mTelephonyRcsService;
Andrew Lee9431b832015-03-09 18:46:45 -0700167 public PhoneInterfaceManager phoneMgr;
James.cf Linaf3183c2019-10-24 00:59:00 +0800168 public ImsRcsController imsRcsController;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000169 public ImsStateCallbackController mImsStateCallbackController;
joonhunshincffb7fc2021-11-28 07:32:01 +0000170 public ImsProvisioningController mImsProvisioningController;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800171 CarrierConfigLoader configLoader;
Santos Cordon63a84242013-07-23 13:32:52 -0700172
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530173 private Phone phoneInEcm;
Santos Cordon63a84242013-07-23 13:32:52 -0700174
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700175 static boolean sVoiceCapable = true;
176
Santos Cordonc593d002015-06-03 15:41:15 -0700177 // TODO: Remove, no longer used.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700178 CdmaPhoneCallState cdmaPhoneCallState;
179
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700180 // The currently-active PUK entry activity and progress dialog.
181 // Normally, these are the Emergency Dialer and the subsequent
182 // progress dialog. null if there is are no such objects in
183 // the foreground.
184 private Activity mPUKEntryActivity;
185 private ProgressDialog mPUKEntryProgressDialog;
186
Jordan Liuff2ccd72019-07-23 15:54:41 -0700187 /** @hide */
188 @Retention(RetentionPolicy.SOURCE)
sangyun35f23f82023-07-18 01:37:53 +0900189 @IntDef(prefix = {"ROAMING_NOTIFICATION_REASON_"},
190 value = {
191 ROAMING_NOTIFICATION_REASON_DATA_SETTING_CHANGED,
192 ROAMING_NOTIFICATION_REASON_DATA_ROAMING_SETTING_CHANGED,
193 ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED,
194 ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED,
sangyund2cfeaa2024-03-31 12:20:40 +0900195 ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED,
196 ROAMING_NOTIFICATION_REASON_DISCONNECTED_SINGLE_NETWORK})
sangyun35f23f82023-07-18 01:37:53 +0900197 public @interface RoamingNotificationReason {}
198 private static final int ROAMING_NOTIFICATION_REASON_DATA_SETTING_CHANGED = 0;
199 private static final int ROAMING_NOTIFICATION_REASON_DATA_ROAMING_SETTING_CHANGED = 1;
200 private static final int ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED = 2;
201 private static final int ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED = 3;
202 private static final int ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED = 4;
sangyund2cfeaa2024-03-31 12:20:40 +0900203 private static final int ROAMING_NOTIFICATION_REASON_DISCONNECTED_SINGLE_NETWORK = 5;
sangyun35f23f82023-07-18 01:37:53 +0900204
205 /** @hide */
206 @Retention(RetentionPolicy.SOURCE)
Jordan Liuff2ccd72019-07-23 15:54:41 -0700207 @IntDef(prefix = {"ROAMING_NOTIFICATION_"},
208 value = {
209 ROAMING_NOTIFICATION_NO_NOTIFICATION,
210 ROAMING_NOTIFICATION_CONNECTED,
211 ROAMING_NOTIFICATION_DISCONNECTED})
212 public @interface RoamingNotification {}
213
214 private static final int ROAMING_NOTIFICATION_NO_NOTIFICATION = 0;
215 private static final int ROAMING_NOTIFICATION_CONNECTED = 1;
216 private static final int ROAMING_NOTIFICATION_DISCONNECTED = 2;
217
218 @RoamingNotification
sangyun35f23f82023-07-18 01:37:53 +0900219 private int mCurrentRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
Jack Yu953f9352017-05-18 14:41:06 -0700220
sangyun35f23f82023-07-18 01:37:53 +0900221 /**
sangyund2cfeaa2024-03-31 12:20:40 +0900222 * If true, update roaming notifications after the Internet is completely disconnected. If
223 * carrier allows only a single data network, wait until the Internet connection is completely
224 * disconnected and then update the roaming notification once more to check if
225 * ONLY_ALLOWED_SINGLE_NETWORK disallow reason is disappeared.
226 */
227 private AtomicBoolean mWaitForInternetDisconnection = new AtomicBoolean(false);
228
229 /**
sangyun35f23f82023-07-18 01:37:53 +0900230 * Reasons that have already shown notification to prevent duplicate shows for the same reason.
231 */
232 private ArraySet<String> mShownNotificationReasons = new ArraySet<>();
Ling Ma317906d2022-12-05 15:58:14 -0800233
sangyun1c1918a2023-11-13 22:37:50 +0900234 // For reorganize_roaming_notification feature disabled.
235 @RoamingNotification
236 private int mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
237
238 // For reorganize_roaming_notification feature disabled.
239 /** Operator numerics for which we've shown is-roaming notifications. **/
240 private ArraySet<String> mPrevRoamingOperatorNumerics = new ArraySet<>();
241
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700242 private WakeState mWakeState = WakeState.SLEEP;
243
244 private PowerManager mPowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700245 private PowerManager.WakeLock mWakeLock;
246 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700247 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700248
Jack Yu1a2fc352017-07-14 17:14:37 -0700249 private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
250 private final LocalLog mDataRoamingNotifLog = new LocalLog(50);
251
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700252 // Broadcast receiver for various intent broadcasts (see onCreate())
253 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
254
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700255 private final CarrierVvmPackageInstalledReceiver mCarrierVvmPackageInstalledReceiver =
256 new CarrierVvmPackageInstalledReceiver();
257
joonhunshin051ab232024-02-06 02:21:46 +0000258 private SettingsObserver mSettingsObserver;
Siim Sammul182d61b2021-05-04 16:01:42 +0100259 private BinderCallsStats.SettingsObserver mBinderCallsSettingsObserver;
Jack Yu1a2fc352017-07-14 17:14:37 -0700260
Sarah Chin072ffb22022-05-03 17:58:59 -0700261 // Mapping of phone ID to the associated TelephonyCallback. These should be registered without
262 // fine or coarse location since we only use ServiceState for
263 private PhoneAppCallback[] mTelephonyCallbacks;
264
joonhunshin051ab232024-02-06 02:21:46 +0000265 private FeatureFlags mFeatureFlags = new FeatureFlagsImpl();
sangyun15019e02023-11-13 21:50:15 +0900266
Sarah Chin072ffb22022-05-03 17:58:59 -0700267 private class PhoneAppCallback extends TelephonyCallback implements
sangyund2cfeaa2024-03-31 12:20:40 +0900268 TelephonyCallback.ServiceStateListener,
269 TelephonyCallback.DataConnectionStateListener {
Sarah Chin072ffb22022-05-03 17:58:59 -0700270 private final int mSubId;
271
272 PhoneAppCallback(int subId) {
273 mSubId = subId;
274 }
275
276 @Override
277 public void onServiceStateChanged(ServiceState serviceState) {
278 // Note when registering that we should be registering with INCLUDE_LOCATION_DATA_NONE.
279 // PhoneGlobals only uses the state and roaming status, which does not require location.
280 handleServiceStateChanged(serviceState, mSubId);
281 }
282
sangyund2cfeaa2024-03-31 12:20:40 +0900283 @Override
284 public void onDataConnectionStateChanged(int state, int networkType) {
285 if (mSubId == mDefaultDataSubId && state == TelephonyManager.DATA_DISCONNECTED) {
286 // onDataConnectionStateChanged is an event about the state of exact DataNetwork,
287 // but since the DataNetwork of internet may not have been completely removed from
288 // the DataNetworkController list, The post handler event expects the internet data
289 // network to be completely removed from the DataNetworkController list.
290 mHandler.post(() -> {
291 if (mWaitForInternetDisconnection.compareAndSet(true, false)) {
292 Log.d(LOG_TAG, "onDisconnectedInternetDataNetwork.");
293 updateDataRoamingStatus(
294 ROAMING_NOTIFICATION_REASON_DISCONNECTED_SINGLE_NETWORK);
295 }
296 });
297 }
298 }
299
Sarah Chin072ffb22022-05-03 17:58:59 -0700300 public int getSubId() {
301 return mSubId;
302 }
303 }
304
Nazish Tabassum160d2112019-12-23 17:31:33 +0530305 private static class EventSimStateChangedBag {
306 final int mPhoneId;
307 final String mIccStatus;
308
309 EventSimStateChangedBag(int phoneId, String iccStatus) {
310 mPhoneId = phoneId;
311 mIccStatus = iccStatus;
312 }
313 }
314
Jordan Liu06bdef12021-03-24 17:25:46 -0700315 // Some carrier config settings disable the network lock screen, so we call handleSimLock
316 // when either SIM_LOCK or CARRIER_CONFIG changes so that no matter which one happens first,
317 // we still do the right thing
318 private void handleSimLock(int subType, Phone phone) {
319 PersistableBundle cc = getCarrierConfigForSubId(phone.getSubId());
320 if (!CarrierConfigManager.isConfigForIdentifiedCarrier(cc)) {
321 // If we only have the default carrier config just return, to avoid popping up the
322 // the SIM lock screen when it's disabled by the carrier.
323 Log.i(LOG_TAG, "Not showing 'SIM network unlock' screen. Carrier config not loaded");
324 return;
325 }
326 if (cc.getBoolean(CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
327 // Some products don't have the concept of a "SIM network lock"
328 Log.i(LOG_TAG, "Not showing 'SIM network unlock' screen. Disabled by carrier config");
329 return;
330 }
331
332 // if passed in subType is unknown, retrieve it here.
333 if (subType == -1) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000334 final UiccPort uiccPort = phone.getUiccPort();
335 if (uiccPort == null) {
Jordan Liu06bdef12021-03-24 17:25:46 -0700336 Log.e(LOG_TAG,
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000337 "handleSimLock: uiccPort for phone " + phone.getPhoneId() + " is null");
Jordan Liu06bdef12021-03-24 17:25:46 -0700338 return;
339 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000340 final UiccProfile uiccProfile = uiccPort.getUiccProfile();
Jordan Liu06bdef12021-03-24 17:25:46 -0700341 if (uiccProfile == null) {
342 Log.e(LOG_TAG,
343 "handleSimLock: uiccProfile for phone " + phone.getPhoneId() + " is null");
344 return;
345 }
346 subType = uiccProfile.getApplication(
347 uiccProfile.mCurrentAppType).getPersoSubState().ordinal();
348 }
349 // Normal case: show the "SIM network unlock" PIN entry screen.
350 // The user won't be able to do anything else until
351 // they enter a valid SIM network PIN.
352 Log.i(LOG_TAG, "show sim depersonal panel");
353 IccNetworkDepersonalizationPanel.showDialog(phone, subType);
354 }
355
356 private boolean isSimLocked(Phone phone) {
357 TelephonyManager tm = getSystemService(TelephonyManager.class);
358 return tm.createForSubscriptionId(phone.getSubId()).getSimState()
359 == TelephonyManager.SIM_STATE_NETWORK_LOCKED;
360 }
361
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362 Handler mHandler = new Handler() {
363 @Override
364 public void handleMessage(Message msg) {
365 PhoneConstants.State phoneState;
Jack Yu1a2fc352017-07-14 17:14:37 -0700366 if (VDBG) Log.v(LOG_TAG, "event=" + msg.what);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367 switch (msg.what) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700368 // TODO: This event should be handled by the lock screen, just
369 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
370 case EVENT_SIM_NETWORK_LOCKED:
Jordan Liu06bdef12021-03-24 17:25:46 -0700371 int subType = (Integer) ((AsyncResult) msg.obj).result;
372 Phone phone = (Phone) ((AsyncResult) msg.obj).userObj;
373 handleSimLock(subType, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374 break;
375
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700376 case EVENT_DATA_ROAMING_DISCONNECTED:
Aishwarya Mallampati05483bf2024-10-08 21:42:52 +0000377 Log.d(LOG_TAG, "EVENT_DATA_ROAMING_DISCONNECTED");
Nagendra Prasad Nagarle Basavarajuf668eda2024-02-15 15:02:57 +0000378 if (SubscriptionManagerService.getInstance()
379 .isEsimBootStrapProvisioningActiveForSubId(msg.arg1)) {
380 Log.i(LOG_TAG,
381 "skip notification/warnings during esim bootstrap activation");
Aishwarya Mallampati05483bf2024-10-08 21:42:52 +0000382 } else if (skipDataRoamingDisconnectedNotificationInSatelliteMode((msg.arg1))) {
383 Log.i(LOG_TAG, "skip data roaming disconnected notification when device is "
384 + "connected to satellite network that does not support data.");
Nagendra Prasad Nagarle Basavarajuf668eda2024-02-15 15:02:57 +0000385 } else {
Aishwarya Mallampati05483bf2024-10-08 21:42:52 +0000386 notificationMgr.showDataRoamingNotification((msg.arg1), false);
Nagendra Prasad Nagarle Basavarajuf668eda2024-02-15 15:02:57 +0000387 }
Jordan Liuff2ccd72019-07-23 15:54:41 -0700388 break;
389
390 case EVENT_DATA_ROAMING_CONNECTED:
Nagendra Prasad Nagarle Basavarajuf668eda2024-02-15 15:02:57 +0000391 if (SubscriptionManagerService.getInstance()
392 .isEsimBootStrapProvisioningActiveForSubId(msg.arg1)) {
393 Log.i(LOG_TAG,
394 "skip notification/warnings during esim bootstrap activation");
395 } else {
396 notificationMgr.showDataRoamingNotification(msg.arg1, true);
397 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398 break;
399
400 case EVENT_DATA_ROAMING_OK:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700401 notificationMgr.hideDataRoamingNotification();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700402 break;
403
404 case MMI_COMPLETE:
405 onMMIComplete((AsyncResult) msg.obj);
406 break;
407
408 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800409 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700410 break;
411
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700412 case EVENT_SIM_STATE_CHANGED:
Nazish Tabassum160d2112019-12-23 17:31:33 +0530413 EventSimStateChangedBag bag = (EventSimStateChangedBag)msg.obj;
Sarah Chin010884c2023-06-14 15:55:08 -0700414 // Dismiss the "No services" notification if the SIM is removed.
415 if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(bag.mIccStatus)) {
416 notificationMgr.dismissNetworkSelectionNotificationForInactiveSubId();
417 }
418
419 // Marks the event where the SIM goes into ready state.
420 // Right now, this is only used for the PUK-unlocking process.
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700421 if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(bag.mIccStatus)
Nazish Tabassum59126a92020-07-03 21:44:49 +0530422 || IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(bag.mIccStatus)
423 || IccCardConstants.INTENT_VALUE_ICC_NOT_READY.equals(bag.mIccStatus)
424 || IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(bag.mIccStatus)) {
Sarah Chin010884c2023-06-14 15:55:08 -0700425 // When the right event is triggered and there are UI objects in the
426 // foreground, we close them to display the lock panel.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427 if (mPUKEntryActivity != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700428 Log.i(LOG_TAG, "Dismiss puk entry activity");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700429 mPUKEntryActivity.finish();
430 mPUKEntryActivity = null;
431 }
432 if (mPUKEntryProgressDialog != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700433 Log.i(LOG_TAG, "Dismiss puk progress dialog");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434 mPUKEntryProgressDialog.dismiss();
435 mPUKEntryProgressDialog = null;
436 }
Nazish Tabassum59126a92020-07-03 21:44:49 +0530437 Log.i(LOG_TAG, "Dismissing depersonal panel" + (bag.mIccStatus));
Nazish Tabassum160d2112019-12-23 17:31:33 +0530438 IccNetworkDepersonalizationPanel.dialogDismiss(bag.mPhoneId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700439 }
440 break;
441
442 case EVENT_UNSOL_CDMA_INFO_RECORD:
443 //TODO: handle message here;
444 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700445 case EVENT_DATA_ROAMING_SETTINGS_CHANGED:
sangyun1c1918a2023-11-13 22:37:50 +0900446 if (mFeatureFlags.reorganizeRoamingNotification()) {
447 updateDataRoamingStatus(
448 ROAMING_NOTIFICATION_REASON_DATA_ROAMING_SETTING_CHANGED);
449 } else {
450 updateDataRoamingStatusForFeatureDisabled(null);
451 }
sangyun35f23f82023-07-18 01:37:53 +0900452 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700453 case EVENT_MOBILE_DATA_SETTINGS_CHANGED:
sangyun1c1918a2023-11-13 22:37:50 +0900454 if (mFeatureFlags.reorganizeRoamingNotification()) {
455 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_DATA_SETTING_CHANGED);
456 } else {
457 updateDataRoamingStatusForFeatureDisabled(null);
458 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700459 break;
Lei Liu863eac02020-06-24 20:12:55 +0800460 case EVENT_CARRIER_CONFIG_CHANGED:
461 int subId = (Integer) msg.obj;
462 // The voicemail number could be overridden by carrier config, so need to
463 // refresh the message waiting (voicemail) indicator.
464 refreshMwiIndicator(subId);
Jordan Liu06bdef12021-03-24 17:25:46 -0700465 phone = getPhone(subId);
Sarah Chin072ffb22022-05-03 17:58:59 -0700466 if (phone != null) {
467 if (isSimLocked(phone)) {
468 // pass in subType=-1 so handleSimLock can find the actual subType if
469 // needed. This is safe as valid values for subType are >= 0
470 handleSimLock(-1, phone);
471 }
472 TelephonyManager tm = getSystemService(TelephonyManager.class);
473 PhoneAppCallback callback = mTelephonyCallbacks[phone.getPhoneId()];
474 // TODO: We may need to figure out a way to unregister if subId is invalid
475 tm.createForSubscriptionId(callback.getSubId())
476 .unregisterTelephonyCallback(callback);
477 callback = new PhoneAppCallback(subId);
478 tm.createForSubscriptionId(subId).registerTelephonyCallback(
Ling Ma317906d2022-12-05 15:58:14 -0800479 TelephonyManager.INCLUDE_LOCATION_DATA_COARSE, mHandler::post,
Sarah Chin072ffb22022-05-03 17:58:59 -0700480 callback);
481 mTelephonyCallbacks[phone.getPhoneId()] = callback;
482 }
483 break;
484 case EVENT_MULTI_SIM_CONFIG_CHANGED:
485 int activeModems = (int) ((AsyncResult) msg.obj).result;
486 TelephonyManager tm = getSystemService(TelephonyManager.class);
487 // Unregister all previous callbacks
488 for (int phoneId = 0; phoneId < mTelephonyCallbacks.length; phoneId++) {
489 PhoneAppCallback callback = mTelephonyCallbacks[phoneId];
490 if (callback != null) {
491 tm.createForSubscriptionId(callback.getSubId())
492 .unregisterTelephonyCallback(callback);
493 mTelephonyCallbacks[phoneId] = null;
494 }
495 }
496 // Register callbacks for all active modems
497 for (int phoneId = 0; phoneId < activeModems; phoneId++) {
498 int sub = PhoneFactory.getPhone(phoneId).getSubId();
499 PhoneAppCallback callback = new PhoneAppCallback(sub);
500 tm.createForSubscriptionId(sub).registerTelephonyCallback(
501 TelephonyManager.INCLUDE_LOCATION_DATA_NONE, mHandler::post,
502 callback);
503 mTelephonyCallbacks[phoneId] = callback;
Jordan Liu06bdef12021-03-24 17:25:46 -0700504 }
Lei Liu863eac02020-06-24 20:12:55 +0800505 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700506 }
507 }
508 };
509
510 public PhoneGlobals(Context context) {
511 super(context);
512 sMe = this;
joonhunshin051ab232024-02-06 02:21:46 +0000513 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
514 if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
515 mSettingsObserver = new SettingsObserver(context, mHandler);
516 }
517 } else {
518 mSettingsObserver = new SettingsObserver(context, mHandler);
519 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700520 }
521
522 public void onCreate() {
523 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
524
525 ContentResolver resolver = getContentResolver();
526
Tomasz Wasilczyka8564412024-05-23 13:30:23 -0700527 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()
528 && !getResources().getBoolean(
529 com.android.internal.R.bool.config_force_phone_globals_creation)) {
joonhunshin051ab232024-02-06 02:21:46 +0000530 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
531 Log.v(LOG_TAG, "onCreate()... but not defined FEATURE_TELEPHONY");
532 return;
533 }
534 }
535
Hall Liuaa4211e2021-01-20 15:43:39 -0800536 // Initialize the shim from frameworks/opt/telephony into packages/services/Telephony.
537 TelephonyLocalConnection.setInstance(new LocalConnectionImpl(this));
538
Sarah Chin072ffb22022-05-03 17:58:59 -0700539 TelephonyManager tm = getSystemService(TelephonyManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700540 // Cache the "voice capable" flag.
541 // This flag currently comes from a resource (which is
542 // overrideable on a per-product basis):
Sarah Chin072ffb22022-05-03 17:58:59 -0700543 sVoiceCapable = tm.isVoiceCapable();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700544 // ...but this might eventually become a PackageManager "system
545 // feature" instead, in which case we'd do something like:
546 // sVoiceCapable =
547 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
548
Stuart Scottdcf40a92014-12-09 10:45:01 -0800549 if (mCM == null) {
Nathan Haroldf9df6ea2019-03-08 11:54:22 -0800550 // Initialize AnomalyReporter early so that it can be used
551 AnomalyReporter.initialize(this);
Nathan Harold0db5c5e2019-01-22 20:18:56 -0800552
Youming Ye47a6adc2018-11-19 15:33:36 -0800553 // Inject telephony component factory if configured using other jars.
554 XmlResourceParser parser = getResources().getXml(R.xml.telephony_injection);
555 TelephonyComponentFactory.getInstance().injectTheComponentFactory(parser);
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000556
557 // Create DomainSelectionResolver always, but it MUST be initialized only when
558 // the device supports AOSP domain selection architecture and
559 // has new IRadio that supports its related HAL APIs.
Hwangoo Parkbf3968c2024-01-19 07:49:22 +0000560 String dssComponentName = getResources().getString(
561 R.string.config_domain_selection_service_component_name);
562 DomainSelectionResolver.make(this, dssComponentName);
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000563
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700564 // Initialize the telephony framework
sangyun15019e02023-11-13 21:50:15 +0900565 PhoneFactory.makeDefaultPhones(this, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700566
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000567 // Initialize the DomainSelectionResolver after creating the Phone instance
568 // to check the Radio HAL version.
569 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
Hwangoo Parkbf3968c2024-01-19 07:49:22 +0000570 DomainSelectionResolver.getInstance().initialize();
Daniel Bantab26e96f2022-10-19 23:25:35 +0000571 // Initialize EmergencyStateTracker if domain selection is supported
572 boolean isSuplDdsSwitchRequiredForEmergencyCall = getResources()
573 .getBoolean(R.bool.config_gnss_supl_requires_default_data_for_emergency);
574 EmergencyStateTracker.make(this, isSuplDdsSwitchRequiredForEmergencyCall);
Hunsuk Choic2e3fbc2024-05-10 05:05:17 +0000575 DynamicRoutingController.getInstance().initialize(this);
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000576 }
577
Brad Ebinger05f52c22019-12-05 13:03:21 -0800578 // Only bring up ImsResolver if the device supports having an IMS stack.
579 if (getPackageManager().hasSystemFeature(
580 PackageManager.FEATURE_TELEPHONY_IMS)) {
581 // Get the package name of the default IMS implementation.
582 String defaultImsMmtelPackage = getResources().getString(
583 R.string.config_ims_mmtel_package);
584 String defaultImsRcsPackage = getResources().getString(
585 R.string.config_ims_rcs_package);
Brad Ebingerd1947d82021-05-17 20:54:49 +0000586 ImsResolver.make(this, defaultImsMmtelPackage,
Brad Ebingere3ae65a2020-09-11 12:45:11 -0700587 defaultImsRcsPackage, PhoneFactory.getPhones().length,
joonhunshin42441672024-04-26 01:26:14 +0000588 new ImsFeatureBinderRepository(), mFeatureFlags);
Brad Ebingerd1947d82021-05-17 20:54:49 +0000589 ImsResolver.getInstance().initialize();
Tyler Gunn92479152021-01-20 16:30:10 -0800590
591 // With the IMS phone created, load static config.xml values from the phone process
592 // so that it can be provided to the ImsPhoneCallTracker.
593 for (Phone p : PhoneFactory.getPhones()) {
594 Phone imsPhone = p.getImsPhone();
595 if (imsPhone != null && imsPhone instanceof ImsPhone) {
596 ImsPhone theImsPhone = (ImsPhone) imsPhone;
597 if (theImsPhone.getCallTracker() instanceof ImsPhoneCallTracker) {
598 ImsPhoneCallTracker ict = (ImsPhoneCallTracker)
599 theImsPhone.getCallTracker();
600
601 ImsPhoneCallTracker.Config config = new ImsPhoneCallTracker.Config();
602 config.isD2DCommunicationSupported = getResources().getBoolean(
603 R.bool.config_use_device_to_device_communication);
604 ict.setConfig(config);
605 }
606 }
607 }
Jack Yu4a0c5382024-09-05 23:03:20 -0700608 RcsProvisioningMonitor.make(this, mFeatureFlags);
Brad Ebinger05f52c22019-12-05 13:03:21 -0800609 }
610
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700611 // Start TelephonyDebugService After the default phone is created.
612 Intent intent = new Intent(this, TelephonyDebugService.class);
613 startService(intent);
614
615 mCM = CallManager.getInstance();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700616
617 // Create the NotificationMgr singleton, which is used to display
618 // status bar icons and control other status bar behavior.
619 notificationMgr = NotificationMgr.init(this);
620
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000621 // Create the SatelliteController singleton, which acts as a backend service for
622 // {@link android.telephony.satellite.SatelliteManager}.
sangyun15019e02023-11-13 21:50:15 +0900623 SatelliteController.make(this, mFeatureFlags);
Sarah Chin5f57c582023-02-14 04:16:10 -0800624
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700625 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
626 cdmaPhoneCallState = new CdmaPhoneCallState();
627 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700628
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700629 // before registering for phone state changes
630 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
631 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
632 // lock used to keep the processor awake, when we don't care for the display.
633 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
634 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700635
636 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
637
sangyun15019e02023-11-13 21:50:15 +0900638 phoneMgr = PhoneInterfaceManager.init(this, mFeatureFlags);
Santos Cordon406c0342013-08-28 00:07:47 -0700639
joonhunshin2c33ed92023-12-12 14:29:23 +0000640 imsRcsController = ImsRcsController.init(this, mFeatureFlags);
James.cf Linaf3183c2019-10-24 00:59:00 +0800641
joonhunshin21a86812023-12-10 08:21:25 +0000642 configLoader = CarrierConfigLoader.init(this, mFeatureFlags);
Brad Ebinger6c53e7f2023-01-27 16:26:44 -0800643
James.cf Linc9f35a42020-01-15 02:35:22 +0800644 if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000645 mImsStateCallbackController =
joonhunshin7da71b82024-07-17 05:20:47 +0000646 ImsStateCallbackController.make(this, PhoneFactory.getPhones().length,
647 mFeatureFlags);
Brad Ebingera68a4972020-01-30 17:31:23 -0800648 mTelephonyRcsService = new TelephonyRcsService(this,
joonhunshind9dfe8d2024-02-05 09:08:06 +0000649 PhoneFactory.getPhones().length, mFeatureFlags);
Brad Ebingera68a4972020-01-30 17:31:23 -0800650 mTelephonyRcsService.initialize();
James.cf Linc9f35a42020-01-15 02:35:22 +0800651 imsRcsController.setRcsService(mTelephonyRcsService);
joonhunshincffb7fc2021-11-28 07:32:01 +0000652 mImsProvisioningController =
joonhunshin711a8872024-03-19 10:04:08 +0000653 ImsProvisioningController.make(this, PhoneFactory.getPhones().length,
654 mFeatureFlags);
James.cf Linc9f35a42020-01-15 02:35:22 +0800655 }
656
Jack Yu1a2fc352017-07-14 17:14:37 -0700657 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700658 // asynchronous events from the telephony layer (like
659 // launching the incoming-call UI when an incoming call comes
660 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800661 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700662
Stuart Scottdcf40a92014-12-09 10:45:01 -0800663 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700664
665 // register for MMI/USSD
666 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
667
Qiong Liucc3fe812019-09-23 15:25:44 +0800668 // Initialize cell status using current airplane mode.
Taesu Lee62f826d2020-08-10 16:01:18 +0900669 handleAirplaneModeChange(
670 Settings.Global.getInt(
671 getContentResolver(),
672 Settings.Global.AIRPLANE_MODE_ON,
673 AIRPLANE_OFF)
674 == AIRPLANE_ON);
Qiong Liucc3fe812019-09-23 15:25:44 +0800675
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700676 // Register for misc other intent broadcasts.
677 IntentFilter intentFilter =
678 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700679 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
680 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700681 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700682 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
683 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700684 registerReceiver(mReceiver, intentFilter);
Jack Yuec144222023-12-13 16:03:03 -0800685 int defaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
686 if (SubscriptionManager.isValidSubscriptionId(defaultDataSubId)) {
687 if (VDBG) {
688 Log.v(LOG_TAG, "Loaded initial default data sub: " + defaultDataSubId);
sangyun15019e02023-11-13 21:50:15 +0900689 }
Jack Yuec144222023-12-13 16:03:03 -0800690 mDefaultDataSubId = defaultDataSubId;
691 registerSettingsObserver();
692 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED);
sangyundce559b2023-09-11 10:25:55 +0900693 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700694
Sarah Chin072ffb22022-05-03 17:58:59 -0700695 PhoneConfigurationManager.registerForMultiSimConfigChange(
696 mHandler, EVENT_MULTI_SIM_CONFIG_CHANGED, null);
697
698 mTelephonyCallbacks = new PhoneAppCallback[tm.getSupportedModemCount()];
Fangyuan Li7f5c2752022-06-29 18:02:31 +0800699 if (tm.getSupportedModemCount() > 0) {
700 for (Phone phone : PhoneFactory.getPhones()) {
701 int subId = phone.getSubId();
702 PhoneAppCallback callback = new PhoneAppCallback(subId);
703 tm.createForSubscriptionId(subId).registerTelephonyCallback(
704 TelephonyManager.INCLUDE_LOCATION_DATA_NONE, mHandler::post, callback);
705 mTelephonyCallbacks[phone.getPhoneId()] = callback;
706 }
Sarah Chin072ffb22022-05-03 17:58:59 -0700707 }
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700708 mCarrierVvmPackageInstalledReceiver.register(this);
709
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700710 //set the default values for the preferences in the phone.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700711 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700712 }
713
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700714 // XXX pre-load the SimProvider so that it's ready
715 resolver.getType(Uri.parse("content://icc/adn"));
716
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700717 // TODO: Register for Cdma Information Records
718 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
719
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700720 // Read HAC settings and configure audio hardware
721 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800722 int hac = android.provider.Settings.System.getInt(
723 getContentResolver(),
724 android.provider.Settings.System.HEARING_AID,
725 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700726 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Jordan Liuf71aeef2019-08-21 11:46:09 -0700727 audioManager.setParameters(
728 SettingsConstants.HAC_KEY + "=" + (hac == SettingsConstants.HAC_ENABLED
729 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700730 }
Siim Sammul182d61b2021-05-04 16:01:42 +0100731
732 // Start tracking Binder latency for the phone process.
733 mBinderCallsSettingsObserver = new BinderCallsStats.SettingsObserver(
734 getApplicationContext(),
Siim Sammula6950092021-06-22 17:14:03 +0100735 new BinderCallsStats(
736 new BinderCallsStats.Injector(),
737 com.android.internal.os.BinderLatencyProto.Dims.TELEPHONY));
Santos Cordonff506f52013-11-21 19:13:19 -0800738 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700739
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700740 /**
741 * Returns the singleton instance of the PhoneApp.
742 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800743 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700744 if (sMe == null) {
745 throw new IllegalStateException("No PhoneGlobals here!");
746 }
747 return sMe;
748 }
749
750 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800751 * Returns the default phone.
752 *
Andrew Lee385019f2014-11-24 14:19:50 -0800753 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700754 */
Andrew Lee83383e42014-10-31 12:42:28 -0700755 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800756 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700757 }
758
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800759 public static Phone getPhone(int subId) {
760 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800761 }
762
Santos Cordonde10b752013-09-19 04:11:33 -0700763 /* package */ CallManager getCallManager() {
764 return mCM;
765 }
766
Chris Manton4e9fa912015-06-19 11:26:57 -0700767 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800768 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700769 }
770
Chris Manton4e9fa912015-06-19 11:26:57 -0700771 public PersistableBundle getCarrierConfigForSubId(int subId) {
Philip P. Moltmann0079aae2020-03-05 16:24:02 -0800772 return configLoader.getConfigForSubIdWithFeature(subId, getOpPackageName(),
773 getAttributionTag());
Junda Liu605148f2015-04-28 15:23:40 -0700774 }
775
Jack Yu1a2fc352017-07-14 17:14:37 -0700776 private void registerSettingsObserver() {
777 mSettingsObserver.unobserve();
778 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
779 String mobileDataSetting = Settings.Global.MOBILE_DATA;
780 if (TelephonyManager.getDefault().getSimCount() > 1) {
781 int subId = mDefaultDataSubId;
782 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
783 dataRoamingSetting += subId;
784 mobileDataSetting += subId;
785 }
786 }
787
788 // Listen for user data roaming setting changed event
789 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
790 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
791
792 // Listen for mobile data setting changed event
793 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
794 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
795 }
796
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700797 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700798 * Sets the activity responsible for un-PUK-blocking the device
799 * so that we may close it when we receive a positive result.
800 * mPUKEntryActivity is also used to indicate to the device that
801 * we are trying to un-PUK-lock the phone. In other words, iff
802 * it is NOT null, then we are trying to unlock and waiting for
803 * the SIM to move to READY state.
804 *
805 * @param activity is the activity to close when PUK has
806 * finished unlocking. Can be set to null to indicate the unlock
807 * or SIM READYing process is over.
808 */
809 void setPukEntryActivity(Activity activity) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700810 Log.i(LOG_TAG, "setPukEntryActivity - set to " + (activity == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700811 mPUKEntryActivity = activity;
812 }
813
814 Activity getPUKEntryActivity() {
815 return mPUKEntryActivity;
816 }
817
818 /**
819 * Sets the dialog responsible for notifying the user of un-PUK-
820 * blocking - SIM READYing progress, so that we may dismiss it
821 * when we receive a positive result.
822 *
823 * @param dialog indicates the progress dialog informing the user
824 * of the state of the device. Dismissed upon completion of
825 * READYing process
826 */
827 void setPukEntryProgressDialog(ProgressDialog dialog) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700828 Log.i(LOG_TAG, "setPukEntryProgressDialog - set to "
829 + (dialog == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700830 mPUKEntryProgressDialog = dialog;
831 }
832
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700833 KeyguardManager getKeyguardManager() {
834 return mKeyguardManager;
835 }
836
837 private void onMMIComplete(AsyncResult r) {
838 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
839 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800840 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700841 }
842
fionaxu80126972017-02-01 17:01:26 -0800843 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700844 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700845 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700846 }
847
Taesu Lee62f826d2020-08-10 16:01:18 +0900848 private void handleAirplaneModeChange(boolean isAirplaneNewlyOn) {
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700849 Log.i(LOG_TAG, "handleAirplaneModeChange: isAirplaneNewlyOn=" + isAirplaneNewlyOn);
Taesu Lee62f826d2020-08-10 16:01:18 +0900850 int cellState =
851 Settings.Global.getInt(
852 getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
Chris Mantona09f3632016-02-09 14:48:42 -0800853 switch (cellState) {
854 case PhoneConstants.CELL_OFF_FLAG:
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700855 // Airplane mode does not affect the cell radio if user has turned it off.
856 Log.i(LOG_TAG, "Ignore airplane mode change due to cell off.");
Chris Mantona09f3632016-02-09 14:48:42 -0800857 break;
858 case PhoneConstants.CELL_ON_FLAG:
Taesu Lee62f826d2020-08-10 16:01:18 +0900859 maybeTurnCellOff(isAirplaneNewlyOn);
Chris Mantona09f3632016-02-09 14:48:42 -0800860 break;
861 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
Taesu Lee62f826d2020-08-10 16:01:18 +0900862 maybeTurnCellOn(isAirplaneNewlyOn);
Chris Mantona09f3632016-02-09 14:48:42 -0800863 break;
864 }
Hall Liu7f56e1a2019-07-10 14:41:14 -0700865 for (Phone phone : PhoneFactory.getPhones()) {
866 phone.getServiceStateTracker().onAirplaneModeChanged(isAirplaneNewlyOn);
867 }
Chris Mantona09f3632016-02-09 14:48:42 -0800868 }
869
870 /*
871 * Returns true if the radio must be turned off when entering airplane mode.
872 */
Taesu Lee62f826d2020-08-10 16:01:18 +0900873 private boolean isCellOffInAirplaneMode() {
874 String airplaneModeRadios =
875 Settings.Global.getString(
876 getContentResolver(), Settings.Global.AIRPLANE_MODE_RADIOS);
Chris Mantona09f3632016-02-09 14:48:42 -0800877 return airplaneModeRadios == null
878 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
879 }
880
Taesu Lee62f826d2020-08-10 16:01:18 +0900881 private void setRadioPowerOff() {
Chris Mantona09f3632016-02-09 14:48:42 -0800882 Log.i(LOG_TAG, "Turning radio off - airplane");
Taesu Lee62f826d2020-08-10 16:01:18 +0900883 Settings.Global.putInt(
884 getContentResolver(),
885 Settings.Global.CELL_ON,
886 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Chris Mantona09f3632016-02-09 14:48:42 -0800887 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
Taesu Lee62f826d2020-08-10 16:01:18 +0900888 TelephonyProperties.airplane_mode_on(true); // true means int value 1
Chris Mantona09f3632016-02-09 14:48:42 -0800889 PhoneUtils.setRadioPower(false);
Ling Ma317906d2022-12-05 15:58:14 -0800890 clearCacheOnRadioOff();
891 }
892
893 /** Clear fields on power off radio **/
894 private void clearCacheOnRadioOff() {
895 // Re-show is-roaming notifications after APM mode
sangyun1c1918a2023-11-13 22:37:50 +0900896 if (mFeatureFlags.reorganizeRoamingNotification()) {
897 mShownNotificationReasons.clear();
898 } else {
899 mPrevRoamingOperatorNumerics.clear();
900 }
Chris Mantona09f3632016-02-09 14:48:42 -0800901 }
902
Taesu Lee62f826d2020-08-10 16:01:18 +0900903 private void setRadioPowerOn() {
Chris Mantona09f3632016-02-09 14:48:42 -0800904 Log.i(LOG_TAG, "Turning radio on - airplane");
Taesu Lee62f826d2020-08-10 16:01:18 +0900905 Settings.Global.putInt(
906 getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
907 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 1);
Meng Wang61307622019-10-23 14:08:43 -0700908 TelephonyProperties.airplane_mode_on(false); // false means int value 0
Chris Mantona09f3632016-02-09 14:48:42 -0800909 PhoneUtils.setRadioPower(true);
910 }
911
Taesu Lee62f826d2020-08-10 16:01:18 +0900912 private void maybeTurnCellOff(boolean isAirplaneNewlyOn) {
Chris Mantona09f3632016-02-09 14:48:42 -0800913 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700914 // If we are trying to turn off the radio, make sure there are no active
915 // emergency calls. If there are, switch airplane mode back to off.
Taesu Lee62f826d2020-08-10 16:01:18 +0900916 TelecomManager tm = (TelecomManager) getSystemService(TELECOM_SERVICE);
Tyler Gunn900d8fd2018-09-21 09:22:12 -0700917
918 if (tm != null && tm.isInEmergencyCall()) {
Santos Cordone18902f2016-03-22 17:16:04 -0700919 // Switch airplane mode back to off.
Jordan Liu0e819b12019-08-28 15:33:05 -0700920 ConnectivityManager cm =
Taesu Lee62f826d2020-08-10 16:01:18 +0900921 (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
Jordan Liu0e819b12019-08-28 15:33:05 -0700922 cm.setAirplaneMode(false);
Santos Cordone18902f2016-03-22 17:16:04 -0700923 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
924 .show();
925 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Taesu Lee62f826d2020-08-10 16:01:18 +0900926 } else if (isCellOffInAirplaneMode()) {
927 setRadioPowerOff();
Santos Cordone18902f2016-03-22 17:16:04 -0700928 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800929 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700930 }
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700931 } else {
932 Log.i(LOG_TAG, "Ignoring airplane mode: not newly on");
Chris Mantona09f3632016-02-09 14:48:42 -0800933 }
934 }
935
Taesu Lee62f826d2020-08-10 16:01:18 +0900936 private void maybeTurnCellOn(boolean isAirplaneNewlyOn) {
Chris Mantona09f3632016-02-09 14:48:42 -0800937 if (!isAirplaneNewlyOn) {
Taesu Lee62f826d2020-08-10 16:01:18 +0900938 setRadioPowerOn();
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700939 } else {
940 Log.i(LOG_TAG, "Ignoring airplane mode off: radio is already on.");
Santos Cordone18902f2016-03-22 17:16:04 -0700941 }
942 }
943
Santos Cordon593ab382013-08-06 21:58:23 -0700944 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700945 * Receiver for misc intent broadcasts the Phone app cares about.
946 */
947 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
948 @Override
949 public void onReceive(Context context, Intent intent) {
950 String action = intent.getAction();
951 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Taesu Lee3dc572b2020-08-07 18:16:22 +0900952 boolean airplaneMode = intent.getBooleanExtra("state", false);
Taesu Lee62f826d2020-08-10 16:01:18 +0900953 handleAirplaneModeChange(airplaneMode);
Amit Mahajanf5d92c82018-11-02 17:44:40 -0700954 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
955 // re-register as it may be a new IccCard
956 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
957 SubscriptionManager.INVALID_PHONE_INDEX);
958 if (SubscriptionManager.isValidPhoneId(phoneId)) {
959 PhoneUtils.unregisterIccStatus(mHandler, phoneId);
960 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED, phoneId);
961 }
Nazish Tabassum160d2112019-12-23 17:31:33 +0530962 String iccStatus = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
963 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
964 new EventSimStateChangedBag(phoneId, iccStatus)));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700965 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
966 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800967 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
968 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700969 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530970 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530971 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530972 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
973 if (phoneInEcm != null) {
974 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
975 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
976 // Start Emergency Callback Mode service
Daniel Bright30efde42020-01-09 22:11:15 -0800977 if (intent.getBooleanExtra(
978 TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530979 context.startService(new Intent(context,
980 EmergencyCallbackModeService.class));
981 } else {
982 phoneInEcm = null;
983 }
984 } else {
985 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
986 // on a device that doesn't support ECM in the first place.
987 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
988 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
989 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700990 }
991 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530992 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700993 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700994 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
995 // Roaming status could be overridden by carrier config, so we need to update it.
996 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
sangyun1c1918a2023-11-13 22:37:50 +0900997 if (mFeatureFlags.reorganizeRoamingNotification()) {
998 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED);
999 } else {
1000 updateDataRoamingStatusForFeatureDisabled(null);
1001 }
chen xubaf9fe52019-07-02 17:28:24 -07001002 updateLimitedSimFunctionForDualSim();
Lei Liu863eac02020-06-24 20:12:55 +08001003 int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
1004 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1005 if (SubscriptionManager.isValidSubscriptionId(subId)) {
1006 mHandler.sendMessage(mHandler.obtainMessage(EVENT_CARRIER_CONFIG_CHANGED,
1007 new Integer(subId)));
1008 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001009 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
1010 // We also need to pay attention when default data subscription changes.
1011 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
1012 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
1013 registerSettingsObserver();
1014 Phone phone = getPhone(mDefaultDataSubId);
1015 if (phone != null) {
sangyun1c1918a2023-11-13 22:37:50 +09001016 if (mFeatureFlags.reorganizeRoamingNotification()) {
1017 updateDataRoamingStatus(
1018 ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED);
1019 } else {
1020 updateDataRoamingStatusForFeatureDisabled(null);
1021 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001022 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001023 }
1024 }
1025 }
1026
Sarah Chin072ffb22022-05-03 17:58:59 -07001027 private void handleServiceStateChanged(ServiceState serviceState, int subId) {
Jack Yu1a2fc352017-07-14 17:14:37 -07001028 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Sarah Chin072ffb22022-05-03 17:58:59 -07001029 int state = serviceState.getState();
1030 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -07001031
Sarah Chin072ffb22022-05-03 17:58:59 -07001032 if (VDBG) {
1033 Log.v(LOG_TAG, "subId=" + subId + ", mDefaultDataSubId="
1034 + mDefaultDataSubId + ", ss roaming=" + serviceState.getDataRoaming());
1035 }
1036 if (subId == mDefaultDataSubId) {
sangyun1c1918a2023-11-13 22:37:50 +09001037 if (mFeatureFlags.reorganizeRoamingNotification()) {
1038 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED);
1039 } else {
1040 updateDataRoamingStatusForFeatureDisabled(serviceState.getOperatorNumeric());
1041 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001042 }
1043 }
1044
Jack Yu1a2fc352017-07-14 17:14:37 -07001045 /**
1046 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
1047 * to notify the user so they can enable it through settings. Vise versa if the condition
1048 * changes, we need to dismiss the notification.
sangyund2cfeaa2024-03-31 12:20:40 +09001049 * @param notificationReason to inform which event is called for notification update.
Jack Yu1a2fc352017-07-14 17:14:37 -07001050 */
sangyund2cfeaa2024-03-31 12:20:40 +09001051 private void updateDataRoamingStatus(@RoamingNotificationReason int notificationReason) {
Jack Yu1a2fc352017-07-14 17:14:37 -07001052 Phone phone = getPhone(mDefaultDataSubId);
1053 if (phone == null) {
1054 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
1055 return;
1056 }
1057
sangyun35f23f82023-07-18 01:37:53 +09001058 ServiceState serviceState = phone.getServiceState();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08001059 if (serviceState == null) {
1060 Log.e(LOG_TAG, "updateDataRoamingStatus: serviceState is null");
1061 return;
1062 }
1063
sangyund2cfeaa2024-03-31 12:20:40 +09001064 List<DataDisallowedReason> disallowReasons = phone.getDataNetworkController()
1065 .getInternetDataDisallowedReasons();
1066
1067 if (mFeatureFlags.roamingNotificationForSingleDataNetwork()) {
1068 if (disallowReasons.contains(DataDisallowedReason.ONLY_ALLOWED_SINGLE_NETWORK)
1069 && disallowReasons.contains(DataDisallowedReason.ROAMING_DISABLED)
1070 && (notificationReason == ROAMING_NOTIFICATION_REASON_DATA_SETTING_CHANGED
1071 || notificationReason
1072 == ROAMING_NOTIFICATION_REASON_DATA_ROAMING_SETTING_CHANGED)) {
1073 // If the ONLY_ALLOWED_SINGLE_NETWORK disallow reason has not yet been removed due
1074 // to a change in mobile_data (including roaming_data) settings, update roaming
1075 // notification again after the Internet is completely disconnected to check
1076 // ONLY_ALLOWED_SINGLE_NETWORK disallow reason is removed.
1077 mWaitForInternetDisconnection.set(true);
1078 Log.d(LOG_TAG, "updateDataRoamingStatus,"
1079 + " wait for internet disconnection for single data network");
1080 } else if (!disallowReasons.contains(DataDisallowedReason.ONLY_ALLOWED_SINGLE_NETWORK)
1081 && mWaitForInternetDisconnection.compareAndSet(true, false)) {
1082 // If the ONLY_ALLOWED_SINGLE_NETWORK disallow reason has been removed,
1083 // no longer wait for Internet disconnection.
1084 Log.d(LOG_TAG, "updateDataRoamingStatus,"
1085 + " cancel to wait for internet disconnection for single data network");
1086 }
1087 }
1088
1089 updateDataRoamingStatus(notificationReason, disallowReasons, serviceState);
1090 }
1091
1092 /**
1093 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
1094 * to notify the user so they can enable it through settings. Vise versa if the condition
1095 * changes, we need to dismiss the notification.
1096 * @param notificationReason to inform which event is called for notification update.
1097 * @param disallowReasons List of reasons why internet data is not allowed. An empty list if
1098 * internet is allowed.
1099 * @param serviceState Service state from phone
1100 */
1101 private void updateDataRoamingStatus(@RoamingNotificationReason int notificationReason,
1102 List<DataDisallowedReason> disallowReasons, ServiceState serviceState) {
1103
1104 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
sangyun35f23f82023-07-18 01:37:53 +09001105 String roamingNumeric = serviceState.getOperatorNumeric();
1106 String roamingNumericReason = "RoamingNumeric=" + roamingNumeric;
sangyund2cfeaa2024-03-31 12:20:40 +09001107 String callingReason = "CallingReason=" + notificationReason;
sangyun35f23f82023-07-18 01:37:53 +09001108 boolean dataIsNowRoaming = serviceState.getDataRoaming();
Jack Yu3e2ac6e2022-03-26 13:59:45 -07001109 boolean dataAllowed;
1110 boolean notAllowedDueToRoamingOff;
sangyund2cfeaa2024-03-31 12:20:40 +09001111 dataAllowed = disallowReasons.isEmpty();
1112 notAllowedDueToRoamingOff = (disallowReasons.size() == 1
1113 && disallowReasons.contains(DataDisallowedReason.ROAMING_DISABLED));
sangyun35f23f82023-07-18 01:37:53 +09001114 StringBuilder sb = new StringBuilder("updateDataRoamingStatus");
1115 sb.append(" dataAllowed=").append(dataAllowed);
sangyund2cfeaa2024-03-31 12:20:40 +09001116 sb.append(", disallowReasons=").append(disallowReasons);
sangyun35f23f82023-07-18 01:37:53 +09001117 sb.append(", dataIsNowRoaming=").append(dataIsNowRoaming);
1118 sb.append(", ").append(roamingNumericReason);
1119 sb.append(", ").append(callingReason);
1120 mDataRoamingNotifLog.log(sb.toString());
Ling Ma317906d2022-12-05 15:58:14 -08001121 if (VDBG) {
sangyun35f23f82023-07-18 01:37:53 +09001122 Log.v(LOG_TAG, sb.toString());
Ling Ma317906d2022-12-05 15:58:14 -08001123 }
Jack Yu3e2ac6e2022-03-26 13:59:45 -07001124
sangyun35f23f82023-07-18 01:37:53 +09001125 // Determine if a given roaming numeric has never been shown.
1126 boolean shownInThisNumeric = false;
sangyund2cfeaa2024-03-31 12:20:40 +09001127 if (notificationReason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED
1128 || notificationReason == ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED) {
sangyun35f23f82023-07-18 01:37:53 +09001129 shownInThisNumeric = mShownNotificationReasons.contains(roamingNumericReason);
1130 }
1131 // Determine if a notification has never been shown by given calling reason.
1132 boolean shownForThisReason = mShownNotificationReasons.contains(callingReason);
1133
Jack Yu3e2ac6e2022-03-26 13:59:45 -07001134 if (!dataAllowed && notAllowedDueToRoamingOff) {
sangyun35f23f82023-07-18 01:37:53 +09001135 if (!shownInThisNumeric && roamingNumeric != null) {
1136 mShownNotificationReasons.add(roamingNumericReason);
1137 }
1138 if (!shownForThisReason
sangyund2cfeaa2024-03-31 12:20:40 +09001139 && notificationReason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED) {
sangyun35f23f82023-07-18 01:37:53 +09001140 mShownNotificationReasons.add(callingReason);
Ling Ma4e15c322022-12-07 11:20:53 -08001141 }
Jordan Liuff2ccd72019-07-23 15:54:41 -07001142 // No need to show it again if we never cancelled it explicitly.
sangyun35f23f82023-07-18 01:37:53 +09001143 if (getCurrentRoamingNotification() == ROAMING_NOTIFICATION_DISCONNECTED) {
1144 return;
1145 }
1146
Jack Yu1a2fc352017-07-14 17:14:37 -07001147 // If the only reason of no data is data roaming disabled, then we notify the user
1148 // so the user can turn on data roaming.
sangyun35f23f82023-07-18 01:37:53 +09001149 if (!shownInThisNumeric && !shownForThisReason) {
1150 updateDataRoamingNotification(ROAMING_NOTIFICATION_DISCONNECTED);
1151 } else {
1152 // Don't show roaming notification if we've already shown for this MccMnc
1153 Log.d(LOG_TAG, "Skip roaming disconnected notification since already"
1154 + " shownInThisNumeric=" + shownInThisNumeric
1155 + " shownForThisReason=" + shownForThisReason);
1156 // Dismiss notification if the other notification is shown.
1157 if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
1158 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
1159 }
1160 }
1161 } else if (dataAllowed && dataIsNowRoaming) {
1162 if (!shownInThisNumeric && roamingNumeric != null) {
1163 mShownNotificationReasons.add(roamingNumericReason);
1164 }
1165 if (!shownForThisReason
sangyund2cfeaa2024-03-31 12:20:40 +09001166 && notificationReason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED) {
sangyun35f23f82023-07-18 01:37:53 +09001167 mShownNotificationReasons.add(callingReason);
1168 }
Sarah Chin37b39072023-11-05 13:28:21 -08001169 boolean shouldShowRoamingNotification = shouldShowRoamingNotification(roamingNumeric);
sangyun35f23f82023-07-18 01:37:53 +09001170 // No need to show it again if we never cancelled it explicitly.
1171 if (getCurrentRoamingNotification() == ROAMING_NOTIFICATION_CONNECTED) {
Ling Ma4e15c322022-12-07 11:20:53 -08001172 return;
1173 }
sangyun35f23f82023-07-18 01:37:53 +09001174
1175 // Inform users that roaming charges may apply.
Sarah Chin37b39072023-11-05 13:28:21 -08001176 if (!shownInThisNumeric && !shownForThisReason && shouldShowRoamingNotification) {
sangyun35f23f82023-07-18 01:37:53 +09001177 updateDataRoamingNotification(ROAMING_NOTIFICATION_CONNECTED);
1178 } else {
1179 // Don't show roaming notification if we've already shown for this MccMnc or
1180 // disabled from carrier config.
1181 Log.d(LOG_TAG, "Skip roaming connected notification since already"
1182 + " shownInThisNumeric:" + shownInThisNumeric
1183 + " shownForThisReason:" + shownForThisReason
Sarah Chin37b39072023-11-05 13:28:21 -08001184 + " shouldShowRoamingNotification:" + shouldShowRoamingNotification);
sangyun35f23f82023-07-18 01:37:53 +09001185 // Dismiss notification if the other notification is shown.
1186 if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
1187 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
1188 }
1189 }
1190 } else if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
Jordan Liuff2ccd72019-07-23 15:54:41 -07001191 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
1192 // is not the only data disable reason. In this case we dismiss the notification we
1193 // showed earlier.
sangyun35f23f82023-07-18 01:37:53 +09001194 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
Jack Yu1a2fc352017-07-14 17:14:37 -07001195 }
1196 }
1197
sangyun35f23f82023-07-18 01:37:53 +09001198 private void updateDataRoamingNotification(@RoamingNotification int roamingNotification) {
1199 int event;
1200 switch (roamingNotification) {
1201 case ROAMING_NOTIFICATION_NO_NOTIFICATION:
1202 Log.d(LOG_TAG, "Dismiss roaming notification");
1203 mDataRoamingNotifLog.log("Hide roaming.");
1204 event = EVENT_DATA_ROAMING_OK;
1205 break;
1206 case ROAMING_NOTIFICATION_CONNECTED:
1207 Log.d(LOG_TAG, "Show roaming connected notification");
1208 mDataRoamingNotifLog.log("Show roaming on.");
1209 event = EVENT_DATA_ROAMING_CONNECTED;
1210 break;
1211 case ROAMING_NOTIFICATION_DISCONNECTED:
1212 Log.d(LOG_TAG, "Show roaming disconnected notification");
1213 mDataRoamingNotifLog.log("Show roaming off.");
1214 event = EVENT_DATA_ROAMING_DISCONNECTED;
1215 break;
1216 default:
1217 Log.d(LOG_TAG, "Should never reach here.");
1218 mDataRoamingNotifLog.log("Should never reach here.");
1219 return;
1220 }
1221 mCurrentRoamingNotification = roamingNotification;
1222 mHandler.obtainMessage(event, mDefaultDataSubId, 0).sendToTarget();
1223 }
1224
1225 private @RoamingNotification int getCurrentRoamingNotification() {
1226 return mCurrentRoamingNotification;
1227 }
1228
sangyun1c1918a2023-11-13 22:37:50 +09001229 // For reorganize_roaming_notification feature disabled.
1230 /**
1231 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
1232 * to notify the user so they can enable it through settings. Vise versa if the condition
1233 * changes, we need to dismiss the notification.
1234 * @param roamingOperatorNumeric The operator numeric for the current roaming. {@code null} if
1235 * the current roaming operator numeric didn't change.
1236 */
1237 private void updateDataRoamingStatusForFeatureDisabled(
1238 @Nullable String roamingOperatorNumeric) {
1239 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatusForFeatureDisabled");
1240 Phone phone = getPhone(mDefaultDataSubId);
1241 if (phone == null) {
1242 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
1243 return;
1244 }
1245
1246 boolean dataAllowed;
1247 boolean notAllowedDueToRoamingOff;
1248 List<DataDisallowedReason> reasons = phone.getDataNetworkController()
1249 .getInternetDataDisallowedReasons();
1250 dataAllowed = reasons.isEmpty();
1251 notAllowedDueToRoamingOff = (reasons.size() == 1
1252 && reasons.contains(DataDisallowedReason.ROAMING_DISABLED));
1253 mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons
1254 + ", roamingOperatorNumeric=" + roamingOperatorNumeric);
1255 if (VDBG) {
1256 Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons
1257 + ", roamingOperatorNumeric=" + roamingOperatorNumeric);
1258 }
1259
1260 if (!dataAllowed && notAllowedDueToRoamingOff) {
1261 // Don't show roaming notification if we've already shown for this MccMnc
1262 if (roamingOperatorNumeric != null
1263 && !mPrevRoamingOperatorNumerics.add(roamingOperatorNumeric)) {
1264 Log.d(LOG_TAG, "Skip roaming disconnected notification since already shown in "
1265 + "MccMnc " + roamingOperatorNumeric);
1266 return;
1267 }
1268 // No need to show it again if we never cancelled it explicitly.
1269 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_DISCONNECTED) return;
1270 // If the only reason of no data is data roaming disabled, then we notify the user
1271 // so the user can turn on data roaming.
1272 mPrevRoamingNotification = ROAMING_NOTIFICATION_DISCONNECTED;
1273 Log.d(LOG_TAG, "Show roaming disconnected notification");
1274 mDataRoamingNotifLog.log("Show roaming off.");
1275 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_DISCONNECTED);
1276 msg.arg1 = mDefaultDataSubId;
1277 msg.sendToTarget();
1278 } else if (dataAllowed && dataIsNowRoaming(mDefaultDataSubId)) {
sangyun5abbf7e2024-02-01 00:47:30 +09001279 if (!shouldShowRoamingNotification(roamingOperatorNumeric != null
1280 ? roamingOperatorNumeric : phone.getServiceState().getOperatorNumeric())) {
Sarah Chin37b39072023-11-05 13:28:21 -08001281 Log.d(LOG_TAG, "Skip showing roaming connected notification.");
1282 return;
1283 }
sangyun1c1918a2023-11-13 22:37:50 +09001284 // Don't show roaming notification if we've already shown for this MccMnc
1285 if (roamingOperatorNumeric != null
1286 && !mPrevRoamingOperatorNumerics.add(roamingOperatorNumeric)) {
1287 Log.d(LOG_TAG, "Skip roaming connected notification since already shown in "
1288 + "MccMnc " + roamingOperatorNumeric);
1289 return;
1290 }
1291 // No need to show it again if we never cancelled it explicitly, or carrier config
1292 // indicates this is not needed.
1293 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_CONNECTED) return;
1294 mPrevRoamingNotification = ROAMING_NOTIFICATION_CONNECTED;
1295 Log.d(LOG_TAG, "Show roaming connected notification");
1296 mDataRoamingNotifLog.log("Show roaming on.");
1297 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_CONNECTED);
1298 msg.arg1 = mDefaultDataSubId;
1299 msg.sendToTarget();
1300 } else if (mPrevRoamingNotification != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
1301 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
1302 // is not the only data disable reason. In this case we dismiss the notification we
1303 // showed earlier.
1304 mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
1305 Log.d(LOG_TAG, "Dismiss roaming notification");
1306 mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed);
1307 mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
1308 }
1309 }
1310
Jordan Liuff2ccd72019-07-23 15:54:41 -07001311 /**
1312 *
1313 * @param subId to check roaming on
1314 * @return whether we have transitioned to dataRoaming
1315 */
1316 private boolean dataIsNowRoaming(int subId) {
Sarah Chine04784a2022-10-31 20:32:34 -07001317 return getPhone(subId).getServiceState().getDataRoaming();
Jordan Liuff2ccd72019-07-23 15:54:41 -07001318 }
1319
Sarah Chin37b39072023-11-05 13:28:21 -08001320 private boolean shouldShowRoamingNotification(String roamingNumeric) {
1321 PersistableBundle config = getCarrierConfigForSubId(mDefaultDataSubId);
1322 boolean showRoamingNotification = config.getBoolean(
1323 CarrierConfigManager.KEY_SHOW_DATA_CONNECTED_ROAMING_NOTIFICATION_BOOL);
1324
1325 if (TextUtils.isEmpty(roamingNumeric) || !mFeatureFlags.hideRoamingIcon()) {
1326 Log.d(LOG_TAG, "shouldShowRoamingNotification: roamingNumeric=" + roamingNumeric
1327 + ", hideRoaming=" + mFeatureFlags.hideRoamingIcon());
1328 return showRoamingNotification;
1329 }
1330
1331 String[] includedMccMncs = config.getStringArray(CarrierConfigManager
1332 .KEY_DATA_CONNECTED_ROAMING_NOTIFICATION_INCLUDED_MCC_MNCS_STRING_ARRAY);
1333 if (includedMccMncs != null) {
1334 for (String mccMnc : includedMccMncs) {
1335 if (roamingNumeric.equals(mccMnc)) {
1336 Log.d(LOG_TAG, "shouldShowRoamingNotification: show for MCC/MNC " + mccMnc);
1337 return showRoamingNotification;
1338 }
1339 }
1340 }
1341
1342 String[] excludedMccs = config.getStringArray(CarrierConfigManager
1343 .KEY_DATA_CONNECTED_ROAMING_NOTIFICATION_EXCLUDED_MCCS_STRING_ARRAY);
1344 String roamingMcc = roamingNumeric.length() < 3 ? "" : roamingNumeric.substring(0, 3);
1345 if (excludedMccs != null && !TextUtils.isEmpty(roamingMcc)) {
1346 for (String mcc : excludedMccs) {
1347 if (roamingMcc.equals(mcc)) {
1348 Log.d(LOG_TAG, "shouldShowRoamingNotification: ignore for MCC " + mcc);
1349 return false;
1350 }
1351 }
1352 }
1353
1354 if (showRoamingNotification) {
1355 Log.d(LOG_TAG, "shouldShowRoamingNotification: show for numeric " + roamingNumeric);
1356 }
1357 return showRoamingNotification;
1358 }
1359
chen xubaf9fe52019-07-02 17:28:24 -07001360 private void updateLimitedSimFunctionForDualSim() {
1361 if (DBG) Log.d(LOG_TAG, "updateLimitedSimFunctionForDualSim");
1362 // check conditions to display limited SIM function notification under dual SIM
1363 SubscriptionManager subMgr = (SubscriptionManager) getSystemService(
1364 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
1365 List<SubscriptionInfo> subList = subMgr.getActiveSubscriptionInfoList(false);
1366 if (subList != null && subList.size() > 1) {
1367 CarrierConfigManager configMgr = (CarrierConfigManager)
1368 getSystemService(Context.CARRIER_CONFIG_SERVICE);
1369 for (SubscriptionInfo info : subList) {
1370 PersistableBundle b = configMgr.getConfigForSubId(info.getSubscriptionId());
1371 if (b != null) {
1372 if (b.getBoolean(CarrierConfigManager
1373 .KEY_LIMITED_SIM_FUNCTION_NOTIFICATION_FOR_DSDS_BOOL)) {
1374 notificationMgr.showLimitedSimFunctionWarningNotification(
1375 info.getSubscriptionId(),
1376 info.getDisplayName().toString());
1377 } else {
1378 notificationMgr.dismissLimitedSimFunctionWarningNotification(
1379 info.getSubscriptionId());
1380 }
1381 }
1382 }
1383 } else {
1384 // cancel notifications for all subs
1385 notificationMgr.dismissLimitedSimFunctionWarningNotification(
1386 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1387 }
1388 notificationMgr.dismissLimitedSimFunctionWarningNotificationForInactiveSubs();
1389
1390 }
1391
Sandeep Kuntade73a6a2014-10-15 18:45:56 +05301392 public Phone getPhoneInEcm() {
1393 return phoneInEcm;
1394 }
1395
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001396 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -08001397 * Triggers a refresh of the message waiting (voicemail) indicator.
1398 *
1399 * @param subId the subscription id we should refresh the notification for.
1400 */
1401 public void refreshMwiIndicator(int subId) {
1402 notificationMgr.refreshMwi(subId);
1403 }
1404
1405 /**
Pengquan Mengdd9ac822018-09-20 15:25:35 -07001406 * Called when the network selection on the subscription {@code subId} is changed by the user.
1407 *
1408 * @param subId the subscription id.
1409 */
1410 public void onNetworkSelectionChanged(int subId) {
1411 Phone phone = getPhone(subId);
1412 if (phone != null) {
1413 notificationMgr.updateNetworkSelection(phone.getServiceState().getState(), subId);
1414 } else {
1415 Log.w(LOG_TAG, "onNetworkSelectionChanged on null phone, subId: " + subId);
1416 }
1417 }
1418
1419 /**
James.cf Lin4b784aa2021-01-31 03:25:15 +08001420 * @return whether the device supports RCS User Capability Exchange or not.
1421 */
1422 public boolean getDeviceUceEnabled() {
1423 return (mTelephonyRcsService == null) ? false : mTelephonyRcsService.isDeviceUceEnabled();
1424 }
1425
1426 /**
1427 * Set the device supports RCS User Capability Exchange.
1428 * @param isEnabled true if the device supports UCE.
1429 */
1430 public void setDeviceUceEnabled(boolean isEnabled) {
1431 if (mTelephonyRcsService != null) {
1432 mTelephonyRcsService.setDeviceUceEnabled(isEnabled);
1433 }
1434 }
1435
1436 /**
Jack Yu1a2fc352017-07-14 17:14:37 -07001437 * Dump the state of the object, add calls to other objects as desired.
1438 *
1439 * @param fd File descriptor
1440 * @param printWriter Print writer
1441 * @param args Arguments
1442 */
1443 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
1444 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
1445 pw.println("------- PhoneGlobals -------");
1446 pw.increaseIndent();
sangyun15019e02023-11-13 21:50:15 +09001447 pw.println("FeatureFlags:");
1448 pw.increaseIndent();
sangyun1c1918a2023-11-13 22:37:50 +09001449 pw.println("reorganizeRoamingNotification="
1450 + mFeatureFlags.reorganizeRoamingNotification());
sangyund5f37ab2023-11-13 22:52:28 +09001451 pw.println("dismissNetworkSelectionNotificationOnSimDisable="
1452 + mFeatureFlags.dismissNetworkSelectionNotificationOnSimDisable());
sangyun15019e02023-11-13 21:50:15 +09001453 pw.decreaseIndent();
sangyun1c1918a2023-11-13 22:37:50 +09001454 if (mFeatureFlags.reorganizeRoamingNotification()) {
1455 pw.println("mCurrentRoamingNotification=" + mCurrentRoamingNotification);
1456 } else {
1457 pw.println("mPrevRoamingNotification=" + mPrevRoamingNotification);
1458 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001459 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
Keun young Parkdebb8532019-05-30 16:35:27 -07001460 pw.println("isSmsCapable=" + TelephonyManager.from(this).isSmsCapable());
sangyun35f23f82023-07-18 01:37:53 +09001461 pw.println("mDataRoamingNotifLog:");
Jack Yu1a2fc352017-07-14 17:14:37 -07001462 pw.increaseIndent();
1463 mDataRoamingNotifLog.dump(fd, pw, args);
1464 pw.decreaseIndent();
Brad Ebinger05f52c22019-12-05 13:03:21 -08001465 pw.println("ImsResolver:");
1466 pw.increaseIndent();
1467 try {
Brad Ebingerd1947d82021-05-17 20:54:49 +00001468 if (ImsResolver.getInstance() != null) ImsResolver.getInstance().dump(fd, pw, args);
Brad Ebinger05f52c22019-12-05 13:03:21 -08001469 } catch (Exception e) {
1470 e.printStackTrace();
1471 }
1472 pw.decreaseIndent();
Brad Ebingera68a4972020-01-30 17:31:23 -08001473 pw.println("RcsService:");
1474 try {
1475 if (mTelephonyRcsService != null) mTelephonyRcsService.dump(fd, pw, args);
1476 } catch (Exception e) {
1477 e.printStackTrace();
1478 }
Hunsuk Choi89bd22c2021-11-01 13:04:54 +00001479 pw.println("ImsStateCallbackController:");
1480 try {
1481 if (mImsStateCallbackController != null) mImsStateCallbackController.dump(pw);
1482 } catch (Exception e) {
1483 e.printStackTrace();
1484 }
Hwangoo Parkba21cf22022-11-30 14:34:04 +00001485 pw.println("DomainSelectionResolver:");
1486 pw.increaseIndent();
1487 try {
1488 if (DomainSelectionResolver.getInstance() != null) {
1489 DomainSelectionResolver.getInstance().dump(fd, pw, args);
1490 }
1491 } catch (Exception e) {
1492 e.printStackTrace();
1493 }
1494 pw.decreaseIndent();
Jack Yu1a2fc352017-07-14 17:14:37 -07001495 pw.decreaseIndent();
sangyun1c1918a2023-11-13 22:37:50 +09001496 if (mFeatureFlags.reorganizeRoamingNotification()) {
1497 pw.println("mShownNotificationReasons=" + mShownNotificationReasons);
1498 } else {
1499 pw.println("mPrevRoamingOperatorNumerics:" + mPrevRoamingOperatorNumerics);
1500 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001501 pw.println("------- End PhoneGlobals -------");
1502 }
Aishwarya Mallampati05483bf2024-10-08 21:42:52 +00001503
1504 private boolean skipDataRoamingDisconnectedNotificationInSatelliteMode(int subId) {
1505 SatelliteController satelliteController = SatelliteController.getInstance();
1506 if (satelliteController.isSatelliteEnabledOrBeingEnabled()) {
1507 Log.d(LOG_TAG, "skipDataRoamingDisconnected - skip notification as "
1508 + "satellite is enabled or being enabled");
1509 return true;
1510 }
1511
1512 int phoneId = SubscriptionManager.getPhoneId(subId);
1513 Phone phone = PhoneFactory.getPhone(phoneId);
1514 ServiceState serviceState = phone.getServiceState();
1515 if (serviceState != null && serviceState.isUsingNonTerrestrialNetwork()) {
1516 Log.d(LOG_TAG, "skipDataRoamingDisconnected - isUsingNtn");
1517 List<Integer> capabilities =
1518 satelliteController.getCapabilitiesForCarrierRoamingSatelliteMode(phone);
1519 if (!capabilities.contains(NetworkRegistrationInfo.SERVICE_TYPE_DATA)) {
1520 // Skip data roaming disconnected notification as device is connected to
1521 // non-terrestrial network that does not support data.
1522 Log.d(LOG_TAG, "skipDataRoamingDisconnected - skip notification as "
1523 + "NTN does not support data");
1524 return true;
1525 }
1526 }
1527
1528 Log.d(LOG_TAG, "skipDataRoamingDisconnected - do not skip notification.");
1529 return false;
1530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001531}