blob: fffdac45130526a741af9d20559099cf57c701d9 [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070020import android.app.Activity;
21import android.app.KeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.ProgressDialog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070023import android.content.BroadcastReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.content.ContentResolver;
25import android.content.Context;
26import android.content.ContextWrapper;
27import android.content.Intent;
28import android.content.IntentFilter;
Brad Ebinger05f52c22019-12-05 13:03:21 -080029import android.content.pm.PackageManager;
Youming Ye47a6adc2018-11-19 15:33:36 -080030import android.content.res.XmlResourceParser;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.media.AudioManager;
Santos Cordone18902f2016-03-22 17:16:04 -070032import android.net.ConnectivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.net.Uri;
34import android.os.AsyncResult;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.os.Handler;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036import android.os.Message;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070037import android.os.PersistableBundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.PowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.preference.PreferenceManager;
Sanket Padawe4c699232016-02-09 11:07:22 -080041import android.provider.Settings;
Meng Wang61307622019-10-23 14:08:43 -070042import android.sysprop.TelephonyProperties;
Tyler Gunn900d8fd2018-09-21 09:22:12 -070043import android.telecom.TelecomManager;
Nathan Haroldf9df6ea2019-03-08 11:54:22 -080044import android.telephony.AnomalyReporter;
Junda Liu12f7d802015-05-01 12:06:44 -070045import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.telephony.ServiceState;
chen xubaf9fe52019-07-02 17:28:24 -070047import android.telephony.SubscriptionInfo;
Andrew Lee385019f2014-11-24 14:19:50 -080048import android.telephony.SubscriptionManager;
Sarah Chin072ffb22022-05-03 17:58:59 -070049import android.telephony.TelephonyCallback;
Hall Liuaa4211e2021-01-20 15:43:39 -080050import android.telephony.TelephonyLocalConnection;
Jack Yu1a2fc352017-07-14 17:14:37 -070051import android.telephony.TelephonyManager;
Ling Ma317906d2022-12-05 15:58:14 -080052import android.util.ArraySet;
Jack Yu1a2fc352017-07-14 17:14:37 -070053import android.util.LocalLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.util.Log;
Santos Cordone18902f2016-03-22 17:16:04 -070055import android.widget.Toast;
Ta-wei Yenb29425b2016-09-21 17:28:14 -070056
Brad Ebingere3ae65a2020-09-11 12:45:11 -070057import com.android.ims.ImsFeatureBinderRepository;
Siim Sammul182d61b2021-05-04 16:01:42 +010058import com.android.internal.os.BinderCallsStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import com.android.internal.telephony.CallManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import com.android.internal.telephony.IccCardConstants;
61import com.android.internal.telephony.MmiCode;
62import com.android.internal.telephony.Phone;
Sarah Chin072ffb22022-05-03 17:58:59 -070063import com.android.internal.telephony.PhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import com.android.internal.telephony.PhoneConstants;
65import com.android.internal.telephony.PhoneFactory;
Jack Yu1a2fc352017-07-14 17:14:37 -070066import com.android.internal.telephony.SettingsObserver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067import com.android.internal.telephony.TelephonyCapabilities;
Youming Ye47a6adc2018-11-19 15:33:36 -080068import com.android.internal.telephony.TelephonyComponentFactory;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070069import com.android.internal.telephony.TelephonyIntents;
Jack Yu3e2ac6e2022-03-26 13:59:45 -070070import com.android.internal.telephony.data.DataEvaluation.DataDisallowedReason;
Hwangoo Parkba21cf22022-11-30 14:34:04 +000071import com.android.internal.telephony.domainselection.DomainSelectionResolver;
Daniel Bantab26e96f2022-10-19 23:25:35 +000072import com.android.internal.telephony.emergency.EmergencyStateTracker;
Thomas Nguyen090fb002023-09-11 17:35:30 -070073import com.android.internal.telephony.flags.FeatureFlags;
Ling Ma51dd3022023-08-29 11:46:38 -070074import com.android.internal.telephony.flags.FeatureFlagsImpl;
Brad Ebinger05f52c22019-12-05 13:03:21 -080075import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn92479152021-01-20 16:30:10 -080076import com.android.internal.telephony.imsphone.ImsPhone;
77import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000078import com.android.internal.telephony.satellite.SatelliteController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000079import com.android.internal.telephony.uicc.UiccPort;
Jordan Liu06bdef12021-03-24 17:25:46 -070080import com.android.internal.telephony.uicc.UiccProfile;
Jack Yu1a2fc352017-07-14 17:14:37 -070081import com.android.internal.util.IndentingPrintWriter;
Andrew Leefb7f92e2015-02-26 16:23:32 -080082import com.android.phone.settings.SettingsConstants;
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -070083import com.android.phone.vvm.CarrierVvmPackageInstalledReceiver;
Hwangoo Parkba21cf22022-11-30 14:34:04 +000084import com.android.services.telephony.domainselection.TelephonyDomainSelectionService;
James.cf Linc9f35a42020-01-15 02:35:22 +080085import com.android.services.telephony.rcs.TelephonyRcsService;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086
Jack Yu1a2fc352017-07-14 17:14:37 -070087import java.io.FileDescriptor;
88import java.io.PrintWriter;
Jordan Liuff2ccd72019-07-23 15:54:41 -070089import java.lang.annotation.Retention;
90import java.lang.annotation.RetentionPolicy;
chen xubaf9fe52019-07-02 17:28:24 -070091import java.util.List;
Jack Yu1a2fc352017-07-14 17:14:37 -070092
Santos Cordon7d4ddf62013-07-10 11:58:08 -070093/**
94 * Global state for the telephony subsystem when running in the primary
95 * phone process.
96 */
Sailesh Nepalbf900542014-07-15 16:18:32 -070097public class PhoneGlobals extends ContextWrapper {
Jack Yu1a2fc352017-07-14 17:14:37 -070098 public static final String LOG_TAG = "PhoneGlobals";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099
100 /**
101 * Phone app-wide debug level:
102 * 0 - no debug logging
103 * 1 - normal debug logging if ro.debuggable is set (which is true in
104 * "eng" and "userdebug" builds but not "user" builds)
105 * 2 - ultra-verbose debug logging
106 *
107 * Most individual classes in the phone app have a local DBG constant,
108 * typically set to
109 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
110 * or else
111 * (PhoneApp.DBG_LEVEL >= 2)
112 * depending on the desired verbosity.
113 *
114 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
115 */
Andrew Lee88b51e22014-10-29 15:48:51 -0700116 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117
118 private static final boolean DBG =
119 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
120 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
121
122 // Message codes; see mHandler below.
123 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700124 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700125 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
Jordan Liuff2ccd72019-07-23 15:54:41 -0700126 private static final int EVENT_DATA_ROAMING_CONNECTED = 11;
127 private static final int EVENT_DATA_ROAMING_OK = 12;
128 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 13;
Jordan Liuff2ccd72019-07-23 15:54:41 -0700129 private static final int EVENT_DATA_ROAMING_SETTINGS_CHANGED = 15;
130 private static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED = 16;
Lei Liu863eac02020-06-24 20:12:55 +0800131 private static final int EVENT_CARRIER_CONFIG_CHANGED = 17;
Sarah Chin072ffb22022-05-03 17:58:59 -0700132 private static final int EVENT_MULTI_SIM_CONFIG_CHANGED = 18;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133
134 // The MMI codes are also used by the InCallScreen.
135 public static final int MMI_INITIATE = 51;
136 public static final int MMI_COMPLETE = 52;
137 public static final int MMI_CANCEL = 53;
138 // Don't use message codes larger than 99 here; those are reserved for
139 // the individual Activities of the Phone UI.
140
Santos Cordone18902f2016-03-22 17:16:04 -0700141 public static final int AIRPLANE_ON = 1;
142 public static final int AIRPLANE_OFF = 0;
143
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700144 /**
145 * Allowable values for the wake lock code.
146 * SLEEP means the device can be put to sleep.
147 * PARTIAL means wake the processor, but we display can be kept off.
148 * FULL means wake both the processor and the display.
149 */
150 public enum WakeState {
151 SLEEP,
152 PARTIAL,
153 FULL
154 }
155
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700156 private static PhoneGlobals sMe;
157
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700158 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700159 CallNotifier notifier;
Santos Cordon63a84242013-07-23 13:32:52 -0700160 NotificationMgr notificationMgr;
James.cf Linc9f35a42020-01-15 02:35:22 +0800161 TelephonyRcsService mTelephonyRcsService;
Andrew Lee9431b832015-03-09 18:46:45 -0700162 public PhoneInterfaceManager phoneMgr;
James.cf Linaf3183c2019-10-24 00:59:00 +0800163 public ImsRcsController imsRcsController;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000164 public ImsStateCallbackController mImsStateCallbackController;
joonhunshincffb7fc2021-11-28 07:32:01 +0000165 public ImsProvisioningController mImsProvisioningController;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800166 CarrierConfigLoader configLoader;
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000167 TelephonyDomainSelectionService mDomainSelectionService;
Santos Cordon63a84242013-07-23 13:32:52 -0700168
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530169 private Phone phoneInEcm;
Santos Cordon63a84242013-07-23 13:32:52 -0700170
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171 static boolean sVoiceCapable = true;
172
Santos Cordonc593d002015-06-03 15:41:15 -0700173 // TODO: Remove, no longer used.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174 CdmaPhoneCallState cdmaPhoneCallState;
175
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700176 // The currently-active PUK entry activity and progress dialog.
177 // Normally, these are the Emergency Dialer and the subsequent
178 // progress dialog. null if there is are no such objects in
179 // the foreground.
180 private Activity mPUKEntryActivity;
181 private ProgressDialog mPUKEntryProgressDialog;
182
Jordan Liuff2ccd72019-07-23 15:54:41 -0700183 /** @hide */
184 @Retention(RetentionPolicy.SOURCE)
sangyun35f23f82023-07-18 01:37:53 +0900185 @IntDef(prefix = {"ROAMING_NOTIFICATION_REASON_"},
186 value = {
187 ROAMING_NOTIFICATION_REASON_DATA_SETTING_CHANGED,
188 ROAMING_NOTIFICATION_REASON_DATA_ROAMING_SETTING_CHANGED,
189 ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED,
190 ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED,
191 ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED})
192 public @interface RoamingNotificationReason {}
193 private static final int ROAMING_NOTIFICATION_REASON_DATA_SETTING_CHANGED = 0;
194 private static final int ROAMING_NOTIFICATION_REASON_DATA_ROAMING_SETTING_CHANGED = 1;
195 private static final int ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED = 2;
196 private static final int ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED = 3;
197 private static final int ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED = 4;
198
199 /** @hide */
200 @Retention(RetentionPolicy.SOURCE)
Jordan Liuff2ccd72019-07-23 15:54:41 -0700201 @IntDef(prefix = {"ROAMING_NOTIFICATION_"},
202 value = {
203 ROAMING_NOTIFICATION_NO_NOTIFICATION,
204 ROAMING_NOTIFICATION_CONNECTED,
205 ROAMING_NOTIFICATION_DISCONNECTED})
206 public @interface RoamingNotification {}
207
208 private static final int ROAMING_NOTIFICATION_NO_NOTIFICATION = 0;
209 private static final int ROAMING_NOTIFICATION_CONNECTED = 1;
210 private static final int ROAMING_NOTIFICATION_DISCONNECTED = 2;
211
212 @RoamingNotification
sangyun35f23f82023-07-18 01:37:53 +0900213 private int mCurrentRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
Jack Yu953f9352017-05-18 14:41:06 -0700214
sangyun35f23f82023-07-18 01:37:53 +0900215 /**
216 * Reasons that have already shown notification to prevent duplicate shows for the same reason.
217 */
218 private ArraySet<String> mShownNotificationReasons = new ArraySet<>();
Ling Ma317906d2022-12-05 15:58:14 -0800219
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700220 private WakeState mWakeState = WakeState.SLEEP;
221
222 private PowerManager mPowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700223 private PowerManager.WakeLock mWakeLock;
224 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700225 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700226
Jack Yu1a2fc352017-07-14 17:14:37 -0700227 private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
228 private final LocalLog mDataRoamingNotifLog = new LocalLog(50);
229
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700230 // Broadcast receiver for various intent broadcasts (see onCreate())
231 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
232
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700233 private final CarrierVvmPackageInstalledReceiver mCarrierVvmPackageInstalledReceiver =
234 new CarrierVvmPackageInstalledReceiver();
235
Jack Yu1a2fc352017-07-14 17:14:37 -0700236 private final SettingsObserver mSettingsObserver;
Siim Sammul182d61b2021-05-04 16:01:42 +0100237 private BinderCallsStats.SettingsObserver mBinderCallsSettingsObserver;
Jack Yu1a2fc352017-07-14 17:14:37 -0700238
Sarah Chin072ffb22022-05-03 17:58:59 -0700239 // Mapping of phone ID to the associated TelephonyCallback. These should be registered without
240 // fine or coarse location since we only use ServiceState for
241 private PhoneAppCallback[] mTelephonyCallbacks;
242
243 private class PhoneAppCallback extends TelephonyCallback implements
244 TelephonyCallback.ServiceStateListener {
245 private final int mSubId;
246
247 PhoneAppCallback(int subId) {
248 mSubId = subId;
249 }
250
251 @Override
252 public void onServiceStateChanged(ServiceState serviceState) {
253 // Note when registering that we should be registering with INCLUDE_LOCATION_DATA_NONE.
254 // PhoneGlobals only uses the state and roaming status, which does not require location.
255 handleServiceStateChanged(serviceState, mSubId);
256 }
257
258 public int getSubId() {
259 return mSubId;
260 }
261 }
262
Nazish Tabassum160d2112019-12-23 17:31:33 +0530263 private static class EventSimStateChangedBag {
264 final int mPhoneId;
265 final String mIccStatus;
266
267 EventSimStateChangedBag(int phoneId, String iccStatus) {
268 mPhoneId = phoneId;
269 mIccStatus = iccStatus;
270 }
271 }
272
Jordan Liu06bdef12021-03-24 17:25:46 -0700273 // Some carrier config settings disable the network lock screen, so we call handleSimLock
274 // when either SIM_LOCK or CARRIER_CONFIG changes so that no matter which one happens first,
275 // we still do the right thing
276 private void handleSimLock(int subType, Phone phone) {
277 PersistableBundle cc = getCarrierConfigForSubId(phone.getSubId());
278 if (!CarrierConfigManager.isConfigForIdentifiedCarrier(cc)) {
279 // If we only have the default carrier config just return, to avoid popping up the
280 // the SIM lock screen when it's disabled by the carrier.
281 Log.i(LOG_TAG, "Not showing 'SIM network unlock' screen. Carrier config not loaded");
282 return;
283 }
284 if (cc.getBoolean(CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
285 // Some products don't have the concept of a "SIM network lock"
286 Log.i(LOG_TAG, "Not showing 'SIM network unlock' screen. Disabled by carrier config");
287 return;
288 }
289
290 // if passed in subType is unknown, retrieve it here.
291 if (subType == -1) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000292 final UiccPort uiccPort = phone.getUiccPort();
293 if (uiccPort == null) {
Jordan Liu06bdef12021-03-24 17:25:46 -0700294 Log.e(LOG_TAG,
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000295 "handleSimLock: uiccPort for phone " + phone.getPhoneId() + " is null");
Jordan Liu06bdef12021-03-24 17:25:46 -0700296 return;
297 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000298 final UiccProfile uiccProfile = uiccPort.getUiccProfile();
Jordan Liu06bdef12021-03-24 17:25:46 -0700299 if (uiccProfile == null) {
300 Log.e(LOG_TAG,
301 "handleSimLock: uiccProfile for phone " + phone.getPhoneId() + " is null");
302 return;
303 }
304 subType = uiccProfile.getApplication(
305 uiccProfile.mCurrentAppType).getPersoSubState().ordinal();
306 }
307 // Normal case: show the "SIM network unlock" PIN entry screen.
308 // The user won't be able to do anything else until
309 // they enter a valid SIM network PIN.
310 Log.i(LOG_TAG, "show sim depersonal panel");
311 IccNetworkDepersonalizationPanel.showDialog(phone, subType);
312 }
313
314 private boolean isSimLocked(Phone phone) {
315 TelephonyManager tm = getSystemService(TelephonyManager.class);
316 return tm.createForSubscriptionId(phone.getSubId()).getSimState()
317 == TelephonyManager.SIM_STATE_NETWORK_LOCKED;
318 }
319
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700320 Handler mHandler = new Handler() {
321 @Override
322 public void handleMessage(Message msg) {
323 PhoneConstants.State phoneState;
Jack Yu1a2fc352017-07-14 17:14:37 -0700324 if (VDBG) Log.v(LOG_TAG, "event=" + msg.what);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700325 switch (msg.what) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700326 // TODO: This event should be handled by the lock screen, just
327 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
328 case EVENT_SIM_NETWORK_LOCKED:
Jordan Liu06bdef12021-03-24 17:25:46 -0700329 int subType = (Integer) ((AsyncResult) msg.obj).result;
330 Phone phone = (Phone) ((AsyncResult) msg.obj).userObj;
331 handleSimLock(subType, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332 break;
333
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700334 case EVENT_DATA_ROAMING_DISCONNECTED:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700335 notificationMgr.showDataRoamingNotification(msg.arg1, false);
336 break;
337
338 case EVENT_DATA_ROAMING_CONNECTED:
339 notificationMgr.showDataRoamingNotification(msg.arg1, true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700340 break;
341
342 case EVENT_DATA_ROAMING_OK:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700343 notificationMgr.hideDataRoamingNotification();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344 break;
345
346 case MMI_COMPLETE:
347 onMMIComplete((AsyncResult) msg.obj);
348 break;
349
350 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800351 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700352 break;
353
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354 case EVENT_SIM_STATE_CHANGED:
Nazish Tabassum160d2112019-12-23 17:31:33 +0530355 EventSimStateChangedBag bag = (EventSimStateChangedBag)msg.obj;
Sarah Chin010884c2023-06-14 15:55:08 -0700356 // Dismiss the "No services" notification if the SIM is removed.
357 if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(bag.mIccStatus)) {
358 notificationMgr.dismissNetworkSelectionNotificationForInactiveSubId();
359 }
360
361 // Marks the event where the SIM goes into ready state.
362 // Right now, this is only used for the PUK-unlocking process.
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700363 if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(bag.mIccStatus)
Nazish Tabassum59126a92020-07-03 21:44:49 +0530364 || IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(bag.mIccStatus)
365 || IccCardConstants.INTENT_VALUE_ICC_NOT_READY.equals(bag.mIccStatus)
366 || IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(bag.mIccStatus)) {
Sarah Chin010884c2023-06-14 15:55:08 -0700367 // When the right event is triggered and there are UI objects in the
368 // foreground, we close them to display the lock panel.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369 if (mPUKEntryActivity != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700370 Log.i(LOG_TAG, "Dismiss puk entry activity");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 mPUKEntryActivity.finish();
372 mPUKEntryActivity = null;
373 }
374 if (mPUKEntryProgressDialog != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700375 Log.i(LOG_TAG, "Dismiss puk progress dialog");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700376 mPUKEntryProgressDialog.dismiss();
377 mPUKEntryProgressDialog = null;
378 }
Nazish Tabassum59126a92020-07-03 21:44:49 +0530379 Log.i(LOG_TAG, "Dismissing depersonal panel" + (bag.mIccStatus));
Nazish Tabassum160d2112019-12-23 17:31:33 +0530380 IccNetworkDepersonalizationPanel.dialogDismiss(bag.mPhoneId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 }
382 break;
383
384 case EVENT_UNSOL_CDMA_INFO_RECORD:
385 //TODO: handle message here;
386 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700387 case EVENT_DATA_ROAMING_SETTINGS_CHANGED:
sangyun35f23f82023-07-18 01:37:53 +0900388 updateDataRoamingStatus(
389 ROAMING_NOTIFICATION_REASON_DATA_ROAMING_SETTING_CHANGED);
390 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700391 case EVENT_MOBILE_DATA_SETTINGS_CHANGED:
sangyun35f23f82023-07-18 01:37:53 +0900392 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_DATA_SETTING_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700393 break;
Lei Liu863eac02020-06-24 20:12:55 +0800394 case EVENT_CARRIER_CONFIG_CHANGED:
395 int subId = (Integer) msg.obj;
396 // The voicemail number could be overridden by carrier config, so need to
397 // refresh the message waiting (voicemail) indicator.
398 refreshMwiIndicator(subId);
Jordan Liu06bdef12021-03-24 17:25:46 -0700399 phone = getPhone(subId);
Sarah Chin072ffb22022-05-03 17:58:59 -0700400 if (phone != null) {
401 if (isSimLocked(phone)) {
402 // pass in subType=-1 so handleSimLock can find the actual subType if
403 // needed. This is safe as valid values for subType are >= 0
404 handleSimLock(-1, phone);
405 }
406 TelephonyManager tm = getSystemService(TelephonyManager.class);
407 PhoneAppCallback callback = mTelephonyCallbacks[phone.getPhoneId()];
408 // TODO: We may need to figure out a way to unregister if subId is invalid
409 tm.createForSubscriptionId(callback.getSubId())
410 .unregisterTelephonyCallback(callback);
411 callback = new PhoneAppCallback(subId);
412 tm.createForSubscriptionId(subId).registerTelephonyCallback(
Ling Ma317906d2022-12-05 15:58:14 -0800413 TelephonyManager.INCLUDE_LOCATION_DATA_COARSE, mHandler::post,
Sarah Chin072ffb22022-05-03 17:58:59 -0700414 callback);
415 mTelephonyCallbacks[phone.getPhoneId()] = callback;
416 }
417 break;
418 case EVENT_MULTI_SIM_CONFIG_CHANGED:
419 int activeModems = (int) ((AsyncResult) msg.obj).result;
420 TelephonyManager tm = getSystemService(TelephonyManager.class);
421 // Unregister all previous callbacks
422 for (int phoneId = 0; phoneId < mTelephonyCallbacks.length; phoneId++) {
423 PhoneAppCallback callback = mTelephonyCallbacks[phoneId];
424 if (callback != null) {
425 tm.createForSubscriptionId(callback.getSubId())
426 .unregisterTelephonyCallback(callback);
427 mTelephonyCallbacks[phoneId] = null;
428 }
429 }
430 // Register callbacks for all active modems
431 for (int phoneId = 0; phoneId < activeModems; phoneId++) {
432 int sub = PhoneFactory.getPhone(phoneId).getSubId();
433 PhoneAppCallback callback = new PhoneAppCallback(sub);
434 tm.createForSubscriptionId(sub).registerTelephonyCallback(
435 TelephonyManager.INCLUDE_LOCATION_DATA_NONE, mHandler::post,
436 callback);
437 mTelephonyCallbacks[phoneId] = callback;
Jordan Liu06bdef12021-03-24 17:25:46 -0700438 }
Lei Liu863eac02020-06-24 20:12:55 +0800439 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700440 }
441 }
442 };
443
444 public PhoneGlobals(Context context) {
445 super(context);
446 sMe = this;
Jack Yu1a2fc352017-07-14 17:14:37 -0700447 mSettingsObserver = new SettingsObserver(context, mHandler);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448 }
449
450 public void onCreate() {
451 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
452
453 ContentResolver resolver = getContentResolver();
454
Hall Liuaa4211e2021-01-20 15:43:39 -0800455 // Initialize the shim from frameworks/opt/telephony into packages/services/Telephony.
456 TelephonyLocalConnection.setInstance(new LocalConnectionImpl(this));
457
Sarah Chin072ffb22022-05-03 17:58:59 -0700458 TelephonyManager tm = getSystemService(TelephonyManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700459 // Cache the "voice capable" flag.
460 // This flag currently comes from a resource (which is
461 // overrideable on a per-product basis):
Sarah Chin072ffb22022-05-03 17:58:59 -0700462 sVoiceCapable = tm.isVoiceCapable();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700463 // ...but this might eventually become a PackageManager "system
464 // feature" instead, in which case we'd do something like:
465 // sVoiceCapable =
466 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
467
Stuart Scottdcf40a92014-12-09 10:45:01 -0800468 if (mCM == null) {
Nathan Haroldf9df6ea2019-03-08 11:54:22 -0800469 // Initialize AnomalyReporter early so that it can be used
470 AnomalyReporter.initialize(this);
Nathan Harold0db5c5e2019-01-22 20:18:56 -0800471
Youming Ye47a6adc2018-11-19 15:33:36 -0800472 // Inject telephony component factory if configured using other jars.
473 XmlResourceParser parser = getResources().getXml(R.xml.telephony_injection);
474 TelephonyComponentFactory.getInstance().injectTheComponentFactory(parser);
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000475
476 // Create DomainSelectionResolver always, but it MUST be initialized only when
477 // the device supports AOSP domain selection architecture and
478 // has new IRadio that supports its related HAL APIs.
479 DomainSelectionResolver.make(this,
480 getResources().getBoolean(R.bool.config_enable_aosp_domain_selection));
481
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700482 // Initialize the telephony framework
Thomas Nguyen090fb002023-09-11 17:35:30 -0700483 FeatureFlags featureFlags = new FeatureFlagsImpl();
484 PhoneFactory.makeDefaultPhones(this, featureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700485
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000486 // Initialize the DomainSelectionResolver after creating the Phone instance
487 // to check the Radio HAL version.
488 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
489 mDomainSelectionService = new TelephonyDomainSelectionService(this);
490 DomainSelectionResolver.getInstance().initialize(mDomainSelectionService);
Daniel Bantab26e96f2022-10-19 23:25:35 +0000491 // Initialize EmergencyStateTracker if domain selection is supported
492 boolean isSuplDdsSwitchRequiredForEmergencyCall = getResources()
493 .getBoolean(R.bool.config_gnss_supl_requires_default_data_for_emergency);
494 EmergencyStateTracker.make(this, isSuplDdsSwitchRequiredForEmergencyCall);
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000495 }
496
Brad Ebinger05f52c22019-12-05 13:03:21 -0800497 // Only bring up ImsResolver if the device supports having an IMS stack.
498 if (getPackageManager().hasSystemFeature(
499 PackageManager.FEATURE_TELEPHONY_IMS)) {
500 // Get the package name of the default IMS implementation.
501 String defaultImsMmtelPackage = getResources().getString(
502 R.string.config_ims_mmtel_package);
503 String defaultImsRcsPackage = getResources().getString(
504 R.string.config_ims_rcs_package);
Brad Ebingerd1947d82021-05-17 20:54:49 +0000505 ImsResolver.make(this, defaultImsMmtelPackage,
Brad Ebingere3ae65a2020-09-11 12:45:11 -0700506 defaultImsRcsPackage, PhoneFactory.getPhones().length,
507 new ImsFeatureBinderRepository());
Brad Ebingerd1947d82021-05-17 20:54:49 +0000508 ImsResolver.getInstance().initialize();
Tyler Gunn92479152021-01-20 16:30:10 -0800509
510 // With the IMS phone created, load static config.xml values from the phone process
511 // so that it can be provided to the ImsPhoneCallTracker.
512 for (Phone p : PhoneFactory.getPhones()) {
513 Phone imsPhone = p.getImsPhone();
514 if (imsPhone != null && imsPhone instanceof ImsPhone) {
515 ImsPhone theImsPhone = (ImsPhone) imsPhone;
516 if (theImsPhone.getCallTracker() instanceof ImsPhoneCallTracker) {
517 ImsPhoneCallTracker ict = (ImsPhoneCallTracker)
518 theImsPhone.getCallTracker();
519
520 ImsPhoneCallTracker.Config config = new ImsPhoneCallTracker.Config();
521 config.isD2DCommunicationSupported = getResources().getBoolean(
522 R.bool.config_use_device_to_device_communication);
523 ict.setConfig(config);
524 }
525 }
526 }
Hui Wang068ab862020-10-31 05:12:53 +0000527 RcsProvisioningMonitor.make(this);
Brad Ebinger05f52c22019-12-05 13:03:21 -0800528 }
529
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700530 // Start TelephonyDebugService After the default phone is created.
531 Intent intent = new Intent(this, TelephonyDebugService.class);
532 startService(intent);
533
534 mCM = CallManager.getInstance();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700535
536 // Create the NotificationMgr singleton, which is used to display
537 // status bar icons and control other status bar behavior.
538 notificationMgr = NotificationMgr.init(this);
539
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000540 // Create the SatelliteController singleton, which acts as a backend service for
541 // {@link android.telephony.satellite.SatelliteManager}.
Thomas Nguyen090fb002023-09-11 17:35:30 -0700542 SatelliteController.make(this, featureFlags);
Sarah Chin5f57c582023-02-14 04:16:10 -0800543
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700544 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
545 cdmaPhoneCallState = new CdmaPhoneCallState();
546 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700547
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700548 // before registering for phone state changes
549 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
550 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
551 // lock used to keep the processor awake, when we don't care for the display.
552 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
553 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700554
555 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
556
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800557 phoneMgr = PhoneInterfaceManager.init(this);
Santos Cordon406c0342013-08-28 00:07:47 -0700558
James.cf Linaf3183c2019-10-24 00:59:00 +0800559 imsRcsController = ImsRcsController.init(this);
560
Brad Ebinger6c53e7f2023-01-27 16:26:44 -0800561 configLoader = CarrierConfigLoader.init(this);
562
James.cf Linc9f35a42020-01-15 02:35:22 +0800563 if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000564 mImsStateCallbackController =
565 ImsStateCallbackController.make(this, PhoneFactory.getPhones().length);
Brad Ebingera68a4972020-01-30 17:31:23 -0800566 mTelephonyRcsService = new TelephonyRcsService(this,
567 PhoneFactory.getPhones().length);
568 mTelephonyRcsService.initialize();
James.cf Linc9f35a42020-01-15 02:35:22 +0800569 imsRcsController.setRcsService(mTelephonyRcsService);
joonhunshincffb7fc2021-11-28 07:32:01 +0000570 mImsProvisioningController =
571 ImsProvisioningController.make(this, PhoneFactory.getPhones().length);
James.cf Linc9f35a42020-01-15 02:35:22 +0800572 }
573
Jack Yu1a2fc352017-07-14 17:14:37 -0700574 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700575 // asynchronous events from the telephony layer (like
576 // launching the incoming-call UI when an incoming call comes
577 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800578 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700579
Stuart Scottdcf40a92014-12-09 10:45:01 -0800580 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700581
582 // register for MMI/USSD
583 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
584
Qiong Liucc3fe812019-09-23 15:25:44 +0800585 // Initialize cell status using current airplane mode.
Taesu Lee62f826d2020-08-10 16:01:18 +0900586 handleAirplaneModeChange(
587 Settings.Global.getInt(
588 getContentResolver(),
589 Settings.Global.AIRPLANE_MODE_ON,
590 AIRPLANE_OFF)
591 == AIRPLANE_ON);
Qiong Liucc3fe812019-09-23 15:25:44 +0800592
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700593 // Register for misc other intent broadcasts.
594 IntentFilter intentFilter =
595 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700596 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
597 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700598 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700599 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
600 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700601 registerReceiver(mReceiver, intentFilter);
602
Sarah Chin072ffb22022-05-03 17:58:59 -0700603 PhoneConfigurationManager.registerForMultiSimConfigChange(
604 mHandler, EVENT_MULTI_SIM_CONFIG_CHANGED, null);
605
606 mTelephonyCallbacks = new PhoneAppCallback[tm.getSupportedModemCount()];
Fangyuan Li7f5c2752022-06-29 18:02:31 +0800607 if (tm.getSupportedModemCount() > 0) {
608 for (Phone phone : PhoneFactory.getPhones()) {
609 int subId = phone.getSubId();
610 PhoneAppCallback callback = new PhoneAppCallback(subId);
611 tm.createForSubscriptionId(subId).registerTelephonyCallback(
612 TelephonyManager.INCLUDE_LOCATION_DATA_NONE, mHandler::post, callback);
613 mTelephonyCallbacks[phone.getPhoneId()] = callback;
614 }
Sarah Chin072ffb22022-05-03 17:58:59 -0700615 }
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700616 mCarrierVvmPackageInstalledReceiver.register(this);
617
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700618 //set the default values for the preferences in the phone.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700619 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700620 }
621
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700622 // XXX pre-load the SimProvider so that it's ready
623 resolver.getType(Uri.parse("content://icc/adn"));
624
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700625 // TODO: Register for Cdma Information Records
626 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
627
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700628 // Read HAC settings and configure audio hardware
629 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800630 int hac = android.provider.Settings.System.getInt(
631 getContentResolver(),
632 android.provider.Settings.System.HEARING_AID,
633 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700634 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Jordan Liuf71aeef2019-08-21 11:46:09 -0700635 audioManager.setParameters(
636 SettingsConstants.HAC_KEY + "=" + (hac == SettingsConstants.HAC_ENABLED
637 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700638 }
Siim Sammul182d61b2021-05-04 16:01:42 +0100639
640 // Start tracking Binder latency for the phone process.
641 mBinderCallsSettingsObserver = new BinderCallsStats.SettingsObserver(
642 getApplicationContext(),
Siim Sammula6950092021-06-22 17:14:03 +0100643 new BinderCallsStats(
644 new BinderCallsStats.Injector(),
645 com.android.internal.os.BinderLatencyProto.Dims.TELEPHONY));
Santos Cordonff506f52013-11-21 19:13:19 -0800646 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700647
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700648 /**
649 * Returns the singleton instance of the PhoneApp.
650 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800651 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700652 if (sMe == null) {
653 throw new IllegalStateException("No PhoneGlobals here!");
654 }
655 return sMe;
656 }
657
658 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800659 * Returns the default phone.
660 *
Andrew Lee385019f2014-11-24 14:19:50 -0800661 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700662 */
Andrew Lee83383e42014-10-31 12:42:28 -0700663 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800664 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700665 }
666
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800667 public static Phone getPhone(int subId) {
668 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800669 }
670
Santos Cordonde10b752013-09-19 04:11:33 -0700671 /* package */ CallManager getCallManager() {
672 return mCM;
673 }
674
Chris Manton4e9fa912015-06-19 11:26:57 -0700675 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800676 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700677 }
678
Chris Manton4e9fa912015-06-19 11:26:57 -0700679 public PersistableBundle getCarrierConfigForSubId(int subId) {
Philip P. Moltmann0079aae2020-03-05 16:24:02 -0800680 return configLoader.getConfigForSubIdWithFeature(subId, getOpPackageName(),
681 getAttributionTag());
Junda Liu605148f2015-04-28 15:23:40 -0700682 }
683
Jack Yu1a2fc352017-07-14 17:14:37 -0700684 private void registerSettingsObserver() {
685 mSettingsObserver.unobserve();
686 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
687 String mobileDataSetting = Settings.Global.MOBILE_DATA;
688 if (TelephonyManager.getDefault().getSimCount() > 1) {
689 int subId = mDefaultDataSubId;
690 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
691 dataRoamingSetting += subId;
692 mobileDataSetting += subId;
693 }
694 }
695
696 // Listen for user data roaming setting changed event
697 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
698 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
699
700 // Listen for mobile data setting changed event
701 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
702 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
703 }
704
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700705 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700706 * Sets the activity responsible for un-PUK-blocking the device
707 * so that we may close it when we receive a positive result.
708 * mPUKEntryActivity is also used to indicate to the device that
709 * we are trying to un-PUK-lock the phone. In other words, iff
710 * it is NOT null, then we are trying to unlock and waiting for
711 * the SIM to move to READY state.
712 *
713 * @param activity is the activity to close when PUK has
714 * finished unlocking. Can be set to null to indicate the unlock
715 * or SIM READYing process is over.
716 */
717 void setPukEntryActivity(Activity activity) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700718 Log.i(LOG_TAG, "setPukEntryActivity - set to " + (activity == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700719 mPUKEntryActivity = activity;
720 }
721
722 Activity getPUKEntryActivity() {
723 return mPUKEntryActivity;
724 }
725
726 /**
727 * Sets the dialog responsible for notifying the user of un-PUK-
728 * blocking - SIM READYing progress, so that we may dismiss it
729 * when we receive a positive result.
730 *
731 * @param dialog indicates the progress dialog informing the user
732 * of the state of the device. Dismissed upon completion of
733 * READYing process
734 */
735 void setPukEntryProgressDialog(ProgressDialog dialog) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700736 Log.i(LOG_TAG, "setPukEntryProgressDialog - set to "
737 + (dialog == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700738 mPUKEntryProgressDialog = dialog;
739 }
740
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700741 KeyguardManager getKeyguardManager() {
742 return mKeyguardManager;
743 }
744
745 private void onMMIComplete(AsyncResult r) {
746 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
747 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800748 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700749 }
750
fionaxu80126972017-02-01 17:01:26 -0800751 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700752 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700753 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700754 }
755
Taesu Lee62f826d2020-08-10 16:01:18 +0900756 private void handleAirplaneModeChange(boolean isAirplaneNewlyOn) {
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700757 Log.i(LOG_TAG, "handleAirplaneModeChange: isAirplaneNewlyOn=" + isAirplaneNewlyOn);
Taesu Lee62f826d2020-08-10 16:01:18 +0900758 int cellState =
759 Settings.Global.getInt(
760 getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
Chris Mantona09f3632016-02-09 14:48:42 -0800761 switch (cellState) {
762 case PhoneConstants.CELL_OFF_FLAG:
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700763 // Airplane mode does not affect the cell radio if user has turned it off.
764 Log.i(LOG_TAG, "Ignore airplane mode change due to cell off.");
Chris Mantona09f3632016-02-09 14:48:42 -0800765 break;
766 case PhoneConstants.CELL_ON_FLAG:
Taesu Lee62f826d2020-08-10 16:01:18 +0900767 maybeTurnCellOff(isAirplaneNewlyOn);
Chris Mantona09f3632016-02-09 14:48:42 -0800768 break;
769 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
Taesu Lee62f826d2020-08-10 16:01:18 +0900770 maybeTurnCellOn(isAirplaneNewlyOn);
Chris Mantona09f3632016-02-09 14:48:42 -0800771 break;
772 }
Hall Liu7f56e1a2019-07-10 14:41:14 -0700773 for (Phone phone : PhoneFactory.getPhones()) {
774 phone.getServiceStateTracker().onAirplaneModeChanged(isAirplaneNewlyOn);
775 }
Chris Mantona09f3632016-02-09 14:48:42 -0800776 }
777
778 /*
779 * Returns true if the radio must be turned off when entering airplane mode.
780 */
Taesu Lee62f826d2020-08-10 16:01:18 +0900781 private boolean isCellOffInAirplaneMode() {
782 String airplaneModeRadios =
783 Settings.Global.getString(
784 getContentResolver(), Settings.Global.AIRPLANE_MODE_RADIOS);
Chris Mantona09f3632016-02-09 14:48:42 -0800785 return airplaneModeRadios == null
786 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
787 }
788
Taesu Lee62f826d2020-08-10 16:01:18 +0900789 private void setRadioPowerOff() {
Chris Mantona09f3632016-02-09 14:48:42 -0800790 Log.i(LOG_TAG, "Turning radio off - airplane");
Taesu Lee62f826d2020-08-10 16:01:18 +0900791 Settings.Global.putInt(
792 getContentResolver(),
793 Settings.Global.CELL_ON,
794 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Chris Mantona09f3632016-02-09 14:48:42 -0800795 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
Taesu Lee62f826d2020-08-10 16:01:18 +0900796 TelephonyProperties.airplane_mode_on(true); // true means int value 1
Chris Mantona09f3632016-02-09 14:48:42 -0800797 PhoneUtils.setRadioPower(false);
Ling Ma317906d2022-12-05 15:58:14 -0800798 clearCacheOnRadioOff();
799 }
800
801 /** Clear fields on power off radio **/
802 private void clearCacheOnRadioOff() {
803 // Re-show is-roaming notifications after APM mode
sangyun35f23f82023-07-18 01:37:53 +0900804 mShownNotificationReasons.clear();
Chris Mantona09f3632016-02-09 14:48:42 -0800805 }
806
Taesu Lee62f826d2020-08-10 16:01:18 +0900807 private void setRadioPowerOn() {
Chris Mantona09f3632016-02-09 14:48:42 -0800808 Log.i(LOG_TAG, "Turning radio on - airplane");
Taesu Lee62f826d2020-08-10 16:01:18 +0900809 Settings.Global.putInt(
810 getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
811 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 1);
Meng Wang61307622019-10-23 14:08:43 -0700812 TelephonyProperties.airplane_mode_on(false); // false means int value 0
Chris Mantona09f3632016-02-09 14:48:42 -0800813 PhoneUtils.setRadioPower(true);
814 }
815
Taesu Lee62f826d2020-08-10 16:01:18 +0900816 private void maybeTurnCellOff(boolean isAirplaneNewlyOn) {
Chris Mantona09f3632016-02-09 14:48:42 -0800817 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700818 // If we are trying to turn off the radio, make sure there are no active
819 // emergency calls. If there are, switch airplane mode back to off.
Taesu Lee62f826d2020-08-10 16:01:18 +0900820 TelecomManager tm = (TelecomManager) getSystemService(TELECOM_SERVICE);
Tyler Gunn900d8fd2018-09-21 09:22:12 -0700821
822 if (tm != null && tm.isInEmergencyCall()) {
Santos Cordone18902f2016-03-22 17:16:04 -0700823 // Switch airplane mode back to off.
Jordan Liu0e819b12019-08-28 15:33:05 -0700824 ConnectivityManager cm =
Taesu Lee62f826d2020-08-10 16:01:18 +0900825 (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
Jordan Liu0e819b12019-08-28 15:33:05 -0700826 cm.setAirplaneMode(false);
Santos Cordone18902f2016-03-22 17:16:04 -0700827 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
828 .show();
829 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Taesu Lee62f826d2020-08-10 16:01:18 +0900830 } else if (isCellOffInAirplaneMode()) {
831 setRadioPowerOff();
Santos Cordone18902f2016-03-22 17:16:04 -0700832 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800833 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700834 }
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700835 } else {
836 Log.i(LOG_TAG, "Ignoring airplane mode: not newly on");
Chris Mantona09f3632016-02-09 14:48:42 -0800837 }
838 }
839
Taesu Lee62f826d2020-08-10 16:01:18 +0900840 private void maybeTurnCellOn(boolean isAirplaneNewlyOn) {
Chris Mantona09f3632016-02-09 14:48:42 -0800841 if (!isAirplaneNewlyOn) {
Taesu Lee62f826d2020-08-10 16:01:18 +0900842 setRadioPowerOn();
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700843 } else {
844 Log.i(LOG_TAG, "Ignoring airplane mode off: radio is already on.");
Santos Cordone18902f2016-03-22 17:16:04 -0700845 }
846 }
847
Santos Cordon593ab382013-08-06 21:58:23 -0700848 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700849 * Receiver for misc intent broadcasts the Phone app cares about.
850 */
851 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
852 @Override
853 public void onReceive(Context context, Intent intent) {
854 String action = intent.getAction();
855 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Taesu Lee3dc572b2020-08-07 18:16:22 +0900856 boolean airplaneMode = intent.getBooleanExtra("state", false);
Taesu Lee62f826d2020-08-10 16:01:18 +0900857 handleAirplaneModeChange(airplaneMode);
Amit Mahajanf5d92c82018-11-02 17:44:40 -0700858 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
859 // re-register as it may be a new IccCard
860 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
861 SubscriptionManager.INVALID_PHONE_INDEX);
862 if (SubscriptionManager.isValidPhoneId(phoneId)) {
863 PhoneUtils.unregisterIccStatus(mHandler, phoneId);
864 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED, phoneId);
865 }
Nazish Tabassum160d2112019-12-23 17:31:33 +0530866 String iccStatus = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
867 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
868 new EventSimStateChangedBag(phoneId, iccStatus)));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700869 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
870 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800871 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
872 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700873 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530874 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530875 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530876 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
877 if (phoneInEcm != null) {
878 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
879 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
880 // Start Emergency Callback Mode service
Daniel Bright30efde42020-01-09 22:11:15 -0800881 if (intent.getBooleanExtra(
882 TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530883 context.startService(new Intent(context,
884 EmergencyCallbackModeService.class));
885 } else {
886 phoneInEcm = null;
887 }
888 } else {
889 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
890 // on a device that doesn't support ECM in the first place.
891 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
892 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
893 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700894 }
895 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530896 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700897 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700898 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
899 // Roaming status could be overridden by carrier config, so we need to update it.
900 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
sangyun35f23f82023-07-18 01:37:53 +0900901 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED);
chen xubaf9fe52019-07-02 17:28:24 -0700902 updateLimitedSimFunctionForDualSim();
Lei Liu863eac02020-06-24 20:12:55 +0800903 int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
904 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
905 if (SubscriptionManager.isValidSubscriptionId(subId)) {
906 mHandler.sendMessage(mHandler.obtainMessage(EVENT_CARRIER_CONFIG_CHANGED,
907 new Integer(subId)));
908 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700909 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
910 // We also need to pay attention when default data subscription changes.
911 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
912 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
913 registerSettingsObserver();
914 Phone phone = getPhone(mDefaultDataSubId);
915 if (phone != null) {
sangyun35f23f82023-07-18 01:37:53 +0900916 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700917 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700918 }
919 }
920 }
921
Sarah Chin072ffb22022-05-03 17:58:59 -0700922 private void handleServiceStateChanged(ServiceState serviceState, int subId) {
Jack Yu1a2fc352017-07-14 17:14:37 -0700923 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Sarah Chin072ffb22022-05-03 17:58:59 -0700924 int state = serviceState.getState();
925 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -0700926
Sarah Chin072ffb22022-05-03 17:58:59 -0700927 if (VDBG) {
928 Log.v(LOG_TAG, "subId=" + subId + ", mDefaultDataSubId="
929 + mDefaultDataSubId + ", ss roaming=" + serviceState.getDataRoaming());
930 }
931 if (subId == mDefaultDataSubId) {
sangyun35f23f82023-07-18 01:37:53 +0900932 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700933 }
934 }
935
Jack Yu1a2fc352017-07-14 17:14:37 -0700936 /**
937 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
938 * to notify the user so they can enable it through settings. Vise versa if the condition
939 * changes, we need to dismiss the notification.
sangyun35f23f82023-07-18 01:37:53 +0900940 * @param reason to inform which event is called for notification update.
Jack Yu1a2fc352017-07-14 17:14:37 -0700941 */
sangyun35f23f82023-07-18 01:37:53 +0900942 private void updateDataRoamingStatus(@RoamingNotificationReason int reason) {
Jack Yu1a2fc352017-07-14 17:14:37 -0700943 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
944 Phone phone = getPhone(mDefaultDataSubId);
945 if (phone == null) {
946 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
947 return;
948 }
949
sangyun35f23f82023-07-18 01:37:53 +0900950 ServiceState serviceState = phone.getServiceState();
951 String roamingNumeric = serviceState.getOperatorNumeric();
952 String roamingNumericReason = "RoamingNumeric=" + roamingNumeric;
953 String callingReason = "CallingReason=" + reason;
954 boolean dataIsNowRoaming = serviceState.getDataRoaming();
Jack Yu3e2ac6e2022-03-26 13:59:45 -0700955 boolean dataAllowed;
956 boolean notAllowedDueToRoamingOff;
Sarah Chine04784a2022-10-31 20:32:34 -0700957 List<DataDisallowedReason> reasons = phone.getDataNetworkController()
958 .getInternetDataDisallowedReasons();
Jack Yu7968c6d2022-07-31 00:43:21 -0700959 dataAllowed = reasons.isEmpty();
960 notAllowedDueToRoamingOff = (reasons.size() == 1
961 && reasons.contains(DataDisallowedReason.ROAMING_DISABLED));
sangyun35f23f82023-07-18 01:37:53 +0900962 StringBuilder sb = new StringBuilder("updateDataRoamingStatus");
963 sb.append(" dataAllowed=").append(dataAllowed);
964 sb.append(", reasons=").append(reasons);
965 sb.append(", dataIsNowRoaming=").append(dataIsNowRoaming);
966 sb.append(", ").append(roamingNumericReason);
967 sb.append(", ").append(callingReason);
968 mDataRoamingNotifLog.log(sb.toString());
Ling Ma317906d2022-12-05 15:58:14 -0800969 if (VDBG) {
sangyun35f23f82023-07-18 01:37:53 +0900970 Log.v(LOG_TAG, sb.toString());
Ling Ma317906d2022-12-05 15:58:14 -0800971 }
Jack Yu3e2ac6e2022-03-26 13:59:45 -0700972
sangyun35f23f82023-07-18 01:37:53 +0900973 // Determine if a given roaming numeric has never been shown.
974 boolean shownInThisNumeric = false;
975 if (reason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED
976 || reason == ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED) {
977 shownInThisNumeric = mShownNotificationReasons.contains(roamingNumericReason);
978 }
979 // Determine if a notification has never been shown by given calling reason.
980 boolean shownForThisReason = mShownNotificationReasons.contains(callingReason);
981
Jack Yu3e2ac6e2022-03-26 13:59:45 -0700982 if (!dataAllowed && notAllowedDueToRoamingOff) {
sangyun35f23f82023-07-18 01:37:53 +0900983 if (!shownInThisNumeric && roamingNumeric != null) {
984 mShownNotificationReasons.add(roamingNumericReason);
985 }
986 if (!shownForThisReason
987 && reason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED) {
988 mShownNotificationReasons.add(callingReason);
Ling Ma4e15c322022-12-07 11:20:53 -0800989 }
Jordan Liuff2ccd72019-07-23 15:54:41 -0700990 // No need to show it again if we never cancelled it explicitly.
sangyun35f23f82023-07-18 01:37:53 +0900991 if (getCurrentRoamingNotification() == ROAMING_NOTIFICATION_DISCONNECTED) {
992 return;
993 }
994
Jack Yu1a2fc352017-07-14 17:14:37 -0700995 // If the only reason of no data is data roaming disabled, then we notify the user
996 // so the user can turn on data roaming.
sangyun35f23f82023-07-18 01:37:53 +0900997 if (!shownInThisNumeric && !shownForThisReason) {
998 updateDataRoamingNotification(ROAMING_NOTIFICATION_DISCONNECTED);
999 } else {
1000 // Don't show roaming notification if we've already shown for this MccMnc
1001 Log.d(LOG_TAG, "Skip roaming disconnected notification since already"
1002 + " shownInThisNumeric=" + shownInThisNumeric
1003 + " shownForThisReason=" + shownForThisReason);
1004 // Dismiss notification if the other notification is shown.
1005 if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
1006 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
1007 }
1008 }
1009 } else if (dataAllowed && dataIsNowRoaming) {
1010 if (!shownInThisNumeric && roamingNumeric != null) {
1011 mShownNotificationReasons.add(roamingNumericReason);
1012 }
1013 if (!shownForThisReason
1014 && reason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED) {
1015 mShownNotificationReasons.add(callingReason);
1016 }
Ling Ma4e15c322022-12-07 11:20:53 -08001017 boolean isShowRoamingNotificationEnabled = getCarrierConfigForSubId(mDefaultDataSubId)
1018 .getBoolean(CarrierConfigManager
1019 .KEY_SHOW_DATA_CONNECTED_ROAMING_NOTIFICATION_BOOL);
sangyun35f23f82023-07-18 01:37:53 +09001020 // No need to show it again if we never cancelled it explicitly.
1021 if (getCurrentRoamingNotification() == ROAMING_NOTIFICATION_CONNECTED) {
Ling Ma4e15c322022-12-07 11:20:53 -08001022 return;
1023 }
sangyun35f23f82023-07-18 01:37:53 +09001024
1025 // Inform users that roaming charges may apply.
1026 if (!shownInThisNumeric && !shownForThisReason && isShowRoamingNotificationEnabled) {
1027 updateDataRoamingNotification(ROAMING_NOTIFICATION_CONNECTED);
1028 } else {
1029 // Don't show roaming notification if we've already shown for this MccMnc or
1030 // disabled from carrier config.
1031 Log.d(LOG_TAG, "Skip roaming connected notification since already"
1032 + " shownInThisNumeric:" + shownInThisNumeric
1033 + " shownForThisReason:" + shownForThisReason
1034 + " isShowRoamingNotificationEnabled:" + isShowRoamingNotificationEnabled);
1035 // Dismiss notification if the other notification is shown.
1036 if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
1037 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
1038 }
1039 }
1040 } else if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
Jordan Liuff2ccd72019-07-23 15:54:41 -07001041 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
1042 // is not the only data disable reason. In this case we dismiss the notification we
1043 // showed earlier.
sangyun35f23f82023-07-18 01:37:53 +09001044 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
Jack Yu1a2fc352017-07-14 17:14:37 -07001045 }
1046 }
1047
sangyun35f23f82023-07-18 01:37:53 +09001048 private void updateDataRoamingNotification(@RoamingNotification int roamingNotification) {
1049 int event;
1050 switch (roamingNotification) {
1051 case ROAMING_NOTIFICATION_NO_NOTIFICATION:
1052 Log.d(LOG_TAG, "Dismiss roaming notification");
1053 mDataRoamingNotifLog.log("Hide roaming.");
1054 event = EVENT_DATA_ROAMING_OK;
1055 break;
1056 case ROAMING_NOTIFICATION_CONNECTED:
1057 Log.d(LOG_TAG, "Show roaming connected notification");
1058 mDataRoamingNotifLog.log("Show roaming on.");
1059 event = EVENT_DATA_ROAMING_CONNECTED;
1060 break;
1061 case ROAMING_NOTIFICATION_DISCONNECTED:
1062 Log.d(LOG_TAG, "Show roaming disconnected notification");
1063 mDataRoamingNotifLog.log("Show roaming off.");
1064 event = EVENT_DATA_ROAMING_DISCONNECTED;
1065 break;
1066 default:
1067 Log.d(LOG_TAG, "Should never reach here.");
1068 mDataRoamingNotifLog.log("Should never reach here.");
1069 return;
1070 }
1071 mCurrentRoamingNotification = roamingNotification;
1072 mHandler.obtainMessage(event, mDefaultDataSubId, 0).sendToTarget();
1073 }
1074
1075 private @RoamingNotification int getCurrentRoamingNotification() {
1076 return mCurrentRoamingNotification;
1077 }
1078
Jordan Liuff2ccd72019-07-23 15:54:41 -07001079 /**
1080 *
1081 * @param subId to check roaming on
1082 * @return whether we have transitioned to dataRoaming
1083 */
1084 private boolean dataIsNowRoaming(int subId) {
Sarah Chine04784a2022-10-31 20:32:34 -07001085 return getPhone(subId).getServiceState().getDataRoaming();
Jordan Liuff2ccd72019-07-23 15:54:41 -07001086 }
1087
chen xubaf9fe52019-07-02 17:28:24 -07001088 private void updateLimitedSimFunctionForDualSim() {
1089 if (DBG) Log.d(LOG_TAG, "updateLimitedSimFunctionForDualSim");
1090 // check conditions to display limited SIM function notification under dual SIM
1091 SubscriptionManager subMgr = (SubscriptionManager) getSystemService(
1092 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
1093 List<SubscriptionInfo> subList = subMgr.getActiveSubscriptionInfoList(false);
1094 if (subList != null && subList.size() > 1) {
1095 CarrierConfigManager configMgr = (CarrierConfigManager)
1096 getSystemService(Context.CARRIER_CONFIG_SERVICE);
1097 for (SubscriptionInfo info : subList) {
1098 PersistableBundle b = configMgr.getConfigForSubId(info.getSubscriptionId());
1099 if (b != null) {
1100 if (b.getBoolean(CarrierConfigManager
1101 .KEY_LIMITED_SIM_FUNCTION_NOTIFICATION_FOR_DSDS_BOOL)) {
1102 notificationMgr.showLimitedSimFunctionWarningNotification(
1103 info.getSubscriptionId(),
1104 info.getDisplayName().toString());
1105 } else {
1106 notificationMgr.dismissLimitedSimFunctionWarningNotification(
1107 info.getSubscriptionId());
1108 }
1109 }
1110 }
1111 } else {
1112 // cancel notifications for all subs
1113 notificationMgr.dismissLimitedSimFunctionWarningNotification(
1114 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1115 }
1116 notificationMgr.dismissLimitedSimFunctionWarningNotificationForInactiveSubs();
1117
1118 }
1119
Sandeep Kuntade73a6a2014-10-15 18:45:56 +05301120 public Phone getPhoneInEcm() {
1121 return phoneInEcm;
1122 }
1123
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001124 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -08001125 * Triggers a refresh of the message waiting (voicemail) indicator.
1126 *
1127 * @param subId the subscription id we should refresh the notification for.
1128 */
1129 public void refreshMwiIndicator(int subId) {
1130 notificationMgr.refreshMwi(subId);
1131 }
1132
1133 /**
Pengquan Mengdd9ac822018-09-20 15:25:35 -07001134 * Called when the network selection on the subscription {@code subId} is changed by the user.
1135 *
1136 * @param subId the subscription id.
1137 */
1138 public void onNetworkSelectionChanged(int subId) {
1139 Phone phone = getPhone(subId);
1140 if (phone != null) {
1141 notificationMgr.updateNetworkSelection(phone.getServiceState().getState(), subId);
1142 } else {
1143 Log.w(LOG_TAG, "onNetworkSelectionChanged on null phone, subId: " + subId);
1144 }
1145 }
1146
1147 /**
James.cf Lin4b784aa2021-01-31 03:25:15 +08001148 * @return whether the device supports RCS User Capability Exchange or not.
1149 */
1150 public boolean getDeviceUceEnabled() {
1151 return (mTelephonyRcsService == null) ? false : mTelephonyRcsService.isDeviceUceEnabled();
1152 }
1153
1154 /**
1155 * Set the device supports RCS User Capability Exchange.
1156 * @param isEnabled true if the device supports UCE.
1157 */
1158 public void setDeviceUceEnabled(boolean isEnabled) {
1159 if (mTelephonyRcsService != null) {
1160 mTelephonyRcsService.setDeviceUceEnabled(isEnabled);
1161 }
1162 }
1163
1164 /**
Jack Yu1a2fc352017-07-14 17:14:37 -07001165 * Dump the state of the object, add calls to other objects as desired.
1166 *
1167 * @param fd File descriptor
1168 * @param printWriter Print writer
1169 * @param args Arguments
1170 */
1171 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
1172 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
1173 pw.println("------- PhoneGlobals -------");
1174 pw.increaseIndent();
sangyun35f23f82023-07-18 01:37:53 +09001175 pw.println("mCurrentRoamingNotification=" + mCurrentRoamingNotification);
Jack Yu1a2fc352017-07-14 17:14:37 -07001176 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
Keun young Parkdebb8532019-05-30 16:35:27 -07001177 pw.println("isSmsCapable=" + TelephonyManager.from(this).isSmsCapable());
sangyun35f23f82023-07-18 01:37:53 +09001178 pw.println("mDataRoamingNotifLog:");
Jack Yu1a2fc352017-07-14 17:14:37 -07001179 pw.increaseIndent();
1180 mDataRoamingNotifLog.dump(fd, pw, args);
1181 pw.decreaseIndent();
Brad Ebinger05f52c22019-12-05 13:03:21 -08001182 pw.println("ImsResolver:");
1183 pw.increaseIndent();
1184 try {
Brad Ebingerd1947d82021-05-17 20:54:49 +00001185 if (ImsResolver.getInstance() != null) ImsResolver.getInstance().dump(fd, pw, args);
Brad Ebinger05f52c22019-12-05 13:03:21 -08001186 } catch (Exception e) {
1187 e.printStackTrace();
1188 }
1189 pw.decreaseIndent();
Brad Ebingera68a4972020-01-30 17:31:23 -08001190 pw.println("RcsService:");
1191 try {
1192 if (mTelephonyRcsService != null) mTelephonyRcsService.dump(fd, pw, args);
1193 } catch (Exception e) {
1194 e.printStackTrace();
1195 }
Hunsuk Choi89bd22c2021-11-01 13:04:54 +00001196 pw.println("ImsStateCallbackController:");
1197 try {
1198 if (mImsStateCallbackController != null) mImsStateCallbackController.dump(pw);
1199 } catch (Exception e) {
1200 e.printStackTrace();
1201 }
Hwangoo Parkba21cf22022-11-30 14:34:04 +00001202 pw.println("DomainSelectionResolver:");
1203 pw.increaseIndent();
1204 try {
1205 if (DomainSelectionResolver.getInstance() != null) {
1206 DomainSelectionResolver.getInstance().dump(fd, pw, args);
1207 }
1208 } catch (Exception e) {
1209 e.printStackTrace();
1210 }
1211 pw.decreaseIndent();
1212 if (mDomainSelectionService != null) {
1213 mDomainSelectionService.dump(fd, pw, args);
1214 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001215 pw.decreaseIndent();
sangyun35f23f82023-07-18 01:37:53 +09001216 pw.println("mShownNotificationReasons=" + mShownNotificationReasons);
Jack Yu1a2fc352017-07-14 17:14:37 -07001217 pw.println("------- End PhoneGlobals -------");
1218 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001219}