blob: cbbc8891ed540fe73ee06e064a50154aa6eb6480 [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
joonhunshin051ab232024-02-06 02:21:46 +0000244 private 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
joonhunshin051ab232024-02-06 02:21:46 +0000251 private FeatureFlags mFeatureFlags = new FeatureFlagsImpl();
sangyun15019e02023-11-13 21:50:15 +0900252
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;
joonhunshin051ab232024-02-06 02:21:46 +0000465 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
466 if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
467 mSettingsObserver = new SettingsObserver(context, mHandler);
468 }
469 } else {
470 mSettingsObserver = new SettingsObserver(context, mHandler);
471 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700472 }
473
474 public void onCreate() {
475 if (VDBG) Log.v(LOG_TAG, "onCreate()...");
476
477 ContentResolver resolver = getContentResolver();
478
joonhunshin051ab232024-02-06 02:21:46 +0000479 if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
480 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
481 Log.v(LOG_TAG, "onCreate()... but not defined FEATURE_TELEPHONY");
482 return;
483 }
484 }
485
Hall Liuaa4211e2021-01-20 15:43:39 -0800486 // Initialize the shim from frameworks/opt/telephony into packages/services/Telephony.
487 TelephonyLocalConnection.setInstance(new LocalConnectionImpl(this));
488
Sarah Chin072ffb22022-05-03 17:58:59 -0700489 TelephonyManager tm = getSystemService(TelephonyManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700490 // Cache the "voice capable" flag.
491 // This flag currently comes from a resource (which is
492 // overrideable on a per-product basis):
Sarah Chin072ffb22022-05-03 17:58:59 -0700493 sVoiceCapable = tm.isVoiceCapable();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700494 // ...but this might eventually become a PackageManager "system
495 // feature" instead, in which case we'd do something like:
496 // sVoiceCapable =
497 // getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);
498
Stuart Scottdcf40a92014-12-09 10:45:01 -0800499 if (mCM == null) {
Nathan Haroldf9df6ea2019-03-08 11:54:22 -0800500 // Initialize AnomalyReporter early so that it can be used
501 AnomalyReporter.initialize(this);
Nathan Harold0db5c5e2019-01-22 20:18:56 -0800502
Youming Ye47a6adc2018-11-19 15:33:36 -0800503 // Inject telephony component factory if configured using other jars.
504 XmlResourceParser parser = getResources().getXml(R.xml.telephony_injection);
505 TelephonyComponentFactory.getInstance().injectTheComponentFactory(parser);
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000506
507 // Create DomainSelectionResolver always, but it MUST be initialized only when
508 // the device supports AOSP domain selection architecture and
509 // has new IRadio that supports its related HAL APIs.
Hwangoo Parkbf3968c2024-01-19 07:49:22 +0000510 String dssComponentName = getResources().getString(
511 R.string.config_domain_selection_service_component_name);
512 DomainSelectionResolver.make(this, dssComponentName);
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000513
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700514 // Initialize the telephony framework
sangyun15019e02023-11-13 21:50:15 +0900515 PhoneFactory.makeDefaultPhones(this, mFeatureFlags);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700516
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000517 // Initialize the DomainSelectionResolver after creating the Phone instance
518 // to check the Radio HAL version.
519 if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) {
Hwangoo Parkbf3968c2024-01-19 07:49:22 +0000520 DomainSelectionResolver.getInstance().initialize();
Daniel Bantab26e96f2022-10-19 23:25:35 +0000521 // Initialize EmergencyStateTracker if domain selection is supported
522 boolean isSuplDdsSwitchRequiredForEmergencyCall = getResources()
523 .getBoolean(R.bool.config_gnss_supl_requires_default_data_for_emergency);
524 EmergencyStateTracker.make(this, isSuplDdsSwitchRequiredForEmergencyCall);
Hwangoo Parkba21cf22022-11-30 14:34:04 +0000525 }
526
Brad Ebinger05f52c22019-12-05 13:03:21 -0800527 // Only bring up ImsResolver if the device supports having an IMS stack.
528 if (getPackageManager().hasSystemFeature(
529 PackageManager.FEATURE_TELEPHONY_IMS)) {
530 // Get the package name of the default IMS implementation.
531 String defaultImsMmtelPackage = getResources().getString(
532 R.string.config_ims_mmtel_package);
533 String defaultImsRcsPackage = getResources().getString(
534 R.string.config_ims_rcs_package);
Brad Ebingerd1947d82021-05-17 20:54:49 +0000535 ImsResolver.make(this, defaultImsMmtelPackage,
Brad Ebingere3ae65a2020-09-11 12:45:11 -0700536 defaultImsRcsPackage, PhoneFactory.getPhones().length,
537 new ImsFeatureBinderRepository());
Brad Ebingerd1947d82021-05-17 20:54:49 +0000538 ImsResolver.getInstance().initialize();
Tyler Gunn92479152021-01-20 16:30:10 -0800539
540 // With the IMS phone created, load static config.xml values from the phone process
541 // so that it can be provided to the ImsPhoneCallTracker.
542 for (Phone p : PhoneFactory.getPhones()) {
543 Phone imsPhone = p.getImsPhone();
544 if (imsPhone != null && imsPhone instanceof ImsPhone) {
545 ImsPhone theImsPhone = (ImsPhone) imsPhone;
546 if (theImsPhone.getCallTracker() instanceof ImsPhoneCallTracker) {
547 ImsPhoneCallTracker ict = (ImsPhoneCallTracker)
548 theImsPhone.getCallTracker();
549
550 ImsPhoneCallTracker.Config config = new ImsPhoneCallTracker.Config();
551 config.isD2DCommunicationSupported = getResources().getBoolean(
552 R.bool.config_use_device_to_device_communication);
553 ict.setConfig(config);
554 }
555 }
556 }
Hui Wang068ab862020-10-31 05:12:53 +0000557 RcsProvisioningMonitor.make(this);
Brad Ebinger05f52c22019-12-05 13:03:21 -0800558 }
559
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700560 // Start TelephonyDebugService After the default phone is created.
561 Intent intent = new Intent(this, TelephonyDebugService.class);
562 startService(intent);
563
564 mCM = CallManager.getInstance();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700565
566 // Create the NotificationMgr singleton, which is used to display
567 // status bar icons and control other status bar behavior.
568 notificationMgr = NotificationMgr.init(this);
569
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000570 // Create the SatelliteController singleton, which acts as a backend service for
571 // {@link android.telephony.satellite.SatelliteManager}.
sangyun15019e02023-11-13 21:50:15 +0900572 SatelliteController.make(this, mFeatureFlags);
Sarah Chin5f57c582023-02-14 04:16:10 -0800573
Anthony Lee03ebdfc2015-07-27 08:12:02 -0700574 // Create an instance of CdmaPhoneCallState and initialize it to IDLE
575 cdmaPhoneCallState = new CdmaPhoneCallState();
576 cdmaPhoneCallState.CdmaPhoneCallStateInit();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700577
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700578 // before registering for phone state changes
579 mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
580 mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
581 // lock used to keep the processor awake, when we don't care for the display.
582 mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
583 | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700584
585 mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
586
sangyun15019e02023-11-13 21:50:15 +0900587 phoneMgr = PhoneInterfaceManager.init(this, mFeatureFlags);
Santos Cordon406c0342013-08-28 00:07:47 -0700588
joonhunshin2c33ed92023-12-12 14:29:23 +0000589 imsRcsController = ImsRcsController.init(this, mFeatureFlags);
James.cf Linaf3183c2019-10-24 00:59:00 +0800590
joonhunshin21a86812023-12-10 08:21:25 +0000591 configLoader = CarrierConfigLoader.init(this, mFeatureFlags);
Brad Ebinger6c53e7f2023-01-27 16:26:44 -0800592
James.cf Linc9f35a42020-01-15 02:35:22 +0800593 if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000594 mImsStateCallbackController =
595 ImsStateCallbackController.make(this, PhoneFactory.getPhones().length);
Brad Ebingera68a4972020-01-30 17:31:23 -0800596 mTelephonyRcsService = new TelephonyRcsService(this,
597 PhoneFactory.getPhones().length);
598 mTelephonyRcsService.initialize();
James.cf Linc9f35a42020-01-15 02:35:22 +0800599 imsRcsController.setRcsService(mTelephonyRcsService);
joonhunshincffb7fc2021-11-28 07:32:01 +0000600 mImsProvisioningController =
601 ImsProvisioningController.make(this, PhoneFactory.getPhones().length);
James.cf Linc9f35a42020-01-15 02:35:22 +0800602 }
603
Jack Yu1a2fc352017-07-14 17:14:37 -0700604 // Create the CallNotifier singleton, which handles
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700605 // asynchronous events from the telephony layer (like
606 // launching the incoming-call UI when an incoming call comes
607 // in.)
Brad Ebingera9c6b6d2016-01-07 17:24:16 -0800608 notifier = CallNotifier.init(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700609
Stuart Scottdcf40a92014-12-09 10:45:01 -0800610 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700611
612 // register for MMI/USSD
613 mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);
614
Qiong Liucc3fe812019-09-23 15:25:44 +0800615 // Initialize cell status using current airplane mode.
Taesu Lee62f826d2020-08-10 16:01:18 +0900616 handleAirplaneModeChange(
617 Settings.Global.getInt(
618 getContentResolver(),
619 Settings.Global.AIRPLANE_MODE_ON,
620 AIRPLANE_OFF)
621 == AIRPLANE_ON);
Qiong Liucc3fe812019-09-23 15:25:44 +0800622
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700623 // Register for misc other intent broadcasts.
624 IntentFilter intentFilter =
625 new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700626 intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
627 intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700628 intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
Jack Yu1a2fc352017-07-14 17:14:37 -0700629 intentFilter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
630 intentFilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700631 registerReceiver(mReceiver, intentFilter);
Jack Yuec144222023-12-13 16:03:03 -0800632 int defaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
633 if (SubscriptionManager.isValidSubscriptionId(defaultDataSubId)) {
634 if (VDBG) {
635 Log.v(LOG_TAG, "Loaded initial default data sub: " + defaultDataSubId);
sangyun15019e02023-11-13 21:50:15 +0900636 }
Jack Yuec144222023-12-13 16:03:03 -0800637 mDefaultDataSubId = defaultDataSubId;
638 registerSettingsObserver();
639 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED);
sangyundce559b2023-09-11 10:25:55 +0900640 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700641
Sarah Chin072ffb22022-05-03 17:58:59 -0700642 PhoneConfigurationManager.registerForMultiSimConfigChange(
643 mHandler, EVENT_MULTI_SIM_CONFIG_CHANGED, null);
644
645 mTelephonyCallbacks = new PhoneAppCallback[tm.getSupportedModemCount()];
Fangyuan Li7f5c2752022-06-29 18:02:31 +0800646 if (tm.getSupportedModemCount() > 0) {
647 for (Phone phone : PhoneFactory.getPhones()) {
648 int subId = phone.getSubId();
649 PhoneAppCallback callback = new PhoneAppCallback(subId);
650 tm.createForSubscriptionId(subId).registerTelephonyCallback(
651 TelephonyManager.INCLUDE_LOCATION_DATA_NONE, mHandler::post, callback);
652 mTelephonyCallbacks[phone.getPhoneId()] = callback;
653 }
Sarah Chin072ffb22022-05-03 17:58:59 -0700654 }
Ta-wei Yenf0a71bc2017-05-17 12:28:28 -0700655 mCarrierVvmPackageInstalledReceiver.register(this);
656
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700657 //set the default values for the preferences in the phone.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700658 PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700659 }
660
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700661 // XXX pre-load the SimProvider so that it's ready
662 resolver.getType(Uri.parse("content://icc/adn"));
663
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700664 // TODO: Register for Cdma Information Records
665 // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);
666
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700667 // Read HAC settings and configure audio hardware
668 if (getResources().getBoolean(R.bool.hac_enabled)) {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800669 int hac = android.provider.Settings.System.getInt(
670 getContentResolver(),
671 android.provider.Settings.System.HEARING_AID,
672 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700673 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Jordan Liuf71aeef2019-08-21 11:46:09 -0700674 audioManager.setParameters(
675 SettingsConstants.HAC_KEY + "=" + (hac == SettingsConstants.HAC_ENABLED
676 ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700677 }
Siim Sammul182d61b2021-05-04 16:01:42 +0100678
679 // Start tracking Binder latency for the phone process.
680 mBinderCallsSettingsObserver = new BinderCallsStats.SettingsObserver(
681 getApplicationContext(),
Siim Sammula6950092021-06-22 17:14:03 +0100682 new BinderCallsStats(
683 new BinderCallsStats.Injector(),
684 com.android.internal.os.BinderLatencyProto.Dims.TELEPHONY));
Santos Cordonff506f52013-11-21 19:13:19 -0800685 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700686
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700687 /**
688 * Returns the singleton instance of the PhoneApp.
689 */
Sailesh Nepal1eaf22b2014-02-22 17:00:49 -0800690 public static PhoneGlobals getInstance() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700691 if (sMe == null) {
692 throw new IllegalStateException("No PhoneGlobals here!");
693 }
694 return sMe;
695 }
696
697 /**
Stuart Scottdcf40a92014-12-09 10:45:01 -0800698 * Returns the default phone.
699 *
Andrew Lee385019f2014-11-24 14:19:50 -0800700 * WARNING: This method should be used carefully, now that there may be multiple phones.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700701 */
Andrew Lee83383e42014-10-31 12:42:28 -0700702 public static Phone getPhone() {
Stuart Scottdcf40a92014-12-09 10:45:01 -0800703 return PhoneFactory.getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700704 }
705
Andrew Lee2fcb6c32014-12-04 14:52:35 -0800706 public static Phone getPhone(int subId) {
707 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Andrew Lee385019f2014-11-24 14:19:50 -0800708 }
709
Santos Cordonde10b752013-09-19 04:11:33 -0700710 /* package */ CallManager getCallManager() {
711 return mCM;
712 }
713
Chris Manton4e9fa912015-06-19 11:26:57 -0700714 public PersistableBundle getCarrierConfig() {
Shishir Agrawald3480e02016-01-25 13:05:49 -0800715 return getCarrierConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
Jonathan Basseri89b0ab42015-05-01 10:52:40 -0700716 }
717
Chris Manton4e9fa912015-06-19 11:26:57 -0700718 public PersistableBundle getCarrierConfigForSubId(int subId) {
Philip P. Moltmann0079aae2020-03-05 16:24:02 -0800719 return configLoader.getConfigForSubIdWithFeature(subId, getOpPackageName(),
720 getAttributionTag());
Junda Liu605148f2015-04-28 15:23:40 -0700721 }
722
Jack Yu1a2fc352017-07-14 17:14:37 -0700723 private void registerSettingsObserver() {
724 mSettingsObserver.unobserve();
725 String dataRoamingSetting = Settings.Global.DATA_ROAMING;
726 String mobileDataSetting = Settings.Global.MOBILE_DATA;
727 if (TelephonyManager.getDefault().getSimCount() > 1) {
728 int subId = mDefaultDataSubId;
729 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
730 dataRoamingSetting += subId;
731 mobileDataSetting += subId;
732 }
733 }
734
735 // Listen for user data roaming setting changed event
736 mSettingsObserver.observe(Settings.Global.getUriFor(dataRoamingSetting),
737 EVENT_DATA_ROAMING_SETTINGS_CHANGED);
738
739 // Listen for mobile data setting changed event
740 mSettingsObserver.observe(Settings.Global.getUriFor(mobileDataSetting),
741 EVENT_MOBILE_DATA_SETTINGS_CHANGED);
742 }
743
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700744 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700745 * Sets the activity responsible for un-PUK-blocking the device
746 * so that we may close it when we receive a positive result.
747 * mPUKEntryActivity is also used to indicate to the device that
748 * we are trying to un-PUK-lock the phone. In other words, iff
749 * it is NOT null, then we are trying to unlock and waiting for
750 * the SIM to move to READY state.
751 *
752 * @param activity is the activity to close when PUK has
753 * finished unlocking. Can be set to null to indicate the unlock
754 * or SIM READYing process is over.
755 */
756 void setPukEntryActivity(Activity activity) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700757 Log.i(LOG_TAG, "setPukEntryActivity - set to " + (activity == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700758 mPUKEntryActivity = activity;
759 }
760
761 Activity getPUKEntryActivity() {
762 return mPUKEntryActivity;
763 }
764
765 /**
766 * Sets the dialog responsible for notifying the user of un-PUK-
767 * blocking - SIM READYing progress, so that we may dismiss it
768 * when we receive a positive result.
769 *
770 * @param dialog indicates the progress dialog informing the user
771 * of the state of the device. Dismissed upon completion of
772 * READYing process
773 */
774 void setPukEntryProgressDialog(ProgressDialog dialog) {
Tyler Gunn3fc09c02020-05-08 16:35:55 -0700775 Log.i(LOG_TAG, "setPukEntryProgressDialog - set to "
776 + (dialog == null ? "null" : "activity"));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700777 mPUKEntryProgressDialog = dialog;
778 }
779
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700780 KeyguardManager getKeyguardManager() {
781 return mKeyguardManager;
782 }
783
784 private void onMMIComplete(AsyncResult r) {
785 if (VDBG) Log.d(LOG_TAG, "onMMIComplete()...");
786 MmiCode mmiCode = (MmiCode) r.result;
Stuart Scottdcf40a92014-12-09 10:45:01 -0800787 PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700788 }
789
fionaxu80126972017-02-01 17:01:26 -0800790 private void initForNewRadioTechnology() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700791 if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700792 notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700793 }
794
Taesu Lee62f826d2020-08-10 16:01:18 +0900795 private void handleAirplaneModeChange(boolean isAirplaneNewlyOn) {
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700796 Log.i(LOG_TAG, "handleAirplaneModeChange: isAirplaneNewlyOn=" + isAirplaneNewlyOn);
Taesu Lee62f826d2020-08-10 16:01:18 +0900797 int cellState =
798 Settings.Global.getInt(
799 getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
Chris Mantona09f3632016-02-09 14:48:42 -0800800 switch (cellState) {
801 case PhoneConstants.CELL_OFF_FLAG:
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700802 // Airplane mode does not affect the cell radio if user has turned it off.
803 Log.i(LOG_TAG, "Ignore airplane mode change due to cell off.");
Chris Mantona09f3632016-02-09 14:48:42 -0800804 break;
805 case PhoneConstants.CELL_ON_FLAG:
Taesu Lee62f826d2020-08-10 16:01:18 +0900806 maybeTurnCellOff(isAirplaneNewlyOn);
Chris Mantona09f3632016-02-09 14:48:42 -0800807 break;
808 case PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG:
Taesu Lee62f826d2020-08-10 16:01:18 +0900809 maybeTurnCellOn(isAirplaneNewlyOn);
Chris Mantona09f3632016-02-09 14:48:42 -0800810 break;
811 }
Hall Liu7f56e1a2019-07-10 14:41:14 -0700812 for (Phone phone : PhoneFactory.getPhones()) {
813 phone.getServiceStateTracker().onAirplaneModeChanged(isAirplaneNewlyOn);
814 }
Chris Mantona09f3632016-02-09 14:48:42 -0800815 }
816
817 /*
818 * Returns true if the radio must be turned off when entering airplane mode.
819 */
Taesu Lee62f826d2020-08-10 16:01:18 +0900820 private boolean isCellOffInAirplaneMode() {
821 String airplaneModeRadios =
822 Settings.Global.getString(
823 getContentResolver(), Settings.Global.AIRPLANE_MODE_RADIOS);
Chris Mantona09f3632016-02-09 14:48:42 -0800824 return airplaneModeRadios == null
825 || airplaneModeRadios.contains(Settings.Global.RADIO_CELL);
826 }
827
Taesu Lee62f826d2020-08-10 16:01:18 +0900828 private void setRadioPowerOff() {
Chris Mantona09f3632016-02-09 14:48:42 -0800829 Log.i(LOG_TAG, "Turning radio off - airplane");
Taesu Lee62f826d2020-08-10 16:01:18 +0900830 Settings.Global.putInt(
831 getContentResolver(),
832 Settings.Global.CELL_ON,
833 PhoneConstants.CELL_OFF_DUE_TO_AIRPLANE_MODE_FLAG);
Chris Mantona09f3632016-02-09 14:48:42 -0800834 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 0);
Taesu Lee62f826d2020-08-10 16:01:18 +0900835 TelephonyProperties.airplane_mode_on(true); // true means int value 1
Chris Mantona09f3632016-02-09 14:48:42 -0800836 PhoneUtils.setRadioPower(false);
Ling Ma317906d2022-12-05 15:58:14 -0800837 clearCacheOnRadioOff();
838 }
839
840 /** Clear fields on power off radio **/
841 private void clearCacheOnRadioOff() {
842 // Re-show is-roaming notifications after APM mode
sangyun1c1918a2023-11-13 22:37:50 +0900843 if (mFeatureFlags.reorganizeRoamingNotification()) {
844 mShownNotificationReasons.clear();
845 } else {
846 mPrevRoamingOperatorNumerics.clear();
847 }
Chris Mantona09f3632016-02-09 14:48:42 -0800848 }
849
Taesu Lee62f826d2020-08-10 16:01:18 +0900850 private void setRadioPowerOn() {
Chris Mantona09f3632016-02-09 14:48:42 -0800851 Log.i(LOG_TAG, "Turning radio on - airplane");
Taesu Lee62f826d2020-08-10 16:01:18 +0900852 Settings.Global.putInt(
853 getContentResolver(), Settings.Global.CELL_ON, PhoneConstants.CELL_ON_FLAG);
854 Settings.Global.putInt(getContentResolver(), Settings.Global.ENABLE_CELLULAR_ON_BOOT, 1);
Meng Wang61307622019-10-23 14:08:43 -0700855 TelephonyProperties.airplane_mode_on(false); // false means int value 0
Chris Mantona09f3632016-02-09 14:48:42 -0800856 PhoneUtils.setRadioPower(true);
857 }
858
Taesu Lee62f826d2020-08-10 16:01:18 +0900859 private void maybeTurnCellOff(boolean isAirplaneNewlyOn) {
Chris Mantona09f3632016-02-09 14:48:42 -0800860 if (isAirplaneNewlyOn) {
Santos Cordone18902f2016-03-22 17:16:04 -0700861 // If we are trying to turn off the radio, make sure there are no active
862 // emergency calls. If there are, switch airplane mode back to off.
Taesu Lee62f826d2020-08-10 16:01:18 +0900863 TelecomManager tm = (TelecomManager) getSystemService(TELECOM_SERVICE);
Tyler Gunn900d8fd2018-09-21 09:22:12 -0700864
865 if (tm != null && tm.isInEmergencyCall()) {
Santos Cordone18902f2016-03-22 17:16:04 -0700866 // Switch airplane mode back to off.
Jordan Liu0e819b12019-08-28 15:33:05 -0700867 ConnectivityManager cm =
Taesu Lee62f826d2020-08-10 16:01:18 +0900868 (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
Jordan Liu0e819b12019-08-28 15:33:05 -0700869 cm.setAirplaneMode(false);
Santos Cordone18902f2016-03-22 17:16:04 -0700870 Toast.makeText(this, R.string.radio_off_during_emergency_call, Toast.LENGTH_LONG)
871 .show();
872 Log.i(LOG_TAG, "Ignoring airplane mode: emergency call. Turning airplane off");
Taesu Lee62f826d2020-08-10 16:01:18 +0900873 } else if (isCellOffInAirplaneMode()) {
874 setRadioPowerOff();
Santos Cordone18902f2016-03-22 17:16:04 -0700875 } else {
Chris Mantona09f3632016-02-09 14:48:42 -0800876 Log.i(LOG_TAG, "Ignoring airplane mode: settings prevent cell radio power off");
Santos Cordone18902f2016-03-22 17:16:04 -0700877 }
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700878 } else {
879 Log.i(LOG_TAG, "Ignoring airplane mode: not newly on");
Chris Mantona09f3632016-02-09 14:48:42 -0800880 }
881 }
882
Taesu Lee62f826d2020-08-10 16:01:18 +0900883 private void maybeTurnCellOn(boolean isAirplaneNewlyOn) {
Chris Mantona09f3632016-02-09 14:48:42 -0800884 if (!isAirplaneNewlyOn) {
Taesu Lee62f826d2020-08-10 16:01:18 +0900885 setRadioPowerOn();
Sarah Chin9ec6e1e2022-08-10 13:29:40 -0700886 } else {
887 Log.i(LOG_TAG, "Ignoring airplane mode off: radio is already on.");
Santos Cordone18902f2016-03-22 17:16:04 -0700888 }
889 }
890
Santos Cordon593ab382013-08-06 21:58:23 -0700891 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700892 * Receiver for misc intent broadcasts the Phone app cares about.
893 */
894 private class PhoneAppBroadcastReceiver extends BroadcastReceiver {
895 @Override
896 public void onReceive(Context context, Intent intent) {
897 String action = intent.getAction();
898 if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
Taesu Lee3dc572b2020-08-07 18:16:22 +0900899 boolean airplaneMode = intent.getBooleanExtra("state", false);
Taesu Lee62f826d2020-08-10 16:01:18 +0900900 handleAirplaneModeChange(airplaneMode);
Amit Mahajanf5d92c82018-11-02 17:44:40 -0700901 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
902 // re-register as it may be a new IccCard
903 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
904 SubscriptionManager.INVALID_PHONE_INDEX);
905 if (SubscriptionManager.isValidPhoneId(phoneId)) {
906 PhoneUtils.unregisterIccStatus(mHandler, phoneId);
907 PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED, phoneId);
908 }
Nazish Tabassum160d2112019-12-23 17:31:33 +0530909 String iccStatus = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
910 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SIM_STATE_CHANGED,
911 new EventSimStateChangedBag(phoneId, iccStatus)));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700912 } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
913 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
fionaxu80126972017-02-01 17:01:26 -0800914 Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
915 initForNewRadioTechnology();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700916 } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530917 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
Srikanth Chintala079912a2016-03-03 16:35:01 +0530918 phoneInEcm = PhoneFactory.getPhone(phoneId);
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530919 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
920 if (phoneInEcm != null) {
921 if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
922 Log.d(LOG_TAG, "Emergency Callback Mode arrived in PhoneApp.");
923 // Start Emergency Callback Mode service
Daniel Bright30efde42020-01-09 22:11:15 -0800924 if (intent.getBooleanExtra(
925 TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false)) {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530926 context.startService(new Intent(context,
927 EmergencyCallbackModeService.class));
928 } else {
929 phoneInEcm = null;
930 }
931 } else {
932 // It doesn't make sense to get ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
933 // on a device that doesn't support ECM in the first place.
934 Log.e(LOG_TAG, "Got ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, but "
935 + "ECM isn't supported for phone: " + phoneInEcm.getPhoneName());
936 phoneInEcm = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700937 }
938 } else {
Sandeep Kuntade73a6a2014-10-15 18:45:56 +0530939 Log.w(LOG_TAG, "phoneInEcm is null.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700940 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700941 } else if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
942 // Roaming status could be overridden by carrier config, so we need to update it.
943 if (VDBG) Log.v(LOG_TAG, "carrier config changed.");
sangyun1c1918a2023-11-13 22:37:50 +0900944 if (mFeatureFlags.reorganizeRoamingNotification()) {
945 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED);
946 } else {
947 updateDataRoamingStatusForFeatureDisabled(null);
948 }
chen xubaf9fe52019-07-02 17:28:24 -0700949 updateLimitedSimFunctionForDualSim();
Lei Liu863eac02020-06-24 20:12:55 +0800950 int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
951 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
952 if (SubscriptionManager.isValidSubscriptionId(subId)) {
953 mHandler.sendMessage(mHandler.obtainMessage(EVENT_CARRIER_CONFIG_CHANGED,
954 new Integer(subId)));
955 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700956 } else if (action.equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
957 // We also need to pay attention when default data subscription changes.
958 if (VDBG) Log.v(LOG_TAG, "default data sub changed.");
959 mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
960 registerSettingsObserver();
961 Phone phone = getPhone(mDefaultDataSubId);
962 if (phone != null) {
sangyun1c1918a2023-11-13 22:37:50 +0900963 if (mFeatureFlags.reorganizeRoamingNotification()) {
964 updateDataRoamingStatus(
965 ROAMING_NOTIFICATION_REASON_DEFAULT_DATA_SUBS_CHANGED);
966 } else {
967 updateDataRoamingStatusForFeatureDisabled(null);
968 }
Jack Yu1a2fc352017-07-14 17:14:37 -0700969 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700970 }
971 }
972 }
973
Sarah Chin072ffb22022-05-03 17:58:59 -0700974 private void handleServiceStateChanged(ServiceState serviceState, int subId) {
Jack Yu1a2fc352017-07-14 17:14:37 -0700975 if (VDBG) Log.v(LOG_TAG, "handleServiceStateChanged");
Sarah Chin072ffb22022-05-03 17:58:59 -0700976 int state = serviceState.getState();
977 notificationMgr.updateNetworkSelection(state, subId);
Jack Yu1a2fc352017-07-14 17:14:37 -0700978
Sarah Chin072ffb22022-05-03 17:58:59 -0700979 if (VDBG) {
980 Log.v(LOG_TAG, "subId=" + subId + ", mDefaultDataSubId="
981 + mDefaultDataSubId + ", ss roaming=" + serviceState.getDataRoaming());
982 }
983 if (subId == mDefaultDataSubId) {
sangyun1c1918a2023-11-13 22:37:50 +0900984 if (mFeatureFlags.reorganizeRoamingNotification()) {
985 updateDataRoamingStatus(ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED);
986 } else {
987 updateDataRoamingStatusForFeatureDisabled(serviceState.getOperatorNumeric());
988 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700989 }
990 }
991
Jack Yu1a2fc352017-07-14 17:14:37 -0700992 /**
993 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
994 * to notify the user so they can enable it through settings. Vise versa if the condition
995 * changes, we need to dismiss the notification.
sangyun35f23f82023-07-18 01:37:53 +0900996 * @param reason to inform which event is called for notification update.
Jack Yu1a2fc352017-07-14 17:14:37 -0700997 */
sangyun35f23f82023-07-18 01:37:53 +0900998 private void updateDataRoamingStatus(@RoamingNotificationReason int reason) {
Jack Yu1a2fc352017-07-14 17:14:37 -0700999 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatus");
1000 Phone phone = getPhone(mDefaultDataSubId);
1001 if (phone == null) {
1002 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
1003 return;
1004 }
1005
sangyun35f23f82023-07-18 01:37:53 +09001006 ServiceState serviceState = phone.getServiceState();
Thomas Nguyen4f9c89e2023-12-18 10:51:57 -08001007 if (serviceState == null) {
1008 Log.e(LOG_TAG, "updateDataRoamingStatus: serviceState is null");
1009 return;
1010 }
1011
sangyun35f23f82023-07-18 01:37:53 +09001012 String roamingNumeric = serviceState.getOperatorNumeric();
1013 String roamingNumericReason = "RoamingNumeric=" + roamingNumeric;
1014 String callingReason = "CallingReason=" + reason;
1015 boolean dataIsNowRoaming = serviceState.getDataRoaming();
Jack Yu3e2ac6e2022-03-26 13:59:45 -07001016 boolean dataAllowed;
1017 boolean notAllowedDueToRoamingOff;
Sarah Chine04784a2022-10-31 20:32:34 -07001018 List<DataDisallowedReason> reasons = phone.getDataNetworkController()
1019 .getInternetDataDisallowedReasons();
Jack Yu7968c6d2022-07-31 00:43:21 -07001020 dataAllowed = reasons.isEmpty();
1021 notAllowedDueToRoamingOff = (reasons.size() == 1
1022 && reasons.contains(DataDisallowedReason.ROAMING_DISABLED));
sangyun35f23f82023-07-18 01:37:53 +09001023 StringBuilder sb = new StringBuilder("updateDataRoamingStatus");
1024 sb.append(" dataAllowed=").append(dataAllowed);
1025 sb.append(", reasons=").append(reasons);
1026 sb.append(", dataIsNowRoaming=").append(dataIsNowRoaming);
1027 sb.append(", ").append(roamingNumericReason);
1028 sb.append(", ").append(callingReason);
1029 mDataRoamingNotifLog.log(sb.toString());
Ling Ma317906d2022-12-05 15:58:14 -08001030 if (VDBG) {
sangyun35f23f82023-07-18 01:37:53 +09001031 Log.v(LOG_TAG, sb.toString());
Ling Ma317906d2022-12-05 15:58:14 -08001032 }
Jack Yu3e2ac6e2022-03-26 13:59:45 -07001033
sangyun35f23f82023-07-18 01:37:53 +09001034 // Determine if a given roaming numeric has never been shown.
1035 boolean shownInThisNumeric = false;
1036 if (reason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED
1037 || reason == ROAMING_NOTIFICATION_REASON_SERVICE_STATE_CHANGED) {
1038 shownInThisNumeric = mShownNotificationReasons.contains(roamingNumericReason);
1039 }
1040 // Determine if a notification has never been shown by given calling reason.
1041 boolean shownForThisReason = mShownNotificationReasons.contains(callingReason);
1042
Jack Yu3e2ac6e2022-03-26 13:59:45 -07001043 if (!dataAllowed && notAllowedDueToRoamingOff) {
sangyun35f23f82023-07-18 01:37:53 +09001044 if (!shownInThisNumeric && roamingNumeric != null) {
1045 mShownNotificationReasons.add(roamingNumericReason);
1046 }
1047 if (!shownForThisReason
1048 && reason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED) {
1049 mShownNotificationReasons.add(callingReason);
Ling Ma4e15c322022-12-07 11:20:53 -08001050 }
Jordan Liuff2ccd72019-07-23 15:54:41 -07001051 // No need to show it again if we never cancelled it explicitly.
sangyun35f23f82023-07-18 01:37:53 +09001052 if (getCurrentRoamingNotification() == ROAMING_NOTIFICATION_DISCONNECTED) {
1053 return;
1054 }
1055
Jack Yu1a2fc352017-07-14 17:14:37 -07001056 // If the only reason of no data is data roaming disabled, then we notify the user
1057 // so the user can turn on data roaming.
sangyun35f23f82023-07-18 01:37:53 +09001058 if (!shownInThisNumeric && !shownForThisReason) {
1059 updateDataRoamingNotification(ROAMING_NOTIFICATION_DISCONNECTED);
1060 } else {
1061 // Don't show roaming notification if we've already shown for this MccMnc
1062 Log.d(LOG_TAG, "Skip roaming disconnected notification since already"
1063 + " shownInThisNumeric=" + shownInThisNumeric
1064 + " shownForThisReason=" + shownForThisReason);
1065 // Dismiss notification if the other notification is shown.
1066 if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
1067 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
1068 }
1069 }
1070 } else if (dataAllowed && dataIsNowRoaming) {
1071 if (!shownInThisNumeric && roamingNumeric != null) {
1072 mShownNotificationReasons.add(roamingNumericReason);
1073 }
1074 if (!shownForThisReason
1075 && reason == ROAMING_NOTIFICATION_REASON_CARRIER_CONFIG_CHANGED) {
1076 mShownNotificationReasons.add(callingReason);
1077 }
Sarah Chin37b39072023-11-05 13:28:21 -08001078 boolean shouldShowRoamingNotification = shouldShowRoamingNotification(roamingNumeric);
sangyun35f23f82023-07-18 01:37:53 +09001079 // No need to show it again if we never cancelled it explicitly.
1080 if (getCurrentRoamingNotification() == ROAMING_NOTIFICATION_CONNECTED) {
Ling Ma4e15c322022-12-07 11:20:53 -08001081 return;
1082 }
sangyun35f23f82023-07-18 01:37:53 +09001083
1084 // Inform users that roaming charges may apply.
Sarah Chin37b39072023-11-05 13:28:21 -08001085 if (!shownInThisNumeric && !shownForThisReason && shouldShowRoamingNotification) {
sangyun35f23f82023-07-18 01:37:53 +09001086 updateDataRoamingNotification(ROAMING_NOTIFICATION_CONNECTED);
1087 } else {
1088 // Don't show roaming notification if we've already shown for this MccMnc or
1089 // disabled from carrier config.
1090 Log.d(LOG_TAG, "Skip roaming connected notification since already"
1091 + " shownInThisNumeric:" + shownInThisNumeric
1092 + " shownForThisReason:" + shownForThisReason
Sarah Chin37b39072023-11-05 13:28:21 -08001093 + " shouldShowRoamingNotification:" + shouldShowRoamingNotification);
sangyun35f23f82023-07-18 01:37:53 +09001094 // Dismiss notification if the other notification is shown.
1095 if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
1096 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
1097 }
1098 }
1099 } else if (getCurrentRoamingNotification() != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
Jordan Liuff2ccd72019-07-23 15:54:41 -07001100 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
1101 // is not the only data disable reason. In this case we dismiss the notification we
1102 // showed earlier.
sangyun35f23f82023-07-18 01:37:53 +09001103 updateDataRoamingNotification(ROAMING_NOTIFICATION_NO_NOTIFICATION);
Jack Yu1a2fc352017-07-14 17:14:37 -07001104 }
1105 }
1106
sangyun35f23f82023-07-18 01:37:53 +09001107 private void updateDataRoamingNotification(@RoamingNotification int roamingNotification) {
1108 int event;
1109 switch (roamingNotification) {
1110 case ROAMING_NOTIFICATION_NO_NOTIFICATION:
1111 Log.d(LOG_TAG, "Dismiss roaming notification");
1112 mDataRoamingNotifLog.log("Hide roaming.");
1113 event = EVENT_DATA_ROAMING_OK;
1114 break;
1115 case ROAMING_NOTIFICATION_CONNECTED:
1116 Log.d(LOG_TAG, "Show roaming connected notification");
1117 mDataRoamingNotifLog.log("Show roaming on.");
1118 event = EVENT_DATA_ROAMING_CONNECTED;
1119 break;
1120 case ROAMING_NOTIFICATION_DISCONNECTED:
1121 Log.d(LOG_TAG, "Show roaming disconnected notification");
1122 mDataRoamingNotifLog.log("Show roaming off.");
1123 event = EVENT_DATA_ROAMING_DISCONNECTED;
1124 break;
1125 default:
1126 Log.d(LOG_TAG, "Should never reach here.");
1127 mDataRoamingNotifLog.log("Should never reach here.");
1128 return;
1129 }
1130 mCurrentRoamingNotification = roamingNotification;
1131 mHandler.obtainMessage(event, mDefaultDataSubId, 0).sendToTarget();
1132 }
1133
1134 private @RoamingNotification int getCurrentRoamingNotification() {
1135 return mCurrentRoamingNotification;
1136 }
1137
sangyun1c1918a2023-11-13 22:37:50 +09001138 // For reorganize_roaming_notification feature disabled.
1139 /**
1140 * When roaming, if mobile data cannot be established due to data roaming not enabled, we need
1141 * to notify the user so they can enable it through settings. Vise versa if the condition
1142 * changes, we need to dismiss the notification.
1143 * @param roamingOperatorNumeric The operator numeric for the current roaming. {@code null} if
1144 * the current roaming operator numeric didn't change.
1145 */
1146 private void updateDataRoamingStatusForFeatureDisabled(
1147 @Nullable String roamingOperatorNumeric) {
1148 if (VDBG) Log.v(LOG_TAG, "updateDataRoamingStatusForFeatureDisabled");
1149 Phone phone = getPhone(mDefaultDataSubId);
1150 if (phone == null) {
1151 Log.w(LOG_TAG, "Can't get phone with sub id = " + mDefaultDataSubId);
1152 return;
1153 }
1154
1155 boolean dataAllowed;
1156 boolean notAllowedDueToRoamingOff;
1157 List<DataDisallowedReason> reasons = phone.getDataNetworkController()
1158 .getInternetDataDisallowedReasons();
1159 dataAllowed = reasons.isEmpty();
1160 notAllowedDueToRoamingOff = (reasons.size() == 1
1161 && reasons.contains(DataDisallowedReason.ROAMING_DISABLED));
1162 mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons
1163 + ", roamingOperatorNumeric=" + roamingOperatorNumeric);
1164 if (VDBG) {
1165 Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons
1166 + ", roamingOperatorNumeric=" + roamingOperatorNumeric);
1167 }
1168
1169 if (!dataAllowed && notAllowedDueToRoamingOff) {
1170 // Don't show roaming notification if we've already shown for this MccMnc
1171 if (roamingOperatorNumeric != null
1172 && !mPrevRoamingOperatorNumerics.add(roamingOperatorNumeric)) {
1173 Log.d(LOG_TAG, "Skip roaming disconnected notification since already shown in "
1174 + "MccMnc " + roamingOperatorNumeric);
1175 return;
1176 }
1177 // No need to show it again if we never cancelled it explicitly.
1178 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_DISCONNECTED) return;
1179 // If the only reason of no data is data roaming disabled, then we notify the user
1180 // so the user can turn on data roaming.
1181 mPrevRoamingNotification = ROAMING_NOTIFICATION_DISCONNECTED;
1182 Log.d(LOG_TAG, "Show roaming disconnected notification");
1183 mDataRoamingNotifLog.log("Show roaming off.");
1184 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_DISCONNECTED);
1185 msg.arg1 = mDefaultDataSubId;
1186 msg.sendToTarget();
1187 } else if (dataAllowed && dataIsNowRoaming(mDefaultDataSubId)) {
Sarah Chin37b39072023-11-05 13:28:21 -08001188 if (!shouldShowRoamingNotification(roamingOperatorNumeric)) {
1189 Log.d(LOG_TAG, "Skip showing roaming connected notification.");
1190 return;
1191 }
sangyun1c1918a2023-11-13 22:37:50 +09001192 // Don't show roaming notification if we've already shown for this MccMnc
1193 if (roamingOperatorNumeric != null
1194 && !mPrevRoamingOperatorNumerics.add(roamingOperatorNumeric)) {
1195 Log.d(LOG_TAG, "Skip roaming connected notification since already shown in "
1196 + "MccMnc " + roamingOperatorNumeric);
1197 return;
1198 }
1199 // No need to show it again if we never cancelled it explicitly, or carrier config
1200 // indicates this is not needed.
1201 if (mPrevRoamingNotification == ROAMING_NOTIFICATION_CONNECTED) return;
1202 mPrevRoamingNotification = ROAMING_NOTIFICATION_CONNECTED;
1203 Log.d(LOG_TAG, "Show roaming connected notification");
1204 mDataRoamingNotifLog.log("Show roaming on.");
1205 Message msg = mHandler.obtainMessage(EVENT_DATA_ROAMING_CONNECTED);
1206 msg.arg1 = mDefaultDataSubId;
1207 msg.sendToTarget();
1208 } else if (mPrevRoamingNotification != ROAMING_NOTIFICATION_NO_NOTIFICATION) {
1209 // Otherwise we either 1) we are not roaming or 2) roaming is off but ROAMING_DISABLED
1210 // is not the only data disable reason. In this case we dismiss the notification we
1211 // showed earlier.
1212 mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
1213 Log.d(LOG_TAG, "Dismiss roaming notification");
1214 mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed);
1215 mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
1216 }
1217 }
1218
Jordan Liuff2ccd72019-07-23 15:54:41 -07001219 /**
1220 *
1221 * @param subId to check roaming on
1222 * @return whether we have transitioned to dataRoaming
1223 */
1224 private boolean dataIsNowRoaming(int subId) {
Sarah Chine04784a2022-10-31 20:32:34 -07001225 return getPhone(subId).getServiceState().getDataRoaming();
Jordan Liuff2ccd72019-07-23 15:54:41 -07001226 }
1227
Sarah Chin37b39072023-11-05 13:28:21 -08001228 private boolean shouldShowRoamingNotification(String roamingNumeric) {
1229 PersistableBundle config = getCarrierConfigForSubId(mDefaultDataSubId);
1230 boolean showRoamingNotification = config.getBoolean(
1231 CarrierConfigManager.KEY_SHOW_DATA_CONNECTED_ROAMING_NOTIFICATION_BOOL);
1232
1233 if (TextUtils.isEmpty(roamingNumeric) || !mFeatureFlags.hideRoamingIcon()) {
1234 Log.d(LOG_TAG, "shouldShowRoamingNotification: roamingNumeric=" + roamingNumeric
1235 + ", hideRoaming=" + mFeatureFlags.hideRoamingIcon());
1236 return showRoamingNotification;
1237 }
1238
1239 String[] includedMccMncs = config.getStringArray(CarrierConfigManager
1240 .KEY_DATA_CONNECTED_ROAMING_NOTIFICATION_INCLUDED_MCC_MNCS_STRING_ARRAY);
1241 if (includedMccMncs != null) {
1242 for (String mccMnc : includedMccMncs) {
1243 if (roamingNumeric.equals(mccMnc)) {
1244 Log.d(LOG_TAG, "shouldShowRoamingNotification: show for MCC/MNC " + mccMnc);
1245 return showRoamingNotification;
1246 }
1247 }
1248 }
1249
1250 String[] excludedMccs = config.getStringArray(CarrierConfigManager
1251 .KEY_DATA_CONNECTED_ROAMING_NOTIFICATION_EXCLUDED_MCCS_STRING_ARRAY);
1252 String roamingMcc = roamingNumeric.length() < 3 ? "" : roamingNumeric.substring(0, 3);
1253 if (excludedMccs != null && !TextUtils.isEmpty(roamingMcc)) {
1254 for (String mcc : excludedMccs) {
1255 if (roamingMcc.equals(mcc)) {
1256 Log.d(LOG_TAG, "shouldShowRoamingNotification: ignore for MCC " + mcc);
1257 return false;
1258 }
1259 }
1260 }
1261
1262 if (showRoamingNotification) {
1263 Log.d(LOG_TAG, "shouldShowRoamingNotification: show for numeric " + roamingNumeric);
1264 }
1265 return showRoamingNotification;
1266 }
1267
chen xubaf9fe52019-07-02 17:28:24 -07001268 private void updateLimitedSimFunctionForDualSim() {
1269 if (DBG) Log.d(LOG_TAG, "updateLimitedSimFunctionForDualSim");
1270 // check conditions to display limited SIM function notification under dual SIM
1271 SubscriptionManager subMgr = (SubscriptionManager) getSystemService(
1272 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
1273 List<SubscriptionInfo> subList = subMgr.getActiveSubscriptionInfoList(false);
1274 if (subList != null && subList.size() > 1) {
1275 CarrierConfigManager configMgr = (CarrierConfigManager)
1276 getSystemService(Context.CARRIER_CONFIG_SERVICE);
1277 for (SubscriptionInfo info : subList) {
1278 PersistableBundle b = configMgr.getConfigForSubId(info.getSubscriptionId());
1279 if (b != null) {
1280 if (b.getBoolean(CarrierConfigManager
1281 .KEY_LIMITED_SIM_FUNCTION_NOTIFICATION_FOR_DSDS_BOOL)) {
1282 notificationMgr.showLimitedSimFunctionWarningNotification(
1283 info.getSubscriptionId(),
1284 info.getDisplayName().toString());
1285 } else {
1286 notificationMgr.dismissLimitedSimFunctionWarningNotification(
1287 info.getSubscriptionId());
1288 }
1289 }
1290 }
1291 } else {
1292 // cancel notifications for all subs
1293 notificationMgr.dismissLimitedSimFunctionWarningNotification(
1294 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1295 }
1296 notificationMgr.dismissLimitedSimFunctionWarningNotificationForInactiveSubs();
1297
1298 }
1299
Sandeep Kuntade73a6a2014-10-15 18:45:56 +05301300 public Phone getPhoneInEcm() {
1301 return phoneInEcm;
1302 }
1303
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001304 /**
Tyler Gunn9c1071f2014-12-09 10:07:54 -08001305 * Triggers a refresh of the message waiting (voicemail) indicator.
1306 *
1307 * @param subId the subscription id we should refresh the notification for.
1308 */
1309 public void refreshMwiIndicator(int subId) {
1310 notificationMgr.refreshMwi(subId);
1311 }
1312
1313 /**
Pengquan Mengdd9ac822018-09-20 15:25:35 -07001314 * Called when the network selection on the subscription {@code subId} is changed by the user.
1315 *
1316 * @param subId the subscription id.
1317 */
1318 public void onNetworkSelectionChanged(int subId) {
1319 Phone phone = getPhone(subId);
1320 if (phone != null) {
1321 notificationMgr.updateNetworkSelection(phone.getServiceState().getState(), subId);
1322 } else {
1323 Log.w(LOG_TAG, "onNetworkSelectionChanged on null phone, subId: " + subId);
1324 }
1325 }
1326
1327 /**
James.cf Lin4b784aa2021-01-31 03:25:15 +08001328 * @return whether the device supports RCS User Capability Exchange or not.
1329 */
1330 public boolean getDeviceUceEnabled() {
1331 return (mTelephonyRcsService == null) ? false : mTelephonyRcsService.isDeviceUceEnabled();
1332 }
1333
1334 /**
1335 * Set the device supports RCS User Capability Exchange.
1336 * @param isEnabled true if the device supports UCE.
1337 */
1338 public void setDeviceUceEnabled(boolean isEnabled) {
1339 if (mTelephonyRcsService != null) {
1340 mTelephonyRcsService.setDeviceUceEnabled(isEnabled);
1341 }
1342 }
1343
1344 /**
Jack Yu1a2fc352017-07-14 17:14:37 -07001345 * Dump the state of the object, add calls to other objects as desired.
1346 *
1347 * @param fd File descriptor
1348 * @param printWriter Print writer
1349 * @param args Arguments
1350 */
1351 public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
1352 IndentingPrintWriter pw = new IndentingPrintWriter(printWriter, " ");
1353 pw.println("------- PhoneGlobals -------");
1354 pw.increaseIndent();
sangyun15019e02023-11-13 21:50:15 +09001355 pw.println("FeatureFlags:");
1356 pw.increaseIndent();
sangyun1c1918a2023-11-13 22:37:50 +09001357 pw.println("reorganizeRoamingNotification="
1358 + mFeatureFlags.reorganizeRoamingNotification());
sangyund5f37ab2023-11-13 22:52:28 +09001359 pw.println("dismissNetworkSelectionNotificationOnSimDisable="
1360 + mFeatureFlags.dismissNetworkSelectionNotificationOnSimDisable());
sangyun15019e02023-11-13 21:50:15 +09001361 pw.decreaseIndent();
sangyun1c1918a2023-11-13 22:37:50 +09001362 if (mFeatureFlags.reorganizeRoamingNotification()) {
1363 pw.println("mCurrentRoamingNotification=" + mCurrentRoamingNotification);
1364 } else {
1365 pw.println("mPrevRoamingNotification=" + mPrevRoamingNotification);
1366 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001367 pw.println("mDefaultDataSubId=" + mDefaultDataSubId);
Keun young Parkdebb8532019-05-30 16:35:27 -07001368 pw.println("isSmsCapable=" + TelephonyManager.from(this).isSmsCapable());
sangyun35f23f82023-07-18 01:37:53 +09001369 pw.println("mDataRoamingNotifLog:");
Jack Yu1a2fc352017-07-14 17:14:37 -07001370 pw.increaseIndent();
1371 mDataRoamingNotifLog.dump(fd, pw, args);
1372 pw.decreaseIndent();
Brad Ebinger05f52c22019-12-05 13:03:21 -08001373 pw.println("ImsResolver:");
1374 pw.increaseIndent();
1375 try {
Brad Ebingerd1947d82021-05-17 20:54:49 +00001376 if (ImsResolver.getInstance() != null) ImsResolver.getInstance().dump(fd, pw, args);
Brad Ebinger05f52c22019-12-05 13:03:21 -08001377 } catch (Exception e) {
1378 e.printStackTrace();
1379 }
1380 pw.decreaseIndent();
Brad Ebingera68a4972020-01-30 17:31:23 -08001381 pw.println("RcsService:");
1382 try {
1383 if (mTelephonyRcsService != null) mTelephonyRcsService.dump(fd, pw, args);
1384 } catch (Exception e) {
1385 e.printStackTrace();
1386 }
Hunsuk Choi89bd22c2021-11-01 13:04:54 +00001387 pw.println("ImsStateCallbackController:");
1388 try {
1389 if (mImsStateCallbackController != null) mImsStateCallbackController.dump(pw);
1390 } catch (Exception e) {
1391 e.printStackTrace();
1392 }
Hwangoo Parkba21cf22022-11-30 14:34:04 +00001393 pw.println("DomainSelectionResolver:");
1394 pw.increaseIndent();
1395 try {
1396 if (DomainSelectionResolver.getInstance() != null) {
1397 DomainSelectionResolver.getInstance().dump(fd, pw, args);
1398 }
1399 } catch (Exception e) {
1400 e.printStackTrace();
1401 }
1402 pw.decreaseIndent();
Jack Yu1a2fc352017-07-14 17:14:37 -07001403 pw.decreaseIndent();
sangyun1c1918a2023-11-13 22:37:50 +09001404 if (mFeatureFlags.reorganizeRoamingNotification()) {
1405 pw.println("mShownNotificationReasons=" + mShownNotificationReasons);
1406 } else {
1407 pw.println("mPrevRoamingOperatorNumerics:" + mPrevRoamingOperatorNumerics);
1408 }
Jack Yu1a2fc352017-07-14 17:14:37 -07001409 pw.println("------- End PhoneGlobals -------");
1410 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001411}