blob: b8ac8b92d2e99e390e045fb647393301c97ce1d2 [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;
Brad Ebinger05f52c22019-12-05 13:03:21 -080073import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn92479152021-01-20 16:30:10 -080074import com.android.internal.telephony.imsphone.ImsPhone;
75import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000076import com.android.internal.telephony.satellite.SatelliteController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000077import com.android.internal.telephony.uicc.UiccPort;
Jordan Liu06bdef12021-03-24 17:25:46 -070078import com.android.internal.telephony.uicc.UiccProfile;
Jack Yu1a2fc352017-07-14 17:14:37 -070079import com.android.internal.util.IndentingPrintWriter;
Andrew Leefb7f92e2015-02-26 16:23:32 -080080import com.android.phone.settings.SettingsConstants;
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -070081import com.android.phone.vvm.CarrierVvmPackageInstalledReceiver;
Hwangoo Parkba21cf22022-11-30 14:34:04 +000082import com.android.services.telephony.domainselection.TelephonyDomainSelectionService;
James.cf Linc9f35a42020-01-15 02:35:22 +080083import com.android.services.telephony.rcs.TelephonyRcsService;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070084
Jack Yu1a2fc352017-07-14 17:14:37 -070085import java.io.FileDescriptor;
86import java.io.PrintWriter;
Jordan Liuff2ccd72019-07-23 15:54:41 -070087import java.lang.annotation.Retention;
88import java.lang.annotation.RetentionPolicy;
chen xubaf9fe52019-07-02 17:28:24 -070089import java.util.List;
Jack Yu1a2fc352017-07-14 17:14:37 -070090
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091/**
92 * Global state for the telephony subsystem when running in the primary
93 * phone process.
94 */
Sailesh Nepalbf900542014-07-15 16:18:32 -070095public class PhoneGlobals extends ContextWrapper {
Jack Yu1a2fc352017-07-14 17:14:37 -070096 public static final String LOG_TAG = "PhoneGlobals";
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097
98 /**
99 * Phone app-wide debug level:
100 * 0 - no debug logging
101 * 1 - normal debug logging if ro.debuggable is set (which is true in
102 * "eng" and "userdebug" builds but not "user" builds)
103 * 2 - ultra-verbose debug logging
104 *
105 * Most individual classes in the phone app have a local DBG constant,
106 * typically set to
107 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
108 * or else
109 * (PhoneApp.DBG_LEVEL >= 2)
110 * depending on the desired verbosity.
111 *
112 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
113 */
Andrew Lee88b51e22014-10-29 15:48:51 -0700114 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115
116 private static final boolean DBG =
117 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
118 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
119
120 // Message codes; see mHandler below.
121 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700122 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
Jordan Liuff2ccd72019-07-23 15:54:41 -0700124 private static final int EVENT_DATA_ROAMING_CONNECTED = 11;
125 private static final int EVENT_DATA_ROAMING_OK = 12;
126 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 13;
Jordan Liuff2ccd72019-07-23 15:54:41 -0700127 private static final int EVENT_DATA_ROAMING_SETTINGS_CHANGED = 15;
128 private static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED = 16;
Lei Liu863eac02020-06-24 20:12:55 +0800129 private static final int EVENT_CARRIER_CONFIG_CHANGED = 17;
Sarah Chin072ffb22022-05-03 17:58:59 -0700130 private static final int EVENT_MULTI_SIM_CONFIG_CHANGED = 18;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131
132 // The MMI codes are also used by the InCallScreen.
133 public static final int MMI_INITIATE = 51;
134 public static final int MMI_COMPLETE = 52;
135 public static final int MMI_CANCEL = 53;
136 // Don't use message codes larger than 99 here; those are reserved for
137 // the individual Activities of the Phone UI.
138
Santos Cordone18902f2016-03-22 17:16:04 -0700139 public static final int AIRPLANE_ON = 1;
140 public static final int AIRPLANE_OFF = 0;
141
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142 /**
143 * Allowable values for the wake lock code.
144 * SLEEP means the device can be put to sleep.
145 * PARTIAL means wake the processor, but we display can be kept off.
146 * FULL means wake both the processor and the display.
147 */
148 public enum WakeState {
149 SLEEP,
150 PARTIAL,
151 FULL
152 }
153
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154 private static PhoneGlobals sMe;
155
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700156 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700157 CallNotifier notifier;
Santos Cordon63a84242013-07-23 13:32:52 -0700158 NotificationMgr notificationMgr;
James.cf Linc9f35a42020-01-15 02:35:22 +0800159 TelephonyRcsService mTelephonyRcsService;
Andrew Lee9431b832015-03-09 18:46:45 -0700160 public PhoneInterfaceManager phoneMgr;
James.cf Linaf3183c2019-10-24 00:59:00 +0800161 public ImsRcsController imsRcsController;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000162 public ImsStateCallbackController mImsStateCallbackController;
joonhunshincffb7fc2021-11-28 07:32:01 +0000163 public ImsProvisioningController mImsProvisioningController;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800164 CarrierConfigLoader configLoader;
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000165 TelephonyDomainSelectionService mDomainSelectionService;
Santos Cordon63a84242013-07-23 13:32:52 -0700166
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530167 private Phone phoneInEcm;
Santos Cordon63a84242013-07-23 13:32:52 -0700168
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700169 static boolean sVoiceCapable = true;
170
Santos Cordonc593d002015-06-03 15:41:15 -0700171 // TODO: Remove, no longer used.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172 CdmaPhoneCallState cdmaPhoneCallState;
173
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174 // The currently-active PUK entry activity and progress dialog.
175 // Normally, these are the Emergency Dialer and the subsequent
176 // progress dialog. null if there is are no such objects in
177 // the foreground.
178 private Activity mPUKEntryActivity;
179 private ProgressDialog mPUKEntryProgressDialog;
180
Jordan Liuff2ccd72019-07-23 15:54:41 -0700181 /** @hide */
182 @Retention(RetentionPolicy.SOURCE)
sangyun35f23f82023-07-18 01:37:53 +0900183 @IntDef(prefix = {"ROAMING_NOTIFICATION_REASON_"},
184 value = {
185 ROAMING_NOTIFICATION_REASON_DATA_SETTING_CHANGED,
186 ROAMING_NOTIFICATION_REASON_DATA_ROAMING_SETTING_CHANGED,
187 ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED,
188 ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED,
189 ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED})
190 public @interface RoamingNotificationReason {}
191 private static final int ROAMING_NOTIFICATION_REASON_DATA_SETTING_CHANGED = 0;
192 private static final int ROAMING_NOTIFICATION_REASON_DATA_ROAMING_SETTING_CHANGED = 1;
193 private static final int ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED = 2;
194 private static final int ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED = 3;
195 private static final int ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED = 4;
196
197 /** @hide */
198 @Retention(RetentionPolicy.SOURCE)
Jordan Liuff2ccd72019-07-23 15:54:41 -0700199 @IntDef(prefix = {"ROAMING_NOTIFICATION_"},
200 value = {
201 ROAMING_NOTIFICATION_NO_NOTIFICATION,
202 ROAMING_NOTIFICATION_CONNECTED,
203 ROAMING_NOTIFICATION_DISCONNECTED})
204 public @interface RoamingNotification {}
205
206 private static final int ROAMING_NOTIFICATION_NO_NOTIFICATION = 0;
207 private static final int ROAMING_NOTIFICATION_CONNECTED = 1;
208 private static final int ROAMING_NOTIFICATION_DISCONNECTED = 2;
209
210 @RoamingNotification
sangyun35f23f82023-07-18 01:37:53 +0900211 private int mCurrentRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
Jack Yu953f9352017-05-18 14:41:06 -0700212
sangyun35f23f82023-07-18 01:37:53 +0900213 /**
214 * Reasons that have already shown notification to prevent duplicate shows for the same reason.
215 */
216 private ArraySet<String> mShownNotificationReasons = new ArraySet<>();
Ling Ma317906d2022-12-05 15:58:14 -0800217
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700218 private WakeState mWakeState = WakeState.SLEEP;
219
220 private PowerManager mPowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700221 private PowerManager.WakeLock mWakeLock;
222 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700223 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700224
Jack Yu1a2fc352017-07-14 17:14:37 -0700225 private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
226 private final LocalLog mDataRoamingNotifLog = new LocalLog(50);
227
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228 // Broadcast receiver for various intent broadcasts (see onCreate())
229 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
230
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700231 private final CarrierVvmPackageInstalledReceiver mCarrierVvmPackageInstalledReceiver =
232 new CarrierVvmPackageInstalledReceiver();
233
Jack Yu1a2fc352017-07-14 17:14:37 -0700234 private final SettingsObserver mSettingsObserver;
Siim Sammul182d61b2021-05-04 16:01:42 +0100235 private BinderCallsStats.SettingsObserver mBinderCallsSettingsObserver;
Jack Yu1a2fc352017-07-14 17:14:37 -0700236
Sarah Chin072ffb22022-05-03 17:58:59 -0700237 // Mapping of phone ID to the associated TelephonyCallback. These should be registered without
238 // fine or coarse location since we only use ServiceState for
239 private PhoneAppCallback[] mTelephonyCallbacks;
240
241 private class PhoneAppCallback extends TelephonyCallback implements
242 TelephonyCallback.ServiceStateListener {
243 private final int mSubId;
244
245 PhoneAppCallback(int subId) {
246 mSubId = subId;
247 }
248
249 @Override
250 public void onServiceStateChanged(ServiceState serviceState) {
251 // Note when registering that we should be registering with INCLUDE_LOCATION_DATA_NONE.
252 // PhoneGlobals only uses the state and roaming status, which does not require location.
253 handleServiceStateChanged(serviceState, mSubId);
254 }
255
256 public int getSubId() {
257 return mSubId;
258 }
259 }
260
Nazish Tabassum160d2112019-12-23 17:31:33 +0530261 private static class EventSimStateChangedBag {
262 final int mPhoneId;
263 final String mIccStatus;
264
265 EventSimStateChangedBag(int phoneId, String iccStatus) {
266 mPhoneId = phoneId;
267 mIccStatus = iccStatus;
268 }
269 }
270
Jordan Liu06bdef12021-03-24 17:25:46 -0700271 // Some carrier config settings disable the network lock screen, so we call handleSimLock
272 // when either SIM_LOCK or CARRIER_CONFIG changes so that no matter which one happens first,
273 // we still do the right thing
274 private void handleSimLock(int subType, Phone phone) {
275 PersistableBundle cc = getCarrierConfigForSubId(phone.getSubId());
276 if (!CarrierConfigManager.isConfigForIdentifiedCarrier(cc)) {
277 // If we only have the default carrier config just return, to avoid popping up the
278 // the SIM lock screen when it's disabled by the carrier.
279 Log.i(LOG_TAG, "Not showing 'SIM network unlock' screen. Carrier config not loaded");
280 return;
281 }
282 if (cc.getBoolean(CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
283 // Some products don't have the concept of a "SIM network lock"
284 Log.i(LOG_TAG, "Not showing 'SIM network unlock' screen. Disabled by carrier config");
285 return;
286 }
287
288 // if passed in subType is unknown, retrieve it here.
289 if (subType == -1) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000290 final UiccPort uiccPort = phone.getUiccPort();
291 if (uiccPort == null) {
Jordan Liu06bdef12021-03-24 17:25:46 -0700292 Log.e(LOG_TAG,
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000293 "handleSimLock: uiccPort for phone " + phone.getPhoneId() + " is null");
Jordan Liu06bdef12021-03-24 17:25:46 -0700294 return;
295 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000296 final UiccProfile uiccProfile = uiccPort.getUiccProfile();
Jordan Liu06bdef12021-03-24 17:25:46 -0700297 if (uiccProfile == null) {
298 Log.e(LOG_TAG,
299 "handleSimLock: uiccProfile for phone " + phone.getPhoneId() + " is null");
300 return;
301 }
302 subType = uiccProfile.getApplication(
303 uiccProfile.mCurrentAppType).getPersoSubState().ordinal();
304 }
305 // Normal case: show the "SIM network unlock" PIN entry screen.
306 // The user won't be able to do anything else until
307 // they enter a valid SIM network PIN.
308 Log.i(LOG_TAG, "show sim depersonal panel");
309 IccNetworkDepersonalizationPanel.showDialog(phone, subType);
310 }
311
312 private boolean isSimLocked(Phone phone) {
313 TelephonyManager tm = getSystemService(TelephonyManager.class);
314 return tm.createForSubscriptionId(phone.getSubId()).getSimState()
315 == TelephonyManager.SIM_STATE_NETWORK_LOCKED;
316 }
317
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700318 Handler mHandler = new Handler() {
319 @Override
320 public void handleMessage(Message msg) {
321 PhoneConstants.State phoneState;
Jack Yu1a2fc352017-07-14 17:14:37 -0700322 if (VDBG) Log.v(LOG_TAG, "event=" + msg.what);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700323 switch (msg.what) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700324 // TODO: This event should be handled by the lock screen, just
325 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
326 case EVENT_SIM_NETWORK_LOCKED:
Jordan Liu06bdef12021-03-24 17:25:46 -0700327 int subType = (Integer) ((AsyncResult) msg.obj).result;
328 Phone phone = (Phone) ((AsyncResult) msg.obj).userObj;
329 handleSimLock(subType, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700330 break;
331
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332 case EVENT_DATA_ROAMING_DISCONNECTED:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700333 notificationMgr.showDataRoamingNotification(msg.arg1, false);
334 break;
335
336 case EVENT_DATA_ROAMING_CONNECTED:
337 notificationMgr.showDataRoamingNotification(msg.arg1, true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338 break;
339
340 case EVENT_DATA_ROAMING_OK:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700341 notificationMgr.hideDataRoamingNotification();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342 break;
343
344 case MMI_COMPLETE:
345 onMMIComplete((AsyncResult) msg.obj);
346 break;
347
348 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800349 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350 break;
351
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700352 case EVENT_SIM_STATE_CHANGED:
Nazish Tabassum160d2112019-12-23 17:31:33 +0530353 EventSimStateChangedBag bag = (EventSimStateChangedBag)msg.obj;
Sarah Chin010884c2023-06-14 15:55:08 -0700354 // Dismiss the "No services" notification if the SIM is removed.
355 if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(bag.mIccStatus)) {
356 notificationMgr.dismissNetworkSelectionNotificationForInactiveSubId();
357 }
358
359 // Marks the event where the SIM goes into ready state.
360 // Right now, this is only used for the PUK-unlocking process.
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700361 if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(bag.mIccStatus)
Nazish Tabassum59126a92020-07-03 21:44:49 +0530362 || IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(bag.mIccStatus)
363 || IccCardConstants.INTENT_VALUE_ICC_NOT_READY.equals(bag.mIccStatus)
364 || IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(bag.mIccStatus)) {
Sarah Chin010884c2023-06-14 15:55:08 -0700365 // When the right event is triggered and there are UI objects in the
366 // foreground, we close them to display the lock panel.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367 if (mPUKEntryActivity != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700368 Log.i(LOG_TAG, "Dismiss puk entry activity");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369 mPUKEntryActivity.finish();
370 mPUKEntryActivity = null;
371 }
372 if (mPUKEntryProgressDialog != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700373 Log.i(LOG_TAG, "Dismiss puk progress dialog");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374 mPUKEntryProgressDialog.dismiss();
375 mPUKEntryProgressDialog = null;
376 }
Nazish Tabassum59126a92020-07-03 21:44:49 +0530377 Log.i(LOG_TAG, "Dismissing depersonal panel" + (bag.mIccStatus));
Nazish Tabassum160d2112019-12-23 17:31:33 +0530378 IccNetworkDepersonalizationPanel.dialogDismiss(bag.mPhoneId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700379 }
380 break;
381
382 case EVENT_UNSOL_CDMA_INFO_RECORD:
383 //TODO: handle message here;
384 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700385 case EVENT_DATA_ROAMING_SETTINGS_CHANGED:
sangyun35f23f82023-07-18 01:37:53 +0900386 updateDataRoamingStatus(
387 ROAMING_NOTIFICATION_REASON_DATA_ROAMING_SETTING_CHANGED);
388 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700389 case EVENT_MOBILE_DATA_SETTINGS_CHANGED:
sangyun35f23f82023-07-18 01:37:53 +0900390 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_DATA_SETTING_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700391 break;
Lei Liu863eac02020-06-24 20:12:55 +0800392 case EVENT_CARRIER_CONFIG_CHANGED:
393 int subId = (Integer) msg.obj;
394 // The voicemail number could be overridden by carrier config, so need to
395 // refresh the message waiting (voicemail) indicator.
396 refreshMwiIndicator(subId);
Jordan Liu06bdef12021-03-24 17:25:46 -0700397 phone = getPhone(subId);
Sarah Chin072ffb22022-05-03 17:58:59 -0700398 if (phone != null) {
399 if (isSimLocked(phone)) {
400 // pass in subType=-1 so handleSimLock can find the actual subType if
401 // needed. This is safe as valid values for subType are >= 0
402 handleSimLock(-1, phone);
403 }
404 TelephonyManager tm = getSystemService(TelephonyManager.class);
405 PhoneAppCallback callback = mTelephonyCallbacks[phone.getPhoneId()];
406 // TODO: We may need to figure out a way to unregister if subId is invalid
407 tm.createForSubscriptionId(callback.getSubId())
408 .unregisterTelephonyCallback(callback);
409 callback = new PhoneAppCallback(subId);
410 tm.createForSubscriptionId(subId).registerTelephonyCallback(
Ling Ma317906d2022-12-05 15:58:14 -0800411 TelephonyManager.INCLUDE_LOCATION_DATA_COARSE, mHandler::post,
Sarah Chin072ffb22022-05-03 17:58:59 -0700412 callback);
413 mTelephonyCallbacks[phone.getPhoneId()] = callback;
414 }
415 break;
416 case EVENT_MULTI_SIM_CONFIG_CHANGED:
417 int activeModems = (int) ((AsyncResult) msg.obj).result;
418 TelephonyManager tm = getSystemService(TelephonyManager.class);
419 // Unregister all previous callbacks
420 for (int phoneId = 0; phoneId < mTelephonyCallbacks.length; phoneId++) {
421 PhoneAppCallback callback = mTelephonyCallbacks[phoneId];
422 if (callback != null) {
423 tm.createForSubscriptionId(callback.getSubId())
424 .unregisterTelephonyCallback(callback);
425 mTelephonyCallbacks[phoneId] = null;
426 }
427 }
428 // Register callbacks for all active modems
429 for (int phoneId = 0; phoneId < activeModems; phoneId++) {
430 int sub = PhoneFactory.getPhone(phoneId).getSubId();
431 PhoneAppCallback callback = new PhoneAppCallback(sub);
432 tm.createForSubscriptionId(sub).registerTelephonyCallback(
433 TelephonyManager.INCLUDE_LOCATION_DATA_NONE, mHandler::post,
434 callback);
435 mTelephonyCallbacks[phoneId] = callback;
Jordan Liu06bdef12021-03-24 17:25:46 -0700436 }
Lei Liu863eac02020-06-24 20:12:55 +0800437 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700438 }
439 }
440 };
441
442 public PhoneGlobals(Context context) {
443 super(context);
444 sMe = this;
Jack Yu1a2fc352017-07-14 17:14:37 -0700445 mSettingsObserver = new SettingsObserver(context, mHandler);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700446 }
447
448 public void onCreate() {
449 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
450
451 ContentResolver resolver = getContentResolver();
452
Hall Liuaa4211e2021-01-20 15:43:39 -0800453 // Initialize the shim from frameworks/opt/telephony into packages/services/Telephony.
454 TelephonyLocalConnection.setInstance(new LocalConnectionImpl(this));
455
Sarah Chin072ffb22022-05-03 17:58:59 -0700456 TelephonyManager tm = getSystemService(TelephonyManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457 // Cache the "voice capable" flag.
458 // This flag currently comes from a resource (which is
459 // overrideable on a per-product basis):
Sarah Chin072ffb22022-05-03 17:58:59 -0700460 sVoiceCapable = tm.isVoiceCapable();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700461 // ...but this might eventually become a PackageManager "system
462 // feature" instead, in which case we'd do something like:
463 // sVoiceCapable =
464 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
465
Stuart Scottdcf40a92014-12-09 10:45:01 -0800466 if (mCM == null) {
Nathan Haroldf9df6ea2019-03-08 11:54:22 -0800467 // Initialize AnomalyReporter early so that it can be used
468 AnomalyReporter.initialize(this);
Nathan Harold0db5c5e2019-01-22 20:18:56 -0800469
Youming Ye47a6adc2018-11-19 15:33:36 -0800470 // Inject telephony component factory if configured using other jars.
471 XmlResourceParser parser = getResources().getXml(R.xml.telephony_injection);
472 TelephonyComponentFactory.getInstance().injectTheComponentFactory(parser);
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000473
474 // Create DomainSelectionResolver always, but it MUST be initialized only when
475 // the device supports AOSP domain selection architecture and
476 // has new IRadio that supports its related HAL APIs.
477 DomainSelectionResolver.make(this,
478 getResources().getBoolean(R.bool.config_enable_aosp_domain_selection));
479
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700480 // Initialize the telephony framework
481 PhoneFactory.makeDefaultPhones(this);
482
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000483 // Initialize the DomainSelectionResolver after creating the Phone instance
484 // to check the Radio HAL version.
485 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
486 mDomainSelectionService = new TelephonyDomainSelectionService(this);
487 DomainSelectionResolver.getInstance().initialize(mDomainSelectionService);
Daniel Bantab26e96f2022-10-19 23:25:35 +0000488 // Initialize EmergencyStateTracker if domain selection is supported
489 boolean isSuplDdsSwitchRequiredForEmergencyCall = getResources()
490 .getBoolean(R.bool.config_gnss_supl_requires_default_data_for_emergency);
491 EmergencyStateTracker.make(this, isSuplDdsSwitchRequiredForEmergencyCall);
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000492 }
493
Brad Ebinger05f52c22019-12-05 13:03:21 -0800494 // Only bring up ImsResolver if the device supports having an IMS stack.
495 if (getPackageManager().hasSystemFeature(
496 PackageManager.FEATURE_TELEPHONY_IMS)) {
497 // Get the package name of the default IMS implementation.
498 String defaultImsMmtelPackage = getResources().getString(
499 R.string.config_ims_mmtel_package);
500 String defaultImsRcsPackage = getResources().getString(
501 R.string.config_ims_rcs_package);
Brad Ebingerd1947d82021-05-17 20:54:49 +0000502 ImsResolver.make(this, defaultImsMmtelPackage,
Brad Ebingere3ae65a2020-09-11 12:45:11 -0700503 defaultImsRcsPackage, PhoneFactory.getPhones().length,
504 new ImsFeatureBinderRepository());
Brad Ebingerd1947d82021-05-17 20:54:49 +0000505 ImsResolver.getInstance().initialize();
Tyler Gunn92479152021-01-20 16:30:10 -0800506
507 // With the IMS phone created, load static config.xml values from the phone process
508 // so that it can be provided to the ImsPhoneCallTracker.
509 for (Phone p : PhoneFactory.getPhones()) {
510 Phone imsPhone = p.getImsPhone();
511 if (imsPhone != null && imsPhone instanceof ImsPhone) {
512 ImsPhone theImsPhone = (ImsPhone) imsPhone;
513 if (theImsPhone.getCallTracker() instanceof ImsPhoneCallTracker) {
514 ImsPhoneCallTracker ict = (ImsPhoneCallTracker)
515 theImsPhone.getCallTracker();
516
517 ImsPhoneCallTracker.Config config = new ImsPhoneCallTracker.Config();
518 config.isD2DCommunicationSupported = getResources().getBoolean(
519 R.bool.config_use_device_to_device_communication);
520 ict.setConfig(config);
521 }
522 }
523 }
Hui Wang068ab862020-10-31 05:12:53 +0000524 RcsProvisioningMonitor.make(this);
Brad Ebinger05f52c22019-12-05 13:03:21 -0800525 }
526
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700527 // Start TelephonyDebugService After the default phone is created.
528 Intent intent = new Intent(this, TelephonyDebugService.class);
529 startService(intent);
530
531 mCM = CallManager.getInstance();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700532
533 // Create the NotificationMgr singleton, which is used to display
534 // status bar icons and control other status bar behavior.
535 notificationMgr = NotificationMgr.init(this);
536
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000537 // Create the SatelliteController singleton, which acts as a backend service for
538 // {@link android.telephony.satellite.SatelliteManager}.
539 SatelliteController.make(this);
Sarah Chin5f57c582023-02-14 04:16:10 -0800540
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700541 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
542 cdmaPhoneCallState = new CdmaPhoneCallState();
543 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700544
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700545 // before registering for phone state changes
546 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
547 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
548 // lock used to keep the processor awake, when we don't care for the display.
549 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
550 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700551
552 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
553
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800554 phoneMgr = PhoneInterfaceManager.init(this);
Santos Cordon406c0342013-08-28 00:07:47 -0700555
James.cf Linaf3183c2019-10-24 00:59:00 +0800556 imsRcsController = ImsRcsController.init(this);
557
Brad Ebinger6c53e7f2023-01-27 16:26:44 -0800558 configLoader = CarrierConfigLoader.init(this);
559
James.cf Linc9f35a42020-01-15 02:35:22 +0800560 if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000561 mImsStateCallbackController =
562 ImsStateCallbackController.make(this, PhoneFactory.getPhones().length);
Brad Ebingera68a4972020-01-30 17:31:23 -0800563 mTelephonyRcsService = new TelephonyRcsService(this,
564 PhoneFactory.getPhones().length);
565 mTelephonyRcsService.initialize();
James.cf Linc9f35a42020-01-15 02:35:22 +0800566 imsRcsController.setRcsService(mTelephonyRcsService);
joonhunshincffb7fc2021-11-28 07:32:01 +0000567 mImsProvisioningController =
568 ImsProvisioningController.make(this, PhoneFactory.getPhones().length);
James.cf Linc9f35a42020-01-15 02:35:22 +0800569 }
570
Jack Yu1a2fc352017-07-14 17:14:37 -0700571 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700572 // asynchronous events from the telephony layer (like
573 // launching the incoming-call UI when an incoming call comes
574 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800575 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700576
Stuart Scottdcf40a92014-12-09 10:45:01 -0800577 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700578
579 // register for MMI/USSD
580 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
581
Qiong Liucc3fe812019-09-23 15:25:44 +0800582 // Initialize cell status using current airplane mode.
Taesu Lee62f826d2020-08-10 16:01:18 +0900583 handleAirplaneModeChange(
584 Settings.Global.getInt(
585 getContentResolver(),
586 Settings.Global.AIRPLANE_MODE_ON,
587 AIRPLANE_OFF)
588 == AIRPLANE_ON);
Qiong Liucc3fe812019-09-23 15:25:44 +0800589
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700590 // Register for misc other intent broadcasts.
591 IntentFilter intentFilter =
592 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700593 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
594 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700595 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700596 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
597 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700598 registerReceiver(mReceiver, intentFilter);
599
Sarah Chin072ffb22022-05-03 17:58:59 -0700600 PhoneConfigurationManager.registerForMultiSimConfigChange(
601 mHandler, EVENT_MULTI_SIM_CONFIG_CHANGED, null);
602
603 mTelephonyCallbacks = new PhoneAppCallback[tm.getSupportedModemCount()];
Fangyuan Li7f5c2752022-06-29 18:02:31 +0800604 if (tm.getSupportedModemCount() > 0) {
605 for (Phone phone : PhoneFactory.getPhones()) {
606 int subId = phone.getSubId();
607 PhoneAppCallback callback = new PhoneAppCallback(subId);
608 tm.createForSubscriptionId(subId).registerTelephonyCallback(
609 TelephonyManager.INCLUDE_LOCATION_DATA_NONE, mHandler::post, callback);
610 mTelephonyCallbacks[phone.getPhoneId()] = callback;
611 }
Sarah Chin072ffb22022-05-03 17:58:59 -0700612 }
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700613 mCarrierVvmPackageInstalledReceiver.register(this);
614
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700615 //set the default values for the preferences in the phone.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700616 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700617 }
618
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700619 // XXX pre-load the SimProvider so that it's ready
620 resolver.getType(Uri.parse("content://icc/adn"));
621
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700622 // TODO: Register for Cdma Information Records
623 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
624
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700625 // Read HAC settings and configure audio hardware
626 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800627 int hac = android.provider.Settings.System.getInt(
628 getContentResolver(),
629 android.provider.Settings.System.HEARING_AID,
630 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700631 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Jordan Liuf71aeef2019-08-21 11:46:09 -0700632 audioManager.setParameters(
633 SettingsConstants.HAC_KEY + "=" + (hac == SettingsConstants.HAC_ENABLED
634 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700635 }
Siim Sammul182d61b2021-05-04 16:01:42 +0100636
637 // Start tracking Binder latency for the phone process.
638 mBinderCallsSettingsObserver = new BinderCallsStats.SettingsObserver(
639 getApplicationContext(),
Siim Sammula6950092021-06-22 17:14:03 +0100640 new BinderCallsStats(
641 new BinderCallsStats.Injector(),
642 com.android.internal.os.BinderLatencyProto.Dims.TELEPHONY));
Santos Cordonff506f52013-11-21 19:13:19 -0800643 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700644
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700645 /**
646 * Returns the singleton instance of the PhoneApp.
647 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800648 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700649 if (sMe == null) {
650 throw new IllegalStateException("No PhoneGlobals here!");
651 }
652 return sMe;
653 }
654
655 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800656 * Returns the default phone.
657 *
Andrew Lee385019f2014-11-24 14:19:50 -0800658 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700659 */
Andrew Lee83383e42014-10-31 12:42:28 -0700660 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800661 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700662 }
663
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800664 public static Phone getPhone(int subId) {
665 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800666 }
667
Santos Cordonde10b752013-09-19 04:11:33 -0700668 /* package */ CallManager getCallManager() {
669 return mCM;
670 }
671
Chris Manton4e9fa912015-06-19 11:26:57 -0700672 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800673 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700674 }
675
Chris Manton4e9fa912015-06-19 11:26:57 -0700676 public PersistableBundle getCarrierConfigForSubId(int subId) {
Philip P. Moltmann0079aae2020-03-05 16:24:02 -0800677 return configLoader.getConfigForSubIdWithFeature(subId, getOpPackageName(),
678 getAttributionTag());
Junda Liu605148f2015-04-28 15:23:40 -0700679 }
680
Jack Yu1a2fc352017-07-14 17:14:37 -0700681 private void registerSettingsObserver() {
682 mSettingsObserver.unobserve();
683 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
684 String mobileDataSetting = Settings.Global.MOBILE_DATA;
685 if (TelephonyManager.getDefault().getSimCount() > 1) {
686 int subId = mDefaultDataSubId;
687 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
688 dataRoamingSetting += subId;
689 mobileDataSetting += subId;
690 }
691 }
692
693 // Listen for user data roaming setting changed event
694 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
695 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
696
697 // Listen for mobile data setting changed event
698 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
699 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
700 }
701
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700702 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700703 * Sets the activity responsible for un-PUK-blocking the device
704 * so that we may close it when we receive a positive result.
705 * mPUKEntryActivity is also used to indicate to the device that
706 * we are trying to un-PUK-lock the phone. In other words, iff
707 * it is NOT null, then we are trying to unlock and waiting for
708 * the SIM to move to READY state.
709 *
710 * @param activity is the activity to close when PUK has
711 * finished unlocking. Can be set to null to indicate the unlock
712 * or SIM READYing process is over.
713 */
714 void setPukEntryActivity(Activity activity) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700715 Log.i(LOG_TAG, "setPukEntryActivity - set to " + (activity == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700716 mPUKEntryActivity = activity;
717 }
718
719 Activity getPUKEntryActivity() {
720 return mPUKEntryActivity;
721 }
722
723 /**
724 * Sets the dialog responsible for notifying the user of un-PUK-
725 * blocking - SIM READYing progress, so that we may dismiss it
726 * when we receive a positive result.
727 *
728 * @param dialog indicates the progress dialog informing the user
729 * of the state of the device. Dismissed upon completion of
730 * READYing process
731 */
732 void setPukEntryProgressDialog(ProgressDialog dialog) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700733 Log.i(LOG_TAG, "setPukEntryProgressDialog - set to "
734 + (dialog == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700735 mPUKEntryProgressDialog = dialog;
736 }
737
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700738 KeyguardManager getKeyguardManager() {
739 return mKeyguardManager;
740 }
741
742 private void onMMIComplete(AsyncResult r) {
743 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
744 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800745 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700746 }
747
fionaxu80126972017-02-01 17:01:26 -0800748 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700749 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700750 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700751 }
752
Taesu Lee62f826d2020-08-10 16:01:18 +0900753 private void handleAirplaneModeChange(boolean isAirplaneNewlyOn) {
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700754 Log.i(LOG_TAG, "handleAirplaneModeChange: isAirplaneNewlyOn=" + isAirplaneNewlyOn);
Taesu Lee62f826d2020-08-10 16:01:18 +0900755 int cellState =
756 Settings.Global.getInt(
757 getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
Chris Mantona09f3632016-02-09 14:48:42 -0800758 switch (cellState) {
759 case PhoneConstants.CELL_OFF_FLAG:
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700760 // Airplane mode does not affect the cell radio if user has turned it off.
761 Log.i(LOG_TAG, "Ignore airplane mode change due to cell off.");
Chris Mantona09f3632016-02-09 14:48:42 -0800762 break;
763 case PhoneConstants.CELL_ON_FLAG:
Taesu Lee62f826d2020-08-10 16:01:18 +0900764 maybeTurnCellOff(isAirplaneNewlyOn);
Chris Mantona09f3632016-02-09 14:48:42 -0800765 break;
766 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
Taesu Lee62f826d2020-08-10 16:01:18 +0900767 maybeTurnCellOn(isAirplaneNewlyOn);
Chris Mantona09f3632016-02-09 14:48:42 -0800768 break;
769 }
Hall Liu7f56e1a2019-07-10 14:41:14 -0700770 for (Phone phone : PhoneFactory.getPhones()) {
771 phone.getServiceStateTracker().onAirplaneModeChanged(isAirplaneNewlyOn);
772 }
Chris Mantona09f3632016-02-09 14:48:42 -0800773 }
774
775 /*
776 * Returns true if the radio must be turned off when entering airplane mode.
777 */
Taesu Lee62f826d2020-08-10 16:01:18 +0900778 private boolean isCellOffInAirplaneMode() {
779 String airplaneModeRadios =
780 Settings.Global.getString(
781 getContentResolver(), Settings.Global.AIRPLANE_MODE_RADIOS);
Chris Mantona09f3632016-02-09 14:48:42 -0800782 return airplaneModeRadios == null
783 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
784 }
785
Taesu Lee62f826d2020-08-10 16:01:18 +0900786 private void setRadioPowerOff() {
Chris Mantona09f3632016-02-09 14:48:42 -0800787 Log.i(LOG_TAG, "Turning radio off - airplane");
Taesu Lee62f826d2020-08-10 16:01:18 +0900788 Settings.Global.putInt(
789 getContentResolver(),
790 Settings.Global.CELL_ON,
791 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Chris Mantona09f3632016-02-09 14:48:42 -0800792 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
Taesu Lee62f826d2020-08-10 16:01:18 +0900793 TelephonyProperties.airplane_mode_on(true); // true means int value 1
Chris Mantona09f3632016-02-09 14:48:42 -0800794 PhoneUtils.setRadioPower(false);
Ling Ma317906d2022-12-05 15:58:14 -0800795 clearCacheOnRadioOff();
796 }
797
798 /** Clear fields on power off radio **/
799 private void clearCacheOnRadioOff() {
800 // Re-show is-roaming notifications after APM mode
sangyun35f23f82023-07-18 01:37:53 +0900801 mShownNotificationReasons.clear();
Chris Mantona09f3632016-02-09 14:48:42 -0800802 }
803
Taesu Lee62f826d2020-08-10 16:01:18 +0900804 private void setRadioPowerOn() {
Chris Mantona09f3632016-02-09 14:48:42 -0800805 Log.i(LOG_TAG, "Turning radio on - airplane");
Taesu Lee62f826d2020-08-10 16:01:18 +0900806 Settings.Global.putInt(
807 getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
808 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 1);
Meng Wang61307622019-10-23 14:08:43 -0700809 TelephonyProperties.airplane_mode_on(false); // false means int value 0
Chris Mantona09f3632016-02-09 14:48:42 -0800810 PhoneUtils.setRadioPower(true);
811 }
812
Taesu Lee62f826d2020-08-10 16:01:18 +0900813 private void maybeTurnCellOff(boolean isAirplaneNewlyOn) {
Chris Mantona09f3632016-02-09 14:48:42 -0800814 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700815 // If we are trying to turn off the radio, make sure there are no active
816 // emergency calls. If there are, switch airplane mode back to off.
Taesu Lee62f826d2020-08-10 16:01:18 +0900817 TelecomManager tm = (TelecomManager) getSystemService(TELECOM_SERVICE);
Tyler Gunn900d8fd2018-09-21 09:22:12 -0700818
819 if (tm != null && tm.isInEmergencyCall()) {
Santos Cordone18902f2016-03-22 17:16:04 -0700820 // Switch airplane mode back to off.
Jordan Liu0e819b12019-08-28 15:33:05 -0700821 ConnectivityManager cm =
Taesu Lee62f826d2020-08-10 16:01:18 +0900822 (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
Jordan Liu0e819b12019-08-28 15:33:05 -0700823 cm.setAirplaneMode(false);
Santos Cordone18902f2016-03-22 17:16:04 -0700824 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
825 .show();
826 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Taesu Lee62f826d2020-08-10 16:01:18 +0900827 } else if (isCellOffInAirplaneMode()) {
828 setRadioPowerOff();
Santos Cordone18902f2016-03-22 17:16:04 -0700829 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800830 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700831 }
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700832 } else {
833 Log.i(LOG_TAG, "Ignoring airplane mode: not newly on");
Chris Mantona09f3632016-02-09 14:48:42 -0800834 }
835 }
836
Taesu Lee62f826d2020-08-10 16:01:18 +0900837 private void maybeTurnCellOn(boolean isAirplaneNewlyOn) {
Chris Mantona09f3632016-02-09 14:48:42 -0800838 if (!isAirplaneNewlyOn) {
Taesu Lee62f826d2020-08-10 16:01:18 +0900839 setRadioPowerOn();
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700840 } else {
841 Log.i(LOG_TAG, "Ignoring airplane mode off: radio is already on.");
Santos Cordone18902f2016-03-22 17:16:04 -0700842 }
843 }
844
Santos Cordon593ab382013-08-06 21:58:23 -0700845 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700846 * Receiver for misc intent broadcasts the Phone app cares about.
847 */
848 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
849 @Override
850 public void onReceive(Context context, Intent intent) {
851 String action = intent.getAction();
852 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Taesu Lee3dc572b2020-08-07 18:16:22 +0900853 boolean airplaneMode = intent.getBooleanExtra("state", false);
Taesu Lee62f826d2020-08-10 16:01:18 +0900854 handleAirplaneModeChange(airplaneMode);
Amit Mahajanf5d92c82018-11-02 17:44:40 -0700855 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
856 // re-register as it may be a new IccCard
857 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
858 SubscriptionManager.INVALID_PHONE_INDEX);
859 if (SubscriptionManager.isValidPhoneId(phoneId)) {
860 PhoneUtils.unregisterIccStatus(mHandler, phoneId);
861 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED, phoneId);
862 }
Nazish Tabassum160d2112019-12-23 17:31:33 +0530863 String iccStatus = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
864 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
865 new EventSimStateChangedBag(phoneId, iccStatus)));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700866 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
867 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800868 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
869 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700870 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530871 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530872 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530873 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
874 if (phoneInEcm != null) {
875 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
876 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
877 // Start Emergency Callback Mode service
Daniel Bright30efde42020-01-09 22:11:15 -0800878 if (intent.getBooleanExtra(
879 TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530880 context.startService(new Intent(context,
881 EmergencyCallbackModeService.class));
882 } else {
883 phoneInEcm = null;
884 }
885 } else {
886 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
887 // on a device that doesn't support ECM in the first place.
888 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
889 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
890 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700891 }
892 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530893 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700894 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700895 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
896 // Roaming status could be overridden by carrier config, so we need to update it.
897 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
sangyun35f23f82023-07-18 01:37:53 +0900898 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED);
chen xubaf9fe52019-07-02 17:28:24 -0700899 updateLimitedSimFunctionForDualSim();
Lei Liu863eac02020-06-24 20:12:55 +0800900 int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
901 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
902 if (SubscriptionManager.isValidSubscriptionId(subId)) {
903 mHandler.sendMessage(mHandler.obtainMessage(EVENT_CARRIER_CONFIG_CHANGED,
904 new Integer(subId)));
905 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700906 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
907 // We also need to pay attention when default data subscription changes.
908 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
909 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
910 registerSettingsObserver();
911 Phone phone = getPhone(mDefaultDataSubId);
912 if (phone != null) {
sangyun35f23f82023-07-18 01:37:53 +0900913 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700914 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700915 }
916 }
917 }
918
Sarah Chin072ffb22022-05-03 17:58:59 -0700919 private void handleServiceStateChanged(ServiceState serviceState, int subId) {
Jack Yu1a2fc352017-07-14 17:14:37 -0700920 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Sarah Chin072ffb22022-05-03 17:58:59 -0700921 int state = serviceState.getState();
922 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -0700923
Sarah Chin072ffb22022-05-03 17:58:59 -0700924 if (VDBG) {
925 Log.v(LOG_TAG, "subId=" + subId + ", mDefaultDataSubId="
926 + mDefaultDataSubId + ", ss roaming=" + serviceState.getDataRoaming());
927 }
928 if (subId == mDefaultDataSubId) {
sangyun35f23f82023-07-18 01:37:53 +0900929 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700930 }
931 }
932
Jack Yu1a2fc352017-07-14 17:14:37 -0700933 /**
934 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
935 * to notify the user so they can enable it through settings. Vise versa if the condition
936 * changes, we need to dismiss the notification.
sangyun35f23f82023-07-18 01:37:53 +0900937 * @param reason to inform which event is called for notification update.
Jack Yu1a2fc352017-07-14 17:14:37 -0700938 */
sangyun35f23f82023-07-18 01:37:53 +0900939 private void updateDataRoamingStatus(@RoamingNotificationReason int reason) {
Jack Yu1a2fc352017-07-14 17:14:37 -0700940 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
941 Phone phone = getPhone(mDefaultDataSubId);
942 if (phone == null) {
943 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
944 return;
945 }
946
sangyun35f23f82023-07-18 01:37:53 +0900947 ServiceState serviceState = phone.getServiceState();
948 String roamingNumeric = serviceState.getOperatorNumeric();
949 String roamingNumericReason = "RoamingNumeric=" + roamingNumeric;
950 String callingReason = "CallingReason=" + reason;
951 boolean dataIsNowRoaming = serviceState.getDataRoaming();
Jack Yu3e2ac6e2022-03-26 13:59:45 -0700952 boolean dataAllowed;
953 boolean notAllowedDueToRoamingOff;
Sarah Chine04784a2022-10-31 20:32:34 -0700954 List<DataDisallowedReason> reasons = phone.getDataNetworkController()
955 .getInternetDataDisallowedReasons();
Jack Yu7968c6d2022-07-31 00:43:21 -0700956 dataAllowed = reasons.isEmpty();
957 notAllowedDueToRoamingOff = (reasons.size() == 1
958 && reasons.contains(DataDisallowedReason.ROAMING_DISABLED));
sangyun35f23f82023-07-18 01:37:53 +0900959 StringBuilder sb = new StringBuilder("updateDataRoamingStatus");
960 sb.append(" dataAllowed=").append(dataAllowed);
961 sb.append(", reasons=").append(reasons);
962 sb.append(", dataIsNowRoaming=").append(dataIsNowRoaming);
963 sb.append(", ").append(roamingNumericReason);
964 sb.append(", ").append(callingReason);
965 mDataRoamingNotifLog.log(sb.toString());
Ling Ma317906d2022-12-05 15:58:14 -0800966 if (VDBG) {
sangyun35f23f82023-07-18 01:37:53 +0900967 Log.v(LOG_TAG, sb.toString());
Ling Ma317906d2022-12-05 15:58:14 -0800968 }
Jack Yu3e2ac6e2022-03-26 13:59:45 -0700969
sangyun35f23f82023-07-18 01:37:53 +0900970 // Determine if a given roaming numeric has never been shown.
971 boolean shownInThisNumeric = false;
972 if (reason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED
973 || reason == ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED) {
974 shownInThisNumeric = mShownNotificationReasons.contains(roamingNumericReason);
975 }
976 // Determine if a notification has never been shown by given calling reason.
977 boolean shownForThisReason = mShownNotificationReasons.contains(callingReason);
978
Jack Yu3e2ac6e2022-03-26 13:59:45 -0700979 if (!dataAllowed && notAllowedDueToRoamingOff) {
sangyun35f23f82023-07-18 01:37:53 +0900980 if (!shownInThisNumeric && roamingNumeric != null) {
981 mShownNotificationReasons.add(roamingNumericReason);
982 }
983 if (!shownForThisReason
984 && reason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED) {
985 mShownNotificationReasons.add(callingReason);
Ling Ma4e15c322022-12-07 11:20:53 -0800986 }
Jordan Liuff2ccd72019-07-23 15:54:41 -0700987 // No need to show it again if we never cancelled it explicitly.
sangyun35f23f82023-07-18 01:37:53 +0900988 if (getCurrentRoamingNotification() == ROAMING_NOTIFICATION_DISCONNECTED) {
989 return;
990 }
991
Jack Yu1a2fc352017-07-14 17:14:37 -0700992 // If the only reason of no data is data roaming disabled, then we notify the user
993 // so the user can turn on data roaming.
sangyun35f23f82023-07-18 01:37:53 +0900994 if (!shownInThisNumeric && !shownForThisReason) {
995 updateDataRoamingNotification(ROAMING_NOTIFICATION_DISCONNECTED);
996 } else {
997 // Don't show roaming notification if we've already shown for this MccMnc
998 Log.d(LOG_TAG, "Skip roaming disconnected notification since already"
999 + " shownInThisNumeric=" + shownInThisNumeric
1000 + " shownForThisReason=" + shownForThisReason);
1001 // Dismiss notification if the other notification is shown.
1002 if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
1003 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
1004 }
1005 }
1006 } else if (dataAllowed && dataIsNowRoaming) {
1007 if (!shownInThisNumeric && roamingNumeric != null) {
1008 mShownNotificationReasons.add(roamingNumericReason);
1009 }
1010 if (!shownForThisReason
1011 && reason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED) {
1012 mShownNotificationReasons.add(callingReason);
1013 }
Ling Ma4e15c322022-12-07 11:20:53 -08001014 boolean isShowRoamingNotificationEnabled = getCarrierConfigForSubId(mDefaultDataSubId)
1015 .getBoolean(CarrierConfigManager
1016 .KEY_SHOW_DATA_CONNECTED_ROAMING_NOTIFICATION_BOOL);
sangyun35f23f82023-07-18 01:37:53 +09001017 // No need to show it again if we never cancelled it explicitly.
1018 if (getCurrentRoamingNotification() == ROAMING_NOTIFICATION_CONNECTED) {
Ling Ma4e15c322022-12-07 11:20:53 -08001019 return;
1020 }
sangyun35f23f82023-07-18 01:37:53 +09001021
1022 // Inform users that roaming charges may apply.
1023 if (!shownInThisNumeric && !shownForThisReason && isShowRoamingNotificationEnabled) {
1024 updateDataRoamingNotification(ROAMING_NOTIFICATION_CONNECTED);
1025 } else {
1026 // Don't show roaming notification if we've already shown for this MccMnc or
1027 // disabled from carrier config.
1028 Log.d(LOG_TAG, "Skip roaming connected notification since already"
1029 + " shownInThisNumeric:" + shownInThisNumeric
1030 + " shownForThisReason:" + shownForThisReason
1031 + " isShowRoamingNotificationEnabled:" + isShowRoamingNotificationEnabled);
1032 // Dismiss notification if the other notification is shown.
1033 if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
1034 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
1035 }
1036 }
1037 } else if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
Jordan Liuff2ccd72019-07-23 15:54:41 -07001038 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
1039 // is not the only data disable reason. In this case we dismiss the notification we
1040 // showed earlier.
sangyun35f23f82023-07-18 01:37:53 +09001041 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
Jack Yu1a2fc352017-07-14 17:14:37 -07001042 }
1043 }
1044
sangyun35f23f82023-07-18 01:37:53 +09001045 private void updateDataRoamingNotification(@RoamingNotification int roamingNotification) {
1046 int event;
1047 switch (roamingNotification) {
1048 case ROAMING_NOTIFICATION_NO_NOTIFICATION:
1049 Log.d(LOG_TAG, "Dismiss roaming notification");
1050 mDataRoamingNotifLog.log("Hide roaming.");
1051 event = EVENT_DATA_ROAMING_OK;
1052 break;
1053 case ROAMING_NOTIFICATION_CONNECTED:
1054 Log.d(LOG_TAG, "Show roaming connected notification");
1055 mDataRoamingNotifLog.log("Show roaming on.");
1056 event = EVENT_DATA_ROAMING_CONNECTED;
1057 break;
1058 case ROAMING_NOTIFICATION_DISCONNECTED:
1059 Log.d(LOG_TAG, "Show roaming disconnected notification");
1060 mDataRoamingNotifLog.log("Show roaming off.");
1061 event = EVENT_DATA_ROAMING_DISCONNECTED;
1062 break;
1063 default:
1064 Log.d(LOG_TAG, "Should never reach here.");
1065 mDataRoamingNotifLog.log("Should never reach here.");
1066 return;
1067 }
1068 mCurrentRoamingNotification = roamingNotification;
1069 mHandler.obtainMessage(event, mDefaultDataSubId, 0).sendToTarget();
1070 }
1071
1072 private @RoamingNotification int getCurrentRoamingNotification() {
1073 return mCurrentRoamingNotification;
1074 }
1075
Jordan Liuff2ccd72019-07-23 15:54:41 -07001076 /**
1077 *
1078 * @param subId to check roaming on
1079 * @return whether we have transitioned to dataRoaming
1080 */
1081 private boolean dataIsNowRoaming(int subId) {
Sarah Chine04784a2022-10-31 20:32:34 -07001082 return getPhone(subId).getServiceState().getDataRoaming();
Jordan Liuff2ccd72019-07-23 15:54:41 -07001083 }
1084
chen xubaf9fe52019-07-02 17:28:24 -07001085 private void updateLimitedSimFunctionForDualSim() {
1086 if (DBG) Log.d(LOG_TAG, "updateLimitedSimFunctionForDualSim");
1087 // check conditions to display limited SIM function notification under dual SIM
1088 SubscriptionManager subMgr = (SubscriptionManager) getSystemService(
1089 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
1090 List<SubscriptionInfo> subList = subMgr.getActiveSubscriptionInfoList(false);
1091 if (subList != null && subList.size() > 1) {
1092 CarrierConfigManager configMgr = (CarrierConfigManager)
1093 getSystemService(Context.CARRIER_CONFIG_SERVICE);
1094 for (SubscriptionInfo info : subList) {
1095 PersistableBundle b = configMgr.getConfigForSubId(info.getSubscriptionId());
1096 if (b != null) {
1097 if (b.getBoolean(CarrierConfigManager
1098 .KEY_LIMITED_SIM_FUNCTION_NOTIFICATION_FOR_DSDS_BOOL)) {
1099 notificationMgr.showLimitedSimFunctionWarningNotification(
1100 info.getSubscriptionId(),
1101 info.getDisplayName().toString());
1102 } else {
1103 notificationMgr.dismissLimitedSimFunctionWarningNotification(
1104 info.getSubscriptionId());
1105 }
1106 }
1107 }
1108 } else {
1109 // cancel notifications for all subs
1110 notificationMgr.dismissLimitedSimFunctionWarningNotification(
1111 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1112 }
1113 notificationMgr.dismissLimitedSimFunctionWarningNotificationForInactiveSubs();
1114
1115 }
1116
Sandeep Kuntade73a6a2014-10-15 18:45:56 +05301117 public Phone getPhoneInEcm() {
1118 return phoneInEcm;
1119 }
1120
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001121 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -08001122 * Triggers a refresh of the message waiting (voicemail) indicator.
1123 *
1124 * @param subId the subscription id we should refresh the notification for.
1125 */
1126 public void refreshMwiIndicator(int subId) {
1127 notificationMgr.refreshMwi(subId);
1128 }
1129
1130 /**
Pengquan Mengdd9ac822018-09-20 15:25:35 -07001131 * Called when the network selection on the subscription {@code subId} is changed by the user.
1132 *
1133 * @param subId the subscription id.
1134 */
1135 public void onNetworkSelectionChanged(int subId) {
1136 Phone phone = getPhone(subId);
1137 if (phone != null) {
1138 notificationMgr.updateNetworkSelection(phone.getServiceState().getState(), subId);
1139 } else {
1140 Log.w(LOG_TAG, "onNetworkSelectionChanged on null phone, subId: " + subId);
1141 }
1142 }
1143
1144 /**
James.cf Lin4b784aa2021-01-31 03:25:15 +08001145 * @return whether the device supports RCS User Capability Exchange or not.
1146 */
1147 public boolean getDeviceUceEnabled() {
1148 return (mTelephonyRcsService == null) ? false : mTelephonyRcsService.isDeviceUceEnabled();
1149 }
1150
1151 /**
1152 * Set the device supports RCS User Capability Exchange.
1153 * @param isEnabled true if the device supports UCE.
1154 */
1155 public void setDeviceUceEnabled(boolean isEnabled) {
1156 if (mTelephonyRcsService != null) {
1157 mTelephonyRcsService.setDeviceUceEnabled(isEnabled);
1158 }
1159 }
1160
1161 /**
Jack Yu1a2fc352017-07-14 17:14:37 -07001162 * Dump the state of the object, add calls to other objects as desired.
1163 *
1164 * @param fd File descriptor
1165 * @param printWriter Print writer
1166 * @param args Arguments
1167 */
1168 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
1169 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
1170 pw.println("------- PhoneGlobals -------");
1171 pw.increaseIndent();
sangyun35f23f82023-07-18 01:37:53 +09001172 pw.println("mCurrentRoamingNotification=" + mCurrentRoamingNotification);
Jack Yu1a2fc352017-07-14 17:14:37 -07001173 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
Keun young Parkdebb8532019-05-30 16:35:27 -07001174 pw.println("isSmsCapable=" + TelephonyManager.from(this).isSmsCapable());
sangyun35f23f82023-07-18 01:37:53 +09001175 pw.println("mDataRoamingNotifLog:");
Jack Yu1a2fc352017-07-14 17:14:37 -07001176 pw.increaseIndent();
1177 mDataRoamingNotifLog.dump(fd, pw, args);
1178 pw.decreaseIndent();
Brad Ebinger05f52c22019-12-05 13:03:21 -08001179 pw.println("ImsResolver:");
1180 pw.increaseIndent();
1181 try {
Brad Ebingerd1947d82021-05-17 20:54:49 +00001182 if (ImsResolver.getInstance() != null) ImsResolver.getInstance().dump(fd, pw, args);
Brad Ebinger05f52c22019-12-05 13:03:21 -08001183 } catch (Exception e) {
1184 e.printStackTrace();
1185 }
1186 pw.decreaseIndent();
Brad Ebingera68a4972020-01-30 17:31:23 -08001187 pw.println("RcsService:");
1188 try {
1189 if (mTelephonyRcsService != null) mTelephonyRcsService.dump(fd, pw, args);
1190 } catch (Exception e) {
1191 e.printStackTrace();
1192 }
Hunsuk Choi89bd22c2021-11-01 13:04:54 +00001193 pw.println("ImsStateCallbackController:");
1194 try {
1195 if (mImsStateCallbackController != null) mImsStateCallbackController.dump(pw);
1196 } catch (Exception e) {
1197 e.printStackTrace();
1198 }
Hwangoo Parkba21cf22022-11-30 14:34:04 +00001199 pw.println("DomainSelectionResolver:");
1200 pw.increaseIndent();
1201 try {
1202 if (DomainSelectionResolver.getInstance() != null) {
1203 DomainSelectionResolver.getInstance().dump(fd, pw, args);
1204 }
1205 } catch (Exception e) {
1206 e.printStackTrace();
1207 }
1208 pw.decreaseIndent();
1209 if (mDomainSelectionService != null) {
1210 mDomainSelectionService.dump(fd, pw, args);
1211 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001212 pw.decreaseIndent();
sangyun35f23f82023-07-18 01:37:53 +09001213 pw.println("mShownNotificationReasons=" + mShownNotificationReasons);
Jack Yu1a2fc352017-07-14 17:14:37 -07001214 pw.println("------- End PhoneGlobals -------");
1215 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001216}