blob: dcddf2bae0910e57f33864ea9ae6a1e1b0079b36 [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);
yongnamcha2980ac02024-10-11 05:13:52 +0000574 EmergencyStateTracker.make(this, isSuplDdsSwitchRequiredForEmergencyCall,
575 mFeatureFlags);
Hunsuk Choic2e3fbc2024-05-10 05:05:17 +0000576 DynamicRoutingController.getInstance().initialize(this);
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000577 }
578
Brad Ebinger05f52c22019-12-05 13:03:21 -0800579 // Only bring up ImsResolver if the device supports having an IMS stack.
580 if (getPackageManager().hasSystemFeature(
581 PackageManager.FEATURE_TELEPHONY_IMS)) {
582 // Get the package name of the default IMS implementation.
583 String defaultImsMmtelPackage = getResources().getString(
584 R.string.config_ims_mmtel_package);
585 String defaultImsRcsPackage = getResources().getString(
586 R.string.config_ims_rcs_package);
Brad Ebingerd1947d82021-05-17 20:54:49 +0000587 ImsResolver.make(this, defaultImsMmtelPackage,
Brad Ebingere3ae65a2020-09-11 12:45:11 -0700588 defaultImsRcsPackage, PhoneFactory.getPhones().length,
joonhunshin42441672024-04-26 01:26:14 +0000589 new ImsFeatureBinderRepository(), mFeatureFlags);
Brad Ebingerd1947d82021-05-17 20:54:49 +0000590 ImsResolver.getInstance().initialize();
Tyler Gunn92479152021-01-20 16:30:10 -0800591
592 // With the IMS phone created, load static config.xml values from the phone process
593 // so that it can be provided to the ImsPhoneCallTracker.
594 for (Phone p : PhoneFactory.getPhones()) {
595 Phone imsPhone = p.getImsPhone();
596 if (imsPhone != null && imsPhone instanceof ImsPhone) {
597 ImsPhone theImsPhone = (ImsPhone) imsPhone;
598 if (theImsPhone.getCallTracker() instanceof ImsPhoneCallTracker) {
599 ImsPhoneCallTracker ict = (ImsPhoneCallTracker)
600 theImsPhone.getCallTracker();
601
602 ImsPhoneCallTracker.Config config = new ImsPhoneCallTracker.Config();
603 config.isD2DCommunicationSupported = getResources().getBoolean(
604 R.bool.config_use_device_to_device_communication);
605 ict.setConfig(config);
606 }
607 }
608 }
Jack Yu4a0c5382024-09-05 23:03:20 -0700609 RcsProvisioningMonitor.make(this, mFeatureFlags);
Brad Ebinger05f52c22019-12-05 13:03:21 -0800610 }
611
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700612 // Start TelephonyDebugService After the default phone is created.
613 Intent intent = new Intent(this, TelephonyDebugService.class);
614 startService(intent);
615
616 mCM = CallManager.getInstance();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700617
618 // Create the NotificationMgr singleton, which is used to display
619 // status bar icons and control other status bar behavior.
620 notificationMgr = NotificationMgr.init(this);
621
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000622 // Create the SatelliteController singleton, which acts as a backend service for
623 // {@link android.telephony.satellite.SatelliteManager}.
sangyun15019e02023-11-13 21:50:15 +0900624 SatelliteController.make(this, mFeatureFlags);
Sarah Chin5f57c582023-02-14 04:16:10 -0800625
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700626 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
627 cdmaPhoneCallState = new CdmaPhoneCallState();
628 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700629
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700630 // before registering for phone state changes
631 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
632 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
633 // lock used to keep the processor awake, when we don't care for the display.
634 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
635 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700636
637 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
638
sangyun15019e02023-11-13 21:50:15 +0900639 phoneMgr = PhoneInterfaceManager.init(this, mFeatureFlags);
Santos Cordon406c0342013-08-28 00:07:47 -0700640
joonhunshin2c33ed92023-12-12 14:29:23 +0000641 imsRcsController = ImsRcsController.init(this, mFeatureFlags);
James.cf Linaf3183c2019-10-24 00:59:00 +0800642
joonhunshin21a86812023-12-10 08:21:25 +0000643 configLoader = CarrierConfigLoader.init(this, mFeatureFlags);
Brad Ebinger6c53e7f2023-01-27 16:26:44 -0800644
James.cf Linc9f35a42020-01-15 02:35:22 +0800645 if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000646 mImsStateCallbackController =
joonhunshin7da71b82024-07-17 05:20:47 +0000647 ImsStateCallbackController.make(this, PhoneFactory.getPhones().length,
648 mFeatureFlags);
Brad Ebingera68a4972020-01-30 17:31:23 -0800649 mTelephonyRcsService = new TelephonyRcsService(this,
joonhunshind9dfe8d2024-02-05 09:08:06 +0000650 PhoneFactory.getPhones().length, mFeatureFlags);
Brad Ebingera68a4972020-01-30 17:31:23 -0800651 mTelephonyRcsService.initialize();
James.cf Linc9f35a42020-01-15 02:35:22 +0800652 imsRcsController.setRcsService(mTelephonyRcsService);
joonhunshincffb7fc2021-11-28 07:32:01 +0000653 mImsProvisioningController =
joonhunshin711a8872024-03-19 10:04:08 +0000654 ImsProvisioningController.make(this, PhoneFactory.getPhones().length,
655 mFeatureFlags);
James.cf Linc9f35a42020-01-15 02:35:22 +0800656 }
657
Jack Yu1a2fc352017-07-14 17:14:37 -0700658 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700659 // asynchronous events from the telephony layer (like
660 // launching the incoming-call UI when an incoming call comes
661 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800662 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700663
Stuart Scottdcf40a92014-12-09 10:45:01 -0800664 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700665
666 // register for MMI/USSD
667 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
668
Qiong Liucc3fe812019-09-23 15:25:44 +0800669 // Initialize cell status using current airplane mode.
Taesu Lee62f826d2020-08-10 16:01:18 +0900670 handleAirplaneModeChange(
671 Settings.Global.getInt(
672 getContentResolver(),
673 Settings.Global.AIRPLANE_MODE_ON,
674 AIRPLANE_OFF)
675 == AIRPLANE_ON);
Qiong Liucc3fe812019-09-23 15:25:44 +0800676
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700677 // Register for misc other intent broadcasts.
678 IntentFilter intentFilter =
679 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700680 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
681 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700682 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700683 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
684 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700685 registerReceiver(mReceiver, intentFilter);
Jack Yuec144222023-12-13 16:03:03 -0800686 int defaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
687 if (SubscriptionManager.isValidSubscriptionId(defaultDataSubId)) {
688 if (VDBG) {
689 Log.v(LOG_TAG, "Loaded initial default data sub: " + defaultDataSubId);
sangyun15019e02023-11-13 21:50:15 +0900690 }
Jack Yuec144222023-12-13 16:03:03 -0800691 mDefaultDataSubId = defaultDataSubId;
692 registerSettingsObserver();
693 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED);
sangyundce559b2023-09-11 10:25:55 +0900694 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700695
Sarah Chin072ffb22022-05-03 17:58:59 -0700696 PhoneConfigurationManager.registerForMultiSimConfigChange(
697 mHandler, EVENT_MULTI_SIM_CONFIG_CHANGED, null);
698
699 mTelephonyCallbacks = new PhoneAppCallback[tm.getSupportedModemCount()];
Fangyuan Li7f5c2752022-06-29 18:02:31 +0800700 if (tm.getSupportedModemCount() > 0) {
701 for (Phone phone : PhoneFactory.getPhones()) {
702 int subId = phone.getSubId();
703 PhoneAppCallback callback = new PhoneAppCallback(subId);
704 tm.createForSubscriptionId(subId).registerTelephonyCallback(
705 TelephonyManager.INCLUDE_LOCATION_DATA_NONE, mHandler::post, callback);
706 mTelephonyCallbacks[phone.getPhoneId()] = callback;
707 }
Sarah Chin072ffb22022-05-03 17:58:59 -0700708 }
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700709 mCarrierVvmPackageInstalledReceiver.register(this);
710
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700711 //set the default values for the preferences in the phone.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700712 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700713 }
714
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700715 // XXX pre-load the SimProvider so that it's ready
716 resolver.getType(Uri.parse("content://icc/adn"));
717
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700718 // TODO: Register for Cdma Information Records
719 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
720
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700721 // Read HAC settings and configure audio hardware
722 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800723 int hac = android.provider.Settings.System.getInt(
724 getContentResolver(),
725 android.provider.Settings.System.HEARING_AID,
726 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700727 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Jordan Liuf71aeef2019-08-21 11:46:09 -0700728 audioManager.setParameters(
729 SettingsConstants.HAC_KEY + "=" + (hac == SettingsConstants.HAC_ENABLED
730 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700731 }
Siim Sammul182d61b2021-05-04 16:01:42 +0100732
733 // Start tracking Binder latency for the phone process.
734 mBinderCallsSettingsObserver = new BinderCallsStats.SettingsObserver(
735 getApplicationContext(),
Siim Sammula6950092021-06-22 17:14:03 +0100736 new BinderCallsStats(
737 new BinderCallsStats.Injector(),
738 com.android.internal.os.BinderLatencyProto.Dims.TELEPHONY));
Santos Cordonff506f52013-11-21 19:13:19 -0800739 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700740
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700741 /**
742 * Returns the singleton instance of the PhoneApp.
743 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800744 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700745 if (sMe == null) {
746 throw new IllegalStateException("No PhoneGlobals here!");
747 }
748 return sMe;
749 }
750
751 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800752 * Returns the default phone.
753 *
Andrew Lee385019f2014-11-24 14:19:50 -0800754 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700755 */
Andrew Lee83383e42014-10-31 12:42:28 -0700756 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800757 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700758 }
759
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800760 public static Phone getPhone(int subId) {
761 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800762 }
763
Santos Cordonde10b752013-09-19 04:11:33 -0700764 /* package */ CallManager getCallManager() {
765 return mCM;
766 }
767
Chris Manton4e9fa912015-06-19 11:26:57 -0700768 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800769 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700770 }
771
Chris Manton4e9fa912015-06-19 11:26:57 -0700772 public PersistableBundle getCarrierConfigForSubId(int subId) {
Philip P. Moltmann0079aae2020-03-05 16:24:02 -0800773 return configLoader.getConfigForSubIdWithFeature(subId, getOpPackageName(),
774 getAttributionTag());
Junda Liu605148f2015-04-28 15:23:40 -0700775 }
776
Jack Yu1a2fc352017-07-14 17:14:37 -0700777 private void registerSettingsObserver() {
778 mSettingsObserver.unobserve();
779 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
780 String mobileDataSetting = Settings.Global.MOBILE_DATA;
781 if (TelephonyManager.getDefault().getSimCount() > 1) {
782 int subId = mDefaultDataSubId;
783 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
784 dataRoamingSetting += subId;
785 mobileDataSetting += subId;
786 }
787 }
788
789 // Listen for user data roaming setting changed event
790 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
791 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
792
793 // Listen for mobile data setting changed event
794 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
795 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
796 }
797
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700798 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700799 * Sets the activity responsible for un-PUK-blocking the device
800 * so that we may close it when we receive a positive result.
801 * mPUKEntryActivity is also used to indicate to the device that
802 * we are trying to un-PUK-lock the phone. In other words, iff
803 * it is NOT null, then we are trying to unlock and waiting for
804 * the SIM to move to READY state.
805 *
806 * @param activity is the activity to close when PUK has
807 * finished unlocking. Can be set to null to indicate the unlock
808 * or SIM READYing process is over.
809 */
810 void setPukEntryActivity(Activity activity) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700811 Log.i(LOG_TAG, "setPukEntryActivity - set to " + (activity == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700812 mPUKEntryActivity = activity;
813 }
814
815 Activity getPUKEntryActivity() {
816 return mPUKEntryActivity;
817 }
818
819 /**
820 * Sets the dialog responsible for notifying the user of un-PUK-
821 * blocking - SIM READYing progress, so that we may dismiss it
822 * when we receive a positive result.
823 *
824 * @param dialog indicates the progress dialog informing the user
825 * of the state of the device. Dismissed upon completion of
826 * READYing process
827 */
828 void setPukEntryProgressDialog(ProgressDialog dialog) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700829 Log.i(LOG_TAG, "setPukEntryProgressDialog - set to "
830 + (dialog == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700831 mPUKEntryProgressDialog = dialog;
832 }
833
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700834 KeyguardManager getKeyguardManager() {
835 return mKeyguardManager;
836 }
837
838 private void onMMIComplete(AsyncResult r) {
839 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
840 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800841 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700842 }
843
fionaxu80126972017-02-01 17:01:26 -0800844 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700845 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700846 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700847 }
848
Taesu Lee62f826d2020-08-10 16:01:18 +0900849 private void handleAirplaneModeChange(boolean isAirplaneNewlyOn) {
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700850 Log.i(LOG_TAG, "handleAirplaneModeChange: isAirplaneNewlyOn=" + isAirplaneNewlyOn);
Taesu Lee62f826d2020-08-10 16:01:18 +0900851 int cellState =
852 Settings.Global.getInt(
853 getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
Chris Mantona09f3632016-02-09 14:48:42 -0800854 switch (cellState) {
855 case PhoneConstants.CELL_OFF_FLAG:
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700856 // Airplane mode does not affect the cell radio if user has turned it off.
857 Log.i(LOG_TAG, "Ignore airplane mode change due to cell off.");
Chris Mantona09f3632016-02-09 14:48:42 -0800858 break;
859 case PhoneConstants.CELL_ON_FLAG:
Taesu Lee62f826d2020-08-10 16:01:18 +0900860 maybeTurnCellOff(isAirplaneNewlyOn);
Chris Mantona09f3632016-02-09 14:48:42 -0800861 break;
862 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
Taesu Lee62f826d2020-08-10 16:01:18 +0900863 maybeTurnCellOn(isAirplaneNewlyOn);
Chris Mantona09f3632016-02-09 14:48:42 -0800864 break;
865 }
Hall Liu7f56e1a2019-07-10 14:41:14 -0700866 for (Phone phone : PhoneFactory.getPhones()) {
867 phone.getServiceStateTracker().onAirplaneModeChanged(isAirplaneNewlyOn);
868 }
Chris Mantona09f3632016-02-09 14:48:42 -0800869 }
870
871 /*
872 * Returns true if the radio must be turned off when entering airplane mode.
873 */
Taesu Lee62f826d2020-08-10 16:01:18 +0900874 private boolean isCellOffInAirplaneMode() {
875 String airplaneModeRadios =
876 Settings.Global.getString(
877 getContentResolver(), Settings.Global.AIRPLANE_MODE_RADIOS);
Chris Mantona09f3632016-02-09 14:48:42 -0800878 return airplaneModeRadios == null
879 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
880 }
881
Taesu Lee62f826d2020-08-10 16:01:18 +0900882 private void setRadioPowerOff() {
Chris Mantona09f3632016-02-09 14:48:42 -0800883 Log.i(LOG_TAG, "Turning radio off - airplane");
Taesu Lee62f826d2020-08-10 16:01:18 +0900884 Settings.Global.putInt(
885 getContentResolver(),
886 Settings.Global.CELL_ON,
887 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Chris Mantona09f3632016-02-09 14:48:42 -0800888 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
Taesu Lee62f826d2020-08-10 16:01:18 +0900889 TelephonyProperties.airplane_mode_on(true); // true means int value 1
Chris Mantona09f3632016-02-09 14:48:42 -0800890 PhoneUtils.setRadioPower(false);
Ling Ma317906d2022-12-05 15:58:14 -0800891 clearCacheOnRadioOff();
892 }
893
894 /** Clear fields on power off radio **/
895 private void clearCacheOnRadioOff() {
896 // Re-show is-roaming notifications after APM mode
sangyun1c1918a2023-11-13 22:37:50 +0900897 if (mFeatureFlags.reorganizeRoamingNotification()) {
898 mShownNotificationReasons.clear();
899 } else {
900 mPrevRoamingOperatorNumerics.clear();
901 }
Chris Mantona09f3632016-02-09 14:48:42 -0800902 }
903
Taesu Lee62f826d2020-08-10 16:01:18 +0900904 private void setRadioPowerOn() {
Chris Mantona09f3632016-02-09 14:48:42 -0800905 Log.i(LOG_TAG, "Turning radio on - airplane");
Taesu Lee62f826d2020-08-10 16:01:18 +0900906 Settings.Global.putInt(
907 getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
908 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 1);
Meng Wang61307622019-10-23 14:08:43 -0700909 TelephonyProperties.airplane_mode_on(false); // false means int value 0
Chris Mantona09f3632016-02-09 14:48:42 -0800910 PhoneUtils.setRadioPower(true);
911 }
912
Taesu Lee62f826d2020-08-10 16:01:18 +0900913 private void maybeTurnCellOff(boolean isAirplaneNewlyOn) {
Chris Mantona09f3632016-02-09 14:48:42 -0800914 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700915 // If we are trying to turn off the radio, make sure there are no active
916 // emergency calls. If there are, switch airplane mode back to off.
Taesu Lee62f826d2020-08-10 16:01:18 +0900917 TelecomManager tm = (TelecomManager) getSystemService(TELECOM_SERVICE);
Tyler Gunn900d8fd2018-09-21 09:22:12 -0700918
919 if (tm != null && tm.isInEmergencyCall()) {
Santos Cordone18902f2016-03-22 17:16:04 -0700920 // Switch airplane mode back to off.
Jordan Liu0e819b12019-08-28 15:33:05 -0700921 ConnectivityManager cm =
Taesu Lee62f826d2020-08-10 16:01:18 +0900922 (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
Jordan Liu0e819b12019-08-28 15:33:05 -0700923 cm.setAirplaneMode(false);
Santos Cordone18902f2016-03-22 17:16:04 -0700924 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
925 .show();
926 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Taesu Lee62f826d2020-08-10 16:01:18 +0900927 } else if (isCellOffInAirplaneMode()) {
928 setRadioPowerOff();
Santos Cordone18902f2016-03-22 17:16:04 -0700929 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800930 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700931 }
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700932 } else {
933 Log.i(LOG_TAG, "Ignoring airplane mode: not newly on");
Chris Mantona09f3632016-02-09 14:48:42 -0800934 }
935 }
936
Taesu Lee62f826d2020-08-10 16:01:18 +0900937 private void maybeTurnCellOn(boolean isAirplaneNewlyOn) {
Chris Mantona09f3632016-02-09 14:48:42 -0800938 if (!isAirplaneNewlyOn) {
Taesu Lee62f826d2020-08-10 16:01:18 +0900939 setRadioPowerOn();
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700940 } else {
941 Log.i(LOG_TAG, "Ignoring airplane mode off: radio is already on.");
Santos Cordone18902f2016-03-22 17:16:04 -0700942 }
943 }
944
Santos Cordon593ab382013-08-06 21:58:23 -0700945 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700946 * Receiver for misc intent broadcasts the Phone app cares about.
947 */
948 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
949 @Override
950 public void onReceive(Context context, Intent intent) {
951 String action = intent.getAction();
952 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Taesu Lee3dc572b2020-08-07 18:16:22 +0900953 boolean airplaneMode = intent.getBooleanExtra("state", false);
Taesu Lee62f826d2020-08-10 16:01:18 +0900954 handleAirplaneModeChange(airplaneMode);
Amit Mahajanf5d92c82018-11-02 17:44:40 -0700955 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
956 // re-register as it may be a new IccCard
957 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
958 SubscriptionManager.INVALID_PHONE_INDEX);
959 if (SubscriptionManager.isValidPhoneId(phoneId)) {
960 PhoneUtils.unregisterIccStatus(mHandler, phoneId);
961 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED, phoneId);
962 }
Nazish Tabassum160d2112019-12-23 17:31:33 +0530963 String iccStatus = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
964 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
965 new EventSimStateChangedBag(phoneId, iccStatus)));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700966 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
967 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800968 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
969 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700970 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530971 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530972 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530973 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
974 if (phoneInEcm != null) {
975 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
976 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
977 // Start Emergency Callback Mode service
Daniel Bright30efde42020-01-09 22:11:15 -0800978 if (intent.getBooleanExtra(
979 TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530980 context.startService(new Intent(context,
981 EmergencyCallbackModeService.class));
982 } else {
983 phoneInEcm = null;
984 }
985 } else {
986 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
987 // on a device that doesn't support ECM in the first place.
988 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
989 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
990 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700991 }
992 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530993 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700994 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700995 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
996 // Roaming status could be overridden by carrier config, so we need to update it.
997 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
sangyun1c1918a2023-11-13 22:37:50 +0900998 if (mFeatureFlags.reorganizeRoamingNotification()) {
999 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED);
1000 } else {
1001 updateDataRoamingStatusForFeatureDisabled(null);
1002 }
chen xubaf9fe52019-07-02 17:28:24 -07001003 updateLimitedSimFunctionForDualSim();
Lei Liu863eac02020-06-24 20:12:55 +08001004 int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
1005 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1006 if (SubscriptionManager.isValidSubscriptionId(subId)) {
1007 mHandler.sendMessage(mHandler.obtainMessage(EVENT_CARRIER_CONFIG_CHANGED,
1008 new Integer(subId)));
1009 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001010 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
1011 // We also need to pay attention when default data subscription changes.
1012 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
1013 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
1014 registerSettingsObserver();
1015 Phone phone = getPhone(mDefaultDataSubId);
1016 if (phone != null) {
sangyun1c1918a2023-11-13 22:37:50 +09001017 if (mFeatureFlags.reorganizeRoamingNotification()) {
1018 updateDataRoamingStatus(
1019 ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED);
1020 } else {
1021 updateDataRoamingStatusForFeatureDisabled(null);
1022 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001023 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001024 }
1025 }
1026 }
1027
Sarah Chin072ffb22022-05-03 17:58:59 -07001028 private void handleServiceStateChanged(ServiceState serviceState, int subId) {
Jack Yu1a2fc352017-07-14 17:14:37 -07001029 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Sarah Chin072ffb22022-05-03 17:58:59 -07001030 int state = serviceState.getState();
1031 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -07001032
Sarah Chin072ffb22022-05-03 17:58:59 -07001033 if (VDBG) {
1034 Log.v(LOG_TAG, "subId=" + subId + ", mDefaultDataSubId="
1035 + mDefaultDataSubId + ", ss roaming=" + serviceState.getDataRoaming());
1036 }
1037 if (subId == mDefaultDataSubId) {
sangyun1c1918a2023-11-13 22:37:50 +09001038 if (mFeatureFlags.reorganizeRoamingNotification()) {
1039 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED);
1040 } else {
1041 updateDataRoamingStatusForFeatureDisabled(serviceState.getOperatorNumeric());
1042 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001043 }
1044 }
1045
Jack Yu1a2fc352017-07-14 17:14:37 -07001046 /**
1047 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
1048 * to notify the user so they can enable it through settings. Vise versa if the condition
1049 * changes, we need to dismiss the notification.
sangyund2cfeaa2024-03-31 12:20:40 +09001050 * @param notificationReason to inform which event is called for notification update.
Jack Yu1a2fc352017-07-14 17:14:37 -07001051 */
sangyund2cfeaa2024-03-31 12:20:40 +09001052 private void updateDataRoamingStatus(@RoamingNotificationReason int notificationReason) {
Jack Yu1a2fc352017-07-14 17:14:37 -07001053 Phone phone = getPhone(mDefaultDataSubId);
1054 if (phone == null) {
1055 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
1056 return;
1057 }
1058
sangyun35f23f82023-07-18 01:37:53 +09001059 ServiceState serviceState = phone.getServiceState();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08001060 if (serviceState == null) {
1061 Log.e(LOG_TAG, "updateDataRoamingStatus: serviceState is null");
1062 return;
1063 }
1064
sangyund2cfeaa2024-03-31 12:20:40 +09001065 List<DataDisallowedReason> disallowReasons = phone.getDataNetworkController()
1066 .getInternetDataDisallowedReasons();
1067
1068 if (mFeatureFlags.roamingNotificationForSingleDataNetwork()) {
1069 if (disallowReasons.contains(DataDisallowedReason.ONLY_ALLOWED_SINGLE_NETWORK)
1070 && disallowReasons.contains(DataDisallowedReason.ROAMING_DISABLED)
1071 && (notificationReason == ROAMING_NOTIFICATION_REASON_DATA_SETTING_CHANGED
1072 || notificationReason
1073 == ROAMING_NOTIFICATION_REASON_DATA_ROAMING_SETTING_CHANGED)) {
1074 // If the ONLY_ALLOWED_SINGLE_NETWORK disallow reason has not yet been removed due
1075 // to a change in mobile_data (including roaming_data) settings, update roaming
1076 // notification again after the Internet is completely disconnected to check
1077 // ONLY_ALLOWED_SINGLE_NETWORK disallow reason is removed.
1078 mWaitForInternetDisconnection.set(true);
1079 Log.d(LOG_TAG, "updateDataRoamingStatus,"
1080 + " wait for internet disconnection for single data network");
1081 } else if (!disallowReasons.contains(DataDisallowedReason.ONLY_ALLOWED_SINGLE_NETWORK)
1082 && mWaitForInternetDisconnection.compareAndSet(true, false)) {
1083 // If the ONLY_ALLOWED_SINGLE_NETWORK disallow reason has been removed,
1084 // no longer wait for Internet disconnection.
1085 Log.d(LOG_TAG, "updateDataRoamingStatus,"
1086 + " cancel to wait for internet disconnection for single data network");
1087 }
1088 }
1089
1090 updateDataRoamingStatus(notificationReason, disallowReasons, serviceState);
1091 }
1092
1093 /**
1094 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
1095 * to notify the user so they can enable it through settings. Vise versa if the condition
1096 * changes, we need to dismiss the notification.
1097 * @param notificationReason to inform which event is called for notification update.
1098 * @param disallowReasons List of reasons why internet data is not allowed. An empty list if
1099 * internet is allowed.
1100 * @param serviceState Service state from phone
1101 */
1102 private void updateDataRoamingStatus(@RoamingNotificationReason int notificationReason,
1103 List<DataDisallowedReason> disallowReasons, ServiceState serviceState) {
1104
1105 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
sangyun35f23f82023-07-18 01:37:53 +09001106 String roamingNumeric = serviceState.getOperatorNumeric();
1107 String roamingNumericReason = "RoamingNumeric=" + roamingNumeric;
sangyund2cfeaa2024-03-31 12:20:40 +09001108 String callingReason = "CallingReason=" + notificationReason;
sangyun35f23f82023-07-18 01:37:53 +09001109 boolean dataIsNowRoaming = serviceState.getDataRoaming();
Jack Yu3e2ac6e2022-03-26 13:59:45 -07001110 boolean dataAllowed;
1111 boolean notAllowedDueToRoamingOff;
sangyund2cfeaa2024-03-31 12:20:40 +09001112 dataAllowed = disallowReasons.isEmpty();
1113 notAllowedDueToRoamingOff = (disallowReasons.size() == 1
1114 && disallowReasons.contains(DataDisallowedReason.ROAMING_DISABLED));
sangyun35f23f82023-07-18 01:37:53 +09001115 StringBuilder sb = new StringBuilder("updateDataRoamingStatus");
1116 sb.append(" dataAllowed=").append(dataAllowed);
sangyund2cfeaa2024-03-31 12:20:40 +09001117 sb.append(", disallowReasons=").append(disallowReasons);
sangyun35f23f82023-07-18 01:37:53 +09001118 sb.append(", dataIsNowRoaming=").append(dataIsNowRoaming);
1119 sb.append(", ").append(roamingNumericReason);
1120 sb.append(", ").append(callingReason);
1121 mDataRoamingNotifLog.log(sb.toString());
Ling Ma317906d2022-12-05 15:58:14 -08001122 if (VDBG) {
sangyun35f23f82023-07-18 01:37:53 +09001123 Log.v(LOG_TAG, sb.toString());
Ling Ma317906d2022-12-05 15:58:14 -08001124 }
Jack Yu3e2ac6e2022-03-26 13:59:45 -07001125
sangyun35f23f82023-07-18 01:37:53 +09001126 // Determine if a given roaming numeric has never been shown.
1127 boolean shownInThisNumeric = false;
sangyund2cfeaa2024-03-31 12:20:40 +09001128 if (notificationReason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED
1129 || notificationReason == ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED) {
sangyun35f23f82023-07-18 01:37:53 +09001130 shownInThisNumeric = mShownNotificationReasons.contains(roamingNumericReason);
1131 }
1132 // Determine if a notification has never been shown by given calling reason.
1133 boolean shownForThisReason = mShownNotificationReasons.contains(callingReason);
1134
Jack Yu3e2ac6e2022-03-26 13:59:45 -07001135 if (!dataAllowed && notAllowedDueToRoamingOff) {
sangyun35f23f82023-07-18 01:37:53 +09001136 if (!shownInThisNumeric && roamingNumeric != null) {
1137 mShownNotificationReasons.add(roamingNumericReason);
1138 }
1139 if (!shownForThisReason
sangyund2cfeaa2024-03-31 12:20:40 +09001140 && notificationReason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED) {
sangyun35f23f82023-07-18 01:37:53 +09001141 mShownNotificationReasons.add(callingReason);
Ling Ma4e15c322022-12-07 11:20:53 -08001142 }
Jordan Liuff2ccd72019-07-23 15:54:41 -07001143 // No need to show it again if we never cancelled it explicitly.
sangyun35f23f82023-07-18 01:37:53 +09001144 if (getCurrentRoamingNotification() == ROAMING_NOTIFICATION_DISCONNECTED) {
1145 return;
1146 }
1147
Jack Yu1a2fc352017-07-14 17:14:37 -07001148 // If the only reason of no data is data roaming disabled, then we notify the user
1149 // so the user can turn on data roaming.
sangyun35f23f82023-07-18 01:37:53 +09001150 if (!shownInThisNumeric && !shownForThisReason) {
1151 updateDataRoamingNotification(ROAMING_NOTIFICATION_DISCONNECTED);
1152 } else {
1153 // Don't show roaming notification if we've already shown for this MccMnc
1154 Log.d(LOG_TAG, "Skip roaming disconnected notification since already"
1155 + " shownInThisNumeric=" + shownInThisNumeric
1156 + " shownForThisReason=" + shownForThisReason);
1157 // Dismiss notification if the other notification is shown.
1158 if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
1159 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
1160 }
1161 }
1162 } else if (dataAllowed && dataIsNowRoaming) {
1163 if (!shownInThisNumeric && roamingNumeric != null) {
1164 mShownNotificationReasons.add(roamingNumericReason);
1165 }
1166 if (!shownForThisReason
sangyund2cfeaa2024-03-31 12:20:40 +09001167 && notificationReason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED) {
sangyun35f23f82023-07-18 01:37:53 +09001168 mShownNotificationReasons.add(callingReason);
1169 }
Sarah Chin37b39072023-11-05 13:28:21 -08001170 boolean shouldShowRoamingNotification = shouldShowRoamingNotification(roamingNumeric);
sangyun35f23f82023-07-18 01:37:53 +09001171 // No need to show it again if we never cancelled it explicitly.
1172 if (getCurrentRoamingNotification() == ROAMING_NOTIFICATION_CONNECTED) {
Ling Ma4e15c322022-12-07 11:20:53 -08001173 return;
1174 }
sangyun35f23f82023-07-18 01:37:53 +09001175
1176 // Inform users that roaming charges may apply.
Sarah Chin37b39072023-11-05 13:28:21 -08001177 if (!shownInThisNumeric && !shownForThisReason && shouldShowRoamingNotification) {
sangyun35f23f82023-07-18 01:37:53 +09001178 updateDataRoamingNotification(ROAMING_NOTIFICATION_CONNECTED);
1179 } else {
1180 // Don't show roaming notification if we've already shown for this MccMnc or
1181 // disabled from carrier config.
1182 Log.d(LOG_TAG, "Skip roaming connected notification since already"
1183 + " shownInThisNumeric:" + shownInThisNumeric
1184 + " shownForThisReason:" + shownForThisReason
Sarah Chin37b39072023-11-05 13:28:21 -08001185 + " shouldShowRoamingNotification:" + shouldShowRoamingNotification);
sangyun35f23f82023-07-18 01:37:53 +09001186 // Dismiss notification if the other notification is shown.
1187 if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
1188 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
1189 }
1190 }
1191 } else if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
Jordan Liuff2ccd72019-07-23 15:54:41 -07001192 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
1193 // is not the only data disable reason. In this case we dismiss the notification we
1194 // showed earlier.
sangyun35f23f82023-07-18 01:37:53 +09001195 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
Jack Yu1a2fc352017-07-14 17:14:37 -07001196 }
1197 }
1198
sangyun35f23f82023-07-18 01:37:53 +09001199 private void updateDataRoamingNotification(@RoamingNotification int roamingNotification) {
1200 int event;
1201 switch (roamingNotification) {
1202 case ROAMING_NOTIFICATION_NO_NOTIFICATION:
1203 Log.d(LOG_TAG, "Dismiss roaming notification");
1204 mDataRoamingNotifLog.log("Hide roaming.");
1205 event = EVENT_DATA_ROAMING_OK;
1206 break;
1207 case ROAMING_NOTIFICATION_CONNECTED:
1208 Log.d(LOG_TAG, "Show roaming connected notification");
1209 mDataRoamingNotifLog.log("Show roaming on.");
1210 event = EVENT_DATA_ROAMING_CONNECTED;
1211 break;
1212 case ROAMING_NOTIFICATION_DISCONNECTED:
1213 Log.d(LOG_TAG, "Show roaming disconnected notification");
1214 mDataRoamingNotifLog.log("Show roaming off.");
1215 event = EVENT_DATA_ROAMING_DISCONNECTED;
1216 break;
1217 default:
1218 Log.d(LOG_TAG, "Should never reach here.");
1219 mDataRoamingNotifLog.log("Should never reach here.");
1220 return;
1221 }
1222 mCurrentRoamingNotification = roamingNotification;
1223 mHandler.obtainMessage(event, mDefaultDataSubId, 0).sendToTarget();
1224 }
1225
1226 private @RoamingNotification int getCurrentRoamingNotification() {
1227 return mCurrentRoamingNotification;
1228 }
1229
sangyun1c1918a2023-11-13 22:37:50 +09001230 // For reorganize_roaming_notification feature disabled.
1231 /**
1232 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
1233 * to notify the user so they can enable it through settings. Vise versa if the condition
1234 * changes, we need to dismiss the notification.
1235 * @param roamingOperatorNumeric The operator numeric for the current roaming. {@code null} if
1236 * the current roaming operator numeric didn't change.
1237 */
1238 private void updateDataRoamingStatusForFeatureDisabled(
1239 @Nullable String roamingOperatorNumeric) {
1240 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatusForFeatureDisabled");
1241 Phone phone = getPhone(mDefaultDataSubId);
1242 if (phone == null) {
1243 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
1244 return;
1245 }
1246
1247 boolean dataAllowed;
1248 boolean notAllowedDueToRoamingOff;
1249 List<DataDisallowedReason> reasons = phone.getDataNetworkController()
1250 .getInternetDataDisallowedReasons();
1251 dataAllowed = reasons.isEmpty();
1252 notAllowedDueToRoamingOff = (reasons.size() == 1
1253 && reasons.contains(DataDisallowedReason.ROAMING_DISABLED));
1254 mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons
1255 + ", roamingOperatorNumeric=" + roamingOperatorNumeric);
1256 if (VDBG) {
1257 Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons
1258 + ", roamingOperatorNumeric=" + roamingOperatorNumeric);
1259 }
1260
1261 if (!dataAllowed && notAllowedDueToRoamingOff) {
1262 // Don't show roaming notification if we've already shown for this MccMnc
1263 if (roamingOperatorNumeric != null
1264 && !mPrevRoamingOperatorNumerics.add(roamingOperatorNumeric)) {
1265 Log.d(LOG_TAG, "Skip roaming disconnected notification since already shown in "
1266 + "MccMnc " + roamingOperatorNumeric);
1267 return;
1268 }
1269 // No need to show it again if we never cancelled it explicitly.
1270 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_DISCONNECTED) return;
1271 // If the only reason of no data is data roaming disabled, then we notify the user
1272 // so the user can turn on data roaming.
1273 mPrevRoamingNotification = ROAMING_NOTIFICATION_DISCONNECTED;
1274 Log.d(LOG_TAG, "Show roaming disconnected notification");
1275 mDataRoamingNotifLog.log("Show roaming off.");
1276 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_DISCONNECTED);
1277 msg.arg1 = mDefaultDataSubId;
1278 msg.sendToTarget();
1279 } else if (dataAllowed && dataIsNowRoaming(mDefaultDataSubId)) {
sangyun5abbf7e2024-02-01 00:47:30 +09001280 if (!shouldShowRoamingNotification(roamingOperatorNumeric != null
1281 ? roamingOperatorNumeric : phone.getServiceState().getOperatorNumeric())) {
Sarah Chin37b39072023-11-05 13:28:21 -08001282 Log.d(LOG_TAG, "Skip showing roaming connected notification.");
1283 return;
1284 }
sangyun1c1918a2023-11-13 22:37:50 +09001285 // Don't show roaming notification if we've already shown for this MccMnc
1286 if (roamingOperatorNumeric != null
1287 && !mPrevRoamingOperatorNumerics.add(roamingOperatorNumeric)) {
1288 Log.d(LOG_TAG, "Skip roaming connected notification since already shown in "
1289 + "MccMnc " + roamingOperatorNumeric);
1290 return;
1291 }
1292 // No need to show it again if we never cancelled it explicitly, or carrier config
1293 // indicates this is not needed.
1294 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_CONNECTED) return;
1295 mPrevRoamingNotification = ROAMING_NOTIFICATION_CONNECTED;
1296 Log.d(LOG_TAG, "Show roaming connected notification");
1297 mDataRoamingNotifLog.log("Show roaming on.");
1298 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_CONNECTED);
1299 msg.arg1 = mDefaultDataSubId;
1300 msg.sendToTarget();
1301 } else if (mPrevRoamingNotification != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
1302 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
1303 // is not the only data disable reason. In this case we dismiss the notification we
1304 // showed earlier.
1305 mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
1306 Log.d(LOG_TAG, "Dismiss roaming notification");
1307 mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed);
1308 mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
1309 }
1310 }
1311
Jordan Liuff2ccd72019-07-23 15:54:41 -07001312 /**
1313 *
1314 * @param subId to check roaming on
1315 * @return whether we have transitioned to dataRoaming
1316 */
1317 private boolean dataIsNowRoaming(int subId) {
Sarah Chine04784a2022-10-31 20:32:34 -07001318 return getPhone(subId).getServiceState().getDataRoaming();
Jordan Liuff2ccd72019-07-23 15:54:41 -07001319 }
1320
Sarah Chin37b39072023-11-05 13:28:21 -08001321 private boolean shouldShowRoamingNotification(String roamingNumeric) {
1322 PersistableBundle config = getCarrierConfigForSubId(mDefaultDataSubId);
1323 boolean showRoamingNotification = config.getBoolean(
1324 CarrierConfigManager.KEY_SHOW_DATA_CONNECTED_ROAMING_NOTIFICATION_BOOL);
1325
1326 if (TextUtils.isEmpty(roamingNumeric) || !mFeatureFlags.hideRoamingIcon()) {
1327 Log.d(LOG_TAG, "shouldShowRoamingNotification: roamingNumeric=" + roamingNumeric
1328 + ", hideRoaming=" + mFeatureFlags.hideRoamingIcon());
1329 return showRoamingNotification;
1330 }
1331
1332 String[] includedMccMncs = config.getStringArray(CarrierConfigManager
1333 .KEY_DATA_CONNECTED_ROAMING_NOTIFICATION_INCLUDED_MCC_MNCS_STRING_ARRAY);
1334 if (includedMccMncs != null) {
1335 for (String mccMnc : includedMccMncs) {
1336 if (roamingNumeric.equals(mccMnc)) {
1337 Log.d(LOG_TAG, "shouldShowRoamingNotification: show for MCC/MNC " + mccMnc);
1338 return showRoamingNotification;
1339 }
1340 }
1341 }
1342
1343 String[] excludedMccs = config.getStringArray(CarrierConfigManager
1344 .KEY_DATA_CONNECTED_ROAMING_NOTIFICATION_EXCLUDED_MCCS_STRING_ARRAY);
1345 String roamingMcc = roamingNumeric.length() < 3 ? "" : roamingNumeric.substring(0, 3);
1346 if (excludedMccs != null && !TextUtils.isEmpty(roamingMcc)) {
1347 for (String mcc : excludedMccs) {
1348 if (roamingMcc.equals(mcc)) {
1349 Log.d(LOG_TAG, "shouldShowRoamingNotification: ignore for MCC " + mcc);
1350 return false;
1351 }
1352 }
1353 }
1354
1355 if (showRoamingNotification) {
1356 Log.d(LOG_TAG, "shouldShowRoamingNotification: show for numeric " + roamingNumeric);
1357 }
1358 return showRoamingNotification;
1359 }
1360
chen xubaf9fe52019-07-02 17:28:24 -07001361 private void updateLimitedSimFunctionForDualSim() {
1362 if (DBG) Log.d(LOG_TAG, "updateLimitedSimFunctionForDualSim");
1363 // check conditions to display limited SIM function notification under dual SIM
1364 SubscriptionManager subMgr = (SubscriptionManager) getSystemService(
1365 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
1366 List<SubscriptionInfo> subList = subMgr.getActiveSubscriptionInfoList(false);
1367 if (subList != null && subList.size() > 1) {
1368 CarrierConfigManager configMgr = (CarrierConfigManager)
1369 getSystemService(Context.CARRIER_CONFIG_SERVICE);
1370 for (SubscriptionInfo info : subList) {
1371 PersistableBundle b = configMgr.getConfigForSubId(info.getSubscriptionId());
1372 if (b != null) {
1373 if (b.getBoolean(CarrierConfigManager
1374 .KEY_LIMITED_SIM_FUNCTION_NOTIFICATION_FOR_DSDS_BOOL)) {
1375 notificationMgr.showLimitedSimFunctionWarningNotification(
1376 info.getSubscriptionId(),
1377 info.getDisplayName().toString());
1378 } else {
1379 notificationMgr.dismissLimitedSimFunctionWarningNotification(
1380 info.getSubscriptionId());
1381 }
1382 }
1383 }
1384 } else {
1385 // cancel notifications for all subs
1386 notificationMgr.dismissLimitedSimFunctionWarningNotification(
1387 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1388 }
1389 notificationMgr.dismissLimitedSimFunctionWarningNotificationForInactiveSubs();
1390
1391 }
1392
Sandeep Kuntade73a6a2014-10-15 18:45:56 +05301393 public Phone getPhoneInEcm() {
1394 return phoneInEcm;
1395 }
1396
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001397 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -08001398 * Triggers a refresh of the message waiting (voicemail) indicator.
1399 *
1400 * @param subId the subscription id we should refresh the notification for.
1401 */
1402 public void refreshMwiIndicator(int subId) {
1403 notificationMgr.refreshMwi(subId);
1404 }
1405
1406 /**
Pengquan Mengdd9ac822018-09-20 15:25:35 -07001407 * Called when the network selection on the subscription {@code subId} is changed by the user.
1408 *
1409 * @param subId the subscription id.
1410 */
1411 public void onNetworkSelectionChanged(int subId) {
1412 Phone phone = getPhone(subId);
1413 if (phone != null) {
1414 notificationMgr.updateNetworkSelection(phone.getServiceState().getState(), subId);
1415 } else {
1416 Log.w(LOG_TAG, "onNetworkSelectionChanged on null phone, subId: " + subId);
1417 }
1418 }
1419
1420 /**
James.cf Lin4b784aa2021-01-31 03:25:15 +08001421 * @return whether the device supports RCS User Capability Exchange or not.
1422 */
1423 public boolean getDeviceUceEnabled() {
1424 return (mTelephonyRcsService == null) ? false : mTelephonyRcsService.isDeviceUceEnabled();
1425 }
1426
1427 /**
1428 * Set the device supports RCS User Capability Exchange.
1429 * @param isEnabled true if the device supports UCE.
1430 */
1431 public void setDeviceUceEnabled(boolean isEnabled) {
1432 if (mTelephonyRcsService != null) {
1433 mTelephonyRcsService.setDeviceUceEnabled(isEnabled);
1434 }
1435 }
1436
1437 /**
Jack Yu1a2fc352017-07-14 17:14:37 -07001438 * Dump the state of the object, add calls to other objects as desired.
1439 *
1440 * @param fd File descriptor
1441 * @param printWriter Print writer
1442 * @param args Arguments
1443 */
1444 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
1445 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
1446 pw.println("------- PhoneGlobals -------");
1447 pw.increaseIndent();
sangyun15019e02023-11-13 21:50:15 +09001448 pw.println("FeatureFlags:");
1449 pw.increaseIndent();
sangyun1c1918a2023-11-13 22:37:50 +09001450 pw.println("reorganizeRoamingNotification="
1451 + mFeatureFlags.reorganizeRoamingNotification());
sangyund5f37ab2023-11-13 22:52:28 +09001452 pw.println("dismissNetworkSelectionNotificationOnSimDisable="
1453 + mFeatureFlags.dismissNetworkSelectionNotificationOnSimDisable());
sangyun15019e02023-11-13 21:50:15 +09001454 pw.decreaseIndent();
sangyun1c1918a2023-11-13 22:37:50 +09001455 if (mFeatureFlags.reorganizeRoamingNotification()) {
1456 pw.println("mCurrentRoamingNotification=" + mCurrentRoamingNotification);
1457 } else {
1458 pw.println("mPrevRoamingNotification=" + mPrevRoamingNotification);
1459 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001460 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
Keun young Parkdebb8532019-05-30 16:35:27 -07001461 pw.println("isSmsCapable=" + TelephonyManager.from(this).isSmsCapable());
sangyun35f23f82023-07-18 01:37:53 +09001462 pw.println("mDataRoamingNotifLog:");
Jack Yu1a2fc352017-07-14 17:14:37 -07001463 pw.increaseIndent();
1464 mDataRoamingNotifLog.dump(fd, pw, args);
1465 pw.decreaseIndent();
Brad Ebinger05f52c22019-12-05 13:03:21 -08001466 pw.println("ImsResolver:");
1467 pw.increaseIndent();
1468 try {
Brad Ebingerd1947d82021-05-17 20:54:49 +00001469 if (ImsResolver.getInstance() != null) ImsResolver.getInstance().dump(fd, pw, args);
Brad Ebinger05f52c22019-12-05 13:03:21 -08001470 } catch (Exception e) {
1471 e.printStackTrace();
1472 }
1473 pw.decreaseIndent();
Brad Ebingera68a4972020-01-30 17:31:23 -08001474 pw.println("RcsService:");
1475 try {
1476 if (mTelephonyRcsService != null) mTelephonyRcsService.dump(fd, pw, args);
1477 } catch (Exception e) {
1478 e.printStackTrace();
1479 }
Hunsuk Choi89bd22c2021-11-01 13:04:54 +00001480 pw.println("ImsStateCallbackController:");
1481 try {
1482 if (mImsStateCallbackController != null) mImsStateCallbackController.dump(pw);
1483 } catch (Exception e) {
1484 e.printStackTrace();
1485 }
Hwangoo Parkba21cf22022-11-30 14:34:04 +00001486 pw.println("DomainSelectionResolver:");
1487 pw.increaseIndent();
1488 try {
1489 if (DomainSelectionResolver.getInstance() != null) {
1490 DomainSelectionResolver.getInstance().dump(fd, pw, args);
1491 }
1492 } catch (Exception e) {
1493 e.printStackTrace();
1494 }
1495 pw.decreaseIndent();
Jack Yu1a2fc352017-07-14 17:14:37 -07001496 pw.decreaseIndent();
sangyun1c1918a2023-11-13 22:37:50 +09001497 if (mFeatureFlags.reorganizeRoamingNotification()) {
1498 pw.println("mShownNotificationReasons=" + mShownNotificationReasons);
1499 } else {
1500 pw.println("mPrevRoamingOperatorNumerics:" + mPrevRoamingOperatorNumerics);
1501 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001502 pw.println("------- End PhoneGlobals -------");
1503 }
Aishwarya Mallampati05483bf2024-10-08 21:42:52 +00001504
1505 private boolean skipDataRoamingDisconnectedNotificationInSatelliteMode(int subId) {
1506 SatelliteController satelliteController = SatelliteController.getInstance();
1507 if (satelliteController.isSatelliteEnabledOrBeingEnabled()) {
1508 Log.d(LOG_TAG, "skipDataRoamingDisconnected - skip notification as "
1509 + "satellite is enabled or being enabled");
1510 return true;
1511 }
1512
1513 int phoneId = SubscriptionManager.getPhoneId(subId);
1514 Phone phone = PhoneFactory.getPhone(phoneId);
1515 ServiceState serviceState = phone.getServiceState();
1516 if (serviceState != null && serviceState.isUsingNonTerrestrialNetwork()) {
1517 Log.d(LOG_TAG, "skipDataRoamingDisconnected - isUsingNtn");
1518 List<Integer> capabilities =
1519 satelliteController.getCapabilitiesForCarrierRoamingSatelliteMode(phone);
1520 if (!capabilities.contains(NetworkRegistrationInfo.SERVICE_TYPE_DATA)) {
1521 // Skip data roaming disconnected notification as device is connected to
1522 // non-terrestrial network that does not support data.
1523 Log.d(LOG_TAG, "skipDataRoamingDisconnected - skip notification as "
1524 + "NTN does not support data");
1525 return true;
1526 }
1527 }
1528
1529 Log.d(LOG_TAG, "skipDataRoamingDisconnected - do not skip notification.");
1530 return false;
1531 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001532}