blob: 76cf979902d101e1f2ea01f62dee972d8d6e83d6 [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.telephony.ServiceState;
chen xubaf9fe52019-07-02 17:28:24 -070048import android.telephony.SubscriptionInfo;
Andrew Lee385019f2014-11-24 14:19:50 -080049import android.telephony.SubscriptionManager;
Sarah Chin072ffb22022-05-03 17:58:59 -070050import android.telephony.TelephonyCallback;
Hall Liuaa4211e2021-01-20 15:43:39 -080051import android.telephony.TelephonyLocalConnection;
Jack Yu1a2fc352017-07-14 17:14:37 -070052import android.telephony.TelephonyManager;
Sarah Chin37b39072023-11-05 13:28:21 -080053import android.text.TextUtils;
Ling Ma317906d2022-12-05 15:58:14 -080054import android.util.ArraySet;
Jack Yu1a2fc352017-07-14 17:14:37 -070055import android.util.LocalLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.util.Log;
Santos Cordone18902f2016-03-22 17:16:04 -070057import android.widget.Toast;
Ta-wei Yenb29425b2016-09-21 17:28:14 -070058
Brad Ebingere3ae65a2020-09-11 12:45:11 -070059import com.android.ims.ImsFeatureBinderRepository;
Siim Sammul182d61b2021-05-04 16:01:42 +010060import com.android.internal.os.BinderCallsStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070061import com.android.internal.telephony.CallManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070062import com.android.internal.telephony.IccCardConstants;
63import com.android.internal.telephony.MmiCode;
64import com.android.internal.telephony.Phone;
Sarah Chin072ffb22022-05-03 17:58:59 -070065import com.android.internal.telephony.PhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066import com.android.internal.telephony.PhoneConstants;
67import com.android.internal.telephony.PhoneFactory;
Jack Yu1a2fc352017-07-14 17:14:37 -070068import com.android.internal.telephony.SettingsObserver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070069import com.android.internal.telephony.TelephonyCapabilities;
Youming Ye47a6adc2018-11-19 15:33:36 -080070import com.android.internal.telephony.TelephonyComponentFactory;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070071import com.android.internal.telephony.TelephonyIntents;
Jack Yu3e2ac6e2022-03-26 13:59:45 -070072import com.android.internal.telephony.data.DataEvaluation.DataDisallowedReason;
Hwangoo Parkba21cf22022-11-30 14:34:04 +000073import com.android.internal.telephony.domainselection.DomainSelectionResolver;
Daniel Bantab26e96f2022-10-19 23:25:35 +000074import com.android.internal.telephony.emergency.EmergencyStateTracker;
Thomas Nguyen090fb002023-09-11 17:35:30 -070075import com.android.internal.telephony.flags.FeatureFlags;
Ling Ma51dd3022023-08-29 11:46:38 -070076import com.android.internal.telephony.flags.FeatureFlagsImpl;
Brad Ebinger05f52c22019-12-05 13:03:21 -080077import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn92479152021-01-20 16:30:10 -080078import com.android.internal.telephony.imsphone.ImsPhone;
79import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000080import com.android.internal.telephony.satellite.SatelliteController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000081import com.android.internal.telephony.uicc.UiccPort;
Jordan Liu06bdef12021-03-24 17:25:46 -070082import com.android.internal.telephony.uicc.UiccProfile;
Jack Yu1a2fc352017-07-14 17:14:37 -070083import com.android.internal.util.IndentingPrintWriter;
Andrew Leefb7f92e2015-02-26 16:23:32 -080084import com.android.phone.settings.SettingsConstants;
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -070085import com.android.phone.vvm.CarrierVvmPackageInstalledReceiver;
Hwangoo Parkba21cf22022-11-30 14:34:04 +000086import com.android.services.telephony.domainselection.TelephonyDomainSelectionService;
James.cf Linc9f35a42020-01-15 02:35:22 +080087import com.android.services.telephony.rcs.TelephonyRcsService;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088
Jack Yu1a2fc352017-07-14 17:14:37 -070089import java.io.FileDescriptor;
90import java.io.PrintWriter;
Jordan Liuff2ccd72019-07-23 15:54:41 -070091import java.lang.annotation.Retention;
92import java.lang.annotation.RetentionPolicy;
chen xubaf9fe52019-07-02 17:28:24 -070093import java.util.List;
Jack Yu1a2fc352017-07-14 17:14:37 -070094
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095/**
96 * Global state for the telephony subsystem when running in the primary
97 * phone process.
98 */
Sailesh Nepalbf900542014-07-15 16:18:32 -070099public class PhoneGlobals extends ContextWrapper {
Jack Yu1a2fc352017-07-14 17:14:37 -0700100 public static final String LOG_TAG = "PhoneGlobals";
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700101
102 /**
103 * Phone app-wide debug level:
104 * 0 - no debug logging
105 * 1 - normal debug logging if ro.debuggable is set (which is true in
106 * "eng" and "userdebug" builds but not "user" builds)
107 * 2 - ultra-verbose debug logging
108 *
109 * Most individual classes in the phone app have a local DBG constant,
110 * typically set to
111 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
112 * or else
113 * (PhoneApp.DBG_LEVEL >= 2)
114 * depending on the desired verbosity.
115 *
116 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
117 */
Andrew Lee88b51e22014-10-29 15:48:51 -0700118 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119
120 private static final boolean DBG =
121 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
122 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
123
124 // Message codes; see mHandler below.
125 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700127 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
Jordan Liuff2ccd72019-07-23 15:54:41 -0700128 private static final int EVENT_DATA_ROAMING_CONNECTED = 11;
129 private static final int EVENT_DATA_ROAMING_OK = 12;
130 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 13;
Jordan Liuff2ccd72019-07-23 15:54:41 -0700131 private static final int EVENT_DATA_ROAMING_SETTINGS_CHANGED = 15;
132 private static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED = 16;
Lei Liu863eac02020-06-24 20:12:55 +0800133 private static final int EVENT_CARRIER_CONFIG_CHANGED = 17;
Sarah Chin072ffb22022-05-03 17:58:59 -0700134 private static final int EVENT_MULTI_SIM_CONFIG_CHANGED = 18;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700135
136 // The MMI codes are also used by the InCallScreen.
137 public static final int MMI_INITIATE = 51;
138 public static final int MMI_COMPLETE = 52;
139 public static final int MMI_CANCEL = 53;
140 // Don't use message codes larger than 99 here; those are reserved for
141 // the individual Activities of the Phone UI.
142
Santos Cordone18902f2016-03-22 17:16:04 -0700143 public static final int AIRPLANE_ON = 1;
144 public static final int AIRPLANE_OFF = 0;
145
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700146 /**
147 * Allowable values for the wake lock code.
148 * SLEEP means the device can be put to sleep.
149 * PARTIAL means wake the processor, but we display can be kept off.
150 * FULL means wake both the processor and the display.
151 */
152 public enum WakeState {
153 SLEEP,
154 PARTIAL,
155 FULL
156 }
157
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700158 private static PhoneGlobals sMe;
159
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700160 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700161 CallNotifier notifier;
Santos Cordon63a84242013-07-23 13:32:52 -0700162 NotificationMgr notificationMgr;
James.cf Linc9f35a42020-01-15 02:35:22 +0800163 TelephonyRcsService mTelephonyRcsService;
Andrew Lee9431b832015-03-09 18:46:45 -0700164 public PhoneInterfaceManager phoneMgr;
James.cf Linaf3183c2019-10-24 00:59:00 +0800165 public ImsRcsController imsRcsController;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000166 public ImsStateCallbackController mImsStateCallbackController;
joonhunshincffb7fc2021-11-28 07:32:01 +0000167 public ImsProvisioningController mImsProvisioningController;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800168 CarrierConfigLoader configLoader;
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000169 TelephonyDomainSelectionService mDomainSelectionService;
Santos Cordon63a84242013-07-23 13:32:52 -0700170
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530171 private Phone phoneInEcm;
Santos Cordon63a84242013-07-23 13:32:52 -0700172
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173 static boolean sVoiceCapable = true;
174
Santos Cordonc593d002015-06-03 15:41:15 -0700175 // TODO: Remove, no longer used.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700176 CdmaPhoneCallState cdmaPhoneCallState;
177
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700178 // The currently-active PUK entry activity and progress dialog.
179 // Normally, these are the Emergency Dialer and the subsequent
180 // progress dialog. null if there is are no such objects in
181 // the foreground.
182 private Activity mPUKEntryActivity;
183 private ProgressDialog mPUKEntryProgressDialog;
184
Jordan Liuff2ccd72019-07-23 15:54:41 -0700185 /** @hide */
186 @Retention(RetentionPolicy.SOURCE)
sangyun35f23f82023-07-18 01:37:53 +0900187 @IntDef(prefix = {"ROAMING_NOTIFICATION_REASON_"},
188 value = {
189 ROAMING_NOTIFICATION_REASON_DATA_SETTING_CHANGED,
190 ROAMING_NOTIFICATION_REASON_DATA_ROAMING_SETTING_CHANGED,
191 ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED,
192 ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED,
193 ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED})
194 public @interface RoamingNotificationReason {}
195 private static final int ROAMING_NOTIFICATION_REASON_DATA_SETTING_CHANGED = 0;
196 private static final int ROAMING_NOTIFICATION_REASON_DATA_ROAMING_SETTING_CHANGED = 1;
197 private static final int ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED = 2;
198 private static final int ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED = 3;
199 private static final int ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED = 4;
200
201 /** @hide */
202 @Retention(RetentionPolicy.SOURCE)
Jordan Liuff2ccd72019-07-23 15:54:41 -0700203 @IntDef(prefix = {"ROAMING_NOTIFICATION_"},
204 value = {
205 ROAMING_NOTIFICATION_NO_NOTIFICATION,
206 ROAMING_NOTIFICATION_CONNECTED,
207 ROAMING_NOTIFICATION_DISCONNECTED})
208 public @interface RoamingNotification {}
209
210 private static final int ROAMING_NOTIFICATION_NO_NOTIFICATION = 0;
211 private static final int ROAMING_NOTIFICATION_CONNECTED = 1;
212 private static final int ROAMING_NOTIFICATION_DISCONNECTED = 2;
213
214 @RoamingNotification
sangyun35f23f82023-07-18 01:37:53 +0900215 private int mCurrentRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
Jack Yu953f9352017-05-18 14:41:06 -0700216
sangyun35f23f82023-07-18 01:37:53 +0900217 /**
218 * Reasons that have already shown notification to prevent duplicate shows for the same reason.
219 */
220 private ArraySet<String> mShownNotificationReasons = new ArraySet<>();
Ling Ma317906d2022-12-05 15:58:14 -0800221
sangyun1c1918a2023-11-13 22:37:50 +0900222 // For reorganize_roaming_notification feature disabled.
223 @RoamingNotification
224 private int mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
225
226 // For reorganize_roaming_notification feature disabled.
227 /** Operator numerics for which we've shown is-roaming notifications. **/
228 private ArraySet<String> mPrevRoamingOperatorNumerics = new ArraySet<>();
229
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700230 private WakeState mWakeState = WakeState.SLEEP;
231
232 private PowerManager mPowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700233 private PowerManager.WakeLock mWakeLock;
234 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700235 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700236
Jack Yu1a2fc352017-07-14 17:14:37 -0700237 private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
238 private final LocalLog mDataRoamingNotifLog = new LocalLog(50);
239
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700240 // Broadcast receiver for various intent broadcasts (see onCreate())
241 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
242
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700243 private final CarrierVvmPackageInstalledReceiver mCarrierVvmPackageInstalledReceiver =
244 new CarrierVvmPackageInstalledReceiver();
245
Jack Yu1a2fc352017-07-14 17:14:37 -0700246 private final SettingsObserver mSettingsObserver;
Siim Sammul182d61b2021-05-04 16:01:42 +0100247 private BinderCallsStats.SettingsObserver mBinderCallsSettingsObserver;
Jack Yu1a2fc352017-07-14 17:14:37 -0700248
Sarah Chin072ffb22022-05-03 17:58:59 -0700249 // Mapping of phone ID to the associated TelephonyCallback. These should be registered without
250 // fine or coarse location since we only use ServiceState for
251 private PhoneAppCallback[] mTelephonyCallbacks;
252
sangyun15019e02023-11-13 21:50:15 +0900253 private FeatureFlags mFeatureFlags;
254
Sarah Chin072ffb22022-05-03 17:58:59 -0700255 private class PhoneAppCallback extends TelephonyCallback implements
256 TelephonyCallback.ServiceStateListener {
257 private final int mSubId;
258
259 PhoneAppCallback(int subId) {
260 mSubId = subId;
261 }
262
263 @Override
264 public void onServiceStateChanged(ServiceState serviceState) {
265 // Note when registering that we should be registering with INCLUDE_LOCATION_DATA_NONE.
266 // PhoneGlobals only uses the state and roaming status, which does not require location.
267 handleServiceStateChanged(serviceState, mSubId);
268 }
269
270 public int getSubId() {
271 return mSubId;
272 }
273 }
274
Nazish Tabassum160d2112019-12-23 17:31:33 +0530275 private static class EventSimStateChangedBag {
276 final int mPhoneId;
277 final String mIccStatus;
278
279 EventSimStateChangedBag(int phoneId, String iccStatus) {
280 mPhoneId = phoneId;
281 mIccStatus = iccStatus;
282 }
283 }
284
Jordan Liu06bdef12021-03-24 17:25:46 -0700285 // Some carrier config settings disable the network lock screen, so we call handleSimLock
286 // when either SIM_LOCK or CARRIER_CONFIG changes so that no matter which one happens first,
287 // we still do the right thing
288 private void handleSimLock(int subType, Phone phone) {
289 PersistableBundle cc = getCarrierConfigForSubId(phone.getSubId());
290 if (!CarrierConfigManager.isConfigForIdentifiedCarrier(cc)) {
291 // If we only have the default carrier config just return, to avoid popping up the
292 // the SIM lock screen when it's disabled by the carrier.
293 Log.i(LOG_TAG, "Not showing 'SIM network unlock' screen. Carrier config not loaded");
294 return;
295 }
296 if (cc.getBoolean(CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
297 // Some products don't have the concept of a "SIM network lock"
298 Log.i(LOG_TAG, "Not showing 'SIM network unlock' screen. Disabled by carrier config");
299 return;
300 }
301
302 // if passed in subType is unknown, retrieve it here.
303 if (subType == -1) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000304 final UiccPort uiccPort = phone.getUiccPort();
305 if (uiccPort == null) {
Jordan Liu06bdef12021-03-24 17:25:46 -0700306 Log.e(LOG_TAG,
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000307 "handleSimLock: uiccPort for phone " + phone.getPhoneId() + " is null");
Jordan Liu06bdef12021-03-24 17:25:46 -0700308 return;
309 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000310 final UiccProfile uiccProfile = uiccPort.getUiccProfile();
Jordan Liu06bdef12021-03-24 17:25:46 -0700311 if (uiccProfile == null) {
312 Log.e(LOG_TAG,
313 "handleSimLock: uiccProfile for phone " + phone.getPhoneId() + " is null");
314 return;
315 }
316 subType = uiccProfile.getApplication(
317 uiccProfile.mCurrentAppType).getPersoSubState().ordinal();
318 }
319 // Normal case: show the "SIM network unlock" PIN entry screen.
320 // The user won't be able to do anything else until
321 // they enter a valid SIM network PIN.
322 Log.i(LOG_TAG, "show sim depersonal panel");
323 IccNetworkDepersonalizationPanel.showDialog(phone, subType);
324 }
325
326 private boolean isSimLocked(Phone phone) {
327 TelephonyManager tm = getSystemService(TelephonyManager.class);
328 return tm.createForSubscriptionId(phone.getSubId()).getSimState()
329 == TelephonyManager.SIM_STATE_NETWORK_LOCKED;
330 }
331
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332 Handler mHandler = new Handler() {
333 @Override
334 public void handleMessage(Message msg) {
335 PhoneConstants.State phoneState;
Jack Yu1a2fc352017-07-14 17:14:37 -0700336 if (VDBG) Log.v(LOG_TAG, "event=" + msg.what);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700337 switch (msg.what) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338 // TODO: This event should be handled by the lock screen, just
339 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
340 case EVENT_SIM_NETWORK_LOCKED:
Jordan Liu06bdef12021-03-24 17:25:46 -0700341 int subType = (Integer) ((AsyncResult) msg.obj).result;
342 Phone phone = (Phone) ((AsyncResult) msg.obj).userObj;
343 handleSimLock(subType, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344 break;
345
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700346 case EVENT_DATA_ROAMING_DISCONNECTED:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700347 notificationMgr.showDataRoamingNotification(msg.arg1, false);
348 break;
349
350 case EVENT_DATA_ROAMING_CONNECTED:
351 notificationMgr.showDataRoamingNotification(msg.arg1, true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700352 break;
353
354 case EVENT_DATA_ROAMING_OK:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700355 notificationMgr.hideDataRoamingNotification();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356 break;
357
358 case MMI_COMPLETE:
359 onMMIComplete((AsyncResult) msg.obj);
360 break;
361
362 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800363 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700364 break;
365
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366 case EVENT_SIM_STATE_CHANGED:
Nazish Tabassum160d2112019-12-23 17:31:33 +0530367 EventSimStateChangedBag bag = (EventSimStateChangedBag)msg.obj;
Sarah Chin010884c2023-06-14 15:55:08 -0700368 // Dismiss the "No services" notification if the SIM is removed.
369 if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(bag.mIccStatus)) {
370 notificationMgr.dismissNetworkSelectionNotificationForInactiveSubId();
371 }
372
373 // Marks the event where the SIM goes into ready state.
374 // Right now, this is only used for the PUK-unlocking process.
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700375 if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(bag.mIccStatus)
Nazish Tabassum59126a92020-07-03 21:44:49 +0530376 || IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(bag.mIccStatus)
377 || IccCardConstants.INTENT_VALUE_ICC_NOT_READY.equals(bag.mIccStatus)
378 || IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(bag.mIccStatus)) {
Sarah Chin010884c2023-06-14 15:55:08 -0700379 // When the right event is triggered and there are UI objects in the
380 // foreground, we close them to display the lock panel.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 if (mPUKEntryActivity != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700382 Log.i(LOG_TAG, "Dismiss puk entry activity");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383 mPUKEntryActivity.finish();
384 mPUKEntryActivity = null;
385 }
386 if (mPUKEntryProgressDialog != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700387 Log.i(LOG_TAG, "Dismiss puk progress dialog");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388 mPUKEntryProgressDialog.dismiss();
389 mPUKEntryProgressDialog = null;
390 }
Nazish Tabassum59126a92020-07-03 21:44:49 +0530391 Log.i(LOG_TAG, "Dismissing depersonal panel" + (bag.mIccStatus));
Nazish Tabassum160d2112019-12-23 17:31:33 +0530392 IccNetworkDepersonalizationPanel.dialogDismiss(bag.mPhoneId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700393 }
394 break;
395
396 case EVENT_UNSOL_CDMA_INFO_RECORD:
397 //TODO: handle message here;
398 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700399 case EVENT_DATA_ROAMING_SETTINGS_CHANGED:
sangyun1c1918a2023-11-13 22:37:50 +0900400 if (mFeatureFlags.reorganizeRoamingNotification()) {
401 updateDataRoamingStatus(
402 ROAMING_NOTIFICATION_REASON_DATA_ROAMING_SETTING_CHANGED);
403 } else {
404 updateDataRoamingStatusForFeatureDisabled(null);
405 }
sangyun35f23f82023-07-18 01:37:53 +0900406 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700407 case EVENT_MOBILE_DATA_SETTINGS_CHANGED:
sangyun1c1918a2023-11-13 22:37:50 +0900408 if (mFeatureFlags.reorganizeRoamingNotification()) {
409 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_DATA_SETTING_CHANGED);
410 } else {
411 updateDataRoamingStatusForFeatureDisabled(null);
412 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700413 break;
Lei Liu863eac02020-06-24 20:12:55 +0800414 case EVENT_CARRIER_CONFIG_CHANGED:
415 int subId = (Integer) msg.obj;
416 // The voicemail number could be overridden by carrier config, so need to
417 // refresh the message waiting (voicemail) indicator.
418 refreshMwiIndicator(subId);
Jordan Liu06bdef12021-03-24 17:25:46 -0700419 phone = getPhone(subId);
Sarah Chin072ffb22022-05-03 17:58:59 -0700420 if (phone != null) {
421 if (isSimLocked(phone)) {
422 // pass in subType=-1 so handleSimLock can find the actual subType if
423 // needed. This is safe as valid values for subType are >= 0
424 handleSimLock(-1, phone);
425 }
426 TelephonyManager tm = getSystemService(TelephonyManager.class);
427 PhoneAppCallback callback = mTelephonyCallbacks[phone.getPhoneId()];
428 // TODO: We may need to figure out a way to unregister if subId is invalid
429 tm.createForSubscriptionId(callback.getSubId())
430 .unregisterTelephonyCallback(callback);
431 callback = new PhoneAppCallback(subId);
432 tm.createForSubscriptionId(subId).registerTelephonyCallback(
Ling Ma317906d2022-12-05 15:58:14 -0800433 TelephonyManager.INCLUDE_LOCATION_DATA_COARSE, mHandler::post,
Sarah Chin072ffb22022-05-03 17:58:59 -0700434 callback);
435 mTelephonyCallbacks[phone.getPhoneId()] = callback;
436 }
437 break;
438 case EVENT_MULTI_SIM_CONFIG_CHANGED:
439 int activeModems = (int) ((AsyncResult) msg.obj).result;
440 TelephonyManager tm = getSystemService(TelephonyManager.class);
441 // Unregister all previous callbacks
442 for (int phoneId = 0; phoneId < mTelephonyCallbacks.length; phoneId++) {
443 PhoneAppCallback callback = mTelephonyCallbacks[phoneId];
444 if (callback != null) {
445 tm.createForSubscriptionId(callback.getSubId())
446 .unregisterTelephonyCallback(callback);
447 mTelephonyCallbacks[phoneId] = null;
448 }
449 }
450 // Register callbacks for all active modems
451 for (int phoneId = 0; phoneId < activeModems; phoneId++) {
452 int sub = PhoneFactory.getPhone(phoneId).getSubId();
453 PhoneAppCallback callback = new PhoneAppCallback(sub);
454 tm.createForSubscriptionId(sub).registerTelephonyCallback(
455 TelephonyManager.INCLUDE_LOCATION_DATA_NONE, mHandler::post,
456 callback);
457 mTelephonyCallbacks[phoneId] = callback;
Jordan Liu06bdef12021-03-24 17:25:46 -0700458 }
Lei Liu863eac02020-06-24 20:12:55 +0800459 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700460 }
461 }
462 };
463
464 public PhoneGlobals(Context context) {
465 super(context);
466 sMe = this;
Jack Yu1a2fc352017-07-14 17:14:37 -0700467 mSettingsObserver = new SettingsObserver(context, mHandler);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700468 }
469
470 public void onCreate() {
471 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
472
473 ContentResolver resolver = getContentResolver();
474
Hall Liuaa4211e2021-01-20 15:43:39 -0800475 // Initialize the shim from frameworks/opt/telephony into packages/services/Telephony.
476 TelephonyLocalConnection.setInstance(new LocalConnectionImpl(this));
477
Sarah Chin072ffb22022-05-03 17:58:59 -0700478 TelephonyManager tm = getSystemService(TelephonyManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700479 // Cache the "voice capable" flag.
480 // This flag currently comes from a resource (which is
481 // overrideable on a per-product basis):
Sarah Chin072ffb22022-05-03 17:58:59 -0700482 sVoiceCapable = tm.isVoiceCapable();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700483 // ...but this might eventually become a PackageManager "system
484 // feature" instead, in which case we'd do something like:
485 // sVoiceCapable =
486 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
487
Stuart Scottdcf40a92014-12-09 10:45:01 -0800488 if (mCM == null) {
Nathan Haroldf9df6ea2019-03-08 11:54:22 -0800489 // Initialize AnomalyReporter early so that it can be used
490 AnomalyReporter.initialize(this);
Nathan Harold0db5c5e2019-01-22 20:18:56 -0800491
Youming Ye47a6adc2018-11-19 15:33:36 -0800492 // Inject telephony component factory if configured using other jars.
493 XmlResourceParser parser = getResources().getXml(R.xml.telephony_injection);
494 TelephonyComponentFactory.getInstance().injectTheComponentFactory(parser);
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000495
496 // Create DomainSelectionResolver always, but it MUST be initialized only when
497 // the device supports AOSP domain selection architecture and
498 // has new IRadio that supports its related HAL APIs.
499 DomainSelectionResolver.make(this,
500 getResources().getBoolean(R.bool.config_enable_aosp_domain_selection));
501
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700502 // Initialize the telephony framework
sangyun15019e02023-11-13 21:50:15 +0900503 mFeatureFlags = new FeatureFlagsImpl();
504 PhoneFactory.makeDefaultPhones(this, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700505
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000506 // Initialize the DomainSelectionResolver after creating the Phone instance
507 // to check the Radio HAL version.
508 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
509 mDomainSelectionService = new TelephonyDomainSelectionService(this);
510 DomainSelectionResolver.getInstance().initialize(mDomainSelectionService);
Daniel Bantab26e96f2022-10-19 23:25:35 +0000511 // Initialize EmergencyStateTracker if domain selection is supported
512 boolean isSuplDdsSwitchRequiredForEmergencyCall = getResources()
513 .getBoolean(R.bool.config_gnss_supl_requires_default_data_for_emergency);
514 EmergencyStateTracker.make(this, isSuplDdsSwitchRequiredForEmergencyCall);
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000515 }
516
Brad Ebinger05f52c22019-12-05 13:03:21 -0800517 // Only bring up ImsResolver if the device supports having an IMS stack.
518 if (getPackageManager().hasSystemFeature(
519 PackageManager.FEATURE_TELEPHONY_IMS)) {
520 // Get the package name of the default IMS implementation.
521 String defaultImsMmtelPackage = getResources().getString(
522 R.string.config_ims_mmtel_package);
523 String defaultImsRcsPackage = getResources().getString(
524 R.string.config_ims_rcs_package);
Brad Ebingerd1947d82021-05-17 20:54:49 +0000525 ImsResolver.make(this, defaultImsMmtelPackage,
Brad Ebingere3ae65a2020-09-11 12:45:11 -0700526 defaultImsRcsPackage, PhoneFactory.getPhones().length,
527 new ImsFeatureBinderRepository());
Brad Ebingerd1947d82021-05-17 20:54:49 +0000528 ImsResolver.getInstance().initialize();
Tyler Gunn92479152021-01-20 16:30:10 -0800529
530 // With the IMS phone created, load static config.xml values from the phone process
531 // so that it can be provided to the ImsPhoneCallTracker.
532 for (Phone p : PhoneFactory.getPhones()) {
533 Phone imsPhone = p.getImsPhone();
534 if (imsPhone != null && imsPhone instanceof ImsPhone) {
535 ImsPhone theImsPhone = (ImsPhone) imsPhone;
536 if (theImsPhone.getCallTracker() instanceof ImsPhoneCallTracker) {
537 ImsPhoneCallTracker ict = (ImsPhoneCallTracker)
538 theImsPhone.getCallTracker();
539
540 ImsPhoneCallTracker.Config config = new ImsPhoneCallTracker.Config();
541 config.isD2DCommunicationSupported = getResources().getBoolean(
542 R.bool.config_use_device_to_device_communication);
543 ict.setConfig(config);
544 }
545 }
546 }
Hui Wang068ab862020-10-31 05:12:53 +0000547 RcsProvisioningMonitor.make(this);
Brad Ebinger05f52c22019-12-05 13:03:21 -0800548 }
549
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700550 // Start TelephonyDebugService After the default phone is created.
551 Intent intent = new Intent(this, TelephonyDebugService.class);
552 startService(intent);
553
554 mCM = CallManager.getInstance();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700555
556 // Create the NotificationMgr singleton, which is used to display
557 // status bar icons and control other status bar behavior.
558 notificationMgr = NotificationMgr.init(this);
559
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000560 // Create the SatelliteController singleton, which acts as a backend service for
561 // {@link android.telephony.satellite.SatelliteManager}.
sangyun15019e02023-11-13 21:50:15 +0900562 SatelliteController.make(this, mFeatureFlags);
Sarah Chin5f57c582023-02-14 04:16:10 -0800563
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700564 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
565 cdmaPhoneCallState = new CdmaPhoneCallState();
566 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700567
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700568 // before registering for phone state changes
569 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
570 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
571 // lock used to keep the processor awake, when we don't care for the display.
572 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
573 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700574
575 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
576
sangyun15019e02023-11-13 21:50:15 +0900577 phoneMgr = PhoneInterfaceManager.init(this, mFeatureFlags);
Santos Cordon406c0342013-08-28 00:07:47 -0700578
joonhunshin2c33ed92023-12-12 14:29:23 +0000579 imsRcsController = ImsRcsController.init(this, mFeatureFlags);
James.cf Linaf3183c2019-10-24 00:59:00 +0800580
joonhunshin21a86812023-12-10 08:21:25 +0000581 configLoader = CarrierConfigLoader.init(this, mFeatureFlags);
Brad Ebinger6c53e7f2023-01-27 16:26:44 -0800582
James.cf Linc9f35a42020-01-15 02:35:22 +0800583 if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000584 mImsStateCallbackController =
585 ImsStateCallbackController.make(this, PhoneFactory.getPhones().length);
Brad Ebingera68a4972020-01-30 17:31:23 -0800586 mTelephonyRcsService = new TelephonyRcsService(this,
587 PhoneFactory.getPhones().length);
588 mTelephonyRcsService.initialize();
James.cf Linc9f35a42020-01-15 02:35:22 +0800589 imsRcsController.setRcsService(mTelephonyRcsService);
joonhunshincffb7fc2021-11-28 07:32:01 +0000590 mImsProvisioningController =
591 ImsProvisioningController.make(this, PhoneFactory.getPhones().length);
James.cf Linc9f35a42020-01-15 02:35:22 +0800592 }
593
Jack Yu1a2fc352017-07-14 17:14:37 -0700594 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700595 // asynchronous events from the telephony layer (like
596 // launching the incoming-call UI when an incoming call comes
597 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800598 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700599
Stuart Scottdcf40a92014-12-09 10:45:01 -0800600 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700601
602 // register for MMI/USSD
603 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
604
Qiong Liucc3fe812019-09-23 15:25:44 +0800605 // Initialize cell status using current airplane mode.
Taesu Lee62f826d2020-08-10 16:01:18 +0900606 handleAirplaneModeChange(
607 Settings.Global.getInt(
608 getContentResolver(),
609 Settings.Global.AIRPLANE_MODE_ON,
610 AIRPLANE_OFF)
611 == AIRPLANE_ON);
Qiong Liucc3fe812019-09-23 15:25:44 +0800612
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700613 // Register for misc other intent broadcasts.
614 IntentFilter intentFilter =
615 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700616 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
617 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700618 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700619 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
620 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700621 registerReceiver(mReceiver, intentFilter);
Jack Yuec144222023-12-13 16:03:03 -0800622 int defaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
623 if (SubscriptionManager.isValidSubscriptionId(defaultDataSubId)) {
624 if (VDBG) {
625 Log.v(LOG_TAG, "Loaded initial default data sub: " + defaultDataSubId);
sangyun15019e02023-11-13 21:50:15 +0900626 }
Jack Yuec144222023-12-13 16:03:03 -0800627 mDefaultDataSubId = defaultDataSubId;
628 registerSettingsObserver();
629 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED);
sangyundce559b2023-09-11 10:25:55 +0900630 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700631
Sarah Chin072ffb22022-05-03 17:58:59 -0700632 PhoneConfigurationManager.registerForMultiSimConfigChange(
633 mHandler, EVENT_MULTI_SIM_CONFIG_CHANGED, null);
634
635 mTelephonyCallbacks = new PhoneAppCallback[tm.getSupportedModemCount()];
Fangyuan Li7f5c2752022-06-29 18:02:31 +0800636 if (tm.getSupportedModemCount() > 0) {
637 for (Phone phone : PhoneFactory.getPhones()) {
638 int subId = phone.getSubId();
639 PhoneAppCallback callback = new PhoneAppCallback(subId);
640 tm.createForSubscriptionId(subId).registerTelephonyCallback(
641 TelephonyManager.INCLUDE_LOCATION_DATA_NONE, mHandler::post, callback);
642 mTelephonyCallbacks[phone.getPhoneId()] = callback;
643 }
Sarah Chin072ffb22022-05-03 17:58:59 -0700644 }
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700645 mCarrierVvmPackageInstalledReceiver.register(this);
646
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700647 //set the default values for the preferences in the phone.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700648 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700649 }
650
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700651 // XXX pre-load the SimProvider so that it's ready
652 resolver.getType(Uri.parse("content://icc/adn"));
653
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700654 // TODO: Register for Cdma Information Records
655 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
656
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700657 // Read HAC settings and configure audio hardware
658 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800659 int hac = android.provider.Settings.System.getInt(
660 getContentResolver(),
661 android.provider.Settings.System.HEARING_AID,
662 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700663 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Jordan Liuf71aeef2019-08-21 11:46:09 -0700664 audioManager.setParameters(
665 SettingsConstants.HAC_KEY + "=" + (hac == SettingsConstants.HAC_ENABLED
666 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700667 }
Siim Sammul182d61b2021-05-04 16:01:42 +0100668
669 // Start tracking Binder latency for the phone process.
670 mBinderCallsSettingsObserver = new BinderCallsStats.SettingsObserver(
671 getApplicationContext(),
Siim Sammula6950092021-06-22 17:14:03 +0100672 new BinderCallsStats(
673 new BinderCallsStats.Injector(),
674 com.android.internal.os.BinderLatencyProto.Dims.TELEPHONY));
Santos Cordonff506f52013-11-21 19:13:19 -0800675 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700676
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700677 /**
678 * Returns the singleton instance of the PhoneApp.
679 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800680 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700681 if (sMe == null) {
682 throw new IllegalStateException("No PhoneGlobals here!");
683 }
684 return sMe;
685 }
686
687 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800688 * Returns the default phone.
689 *
Andrew Lee385019f2014-11-24 14:19:50 -0800690 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700691 */
Andrew Lee83383e42014-10-31 12:42:28 -0700692 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800693 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700694 }
695
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800696 public static Phone getPhone(int subId) {
697 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800698 }
699
Santos Cordonde10b752013-09-19 04:11:33 -0700700 /* package */ CallManager getCallManager() {
701 return mCM;
702 }
703
Chris Manton4e9fa912015-06-19 11:26:57 -0700704 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800705 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700706 }
707
Chris Manton4e9fa912015-06-19 11:26:57 -0700708 public PersistableBundle getCarrierConfigForSubId(int subId) {
Philip P. Moltmann0079aae2020-03-05 16:24:02 -0800709 return configLoader.getConfigForSubIdWithFeature(subId, getOpPackageName(),
710 getAttributionTag());
Junda Liu605148f2015-04-28 15:23:40 -0700711 }
712
Jack Yu1a2fc352017-07-14 17:14:37 -0700713 private void registerSettingsObserver() {
714 mSettingsObserver.unobserve();
715 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
716 String mobileDataSetting = Settings.Global.MOBILE_DATA;
717 if (TelephonyManager.getDefault().getSimCount() > 1) {
718 int subId = mDefaultDataSubId;
719 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
720 dataRoamingSetting += subId;
721 mobileDataSetting += subId;
722 }
723 }
724
725 // Listen for user data roaming setting changed event
726 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
727 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
728
729 // Listen for mobile data setting changed event
730 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
731 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
732 }
733
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700734 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700735 * Sets the activity responsible for un-PUK-blocking the device
736 * so that we may close it when we receive a positive result.
737 * mPUKEntryActivity is also used to indicate to the device that
738 * we are trying to un-PUK-lock the phone. In other words, iff
739 * it is NOT null, then we are trying to unlock and waiting for
740 * the SIM to move to READY state.
741 *
742 * @param activity is the activity to close when PUK has
743 * finished unlocking. Can be set to null to indicate the unlock
744 * or SIM READYing process is over.
745 */
746 void setPukEntryActivity(Activity activity) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700747 Log.i(LOG_TAG, "setPukEntryActivity - set to " + (activity == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700748 mPUKEntryActivity = activity;
749 }
750
751 Activity getPUKEntryActivity() {
752 return mPUKEntryActivity;
753 }
754
755 /**
756 * Sets the dialog responsible for notifying the user of un-PUK-
757 * blocking - SIM READYing progress, so that we may dismiss it
758 * when we receive a positive result.
759 *
760 * @param dialog indicates the progress dialog informing the user
761 * of the state of the device. Dismissed upon completion of
762 * READYing process
763 */
764 void setPukEntryProgressDialog(ProgressDialog dialog) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700765 Log.i(LOG_TAG, "setPukEntryProgressDialog - set to "
766 + (dialog == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700767 mPUKEntryProgressDialog = dialog;
768 }
769
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700770 KeyguardManager getKeyguardManager() {
771 return mKeyguardManager;
772 }
773
774 private void onMMIComplete(AsyncResult r) {
775 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
776 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800777 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700778 }
779
fionaxu80126972017-02-01 17:01:26 -0800780 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700781 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700782 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700783 }
784
Taesu Lee62f826d2020-08-10 16:01:18 +0900785 private void handleAirplaneModeChange(boolean isAirplaneNewlyOn) {
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700786 Log.i(LOG_TAG, "handleAirplaneModeChange: isAirplaneNewlyOn=" + isAirplaneNewlyOn);
Taesu Lee62f826d2020-08-10 16:01:18 +0900787 int cellState =
788 Settings.Global.getInt(
789 getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
Chris Mantona09f3632016-02-09 14:48:42 -0800790 switch (cellState) {
791 case PhoneConstants.CELL_OFF_FLAG:
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700792 // Airplane mode does not affect the cell radio if user has turned it off.
793 Log.i(LOG_TAG, "Ignore airplane mode change due to cell off.");
Chris Mantona09f3632016-02-09 14:48:42 -0800794 break;
795 case PhoneConstants.CELL_ON_FLAG:
Taesu Lee62f826d2020-08-10 16:01:18 +0900796 maybeTurnCellOff(isAirplaneNewlyOn);
Chris Mantona09f3632016-02-09 14:48:42 -0800797 break;
798 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
Taesu Lee62f826d2020-08-10 16:01:18 +0900799 maybeTurnCellOn(isAirplaneNewlyOn);
Chris Mantona09f3632016-02-09 14:48:42 -0800800 break;
801 }
Hall Liu7f56e1a2019-07-10 14:41:14 -0700802 for (Phone phone : PhoneFactory.getPhones()) {
803 phone.getServiceStateTracker().onAirplaneModeChanged(isAirplaneNewlyOn);
804 }
Chris Mantona09f3632016-02-09 14:48:42 -0800805 }
806
807 /*
808 * Returns true if the radio must be turned off when entering airplane mode.
809 */
Taesu Lee62f826d2020-08-10 16:01:18 +0900810 private boolean isCellOffInAirplaneMode() {
811 String airplaneModeRadios =
812 Settings.Global.getString(
813 getContentResolver(), Settings.Global.AIRPLANE_MODE_RADIOS);
Chris Mantona09f3632016-02-09 14:48:42 -0800814 return airplaneModeRadios == null
815 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
816 }
817
Taesu Lee62f826d2020-08-10 16:01:18 +0900818 private void setRadioPowerOff() {
Chris Mantona09f3632016-02-09 14:48:42 -0800819 Log.i(LOG_TAG, "Turning radio off - airplane");
Taesu Lee62f826d2020-08-10 16:01:18 +0900820 Settings.Global.putInt(
821 getContentResolver(),
822 Settings.Global.CELL_ON,
823 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Chris Mantona09f3632016-02-09 14:48:42 -0800824 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
Taesu Lee62f826d2020-08-10 16:01:18 +0900825 TelephonyProperties.airplane_mode_on(true); // true means int value 1
Chris Mantona09f3632016-02-09 14:48:42 -0800826 PhoneUtils.setRadioPower(false);
Ling Ma317906d2022-12-05 15:58:14 -0800827 clearCacheOnRadioOff();
828 }
829
830 /** Clear fields on power off radio **/
831 private void clearCacheOnRadioOff() {
832 // Re-show is-roaming notifications after APM mode
sangyun1c1918a2023-11-13 22:37:50 +0900833 if (mFeatureFlags.reorganizeRoamingNotification()) {
834 mShownNotificationReasons.clear();
835 } else {
836 mPrevRoamingOperatorNumerics.clear();
837 }
Chris Mantona09f3632016-02-09 14:48:42 -0800838 }
839
Taesu Lee62f826d2020-08-10 16:01:18 +0900840 private void setRadioPowerOn() {
Chris Mantona09f3632016-02-09 14:48:42 -0800841 Log.i(LOG_TAG, "Turning radio on - airplane");
Taesu Lee62f826d2020-08-10 16:01:18 +0900842 Settings.Global.putInt(
843 getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
844 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 1);
Meng Wang61307622019-10-23 14:08:43 -0700845 TelephonyProperties.airplane_mode_on(false); // false means int value 0
Chris Mantona09f3632016-02-09 14:48:42 -0800846 PhoneUtils.setRadioPower(true);
847 }
848
Taesu Lee62f826d2020-08-10 16:01:18 +0900849 private void maybeTurnCellOff(boolean isAirplaneNewlyOn) {
Chris Mantona09f3632016-02-09 14:48:42 -0800850 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700851 // If we are trying to turn off the radio, make sure there are no active
852 // emergency calls. If there are, switch airplane mode back to off.
Taesu Lee62f826d2020-08-10 16:01:18 +0900853 TelecomManager tm = (TelecomManager) getSystemService(TELECOM_SERVICE);
Tyler Gunn900d8fd2018-09-21 09:22:12 -0700854
855 if (tm != null && tm.isInEmergencyCall()) {
Santos Cordone18902f2016-03-22 17:16:04 -0700856 // Switch airplane mode back to off.
Jordan Liu0e819b12019-08-28 15:33:05 -0700857 ConnectivityManager cm =
Taesu Lee62f826d2020-08-10 16:01:18 +0900858 (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
Jordan Liu0e819b12019-08-28 15:33:05 -0700859 cm.setAirplaneMode(false);
Santos Cordone18902f2016-03-22 17:16:04 -0700860 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
861 .show();
862 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Taesu Lee62f826d2020-08-10 16:01:18 +0900863 } else if (isCellOffInAirplaneMode()) {
864 setRadioPowerOff();
Santos Cordone18902f2016-03-22 17:16:04 -0700865 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800866 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700867 }
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700868 } else {
869 Log.i(LOG_TAG, "Ignoring airplane mode: not newly on");
Chris Mantona09f3632016-02-09 14:48:42 -0800870 }
871 }
872
Taesu Lee62f826d2020-08-10 16:01:18 +0900873 private void maybeTurnCellOn(boolean isAirplaneNewlyOn) {
Chris Mantona09f3632016-02-09 14:48:42 -0800874 if (!isAirplaneNewlyOn) {
Taesu Lee62f826d2020-08-10 16:01:18 +0900875 setRadioPowerOn();
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700876 } else {
877 Log.i(LOG_TAG, "Ignoring airplane mode off: radio is already on.");
Santos Cordone18902f2016-03-22 17:16:04 -0700878 }
879 }
880
Santos Cordon593ab382013-08-06 21:58:23 -0700881 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700882 * Receiver for misc intent broadcasts the Phone app cares about.
883 */
884 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
885 @Override
886 public void onReceive(Context context, Intent intent) {
887 String action = intent.getAction();
888 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Taesu Lee3dc572b2020-08-07 18:16:22 +0900889 boolean airplaneMode = intent.getBooleanExtra("state", false);
Taesu Lee62f826d2020-08-10 16:01:18 +0900890 handleAirplaneModeChange(airplaneMode);
Amit Mahajanf5d92c82018-11-02 17:44:40 -0700891 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
892 // re-register as it may be a new IccCard
893 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
894 SubscriptionManager.INVALID_PHONE_INDEX);
895 if (SubscriptionManager.isValidPhoneId(phoneId)) {
896 PhoneUtils.unregisterIccStatus(mHandler, phoneId);
897 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED, phoneId);
898 }
Nazish Tabassum160d2112019-12-23 17:31:33 +0530899 String iccStatus = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
900 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
901 new EventSimStateChangedBag(phoneId, iccStatus)));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700902 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
903 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800904 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
905 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700906 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530907 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530908 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530909 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
910 if (phoneInEcm != null) {
911 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
912 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
913 // Start Emergency Callback Mode service
Daniel Bright30efde42020-01-09 22:11:15 -0800914 if (intent.getBooleanExtra(
915 TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530916 context.startService(new Intent(context,
917 EmergencyCallbackModeService.class));
918 } else {
919 phoneInEcm = null;
920 }
921 } else {
922 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
923 // on a device that doesn't support ECM in the first place.
924 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
925 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
926 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700927 }
928 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530929 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700930 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700931 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
932 // Roaming status could be overridden by carrier config, so we need to update it.
933 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
sangyun1c1918a2023-11-13 22:37:50 +0900934 if (mFeatureFlags.reorganizeRoamingNotification()) {
935 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED);
936 } else {
937 updateDataRoamingStatusForFeatureDisabled(null);
938 }
chen xubaf9fe52019-07-02 17:28:24 -0700939 updateLimitedSimFunctionForDualSim();
Lei Liu863eac02020-06-24 20:12:55 +0800940 int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
941 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
942 if (SubscriptionManager.isValidSubscriptionId(subId)) {
943 mHandler.sendMessage(mHandler.obtainMessage(EVENT_CARRIER_CONFIG_CHANGED,
944 new Integer(subId)));
945 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700946 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
947 // We also need to pay attention when default data subscription changes.
948 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
949 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
950 registerSettingsObserver();
951 Phone phone = getPhone(mDefaultDataSubId);
952 if (phone != null) {
sangyun1c1918a2023-11-13 22:37:50 +0900953 if (mFeatureFlags.reorganizeRoamingNotification()) {
954 updateDataRoamingStatus(
955 ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED);
956 } else {
957 updateDataRoamingStatusForFeatureDisabled(null);
958 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700959 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700960 }
961 }
962 }
963
Sarah Chin072ffb22022-05-03 17:58:59 -0700964 private void handleServiceStateChanged(ServiceState serviceState, int subId) {
Jack Yu1a2fc352017-07-14 17:14:37 -0700965 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Sarah Chin072ffb22022-05-03 17:58:59 -0700966 int state = serviceState.getState();
967 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -0700968
Sarah Chin072ffb22022-05-03 17:58:59 -0700969 if (VDBG) {
970 Log.v(LOG_TAG, "subId=" + subId + ", mDefaultDataSubId="
971 + mDefaultDataSubId + ", ss roaming=" + serviceState.getDataRoaming());
972 }
973 if (subId == mDefaultDataSubId) {
sangyun1c1918a2023-11-13 22:37:50 +0900974 if (mFeatureFlags.reorganizeRoamingNotification()) {
975 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED);
976 } else {
977 updateDataRoamingStatusForFeatureDisabled(serviceState.getOperatorNumeric());
978 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700979 }
980 }
981
Jack Yu1a2fc352017-07-14 17:14:37 -0700982 /**
983 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
984 * to notify the user so they can enable it through settings. Vise versa if the condition
985 * changes, we need to dismiss the notification.
sangyun35f23f82023-07-18 01:37:53 +0900986 * @param reason to inform which event is called for notification update.
Jack Yu1a2fc352017-07-14 17:14:37 -0700987 */
sangyun35f23f82023-07-18 01:37:53 +0900988 private void updateDataRoamingStatus(@RoamingNotificationReason int reason) {
Jack Yu1a2fc352017-07-14 17:14:37 -0700989 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
990 Phone phone = getPhone(mDefaultDataSubId);
991 if (phone == null) {
992 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
993 return;
994 }
995
sangyun35f23f82023-07-18 01:37:53 +0900996 ServiceState serviceState = phone.getServiceState();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800997 if (serviceState == null) {
998 Log.e(LOG_TAG, "updateDataRoamingStatus: serviceState is null");
999 return;
1000 }
1001
sangyun35f23f82023-07-18 01:37:53 +09001002 String roamingNumeric = serviceState.getOperatorNumeric();
1003 String roamingNumericReason = "RoamingNumeric=" + roamingNumeric;
1004 String callingReason = "CallingReason=" + reason;
1005 boolean dataIsNowRoaming = serviceState.getDataRoaming();
Jack Yu3e2ac6e2022-03-26 13:59:45 -07001006 boolean dataAllowed;
1007 boolean notAllowedDueToRoamingOff;
Sarah Chine04784a2022-10-31 20:32:34 -07001008 List<DataDisallowedReason> reasons = phone.getDataNetworkController()
1009 .getInternetDataDisallowedReasons();
Jack Yu7968c6d2022-07-31 00:43:21 -07001010 dataAllowed = reasons.isEmpty();
1011 notAllowedDueToRoamingOff = (reasons.size() == 1
1012 && reasons.contains(DataDisallowedReason.ROAMING_DISABLED));
sangyun35f23f82023-07-18 01:37:53 +09001013 StringBuilder sb = new StringBuilder("updateDataRoamingStatus");
1014 sb.append(" dataAllowed=").append(dataAllowed);
1015 sb.append(", reasons=").append(reasons);
1016 sb.append(", dataIsNowRoaming=").append(dataIsNowRoaming);
1017 sb.append(", ").append(roamingNumericReason);
1018 sb.append(", ").append(callingReason);
1019 mDataRoamingNotifLog.log(sb.toString());
Ling Ma317906d2022-12-05 15:58:14 -08001020 if (VDBG) {
sangyun35f23f82023-07-18 01:37:53 +09001021 Log.v(LOG_TAG, sb.toString());
Ling Ma317906d2022-12-05 15:58:14 -08001022 }
Jack Yu3e2ac6e2022-03-26 13:59:45 -07001023
sangyun35f23f82023-07-18 01:37:53 +09001024 // Determine if a given roaming numeric has never been shown.
1025 boolean shownInThisNumeric = false;
1026 if (reason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED
1027 || reason == ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED) {
1028 shownInThisNumeric = mShownNotificationReasons.contains(roamingNumericReason);
1029 }
1030 // Determine if a notification has never been shown by given calling reason.
1031 boolean shownForThisReason = mShownNotificationReasons.contains(callingReason);
1032
Jack Yu3e2ac6e2022-03-26 13:59:45 -07001033 if (!dataAllowed && notAllowedDueToRoamingOff) {
sangyun35f23f82023-07-18 01:37:53 +09001034 if (!shownInThisNumeric && roamingNumeric != null) {
1035 mShownNotificationReasons.add(roamingNumericReason);
1036 }
1037 if (!shownForThisReason
1038 && reason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED) {
1039 mShownNotificationReasons.add(callingReason);
Ling Ma4e15c322022-12-07 11:20:53 -08001040 }
Jordan Liuff2ccd72019-07-23 15:54:41 -07001041 // No need to show it again if we never cancelled it explicitly.
sangyun35f23f82023-07-18 01:37:53 +09001042 if (getCurrentRoamingNotification() == ROAMING_NOTIFICATION_DISCONNECTED) {
1043 return;
1044 }
1045
Jack Yu1a2fc352017-07-14 17:14:37 -07001046 // If the only reason of no data is data roaming disabled, then we notify the user
1047 // so the user can turn on data roaming.
sangyun35f23f82023-07-18 01:37:53 +09001048 if (!shownInThisNumeric && !shownForThisReason) {
1049 updateDataRoamingNotification(ROAMING_NOTIFICATION_DISCONNECTED);
1050 } else {
1051 // Don't show roaming notification if we've already shown for this MccMnc
1052 Log.d(LOG_TAG, "Skip roaming disconnected notification since already"
1053 + " shownInThisNumeric=" + shownInThisNumeric
1054 + " shownForThisReason=" + shownForThisReason);
1055 // Dismiss notification if the other notification is shown.
1056 if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
1057 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
1058 }
1059 }
1060 } else if (dataAllowed && dataIsNowRoaming) {
1061 if (!shownInThisNumeric && roamingNumeric != null) {
1062 mShownNotificationReasons.add(roamingNumericReason);
1063 }
1064 if (!shownForThisReason
1065 && reason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED) {
1066 mShownNotificationReasons.add(callingReason);
1067 }
Sarah Chin37b39072023-11-05 13:28:21 -08001068 boolean shouldShowRoamingNotification = shouldShowRoamingNotification(roamingNumeric);
sangyun35f23f82023-07-18 01:37:53 +09001069 // No need to show it again if we never cancelled it explicitly.
1070 if (getCurrentRoamingNotification() == ROAMING_NOTIFICATION_CONNECTED) {
Ling Ma4e15c322022-12-07 11:20:53 -08001071 return;
1072 }
sangyun35f23f82023-07-18 01:37:53 +09001073
1074 // Inform users that roaming charges may apply.
Sarah Chin37b39072023-11-05 13:28:21 -08001075 if (!shownInThisNumeric && !shownForThisReason && shouldShowRoamingNotification) {
sangyun35f23f82023-07-18 01:37:53 +09001076 updateDataRoamingNotification(ROAMING_NOTIFICATION_CONNECTED);
1077 } else {
1078 // Don't show roaming notification if we've already shown for this MccMnc or
1079 // disabled from carrier config.
1080 Log.d(LOG_TAG, "Skip roaming connected notification since already"
1081 + " shownInThisNumeric:" + shownInThisNumeric
1082 + " shownForThisReason:" + shownForThisReason
Sarah Chin37b39072023-11-05 13:28:21 -08001083 + " shouldShowRoamingNotification:" + shouldShowRoamingNotification);
sangyun35f23f82023-07-18 01:37:53 +09001084 // Dismiss notification if the other notification is shown.
1085 if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
1086 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
1087 }
1088 }
1089 } else if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
Jordan Liuff2ccd72019-07-23 15:54:41 -07001090 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
1091 // is not the only data disable reason. In this case we dismiss the notification we
1092 // showed earlier.
sangyun35f23f82023-07-18 01:37:53 +09001093 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
Jack Yu1a2fc352017-07-14 17:14:37 -07001094 }
1095 }
1096
sangyun35f23f82023-07-18 01:37:53 +09001097 private void updateDataRoamingNotification(@RoamingNotification int roamingNotification) {
1098 int event;
1099 switch (roamingNotification) {
1100 case ROAMING_NOTIFICATION_NO_NOTIFICATION:
1101 Log.d(LOG_TAG, "Dismiss roaming notification");
1102 mDataRoamingNotifLog.log("Hide roaming.");
1103 event = EVENT_DATA_ROAMING_OK;
1104 break;
1105 case ROAMING_NOTIFICATION_CONNECTED:
1106 Log.d(LOG_TAG, "Show roaming connected notification");
1107 mDataRoamingNotifLog.log("Show roaming on.");
1108 event = EVENT_DATA_ROAMING_CONNECTED;
1109 break;
1110 case ROAMING_NOTIFICATION_DISCONNECTED:
1111 Log.d(LOG_TAG, "Show roaming disconnected notification");
1112 mDataRoamingNotifLog.log("Show roaming off.");
1113 event = EVENT_DATA_ROAMING_DISCONNECTED;
1114 break;
1115 default:
1116 Log.d(LOG_TAG, "Should never reach here.");
1117 mDataRoamingNotifLog.log("Should never reach here.");
1118 return;
1119 }
1120 mCurrentRoamingNotification = roamingNotification;
1121 mHandler.obtainMessage(event, mDefaultDataSubId, 0).sendToTarget();
1122 }
1123
1124 private @RoamingNotification int getCurrentRoamingNotification() {
1125 return mCurrentRoamingNotification;
1126 }
1127
sangyun1c1918a2023-11-13 22:37:50 +09001128 // For reorganize_roaming_notification feature disabled.
1129 /**
1130 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
1131 * to notify the user so they can enable it through settings. Vise versa if the condition
1132 * changes, we need to dismiss the notification.
1133 * @param roamingOperatorNumeric The operator numeric for the current roaming. {@code null} if
1134 * the current roaming operator numeric didn't change.
1135 */
1136 private void updateDataRoamingStatusForFeatureDisabled(
1137 @Nullable String roamingOperatorNumeric) {
1138 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatusForFeatureDisabled");
1139 Phone phone = getPhone(mDefaultDataSubId);
1140 if (phone == null) {
1141 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
1142 return;
1143 }
1144
1145 boolean dataAllowed;
1146 boolean notAllowedDueToRoamingOff;
1147 List<DataDisallowedReason> reasons = phone.getDataNetworkController()
1148 .getInternetDataDisallowedReasons();
1149 dataAllowed = reasons.isEmpty();
1150 notAllowedDueToRoamingOff = (reasons.size() == 1
1151 && reasons.contains(DataDisallowedReason.ROAMING_DISABLED));
1152 mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons
1153 + ", roamingOperatorNumeric=" + roamingOperatorNumeric);
1154 if (VDBG) {
1155 Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons
1156 + ", roamingOperatorNumeric=" + roamingOperatorNumeric);
1157 }
1158
1159 if (!dataAllowed && notAllowedDueToRoamingOff) {
1160 // Don't show roaming notification if we've already shown for this MccMnc
1161 if (roamingOperatorNumeric != null
1162 && !mPrevRoamingOperatorNumerics.add(roamingOperatorNumeric)) {
1163 Log.d(LOG_TAG, "Skip roaming disconnected notification since already shown in "
1164 + "MccMnc " + roamingOperatorNumeric);
1165 return;
1166 }
1167 // No need to show it again if we never cancelled it explicitly.
1168 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_DISCONNECTED) return;
1169 // If the only reason of no data is data roaming disabled, then we notify the user
1170 // so the user can turn on data roaming.
1171 mPrevRoamingNotification = ROAMING_NOTIFICATION_DISCONNECTED;
1172 Log.d(LOG_TAG, "Show roaming disconnected notification");
1173 mDataRoamingNotifLog.log("Show roaming off.");
1174 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_DISCONNECTED);
1175 msg.arg1 = mDefaultDataSubId;
1176 msg.sendToTarget();
1177 } else if (dataAllowed && dataIsNowRoaming(mDefaultDataSubId)) {
Sarah Chin37b39072023-11-05 13:28:21 -08001178 if (!shouldShowRoamingNotification(roamingOperatorNumeric)) {
1179 Log.d(LOG_TAG, "Skip showing roaming connected notification.");
1180 return;
1181 }
sangyun1c1918a2023-11-13 22:37:50 +09001182 // Don't show roaming notification if we've already shown for this MccMnc
1183 if (roamingOperatorNumeric != null
1184 && !mPrevRoamingOperatorNumerics.add(roamingOperatorNumeric)) {
1185 Log.d(LOG_TAG, "Skip roaming connected notification since already shown in "
1186 + "MccMnc " + roamingOperatorNumeric);
1187 return;
1188 }
1189 // No need to show it again if we never cancelled it explicitly, or carrier config
1190 // indicates this is not needed.
1191 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_CONNECTED) return;
1192 mPrevRoamingNotification = ROAMING_NOTIFICATION_CONNECTED;
1193 Log.d(LOG_TAG, "Show roaming connected notification");
1194 mDataRoamingNotifLog.log("Show roaming on.");
1195 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_CONNECTED);
1196 msg.arg1 = mDefaultDataSubId;
1197 msg.sendToTarget();
1198 } else if (mPrevRoamingNotification != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
1199 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
1200 // is not the only data disable reason. In this case we dismiss the notification we
1201 // showed earlier.
1202 mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
1203 Log.d(LOG_TAG, "Dismiss roaming notification");
1204 mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed);
1205 mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
1206 }
1207 }
1208
Jordan Liuff2ccd72019-07-23 15:54:41 -07001209 /**
1210 *
1211 * @param subId to check roaming on
1212 * @return whether we have transitioned to dataRoaming
1213 */
1214 private boolean dataIsNowRoaming(int subId) {
Sarah Chine04784a2022-10-31 20:32:34 -07001215 return getPhone(subId).getServiceState().getDataRoaming();
Jordan Liuff2ccd72019-07-23 15:54:41 -07001216 }
1217
Sarah Chin37b39072023-11-05 13:28:21 -08001218 private boolean shouldShowRoamingNotification(String roamingNumeric) {
1219 PersistableBundle config = getCarrierConfigForSubId(mDefaultDataSubId);
1220 boolean showRoamingNotification = config.getBoolean(
1221 CarrierConfigManager.KEY_SHOW_DATA_CONNECTED_ROAMING_NOTIFICATION_BOOL);
1222
1223 if (TextUtils.isEmpty(roamingNumeric) || !mFeatureFlags.hideRoamingIcon()) {
1224 Log.d(LOG_TAG, "shouldShowRoamingNotification: roamingNumeric=" + roamingNumeric
1225 + ", hideRoaming=" + mFeatureFlags.hideRoamingIcon());
1226 return showRoamingNotification;
1227 }
1228
1229 String[] includedMccMncs = config.getStringArray(CarrierConfigManager
1230 .KEY_DATA_CONNECTED_ROAMING_NOTIFICATION_INCLUDED_MCC_MNCS_STRING_ARRAY);
1231 if (includedMccMncs != null) {
1232 for (String mccMnc : includedMccMncs) {
1233 if (roamingNumeric.equals(mccMnc)) {
1234 Log.d(LOG_TAG, "shouldShowRoamingNotification: show for MCC/MNC " + mccMnc);
1235 return showRoamingNotification;
1236 }
1237 }
1238 }
1239
1240 String[] excludedMccs = config.getStringArray(CarrierConfigManager
1241 .KEY_DATA_CONNECTED_ROAMING_NOTIFICATION_EXCLUDED_MCCS_STRING_ARRAY);
1242 String roamingMcc = roamingNumeric.length() < 3 ? "" : roamingNumeric.substring(0, 3);
1243 if (excludedMccs != null && !TextUtils.isEmpty(roamingMcc)) {
1244 for (String mcc : excludedMccs) {
1245 if (roamingMcc.equals(mcc)) {
1246 Log.d(LOG_TAG, "shouldShowRoamingNotification: ignore for MCC " + mcc);
1247 return false;
1248 }
1249 }
1250 }
1251
1252 if (showRoamingNotification) {
1253 Log.d(LOG_TAG, "shouldShowRoamingNotification: show for numeric " + roamingNumeric);
1254 }
1255 return showRoamingNotification;
1256 }
1257
chen xubaf9fe52019-07-02 17:28:24 -07001258 private void updateLimitedSimFunctionForDualSim() {
1259 if (DBG) Log.d(LOG_TAG, "updateLimitedSimFunctionForDualSim");
1260 // check conditions to display limited SIM function notification under dual SIM
1261 SubscriptionManager subMgr = (SubscriptionManager) getSystemService(
1262 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
1263 List<SubscriptionInfo> subList = subMgr.getActiveSubscriptionInfoList(false);
1264 if (subList != null && subList.size() > 1) {
1265 CarrierConfigManager configMgr = (CarrierConfigManager)
1266 getSystemService(Context.CARRIER_CONFIG_SERVICE);
1267 for (SubscriptionInfo info : subList) {
1268 PersistableBundle b = configMgr.getConfigForSubId(info.getSubscriptionId());
1269 if (b != null) {
1270 if (b.getBoolean(CarrierConfigManager
1271 .KEY_LIMITED_SIM_FUNCTION_NOTIFICATION_FOR_DSDS_BOOL)) {
1272 notificationMgr.showLimitedSimFunctionWarningNotification(
1273 info.getSubscriptionId(),
1274 info.getDisplayName().toString());
1275 } else {
1276 notificationMgr.dismissLimitedSimFunctionWarningNotification(
1277 info.getSubscriptionId());
1278 }
1279 }
1280 }
1281 } else {
1282 // cancel notifications for all subs
1283 notificationMgr.dismissLimitedSimFunctionWarningNotification(
1284 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1285 }
1286 notificationMgr.dismissLimitedSimFunctionWarningNotificationForInactiveSubs();
1287
1288 }
1289
Sandeep Kuntade73a6a2014-10-15 18:45:56 +05301290 public Phone getPhoneInEcm() {
1291 return phoneInEcm;
1292 }
1293
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001294 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -08001295 * Triggers a refresh of the message waiting (voicemail) indicator.
1296 *
1297 * @param subId the subscription id we should refresh the notification for.
1298 */
1299 public void refreshMwiIndicator(int subId) {
1300 notificationMgr.refreshMwi(subId);
1301 }
1302
1303 /**
Pengquan Mengdd9ac822018-09-20 15:25:35 -07001304 * Called when the network selection on the subscription {@code subId} is changed by the user.
1305 *
1306 * @param subId the subscription id.
1307 */
1308 public void onNetworkSelectionChanged(int subId) {
1309 Phone phone = getPhone(subId);
1310 if (phone != null) {
1311 notificationMgr.updateNetworkSelection(phone.getServiceState().getState(), subId);
1312 } else {
1313 Log.w(LOG_TAG, "onNetworkSelectionChanged on null phone, subId: " + subId);
1314 }
1315 }
1316
1317 /**
James.cf Lin4b784aa2021-01-31 03:25:15 +08001318 * @return whether the device supports RCS User Capability Exchange or not.
1319 */
1320 public boolean getDeviceUceEnabled() {
1321 return (mTelephonyRcsService == null) ? false : mTelephonyRcsService.isDeviceUceEnabled();
1322 }
1323
1324 /**
1325 * Set the device supports RCS User Capability Exchange.
1326 * @param isEnabled true if the device supports UCE.
1327 */
1328 public void setDeviceUceEnabled(boolean isEnabled) {
1329 if (mTelephonyRcsService != null) {
1330 mTelephonyRcsService.setDeviceUceEnabled(isEnabled);
1331 }
1332 }
1333
1334 /**
Jack Yu1a2fc352017-07-14 17:14:37 -07001335 * Dump the state of the object, add calls to other objects as desired.
1336 *
1337 * @param fd File descriptor
1338 * @param printWriter Print writer
1339 * @param args Arguments
1340 */
1341 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
1342 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
1343 pw.println("------- PhoneGlobals -------");
1344 pw.increaseIndent();
sangyun15019e02023-11-13 21:50:15 +09001345 pw.println("FeatureFlags:");
1346 pw.increaseIndent();
sangyun1c1918a2023-11-13 22:37:50 +09001347 pw.println("reorganizeRoamingNotification="
1348 + mFeatureFlags.reorganizeRoamingNotification());
sangyund5f37ab2023-11-13 22:52:28 +09001349 pw.println("dismissNetworkSelectionNotificationOnSimDisable="
1350 + mFeatureFlags.dismissNetworkSelectionNotificationOnSimDisable());
sangyun15019e02023-11-13 21:50:15 +09001351 pw.decreaseIndent();
sangyun1c1918a2023-11-13 22:37:50 +09001352 if (mFeatureFlags.reorganizeRoamingNotification()) {
1353 pw.println("mCurrentRoamingNotification=" + mCurrentRoamingNotification);
1354 } else {
1355 pw.println("mPrevRoamingNotification=" + mPrevRoamingNotification);
1356 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001357 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
Keun young Parkdebb8532019-05-30 16:35:27 -07001358 pw.println("isSmsCapable=" + TelephonyManager.from(this).isSmsCapable());
sangyun35f23f82023-07-18 01:37:53 +09001359 pw.println("mDataRoamingNotifLog:");
Jack Yu1a2fc352017-07-14 17:14:37 -07001360 pw.increaseIndent();
1361 mDataRoamingNotifLog.dump(fd, pw, args);
1362 pw.decreaseIndent();
Brad Ebinger05f52c22019-12-05 13:03:21 -08001363 pw.println("ImsResolver:");
1364 pw.increaseIndent();
1365 try {
Brad Ebingerd1947d82021-05-17 20:54:49 +00001366 if (ImsResolver.getInstance() != null) ImsResolver.getInstance().dump(fd, pw, args);
Brad Ebinger05f52c22019-12-05 13:03:21 -08001367 } catch (Exception e) {
1368 e.printStackTrace();
1369 }
1370 pw.decreaseIndent();
Brad Ebingera68a4972020-01-30 17:31:23 -08001371 pw.println("RcsService:");
1372 try {
1373 if (mTelephonyRcsService != null) mTelephonyRcsService.dump(fd, pw, args);
1374 } catch (Exception e) {
1375 e.printStackTrace();
1376 }
Hunsuk Choi89bd22c2021-11-01 13:04:54 +00001377 pw.println("ImsStateCallbackController:");
1378 try {
1379 if (mImsStateCallbackController != null) mImsStateCallbackController.dump(pw);
1380 } catch (Exception e) {
1381 e.printStackTrace();
1382 }
Hwangoo Parkba21cf22022-11-30 14:34:04 +00001383 pw.println("DomainSelectionResolver:");
1384 pw.increaseIndent();
1385 try {
1386 if (DomainSelectionResolver.getInstance() != null) {
1387 DomainSelectionResolver.getInstance().dump(fd, pw, args);
1388 }
1389 } catch (Exception e) {
1390 e.printStackTrace();
1391 }
1392 pw.decreaseIndent();
1393 if (mDomainSelectionService != null) {
1394 mDomainSelectionService.dump(fd, pw, args);
1395 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001396 pw.decreaseIndent();
sangyun1c1918a2023-11-13 22:37:50 +09001397 if (mFeatureFlags.reorganizeRoamingNotification()) {
1398 pw.println("mShownNotificationReasons=" + mShownNotificationReasons);
1399 } else {
1400 pw.println("mPrevRoamingOperatorNumerics:" + mPrevRoamingOperatorNumerics);
1401 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001402 pw.println("------- End PhoneGlobals -------");
1403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001404}