blob: 483a706d204f59d53e8402c9dc5b88c49903708b [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;
Ling Ma317906d2022-12-05 15:58:14 -080053import android.util.ArraySet;
Jack Yu1a2fc352017-07-14 17:14:37 -070054import android.util.LocalLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.util.Log;
Santos Cordone18902f2016-03-22 17:16:04 -070056import android.widget.Toast;
Ta-wei Yenb29425b2016-09-21 17:28:14 -070057
Brad Ebingere3ae65a2020-09-11 12:45:11 -070058import com.android.ims.ImsFeatureBinderRepository;
Siim Sammul182d61b2021-05-04 16:01:42 +010059import com.android.internal.os.BinderCallsStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import com.android.internal.telephony.CallManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070061import com.android.internal.telephony.IccCardConstants;
62import com.android.internal.telephony.MmiCode;
63import com.android.internal.telephony.Phone;
Sarah Chin072ffb22022-05-03 17:58:59 -070064import com.android.internal.telephony.PhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import com.android.internal.telephony.PhoneConstants;
66import com.android.internal.telephony.PhoneFactory;
Jack Yu1a2fc352017-07-14 17:14:37 -070067import com.android.internal.telephony.SettingsObserver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068import com.android.internal.telephony.TelephonyCapabilities;
Youming Ye47a6adc2018-11-19 15:33:36 -080069import com.android.internal.telephony.TelephonyComponentFactory;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070import com.android.internal.telephony.TelephonyIntents;
Jack Yu3e2ac6e2022-03-26 13:59:45 -070071import com.android.internal.telephony.data.DataEvaluation.DataDisallowedReason;
Hwangoo Parkba21cf22022-11-30 14:34:04 +000072import com.android.internal.telephony.domainselection.DomainSelectionResolver;
Daniel Bantab26e96f2022-10-19 23:25:35 +000073import com.android.internal.telephony.emergency.EmergencyStateTracker;
Thomas Nguyen090fb002023-09-11 17:35:30 -070074import com.android.internal.telephony.flags.FeatureFlags;
Ling Ma51dd3022023-08-29 11:46:38 -070075import com.android.internal.telephony.flags.FeatureFlagsImpl;
Brad Ebinger05f52c22019-12-05 13:03:21 -080076import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn92479152021-01-20 16:30:10 -080077import com.android.internal.telephony.imsphone.ImsPhone;
78import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000079import com.android.internal.telephony.satellite.SatelliteController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000080import com.android.internal.telephony.uicc.UiccPort;
Jordan Liu06bdef12021-03-24 17:25:46 -070081import com.android.internal.telephony.uicc.UiccProfile;
Jack Yu1a2fc352017-07-14 17:14:37 -070082import com.android.internal.util.IndentingPrintWriter;
Andrew Leefb7f92e2015-02-26 16:23:32 -080083import com.android.phone.settings.SettingsConstants;
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -070084import com.android.phone.vvm.CarrierVvmPackageInstalledReceiver;
Hwangoo Parkba21cf22022-11-30 14:34:04 +000085import com.android.services.telephony.domainselection.TelephonyDomainSelectionService;
James.cf Linc9f35a42020-01-15 02:35:22 +080086import com.android.services.telephony.rcs.TelephonyRcsService;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087
Jack Yu1a2fc352017-07-14 17:14:37 -070088import java.io.FileDescriptor;
89import java.io.PrintWriter;
Jordan Liuff2ccd72019-07-23 15:54:41 -070090import java.lang.annotation.Retention;
91import java.lang.annotation.RetentionPolicy;
chen xubaf9fe52019-07-02 17:28:24 -070092import java.util.List;
Jack Yu1a2fc352017-07-14 17:14:37 -070093
Santos Cordon7d4ddf62013-07-10 11:58:08 -070094/**
95 * Global state for the telephony subsystem when running in the primary
96 * phone process.
97 */
Sailesh Nepalbf900542014-07-15 16:18:32 -070098public class PhoneGlobals extends ContextWrapper {
Jack Yu1a2fc352017-07-14 17:14:37 -070099 public static final String LOG_TAG = "PhoneGlobals";
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700100
101 /**
102 * Phone app-wide debug level:
103 * 0 - no debug logging
104 * 1 - normal debug logging if ro.debuggable is set (which is true in
105 * "eng" and "userdebug" builds but not "user" builds)
106 * 2 - ultra-verbose debug logging
107 *
108 * Most individual classes in the phone app have a local DBG constant,
109 * typically set to
110 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
111 * or else
112 * (PhoneApp.DBG_LEVEL >= 2)
113 * depending on the desired verbosity.
114 *
115 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
116 */
Andrew Lee88b51e22014-10-29 15:48:51 -0700117 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118
119 private static final boolean DBG =
120 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
121 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
122
123 // Message codes; see mHandler below.
124 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700125 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
Jordan Liuff2ccd72019-07-23 15:54:41 -0700127 private static final int EVENT_DATA_ROAMING_CONNECTED = 11;
128 private static final int EVENT_DATA_ROAMING_OK = 12;
129 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 13;
Jordan Liuff2ccd72019-07-23 15:54:41 -0700130 private static final int EVENT_DATA_ROAMING_SETTINGS_CHANGED = 15;
131 private static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED = 16;
Lei Liu863eac02020-06-24 20:12:55 +0800132 private static final int EVENT_CARRIER_CONFIG_CHANGED = 17;
Sarah Chin072ffb22022-05-03 17:58:59 -0700133 private static final int EVENT_MULTI_SIM_CONFIG_CHANGED = 18;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134
135 // The MMI codes are also used by the InCallScreen.
136 public static final int MMI_INITIATE = 51;
137 public static final int MMI_COMPLETE = 52;
138 public static final int MMI_CANCEL = 53;
139 // Don't use message codes larger than 99 here; those are reserved for
140 // the individual Activities of the Phone UI.
141
Santos Cordone18902f2016-03-22 17:16:04 -0700142 public static final int AIRPLANE_ON = 1;
143 public static final int AIRPLANE_OFF = 0;
144
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700145 /**
146 * Allowable values for the wake lock code.
147 * SLEEP means the device can be put to sleep.
148 * PARTIAL means wake the processor, but we display can be kept off.
149 * FULL means wake both the processor and the display.
150 */
151 public enum WakeState {
152 SLEEP,
153 PARTIAL,
154 FULL
155 }
156
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157 private static PhoneGlobals sMe;
158
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700160 CallNotifier notifier;
Santos Cordon63a84242013-07-23 13:32:52 -0700161 NotificationMgr notificationMgr;
James.cf Linc9f35a42020-01-15 02:35:22 +0800162 TelephonyRcsService mTelephonyRcsService;
Andrew Lee9431b832015-03-09 18:46:45 -0700163 public PhoneInterfaceManager phoneMgr;
James.cf Linaf3183c2019-10-24 00:59:00 +0800164 public ImsRcsController imsRcsController;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000165 public ImsStateCallbackController mImsStateCallbackController;
joonhunshincffb7fc2021-11-28 07:32:01 +0000166 public ImsProvisioningController mImsProvisioningController;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800167 CarrierConfigLoader configLoader;
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000168 TelephonyDomainSelectionService mDomainSelectionService;
Santos Cordon63a84242013-07-23 13:32:52 -0700169
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530170 private Phone phoneInEcm;
Santos Cordon63a84242013-07-23 13:32:52 -0700171
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172 static boolean sVoiceCapable = true;
173
Santos Cordonc593d002015-06-03 15:41:15 -0700174 // TODO: Remove, no longer used.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700175 CdmaPhoneCallState cdmaPhoneCallState;
176
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700177 // The currently-active PUK entry activity and progress dialog.
178 // Normally, these are the Emergency Dialer and the subsequent
179 // progress dialog. null if there is are no such objects in
180 // the foreground.
181 private Activity mPUKEntryActivity;
182 private ProgressDialog mPUKEntryProgressDialog;
183
Jordan Liuff2ccd72019-07-23 15:54:41 -0700184 /** @hide */
185 @Retention(RetentionPolicy.SOURCE)
sangyun35f23f82023-07-18 01:37:53 +0900186 @IntDef(prefix = {"ROAMING_NOTIFICATION_REASON_"},
187 value = {
188 ROAMING_NOTIFICATION_REASON_DATA_SETTING_CHANGED,
189 ROAMING_NOTIFICATION_REASON_DATA_ROAMING_SETTING_CHANGED,
190 ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED,
191 ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED,
192 ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED})
193 public @interface RoamingNotificationReason {}
194 private static final int ROAMING_NOTIFICATION_REASON_DATA_SETTING_CHANGED = 0;
195 private static final int ROAMING_NOTIFICATION_REASON_DATA_ROAMING_SETTING_CHANGED = 1;
196 private static final int ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED = 2;
197 private static final int ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED = 3;
198 private static final int ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED = 4;
199
200 /** @hide */
201 @Retention(RetentionPolicy.SOURCE)
Jordan Liuff2ccd72019-07-23 15:54:41 -0700202 @IntDef(prefix = {"ROAMING_NOTIFICATION_"},
203 value = {
204 ROAMING_NOTIFICATION_NO_NOTIFICATION,
205 ROAMING_NOTIFICATION_CONNECTED,
206 ROAMING_NOTIFICATION_DISCONNECTED})
207 public @interface RoamingNotification {}
208
209 private static final int ROAMING_NOTIFICATION_NO_NOTIFICATION = 0;
210 private static final int ROAMING_NOTIFICATION_CONNECTED = 1;
211 private static final int ROAMING_NOTIFICATION_DISCONNECTED = 2;
212
213 @RoamingNotification
sangyun35f23f82023-07-18 01:37:53 +0900214 private int mCurrentRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
Jack Yu953f9352017-05-18 14:41:06 -0700215
sangyun35f23f82023-07-18 01:37:53 +0900216 /**
217 * Reasons that have already shown notification to prevent duplicate shows for the same reason.
218 */
219 private ArraySet<String> mShownNotificationReasons = new ArraySet<>();
Ling Ma317906d2022-12-05 15:58:14 -0800220
sangyun1c1918a2023-11-13 22:37:50 +0900221 // For reorganize_roaming_notification feature disabled.
222 @RoamingNotification
223 private int mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
224
225 // For reorganize_roaming_notification feature disabled.
226 /** Operator numerics for which we've shown is-roaming notifications. **/
227 private ArraySet<String> mPrevRoamingOperatorNumerics = new ArraySet<>();
228
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700229 private WakeState mWakeState = WakeState.SLEEP;
230
231 private PowerManager mPowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700232 private PowerManager.WakeLock mWakeLock;
233 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700234 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700235
Jack Yu1a2fc352017-07-14 17:14:37 -0700236 private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
237 private final LocalLog mDataRoamingNotifLog = new LocalLog(50);
238
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700239 // Broadcast receiver for various intent broadcasts (see onCreate())
240 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
241
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700242 private final CarrierVvmPackageInstalledReceiver mCarrierVvmPackageInstalledReceiver =
243 new CarrierVvmPackageInstalledReceiver();
244
Jack Yu1a2fc352017-07-14 17:14:37 -0700245 private final SettingsObserver mSettingsObserver;
Siim Sammul182d61b2021-05-04 16:01:42 +0100246 private BinderCallsStats.SettingsObserver mBinderCallsSettingsObserver;
Jack Yu1a2fc352017-07-14 17:14:37 -0700247
Sarah Chin072ffb22022-05-03 17:58:59 -0700248 // Mapping of phone ID to the associated TelephonyCallback. These should be registered without
249 // fine or coarse location since we only use ServiceState for
250 private PhoneAppCallback[] mTelephonyCallbacks;
251
sangyun15019e02023-11-13 21:50:15 +0900252 private FeatureFlags mFeatureFlags;
253
Sarah Chin072ffb22022-05-03 17:58:59 -0700254 private class PhoneAppCallback extends TelephonyCallback implements
255 TelephonyCallback.ServiceStateListener {
256 private final int mSubId;
257
258 PhoneAppCallback(int subId) {
259 mSubId = subId;
260 }
261
262 @Override
263 public void onServiceStateChanged(ServiceState serviceState) {
264 // Note when registering that we should be registering with INCLUDE_LOCATION_DATA_NONE.
265 // PhoneGlobals only uses the state and roaming status, which does not require location.
266 handleServiceStateChanged(serviceState, mSubId);
267 }
268
269 public int getSubId() {
270 return mSubId;
271 }
272 }
273
Nazish Tabassum160d2112019-12-23 17:31:33 +0530274 private static class EventSimStateChangedBag {
275 final int mPhoneId;
276 final String mIccStatus;
277
278 EventSimStateChangedBag(int phoneId, String iccStatus) {
279 mPhoneId = phoneId;
280 mIccStatus = iccStatus;
281 }
282 }
283
Jordan Liu06bdef12021-03-24 17:25:46 -0700284 // Some carrier config settings disable the network lock screen, so we call handleSimLock
285 // when either SIM_LOCK or CARRIER_CONFIG changes so that no matter which one happens first,
286 // we still do the right thing
287 private void handleSimLock(int subType, Phone phone) {
288 PersistableBundle cc = getCarrierConfigForSubId(phone.getSubId());
289 if (!CarrierConfigManager.isConfigForIdentifiedCarrier(cc)) {
290 // If we only have the default carrier config just return, to avoid popping up the
291 // the SIM lock screen when it's disabled by the carrier.
292 Log.i(LOG_TAG, "Not showing 'SIM network unlock' screen. Carrier config not loaded");
293 return;
294 }
295 if (cc.getBoolean(CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
296 // Some products don't have the concept of a "SIM network lock"
297 Log.i(LOG_TAG, "Not showing 'SIM network unlock' screen. Disabled by carrier config");
298 return;
299 }
300
301 // if passed in subType is unknown, retrieve it here.
302 if (subType == -1) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000303 final UiccPort uiccPort = phone.getUiccPort();
304 if (uiccPort == null) {
Jordan Liu06bdef12021-03-24 17:25:46 -0700305 Log.e(LOG_TAG,
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000306 "handleSimLock: uiccPort for phone " + phone.getPhoneId() + " is null");
Jordan Liu06bdef12021-03-24 17:25:46 -0700307 return;
308 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000309 final UiccProfile uiccProfile = uiccPort.getUiccProfile();
Jordan Liu06bdef12021-03-24 17:25:46 -0700310 if (uiccProfile == null) {
311 Log.e(LOG_TAG,
312 "handleSimLock: uiccProfile for phone " + phone.getPhoneId() + " is null");
313 return;
314 }
315 subType = uiccProfile.getApplication(
316 uiccProfile.mCurrentAppType).getPersoSubState().ordinal();
317 }
318 // Normal case: show the "SIM network unlock" PIN entry screen.
319 // The user won't be able to do anything else until
320 // they enter a valid SIM network PIN.
321 Log.i(LOG_TAG, "show sim depersonal panel");
322 IccNetworkDepersonalizationPanel.showDialog(phone, subType);
323 }
324
325 private boolean isSimLocked(Phone phone) {
326 TelephonyManager tm = getSystemService(TelephonyManager.class);
327 return tm.createForSubscriptionId(phone.getSubId()).getSimState()
328 == TelephonyManager.SIM_STATE_NETWORK_LOCKED;
329 }
330
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700331 Handler mHandler = new Handler() {
332 @Override
333 public void handleMessage(Message msg) {
334 PhoneConstants.State phoneState;
Jack Yu1a2fc352017-07-14 17:14:37 -0700335 if (VDBG) Log.v(LOG_TAG, "event=" + msg.what);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700336 switch (msg.what) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700337 // TODO: This event should be handled by the lock screen, just
338 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
339 case EVENT_SIM_NETWORK_LOCKED:
Jordan Liu06bdef12021-03-24 17:25:46 -0700340 int subType = (Integer) ((AsyncResult) msg.obj).result;
341 Phone phone = (Phone) ((AsyncResult) msg.obj).userObj;
342 handleSimLock(subType, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343 break;
344
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700345 case EVENT_DATA_ROAMING_DISCONNECTED:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700346 notificationMgr.showDataRoamingNotification(msg.arg1, false);
347 break;
348
349 case EVENT_DATA_ROAMING_CONNECTED:
350 notificationMgr.showDataRoamingNotification(msg.arg1, true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700351 break;
352
353 case EVENT_DATA_ROAMING_OK:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700354 notificationMgr.hideDataRoamingNotification();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355 break;
356
357 case MMI_COMPLETE:
358 onMMIComplete((AsyncResult) msg.obj);
359 break;
360
361 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800362 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700363 break;
364
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365 case EVENT_SIM_STATE_CHANGED:
Nazish Tabassum160d2112019-12-23 17:31:33 +0530366 EventSimStateChangedBag bag = (EventSimStateChangedBag)msg.obj;
Sarah Chin010884c2023-06-14 15:55:08 -0700367 // Dismiss the "No services" notification if the SIM is removed.
368 if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(bag.mIccStatus)) {
369 notificationMgr.dismissNetworkSelectionNotificationForInactiveSubId();
370 }
371
372 // Marks the event where the SIM goes into ready state.
373 // Right now, this is only used for the PUK-unlocking process.
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700374 if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(bag.mIccStatus)
Nazish Tabassum59126a92020-07-03 21:44:49 +0530375 || IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(bag.mIccStatus)
376 || IccCardConstants.INTENT_VALUE_ICC_NOT_READY.equals(bag.mIccStatus)
377 || IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(bag.mIccStatus)) {
Sarah Chin010884c2023-06-14 15:55:08 -0700378 // When the right event is triggered and there are UI objects in the
379 // foreground, we close them to display the lock panel.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380 if (mPUKEntryActivity != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700381 Log.i(LOG_TAG, "Dismiss puk entry activity");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382 mPUKEntryActivity.finish();
383 mPUKEntryActivity = null;
384 }
385 if (mPUKEntryProgressDialog != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700386 Log.i(LOG_TAG, "Dismiss puk progress dialog");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700387 mPUKEntryProgressDialog.dismiss();
388 mPUKEntryProgressDialog = null;
389 }
Nazish Tabassum59126a92020-07-03 21:44:49 +0530390 Log.i(LOG_TAG, "Dismissing depersonal panel" + (bag.mIccStatus));
Nazish Tabassum160d2112019-12-23 17:31:33 +0530391 IccNetworkDepersonalizationPanel.dialogDismiss(bag.mPhoneId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700392 }
393 break;
394
395 case EVENT_UNSOL_CDMA_INFO_RECORD:
396 //TODO: handle message here;
397 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700398 case EVENT_DATA_ROAMING_SETTINGS_CHANGED:
sangyun1c1918a2023-11-13 22:37:50 +0900399 if (mFeatureFlags.reorganizeRoamingNotification()) {
400 updateDataRoamingStatus(
401 ROAMING_NOTIFICATION_REASON_DATA_ROAMING_SETTING_CHANGED);
402 } else {
403 updateDataRoamingStatusForFeatureDisabled(null);
404 }
sangyun35f23f82023-07-18 01:37:53 +0900405 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700406 case EVENT_MOBILE_DATA_SETTINGS_CHANGED:
sangyun1c1918a2023-11-13 22:37:50 +0900407 if (mFeatureFlags.reorganizeRoamingNotification()) {
408 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_DATA_SETTING_CHANGED);
409 } else {
410 updateDataRoamingStatusForFeatureDisabled(null);
411 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700412 break;
Lei Liu863eac02020-06-24 20:12:55 +0800413 case EVENT_CARRIER_CONFIG_CHANGED:
414 int subId = (Integer) msg.obj;
415 // The voicemail number could be overridden by carrier config, so need to
416 // refresh the message waiting (voicemail) indicator.
417 refreshMwiIndicator(subId);
Jordan Liu06bdef12021-03-24 17:25:46 -0700418 phone = getPhone(subId);
Sarah Chin072ffb22022-05-03 17:58:59 -0700419 if (phone != null) {
420 if (isSimLocked(phone)) {
421 // pass in subType=-1 so handleSimLock can find the actual subType if
422 // needed. This is safe as valid values for subType are >= 0
423 handleSimLock(-1, phone);
424 }
425 TelephonyManager tm = getSystemService(TelephonyManager.class);
426 PhoneAppCallback callback = mTelephonyCallbacks[phone.getPhoneId()];
427 // TODO: We may need to figure out a way to unregister if subId is invalid
428 tm.createForSubscriptionId(callback.getSubId())
429 .unregisterTelephonyCallback(callback);
430 callback = new PhoneAppCallback(subId);
431 tm.createForSubscriptionId(subId).registerTelephonyCallback(
Ling Ma317906d2022-12-05 15:58:14 -0800432 TelephonyManager.INCLUDE_LOCATION_DATA_COARSE, mHandler::post,
Sarah Chin072ffb22022-05-03 17:58:59 -0700433 callback);
434 mTelephonyCallbacks[phone.getPhoneId()] = callback;
435 }
436 break;
437 case EVENT_MULTI_SIM_CONFIG_CHANGED:
438 int activeModems = (int) ((AsyncResult) msg.obj).result;
439 TelephonyManager tm = getSystemService(TelephonyManager.class);
440 // Unregister all previous callbacks
441 for (int phoneId = 0; phoneId < mTelephonyCallbacks.length; phoneId++) {
442 PhoneAppCallback callback = mTelephonyCallbacks[phoneId];
443 if (callback != null) {
444 tm.createForSubscriptionId(callback.getSubId())
445 .unregisterTelephonyCallback(callback);
446 mTelephonyCallbacks[phoneId] = null;
447 }
448 }
449 // Register callbacks for all active modems
450 for (int phoneId = 0; phoneId < activeModems; phoneId++) {
451 int sub = PhoneFactory.getPhone(phoneId).getSubId();
452 PhoneAppCallback callback = new PhoneAppCallback(sub);
453 tm.createForSubscriptionId(sub).registerTelephonyCallback(
454 TelephonyManager.INCLUDE_LOCATION_DATA_NONE, mHandler::post,
455 callback);
456 mTelephonyCallbacks[phoneId] = callback;
Jordan Liu06bdef12021-03-24 17:25:46 -0700457 }
Lei Liu863eac02020-06-24 20:12:55 +0800458 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700459 }
460 }
461 };
462
463 public PhoneGlobals(Context context) {
464 super(context);
465 sMe = this;
Jack Yu1a2fc352017-07-14 17:14:37 -0700466 mSettingsObserver = new SettingsObserver(context, mHandler);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700467 }
468
469 public void onCreate() {
470 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
471
472 ContentResolver resolver = getContentResolver();
473
Hall Liuaa4211e2021-01-20 15:43:39 -0800474 // Initialize the shim from frameworks/opt/telephony into packages/services/Telephony.
475 TelephonyLocalConnection.setInstance(new LocalConnectionImpl(this));
476
Sarah Chin072ffb22022-05-03 17:58:59 -0700477 TelephonyManager tm = getSystemService(TelephonyManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700478 // Cache the "voice capable" flag.
479 // This flag currently comes from a resource (which is
480 // overrideable on a per-product basis):
Sarah Chin072ffb22022-05-03 17:58:59 -0700481 sVoiceCapable = tm.isVoiceCapable();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700482 // ...but this might eventually become a PackageManager "system
483 // feature" instead, in which case we'd do something like:
484 // sVoiceCapable =
485 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
486
Stuart Scottdcf40a92014-12-09 10:45:01 -0800487 if (mCM == null) {
Nathan Haroldf9df6ea2019-03-08 11:54:22 -0800488 // Initialize AnomalyReporter early so that it can be used
489 AnomalyReporter.initialize(this);
Nathan Harold0db5c5e2019-01-22 20:18:56 -0800490
Youming Ye47a6adc2018-11-19 15:33:36 -0800491 // Inject telephony component factory if configured using other jars.
492 XmlResourceParser parser = getResources().getXml(R.xml.telephony_injection);
493 TelephonyComponentFactory.getInstance().injectTheComponentFactory(parser);
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000494
495 // Create DomainSelectionResolver always, but it MUST be initialized only when
496 // the device supports AOSP domain selection architecture and
497 // has new IRadio that supports its related HAL APIs.
498 DomainSelectionResolver.make(this,
499 getResources().getBoolean(R.bool.config_enable_aosp_domain_selection));
500
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700501 // Initialize the telephony framework
sangyun15019e02023-11-13 21:50:15 +0900502 mFeatureFlags = new FeatureFlagsImpl();
503 PhoneFactory.makeDefaultPhones(this, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700504
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000505 // Initialize the DomainSelectionResolver after creating the Phone instance
506 // to check the Radio HAL version.
507 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
508 mDomainSelectionService = new TelephonyDomainSelectionService(this);
509 DomainSelectionResolver.getInstance().initialize(mDomainSelectionService);
Daniel Bantab26e96f2022-10-19 23:25:35 +0000510 // Initialize EmergencyStateTracker if domain selection is supported
511 boolean isSuplDdsSwitchRequiredForEmergencyCall = getResources()
512 .getBoolean(R.bool.config_gnss_supl_requires_default_data_for_emergency);
513 EmergencyStateTracker.make(this, isSuplDdsSwitchRequiredForEmergencyCall);
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000514 }
515
Brad Ebinger05f52c22019-12-05 13:03:21 -0800516 // Only bring up ImsResolver if the device supports having an IMS stack.
517 if (getPackageManager().hasSystemFeature(
518 PackageManager.FEATURE_TELEPHONY_IMS)) {
519 // Get the package name of the default IMS implementation.
520 String defaultImsMmtelPackage = getResources().getString(
521 R.string.config_ims_mmtel_package);
522 String defaultImsRcsPackage = getResources().getString(
523 R.string.config_ims_rcs_package);
Brad Ebingerd1947d82021-05-17 20:54:49 +0000524 ImsResolver.make(this, defaultImsMmtelPackage,
Brad Ebingere3ae65a2020-09-11 12:45:11 -0700525 defaultImsRcsPackage, PhoneFactory.getPhones().length,
526 new ImsFeatureBinderRepository());
Brad Ebingerd1947d82021-05-17 20:54:49 +0000527 ImsResolver.getInstance().initialize();
Tyler Gunn92479152021-01-20 16:30:10 -0800528
529 // With the IMS phone created, load static config.xml values from the phone process
530 // so that it can be provided to the ImsPhoneCallTracker.
531 for (Phone p : PhoneFactory.getPhones()) {
532 Phone imsPhone = p.getImsPhone();
533 if (imsPhone != null && imsPhone instanceof ImsPhone) {
534 ImsPhone theImsPhone = (ImsPhone) imsPhone;
535 if (theImsPhone.getCallTracker() instanceof ImsPhoneCallTracker) {
536 ImsPhoneCallTracker ict = (ImsPhoneCallTracker)
537 theImsPhone.getCallTracker();
538
539 ImsPhoneCallTracker.Config config = new ImsPhoneCallTracker.Config();
540 config.isD2DCommunicationSupported = getResources().getBoolean(
541 R.bool.config_use_device_to_device_communication);
542 ict.setConfig(config);
543 }
544 }
545 }
Hui Wang068ab862020-10-31 05:12:53 +0000546 RcsProvisioningMonitor.make(this);
Brad Ebinger05f52c22019-12-05 13:03:21 -0800547 }
548
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700549 // Start TelephonyDebugService After the default phone is created.
550 Intent intent = new Intent(this, TelephonyDebugService.class);
551 startService(intent);
552
553 mCM = CallManager.getInstance();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700554
555 // Create the NotificationMgr singleton, which is used to display
556 // status bar icons and control other status bar behavior.
557 notificationMgr = NotificationMgr.init(this);
558
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000559 // Create the SatelliteController singleton, which acts as a backend service for
560 // {@link android.telephony.satellite.SatelliteManager}.
sangyun15019e02023-11-13 21:50:15 +0900561 SatelliteController.make(this, mFeatureFlags);
Sarah Chin5f57c582023-02-14 04:16:10 -0800562
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700563 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
564 cdmaPhoneCallState = new CdmaPhoneCallState();
565 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700566
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700567 // before registering for phone state changes
568 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
569 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
570 // lock used to keep the processor awake, when we don't care for the display.
571 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
572 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700573
574 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
575
sangyun15019e02023-11-13 21:50:15 +0900576 phoneMgr = PhoneInterfaceManager.init(this, mFeatureFlags);
Santos Cordon406c0342013-08-28 00:07:47 -0700577
James.cf Linaf3183c2019-10-24 00:59:00 +0800578 imsRcsController = ImsRcsController.init(this);
579
Brad Ebinger6c53e7f2023-01-27 16:26:44 -0800580 configLoader = CarrierConfigLoader.init(this);
581
James.cf Linc9f35a42020-01-15 02:35:22 +0800582 if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000583 mImsStateCallbackController =
584 ImsStateCallbackController.make(this, PhoneFactory.getPhones().length);
Brad Ebingera68a4972020-01-30 17:31:23 -0800585 mTelephonyRcsService = new TelephonyRcsService(this,
586 PhoneFactory.getPhones().length);
587 mTelephonyRcsService.initialize();
James.cf Linc9f35a42020-01-15 02:35:22 +0800588 imsRcsController.setRcsService(mTelephonyRcsService);
joonhunshincffb7fc2021-11-28 07:32:01 +0000589 mImsProvisioningController =
590 ImsProvisioningController.make(this, PhoneFactory.getPhones().length);
James.cf Linc9f35a42020-01-15 02:35:22 +0800591 }
592
Jack Yu1a2fc352017-07-14 17:14:37 -0700593 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700594 // asynchronous events from the telephony layer (like
595 // launching the incoming-call UI when an incoming call comes
596 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800597 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700598
Stuart Scottdcf40a92014-12-09 10:45:01 -0800599 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700600
601 // register for MMI/USSD
602 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
603
Qiong Liucc3fe812019-09-23 15:25:44 +0800604 // Initialize cell status using current airplane mode.
Taesu Lee62f826d2020-08-10 16:01:18 +0900605 handleAirplaneModeChange(
606 Settings.Global.getInt(
607 getContentResolver(),
608 Settings.Global.AIRPLANE_MODE_ON,
609 AIRPLANE_OFF)
610 == AIRPLANE_ON);
Qiong Liucc3fe812019-09-23 15:25:44 +0800611
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700612 // Register for misc other intent broadcasts.
613 IntentFilter intentFilter =
614 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700615 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
616 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700617 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700618 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
619 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700620 registerReceiver(mReceiver, intentFilter);
sangyun15019e02023-11-13 21:50:15 +0900621 if (mFeatureFlags.loadDdsOnCreate()) {
622 int defaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
623 if (SubscriptionManager.isValidSubscriptionId(defaultDataSubId)) {
624 if (VDBG) {
625 Log.v(LOG_TAG, "Loaded initial default data sub: " + defaultDataSubId);
626 }
627 mDefaultDataSubId = defaultDataSubId;
628 registerSettingsObserver();
629 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED);
630 }
sangyundce559b2023-09-11 10:25:55 +0900631 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700632
Sarah Chin072ffb22022-05-03 17:58:59 -0700633 PhoneConfigurationManager.registerForMultiSimConfigChange(
634 mHandler, EVENT_MULTI_SIM_CONFIG_CHANGED, null);
635
636 mTelephonyCallbacks = new PhoneAppCallback[tm.getSupportedModemCount()];
Fangyuan Li7f5c2752022-06-29 18:02:31 +0800637 if (tm.getSupportedModemCount() > 0) {
638 for (Phone phone : PhoneFactory.getPhones()) {
639 int subId = phone.getSubId();
640 PhoneAppCallback callback = new PhoneAppCallback(subId);
641 tm.createForSubscriptionId(subId).registerTelephonyCallback(
642 TelephonyManager.INCLUDE_LOCATION_DATA_NONE, mHandler::post, callback);
643 mTelephonyCallbacks[phone.getPhoneId()] = callback;
644 }
Sarah Chin072ffb22022-05-03 17:58:59 -0700645 }
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700646 mCarrierVvmPackageInstalledReceiver.register(this);
647
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700648 //set the default values for the preferences in the phone.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700649 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700650 }
651
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700652 // XXX pre-load the SimProvider so that it's ready
653 resolver.getType(Uri.parse("content://icc/adn"));
654
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700655 // TODO: Register for Cdma Information Records
656 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
657
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700658 // Read HAC settings and configure audio hardware
659 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800660 int hac = android.provider.Settings.System.getInt(
661 getContentResolver(),
662 android.provider.Settings.System.HEARING_AID,
663 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700664 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Jordan Liuf71aeef2019-08-21 11:46:09 -0700665 audioManager.setParameters(
666 SettingsConstants.HAC_KEY + "=" + (hac == SettingsConstants.HAC_ENABLED
667 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700668 }
Siim Sammul182d61b2021-05-04 16:01:42 +0100669
670 // Start tracking Binder latency for the phone process.
671 mBinderCallsSettingsObserver = new BinderCallsStats.SettingsObserver(
672 getApplicationContext(),
Siim Sammula6950092021-06-22 17:14:03 +0100673 new BinderCallsStats(
674 new BinderCallsStats.Injector(),
675 com.android.internal.os.BinderLatencyProto.Dims.TELEPHONY));
Santos Cordonff506f52013-11-21 19:13:19 -0800676 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700677
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700678 /**
679 * Returns the singleton instance of the PhoneApp.
680 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800681 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700682 if (sMe == null) {
683 throw new IllegalStateException("No PhoneGlobals here!");
684 }
685 return sMe;
686 }
687
688 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800689 * Returns the default phone.
690 *
Andrew Lee385019f2014-11-24 14:19:50 -0800691 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700692 */
Andrew Lee83383e42014-10-31 12:42:28 -0700693 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800694 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700695 }
696
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800697 public static Phone getPhone(int subId) {
698 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800699 }
700
Santos Cordonde10b752013-09-19 04:11:33 -0700701 /* package */ CallManager getCallManager() {
702 return mCM;
703 }
704
Chris Manton4e9fa912015-06-19 11:26:57 -0700705 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800706 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700707 }
708
Chris Manton4e9fa912015-06-19 11:26:57 -0700709 public PersistableBundle getCarrierConfigForSubId(int subId) {
Philip P. Moltmann0079aae2020-03-05 16:24:02 -0800710 return configLoader.getConfigForSubIdWithFeature(subId, getOpPackageName(),
711 getAttributionTag());
Junda Liu605148f2015-04-28 15:23:40 -0700712 }
713
Jack Yu1a2fc352017-07-14 17:14:37 -0700714 private void registerSettingsObserver() {
715 mSettingsObserver.unobserve();
716 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
717 String mobileDataSetting = Settings.Global.MOBILE_DATA;
718 if (TelephonyManager.getDefault().getSimCount() > 1) {
719 int subId = mDefaultDataSubId;
720 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
721 dataRoamingSetting += subId;
722 mobileDataSetting += subId;
723 }
724 }
725
726 // Listen for user data roaming setting changed event
727 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
728 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
729
730 // Listen for mobile data setting changed event
731 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
732 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
733 }
734
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700735 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700736 * Sets the activity responsible for un-PUK-blocking the device
737 * so that we may close it when we receive a positive result.
738 * mPUKEntryActivity is also used to indicate to the device that
739 * we are trying to un-PUK-lock the phone. In other words, iff
740 * it is NOT null, then we are trying to unlock and waiting for
741 * the SIM to move to READY state.
742 *
743 * @param activity is the activity to close when PUK has
744 * finished unlocking. Can be set to null to indicate the unlock
745 * or SIM READYing process is over.
746 */
747 void setPukEntryActivity(Activity activity) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700748 Log.i(LOG_TAG, "setPukEntryActivity - set to " + (activity == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700749 mPUKEntryActivity = activity;
750 }
751
752 Activity getPUKEntryActivity() {
753 return mPUKEntryActivity;
754 }
755
756 /**
757 * Sets the dialog responsible for notifying the user of un-PUK-
758 * blocking - SIM READYing progress, so that we may dismiss it
759 * when we receive a positive result.
760 *
761 * @param dialog indicates the progress dialog informing the user
762 * of the state of the device. Dismissed upon completion of
763 * READYing process
764 */
765 void setPukEntryProgressDialog(ProgressDialog dialog) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700766 Log.i(LOG_TAG, "setPukEntryProgressDialog - set to "
767 + (dialog == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700768 mPUKEntryProgressDialog = dialog;
769 }
770
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700771 KeyguardManager getKeyguardManager() {
772 return mKeyguardManager;
773 }
774
775 private void onMMIComplete(AsyncResult r) {
776 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
777 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800778 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700779 }
780
fionaxu80126972017-02-01 17:01:26 -0800781 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700782 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700783 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700784 }
785
Taesu Lee62f826d2020-08-10 16:01:18 +0900786 private void handleAirplaneModeChange(boolean isAirplaneNewlyOn) {
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700787 Log.i(LOG_TAG, "handleAirplaneModeChange: isAirplaneNewlyOn=" + isAirplaneNewlyOn);
Taesu Lee62f826d2020-08-10 16:01:18 +0900788 int cellState =
789 Settings.Global.getInt(
790 getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
Chris Mantona09f3632016-02-09 14:48:42 -0800791 switch (cellState) {
792 case PhoneConstants.CELL_OFF_FLAG:
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700793 // Airplane mode does not affect the cell radio if user has turned it off.
794 Log.i(LOG_TAG, "Ignore airplane mode change due to cell off.");
Chris Mantona09f3632016-02-09 14:48:42 -0800795 break;
796 case PhoneConstants.CELL_ON_FLAG:
Taesu Lee62f826d2020-08-10 16:01:18 +0900797 maybeTurnCellOff(isAirplaneNewlyOn);
Chris Mantona09f3632016-02-09 14:48:42 -0800798 break;
799 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
Taesu Lee62f826d2020-08-10 16:01:18 +0900800 maybeTurnCellOn(isAirplaneNewlyOn);
Chris Mantona09f3632016-02-09 14:48:42 -0800801 break;
802 }
Hall Liu7f56e1a2019-07-10 14:41:14 -0700803 for (Phone phone : PhoneFactory.getPhones()) {
804 phone.getServiceStateTracker().onAirplaneModeChanged(isAirplaneNewlyOn);
805 }
Chris Mantona09f3632016-02-09 14:48:42 -0800806 }
807
808 /*
809 * Returns true if the radio must be turned off when entering airplane mode.
810 */
Taesu Lee62f826d2020-08-10 16:01:18 +0900811 private boolean isCellOffInAirplaneMode() {
812 String airplaneModeRadios =
813 Settings.Global.getString(
814 getContentResolver(), Settings.Global.AIRPLANE_MODE_RADIOS);
Chris Mantona09f3632016-02-09 14:48:42 -0800815 return airplaneModeRadios == null
816 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
817 }
818
Taesu Lee62f826d2020-08-10 16:01:18 +0900819 private void setRadioPowerOff() {
Chris Mantona09f3632016-02-09 14:48:42 -0800820 Log.i(LOG_TAG, "Turning radio off - airplane");
Taesu Lee62f826d2020-08-10 16:01:18 +0900821 Settings.Global.putInt(
822 getContentResolver(),
823 Settings.Global.CELL_ON,
824 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Chris Mantona09f3632016-02-09 14:48:42 -0800825 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
Taesu Lee62f826d2020-08-10 16:01:18 +0900826 TelephonyProperties.airplane_mode_on(true); // true means int value 1
Chris Mantona09f3632016-02-09 14:48:42 -0800827 PhoneUtils.setRadioPower(false);
Ling Ma317906d2022-12-05 15:58:14 -0800828 clearCacheOnRadioOff();
829 }
830
831 /** Clear fields on power off radio **/
832 private void clearCacheOnRadioOff() {
833 // Re-show is-roaming notifications after APM mode
sangyun1c1918a2023-11-13 22:37:50 +0900834 if (mFeatureFlags.reorganizeRoamingNotification()) {
835 mShownNotificationReasons.clear();
836 } else {
837 mPrevRoamingOperatorNumerics.clear();
838 }
Chris Mantona09f3632016-02-09 14:48:42 -0800839 }
840
Taesu Lee62f826d2020-08-10 16:01:18 +0900841 private void setRadioPowerOn() {
Chris Mantona09f3632016-02-09 14:48:42 -0800842 Log.i(LOG_TAG, "Turning radio on - airplane");
Taesu Lee62f826d2020-08-10 16:01:18 +0900843 Settings.Global.putInt(
844 getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
845 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 1);
Meng Wang61307622019-10-23 14:08:43 -0700846 TelephonyProperties.airplane_mode_on(false); // false means int value 0
Chris Mantona09f3632016-02-09 14:48:42 -0800847 PhoneUtils.setRadioPower(true);
848 }
849
Taesu Lee62f826d2020-08-10 16:01:18 +0900850 private void maybeTurnCellOff(boolean isAirplaneNewlyOn) {
Chris Mantona09f3632016-02-09 14:48:42 -0800851 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700852 // If we are trying to turn off the radio, make sure there are no active
853 // emergency calls. If there are, switch airplane mode back to off.
Taesu Lee62f826d2020-08-10 16:01:18 +0900854 TelecomManager tm = (TelecomManager) getSystemService(TELECOM_SERVICE);
Tyler Gunn900d8fd2018-09-21 09:22:12 -0700855
856 if (tm != null && tm.isInEmergencyCall()) {
Santos Cordone18902f2016-03-22 17:16:04 -0700857 // Switch airplane mode back to off.
Jordan Liu0e819b12019-08-28 15:33:05 -0700858 ConnectivityManager cm =
Taesu Lee62f826d2020-08-10 16:01:18 +0900859 (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
Jordan Liu0e819b12019-08-28 15:33:05 -0700860 cm.setAirplaneMode(false);
Santos Cordone18902f2016-03-22 17:16:04 -0700861 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
862 .show();
863 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Taesu Lee62f826d2020-08-10 16:01:18 +0900864 } else if (isCellOffInAirplaneMode()) {
865 setRadioPowerOff();
Santos Cordone18902f2016-03-22 17:16:04 -0700866 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800867 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700868 }
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700869 } else {
870 Log.i(LOG_TAG, "Ignoring airplane mode: not newly on");
Chris Mantona09f3632016-02-09 14:48:42 -0800871 }
872 }
873
Taesu Lee62f826d2020-08-10 16:01:18 +0900874 private void maybeTurnCellOn(boolean isAirplaneNewlyOn) {
Chris Mantona09f3632016-02-09 14:48:42 -0800875 if (!isAirplaneNewlyOn) {
Taesu Lee62f826d2020-08-10 16:01:18 +0900876 setRadioPowerOn();
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700877 } else {
878 Log.i(LOG_TAG, "Ignoring airplane mode off: radio is already on.");
Santos Cordone18902f2016-03-22 17:16:04 -0700879 }
880 }
881
Santos Cordon593ab382013-08-06 21:58:23 -0700882 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700883 * Receiver for misc intent broadcasts the Phone app cares about.
884 */
885 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
886 @Override
887 public void onReceive(Context context, Intent intent) {
888 String action = intent.getAction();
889 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Taesu Lee3dc572b2020-08-07 18:16:22 +0900890 boolean airplaneMode = intent.getBooleanExtra("state", false);
Taesu Lee62f826d2020-08-10 16:01:18 +0900891 handleAirplaneModeChange(airplaneMode);
Amit Mahajanf5d92c82018-11-02 17:44:40 -0700892 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
893 // re-register as it may be a new IccCard
894 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
895 SubscriptionManager.INVALID_PHONE_INDEX);
896 if (SubscriptionManager.isValidPhoneId(phoneId)) {
897 PhoneUtils.unregisterIccStatus(mHandler, phoneId);
898 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED, phoneId);
899 }
Nazish Tabassum160d2112019-12-23 17:31:33 +0530900 String iccStatus = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
901 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
902 new EventSimStateChangedBag(phoneId, iccStatus)));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700903 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
904 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800905 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
906 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700907 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530908 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530909 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530910 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
911 if (phoneInEcm != null) {
912 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
913 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
914 // Start Emergency Callback Mode service
Daniel Bright30efde42020-01-09 22:11:15 -0800915 if (intent.getBooleanExtra(
916 TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530917 context.startService(new Intent(context,
918 EmergencyCallbackModeService.class));
919 } else {
920 phoneInEcm = null;
921 }
922 } else {
923 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
924 // on a device that doesn't support ECM in the first place.
925 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
926 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
927 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700928 }
929 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530930 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700931 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700932 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
933 // Roaming status could be overridden by carrier config, so we need to update it.
934 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
sangyun1c1918a2023-11-13 22:37:50 +0900935 if (mFeatureFlags.reorganizeRoamingNotification()) {
936 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED);
937 } else {
938 updateDataRoamingStatusForFeatureDisabled(null);
939 }
chen xubaf9fe52019-07-02 17:28:24 -0700940 updateLimitedSimFunctionForDualSim();
Lei Liu863eac02020-06-24 20:12:55 +0800941 int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
942 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
943 if (SubscriptionManager.isValidSubscriptionId(subId)) {
944 mHandler.sendMessage(mHandler.obtainMessage(EVENT_CARRIER_CONFIG_CHANGED,
945 new Integer(subId)));
946 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700947 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
948 // We also need to pay attention when default data subscription changes.
949 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
950 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
951 registerSettingsObserver();
952 Phone phone = getPhone(mDefaultDataSubId);
953 if (phone != null) {
sangyun1c1918a2023-11-13 22:37:50 +0900954 if (mFeatureFlags.reorganizeRoamingNotification()) {
955 updateDataRoamingStatus(
956 ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED);
957 } else {
958 updateDataRoamingStatusForFeatureDisabled(null);
959 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700960 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700961 }
962 }
963 }
964
Sarah Chin072ffb22022-05-03 17:58:59 -0700965 private void handleServiceStateChanged(ServiceState serviceState, int subId) {
Jack Yu1a2fc352017-07-14 17:14:37 -0700966 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Sarah Chin072ffb22022-05-03 17:58:59 -0700967 int state = serviceState.getState();
968 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -0700969
Sarah Chin072ffb22022-05-03 17:58:59 -0700970 if (VDBG) {
971 Log.v(LOG_TAG, "subId=" + subId + ", mDefaultDataSubId="
972 + mDefaultDataSubId + ", ss roaming=" + serviceState.getDataRoaming());
973 }
974 if (subId == mDefaultDataSubId) {
sangyun1c1918a2023-11-13 22:37:50 +0900975 if (mFeatureFlags.reorganizeRoamingNotification()) {
976 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED);
977 } else {
978 updateDataRoamingStatusForFeatureDisabled(serviceState.getOperatorNumeric());
979 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700980 }
981 }
982
Jack Yu1a2fc352017-07-14 17:14:37 -0700983 /**
984 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
985 * to notify the user so they can enable it through settings. Vise versa if the condition
986 * changes, we need to dismiss the notification.
sangyun35f23f82023-07-18 01:37:53 +0900987 * @param reason to inform which event is called for notification update.
Jack Yu1a2fc352017-07-14 17:14:37 -0700988 */
sangyun35f23f82023-07-18 01:37:53 +0900989 private void updateDataRoamingStatus(@RoamingNotificationReason int reason) {
Jack Yu1a2fc352017-07-14 17:14:37 -0700990 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
991 Phone phone = getPhone(mDefaultDataSubId);
992 if (phone == null) {
993 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
994 return;
995 }
996
sangyun35f23f82023-07-18 01:37:53 +0900997 ServiceState serviceState = phone.getServiceState();
998 String roamingNumeric = serviceState.getOperatorNumeric();
999 String roamingNumericReason = "RoamingNumeric=" + roamingNumeric;
1000 String callingReason = "CallingReason=" + reason;
1001 boolean dataIsNowRoaming = serviceState.getDataRoaming();
Jack Yu3e2ac6e2022-03-26 13:59:45 -07001002 boolean dataAllowed;
1003 boolean notAllowedDueToRoamingOff;
Sarah Chine04784a2022-10-31 20:32:34 -07001004 List<DataDisallowedReason> reasons = phone.getDataNetworkController()
1005 .getInternetDataDisallowedReasons();
Jack Yu7968c6d2022-07-31 00:43:21 -07001006 dataAllowed = reasons.isEmpty();
1007 notAllowedDueToRoamingOff = (reasons.size() == 1
1008 && reasons.contains(DataDisallowedReason.ROAMING_DISABLED));
sangyun35f23f82023-07-18 01:37:53 +09001009 StringBuilder sb = new StringBuilder("updateDataRoamingStatus");
1010 sb.append(" dataAllowed=").append(dataAllowed);
1011 sb.append(", reasons=").append(reasons);
1012 sb.append(", dataIsNowRoaming=").append(dataIsNowRoaming);
1013 sb.append(", ").append(roamingNumericReason);
1014 sb.append(", ").append(callingReason);
1015 mDataRoamingNotifLog.log(sb.toString());
Ling Ma317906d2022-12-05 15:58:14 -08001016 if (VDBG) {
sangyun35f23f82023-07-18 01:37:53 +09001017 Log.v(LOG_TAG, sb.toString());
Ling Ma317906d2022-12-05 15:58:14 -08001018 }
Jack Yu3e2ac6e2022-03-26 13:59:45 -07001019
sangyun35f23f82023-07-18 01:37:53 +09001020 // Determine if a given roaming numeric has never been shown.
1021 boolean shownInThisNumeric = false;
1022 if (reason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED
1023 || reason == ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED) {
1024 shownInThisNumeric = mShownNotificationReasons.contains(roamingNumericReason);
1025 }
1026 // Determine if a notification has never been shown by given calling reason.
1027 boolean shownForThisReason = mShownNotificationReasons.contains(callingReason);
1028
Jack Yu3e2ac6e2022-03-26 13:59:45 -07001029 if (!dataAllowed && notAllowedDueToRoamingOff) {
sangyun35f23f82023-07-18 01:37:53 +09001030 if (!shownInThisNumeric && roamingNumeric != null) {
1031 mShownNotificationReasons.add(roamingNumericReason);
1032 }
1033 if (!shownForThisReason
1034 && reason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED) {
1035 mShownNotificationReasons.add(callingReason);
Ling Ma4e15c322022-12-07 11:20:53 -08001036 }
Jordan Liuff2ccd72019-07-23 15:54:41 -07001037 // No need to show it again if we never cancelled it explicitly.
sangyun35f23f82023-07-18 01:37:53 +09001038 if (getCurrentRoamingNotification() == ROAMING_NOTIFICATION_DISCONNECTED) {
1039 return;
1040 }
1041
Jack Yu1a2fc352017-07-14 17:14:37 -07001042 // If the only reason of no data is data roaming disabled, then we notify the user
1043 // so the user can turn on data roaming.
sangyun35f23f82023-07-18 01:37:53 +09001044 if (!shownInThisNumeric && !shownForThisReason) {
1045 updateDataRoamingNotification(ROAMING_NOTIFICATION_DISCONNECTED);
1046 } else {
1047 // Don't show roaming notification if we've already shown for this MccMnc
1048 Log.d(LOG_TAG, "Skip roaming disconnected notification since already"
1049 + " shownInThisNumeric=" + shownInThisNumeric
1050 + " shownForThisReason=" + shownForThisReason);
1051 // Dismiss notification if the other notification is shown.
1052 if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
1053 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
1054 }
1055 }
1056 } else if (dataAllowed && dataIsNowRoaming) {
1057 if (!shownInThisNumeric && roamingNumeric != null) {
1058 mShownNotificationReasons.add(roamingNumericReason);
1059 }
1060 if (!shownForThisReason
1061 && reason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED) {
1062 mShownNotificationReasons.add(callingReason);
1063 }
Ling Ma4e15c322022-12-07 11:20:53 -08001064 boolean isShowRoamingNotificationEnabled = getCarrierConfigForSubId(mDefaultDataSubId)
1065 .getBoolean(CarrierConfigManager
1066 .KEY_SHOW_DATA_CONNECTED_ROAMING_NOTIFICATION_BOOL);
sangyun35f23f82023-07-18 01:37:53 +09001067 // No need to show it again if we never cancelled it explicitly.
1068 if (getCurrentRoamingNotification() == ROAMING_NOTIFICATION_CONNECTED) {
Ling Ma4e15c322022-12-07 11:20:53 -08001069 return;
1070 }
sangyun35f23f82023-07-18 01:37:53 +09001071
1072 // Inform users that roaming charges may apply.
1073 if (!shownInThisNumeric && !shownForThisReason && isShowRoamingNotificationEnabled) {
1074 updateDataRoamingNotification(ROAMING_NOTIFICATION_CONNECTED);
1075 } else {
1076 // Don't show roaming notification if we've already shown for this MccMnc or
1077 // disabled from carrier config.
1078 Log.d(LOG_TAG, "Skip roaming connected notification since already"
1079 + " shownInThisNumeric:" + shownInThisNumeric
1080 + " shownForThisReason:" + shownForThisReason
1081 + " isShowRoamingNotificationEnabled:" + isShowRoamingNotificationEnabled);
1082 // Dismiss notification if the other notification is shown.
1083 if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
1084 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
1085 }
1086 }
1087 } else if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
Jordan Liuff2ccd72019-07-23 15:54:41 -07001088 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
1089 // is not the only data disable reason. In this case we dismiss the notification we
1090 // showed earlier.
sangyun35f23f82023-07-18 01:37:53 +09001091 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
Jack Yu1a2fc352017-07-14 17:14:37 -07001092 }
1093 }
1094
sangyun35f23f82023-07-18 01:37:53 +09001095 private void updateDataRoamingNotification(@RoamingNotification int roamingNotification) {
1096 int event;
1097 switch (roamingNotification) {
1098 case ROAMING_NOTIFICATION_NO_NOTIFICATION:
1099 Log.d(LOG_TAG, "Dismiss roaming notification");
1100 mDataRoamingNotifLog.log("Hide roaming.");
1101 event = EVENT_DATA_ROAMING_OK;
1102 break;
1103 case ROAMING_NOTIFICATION_CONNECTED:
1104 Log.d(LOG_TAG, "Show roaming connected notification");
1105 mDataRoamingNotifLog.log("Show roaming on.");
1106 event = EVENT_DATA_ROAMING_CONNECTED;
1107 break;
1108 case ROAMING_NOTIFICATION_DISCONNECTED:
1109 Log.d(LOG_TAG, "Show roaming disconnected notification");
1110 mDataRoamingNotifLog.log("Show roaming off.");
1111 event = EVENT_DATA_ROAMING_DISCONNECTED;
1112 break;
1113 default:
1114 Log.d(LOG_TAG, "Should never reach here.");
1115 mDataRoamingNotifLog.log("Should never reach here.");
1116 return;
1117 }
1118 mCurrentRoamingNotification = roamingNotification;
1119 mHandler.obtainMessage(event, mDefaultDataSubId, 0).sendToTarget();
1120 }
1121
1122 private @RoamingNotification int getCurrentRoamingNotification() {
1123 return mCurrentRoamingNotification;
1124 }
1125
sangyun1c1918a2023-11-13 22:37:50 +09001126 // For reorganize_roaming_notification feature disabled.
1127 /**
1128 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
1129 * to notify the user so they can enable it through settings. Vise versa if the condition
1130 * changes, we need to dismiss the notification.
1131 * @param roamingOperatorNumeric The operator numeric for the current roaming. {@code null} if
1132 * the current roaming operator numeric didn't change.
1133 */
1134 private void updateDataRoamingStatusForFeatureDisabled(
1135 @Nullable String roamingOperatorNumeric) {
1136 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatusForFeatureDisabled");
1137 Phone phone = getPhone(mDefaultDataSubId);
1138 if (phone == null) {
1139 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
1140 return;
1141 }
1142
1143 boolean dataAllowed;
1144 boolean notAllowedDueToRoamingOff;
1145 List<DataDisallowedReason> reasons = phone.getDataNetworkController()
1146 .getInternetDataDisallowedReasons();
1147 dataAllowed = reasons.isEmpty();
1148 notAllowedDueToRoamingOff = (reasons.size() == 1
1149 && reasons.contains(DataDisallowedReason.ROAMING_DISABLED));
1150 mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons
1151 + ", roamingOperatorNumeric=" + roamingOperatorNumeric);
1152 if (VDBG) {
1153 Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons
1154 + ", roamingOperatorNumeric=" + roamingOperatorNumeric);
1155 }
1156
1157 if (!dataAllowed && notAllowedDueToRoamingOff) {
1158 // Don't show roaming notification if we've already shown for this MccMnc
1159 if (roamingOperatorNumeric != null
1160 && !mPrevRoamingOperatorNumerics.add(roamingOperatorNumeric)) {
1161 Log.d(LOG_TAG, "Skip roaming disconnected notification since already shown in "
1162 + "MccMnc " + roamingOperatorNumeric);
1163 return;
1164 }
1165 // No need to show it again if we never cancelled it explicitly.
1166 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_DISCONNECTED) return;
1167 // If the only reason of no data is data roaming disabled, then we notify the user
1168 // so the user can turn on data roaming.
1169 mPrevRoamingNotification = ROAMING_NOTIFICATION_DISCONNECTED;
1170 Log.d(LOG_TAG, "Show roaming disconnected notification");
1171 mDataRoamingNotifLog.log("Show roaming off.");
1172 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_DISCONNECTED);
1173 msg.arg1 = mDefaultDataSubId;
1174 msg.sendToTarget();
1175 } else if (dataAllowed && dataIsNowRoaming(mDefaultDataSubId)) {
1176 boolean isShowRoamingNotificationEnabled = getCarrierConfigForSubId(mDefaultDataSubId)
1177 .getBoolean(CarrierConfigManager
1178 .KEY_SHOW_DATA_CONNECTED_ROAMING_NOTIFICATION_BOOL);
1179 if (!isShowRoamingNotificationEnabled) return;
1180 // Don't show roaming notification if we've already shown for this MccMnc
1181 if (roamingOperatorNumeric != null
1182 && !mPrevRoamingOperatorNumerics.add(roamingOperatorNumeric)) {
1183 Log.d(LOG_TAG, "Skip roaming connected notification since already shown in "
1184 + "MccMnc " + roamingOperatorNumeric);
1185 return;
1186 }
1187 // No need to show it again if we never cancelled it explicitly, or carrier config
1188 // indicates this is not needed.
1189 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_CONNECTED) return;
1190 mPrevRoamingNotification = ROAMING_NOTIFICATION_CONNECTED;
1191 Log.d(LOG_TAG, "Show roaming connected notification");
1192 mDataRoamingNotifLog.log("Show roaming on.");
1193 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_CONNECTED);
1194 msg.arg1 = mDefaultDataSubId;
1195 msg.sendToTarget();
1196 } else if (mPrevRoamingNotification != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
1197 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
1198 // is not the only data disable reason. In this case we dismiss the notification we
1199 // showed earlier.
1200 mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
1201 Log.d(LOG_TAG, "Dismiss roaming notification");
1202 mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed);
1203 mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
1204 }
1205 }
1206
Jordan Liuff2ccd72019-07-23 15:54:41 -07001207 /**
1208 *
1209 * @param subId to check roaming on
1210 * @return whether we have transitioned to dataRoaming
1211 */
1212 private boolean dataIsNowRoaming(int subId) {
Sarah Chine04784a2022-10-31 20:32:34 -07001213 return getPhone(subId).getServiceState().getDataRoaming();
Jordan Liuff2ccd72019-07-23 15:54:41 -07001214 }
1215
chen xubaf9fe52019-07-02 17:28:24 -07001216 private void updateLimitedSimFunctionForDualSim() {
1217 if (DBG) Log.d(LOG_TAG, "updateLimitedSimFunctionForDualSim");
1218 // check conditions to display limited SIM function notification under dual SIM
1219 SubscriptionManager subMgr = (SubscriptionManager) getSystemService(
1220 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
1221 List<SubscriptionInfo> subList = subMgr.getActiveSubscriptionInfoList(false);
1222 if (subList != null && subList.size() > 1) {
1223 CarrierConfigManager configMgr = (CarrierConfigManager)
1224 getSystemService(Context.CARRIER_CONFIG_SERVICE);
1225 for (SubscriptionInfo info : subList) {
1226 PersistableBundle b = configMgr.getConfigForSubId(info.getSubscriptionId());
1227 if (b != null) {
1228 if (b.getBoolean(CarrierConfigManager
1229 .KEY_LIMITED_SIM_FUNCTION_NOTIFICATION_FOR_DSDS_BOOL)) {
1230 notificationMgr.showLimitedSimFunctionWarningNotification(
1231 info.getSubscriptionId(),
1232 info.getDisplayName().toString());
1233 } else {
1234 notificationMgr.dismissLimitedSimFunctionWarningNotification(
1235 info.getSubscriptionId());
1236 }
1237 }
1238 }
1239 } else {
1240 // cancel notifications for all subs
1241 notificationMgr.dismissLimitedSimFunctionWarningNotification(
1242 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1243 }
1244 notificationMgr.dismissLimitedSimFunctionWarningNotificationForInactiveSubs();
1245
1246 }
1247
Sandeep Kuntade73a6a2014-10-15 18:45:56 +05301248 public Phone getPhoneInEcm() {
1249 return phoneInEcm;
1250 }
1251
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001252 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -08001253 * Triggers a refresh of the message waiting (voicemail) indicator.
1254 *
1255 * @param subId the subscription id we should refresh the notification for.
1256 */
1257 public void refreshMwiIndicator(int subId) {
1258 notificationMgr.refreshMwi(subId);
1259 }
1260
1261 /**
Pengquan Mengdd9ac822018-09-20 15:25:35 -07001262 * Called when the network selection on the subscription {@code subId} is changed by the user.
1263 *
1264 * @param subId the subscription id.
1265 */
1266 public void onNetworkSelectionChanged(int subId) {
1267 Phone phone = getPhone(subId);
1268 if (phone != null) {
1269 notificationMgr.updateNetworkSelection(phone.getServiceState().getState(), subId);
1270 } else {
1271 Log.w(LOG_TAG, "onNetworkSelectionChanged on null phone, subId: " + subId);
1272 }
1273 }
1274
1275 /**
James.cf Lin4b784aa2021-01-31 03:25:15 +08001276 * @return whether the device supports RCS User Capability Exchange or not.
1277 */
1278 public boolean getDeviceUceEnabled() {
1279 return (mTelephonyRcsService == null) ? false : mTelephonyRcsService.isDeviceUceEnabled();
1280 }
1281
1282 /**
1283 * Set the device supports RCS User Capability Exchange.
1284 * @param isEnabled true if the device supports UCE.
1285 */
1286 public void setDeviceUceEnabled(boolean isEnabled) {
1287 if (mTelephonyRcsService != null) {
1288 mTelephonyRcsService.setDeviceUceEnabled(isEnabled);
1289 }
1290 }
1291
1292 /**
Jack Yu1a2fc352017-07-14 17:14:37 -07001293 * Dump the state of the object, add calls to other objects as desired.
1294 *
1295 * @param fd File descriptor
1296 * @param printWriter Print writer
1297 * @param args Arguments
1298 */
1299 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
1300 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
1301 pw.println("------- PhoneGlobals -------");
1302 pw.increaseIndent();
sangyun15019e02023-11-13 21:50:15 +09001303 pw.println("FeatureFlags:");
1304 pw.increaseIndent();
1305 pw.println("loadDdsOnCreate=" + mFeatureFlags.loadDdsOnCreate());
sangyun1c1918a2023-11-13 22:37:50 +09001306 pw.println("reorganizeRoamingNotification="
1307 + mFeatureFlags.reorganizeRoamingNotification());
sangyund5f37ab2023-11-13 22:52:28 +09001308 pw.println("dismissNetworkSelectionNotificationOnSimDisable="
1309 + mFeatureFlags.dismissNetworkSelectionNotificationOnSimDisable());
sangyun15019e02023-11-13 21:50:15 +09001310 pw.decreaseIndent();
sangyun1c1918a2023-11-13 22:37:50 +09001311 if (mFeatureFlags.reorganizeRoamingNotification()) {
1312 pw.println("mCurrentRoamingNotification=" + mCurrentRoamingNotification);
1313 } else {
1314 pw.println("mPrevRoamingNotification=" + mPrevRoamingNotification);
1315 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001316 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
Keun young Parkdebb8532019-05-30 16:35:27 -07001317 pw.println("isSmsCapable=" + TelephonyManager.from(this).isSmsCapable());
sangyun35f23f82023-07-18 01:37:53 +09001318 pw.println("mDataRoamingNotifLog:");
Jack Yu1a2fc352017-07-14 17:14:37 -07001319 pw.increaseIndent();
1320 mDataRoamingNotifLog.dump(fd, pw, args);
1321 pw.decreaseIndent();
Brad Ebinger05f52c22019-12-05 13:03:21 -08001322 pw.println("ImsResolver:");
1323 pw.increaseIndent();
1324 try {
Brad Ebingerd1947d82021-05-17 20:54:49 +00001325 if (ImsResolver.getInstance() != null) ImsResolver.getInstance().dump(fd, pw, args);
Brad Ebinger05f52c22019-12-05 13:03:21 -08001326 } catch (Exception e) {
1327 e.printStackTrace();
1328 }
1329 pw.decreaseIndent();
Brad Ebingera68a4972020-01-30 17:31:23 -08001330 pw.println("RcsService:");
1331 try {
1332 if (mTelephonyRcsService != null) mTelephonyRcsService.dump(fd, pw, args);
1333 } catch (Exception e) {
1334 e.printStackTrace();
1335 }
Hunsuk Choi89bd22c2021-11-01 13:04:54 +00001336 pw.println("ImsStateCallbackController:");
1337 try {
1338 if (mImsStateCallbackController != null) mImsStateCallbackController.dump(pw);
1339 } catch (Exception e) {
1340 e.printStackTrace();
1341 }
Hwangoo Parkba21cf22022-11-30 14:34:04 +00001342 pw.println("DomainSelectionResolver:");
1343 pw.increaseIndent();
1344 try {
1345 if (DomainSelectionResolver.getInstance() != null) {
1346 DomainSelectionResolver.getInstance().dump(fd, pw, args);
1347 }
1348 } catch (Exception e) {
1349 e.printStackTrace();
1350 }
1351 pw.decreaseIndent();
1352 if (mDomainSelectionService != null) {
1353 mDomainSelectionService.dump(fd, pw, args);
1354 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001355 pw.decreaseIndent();
sangyun1c1918a2023-11-13 22:37:50 +09001356 if (mFeatureFlags.reorganizeRoamingNotification()) {
1357 pw.println("mShownNotificationReasons=" + mShownNotificationReasons);
1358 } else {
1359 pw.println("mPrevRoamingOperatorNumerics:" + mPrevRoamingOperatorNumerics);
1360 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001361 pw.println("------- End PhoneGlobals -------");
1362 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001363}