blob: 7fba6511c78b4caceeb367718a4b357053362c23 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Jordan Liuff2ccd72019-07-23 15:54:41 -070019import android.annotation.IntDef;
sangyun1c1918a2023-11-13 22:37:50 +090020import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070021import android.app.Activity;
22import android.app.KeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070023import android.app.ProgressDialog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.content.BroadcastReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.ContentResolver;
26import android.content.Context;
27import android.content.ContextWrapper;
28import android.content.Intent;
29import android.content.IntentFilter;
Brad Ebinger05f52c22019-12-05 13:03:21 -080030import android.content.pm.PackageManager;
Youming Ye47a6adc2018-11-19 15:33:36 -080031import android.content.res.XmlResourceParser;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.media.AudioManager;
Santos Cordone18902f2016-03-22 17:16:04 -070033import android.net.ConnectivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070034import android.net.Uri;
35import android.os.AsyncResult;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036import android.os.Handler;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.os.Message;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070038import android.os.PersistableBundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.os.PowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.preference.PreferenceManager;
Sanket Padawe4c699232016-02-09 11:07:22 -080042import android.provider.Settings;
Meng Wang61307622019-10-23 14:08:43 -070043import android.sysprop.TelephonyProperties;
Tyler Gunn900d8fd2018-09-21 09:22:12 -070044import android.telecom.TelecomManager;
Nathan Haroldf9df6ea2019-03-08 11:54:22 -080045import android.telephony.AnomalyReporter;
Junda Liu12f7d802015-05-01 12:06:44 -070046import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.telephony.ServiceState;
chen xubaf9fe52019-07-02 17:28:24 -070048import android.telephony.SubscriptionInfo;
Andrew Lee385019f2014-11-24 14:19:50 -080049import android.telephony.SubscriptionManager;
Sarah Chin072ffb22022-05-03 17:58:59 -070050import android.telephony.TelephonyCallback;
Hall Liuaa4211e2021-01-20 15:43:39 -080051import android.telephony.TelephonyLocalConnection;
Jack Yu1a2fc352017-07-14 17:14:37 -070052import android.telephony.TelephonyManager;
Sarah Chin37b39072023-11-05 13:28:21 -080053import android.text.TextUtils;
Ling Ma317906d2022-12-05 15:58:14 -080054import android.util.ArraySet;
Jack Yu1a2fc352017-07-14 17:14:37 -070055import android.util.LocalLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.util.Log;
Santos Cordone18902f2016-03-22 17:16:04 -070057import android.widget.Toast;
Ta-wei Yenb29425b2016-09-21 17:28:14 -070058
Brad Ebingere3ae65a2020-09-11 12:45:11 -070059import com.android.ims.ImsFeatureBinderRepository;
Siim Sammul182d61b2021-05-04 16:01:42 +010060import com.android.internal.os.BinderCallsStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070061import com.android.internal.telephony.CallManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070062import com.android.internal.telephony.IccCardConstants;
63import com.android.internal.telephony.MmiCode;
64import com.android.internal.telephony.Phone;
Sarah Chin072ffb22022-05-03 17:58:59 -070065import com.android.internal.telephony.PhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066import com.android.internal.telephony.PhoneConstants;
67import com.android.internal.telephony.PhoneFactory;
Jack Yu1a2fc352017-07-14 17:14:37 -070068import com.android.internal.telephony.SettingsObserver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070069import com.android.internal.telephony.TelephonyCapabilities;
Youming Ye47a6adc2018-11-19 15:33:36 -080070import com.android.internal.telephony.TelephonyComponentFactory;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070071import com.android.internal.telephony.TelephonyIntents;
Jack Yu3e2ac6e2022-03-26 13:59:45 -070072import com.android.internal.telephony.data.DataEvaluation.DataDisallowedReason;
Hwangoo Parkba21cf22022-11-30 14:34:04 +000073import com.android.internal.telephony.domainselection.DomainSelectionResolver;
Daniel Bantab26e96f2022-10-19 23:25:35 +000074import com.android.internal.telephony.emergency.EmergencyStateTracker;
Thomas Nguyen090fb002023-09-11 17:35:30 -070075import com.android.internal.telephony.flags.FeatureFlags;
Ling Ma51dd3022023-08-29 11:46:38 -070076import com.android.internal.telephony.flags.FeatureFlagsImpl;
Brad Ebinger05f52c22019-12-05 13:03:21 -080077import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn92479152021-01-20 16:30:10 -080078import com.android.internal.telephony.imsphone.ImsPhone;
79import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000080import com.android.internal.telephony.satellite.SatelliteController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000081import com.android.internal.telephony.uicc.UiccPort;
Jordan Liu06bdef12021-03-24 17:25:46 -070082import com.android.internal.telephony.uicc.UiccProfile;
Jack Yu1a2fc352017-07-14 17:14:37 -070083import com.android.internal.util.IndentingPrintWriter;
Andrew Leefb7f92e2015-02-26 16:23:32 -080084import com.android.phone.settings.SettingsConstants;
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -070085import com.android.phone.vvm.CarrierVvmPackageInstalledReceiver;
James.cf Linc9f35a42020-01-15 02:35:22 +080086import com.android.services.telephony.rcs.TelephonyRcsService;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087
Jack Yu1a2fc352017-07-14 17:14:37 -070088import java.io.FileDescriptor;
89import java.io.PrintWriter;
Jordan Liuff2ccd72019-07-23 15:54:41 -070090import java.lang.annotation.Retention;
91import java.lang.annotation.RetentionPolicy;
chen xubaf9fe52019-07-02 17:28:24 -070092import java.util.List;
Jack Yu1a2fc352017-07-14 17:14:37 -070093
Santos Cordon7d4ddf62013-07-10 11:58:08 -070094/**
95 * Global state for the telephony subsystem when running in the primary
96 * phone process.
97 */
Sailesh Nepalbf900542014-07-15 16:18:32 -070098public class PhoneGlobals extends ContextWrapper {
Jack Yu1a2fc352017-07-14 17:14:37 -070099 public static final String LOG_TAG = "PhoneGlobals";
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700100
101 /**
102 * Phone app-wide debug level:
103 * 0 - no debug logging
104 * 1 - normal debug logging if ro.debuggable is set (which is true in
105 * "eng" and "userdebug" builds but not "user" builds)
106 * 2 - ultra-verbose debug logging
107 *
108 * Most individual classes in the phone app have a local DBG constant,
109 * typically set to
110 * (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1)
111 * or else
112 * (PhoneApp.DBG_LEVEL >= 2)
113 * depending on the desired verbosity.
114 *
115 * ***** DO NOT SUBMIT WITH DBG_LEVEL > 0 *************
116 */
Andrew Lee88b51e22014-10-29 15:48:51 -0700117 public static final int DBG_LEVEL = 0;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118
119 private static final boolean DBG =
120 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
121 private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
122
123 // Message codes; see mHandler below.
124 private static final int EVENT_SIM_NETWORK_LOCKED = 3;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700125 private static final int EVENT_SIM_STATE_CHANGED = 8;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126 private static final int EVENT_DATA_ROAMING_DISCONNECTED = 10;
Jordan Liuff2ccd72019-07-23 15:54:41 -0700127 private static final int EVENT_DATA_ROAMING_CONNECTED = 11;
128 private static final int EVENT_DATA_ROAMING_OK = 12;
129 private static final int EVENT_UNSOL_CDMA_INFO_RECORD = 13;
Jordan Liuff2ccd72019-07-23 15:54:41 -0700130 private static final int EVENT_DATA_ROAMING_SETTINGS_CHANGED = 15;
131 private static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED = 16;
Lei Liu863eac02020-06-24 20:12:55 +0800132 private static final int EVENT_CARRIER_CONFIG_CHANGED = 17;
Sarah Chin072ffb22022-05-03 17:58:59 -0700133 private static final int EVENT_MULTI_SIM_CONFIG_CHANGED = 18;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134
135 // The MMI codes are also used by the InCallScreen.
136 public static final int MMI_INITIATE = 51;
137 public static final int MMI_COMPLETE = 52;
138 public static final int MMI_CANCEL = 53;
139 // Don't use message codes larger than 99 here; those are reserved for
140 // the individual Activities of the Phone UI.
141
Santos Cordone18902f2016-03-22 17:16:04 -0700142 public static final int AIRPLANE_ON = 1;
143 public static final int AIRPLANE_OFF = 0;
144
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700145 /**
146 * Allowable values for the wake lock code.
147 * SLEEP means the device can be put to sleep.
148 * PARTIAL means wake the processor, but we display can be kept off.
149 * FULL means wake both the processor and the display.
150 */
151 public enum WakeState {
152 SLEEP,
153 PARTIAL,
154 FULL
155 }
156
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157 private static PhoneGlobals sMe;
158
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159 CallManager mCM;
Santos Cordon63a84242013-07-23 13:32:52 -0700160 CallNotifier notifier;
Santos Cordon63a84242013-07-23 13:32:52 -0700161 NotificationMgr notificationMgr;
James.cf Linc9f35a42020-01-15 02:35:22 +0800162 TelephonyRcsService mTelephonyRcsService;
Andrew Lee9431b832015-03-09 18:46:45 -0700163 public PhoneInterfaceManager phoneMgr;
James.cf Linaf3183c2019-10-24 00:59:00 +0800164 public ImsRcsController imsRcsController;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000165 public ImsStateCallbackController mImsStateCallbackController;
joonhunshincffb7fc2021-11-28 07:32:01 +0000166 public ImsProvisioningController mImsProvisioningController;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800167 CarrierConfigLoader configLoader;
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
sangyun1c1918a2023-11-13 22:37:50 +0900220 // For reorganize_roaming_notification feature disabled.
221 @RoamingNotification
222 private int mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
223
224 // For reorganize_roaming_notification feature disabled.
225 /** Operator numerics for which we've shown is-roaming notifications. **/
226 private ArraySet<String> mPrevRoamingOperatorNumerics = new ArraySet<>();
227
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228 private WakeState mWakeState = WakeState.SLEEP;
229
230 private PowerManager mPowerManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700231 private PowerManager.WakeLock mWakeLock;
232 private PowerManager.WakeLock mPartialWakeLock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700233 private KeyguardManager mKeyguardManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700234
Jack Yu1a2fc352017-07-14 17:14:37 -0700235 private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
236 private final LocalLog mDataRoamingNotifLog = new LocalLog(50);
237
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700238 // Broadcast receiver for various intent broadcasts (see onCreate())
239 private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
240
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700241 private final CarrierVvmPackageInstalledReceiver mCarrierVvmPackageInstalledReceiver =
242 new CarrierVvmPackageInstalledReceiver();
243
Jack Yu1a2fc352017-07-14 17:14:37 -0700244 private final SettingsObserver mSettingsObserver;
Siim Sammul182d61b2021-05-04 16:01:42 +0100245 private BinderCallsStats.SettingsObserver mBinderCallsSettingsObserver;
Jack Yu1a2fc352017-07-14 17:14:37 -0700246
Sarah Chin072ffb22022-05-03 17:58:59 -0700247 // Mapping of phone ID to the associated TelephonyCallback. These should be registered without
248 // fine or coarse location since we only use ServiceState for
249 private PhoneAppCallback[] mTelephonyCallbacks;
250
sangyun15019e02023-11-13 21:50:15 +0900251 private FeatureFlags mFeatureFlags;
252
Sarah Chin072ffb22022-05-03 17:58:59 -0700253 private class PhoneAppCallback extends TelephonyCallback implements
254 TelephonyCallback.ServiceStateListener {
255 private final int mSubId;
256
257 PhoneAppCallback(int subId) {
258 mSubId = subId;
259 }
260
261 @Override
262 public void onServiceStateChanged(ServiceState serviceState) {
263 // Note when registering that we should be registering with INCLUDE_LOCATION_DATA_NONE.
264 // PhoneGlobals only uses the state and roaming status, which does not require location.
265 handleServiceStateChanged(serviceState, mSubId);
266 }
267
268 public int getSubId() {
269 return mSubId;
270 }
271 }
272
Nazish Tabassum160d2112019-12-23 17:31:33 +0530273 private static class EventSimStateChangedBag {
274 final int mPhoneId;
275 final String mIccStatus;
276
277 EventSimStateChangedBag(int phoneId, String iccStatus) {
278 mPhoneId = phoneId;
279 mIccStatus = iccStatus;
280 }
281 }
282
Jordan Liu06bdef12021-03-24 17:25:46 -0700283 // Some carrier config settings disable the network lock screen, so we call handleSimLock
284 // when either SIM_LOCK or CARRIER_CONFIG changes so that no matter which one happens first,
285 // we still do the right thing
286 private void handleSimLock(int subType, Phone phone) {
287 PersistableBundle cc = getCarrierConfigForSubId(phone.getSubId());
288 if (!CarrierConfigManager.isConfigForIdentifiedCarrier(cc)) {
289 // If we only have the default carrier config just return, to avoid popping up the
290 // the SIM lock screen when it's disabled by the carrier.
291 Log.i(LOG_TAG, "Not showing 'SIM network unlock' screen. Carrier config not loaded");
292 return;
293 }
294 if (cc.getBoolean(CarrierConfigManager.KEY_IGNORE_SIM_NETWORK_LOCKED_EVENTS_BOOL)) {
295 // Some products don't have the concept of a "SIM network lock"
296 Log.i(LOG_TAG, "Not showing 'SIM network unlock' screen. Disabled by carrier config");
297 return;
298 }
299
300 // if passed in subType is unknown, retrieve it here.
301 if (subType == -1) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000302 final UiccPort uiccPort = phone.getUiccPort();
303 if (uiccPort == null) {
Jordan Liu06bdef12021-03-24 17:25:46 -0700304 Log.e(LOG_TAG,
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000305 "handleSimLock: uiccPort for phone " + phone.getPhoneId() + " is null");
Jordan Liu06bdef12021-03-24 17:25:46 -0700306 return;
307 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000308 final UiccProfile uiccProfile = uiccPort.getUiccProfile();
Jordan Liu06bdef12021-03-24 17:25:46 -0700309 if (uiccProfile == null) {
310 Log.e(LOG_TAG,
311 "handleSimLock: uiccProfile for phone " + phone.getPhoneId() + " is null");
312 return;
313 }
314 subType = uiccProfile.getApplication(
315 uiccProfile.mCurrentAppType).getPersoSubState().ordinal();
316 }
317 // Normal case: show the "SIM network unlock" PIN entry screen.
318 // The user won't be able to do anything else until
319 // they enter a valid SIM network PIN.
320 Log.i(LOG_TAG, "show sim depersonal panel");
321 IccNetworkDepersonalizationPanel.showDialog(phone, subType);
322 }
323
324 private boolean isSimLocked(Phone phone) {
325 TelephonyManager tm = getSystemService(TelephonyManager.class);
326 return tm.createForSubscriptionId(phone.getSubId()).getSimState()
327 == TelephonyManager.SIM_STATE_NETWORK_LOCKED;
328 }
329
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700330 Handler mHandler = new Handler() {
331 @Override
332 public void handleMessage(Message msg) {
333 PhoneConstants.State phoneState;
Jack Yu1a2fc352017-07-14 17:14:37 -0700334 if (VDBG) Log.v(LOG_TAG, "event=" + msg.what);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700335 switch (msg.what) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700336 // TODO: This event should be handled by the lock screen, just
337 // like the "SIM missing" and "Sim locked" cases (bug 1804111).
338 case EVENT_SIM_NETWORK_LOCKED:
Jordan Liu06bdef12021-03-24 17:25:46 -0700339 int subType = (Integer) ((AsyncResult) msg.obj).result;
340 Phone phone = (Phone) ((AsyncResult) msg.obj).userObj;
341 handleSimLock(subType, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342 break;
343
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344 case EVENT_DATA_ROAMING_DISCONNECTED:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700345 notificationMgr.showDataRoamingNotification(msg.arg1, false);
346 break;
347
348 case EVENT_DATA_ROAMING_CONNECTED:
349 notificationMgr.showDataRoamingNotification(msg.arg1, true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350 break;
351
352 case EVENT_DATA_ROAMING_OK:
Jordan Liuff2ccd72019-07-23 15:54:41 -0700353 notificationMgr.hideDataRoamingNotification();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354 break;
355
356 case MMI_COMPLETE:
357 onMMIComplete((AsyncResult) msg.obj);
358 break;
359
360 case MMI_CANCEL:
Stuart Scottdcf40a92014-12-09 10:45:01 -0800361 PhoneUtils.cancelMmiCode(mCM.getFgPhone());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362 break;
363
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700364 case EVENT_SIM_STATE_CHANGED:
Nazish Tabassum160d2112019-12-23 17:31:33 +0530365 EventSimStateChangedBag bag = (EventSimStateChangedBag)msg.obj;
Sarah Chin010884c2023-06-14 15:55:08 -0700366 // Dismiss the "No services" notification if the SIM is removed.
367 if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(bag.mIccStatus)) {
368 notificationMgr.dismissNetworkSelectionNotificationForInactiveSubId();
369 }
370
371 // Marks the event where the SIM goes into ready state.
372 // Right now, this is only used for the PUK-unlocking process.
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700373 if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(bag.mIccStatus)
Nazish Tabassum59126a92020-07-03 21:44:49 +0530374 || IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(bag.mIccStatus)
375 || IccCardConstants.INTENT_VALUE_ICC_NOT_READY.equals(bag.mIccStatus)
376 || IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(bag.mIccStatus)) {
Sarah Chin010884c2023-06-14 15:55:08 -0700377 // When the right event is triggered and there are UI objects in the
378 // foreground, we close them to display the lock panel.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700379 if (mPUKEntryActivity != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700380 Log.i(LOG_TAG, "Dismiss puk entry activity");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 mPUKEntryActivity.finish();
382 mPUKEntryActivity = null;
383 }
384 if (mPUKEntryProgressDialog != null) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700385 Log.i(LOG_TAG, "Dismiss puk progress dialog");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700386 mPUKEntryProgressDialog.dismiss();
387 mPUKEntryProgressDialog = null;
388 }
Nazish Tabassum59126a92020-07-03 21:44:49 +0530389 Log.i(LOG_TAG, "Dismissing depersonal panel" + (bag.mIccStatus));
Nazish Tabassum160d2112019-12-23 17:31:33 +0530390 IccNetworkDepersonalizationPanel.dialogDismiss(bag.mPhoneId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700391 }
392 break;
393
394 case EVENT_UNSOL_CDMA_INFO_RECORD:
395 //TODO: handle message here;
396 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700397 case EVENT_DATA_ROAMING_SETTINGS_CHANGED:
sangyun1c1918a2023-11-13 22:37:50 +0900398 if (mFeatureFlags.reorganizeRoamingNotification()) {
399 updateDataRoamingStatus(
400 ROAMING_NOTIFICATION_REASON_DATA_ROAMING_SETTING_CHANGED);
401 } else {
402 updateDataRoamingStatusForFeatureDisabled(null);
403 }
sangyun35f23f82023-07-18 01:37:53 +0900404 break;
Jack Yu1a2fc352017-07-14 17:14:37 -0700405 case EVENT_MOBILE_DATA_SETTINGS_CHANGED:
sangyun1c1918a2023-11-13 22:37:50 +0900406 if (mFeatureFlags.reorganizeRoamingNotification()) {
407 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_DATA_SETTING_CHANGED);
408 } else {
409 updateDataRoamingStatusForFeatureDisabled(null);
410 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700411 break;
Lei Liu863eac02020-06-24 20:12:55 +0800412 case EVENT_CARRIER_CONFIG_CHANGED:
413 int subId = (Integer) msg.obj;
414 // The voicemail number could be overridden by carrier config, so need to
415 // refresh the message waiting (voicemail) indicator.
416 refreshMwiIndicator(subId);
Jordan Liu06bdef12021-03-24 17:25:46 -0700417 phone = getPhone(subId);
Sarah Chin072ffb22022-05-03 17:58:59 -0700418 if (phone != null) {
419 if (isSimLocked(phone)) {
420 // pass in subType=-1 so handleSimLock can find the actual subType if
421 // needed. This is safe as valid values for subType are >= 0
422 handleSimLock(-1, phone);
423 }
424 TelephonyManager tm = getSystemService(TelephonyManager.class);
425 PhoneAppCallback callback = mTelephonyCallbacks[phone.getPhoneId()];
426 // TODO: We may need to figure out a way to unregister if subId is invalid
427 tm.createForSubscriptionId(callback.getSubId())
428 .unregisterTelephonyCallback(callback);
429 callback = new PhoneAppCallback(subId);
430 tm.createForSubscriptionId(subId).registerTelephonyCallback(
Ling Ma317906d2022-12-05 15:58:14 -0800431 TelephonyManager.INCLUDE_LOCATION_DATA_COARSE, mHandler::post,
Sarah Chin072ffb22022-05-03 17:58:59 -0700432 callback);
433 mTelephonyCallbacks[phone.getPhoneId()] = callback;
434 }
435 break;
436 case EVENT_MULTI_SIM_CONFIG_CHANGED:
437 int activeModems = (int) ((AsyncResult) msg.obj).result;
438 TelephonyManager tm = getSystemService(TelephonyManager.class);
439 // Unregister all previous callbacks
440 for (int phoneId = 0; phoneId < mTelephonyCallbacks.length; phoneId++) {
441 PhoneAppCallback callback = mTelephonyCallbacks[phoneId];
442 if (callback != null) {
443 tm.createForSubscriptionId(callback.getSubId())
444 .unregisterTelephonyCallback(callback);
445 mTelephonyCallbacks[phoneId] = null;
446 }
447 }
448 // Register callbacks for all active modems
449 for (int phoneId = 0; phoneId < activeModems; phoneId++) {
450 int sub = PhoneFactory.getPhone(phoneId).getSubId();
451 PhoneAppCallback callback = new PhoneAppCallback(sub);
452 tm.createForSubscriptionId(sub).registerTelephonyCallback(
453 TelephonyManager.INCLUDE_LOCATION_DATA_NONE, mHandler::post,
454 callback);
455 mTelephonyCallbacks[phoneId] = callback;
Jordan Liu06bdef12021-03-24 17:25:46 -0700456 }
Lei Liu863eac02020-06-24 20:12:55 +0800457 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700458 }
459 }
460 };
461
462 public PhoneGlobals(Context context) {
463 super(context);
464 sMe = this;
Jack Yu1a2fc352017-07-14 17:14:37 -0700465 mSettingsObserver = new SettingsObserver(context, mHandler);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700466 }
467
468 public void onCreate() {
469 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
470
471 ContentResolver resolver = getContentResolver();
472
Hall Liuaa4211e2021-01-20 15:43:39 -0800473 // Initialize the shim from frameworks/opt/telephony into packages/services/Telephony.
474 TelephonyLocalConnection.setInstance(new LocalConnectionImpl(this));
475
Sarah Chin072ffb22022-05-03 17:58:59 -0700476 TelephonyManager tm = getSystemService(TelephonyManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700477 // Cache the "voice capable" flag.
478 // This flag currently comes from a resource (which is
479 // overrideable on a per-product basis):
Sarah Chin072ffb22022-05-03 17:58:59 -0700480 sVoiceCapable = tm.isVoiceCapable();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700481 // ...but this might eventually become a PackageManager "system
482 // feature" instead, in which case we'd do something like:
483 // sVoiceCapable =
484 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
485
Stuart Scottdcf40a92014-12-09 10:45:01 -0800486 if (mCM == null) {
Nathan Haroldf9df6ea2019-03-08 11:54:22 -0800487 // Initialize AnomalyReporter early so that it can be used
488 AnomalyReporter.initialize(this);
Nathan Harold0db5c5e2019-01-22 20:18:56 -0800489
Youming Ye47a6adc2018-11-19 15:33:36 -0800490 // Inject telephony component factory if configured using other jars.
491 XmlResourceParser parser = getResources().getXml(R.xml.telephony_injection);
492 TelephonyComponentFactory.getInstance().injectTheComponentFactory(parser);
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000493
494 // Create DomainSelectionResolver always, but it MUST be initialized only when
495 // the device supports AOSP domain selection architecture and
496 // has new IRadio that supports its related HAL APIs.
Hwangoo Parkbf3968c2024-01-19 07:49:22 +0000497 String dssComponentName = getResources().getString(
498 R.string.config_domain_selection_service_component_name);
499 DomainSelectionResolver.make(this, dssComponentName);
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000500
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700501 // Initialize the telephony framework
sangyun15019e02023-11-13 21:50:15 +0900502 mFeatureFlags = new FeatureFlagsImpl();
503 PhoneFactory.makeDefaultPhones(this, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700504
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000505 // Initialize the DomainSelectionResolver after creating the Phone instance
506 // to check the Radio HAL version.
507 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
Hwangoo Parkbf3968c2024-01-19 07:49:22 +0000508 DomainSelectionResolver.getInstance().initialize();
Daniel Bantab26e96f2022-10-19 23:25:35 +0000509 // Initialize EmergencyStateTracker if domain selection is supported
510 boolean isSuplDdsSwitchRequiredForEmergencyCall = getResources()
511 .getBoolean(R.bool.config_gnss_supl_requires_default_data_for_emergency);
512 EmergencyStateTracker.make(this, isSuplDdsSwitchRequiredForEmergencyCall);
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000513 }
514
Brad Ebinger05f52c22019-12-05 13:03:21 -0800515 // Only bring up ImsResolver if the device supports having an IMS stack.
516 if (getPackageManager().hasSystemFeature(
517 PackageManager.FEATURE_TELEPHONY_IMS)) {
518 // Get the package name of the default IMS implementation.
519 String defaultImsMmtelPackage = getResources().getString(
520 R.string.config_ims_mmtel_package);
521 String defaultImsRcsPackage = getResources().getString(
522 R.string.config_ims_rcs_package);
Brad Ebingerd1947d82021-05-17 20:54:49 +0000523 ImsResolver.make(this, defaultImsMmtelPackage,
Brad Ebingere3ae65a2020-09-11 12:45:11 -0700524 defaultImsRcsPackage, PhoneFactory.getPhones().length,
525 new ImsFeatureBinderRepository());
Brad Ebingerd1947d82021-05-17 20:54:49 +0000526 ImsResolver.getInstance().initialize();
Tyler Gunn92479152021-01-20 16:30:10 -0800527
528 // With the IMS phone created, load static config.xml values from the phone process
529 // so that it can be provided to the ImsPhoneCallTracker.
530 for (Phone p : PhoneFactory.getPhones()) {
531 Phone imsPhone = p.getImsPhone();
532 if (imsPhone != null && imsPhone instanceof ImsPhone) {
533 ImsPhone theImsPhone = (ImsPhone) imsPhone;
534 if (theImsPhone.getCallTracker() instanceof ImsPhoneCallTracker) {
535 ImsPhoneCallTracker ict = (ImsPhoneCallTracker)
536 theImsPhone.getCallTracker();
537
538 ImsPhoneCallTracker.Config config = new ImsPhoneCallTracker.Config();
539 config.isD2DCommunicationSupported = getResources().getBoolean(
540 R.bool.config_use_device_to_device_communication);
541 ict.setConfig(config);
542 }
543 }
544 }
Hui Wang068ab862020-10-31 05:12:53 +0000545 RcsProvisioningMonitor.make(this);
Brad Ebinger05f52c22019-12-05 13:03:21 -0800546 }
547
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700548 // Start TelephonyDebugService After the default phone is created.
549 Intent intent = new Intent(this, TelephonyDebugService.class);
550 startService(intent);
551
552 mCM = CallManager.getInstance();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700553
554 // Create the NotificationMgr singleton, which is used to display
555 // status bar icons and control other status bar behavior.
556 notificationMgr = NotificationMgr.init(this);
557
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000558 // Create the SatelliteController singleton, which acts as a backend service for
559 // {@link android.telephony.satellite.SatelliteManager}.
sangyun15019e02023-11-13 21:50:15 +0900560 SatelliteController.make(this, mFeatureFlags);
Sarah Chin5f57c582023-02-14 04:16:10 -0800561
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700562 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
563 cdmaPhoneCallState = new CdmaPhoneCallState();
564 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700565
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700566 // before registering for phone state changes
567 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
568 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
569 // lock used to keep the processor awake, when we don't care for the display.
570 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
571 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700572
573 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
574
sangyun15019e02023-11-13 21:50:15 +0900575 phoneMgr = PhoneInterfaceManager.init(this, mFeatureFlags);
Santos Cordon406c0342013-08-28 00:07:47 -0700576
joonhunshin2c33ed92023-12-12 14:29:23 +0000577 imsRcsController = ImsRcsController.init(this, mFeatureFlags);
James.cf Linaf3183c2019-10-24 00:59:00 +0800578
joonhunshin21a86812023-12-10 08:21:25 +0000579 configLoader = CarrierConfigLoader.init(this, mFeatureFlags);
Brad Ebinger6c53e7f2023-01-27 16:26:44 -0800580
James.cf Linc9f35a42020-01-15 02:35:22 +0800581 if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000582 mImsStateCallbackController =
583 ImsStateCallbackController.make(this, PhoneFactory.getPhones().length);
Brad Ebingera68a4972020-01-30 17:31:23 -0800584 mTelephonyRcsService = new TelephonyRcsService(this,
585 PhoneFactory.getPhones().length);
586 mTelephonyRcsService.initialize();
James.cf Linc9f35a42020-01-15 02:35:22 +0800587 imsRcsController.setRcsService(mTelephonyRcsService);
joonhunshincffb7fc2021-11-28 07:32:01 +0000588 mImsProvisioningController =
589 ImsProvisioningController.make(this, PhoneFactory.getPhones().length);
James.cf Linc9f35a42020-01-15 02:35:22 +0800590 }
591
Jack Yu1a2fc352017-07-14 17:14:37 -0700592 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700593 // asynchronous events from the telephony layer (like
594 // launching the incoming-call UI when an incoming call comes
595 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800596 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700597
Stuart Scottdcf40a92014-12-09 10:45:01 -0800598 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700599
600 // register for MMI/USSD
601 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
602
Qiong Liucc3fe812019-09-23 15:25:44 +0800603 // Initialize cell status using current airplane mode.
Taesu Lee62f826d2020-08-10 16:01:18 +0900604 handleAirplaneModeChange(
605 Settings.Global.getInt(
606 getContentResolver(),
607 Settings.Global.AIRPLANE_MODE_ON,
608 AIRPLANE_OFF)
609 == AIRPLANE_ON);
Qiong Liucc3fe812019-09-23 15:25:44 +0800610
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700611 // Register for misc other intent broadcasts.
612 IntentFilter intentFilter =
613 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700614 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
615 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700616 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700617 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
618 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700619 registerReceiver(mReceiver, intentFilter);
Jack Yuec144222023-12-13 16:03:03 -0800620 int defaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
621 if (SubscriptionManager.isValidSubscriptionId(defaultDataSubId)) {
622 if (VDBG) {
623 Log.v(LOG_TAG, "Loaded initial default data sub: " + defaultDataSubId);
sangyun15019e02023-11-13 21:50:15 +0900624 }
Jack Yuec144222023-12-13 16:03:03 -0800625 mDefaultDataSubId = defaultDataSubId;
626 registerSettingsObserver();
627 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED);
sangyundce559b2023-09-11 10:25:55 +0900628 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700629
Sarah Chin072ffb22022-05-03 17:58:59 -0700630 PhoneConfigurationManager.registerForMultiSimConfigChange(
631 mHandler, EVENT_MULTI_SIM_CONFIG_CHANGED, null);
632
633 mTelephonyCallbacks = new PhoneAppCallback[tm.getSupportedModemCount()];
Fangyuan Li7f5c2752022-06-29 18:02:31 +0800634 if (tm.getSupportedModemCount() > 0) {
635 for (Phone phone : PhoneFactory.getPhones()) {
636 int subId = phone.getSubId();
637 PhoneAppCallback callback = new PhoneAppCallback(subId);
638 tm.createForSubscriptionId(subId).registerTelephonyCallback(
639 TelephonyManager.INCLUDE_LOCATION_DATA_NONE, mHandler::post, callback);
640 mTelephonyCallbacks[phone.getPhoneId()] = callback;
641 }
Sarah Chin072ffb22022-05-03 17:58:59 -0700642 }
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700643 mCarrierVvmPackageInstalledReceiver.register(this);
644
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700645 //set the default values for the preferences in the phone.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700646 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700647 }
648
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700649 // XXX pre-load the SimProvider so that it's ready
650 resolver.getType(Uri.parse("content://icc/adn"));
651
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700652 // TODO: Register for Cdma Information Records
653 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
654
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700655 // Read HAC settings and configure audio hardware
656 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800657 int hac = android.provider.Settings.System.getInt(
658 getContentResolver(),
659 android.provider.Settings.System.HEARING_AID,
660 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700661 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Jordan Liuf71aeef2019-08-21 11:46:09 -0700662 audioManager.setParameters(
663 SettingsConstants.HAC_KEY + "=" + (hac == SettingsConstants.HAC_ENABLED
664 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700665 }
Siim Sammul182d61b2021-05-04 16:01:42 +0100666
667 // Start tracking Binder latency for the phone process.
668 mBinderCallsSettingsObserver = new BinderCallsStats.SettingsObserver(
669 getApplicationContext(),
Siim Sammula6950092021-06-22 17:14:03 +0100670 new BinderCallsStats(
671 new BinderCallsStats.Injector(),
672 com.android.internal.os.BinderLatencyProto.Dims.TELEPHONY));
Santos Cordonff506f52013-11-21 19:13:19 -0800673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700674
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700675 /**
676 * Returns the singleton instance of the PhoneApp.
677 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800678 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700679 if (sMe == null) {
680 throw new IllegalStateException("No PhoneGlobals here!");
681 }
682 return sMe;
683 }
684
685 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800686 * Returns the default phone.
687 *
Andrew Lee385019f2014-11-24 14:19:50 -0800688 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700689 */
Andrew Lee83383e42014-10-31 12:42:28 -0700690 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800691 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700692 }
693
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800694 public static Phone getPhone(int subId) {
695 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800696 }
697
Santos Cordonde10b752013-09-19 04:11:33 -0700698 /* package */ CallManager getCallManager() {
699 return mCM;
700 }
701
Chris Manton4e9fa912015-06-19 11:26:57 -0700702 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800703 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700704 }
705
Chris Manton4e9fa912015-06-19 11:26:57 -0700706 public PersistableBundle getCarrierConfigForSubId(int subId) {
Philip P. Moltmann0079aae2020-03-05 16:24:02 -0800707 return configLoader.getConfigForSubIdWithFeature(subId, getOpPackageName(),
708 getAttributionTag());
Junda Liu605148f2015-04-28 15:23:40 -0700709 }
710
Jack Yu1a2fc352017-07-14 17:14:37 -0700711 private void registerSettingsObserver() {
712 mSettingsObserver.unobserve();
713 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
714 String mobileDataSetting = Settings.Global.MOBILE_DATA;
715 if (TelephonyManager.getDefault().getSimCount() > 1) {
716 int subId = mDefaultDataSubId;
717 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
718 dataRoamingSetting += subId;
719 mobileDataSetting += subId;
720 }
721 }
722
723 // Listen for user data roaming setting changed event
724 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
725 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
726
727 // Listen for mobile data setting changed event
728 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
729 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
730 }
731
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700732 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700733 * Sets the activity responsible for un-PUK-blocking the device
734 * so that we may close it when we receive a positive result.
735 * mPUKEntryActivity is also used to indicate to the device that
736 * we are trying to un-PUK-lock the phone. In other words, iff
737 * it is NOT null, then we are trying to unlock and waiting for
738 * the SIM to move to READY state.
739 *
740 * @param activity is the activity to close when PUK has
741 * finished unlocking. Can be set to null to indicate the unlock
742 * or SIM READYing process is over.
743 */
744 void setPukEntryActivity(Activity activity) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700745 Log.i(LOG_TAG, "setPukEntryActivity - set to " + (activity == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700746 mPUKEntryActivity = activity;
747 }
748
749 Activity getPUKEntryActivity() {
750 return mPUKEntryActivity;
751 }
752
753 /**
754 * Sets the dialog responsible for notifying the user of un-PUK-
755 * blocking - SIM READYing progress, so that we may dismiss it
756 * when we receive a positive result.
757 *
758 * @param dialog indicates the progress dialog informing the user
759 * of the state of the device. Dismissed upon completion of
760 * READYing process
761 */
762 void setPukEntryProgressDialog(ProgressDialog dialog) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700763 Log.i(LOG_TAG, "setPukEntryProgressDialog - set to "
764 + (dialog == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700765 mPUKEntryProgressDialog = dialog;
766 }
767
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700768 KeyguardManager getKeyguardManager() {
769 return mKeyguardManager;
770 }
771
772 private void onMMIComplete(AsyncResult r) {
773 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
774 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800775 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700776 }
777
fionaxu80126972017-02-01 17:01:26 -0800778 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700779 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700780 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700781 }
782
Taesu Lee62f826d2020-08-10 16:01:18 +0900783 private void handleAirplaneModeChange(boolean isAirplaneNewlyOn) {
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700784 Log.i(LOG_TAG, "handleAirplaneModeChange: isAirplaneNewlyOn=" + isAirplaneNewlyOn);
Taesu Lee62f826d2020-08-10 16:01:18 +0900785 int cellState =
786 Settings.Global.getInt(
787 getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
Chris Mantona09f3632016-02-09 14:48:42 -0800788 switch (cellState) {
789 case PhoneConstants.CELL_OFF_FLAG:
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700790 // Airplane mode does not affect the cell radio if user has turned it off.
791 Log.i(LOG_TAG, "Ignore airplane mode change due to cell off.");
Chris Mantona09f3632016-02-09 14:48:42 -0800792 break;
793 case PhoneConstants.CELL_ON_FLAG:
Taesu Lee62f826d2020-08-10 16:01:18 +0900794 maybeTurnCellOff(isAirplaneNewlyOn);
Chris Mantona09f3632016-02-09 14:48:42 -0800795 break;
796 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
Taesu Lee62f826d2020-08-10 16:01:18 +0900797 maybeTurnCellOn(isAirplaneNewlyOn);
Chris Mantona09f3632016-02-09 14:48:42 -0800798 break;
799 }
Hall Liu7f56e1a2019-07-10 14:41:14 -0700800 for (Phone phone : PhoneFactory.getPhones()) {
801 phone.getServiceStateTracker().onAirplaneModeChanged(isAirplaneNewlyOn);
802 }
Chris Mantona09f3632016-02-09 14:48:42 -0800803 }
804
805 /*
806 * Returns true if the radio must be turned off when entering airplane mode.
807 */
Taesu Lee62f826d2020-08-10 16:01:18 +0900808 private boolean isCellOffInAirplaneMode() {
809 String airplaneModeRadios =
810 Settings.Global.getString(
811 getContentResolver(), Settings.Global.AIRPLANE_MODE_RADIOS);
Chris Mantona09f3632016-02-09 14:48:42 -0800812 return airplaneModeRadios == null
813 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
814 }
815
Taesu Lee62f826d2020-08-10 16:01:18 +0900816 private void setRadioPowerOff() {
Chris Mantona09f3632016-02-09 14:48:42 -0800817 Log.i(LOG_TAG, "Turning radio off - airplane");
Taesu Lee62f826d2020-08-10 16:01:18 +0900818 Settings.Global.putInt(
819 getContentResolver(),
820 Settings.Global.CELL_ON,
821 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Chris Mantona09f3632016-02-09 14:48:42 -0800822 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
Taesu Lee62f826d2020-08-10 16:01:18 +0900823 TelephonyProperties.airplane_mode_on(true); // true means int value 1
Chris Mantona09f3632016-02-09 14:48:42 -0800824 PhoneUtils.setRadioPower(false);
Ling Ma317906d2022-12-05 15:58:14 -0800825 clearCacheOnRadioOff();
826 }
827
828 /** Clear fields on power off radio **/
829 private void clearCacheOnRadioOff() {
830 // Re-show is-roaming notifications after APM mode
sangyun1c1918a2023-11-13 22:37:50 +0900831 if (mFeatureFlags.reorganizeRoamingNotification()) {
832 mShownNotificationReasons.clear();
833 } else {
834 mPrevRoamingOperatorNumerics.clear();
835 }
Chris Mantona09f3632016-02-09 14:48:42 -0800836 }
837
Taesu Lee62f826d2020-08-10 16:01:18 +0900838 private void setRadioPowerOn() {
Chris Mantona09f3632016-02-09 14:48:42 -0800839 Log.i(LOG_TAG, "Turning radio on - airplane");
Taesu Lee62f826d2020-08-10 16:01:18 +0900840 Settings.Global.putInt(
841 getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
842 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 1);
Meng Wang61307622019-10-23 14:08:43 -0700843 TelephonyProperties.airplane_mode_on(false); // false means int value 0
Chris Mantona09f3632016-02-09 14:48:42 -0800844 PhoneUtils.setRadioPower(true);
845 }
846
Taesu Lee62f826d2020-08-10 16:01:18 +0900847 private void maybeTurnCellOff(boolean isAirplaneNewlyOn) {
Chris Mantona09f3632016-02-09 14:48:42 -0800848 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700849 // If we are trying to turn off the radio, make sure there are no active
850 // emergency calls. If there are, switch airplane mode back to off.
Taesu Lee62f826d2020-08-10 16:01:18 +0900851 TelecomManager tm = (TelecomManager) getSystemService(TELECOM_SERVICE);
Tyler Gunn900d8fd2018-09-21 09:22:12 -0700852
853 if (tm != null && tm.isInEmergencyCall()) {
Santos Cordone18902f2016-03-22 17:16:04 -0700854 // Switch airplane mode back to off.
Jordan Liu0e819b12019-08-28 15:33:05 -0700855 ConnectivityManager cm =
Taesu Lee62f826d2020-08-10 16:01:18 +0900856 (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
Jordan Liu0e819b12019-08-28 15:33:05 -0700857 cm.setAirplaneMode(false);
Santos Cordone18902f2016-03-22 17:16:04 -0700858 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
859 .show();
860 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Taesu Lee62f826d2020-08-10 16:01:18 +0900861 } else if (isCellOffInAirplaneMode()) {
862 setRadioPowerOff();
Santos Cordone18902f2016-03-22 17:16:04 -0700863 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800864 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700865 }
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700866 } else {
867 Log.i(LOG_TAG, "Ignoring airplane mode: not newly on");
Chris Mantona09f3632016-02-09 14:48:42 -0800868 }
869 }
870
Taesu Lee62f826d2020-08-10 16:01:18 +0900871 private void maybeTurnCellOn(boolean isAirplaneNewlyOn) {
Chris Mantona09f3632016-02-09 14:48:42 -0800872 if (!isAirplaneNewlyOn) {
Taesu Lee62f826d2020-08-10 16:01:18 +0900873 setRadioPowerOn();
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700874 } else {
875 Log.i(LOG_TAG, "Ignoring airplane mode off: radio is already on.");
Santos Cordone18902f2016-03-22 17:16:04 -0700876 }
877 }
878
Santos Cordon593ab382013-08-06 21:58:23 -0700879 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700880 * Receiver for misc intent broadcasts the Phone app cares about.
881 */
882 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
883 @Override
884 public void onReceive(Context context, Intent intent) {
885 String action = intent.getAction();
886 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Taesu Lee3dc572b2020-08-07 18:16:22 +0900887 boolean airplaneMode = intent.getBooleanExtra("state", false);
Taesu Lee62f826d2020-08-10 16:01:18 +0900888 handleAirplaneModeChange(airplaneMode);
Amit Mahajanf5d92c82018-11-02 17:44:40 -0700889 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
890 // re-register as it may be a new IccCard
891 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
892 SubscriptionManager.INVALID_PHONE_INDEX);
893 if (SubscriptionManager.isValidPhoneId(phoneId)) {
894 PhoneUtils.unregisterIccStatus(mHandler, phoneId);
895 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED, phoneId);
896 }
Nazish Tabassum160d2112019-12-23 17:31:33 +0530897 String iccStatus = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
898 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
899 new EventSimStateChangedBag(phoneId, iccStatus)));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700900 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
901 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800902 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
903 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700904 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530905 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530906 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530907 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
908 if (phoneInEcm != null) {
909 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
910 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
911 // Start Emergency Callback Mode service
Daniel Bright30efde42020-01-09 22:11:15 -0800912 if (intent.getBooleanExtra(
913 TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530914 context.startService(new Intent(context,
915 EmergencyCallbackModeService.class));
916 } else {
917 phoneInEcm = null;
918 }
919 } else {
920 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
921 // on a device that doesn't support ECM in the first place.
922 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
923 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
924 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700925 }
926 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530927 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700928 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700929 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
930 // Roaming status could be overridden by carrier config, so we need to update it.
931 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
sangyun1c1918a2023-11-13 22:37:50 +0900932 if (mFeatureFlags.reorganizeRoamingNotification()) {
933 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED);
934 } else {
935 updateDataRoamingStatusForFeatureDisabled(null);
936 }
chen xubaf9fe52019-07-02 17:28:24 -0700937 updateLimitedSimFunctionForDualSim();
Lei Liu863eac02020-06-24 20:12:55 +0800938 int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
939 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
940 if (SubscriptionManager.isValidSubscriptionId(subId)) {
941 mHandler.sendMessage(mHandler.obtainMessage(EVENT_CARRIER_CONFIG_CHANGED,
942 new Integer(subId)));
943 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700944 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
945 // We also need to pay attention when default data subscription changes.
946 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
947 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
948 registerSettingsObserver();
949 Phone phone = getPhone(mDefaultDataSubId);
950 if (phone != null) {
sangyun1c1918a2023-11-13 22:37:50 +0900951 if (mFeatureFlags.reorganizeRoamingNotification()) {
952 updateDataRoamingStatus(
953 ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED);
954 } else {
955 updateDataRoamingStatusForFeatureDisabled(null);
956 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700957 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700958 }
959 }
960 }
961
Sarah Chin072ffb22022-05-03 17:58:59 -0700962 private void handleServiceStateChanged(ServiceState serviceState, int subId) {
Jack Yu1a2fc352017-07-14 17:14:37 -0700963 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Sarah Chin072ffb22022-05-03 17:58:59 -0700964 int state = serviceState.getState();
965 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -0700966
Sarah Chin072ffb22022-05-03 17:58:59 -0700967 if (VDBG) {
968 Log.v(LOG_TAG, "subId=" + subId + ", mDefaultDataSubId="
969 + mDefaultDataSubId + ", ss roaming=" + serviceState.getDataRoaming());
970 }
971 if (subId == mDefaultDataSubId) {
sangyun1c1918a2023-11-13 22:37:50 +0900972 if (mFeatureFlags.reorganizeRoamingNotification()) {
973 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED);
974 } else {
975 updateDataRoamingStatusForFeatureDisabled(serviceState.getOperatorNumeric());
976 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700977 }
978 }
979
Jack Yu1a2fc352017-07-14 17:14:37 -0700980 /**
981 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
982 * to notify the user so they can enable it through settings. Vise versa if the condition
983 * changes, we need to dismiss the notification.
sangyun35f23f82023-07-18 01:37:53 +0900984 * @param reason to inform which event is called for notification update.
Jack Yu1a2fc352017-07-14 17:14:37 -0700985 */
sangyun35f23f82023-07-18 01:37:53 +0900986 private void updateDataRoamingStatus(@RoamingNotificationReason int reason) {
Jack Yu1a2fc352017-07-14 17:14:37 -0700987 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
988 Phone phone = getPhone(mDefaultDataSubId);
989 if (phone == null) {
990 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
991 return;
992 }
993
sangyun35f23f82023-07-18 01:37:53 +0900994 ServiceState serviceState = phone.getServiceState();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -0800995 if (serviceState == null) {
996 Log.e(LOG_TAG, "updateDataRoamingStatus: serviceState is null");
997 return;
998 }
999
sangyun35f23f82023-07-18 01:37:53 +09001000 String roamingNumeric = serviceState.getOperatorNumeric();
1001 String roamingNumericReason = "RoamingNumeric=" + roamingNumeric;
1002 String callingReason = "CallingReason=" + reason;
1003 boolean dataIsNowRoaming = serviceState.getDataRoaming();
Jack Yu3e2ac6e2022-03-26 13:59:45 -07001004 boolean dataAllowed;
1005 boolean notAllowedDueToRoamingOff;
Sarah Chine04784a2022-10-31 20:32:34 -07001006 List<DataDisallowedReason> reasons = phone.getDataNetworkController()
1007 .getInternetDataDisallowedReasons();
Jack Yu7968c6d2022-07-31 00:43:21 -07001008 dataAllowed = reasons.isEmpty();
1009 notAllowedDueToRoamingOff = (reasons.size() == 1
1010 && reasons.contains(DataDisallowedReason.ROAMING_DISABLED));
sangyun35f23f82023-07-18 01:37:53 +09001011 StringBuilder sb = new StringBuilder("updateDataRoamingStatus");
1012 sb.append(" dataAllowed=").append(dataAllowed);
1013 sb.append(", reasons=").append(reasons);
1014 sb.append(", dataIsNowRoaming=").append(dataIsNowRoaming);
1015 sb.append(", ").append(roamingNumericReason);
1016 sb.append(", ").append(callingReason);
1017 mDataRoamingNotifLog.log(sb.toString());
Ling Ma317906d2022-12-05 15:58:14 -08001018 if (VDBG) {
sangyun35f23f82023-07-18 01:37:53 +09001019 Log.v(LOG_TAG, sb.toString());
Ling Ma317906d2022-12-05 15:58:14 -08001020 }
Jack Yu3e2ac6e2022-03-26 13:59:45 -07001021
sangyun35f23f82023-07-18 01:37:53 +09001022 // Determine if a given roaming numeric has never been shown.
1023 boolean shownInThisNumeric = false;
1024 if (reason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED
1025 || reason == ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED) {
1026 shownInThisNumeric = mShownNotificationReasons.contains(roamingNumericReason);
1027 }
1028 // Determine if a notification has never been shown by given calling reason.
1029 boolean shownForThisReason = mShownNotificationReasons.contains(callingReason);
1030
Jack Yu3e2ac6e2022-03-26 13:59:45 -07001031 if (!dataAllowed && notAllowedDueToRoamingOff) {
sangyun35f23f82023-07-18 01:37:53 +09001032 if (!shownInThisNumeric && roamingNumeric != null) {
1033 mShownNotificationReasons.add(roamingNumericReason);
1034 }
1035 if (!shownForThisReason
1036 && reason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED) {
1037 mShownNotificationReasons.add(callingReason);
Ling Ma4e15c322022-12-07 11:20:53 -08001038 }
Jordan Liuff2ccd72019-07-23 15:54:41 -07001039 // No need to show it again if we never cancelled it explicitly.
sangyun35f23f82023-07-18 01:37:53 +09001040 if (getCurrentRoamingNotification() == ROAMING_NOTIFICATION_DISCONNECTED) {
1041 return;
1042 }
1043
Jack Yu1a2fc352017-07-14 17:14:37 -07001044 // If the only reason of no data is data roaming disabled, then we notify the user
1045 // so the user can turn on data roaming.
sangyun35f23f82023-07-18 01:37:53 +09001046 if (!shownInThisNumeric && !shownForThisReason) {
1047 updateDataRoamingNotification(ROAMING_NOTIFICATION_DISCONNECTED);
1048 } else {
1049 // Don't show roaming notification if we've already shown for this MccMnc
1050 Log.d(LOG_TAG, "Skip roaming disconnected notification since already"
1051 + " shownInThisNumeric=" + shownInThisNumeric
1052 + " shownForThisReason=" + shownForThisReason);
1053 // Dismiss notification if the other notification is shown.
1054 if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
1055 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
1056 }
1057 }
1058 } else if (dataAllowed && dataIsNowRoaming) {
1059 if (!shownInThisNumeric && roamingNumeric != null) {
1060 mShownNotificationReasons.add(roamingNumericReason);
1061 }
1062 if (!shownForThisReason
1063 && reason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED) {
1064 mShownNotificationReasons.add(callingReason);
1065 }
Sarah Chin37b39072023-11-05 13:28:21 -08001066 boolean shouldShowRoamingNotification = shouldShowRoamingNotification(roamingNumeric);
sangyun35f23f82023-07-18 01:37:53 +09001067 // No need to show it again if we never cancelled it explicitly.
1068 if (getCurrentRoamingNotification() == ROAMING_NOTIFICATION_CONNECTED) {
Ling Ma4e15c322022-12-07 11:20:53 -08001069 return;
1070 }
sangyun35f23f82023-07-18 01:37:53 +09001071
1072 // Inform users that roaming charges may apply.
Sarah Chin37b39072023-11-05 13:28:21 -08001073 if (!shownInThisNumeric && !shownForThisReason && shouldShowRoamingNotification) {
sangyun35f23f82023-07-18 01:37:53 +09001074 updateDataRoamingNotification(ROAMING_NOTIFICATION_CONNECTED);
1075 } else {
1076 // Don't show roaming notification if we've already shown for this MccMnc or
1077 // disabled from carrier config.
1078 Log.d(LOG_TAG, "Skip roaming connected notification since already"
1079 + " shownInThisNumeric:" + shownInThisNumeric
1080 + " shownForThisReason:" + shownForThisReason
Sarah Chin37b39072023-11-05 13:28:21 -08001081 + " shouldShowRoamingNotification:" + shouldShowRoamingNotification);
sangyun35f23f82023-07-18 01:37:53 +09001082 // Dismiss notification if the other notification is shown.
1083 if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
1084 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
1085 }
1086 }
1087 } else if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
Jordan Liuff2ccd72019-07-23 15:54:41 -07001088 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
1089 // is not the only data disable reason. In this case we dismiss the notification we
1090 // showed earlier.
sangyun35f23f82023-07-18 01:37:53 +09001091 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
Jack Yu1a2fc352017-07-14 17:14:37 -07001092 }
1093 }
1094
sangyun35f23f82023-07-18 01:37:53 +09001095 private void updateDataRoamingNotification(@RoamingNotification int roamingNotification) {
1096 int event;
1097 switch (roamingNotification) {
1098 case ROAMING_NOTIFICATION_NO_NOTIFICATION:
1099 Log.d(LOG_TAG, "Dismiss roaming notification");
1100 mDataRoamingNotifLog.log("Hide roaming.");
1101 event = EVENT_DATA_ROAMING_OK;
1102 break;
1103 case ROAMING_NOTIFICATION_CONNECTED:
1104 Log.d(LOG_TAG, "Show roaming connected notification");
1105 mDataRoamingNotifLog.log("Show roaming on.");
1106 event = EVENT_DATA_ROAMING_CONNECTED;
1107 break;
1108 case ROAMING_NOTIFICATION_DISCONNECTED:
1109 Log.d(LOG_TAG, "Show roaming disconnected notification");
1110 mDataRoamingNotifLog.log("Show roaming off.");
1111 event = EVENT_DATA_ROAMING_DISCONNECTED;
1112 break;
1113 default:
1114 Log.d(LOG_TAG, "Should never reach here.");
1115 mDataRoamingNotifLog.log("Should never reach here.");
1116 return;
1117 }
1118 mCurrentRoamingNotification = roamingNotification;
1119 mHandler.obtainMessage(event, mDefaultDataSubId, 0).sendToTarget();
1120 }
1121
1122 private @RoamingNotification int getCurrentRoamingNotification() {
1123 return mCurrentRoamingNotification;
1124 }
1125
sangyun1c1918a2023-11-13 22:37:50 +09001126 // For reorganize_roaming_notification feature disabled.
1127 /**
1128 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
1129 * to notify the user so they can enable it through settings. Vise versa if the condition
1130 * changes, we need to dismiss the notification.
1131 * @param roamingOperatorNumeric The operator numeric for the current roaming. {@code null} if
1132 * the current roaming operator numeric didn't change.
1133 */
1134 private void updateDataRoamingStatusForFeatureDisabled(
1135 @Nullable String roamingOperatorNumeric) {
1136 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatusForFeatureDisabled");
1137 Phone phone = getPhone(mDefaultDataSubId);
1138 if (phone == null) {
1139 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
1140 return;
1141 }
1142
1143 boolean dataAllowed;
1144 boolean notAllowedDueToRoamingOff;
1145 List<DataDisallowedReason> reasons = phone.getDataNetworkController()
1146 .getInternetDataDisallowedReasons();
1147 dataAllowed = reasons.isEmpty();
1148 notAllowedDueToRoamingOff = (reasons.size() == 1
1149 && reasons.contains(DataDisallowedReason.ROAMING_DISABLED));
1150 mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons
1151 + ", roamingOperatorNumeric=" + roamingOperatorNumeric);
1152 if (VDBG) {
1153 Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons
1154 + ", roamingOperatorNumeric=" + roamingOperatorNumeric);
1155 }
1156
1157 if (!dataAllowed && notAllowedDueToRoamingOff) {
1158 // Don't show roaming notification if we've already shown for this MccMnc
1159 if (roamingOperatorNumeric != null
1160 && !mPrevRoamingOperatorNumerics.add(roamingOperatorNumeric)) {
1161 Log.d(LOG_TAG, "Skip roaming disconnected notification since already shown in "
1162 + "MccMnc " + roamingOperatorNumeric);
1163 return;
1164 }
1165 // No need to show it again if we never cancelled it explicitly.
1166 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_DISCONNECTED) return;
1167 // If the only reason of no data is data roaming disabled, then we notify the user
1168 // so the user can turn on data roaming.
1169 mPrevRoamingNotification = ROAMING_NOTIFICATION_DISCONNECTED;
1170 Log.d(LOG_TAG, "Show roaming disconnected notification");
1171 mDataRoamingNotifLog.log("Show roaming off.");
1172 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_DISCONNECTED);
1173 msg.arg1 = mDefaultDataSubId;
1174 msg.sendToTarget();
1175 } else if (dataAllowed && dataIsNowRoaming(mDefaultDataSubId)) {
Sarah Chin37b39072023-11-05 13:28:21 -08001176 if (!shouldShowRoamingNotification(roamingOperatorNumeric)) {
1177 Log.d(LOG_TAG, "Skip showing roaming connected notification.");
1178 return;
1179 }
sangyun1c1918a2023-11-13 22:37:50 +09001180 // Don't show roaming notification if we've already shown for this MccMnc
1181 if (roamingOperatorNumeric != null
1182 && !mPrevRoamingOperatorNumerics.add(roamingOperatorNumeric)) {
1183 Log.d(LOG_TAG, "Skip roaming connected notification since already shown in "
1184 + "MccMnc " + roamingOperatorNumeric);
1185 return;
1186 }
1187 // No need to show it again if we never cancelled it explicitly, or carrier config
1188 // indicates this is not needed.
1189 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_CONNECTED) return;
1190 mPrevRoamingNotification = ROAMING_NOTIFICATION_CONNECTED;
1191 Log.d(LOG_TAG, "Show roaming connected notification");
1192 mDataRoamingNotifLog.log("Show roaming on.");
1193 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_CONNECTED);
1194 msg.arg1 = mDefaultDataSubId;
1195 msg.sendToTarget();
1196 } else if (mPrevRoamingNotification != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
1197 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
1198 // is not the only data disable reason. In this case we dismiss the notification we
1199 // showed earlier.
1200 mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
1201 Log.d(LOG_TAG, "Dismiss roaming notification");
1202 mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed);
1203 mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
1204 }
1205 }
1206
Jordan Liuff2ccd72019-07-23 15:54:41 -07001207 /**
1208 *
1209 * @param subId to check roaming on
1210 * @return whether we have transitioned to dataRoaming
1211 */
1212 private boolean dataIsNowRoaming(int subId) {
Sarah Chine04784a2022-10-31 20:32:34 -07001213 return getPhone(subId).getServiceState().getDataRoaming();
Jordan Liuff2ccd72019-07-23 15:54:41 -07001214 }
1215
Sarah Chin37b39072023-11-05 13:28:21 -08001216 private boolean shouldShowRoamingNotification(String roamingNumeric) {
1217 PersistableBundle config = getCarrierConfigForSubId(mDefaultDataSubId);
1218 boolean showRoamingNotification = config.getBoolean(
1219 CarrierConfigManager.KEY_SHOW_DATA_CONNECTED_ROAMING_NOTIFICATION_BOOL);
1220
1221 if (TextUtils.isEmpty(roamingNumeric) || !mFeatureFlags.hideRoamingIcon()) {
1222 Log.d(LOG_TAG, "shouldShowRoamingNotification: roamingNumeric=" + roamingNumeric
1223 + ", hideRoaming=" + mFeatureFlags.hideRoamingIcon());
1224 return showRoamingNotification;
1225 }
1226
1227 String[] includedMccMncs = config.getStringArray(CarrierConfigManager
1228 .KEY_DATA_CONNECTED_ROAMING_NOTIFICATION_INCLUDED_MCC_MNCS_STRING_ARRAY);
1229 if (includedMccMncs != null) {
1230 for (String mccMnc : includedMccMncs) {
1231 if (roamingNumeric.equals(mccMnc)) {
1232 Log.d(LOG_TAG, "shouldShowRoamingNotification: show for MCC/MNC " + mccMnc);
1233 return showRoamingNotification;
1234 }
1235 }
1236 }
1237
1238 String[] excludedMccs = config.getStringArray(CarrierConfigManager
1239 .KEY_DATA_CONNECTED_ROAMING_NOTIFICATION_EXCLUDED_MCCS_STRING_ARRAY);
1240 String roamingMcc = roamingNumeric.length() < 3 ? "" : roamingNumeric.substring(0, 3);
1241 if (excludedMccs != null && !TextUtils.isEmpty(roamingMcc)) {
1242 for (String mcc : excludedMccs) {
1243 if (roamingMcc.equals(mcc)) {
1244 Log.d(LOG_TAG, "shouldShowRoamingNotification: ignore for MCC " + mcc);
1245 return false;
1246 }
1247 }
1248 }
1249
1250 if (showRoamingNotification) {
1251 Log.d(LOG_TAG, "shouldShowRoamingNotification: show for numeric " + roamingNumeric);
1252 }
1253 return showRoamingNotification;
1254 }
1255
chen xubaf9fe52019-07-02 17:28:24 -07001256 private void updateLimitedSimFunctionForDualSim() {
1257 if (DBG) Log.d(LOG_TAG, "updateLimitedSimFunctionForDualSim");
1258 // check conditions to display limited SIM function notification under dual SIM
1259 SubscriptionManager subMgr = (SubscriptionManager) getSystemService(
1260 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
1261 List<SubscriptionInfo> subList = subMgr.getActiveSubscriptionInfoList(false);
1262 if (subList != null && subList.size() > 1) {
1263 CarrierConfigManager configMgr = (CarrierConfigManager)
1264 getSystemService(Context.CARRIER_CONFIG_SERVICE);
1265 for (SubscriptionInfo info : subList) {
1266 PersistableBundle b = configMgr.getConfigForSubId(info.getSubscriptionId());
1267 if (b != null) {
1268 if (b.getBoolean(CarrierConfigManager
1269 .KEY_LIMITED_SIM_FUNCTION_NOTIFICATION_FOR_DSDS_BOOL)) {
1270 notificationMgr.showLimitedSimFunctionWarningNotification(
1271 info.getSubscriptionId(),
1272 info.getDisplayName().toString());
1273 } else {
1274 notificationMgr.dismissLimitedSimFunctionWarningNotification(
1275 info.getSubscriptionId());
1276 }
1277 }
1278 }
1279 } else {
1280 // cancel notifications for all subs
1281 notificationMgr.dismissLimitedSimFunctionWarningNotification(
1282 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1283 }
1284 notificationMgr.dismissLimitedSimFunctionWarningNotificationForInactiveSubs();
1285
1286 }
1287
Sandeep Kuntade73a6a2014-10-15 18:45:56 +05301288 public Phone getPhoneInEcm() {
1289 return phoneInEcm;
1290 }
1291
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001292 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -08001293 * Triggers a refresh of the message waiting (voicemail) indicator.
1294 *
1295 * @param subId the subscription id we should refresh the notification for.
1296 */
1297 public void refreshMwiIndicator(int subId) {
1298 notificationMgr.refreshMwi(subId);
1299 }
1300
1301 /**
Pengquan Mengdd9ac822018-09-20 15:25:35 -07001302 * Called when the network selection on the subscription {@code subId} is changed by the user.
1303 *
1304 * @param subId the subscription id.
1305 */
1306 public void onNetworkSelectionChanged(int subId) {
1307 Phone phone = getPhone(subId);
1308 if (phone != null) {
1309 notificationMgr.updateNetworkSelection(phone.getServiceState().getState(), subId);
1310 } else {
1311 Log.w(LOG_TAG, "onNetworkSelectionChanged on null phone, subId: " + subId);
1312 }
1313 }
1314
1315 /**
James.cf Lin4b784aa2021-01-31 03:25:15 +08001316 * @return whether the device supports RCS User Capability Exchange or not.
1317 */
1318 public boolean getDeviceUceEnabled() {
1319 return (mTelephonyRcsService == null) ? false : mTelephonyRcsService.isDeviceUceEnabled();
1320 }
1321
1322 /**
1323 * Set the device supports RCS User Capability Exchange.
1324 * @param isEnabled true if the device supports UCE.
1325 */
1326 public void setDeviceUceEnabled(boolean isEnabled) {
1327 if (mTelephonyRcsService != null) {
1328 mTelephonyRcsService.setDeviceUceEnabled(isEnabled);
1329 }
1330 }
1331
1332 /**
Jack Yu1a2fc352017-07-14 17:14:37 -07001333 * Dump the state of the object, add calls to other objects as desired.
1334 *
1335 * @param fd File descriptor
1336 * @param printWriter Print writer
1337 * @param args Arguments
1338 */
1339 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
1340 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
1341 pw.println("------- PhoneGlobals -------");
1342 pw.increaseIndent();
sangyun15019e02023-11-13 21:50:15 +09001343 pw.println("FeatureFlags:");
1344 pw.increaseIndent();
sangyun1c1918a2023-11-13 22:37:50 +09001345 pw.println("reorganizeRoamingNotification="
1346 + mFeatureFlags.reorganizeRoamingNotification());
sangyund5f37ab2023-11-13 22:52:28 +09001347 pw.println("dismissNetworkSelectionNotificationOnSimDisable="
1348 + mFeatureFlags.dismissNetworkSelectionNotificationOnSimDisable());
sangyun15019e02023-11-13 21:50:15 +09001349 pw.decreaseIndent();
sangyun1c1918a2023-11-13 22:37:50 +09001350 if (mFeatureFlags.reorganizeRoamingNotification()) {
1351 pw.println("mCurrentRoamingNotification=" + mCurrentRoamingNotification);
1352 } else {
1353 pw.println("mPrevRoamingNotification=" + mPrevRoamingNotification);
1354 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001355 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
Keun young Parkdebb8532019-05-30 16:35:27 -07001356 pw.println("isSmsCapable=" + TelephonyManager.from(this).isSmsCapable());
sangyun35f23f82023-07-18 01:37:53 +09001357 pw.println("mDataRoamingNotifLog:");
Jack Yu1a2fc352017-07-14 17:14:37 -07001358 pw.increaseIndent();
1359 mDataRoamingNotifLog.dump(fd, pw, args);
1360 pw.decreaseIndent();
Brad Ebinger05f52c22019-12-05 13:03:21 -08001361 pw.println("ImsResolver:");
1362 pw.increaseIndent();
1363 try {
Brad Ebingerd1947d82021-05-17 20:54:49 +00001364 if (ImsResolver.getInstance() != null) ImsResolver.getInstance().dump(fd, pw, args);
Brad Ebinger05f52c22019-12-05 13:03:21 -08001365 } catch (Exception e) {
1366 e.printStackTrace();
1367 }
1368 pw.decreaseIndent();
Brad Ebingera68a4972020-01-30 17:31:23 -08001369 pw.println("RcsService:");
1370 try {
1371 if (mTelephonyRcsService != null) mTelephonyRcsService.dump(fd, pw, args);
1372 } catch (Exception e) {
1373 e.printStackTrace();
1374 }
Hunsuk Choi89bd22c2021-11-01 13:04:54 +00001375 pw.println("ImsStateCallbackController:");
1376 try {
1377 if (mImsStateCallbackController != null) mImsStateCallbackController.dump(pw);
1378 } catch (Exception e) {
1379 e.printStackTrace();
1380 }
Hwangoo Parkba21cf22022-11-30 14:34:04 +00001381 pw.println("DomainSelectionResolver:");
1382 pw.increaseIndent();
1383 try {
1384 if (DomainSelectionResolver.getInstance() != null) {
1385 DomainSelectionResolver.getInstance().dump(fd, pw, args);
1386 }
1387 } catch (Exception e) {
1388 e.printStackTrace();
1389 }
1390 pw.decreaseIndent();
Jack Yu1a2fc352017-07-14 17:14:37 -07001391 pw.decreaseIndent();
sangyun1c1918a2023-11-13 22:37:50 +09001392 if (mFeatureFlags.reorganizeRoamingNotification()) {
1393 pw.println("mShownNotificationReasons=" + mShownNotificationReasons);
1394 } else {
1395 pw.println("mPrevRoamingOperatorNumerics:" + mPrevRoamingOperatorNumerics);
1396 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001397 pw.println("------- End PhoneGlobals -------");
1398 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001399}