blob: bab260ce2bf68407845d1537856bba2471570f18 [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);
jaesikkong127483f2024-10-28 08:59:32 +0000574 int inServiceWaitTimeWhenDialEccInApm = getResources().getInteger(R.integer
575 .config_in_service_wait_timer_when_dialing_emergency_routing_ecc_in_apm);
yongnamcha2980ac02024-10-11 05:13:52 +0000576 EmergencyStateTracker.make(this, isSuplDdsSwitchRequiredForEmergencyCall,
jaesikkong127483f2024-10-28 08:59:32 +0000577 inServiceWaitTimeWhenDialEccInApm, mFeatureFlags);
Hunsuk Choic2e3fbc2024-05-10 05:05:17 +0000578 DynamicRoutingController.getInstance().initialize(this);
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000579 }
580
Brad Ebinger05f52c22019-12-05 13:03:21 -0800581 // Only bring up ImsResolver if the device supports having an IMS stack.
582 if (getPackageManager().hasSystemFeature(
583 PackageManager.FEATURE_TELEPHONY_IMS)) {
584 // Get the package name of the default IMS implementation.
585 String defaultImsMmtelPackage = getResources().getString(
586 R.string.config_ims_mmtel_package);
587 String defaultImsRcsPackage = getResources().getString(
588 R.string.config_ims_rcs_package);
Brad Ebingerd1947d82021-05-17 20:54:49 +0000589 ImsResolver.make(this, defaultImsMmtelPackage,
Brad Ebingere3ae65a2020-09-11 12:45:11 -0700590 defaultImsRcsPackage, PhoneFactory.getPhones().length,
joonhunshin42441672024-04-26 01:26:14 +0000591 new ImsFeatureBinderRepository(), mFeatureFlags);
Brad Ebingerd1947d82021-05-17 20:54:49 +0000592 ImsResolver.getInstance().initialize();
Tyler Gunn92479152021-01-20 16:30:10 -0800593
594 // With the IMS phone created, load static config.xml values from the phone process
595 // so that it can be provided to the ImsPhoneCallTracker.
596 for (Phone p : PhoneFactory.getPhones()) {
597 Phone imsPhone = p.getImsPhone();
598 if (imsPhone != null && imsPhone instanceof ImsPhone) {
599 ImsPhone theImsPhone = (ImsPhone) imsPhone;
600 if (theImsPhone.getCallTracker() instanceof ImsPhoneCallTracker) {
601 ImsPhoneCallTracker ict = (ImsPhoneCallTracker)
602 theImsPhone.getCallTracker();
603
604 ImsPhoneCallTracker.Config config = new ImsPhoneCallTracker.Config();
605 config.isD2DCommunicationSupported = getResources().getBoolean(
606 R.bool.config_use_device_to_device_communication);
607 ict.setConfig(config);
608 }
609 }
610 }
Jack Yu4a0c5382024-09-05 23:03:20 -0700611 RcsProvisioningMonitor.make(this, mFeatureFlags);
Brad Ebinger05f52c22019-12-05 13:03:21 -0800612 }
613
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700614 // Start TelephonyDebugService After the default phone is created.
615 Intent intent = new Intent(this, TelephonyDebugService.class);
616 startService(intent);
617
618 mCM = CallManager.getInstance();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700619
620 // Create the NotificationMgr singleton, which is used to display
621 // status bar icons and control other status bar behavior.
622 notificationMgr = NotificationMgr.init(this);
623
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000624 // Create the SatelliteController singleton, which acts as a backend service for
625 // {@link android.telephony.satellite.SatelliteManager}.
sangyun15019e02023-11-13 21:50:15 +0900626 SatelliteController.make(this, mFeatureFlags);
Sarah Chin5f57c582023-02-14 04:16:10 -0800627
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700628 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
629 cdmaPhoneCallState = new CdmaPhoneCallState();
630 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700631
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700632 // before registering for phone state changes
633 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
634 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
635 // lock used to keep the processor awake, when we don't care for the display.
636 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
637 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700638
639 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
640
sangyun15019e02023-11-13 21:50:15 +0900641 phoneMgr = PhoneInterfaceManager.init(this, mFeatureFlags);
Santos Cordon406c0342013-08-28 00:07:47 -0700642
joonhunshin2c33ed92023-12-12 14:29:23 +0000643 imsRcsController = ImsRcsController.init(this, mFeatureFlags);
James.cf Linaf3183c2019-10-24 00:59:00 +0800644
joonhunshin21a86812023-12-10 08:21:25 +0000645 configLoader = CarrierConfigLoader.init(this, mFeatureFlags);
Brad Ebinger6c53e7f2023-01-27 16:26:44 -0800646
James.cf Linc9f35a42020-01-15 02:35:22 +0800647 if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000648 mImsStateCallbackController =
joonhunshin7da71b82024-07-17 05:20:47 +0000649 ImsStateCallbackController.make(this, PhoneFactory.getPhones().length,
650 mFeatureFlags);
Brad Ebingera68a4972020-01-30 17:31:23 -0800651 mTelephonyRcsService = new TelephonyRcsService(this,
joonhunshind9dfe8d2024-02-05 09:08:06 +0000652 PhoneFactory.getPhones().length, mFeatureFlags);
Brad Ebingera68a4972020-01-30 17:31:23 -0800653 mTelephonyRcsService.initialize();
James.cf Linc9f35a42020-01-15 02:35:22 +0800654 imsRcsController.setRcsService(mTelephonyRcsService);
joonhunshincffb7fc2021-11-28 07:32:01 +0000655 mImsProvisioningController =
joonhunshin711a8872024-03-19 10:04:08 +0000656 ImsProvisioningController.make(this, PhoneFactory.getPhones().length,
657 mFeatureFlags);
James.cf Linc9f35a42020-01-15 02:35:22 +0800658 }
659
Jack Yu1a2fc352017-07-14 17:14:37 -0700660 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700661 // asynchronous events from the telephony layer (like
662 // launching the incoming-call UI when an incoming call comes
663 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800664 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700665
Stuart Scottdcf40a92014-12-09 10:45:01 -0800666 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700667
668 // register for MMI/USSD
669 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
670
Qiong Liucc3fe812019-09-23 15:25:44 +0800671 // Initialize cell status using current airplane mode.
Taesu Lee62f826d2020-08-10 16:01:18 +0900672 handleAirplaneModeChange(
673 Settings.Global.getInt(
674 getContentResolver(),
675 Settings.Global.AIRPLANE_MODE_ON,
676 AIRPLANE_OFF)
677 == AIRPLANE_ON);
Qiong Liucc3fe812019-09-23 15:25:44 +0800678
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700679 // Register for misc other intent broadcasts.
680 IntentFilter intentFilter =
681 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700682 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
683 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700684 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700685 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
686 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700687 registerReceiver(mReceiver, intentFilter);
Jack Yuec144222023-12-13 16:03:03 -0800688 int defaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
689 if (SubscriptionManager.isValidSubscriptionId(defaultDataSubId)) {
690 if (VDBG) {
691 Log.v(LOG_TAG, "Loaded initial default data sub: " + defaultDataSubId);
sangyun15019e02023-11-13 21:50:15 +0900692 }
Jack Yuec144222023-12-13 16:03:03 -0800693 mDefaultDataSubId = defaultDataSubId;
694 registerSettingsObserver();
695 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED);
sangyundce559b2023-09-11 10:25:55 +0900696 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700697
Sarah Chin072ffb22022-05-03 17:58:59 -0700698 PhoneConfigurationManager.registerForMultiSimConfigChange(
699 mHandler, EVENT_MULTI_SIM_CONFIG_CHANGED, null);
700
701 mTelephonyCallbacks = new PhoneAppCallback[tm.getSupportedModemCount()];
Fangyuan Li7f5c2752022-06-29 18:02:31 +0800702 if (tm.getSupportedModemCount() > 0) {
703 for (Phone phone : PhoneFactory.getPhones()) {
704 int subId = phone.getSubId();
705 PhoneAppCallback callback = new PhoneAppCallback(subId);
706 tm.createForSubscriptionId(subId).registerTelephonyCallback(
707 TelephonyManager.INCLUDE_LOCATION_DATA_NONE, mHandler::post, callback);
708 mTelephonyCallbacks[phone.getPhoneId()] = callback;
709 }
Sarah Chin072ffb22022-05-03 17:58:59 -0700710 }
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700711 mCarrierVvmPackageInstalledReceiver.register(this);
712
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700713 //set the default values for the preferences in the phone.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700714 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700715 }
716
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700717 // XXX pre-load the SimProvider so that it's ready
718 resolver.getType(Uri.parse("content://icc/adn"));
719
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700720 // TODO: Register for Cdma Information Records
721 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
722
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700723 // Read HAC settings and configure audio hardware
724 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800725 int hac = android.provider.Settings.System.getInt(
726 getContentResolver(),
727 android.provider.Settings.System.HEARING_AID,
728 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700729 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Jordan Liuf71aeef2019-08-21 11:46:09 -0700730 audioManager.setParameters(
731 SettingsConstants.HAC_KEY + "=" + (hac == SettingsConstants.HAC_ENABLED
732 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700733 }
Siim Sammul182d61b2021-05-04 16:01:42 +0100734
735 // Start tracking Binder latency for the phone process.
736 mBinderCallsSettingsObserver = new BinderCallsStats.SettingsObserver(
737 getApplicationContext(),
Siim Sammula6950092021-06-22 17:14:03 +0100738 new BinderCallsStats(
739 new BinderCallsStats.Injector(),
740 com.android.internal.os.BinderLatencyProto.Dims.TELEPHONY));
Santos Cordonff506f52013-11-21 19:13:19 -0800741 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700742
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700743 /**
744 * Returns the singleton instance of the PhoneApp.
745 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800746 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700747 if (sMe == null) {
748 throw new IllegalStateException("No PhoneGlobals here!");
749 }
750 return sMe;
751 }
752
753 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800754 * Returns the default phone.
755 *
Andrew Lee385019f2014-11-24 14:19:50 -0800756 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700757 */
Andrew Lee83383e42014-10-31 12:42:28 -0700758 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800759 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700760 }
761
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800762 public static Phone getPhone(int subId) {
763 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800764 }
765
Santos Cordonde10b752013-09-19 04:11:33 -0700766 /* package */ CallManager getCallManager() {
767 return mCM;
768 }
769
Chris Manton4e9fa912015-06-19 11:26:57 -0700770 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800771 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700772 }
773
Chris Manton4e9fa912015-06-19 11:26:57 -0700774 public PersistableBundle getCarrierConfigForSubId(int subId) {
Philip P. Moltmann0079aae2020-03-05 16:24:02 -0800775 return configLoader.getConfigForSubIdWithFeature(subId, getOpPackageName(),
776 getAttributionTag());
Junda Liu605148f2015-04-28 15:23:40 -0700777 }
778
Jack Yu1a2fc352017-07-14 17:14:37 -0700779 private void registerSettingsObserver() {
780 mSettingsObserver.unobserve();
781 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
782 String mobileDataSetting = Settings.Global.MOBILE_DATA;
783 if (TelephonyManager.getDefault().getSimCount() > 1) {
784 int subId = mDefaultDataSubId;
785 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
786 dataRoamingSetting += subId;
787 mobileDataSetting += subId;
788 }
789 }
790
791 // Listen for user data roaming setting changed event
792 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
793 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
794
795 // Listen for mobile data setting changed event
796 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
797 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
798 }
799
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700800 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700801 * Sets the activity responsible for un-PUK-blocking the device
802 * so that we may close it when we receive a positive result.
803 * mPUKEntryActivity is also used to indicate to the device that
804 * we are trying to un-PUK-lock the phone. In other words, iff
805 * it is NOT null, then we are trying to unlock and waiting for
806 * the SIM to move to READY state.
807 *
808 * @param activity is the activity to close when PUK has
809 * finished unlocking. Can be set to null to indicate the unlock
810 * or SIM READYing process is over.
811 */
812 void setPukEntryActivity(Activity activity) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700813 Log.i(LOG_TAG, "setPukEntryActivity - set to " + (activity == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700814 mPUKEntryActivity = activity;
815 }
816
817 Activity getPUKEntryActivity() {
818 return mPUKEntryActivity;
819 }
820
821 /**
822 * Sets the dialog responsible for notifying the user of un-PUK-
823 * blocking - SIM READYing progress, so that we may dismiss it
824 * when we receive a positive result.
825 *
826 * @param dialog indicates the progress dialog informing the user
827 * of the state of the device. Dismissed upon completion of
828 * READYing process
829 */
830 void setPukEntryProgressDialog(ProgressDialog dialog) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700831 Log.i(LOG_TAG, "setPukEntryProgressDialog - set to "
832 + (dialog == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700833 mPUKEntryProgressDialog = dialog;
834 }
835
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700836 KeyguardManager getKeyguardManager() {
837 return mKeyguardManager;
838 }
839
840 private void onMMIComplete(AsyncResult r) {
841 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
842 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800843 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700844 }
845
fionaxu80126972017-02-01 17:01:26 -0800846 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700847 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700848 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700849 }
850
Taesu Lee62f826d2020-08-10 16:01:18 +0900851 private void handleAirplaneModeChange(boolean isAirplaneNewlyOn) {
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700852 Log.i(LOG_TAG, "handleAirplaneModeChange: isAirplaneNewlyOn=" + isAirplaneNewlyOn);
Taesu Lee62f826d2020-08-10 16:01:18 +0900853 int cellState =
854 Settings.Global.getInt(
855 getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
Chris Mantona09f3632016-02-09 14:48:42 -0800856 switch (cellState) {
857 case PhoneConstants.CELL_OFF_FLAG:
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700858 // Airplane mode does not affect the cell radio if user has turned it off.
859 Log.i(LOG_TAG, "Ignore airplane mode change due to cell off.");
Chris Mantona09f3632016-02-09 14:48:42 -0800860 break;
861 case PhoneConstants.CELL_ON_FLAG:
Taesu Lee62f826d2020-08-10 16:01:18 +0900862 maybeTurnCellOff(isAirplaneNewlyOn);
Chris Mantona09f3632016-02-09 14:48:42 -0800863 break;
864 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
Taesu Lee62f826d2020-08-10 16:01:18 +0900865 maybeTurnCellOn(isAirplaneNewlyOn);
Chris Mantona09f3632016-02-09 14:48:42 -0800866 break;
867 }
Hall Liu7f56e1a2019-07-10 14:41:14 -0700868 for (Phone phone : PhoneFactory.getPhones()) {
869 phone.getServiceStateTracker().onAirplaneModeChanged(isAirplaneNewlyOn);
870 }
Chris Mantona09f3632016-02-09 14:48:42 -0800871 }
872
873 /*
874 * Returns true if the radio must be turned off when entering airplane mode.
875 */
Taesu Lee62f826d2020-08-10 16:01:18 +0900876 private boolean isCellOffInAirplaneMode() {
877 String airplaneModeRadios =
878 Settings.Global.getString(
879 getContentResolver(), Settings.Global.AIRPLANE_MODE_RADIOS);
Chris Mantona09f3632016-02-09 14:48:42 -0800880 return airplaneModeRadios == null
881 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
882 }
883
Taesu Lee62f826d2020-08-10 16:01:18 +0900884 private void setRadioPowerOff() {
Chris Mantona09f3632016-02-09 14:48:42 -0800885 Log.i(LOG_TAG, "Turning radio off - airplane");
Taesu Lee62f826d2020-08-10 16:01:18 +0900886 Settings.Global.putInt(
887 getContentResolver(),
888 Settings.Global.CELL_ON,
889 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Chris Mantona09f3632016-02-09 14:48:42 -0800890 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
Taesu Lee62f826d2020-08-10 16:01:18 +0900891 TelephonyProperties.airplane_mode_on(true); // true means int value 1
Chris Mantona09f3632016-02-09 14:48:42 -0800892 PhoneUtils.setRadioPower(false);
Ling Ma317906d2022-12-05 15:58:14 -0800893 clearCacheOnRadioOff();
894 }
895
896 /** Clear fields on power off radio **/
897 private void clearCacheOnRadioOff() {
898 // Re-show is-roaming notifications after APM mode
sangyun1c1918a2023-11-13 22:37:50 +0900899 if (mFeatureFlags.reorganizeRoamingNotification()) {
900 mShownNotificationReasons.clear();
901 } else {
902 mPrevRoamingOperatorNumerics.clear();
903 }
Chris Mantona09f3632016-02-09 14:48:42 -0800904 }
905
Taesu Lee62f826d2020-08-10 16:01:18 +0900906 private void setRadioPowerOn() {
Chris Mantona09f3632016-02-09 14:48:42 -0800907 Log.i(LOG_TAG, "Turning radio on - airplane");
Taesu Lee62f826d2020-08-10 16:01:18 +0900908 Settings.Global.putInt(
909 getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
910 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 1);
Meng Wang61307622019-10-23 14:08:43 -0700911 TelephonyProperties.airplane_mode_on(false); // false means int value 0
Chris Mantona09f3632016-02-09 14:48:42 -0800912 PhoneUtils.setRadioPower(true);
913 }
914
Taesu Lee62f826d2020-08-10 16:01:18 +0900915 private void maybeTurnCellOff(boolean isAirplaneNewlyOn) {
Chris Mantona09f3632016-02-09 14:48:42 -0800916 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700917 // If we are trying to turn off the radio, make sure there are no active
918 // emergency calls. If there are, switch airplane mode back to off.
Taesu Lee62f826d2020-08-10 16:01:18 +0900919 TelecomManager tm = (TelecomManager) getSystemService(TELECOM_SERVICE);
Tyler Gunn900d8fd2018-09-21 09:22:12 -0700920
921 if (tm != null && tm.isInEmergencyCall()) {
Santos Cordone18902f2016-03-22 17:16:04 -0700922 // Switch airplane mode back to off.
Jordan Liu0e819b12019-08-28 15:33:05 -0700923 ConnectivityManager cm =
Taesu Lee62f826d2020-08-10 16:01:18 +0900924 (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
Jordan Liu0e819b12019-08-28 15:33:05 -0700925 cm.setAirplaneMode(false);
Santos Cordone18902f2016-03-22 17:16:04 -0700926 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
927 .show();
928 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Taesu Lee62f826d2020-08-10 16:01:18 +0900929 } else if (isCellOffInAirplaneMode()) {
930 setRadioPowerOff();
Santos Cordone18902f2016-03-22 17:16:04 -0700931 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800932 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700933 }
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700934 } else {
935 Log.i(LOG_TAG, "Ignoring airplane mode: not newly on");
Chris Mantona09f3632016-02-09 14:48:42 -0800936 }
937 }
938
Taesu Lee62f826d2020-08-10 16:01:18 +0900939 private void maybeTurnCellOn(boolean isAirplaneNewlyOn) {
Chris Mantona09f3632016-02-09 14:48:42 -0800940 if (!isAirplaneNewlyOn) {
Taesu Lee62f826d2020-08-10 16:01:18 +0900941 setRadioPowerOn();
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700942 } else {
943 Log.i(LOG_TAG, "Ignoring airplane mode off: radio is already on.");
Santos Cordone18902f2016-03-22 17:16:04 -0700944 }
945 }
946
Santos Cordon593ab382013-08-06 21:58:23 -0700947 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700948 * Receiver for misc intent broadcasts the Phone app cares about.
949 */
950 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
951 @Override
952 public void onReceive(Context context, Intent intent) {
953 String action = intent.getAction();
954 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Taesu Lee3dc572b2020-08-07 18:16:22 +0900955 boolean airplaneMode = intent.getBooleanExtra("state", false);
Taesu Lee62f826d2020-08-10 16:01:18 +0900956 handleAirplaneModeChange(airplaneMode);
Amit Mahajanf5d92c82018-11-02 17:44:40 -0700957 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
958 // re-register as it may be a new IccCard
959 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
960 SubscriptionManager.INVALID_PHONE_INDEX);
961 if (SubscriptionManager.isValidPhoneId(phoneId)) {
962 PhoneUtils.unregisterIccStatus(mHandler, phoneId);
963 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED, phoneId);
964 }
Nazish Tabassum160d2112019-12-23 17:31:33 +0530965 String iccStatus = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
966 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
967 new EventSimStateChangedBag(phoneId, iccStatus)));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700968 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
969 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800970 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
971 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700972 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530973 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530974 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530975 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
976 if (phoneInEcm != null) {
977 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
978 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
979 // Start Emergency Callback Mode service
Daniel Bright30efde42020-01-09 22:11:15 -0800980 if (intent.getBooleanExtra(
981 TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530982 context.startService(new Intent(context,
983 EmergencyCallbackModeService.class));
984 } else {
985 phoneInEcm = null;
986 }
987 } else {
988 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
989 // on a device that doesn't support ECM in the first place.
990 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
991 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
992 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700993 }
994 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530995 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700996 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700997 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
998 // Roaming status could be overridden by carrier config, so we need to update it.
999 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
sangyun1c1918a2023-11-13 22:37:50 +09001000 if (mFeatureFlags.reorganizeRoamingNotification()) {
1001 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED);
1002 } else {
1003 updateDataRoamingStatusForFeatureDisabled(null);
1004 }
chen xubaf9fe52019-07-02 17:28:24 -07001005 updateLimitedSimFunctionForDualSim();
Lei Liu863eac02020-06-24 20:12:55 +08001006 int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
1007 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1008 if (SubscriptionManager.isValidSubscriptionId(subId)) {
1009 mHandler.sendMessage(mHandler.obtainMessage(EVENT_CARRIER_CONFIG_CHANGED,
1010 new Integer(subId)));
1011 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001012 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
1013 // We also need to pay attention when default data subscription changes.
1014 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
1015 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
1016 registerSettingsObserver();
1017 Phone phone = getPhone(mDefaultDataSubId);
1018 if (phone != null) {
sangyun1c1918a2023-11-13 22:37:50 +09001019 if (mFeatureFlags.reorganizeRoamingNotification()) {
1020 updateDataRoamingStatus(
1021 ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED);
1022 } else {
1023 updateDataRoamingStatusForFeatureDisabled(null);
1024 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001025 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001026 }
1027 }
1028 }
1029
Sarah Chin072ffb22022-05-03 17:58:59 -07001030 private void handleServiceStateChanged(ServiceState serviceState, int subId) {
Jack Yu1a2fc352017-07-14 17:14:37 -07001031 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Sarah Chin072ffb22022-05-03 17:58:59 -07001032 int state = serviceState.getState();
1033 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -07001034
Sarah Chin072ffb22022-05-03 17:58:59 -07001035 if (VDBG) {
1036 Log.v(LOG_TAG, "subId=" + subId + ", mDefaultDataSubId="
1037 + mDefaultDataSubId + ", ss roaming=" + serviceState.getDataRoaming());
1038 }
1039 if (subId == mDefaultDataSubId) {
sangyun1c1918a2023-11-13 22:37:50 +09001040 if (mFeatureFlags.reorganizeRoamingNotification()) {
1041 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED);
1042 } else {
1043 updateDataRoamingStatusForFeatureDisabled(serviceState.getOperatorNumeric());
1044 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001045 }
1046 }
1047
Jack Yu1a2fc352017-07-14 17:14:37 -07001048 /**
1049 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
1050 * to notify the user so they can enable it through settings. Vise versa if the condition
1051 * changes, we need to dismiss the notification.
sangyund2cfeaa2024-03-31 12:20:40 +09001052 * @param notificationReason to inform which event is called for notification update.
Jack Yu1a2fc352017-07-14 17:14:37 -07001053 */
sangyund2cfeaa2024-03-31 12:20:40 +09001054 private void updateDataRoamingStatus(@RoamingNotificationReason int notificationReason) {
Jack Yu1a2fc352017-07-14 17:14:37 -07001055 Phone phone = getPhone(mDefaultDataSubId);
1056 if (phone == null) {
1057 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
1058 return;
1059 }
1060
sangyun35f23f82023-07-18 01:37:53 +09001061 ServiceState serviceState = phone.getServiceState();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08001062 if (serviceState == null) {
1063 Log.e(LOG_TAG, "updateDataRoamingStatus: serviceState is null");
1064 return;
1065 }
1066
sangyund2cfeaa2024-03-31 12:20:40 +09001067 List<DataDisallowedReason> disallowReasons = phone.getDataNetworkController()
1068 .getInternetDataDisallowedReasons();
1069
1070 if (mFeatureFlags.roamingNotificationForSingleDataNetwork()) {
1071 if (disallowReasons.contains(DataDisallowedReason.ONLY_ALLOWED_SINGLE_NETWORK)
1072 && disallowReasons.contains(DataDisallowedReason.ROAMING_DISABLED)
1073 && (notificationReason == ROAMING_NOTIFICATION_REASON_DATA_SETTING_CHANGED
1074 || notificationReason
1075 == ROAMING_NOTIFICATION_REASON_DATA_ROAMING_SETTING_CHANGED)) {
1076 // If the ONLY_ALLOWED_SINGLE_NETWORK disallow reason has not yet been removed due
1077 // to a change in mobile_data (including roaming_data) settings, update roaming
1078 // notification again after the Internet is completely disconnected to check
1079 // ONLY_ALLOWED_SINGLE_NETWORK disallow reason is removed.
1080 mWaitForInternetDisconnection.set(true);
1081 Log.d(LOG_TAG, "updateDataRoamingStatus,"
1082 + " wait for internet disconnection for single data network");
1083 } else if (!disallowReasons.contains(DataDisallowedReason.ONLY_ALLOWED_SINGLE_NETWORK)
1084 && mWaitForInternetDisconnection.compareAndSet(true, false)) {
1085 // If the ONLY_ALLOWED_SINGLE_NETWORK disallow reason has been removed,
1086 // no longer wait for Internet disconnection.
1087 Log.d(LOG_TAG, "updateDataRoamingStatus,"
1088 + " cancel to wait for internet disconnection for single data network");
1089 }
1090 }
1091
1092 updateDataRoamingStatus(notificationReason, disallowReasons, serviceState);
1093 }
1094
1095 /**
1096 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
1097 * to notify the user so they can enable it through settings. Vise versa if the condition
1098 * changes, we need to dismiss the notification.
1099 * @param notificationReason to inform which event is called for notification update.
1100 * @param disallowReasons List of reasons why internet data is not allowed. An empty list if
1101 * internet is allowed.
1102 * @param serviceState Service state from phone
1103 */
1104 private void updateDataRoamingStatus(@RoamingNotificationReason int notificationReason,
1105 List<DataDisallowedReason> disallowReasons, ServiceState serviceState) {
1106
1107 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
sangyun35f23f82023-07-18 01:37:53 +09001108 String roamingNumeric = serviceState.getOperatorNumeric();
1109 String roamingNumericReason = "RoamingNumeric=" + roamingNumeric;
sangyund2cfeaa2024-03-31 12:20:40 +09001110 String callingReason = "CallingReason=" + notificationReason;
sangyun35f23f82023-07-18 01:37:53 +09001111 boolean dataIsNowRoaming = serviceState.getDataRoaming();
Jack Yu3e2ac6e2022-03-26 13:59:45 -07001112 boolean dataAllowed;
1113 boolean notAllowedDueToRoamingOff;
sangyund2cfeaa2024-03-31 12:20:40 +09001114 dataAllowed = disallowReasons.isEmpty();
1115 notAllowedDueToRoamingOff = (disallowReasons.size() == 1
1116 && disallowReasons.contains(DataDisallowedReason.ROAMING_DISABLED));
sangyun35f23f82023-07-18 01:37:53 +09001117 StringBuilder sb = new StringBuilder("updateDataRoamingStatus");
1118 sb.append(" dataAllowed=").append(dataAllowed);
sangyund2cfeaa2024-03-31 12:20:40 +09001119 sb.append(", disallowReasons=").append(disallowReasons);
sangyun35f23f82023-07-18 01:37:53 +09001120 sb.append(", dataIsNowRoaming=").append(dataIsNowRoaming);
1121 sb.append(", ").append(roamingNumericReason);
1122 sb.append(", ").append(callingReason);
1123 mDataRoamingNotifLog.log(sb.toString());
Ling Ma317906d2022-12-05 15:58:14 -08001124 if (VDBG) {
sangyun35f23f82023-07-18 01:37:53 +09001125 Log.v(LOG_TAG, sb.toString());
Ling Ma317906d2022-12-05 15:58:14 -08001126 }
Jack Yu3e2ac6e2022-03-26 13:59:45 -07001127
sangyun35f23f82023-07-18 01:37:53 +09001128 // Determine if a given roaming numeric has never been shown.
1129 boolean shownInThisNumeric = false;
sangyund2cfeaa2024-03-31 12:20:40 +09001130 if (notificationReason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED
1131 || notificationReason == ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED) {
sangyun35f23f82023-07-18 01:37:53 +09001132 shownInThisNumeric = mShownNotificationReasons.contains(roamingNumericReason);
1133 }
1134 // Determine if a notification has never been shown by given calling reason.
1135 boolean shownForThisReason = mShownNotificationReasons.contains(callingReason);
1136
Jack Yu3e2ac6e2022-03-26 13:59:45 -07001137 if (!dataAllowed && notAllowedDueToRoamingOff) {
sangyun35f23f82023-07-18 01:37:53 +09001138 if (!shownInThisNumeric && roamingNumeric != null) {
1139 mShownNotificationReasons.add(roamingNumericReason);
1140 }
1141 if (!shownForThisReason
sangyund2cfeaa2024-03-31 12:20:40 +09001142 && notificationReason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED) {
sangyun35f23f82023-07-18 01:37:53 +09001143 mShownNotificationReasons.add(callingReason);
Ling Ma4e15c322022-12-07 11:20:53 -08001144 }
Jordan Liuff2ccd72019-07-23 15:54:41 -07001145 // No need to show it again if we never cancelled it explicitly.
sangyun35f23f82023-07-18 01:37:53 +09001146 if (getCurrentRoamingNotification() == ROAMING_NOTIFICATION_DISCONNECTED) {
1147 return;
1148 }
1149
Jack Yu1a2fc352017-07-14 17:14:37 -07001150 // If the only reason of no data is data roaming disabled, then we notify the user
1151 // so the user can turn on data roaming.
sangyun35f23f82023-07-18 01:37:53 +09001152 if (!shownInThisNumeric && !shownForThisReason) {
1153 updateDataRoamingNotification(ROAMING_NOTIFICATION_DISCONNECTED);
1154 } else {
1155 // Don't show roaming notification if we've already shown for this MccMnc
1156 Log.d(LOG_TAG, "Skip roaming disconnected notification since already"
1157 + " shownInThisNumeric=" + shownInThisNumeric
1158 + " shownForThisReason=" + shownForThisReason);
1159 // Dismiss notification if the other notification is shown.
1160 if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
1161 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
1162 }
1163 }
1164 } else if (dataAllowed && dataIsNowRoaming) {
1165 if (!shownInThisNumeric && roamingNumeric != null) {
1166 mShownNotificationReasons.add(roamingNumericReason);
1167 }
1168 if (!shownForThisReason
sangyund2cfeaa2024-03-31 12:20:40 +09001169 && notificationReason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED) {
sangyun35f23f82023-07-18 01:37:53 +09001170 mShownNotificationReasons.add(callingReason);
1171 }
Sarah Chin37b39072023-11-05 13:28:21 -08001172 boolean shouldShowRoamingNotification = shouldShowRoamingNotification(roamingNumeric);
sangyun35f23f82023-07-18 01:37:53 +09001173 // No need to show it again if we never cancelled it explicitly.
1174 if (getCurrentRoamingNotification() == ROAMING_NOTIFICATION_CONNECTED) {
Ling Ma4e15c322022-12-07 11:20:53 -08001175 return;
1176 }
sangyun35f23f82023-07-18 01:37:53 +09001177
1178 // Inform users that roaming charges may apply.
Sarah Chin37b39072023-11-05 13:28:21 -08001179 if (!shownInThisNumeric && !shownForThisReason && shouldShowRoamingNotification) {
sangyun35f23f82023-07-18 01:37:53 +09001180 updateDataRoamingNotification(ROAMING_NOTIFICATION_CONNECTED);
1181 } else {
1182 // Don't show roaming notification if we've already shown for this MccMnc or
1183 // disabled from carrier config.
1184 Log.d(LOG_TAG, "Skip roaming connected notification since already"
1185 + " shownInThisNumeric:" + shownInThisNumeric
1186 + " shownForThisReason:" + shownForThisReason
Sarah Chin37b39072023-11-05 13:28:21 -08001187 + " shouldShowRoamingNotification:" + shouldShowRoamingNotification);
sangyun35f23f82023-07-18 01:37:53 +09001188 // Dismiss notification if the other notification is shown.
1189 if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
1190 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
1191 }
1192 }
1193 } else if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
Jordan Liuff2ccd72019-07-23 15:54:41 -07001194 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
1195 // is not the only data disable reason. In this case we dismiss the notification we
1196 // showed earlier.
sangyun35f23f82023-07-18 01:37:53 +09001197 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
Jack Yu1a2fc352017-07-14 17:14:37 -07001198 }
1199 }
1200
sangyun35f23f82023-07-18 01:37:53 +09001201 private void updateDataRoamingNotification(@RoamingNotification int roamingNotification) {
1202 int event;
1203 switch (roamingNotification) {
1204 case ROAMING_NOTIFICATION_NO_NOTIFICATION:
1205 Log.d(LOG_TAG, "Dismiss roaming notification");
1206 mDataRoamingNotifLog.log("Hide roaming.");
1207 event = EVENT_DATA_ROAMING_OK;
1208 break;
1209 case ROAMING_NOTIFICATION_CONNECTED:
1210 Log.d(LOG_TAG, "Show roaming connected notification");
1211 mDataRoamingNotifLog.log("Show roaming on.");
1212 event = EVENT_DATA_ROAMING_CONNECTED;
1213 break;
1214 case ROAMING_NOTIFICATION_DISCONNECTED:
1215 Log.d(LOG_TAG, "Show roaming disconnected notification");
1216 mDataRoamingNotifLog.log("Show roaming off.");
1217 event = EVENT_DATA_ROAMING_DISCONNECTED;
1218 break;
1219 default:
1220 Log.d(LOG_TAG, "Should never reach here.");
1221 mDataRoamingNotifLog.log("Should never reach here.");
1222 return;
1223 }
1224 mCurrentRoamingNotification = roamingNotification;
1225 mHandler.obtainMessage(event, mDefaultDataSubId, 0).sendToTarget();
1226 }
1227
1228 private @RoamingNotification int getCurrentRoamingNotification() {
1229 return mCurrentRoamingNotification;
1230 }
1231
sangyun1c1918a2023-11-13 22:37:50 +09001232 // For reorganize_roaming_notification feature disabled.
1233 /**
1234 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
1235 * to notify the user so they can enable it through settings. Vise versa if the condition
1236 * changes, we need to dismiss the notification.
1237 * @param roamingOperatorNumeric The operator numeric for the current roaming. {@code null} if
1238 * the current roaming operator numeric didn't change.
1239 */
1240 private void updateDataRoamingStatusForFeatureDisabled(
1241 @Nullable String roamingOperatorNumeric) {
1242 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatusForFeatureDisabled");
1243 Phone phone = getPhone(mDefaultDataSubId);
1244 if (phone == null) {
1245 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
1246 return;
1247 }
1248
1249 boolean dataAllowed;
1250 boolean notAllowedDueToRoamingOff;
1251 List<DataDisallowedReason> reasons = phone.getDataNetworkController()
1252 .getInternetDataDisallowedReasons();
1253 dataAllowed = reasons.isEmpty();
1254 notAllowedDueToRoamingOff = (reasons.size() == 1
1255 && reasons.contains(DataDisallowedReason.ROAMING_DISABLED));
1256 mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons
1257 + ", roamingOperatorNumeric=" + roamingOperatorNumeric);
1258 if (VDBG) {
1259 Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons
1260 + ", roamingOperatorNumeric=" + roamingOperatorNumeric);
1261 }
1262
1263 if (!dataAllowed && notAllowedDueToRoamingOff) {
1264 // Don't show roaming notification if we've already shown for this MccMnc
1265 if (roamingOperatorNumeric != null
1266 && !mPrevRoamingOperatorNumerics.add(roamingOperatorNumeric)) {
1267 Log.d(LOG_TAG, "Skip roaming disconnected notification since already shown in "
1268 + "MccMnc " + roamingOperatorNumeric);
1269 return;
1270 }
1271 // No need to show it again if we never cancelled it explicitly.
1272 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_DISCONNECTED) return;
1273 // If the only reason of no data is data roaming disabled, then we notify the user
1274 // so the user can turn on data roaming.
1275 mPrevRoamingNotification = ROAMING_NOTIFICATION_DISCONNECTED;
1276 Log.d(LOG_TAG, "Show roaming disconnected notification");
1277 mDataRoamingNotifLog.log("Show roaming off.");
1278 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_DISCONNECTED);
1279 msg.arg1 = mDefaultDataSubId;
1280 msg.sendToTarget();
1281 } else if (dataAllowed && dataIsNowRoaming(mDefaultDataSubId)) {
sangyun5abbf7e2024-02-01 00:47:30 +09001282 if (!shouldShowRoamingNotification(roamingOperatorNumeric != null
1283 ? roamingOperatorNumeric : phone.getServiceState().getOperatorNumeric())) {
Sarah Chin37b39072023-11-05 13:28:21 -08001284 Log.d(LOG_TAG, "Skip showing roaming connected notification.");
1285 return;
1286 }
sangyun1c1918a2023-11-13 22:37:50 +09001287 // Don't show roaming notification if we've already shown for this MccMnc
1288 if (roamingOperatorNumeric != null
1289 && !mPrevRoamingOperatorNumerics.add(roamingOperatorNumeric)) {
1290 Log.d(LOG_TAG, "Skip roaming connected notification since already shown in "
1291 + "MccMnc " + roamingOperatorNumeric);
1292 return;
1293 }
1294 // No need to show it again if we never cancelled it explicitly, or carrier config
1295 // indicates this is not needed.
1296 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_CONNECTED) return;
1297 mPrevRoamingNotification = ROAMING_NOTIFICATION_CONNECTED;
1298 Log.d(LOG_TAG, "Show roaming connected notification");
1299 mDataRoamingNotifLog.log("Show roaming on.");
1300 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_CONNECTED);
1301 msg.arg1 = mDefaultDataSubId;
1302 msg.sendToTarget();
1303 } else if (mPrevRoamingNotification != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
1304 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
1305 // is not the only data disable reason. In this case we dismiss the notification we
1306 // showed earlier.
1307 mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
1308 Log.d(LOG_TAG, "Dismiss roaming notification");
1309 mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed);
1310 mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
1311 }
1312 }
1313
Jordan Liuff2ccd72019-07-23 15:54:41 -07001314 /**
1315 *
1316 * @param subId to check roaming on
1317 * @return whether we have transitioned to dataRoaming
1318 */
1319 private boolean dataIsNowRoaming(int subId) {
Sarah Chine04784a2022-10-31 20:32:34 -07001320 return getPhone(subId).getServiceState().getDataRoaming();
Jordan Liuff2ccd72019-07-23 15:54:41 -07001321 }
1322
Sarah Chin37b39072023-11-05 13:28:21 -08001323 private boolean shouldShowRoamingNotification(String roamingNumeric) {
1324 PersistableBundle config = getCarrierConfigForSubId(mDefaultDataSubId);
1325 boolean showRoamingNotification = config.getBoolean(
1326 CarrierConfigManager.KEY_SHOW_DATA_CONNECTED_ROAMING_NOTIFICATION_BOOL);
1327
1328 if (TextUtils.isEmpty(roamingNumeric) || !mFeatureFlags.hideRoamingIcon()) {
1329 Log.d(LOG_TAG, "shouldShowRoamingNotification: roamingNumeric=" + roamingNumeric
1330 + ", hideRoaming=" + mFeatureFlags.hideRoamingIcon());
1331 return showRoamingNotification;
1332 }
1333
1334 String[] includedMccMncs = config.getStringArray(CarrierConfigManager
1335 .KEY_DATA_CONNECTED_ROAMING_NOTIFICATION_INCLUDED_MCC_MNCS_STRING_ARRAY);
1336 if (includedMccMncs != null) {
1337 for (String mccMnc : includedMccMncs) {
1338 if (roamingNumeric.equals(mccMnc)) {
1339 Log.d(LOG_TAG, "shouldShowRoamingNotification: show for MCC/MNC " + mccMnc);
1340 return showRoamingNotification;
1341 }
1342 }
1343 }
1344
1345 String[] excludedMccs = config.getStringArray(CarrierConfigManager
1346 .KEY_DATA_CONNECTED_ROAMING_NOTIFICATION_EXCLUDED_MCCS_STRING_ARRAY);
1347 String roamingMcc = roamingNumeric.length() < 3 ? "" : roamingNumeric.substring(0, 3);
1348 if (excludedMccs != null && !TextUtils.isEmpty(roamingMcc)) {
1349 for (String mcc : excludedMccs) {
1350 if (roamingMcc.equals(mcc)) {
1351 Log.d(LOG_TAG, "shouldShowRoamingNotification: ignore for MCC " + mcc);
1352 return false;
1353 }
1354 }
1355 }
1356
1357 if (showRoamingNotification) {
1358 Log.d(LOG_TAG, "shouldShowRoamingNotification: show for numeric " + roamingNumeric);
1359 }
1360 return showRoamingNotification;
1361 }
1362
chen xubaf9fe52019-07-02 17:28:24 -07001363 private void updateLimitedSimFunctionForDualSim() {
1364 if (DBG) Log.d(LOG_TAG, "updateLimitedSimFunctionForDualSim");
1365 // check conditions to display limited SIM function notification under dual SIM
1366 SubscriptionManager subMgr = (SubscriptionManager) getSystemService(
1367 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
1368 List<SubscriptionInfo> subList = subMgr.getActiveSubscriptionInfoList(false);
1369 if (subList != null && subList.size() > 1) {
1370 CarrierConfigManager configMgr = (CarrierConfigManager)
1371 getSystemService(Context.CARRIER_CONFIG_SERVICE);
1372 for (SubscriptionInfo info : subList) {
1373 PersistableBundle b = configMgr.getConfigForSubId(info.getSubscriptionId());
1374 if (b != null) {
1375 if (b.getBoolean(CarrierConfigManager
1376 .KEY_LIMITED_SIM_FUNCTION_NOTIFICATION_FOR_DSDS_BOOL)) {
1377 notificationMgr.showLimitedSimFunctionWarningNotification(
1378 info.getSubscriptionId(),
1379 info.getDisplayName().toString());
1380 } else {
1381 notificationMgr.dismissLimitedSimFunctionWarningNotification(
1382 info.getSubscriptionId());
1383 }
1384 }
1385 }
1386 } else {
1387 // cancel notifications for all subs
1388 notificationMgr.dismissLimitedSimFunctionWarningNotification(
1389 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1390 }
1391 notificationMgr.dismissLimitedSimFunctionWarningNotificationForInactiveSubs();
1392
1393 }
1394
Sandeep Kuntade73a6a2014-10-15 18:45:56 +05301395 public Phone getPhoneInEcm() {
1396 return phoneInEcm;
1397 }
1398
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001399 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -08001400 * Triggers a refresh of the message waiting (voicemail) indicator.
1401 *
1402 * @param subId the subscription id we should refresh the notification for.
1403 */
1404 public void refreshMwiIndicator(int subId) {
1405 notificationMgr.refreshMwi(subId);
1406 }
1407
1408 /**
Pengquan Mengdd9ac822018-09-20 15:25:35 -07001409 * Called when the network selection on the subscription {@code subId} is changed by the user.
1410 *
1411 * @param subId the subscription id.
1412 */
1413 public void onNetworkSelectionChanged(int subId) {
1414 Phone phone = getPhone(subId);
1415 if (phone != null) {
1416 notificationMgr.updateNetworkSelection(phone.getServiceState().getState(), subId);
1417 } else {
1418 Log.w(LOG_TAG, "onNetworkSelectionChanged on null phone, subId: " + subId);
1419 }
1420 }
1421
1422 /**
James.cf Lin4b784aa2021-01-31 03:25:15 +08001423 * @return whether the device supports RCS User Capability Exchange or not.
1424 */
1425 public boolean getDeviceUceEnabled() {
1426 return (mTelephonyRcsService == null) ? false : mTelephonyRcsService.isDeviceUceEnabled();
1427 }
1428
1429 /**
1430 * Set the device supports RCS User Capability Exchange.
1431 * @param isEnabled true if the device supports UCE.
1432 */
1433 public void setDeviceUceEnabled(boolean isEnabled) {
1434 if (mTelephonyRcsService != null) {
1435 mTelephonyRcsService.setDeviceUceEnabled(isEnabled);
1436 }
1437 }
1438
1439 /**
Jack Yu1a2fc352017-07-14 17:14:37 -07001440 * Dump the state of the object, add calls to other objects as desired.
1441 *
1442 * @param fd File descriptor
1443 * @param printWriter Print writer
1444 * @param args Arguments
1445 */
1446 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
1447 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
1448 pw.println("------- PhoneGlobals -------");
1449 pw.increaseIndent();
sangyun15019e02023-11-13 21:50:15 +09001450 pw.println("FeatureFlags:");
1451 pw.increaseIndent();
sangyun1c1918a2023-11-13 22:37:50 +09001452 pw.println("reorganizeRoamingNotification="
1453 + mFeatureFlags.reorganizeRoamingNotification());
sangyund5f37ab2023-11-13 22:52:28 +09001454 pw.println("dismissNetworkSelectionNotificationOnSimDisable="
1455 + mFeatureFlags.dismissNetworkSelectionNotificationOnSimDisable());
sangyun15019e02023-11-13 21:50:15 +09001456 pw.decreaseIndent();
sangyun1c1918a2023-11-13 22:37:50 +09001457 if (mFeatureFlags.reorganizeRoamingNotification()) {
1458 pw.println("mCurrentRoamingNotification=" + mCurrentRoamingNotification);
1459 } else {
1460 pw.println("mPrevRoamingNotification=" + mPrevRoamingNotification);
1461 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001462 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
Keun young Parkdebb8532019-05-30 16:35:27 -07001463 pw.println("isSmsCapable=" + TelephonyManager.from(this).isSmsCapable());
sangyun35f23f82023-07-18 01:37:53 +09001464 pw.println("mDataRoamingNotifLog:");
Jack Yu1a2fc352017-07-14 17:14:37 -07001465 pw.increaseIndent();
1466 mDataRoamingNotifLog.dump(fd, pw, args);
1467 pw.decreaseIndent();
Brad Ebinger05f52c22019-12-05 13:03:21 -08001468 pw.println("ImsResolver:");
1469 pw.increaseIndent();
1470 try {
Brad Ebingerd1947d82021-05-17 20:54:49 +00001471 if (ImsResolver.getInstance() != null) ImsResolver.getInstance().dump(fd, pw, args);
Brad Ebinger05f52c22019-12-05 13:03:21 -08001472 } catch (Exception e) {
1473 e.printStackTrace();
1474 }
1475 pw.decreaseIndent();
Brad Ebingera68a4972020-01-30 17:31:23 -08001476 pw.println("RcsService:");
1477 try {
1478 if (mTelephonyRcsService != null) mTelephonyRcsService.dump(fd, pw, args);
1479 } catch (Exception e) {
1480 e.printStackTrace();
1481 }
Hunsuk Choi89bd22c2021-11-01 13:04:54 +00001482 pw.println("ImsStateCallbackController:");
1483 try {
1484 if (mImsStateCallbackController != null) mImsStateCallbackController.dump(pw);
1485 } catch (Exception e) {
1486 e.printStackTrace();
1487 }
Hwangoo Parkba21cf22022-11-30 14:34:04 +00001488 pw.println("DomainSelectionResolver:");
1489 pw.increaseIndent();
1490 try {
1491 if (DomainSelectionResolver.getInstance() != null) {
1492 DomainSelectionResolver.getInstance().dump(fd, pw, args);
1493 }
1494 } catch (Exception e) {
1495 e.printStackTrace();
1496 }
1497 pw.decreaseIndent();
Jack Yu1a2fc352017-07-14 17:14:37 -07001498 pw.decreaseIndent();
sangyun1c1918a2023-11-13 22:37:50 +09001499 if (mFeatureFlags.reorganizeRoamingNotification()) {
1500 pw.println("mShownNotificationReasons=" + mShownNotificationReasons);
1501 } else {
1502 pw.println("mPrevRoamingOperatorNumerics:" + mPrevRoamingOperatorNumerics);
1503 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001504 pw.println("------- End PhoneGlobals -------");
1505 }
Aishwarya Mallampati05483bf2024-10-08 21:42:52 +00001506
1507 private boolean skipDataRoamingDisconnectedNotificationInSatelliteMode(int subId) {
1508 SatelliteController satelliteController = SatelliteController.getInstance();
1509 if (satelliteController.isSatelliteEnabledOrBeingEnabled()) {
1510 Log.d(LOG_TAG, "skipDataRoamingDisconnected - skip notification as "
1511 + "satellite is enabled or being enabled");
1512 return true;
1513 }
1514
1515 int phoneId = SubscriptionManager.getPhoneId(subId);
1516 Phone phone = PhoneFactory.getPhone(phoneId);
1517 ServiceState serviceState = phone.getServiceState();
1518 if (serviceState != null && serviceState.isUsingNonTerrestrialNetwork()) {
1519 Log.d(LOG_TAG, "skipDataRoamingDisconnected - isUsingNtn");
1520 List<Integer> capabilities =
1521 satelliteController.getCapabilitiesForCarrierRoamingSatelliteMode(phone);
1522 if (!capabilities.contains(NetworkRegistrationInfo.SERVICE_TYPE_DATA)) {
1523 // Skip data roaming disconnected notification as device is connected to
1524 // non-terrestrial network that does not support data.
1525 Log.d(LOG_TAG, "skipDataRoamingDisconnected - skip notification as "
1526 + "NTN does not support data");
1527 return true;
1528 }
1529 }
1530
1531 Log.d(LOG_TAG, "skipDataRoamingDisconnected - do not skip notification.");
1532 return false;
1533 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001534}